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

using namespace std;

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int combined = r * 100 + g * 10 + b;
  if (combined % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B;
    cin >> A >> B;
    if(A+B >= 10) cout << "error" << endl;
    else cout << A+ B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

typedef pair<xy_t, bool> dat;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a)*b);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a; c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c) ) return -2;
	return 0;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

xy_t crosspoint(const line &l, const line &m){
	double a = cross(l.second - l.first, m.second - m.first);
	double b = cross(l.second - l.first, l.second - m.first);
	if(abs(a) < EPS && abs(b) < EPS) return m.first;
	if(abs(a) < EPS) assert(false);
	return m.first + b / a * (m.second - m.first);
}

const int a = 100;
int visit[200][200];
bool can[200][200];
int dy[] = {1, 0, -1, 0, 1, -1};
int dx[] = {0, -1, 0, 1, 1, -1};


int main(){
	int n, t;
	while(cin >> t >> n && (n || t)){
		memset(visit, -1, sizeof(visit));
		memset(can, true, sizeof(can));
		for(int i = 0; i <n; i++){
			int x, y;
			cin >> x >> y;
			can[x+a][y+a] = false;
		}
		int sx, sy;
		int res = 1;
		cin >> sx >> sy;
		queue<PP> que;
		visit[sx+a][sy+a] = 0;
		que.push(PP(0, P(sx+a, sy+a)));
		while(!que.empty()){
			PP pp = que.front();
			que.pop();
			P p = pp.second;
			int turn = pp.first;
			int x = p.first;
			int y = p.second;
			if(turn>= t) continue;
			for(int i = 0; i < 6;  i++){
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				if(visit[x2][y2] == -1 && can[x2][y2]){
					visit[x2][y2] = turn + 1;
					res++;
					que.push(PP(visit[x2][y2], P(x2, y2)));
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1120
n, k = map(int, input().split())
mink = (n - 1) * (n - 2) // 2
if k > mink:
    print(-1)
else:
    m = n - 1 + (mink - k)
    print(m)
    count = 0
    i = 1
    j = 2
    while count < m:
        if j == n + 1:
            i += 1
            j = i + 1
        print(i, j)
        j += 1
        count += 1

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	ll n,m,k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];


	vector<ll> cumsumA(n+1), cumsumB(m+1);
	rep(i,n) cumsumA[i+1] = cumsumA[i] + a[i];
	rep(i,m) cumsumB[i+1] = cumsumB[i] + b[i];

	ll res = 0;
	ll sumA = 0, cntA = 0;
	ll sumB = 0, cntB = 0;

	// まず、Aから一冊も読まないと仮定
	while(true){
		if(sumB + b[cntB] > k) break;
		sumB += b[cntB];
		cntB++;
		if(cntB == m) break;
	}
	res = cntB;

	// Aから取る冊数を増やしていく
	rep(i,n){
		cntA++;
		sumA += a[i];
		while(sumA + sumB > k){
			cntB--;
			if(cntB < 0) break;
			sumB -= b[cntB];
		}

		if(cntB < 0) break;
		if(sumA + sumB > k) continue;
		res = max(res, cntA + cntB);
	}

	cout << res << endl;
	
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 9516
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,C; cin >> n >> C;
	vvl d(C,vl(C));
	rep(i,C) rep(j,C) cin >> d[i][j];
	vvl s(n,vl(n));
	rep(i,n) rep(j,n) cin >> s[i][j], s[i][j]--;
	vvl ans(3,vl(C,0));
	rep(i,C){
		rep(j,n){
			rep(k,n){
				if((j+k)%3!=0) continue;
				ans[0][i] += d[s[j][k]][i];
			}
		}
	}
	rep(i,C){
		rep(j,n){
			rep(k,n){
				if((j+k)%3!=1) continue;
				ans[1][i] += d[s[j][k]][i];
			}
		}
	}
	rep(i,C){
		rep(j,n){
			rep(k,n){
				if((j+k)%3!=2) continue;
				ans[2][i] += d[s[j][k]][i];
			}
		}
	}
	ll as = linf;
	rep(i,C){
		rep(j,C){
			rep(k,C){
				if(i==j || j==k || k==i) continue;
				chmin(as,ans[0][i]+ans[1][j]+ans[2][k]);
			}
		}
	}
	cout << as << endl;
}

Measured memory_bytes: 2176
import java.util.Arrays;
import java.util.Scanner;
class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int num[]=new int[8];
		for(int i = 0; i < n ; i++){
			int max=0,min=0;
			String str = sc.next();
			for(int j = 0; j < 8; j++){
				num[j]=Integer.parseInt(String.valueOf(str.charAt(j)));
			}
			Arrays.sort(num);
			for(int j = 0; j < 8; j++){
				max += num[j]*Math.pow(10, j);
				min += num[j]*Math.pow(10, 7-j);
				
			}
			System.out.println(max-=min);
		}
	}	
}

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

int N;
int x[8],y[8];

double dist(int i,int j){
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+dy*dy,0.5);
}

int pmt(int n){
  if(n==1)return 1;
  return n*pmt(n-1); 
}

int main(){
  scanf("%d",&N);
  rep(i,N){
    scanf("%d %d",&x[i],&y[i]);
  }

  vector<int> v(N);
  rep(i,N){
    v[i]=i;
  }
  double sum=0.0;
  int count=0;
  do{
    rep(i,N-1){
      sum+=dist(v[i],v[i+1]);
    }
    count++;
  }while(next_permutation(v.begin(),v.end()));
  printf("%.6lf",sum/count);
  
}


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

public class Hello
{
    public static void Main()
    {
        
        int N = int.Parse(Console.ReadLine());
        List<int> A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        
        int ans = A[0];
        for(int i = 1; i < N; i++)
        {
            ans = gcd(ans, A[i]);
            
        }
        Console.WriteLine(ans);
    }
    
    public static int gcd(int a, int b)// a > b
    {
        if(a < b) return gcd(b, a);
        else
        {
            if(b == 0) return a;
            else return gcd(b, a % b);
        }
        
    }
}

Measured memory_bytes: 20832
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=2005;
int n,k,tot,lnk[maxn],son[maxn*2],nxt[maxn*2],ans,r;bool vis[maxn];
inline int read()
{
	int ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
inline void add_e(int x,int y){tot++;son[tot]=y;nxt[tot]=lnk[x];lnk[x]=tot;}
void DFS(int now,int fa,int dis)
{
	if(dis<=r) vis[now]=true;
	for(int i=lnk[now];i;i=nxt[i])
		if(son[i]!=fa)
			DFS(son[i],now,dis+1);
}
inline void Solve()
{
	if(k&1)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=lnk[i];j;j=nxt[j])
			{
				memset(vis,0,sizeof(vis));
				DFS(i,0,0);
				DFS(son[j],0,0);
				int cnt=0;
				for(int t=1;t<=n;t++) if(!vis[t]) cnt++;
				if(cnt<ans) ans=cnt;
			}
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			memset(vis,0,sizeof(vis));
			DFS(i,0,0);
			int cnt=0;
			for(int t=1;t<=n;t++) if(!vis[t]) cnt++;
			if(cnt<ans) ans=cnt;
		}
	}
}
int main()
{
	n=read();k=read();ans=n;r=k>>1;
	for(int i=1;i<n;i++)
	{
		int a=read(),b=read();
		add_e(a,b);add_e(b,a);
	}
	Solve();
	printf("%d\n",ans);
	return 0;
}

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

void shortest_path(int);

#define MAX_E 500000
#define MAX_V 100000

typedef long long ll;

const ll INF = 1e10;

struct edge {
  ll from; //何処から
  ll to;   //何処へ
  ll cost; //重み
};

edge es[MAX_E];  //辺

ll l[MAX_V];

ll V;  //頂点数
ll E;  //辺の数
ll r;  //始点

int main() {

  ll s, t, d;

  cin >> V >> E >> r;

  for(int i=0; i<E; ++i) {
    cin >> s >> t >> d;
    es[i].from = s;
    es[i].to = t;
    es[i].cost = d;
  }

  shortest_path(r);

  return 0;
}

void shortest_path(int s) {

  for(int i=0; i<V; ++i) l[i] = INF;

  l[s] = 0;

  while(true) {
    bool update = false;

    for(int i=0; i<E; ++i) {
      edge e = es[i];

      if(l[e.from] != INF && l[e.to] > l[e.from] + e.cost) {
        l[e.to] = l[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) break;
  }

  for(int i=0; i<V; ++i) {
    if(l[i]==INF) cout << "INF" << endl;
    else cout << l[i] << endl;
  }
}



Measured memory_bytes: 15340
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(){

  int n;
  cin>>n;
  int a,b;
  a = n%10;
  b = n/100;
  if(a==b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() { 
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if(a[0] + a[1] == a[2]) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;

int large = 100000000;

int main()
{
  long n;
  long a, imax;
  cin >> n;
  imax = (int)sqrt((double)n);
  long count;
  
  for(long i = imax; i > 0 ;--i){
    if(n%i==0){
      a = n/i;
      count = a + i -2;
      break;
    }
  }
  cout << count << endl;

}

Measured memory_bytes: 256
import java.util.*;

class Main {

    static long INF = 2_000_000_000_000_000_000L;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int[] A = new int[L];
        for (int i=0;i<L;i++) {
            A[i] = sc.nextInt();
        }
        long[] ruiseki_A = new long[L+1];
        for (int i=0;i<L;i++) {
            ruiseki_A[i+1] = ruiseki_A[i]+(A[i]+1)%2;
        }

        long[][] left = new long[L+1][2]; // left[i][0]: zero, left[i][1]: two
        for (int i=0;i<L;i++) {
            left[i+1][0] = left[i][0] + A[i];
            left[i+1][1] = Math.min(left[i][0] + ((A[i] == 0)?2:(A[i]%2)), left[i][1] + ((A[i] == 0)?2:(A[i]%2)));
        }

        long[][] right = new long[L+1][2];
        for (int i=L;i>=1;i--) {
            right[i-1][0] = right[i][0] + A[i-1];
            right[i-1][1] = Math.min(right[i][0] + ((A[i-1] == 0)?2:(A[i-1]%2)), right[i][1] + ((A[i-1] == 0)?2:(A[i-1]%2)));
        }

        TreeMap<Long, Integer> map = new TreeMap<Long, Integer>();
        for (int i=0;i<L+1;i++) {
            long tmp = Math.min(right[i][0], right[i][1]) + ruiseki_A[i];
            if (map.containsKey(tmp)) {
                map.put(tmp, map.get(tmp)+1);
            } else {
                map.put(tmp, 1);
            }
        }
        // System.out.println(map);
        // System.out.println(Arrays.toString(ruiseki_A));

        long ans = INF;
        for (int i=0;i<L+1;i++) {
            long tmp = Math.min(left[i][0], left[i][1]);
            ans = Math.min(ans, tmp + map.firstKey() - ruiseki_A[i]);
            // System.out.println("i, val: "+i+" "+(tmp + map.firstKey() - ruiseki_A[i]));
            // ans = Math.min(ans, tmp + map.firstKey());

            long tmp_key = Math.min(right[i][0], right[i][1]) + ruiseki_A[i];
            if (map.get(tmp_key) > 1) {
                map.put(tmp_key, map.get(tmp_key) - 1);
            } else {
                map.remove(tmp_key);
            }
        }
        System.out.println(ans);
        // System.out.println(Arrays.deepToString(left));
        // System.out.println(Arrays.deepToString(right));
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back

typedef vector<int> vint;
typedef long long ll;


int main() {
    string s;
    cin >> s;

    int n = s.size();
    ostringstream ans1, ans2;
    for(int i = 0;i < n;i++){
        int tmp = i % 2;
        ans1 << tmp;
        ans2 << 1 - tmp;
    }

    int a1, a2;
    a1 = a2 = 0;

    for(int i = 0;i < n;i++){
        if(ans1.str()[i] != s[i]){
            a1++;
        }
        if(ans2.str()[i] != s[i]){
            a2++;
        }
    }

    cout << min(a1,a2) << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

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

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

string s;

int main(){
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '7'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  long long a; long double b; cin >> a >> b;
  long long b2 = b*100+0.5;
  long long ans2 = a*b2;
  ans2 /= 100;
  printf("%lld\n", ans2);
  return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1)/A << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

Measured memory_bytes: 8684
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){

  string N;
  cin>>N;
  cout<<(N[0]==N[2] ? "Yes" : "No");
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    int n;
    cin >> n;

    string s;
    cin >> s;
    int ans=1;

    rep(i,n){
        if(i==n-1) continue;
        if(s[i] == s[i+1]) continue;
        else ans++;
    }

    cout << ans;
    

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;


	if (K <= A)cout << K << endl;
	else if (K <= A + B) cout << A << endl;
	else cout << A - (K - A - B) << endl;

}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=2010;
const int INF=1e8+10;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair

int n,ans,cnt,lst,l,r,pos;
char a[maxn],b[maxn];
char x[maxn];
pii q[maxn];
vector<pii> v;

int mod(int p)
{
	while(p<=0) p+=n;
	while(p>n) p-=n;
	return p; 
}

int main()
{
	scanf("%s",a+1);
	scanf("%s",b+1);
	n=strlen(a+1);
	
	lst=n;
	while(lst>=0 && b[lst]=='0') lst--;
	if (lst<0) lst=-INF; else lst-=n;
	for(int i=1;i<=n;i++)
	{
		if (b[i]=='1') lst=i;
		q[i].x=lst-i;
	}
	
	lst=1;
	while(lst<=n && b[lst]=='0') lst++;
	if (lst>n) lst=INF; else lst+=n;
	for(int i=n;i>=1;i--)
	{
		if (b[i]=='1') lst=i;
		q[i].y=lst-i;
	}
	
	ans=INF;
	for(int mv=-n;mv<=n;mv++)
	{
		cnt=0;
		for(int i=1;i<=n;i++)
		{
			x[i]=a[mod(i-mv)];
			if (x[i]!=b[i]) cnt++;
		}
		if (!cnt)
		{
			ans=min(ans,abs(mv));
			continue;
		}
		
		v.clear();
		for(int i=1;i<=n;i++) if (x[i]!=b[i])
			v.push_back(q[mod(i-mv)]);
		sort(v.begin(),v.end());
		
		r=max(mv,0);
		pos=0;
		for(l=-n;l<=min(0,mv);l++)
		{
			while(pos<v.size() && v[pos].x<l) r=max(r,v[pos].y),pos++;
			ans=min(ans,cnt+(r-l)*2-abs(mv));
		}
	}
	
	if (ans==INF) ans=-1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
n, m, x = map(int, input().split())
c = []
a = []
for _ in range(n):
    s = input().split()
    c.append(int(s[0]))
    a.append(list(map(int, s[1:])))

# print(c)
# print(*a, sep='\n')

ans = sum(c) + 1
for bit in range(1 << n):
    cand = 0
    b = [0] * m
    for i in range(n):
        if (bit >> i) & 1:
            cand += c[i]
            for j in range(m):
                b[j] += a[i][j]

    is_possible = True
    for j in range(m):
        if b[j] < x:
            is_possible = False
            break

    if is_possible:
        ans = min(ans, cand)

if ans == sum(c) + 1:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	string s;
	cin >> s;
	if(s[0]=='S'){
		cout << "Cloudy" << endl;
	}else if(s[0]=='C'){
		cout << "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Measured memory_bytes: 31092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf (ll)1e18

ll dp[405][405], c[405], cum[405];

ll sol(ll a, ll b)
{
  if (dp[a][b] != inf)
    return dp[a][b];

  if (a == b)
    return 0;

  for (ll i = a; i < b; i++)
  {
    dp[a][b] = min(dp[a][b], cum[b] - cum[a - 1] + sol(a, i) + sol(i + 1, b));
  }

  return dp[a][b];
}

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

  for (ll i = 0; i < 405; i++)
    for (ll j = 0; j < 405; j++)
      dp[i][j] = inf;

  ll n;
  cin >> n;

  cum[0] = 0;
  for (ll i = 1; i <= n; i++)
  {
    cin >> c[i];
    cum[i] = cum[i - 1] + c[i];
  }

  cout << sol(1, n) << "\n";

  return 0;
}

Measured memory_bytes: 1536
lst = []
N,M = gets.split(" ").map{|i|i.to_i}
N.times do |i|
    array = gets.split(" ").map{|i|i.to_i}
lst[i] = array[1..array.length]
end
r = 0
lst[0].each do |i|
    c = 0
    (N-1).times do |j|
        if lst[j+1].include?(i) then
            c+=1
        end
    end
    if c == (N-1) then
        r+=1
    end
end

puts r


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll s; cin >> s;
  ll y2 = min(s/(ll)1e9+1, (ll)1e9);
  ll y1 = (ll)1e9*y2-s;
  cout << 0 << ' ' << 0 << ' '
       << (ll)1e9 << ' ' << y1 << ' '
       << 1 << ' ' << y2 << endk;
  return 0;
}


Measured memory_bytes: 3612
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
s_cnt = Counter(s)
s_cnt_common = s_cnt.most_common()
max_cnt = s_cnt_common[0][1]
ans = []
for i in range(len(s_cnt_common)):
    if s_cnt_common[i][1] == max_cnt:
        ans.append(s_cnt_common[i][0])
ans.sort()
print(*ans)


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

using namespace std;

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}



Measured memory_bytes: 2660
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k,s = LI()
    t = s + 1
    if s == 10**9:
        t = 1
    a = [s] * k + [t] * (n-k)

    return JA(a, " ")


print(main())





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

using namespace std;

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



	

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

    int m;cin>>m;
    ll sum = 0;

    for(int i=1; i<=m; i++)
    {
    	for(int j=1; j<=m; j++)
    	{
    		for(int k=1; k<=m; k++)
    		{
    			sum += gcd(i,gcd(j,k));
    			

    		}    
    	}
    }

    cout<<sum;

	return 0;
	
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void)


{
	int i, a, b, c, count;
	count = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a;i <= b;i++)
	{
		if (c%i == 0)
		{
			count = count + 1;
		}
	}
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 596
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let m: i32 = read();
    let mut jobs: HashMap<i32, Vec<i32>> = HashMap::new();
    for _ in 0..n {
        let day: i32 = read();
        let reward: i32 = read();
        jobs.entry(day).or_insert(vec![]).push(reward);
    }
    let mut heap: BinaryHeap<i32> = BinaryHeap::new();
    let mut sum = 0;
    for i in (0..m).rev() {
        for v in jobs.entry(m - i).or_insert(vec![]) {
            heap.push(*v);
        }
        match heap.pop() {
            Some(i) => {
                sum += i;
            },
            None => {}
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 18068
package main

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

func main() {
	N := nextInt()
	A := make([]int, N+1)
	B := make([]int, N+1)
	C := make([]int, N+1)

	for i := 1; i <= N; i++ {
		A[i] = nextInt()
	}
	for i := 1; i <= N; i++ {
		B[i] = nextInt()
	}
	for i := 1; i <= N; i++ {
		C[i] = nextInt()
	}

	c := 0

	for i := 1; i <= N; i++ {
		c += B[A[i]] // A[i]を食べた

		if i <= N-1 {
			if A[i+1] == A[i]+1 {
				c += C[A[i]]
			}
		}
	}

	fmt.Println(c)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

int main() {
  
  int A, B, C, X; cin >> A >> B >> C >> X; int ans = 0;
  
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if ((i * 500 + j * 100 + k * 50) == X) ans++;
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>

// lib/to_signed.hpp
#ifndef TO_SIGNED_HPP
#define TO_SIGNED_HPP


/*
usage:

std::uint_fast64_t i;
decltype(tools::to_signed(i)) // => std::int_fast64_t
*/

namespace tools {
  template <typename T>
  constexpr typename std::make_signed<T>::type to_signed(const T x) noexcept {
    return x;
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

class city {
public:
  i64 prefecture;
  i64 year;
  i64 order_of_foundation;
  city(const i64 prefecture, const i64 year) :
    prefecture(prefecture), year(year) {
  }
  std::string id() const {
    std::stringstream ss;
    ss << std::setfill('0');
    ss << std::setw(6) << this->prefecture;
    ss << std::setw(6) << this->order_of_foundation;
    return ss.str();
  }
};

int main() {
  i64 N, M;
  std::cin >> N >> M;
  std::vector<std::shared_ptr<city>> cities;
  cities.reserve(M);
  for (i64 i = 1; i <= M; ++i) {
    i64 P_i, Y_i;
    std::cin >> P_i >> Y_i;
    cities.push_back(std::make_shared<city>(P_i, Y_i));
  }

  std::vector<std::vector<std::shared_ptr<city>>> prefectures(N);
  for (std::shared_ptr<city>& city : cities) {
    prefectures[city->prefecture - 1].push_back(city);
  }

  for (std::vector<std::shared_ptr<city>>& prefecture : prefectures) {
    std::sort(prefecture.begin(), prefecture.end(), [](const std::shared_ptr<city>& x, const std::shared_ptr<city>& y) {
      return x->year < y->year;
    });
    for (i64 i = 1; i <= tools::to_signed(prefecture.size()); ++i) {
      prefecture[i - 1]->order_of_foundation = i;
    }
  }

  for (const std::shared_ptr<city>& city : cities) {
    std::cout << city->id() << std::endl;
  }
  return 0;
}

Measured memory_bytes: 13184
#include <iostream>

using namespace std;
bool is[ 100100+9 ];
string a, b;
int main(){

    for(int i=1;i<=316;i++) is[i*i]=1;
    cin >> a >> b;
    a += b;
    if(is[atoi(a.c_str())]) cout<< "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 384
h, w, k = map(int, input().split())
c = []
for _ in range(h):
    c.append(input())
ans = 0
for i in range(2**h):
    for j in range(2**w):
        tmp = 0
        for m in range(h):
            for n in range(w):
                if (i >> m) & 1:
                    continue
                if (j >> n) & 1:
                    continue
                if c[m][n] == "#":
                    tmp += 1
        if tmp == k:
            ans += 1
print(ans)

Measured memory_bytes: 9196
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n, sum = 0, mx = -1;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    mx = max(mx, x);
    sum += x;
  }
  sum -= mx;
  if (mx >= sum) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 256
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n, x[100005], k;
bool dp[100005];
int main()
{
	cin >> n >> k;

	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int j = 0; j <= k; j++)
		for (int i = 0; i < n; i++)
		{
			if (j >= x[i] && !dp[j - x[i]])
				dp[j] = 1;
		}
	if (dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;
	return 0;
}

/*

*/

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;




int main(void){
    int n;
    cin>>n;
    int ans = 0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        while(a%2==0)a/=2,ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
string rotate(string s){
    int N = s.size();
    string ns;
    ns = "";
    for(int i = 0; i < N - 1; i++){
        ns.push_back(s.at(i + 1));
    }
    ns.push_back(s.at(0));
    return ns;
} 
void solve(){
    string s, t;
    cin >> s, cin >> t;
    int n = s.size();
    bool check = false;
    for(int i = 0; i < n; i++){
        if(s == t){
            check = true;
            break;
        }
        s = rotate(s);
    }
    if(check)
    cout << "Yes" << endl;
    else 
    cout << "No" << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = input().split()
a = [int(m) for m in a]
dic = {}
dic2 = {}
for i in range(n + 1):
    dic[a[i]] = 0
    dic2[a[i]] = []
f = 0
s = 0
for i in range(n + 1):
    dic[a[i]] += 1
    dic2[a[i]].append(i)
    if dic[a[i]] == 2:
        f = dic2[a[i]][0]
        s = i
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
mod = 10**9+7 #出力の制限
N = n + 1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
 
for k in range(1,n + 2):
    if k == 1:
        print(n)
    else:
        if f + n - s +1>= k:
            if (cmb(n + 1, k, mod) - cmb(f + n - s, k-1, mod)) >= 0:
                print(cmb(n + 1, k, mod) - cmb(f + n - s, k-1, mod))
            else:
                print(cmb(n + 1, k, mod) - cmb(f + n - s, k-1, mod) + mod)
        elif f+n-s+1<k:
            print(cmb(n + 1, k, mod))

Measured memory_bytes: 50948
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

typedef unsigned long long ull;
unsigned int BASE;

void init_RH() {
  srand(time(NULL));
  BASE = rand() % RAND_MAX + 129;
}

struct RollingHash {
  const ull MASK30 = (1ULL << 30) - 1;
  const ull MASK31 = (1ULL << 31) - 1;
  const ull MODrh = (1ULL << 61) - 1;
  const ull POSITIVIZER = MODrh * ((1ULL << 3) - 1);
  unsigned int Base;
  vector<ull> hash;
  vector<ull> powMemo;

  RollingHash(string s, unsigned int BASE) {
    Base = BASE;
    powMemo = vector<ull>(sz(s) + 1);
    powMemo[0] = 1;
    repp(i, 1, sz(powMemo) - 1) {
      powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }
    hash = vector<ull>(sz(s) + 1);
    rep(i, sz(s)) {
      hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }
  }

  ull Slice(int begin, int length) {
    return CalcMod(hash[begin + length] + POSITIVIZER -
                   Mul(hash[begin], powMemo[length]));
  }

  ull Mul(ull l, ull r) {
    ull lu = l >> 31;
    ull ld = l & MASK31;
    ull ru = r >> 31;
    ull rd = r & MASK31;
    ull middleBit = ld * ru + lu * rd;
    return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) +
           (middleBit >> 30);
  }

  ull CalcMod(ull val) {
    val = (val & MODrh) + (val >> 61);
    if (val > MODrh)
      val -= MODrh;
    return val;
  }
};

int main() {
  init_RH();
  int N;
  cin >> N;
  string S;
  cin >> S;

  RollingHash R(S, BASE);

  int ans = 0;
  rep(i, N) {
    repp(j, i, N - 1) {
      while ((ans < j - i) && (j + ans < N) &&
             R.Slice(i, ans + 1) == R.Slice(j, ans + 1))
        ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=2e5+10;

struct P {
    int id;
    LL c0,c1,w;
} p[N];

bool operator<( P a, P b ) {
    return a.c1*b.c0 < b.c1*a.c0;
}

bool operator>( P a, P b ) {
    return b<a;
}

bool operator!=( P a, P b ) {
    return tie(a.id,a.c0,a.c1)!=tie(b.id,b.c0,b.c1);
}

P operator+( P a, P b ) {
    return {a.id,a.c0+b.c0,a.c1+b.c1,a.w+b.w+a.c1*b.c0};
}

int n,fa[N],g[N],v[N];

int f( int x ) {
    return x==g[x]?x:g[x]=f(g[x]);
}

void main() {
    R(n);
    REP1(i,2,n) R(fa[i]);
    REP1(i,1,n) R(v[i]);
    REP1(i,1,n) p[i]=(v[i]==0 ? P{i,1,0,0} : P{i,0,1,0});
    MinHeap<P> h;
    REP1(i,1,n) h.push(p[i]);
    REP1(i,1,n) g[i]=i;
    while ( !h.empty() ) {
        auto x=h.top(); h.pop();
        if ( x!=p[x.id] ) continue;
        int i=x.id,j=f(fa[i]);
        dump(x.id,x.c0,x.c1,x.w,i,j);
        p[j]=p[j]+p[i];
        if ( j!=0 ) h.push(p[j]);
        g[i]=j;
    }
    LL ans=p[0].w;
    W(ans);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 18284
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
//　35min
int main(void){
  int n;
  char s[100001][11];
  long int sum = 0;
  long int m = 0, a = 0, r = 0, c = 0, h = 0;

  scanf("%d", &n);
  
  for(int i = 0; i < n; i++){
    scanf("%s", s[i]);
  }
  
  for(int i = 0; i < n; i++){    
    //それぞれの文字から始まる人数を数える
    if(s[i][0] == 'M'){
      m++;
    }else if(s[i][0] == 'A'){
      a++;
    }else if(s[i][0] == 'R'){
      r++;
    }else if(s[i][0] == 'C'){
      c++;
    }else if(s[i][0] == 'H'){
      h++;
    }
  }

  //MAR
  sum += m * a * r;

  //MAC
  sum += m * a * c;

  //MAH
  sum += m * a * h;

  //MRC
  sum += m * r * c;

  //MRH
  sum += m * r * h;

  //MCH
  sum += m * c * h;

  //ARC
  sum += a * r * c;

  //ARH
  sum += a * r * h;

  //ACH
  sum += a * c * h;

  //RCH
  sum += r * c * h;


  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
    
    int i,j,H,W;
    
    while(1){
 
        scanf("%d %d", &H, &W);
        
        if( H == 0 && W == 0){
              break;
        }
        
        else{
         
    for(i = 1; i <= H; i++){
        if( i == 1 || i == H){
            for( j = 1; j <=W ; j++){
                printf("#");
            }
        }
        
        else{
            for( j = 1; j <= W; j++){
                if( j == 1 || j == W){
                    printf("#");
                }
                
                else{
                    printf(".");
                }
            }
        }
        
        printf("\n");
    }       
     printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

public class Main{
	
	

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

	int R,G,B,N;
    R=sc.nextInt();
    G=sc.nextInt();
    B=sc.nextInt();
    N=sc.nextInt();
    int count=0;
    for(int a=0;a<=N;a++) {
    	for(int b=0;b<=N-a*R;b++) {
    		int c=N-a*R-b*G;
    		if(c<0) {
    			break;
    		}else if(c%B==0) {
    			count++;
    		}
    		
    	}
    }
    System.out.println(count);
	

		
	}
	

	
}
		

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=3001; //check the limits, dummy
ll a[N][N];
int n, m;
ll INF=1e18;
ll mem[3001][3001][4];
ll dp(int x, int y, int nm){
	if(nm<0)
		return -INF;
	if(x>=n)
		return -INF;
	if(y>=m)
		return -INF;
	if(x==n-1 && y==m-1){
		return (nm>0)*a[x][y];
	}
	if(mem[x][y][nm]!=-1){
		return mem[x][y][nm];
	}
	ll res=0;
	res=max(res, dp(x, y+1, nm));
	res=max(res, dp(x, y+1, nm-1)+a[x][y]);
	res=max(res, dp(x+1, y, 3)+(nm>0)*a[x][y]);
	mem[x][y][nm]=res;
	return res;
}
int main(){
	int k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0; i<k; ++i){
		int x, y, c;
		scanf("%d%d%d",&x,&y,&c);
		a[x-1][y-1]=c;
	}
	memset(mem, -1, sizeof mem);
	ll ans=dp(0, 0, 3);
	cout<<ans<<endl;
}

Measured memory_bytes: 355896
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rrep(i, 1, n + 1) {
    tmp = floor((double)i * 1.08);
    if (tmp == n) {
      Cout(i);
      return 0;
    }
  }
  Cout(":(");
  return 0;
}

Measured memory_bytes: 256