akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    s = input()
    s_num = []
    r = 0
    g = 0
    b = 0
    for t in range(n):
        if s[t] == "R":
            r += 1
            s_num.append(0)
        elif s[t] == "G":
            g += 1
            s_num.append(1)
        else:
            b += 1
            s_num.append(2)
    res = r * g * b
    for i in range(n - 2):
        m = (n - i - 1)//2
        for dif in range(1, m + 1):
            x = s_num[i]
            y = s_num[i + dif]
            z = s_num[i + 2 * dif]
            if (x - y) * (y - z) * (z - x) != 0:
                res -= 1
    print(res)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
import java.util.Scanner;

public class Main {

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

		long N = sc.nextLong();

		long last = 0;

		long i = 1;
		long sqrt_N = (long)Math.sqrt(N);
		while(i <= sqrt_N){
			if(N % i == 0){
				last = N / i;
			}
			i++;
		}

		System.out.println(String.valueOf(last).length());

		sc.close();
	}

}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> k(Q);
    rep(i, Q) cin >> k[i];

    rep(i, Q) {
        ll ans = 0;
        ll DMcnt = 0;
        int Dcnt = 0, Mcnt = 0;
        rep(j, 0, k[i]) {
            if (S[j] == 'D') {
                Dcnt++;
            }
            else if (S[j] == 'M') {
                DMcnt += Dcnt;
                Mcnt++;
            }
            else if (S[j] == 'C') {
                ans += DMcnt;
            }
        }
        rep(j, k[i], N) {
            if (S[j - k[i]] == 'D') {
                Dcnt--;
                DMcnt -= Mcnt;
            }
            else if (S[j - k[i]] == 'M') {
                Mcnt--;
            }
            if (S[j] == 'D') {
                Dcnt++;
            }
            else if (S[j] == 'M') {
                DMcnt += Dcnt;
                Mcnt++;
            }
            else if (S[j] == 'C') {
                ans += DMcnt;
            }
        }

        write(ans);
    }
}

Measured memory_bytes: 1948
#include <stdio.h>

int main(void){
	int W , H , i , j , ph , pw , check[100][100] , flag;
	char sq[100][100];
	while(1){
		flag = 0;
		ph = pw = 0;
		scanf("%d %d" , &H , &W);
		if(W==0 && H==0) break;
		for(i=0;i<100;i++){
			for(j=0;j<100;j++){
				check[i][j] = 0;
				sq[i][j] = '.';
			}
		}
		for(i=0;i<H;i++){
			scanf("%*c");
			for(j=0;j<W;j++){
				scanf("%c" , &sq[i][j]);
			}
		}
		while(1){
			if(check[ph][pw] == 1){
				flag = 1;
				break;
			}else{
				check[ph][pw] = 1;
			}
			if(sq[ph][pw] == '>'){
				pw++;
			}else if(sq[ph][pw] == '<'){
				pw--;
			}else if(sq[ph][pw] == 'v'){
				ph++;
			}else if(sq[ph][pw] == '^'){
				ph--;
			}else{
				break;
			}
		}
		if(flag) printf("LOOP\n");
		else printf("%d %d\n" , pw , ph);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

void func(vector<string> v,int a){
  int k=1,temp=1;
  for(int i=1;i<a;i++){
    if(v[i]==v[i-1]){k++;temp=max(temp,k);}
    else{k=1;}
  }
  k=1;
  if(temp==1){for(int i=0;i<a;i++){cout<<v[i]<<endl;}}
  else{for(int i=1;i<a;i++){
  	if(v[i]==v[i-1]){k++;if(k==temp){cout<<v[i]<<endl;}}
    else{k=1;}
  }}
}
int main(){
  int a;
  cin>>a;
  vector<string> v(a);
  for(int i=0;i<a;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  func(v,a);
 
}


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

int main() {
    int h, w;
    cin >> h >> w;

    int arr[h + 2][w + 2];

    // init
    for (int i = 0; i < h + 2; i++) {
        for (int j = 0; j < w + 2; j++) {
            arr[i][j] = 0;
        }
    }

    // count
    for (int i = 1; i < h + 1; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w + 1; j++) {
            if (s[j] == '#') {
                arr[i - 1][j] += 1;
                arr[i - 1][j + 1] += 1;
                arr[i - 1][j + 2] += 1;
                arr[i][j] += 1;
                arr[i][j + 1] = -1000;
                arr[i][j + 2] += 1;
                arr[i + 1][j] += 1;
                arr[i + 1][j + 1] += 1;
                arr[i + 1][j + 2] += 1;
            }
        }
    }

    // cout
    for (int i = 1; i < h + 1; i++) {
        for (int j = 1; j < w + 1; j++) {
            if (arr[i][j] >= 0) {
                cout << arr[i][j];
            } else {
                cout << "#";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int n, m;
	int sum = 1;
	int count = 0;
	int i, j, l, o;
	int work;
	char str[20];
	
	scanf("%s", str);
	
	for(i = 0; i < strlen(str); i++) {
		if(str[i] == 'x') {
			count++;
		}
	}
	
	if(count >= 8) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}
	
	return 0;
}

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

typedef long long ll;

typedef pair<ll, int> p;

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

    int N, M;
    cin >> N >> M;

    vector<int> c(N);

    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        c[a]++;
        c[b]++;
    }

    for(int i = 0; i < N; i++) {
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;

  return 0;
}

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

class Edge
{
public:
	int d,i,o;
	Edge(int d, int i, int o)
	:d(d),i(i),o(o)
	{}
};

class State
{
public:
	int n,t;
	State(int n, int t)
	:n(n),t(t)
	{}
	
	bool operator<(const State& s) const
	{
		return t>s.t;
	}
};

typedef vector<Edge> Edges;
typedef pair<vector<int>, vector<int> > Train;

int input()
{
	string s;
	cin >> s;
	
	return ((s[0]-'0')*10+(s[1]-'0'))*60+((s[3]-'0')*10+(s[4]-'0'));
}

int beg[1000], end[1000];

int dijk(int S, int st, int lim, vector<Edges>& eg, bool f)
{
	bool v[1000]={0};
	priority_queue<State> q;
	q.push(State(S,st));
	
	while(!q.empty())
	{
		State s=q.top(); q.pop();
		if(s.t>lim) break;
		
		if(v[s.n]) continue;
		v[s.n]=1;
		
		if(f) beg[s.n]=s.t;
		else  end[s.n]=-s.t+24*60;
		
		for(int i=0; i<eg[s.n].size(); i++)
		{
			Edge e=eg[s.n][i];
			if(v[e.d]) continue;
			if(s.t > e.i) continue;
			
			q.push(State(e.d, e.o));
		}
	}
	
	return -1;
}

int main()
{
	int S,T;
	while(cin >> S >> T, (S||T))
	{
		int src,dst,st,dt;
		cin >> src; st=input();
		cin >> dst; dt=input();
		
		src--; dst--;
		
		vector<Edges> eg(1000),reg(1000);
		vector<Train> trains(100);
		
		for(int i=0; i<T; i++)
		{
			int N;
			cin >> N;
			vector<int> p,t;
			for(int j=0; j<N; j++)
			{
				int a,b;
				cin >> a; b=input();
				a--;
				
				p.push_back(a);
				t.push_back(b);
			}
			trains[i]=make_pair(p,t);
			
			for(int j=0; j<N-1; j++)
			{
				int s=p[j], d=p[j+1];
				int a=t[j], b=t[j+1];
				eg[s].push_back(Edge(d,a,b));
				reg[d].push_back(Edge(s,24*60-b, 24*60-a));
			}
		}
		
		for(int i=0; i<S; i++)
		{
			beg[i]=9999;
			end[i]=-1;
		}
		
		dijk(src,st,dt,eg,1);
	    dijk(dst,24*60-dt,24*60-st,reg,0);
		
		int ret=-1;
		if(src==dst&&st<=dt) ret=0;
		
		for(int i=0; i<T; i++)
		{
			int lo=9999,hi=-1;
			for(int j=0; j<trains[i].first.size(); j++)
			{
				int p=trains[i].first[j], t=trains[i].second[j];
				if(beg[p] <= t) lo=min(j,lo);
				if(end[p] >= t) hi=max(j,hi);
			}
			
			if(lo==9999||hi==-1) continue;
			ret=max(ret, trains[i].second[hi]-trains[i].second[lo]);
		}
		if(ret==-1) cout << "impossible" << endl;
		else cout << ret << endl;

	}
}

Measured memory_bytes: 5292
#include <stdio.h>

int prime(int x){
	int i;
	if(x < 2)return 0;
	else if(x == 2) return 1;
	if(x%2==0) return 0;
	
	for(i = 3; i*i <= x; i+=2){
		if(x%i == 0) return 0;
	}
	return 1;
}

int main(void)
{
	int n, i, k=0;
	scanf("%d", &n);
	int a[n];
	
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(prime(a[i]) == 1)k++;
	}
	
	printf("%d\n", k);
	
	return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>
#include <string.h>
#define rep(i,l,n) for(i=l;i<n;i++)
 
int main(void){
    char b[201],a[201];
    int m,i,h,len,j;
     
    while(1){
        scanf("%s",b);
        if(b[0]=='-') break;
        len=strlen(b);
         
        scanf("%d",&m);
         
        rep(i,0,m){
            scanf("%d",&h);
            rep(j,0,len-h) a[j]=b[j+h];
            rep(j,len-h,len) a[j]=b[j-len+h];
            rep(j,0,len) b[j]=a[j];
        }
        rep(i,0,len) printf("%c",b[i]);
        printf("\n");
    }
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const lb PI=3.14159265359;

int main(){

  string s;cin>>s;

  ll ans=0;bool e=false;
  ll count=0;
  rep(i,0,s.size()){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')e=true;
    else e=false;

    if(e)count++;
    else {
      chmax(ans,count);
      count=0;
    }

  }
  if(e)chmax(ans,count);

  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W, M;
  cin>>H>>W>>M;
  map<int, int> amap, bmap;
  map<pair<int, int>, int> cmap;
  int x, y;
  for(int i=0;i<M;++i) {
    cin>>x>>y;
    x--;
    y--;
    amap[x]++;
    bmap[y]++;
    cmap[mp(x, y)]++;
  }
  vector<int> xarr, yarr;
  int xmax=0, ymax=0;
  for(int i=0;i<H;++i) xmax = max(xmax, amap[i]);
  for(int i=0;i<W;++i) ymax = max(ymax, bmap[i]);
  for(int i=0;i<H;++i) {
    if(amap[i]==xmax) xarr.push_back(i);
  }
  for(int i=0;i<W;++i) {
    if(bmap[i]==ymax) yarr.push_back(i);
  }
  bool aru = false;
  for(int i=0;i<xarr.size();++i) {
    for(int j=0;j<yarr.size();++j) {
      if(cmap[mp(xarr[i], yarr[j])]==0) {
        aru = true;
        break;
      }
    }
  }
  if(aru) cout<<xmax+ymax<<endl;
  else cout<<xmax+ymax-1<<endl;
}



Measured memory_bytes: 71300
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define FASTIO ios_base::sync_with_stdio(NULL); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define MOD 1000000007

using namespace std;

void init(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin) ;
  freopen("output.txt", "w", stdout) ;
  #endif
}

// code from below

void solve(){
	int n,m;
    cin>>n>>m;
    char arr[n][m];
    FOR(i,n)
        FOR(j,m)
            cin>>arr[i][j];
    int dp[n][m];
    memset(dp,0,sizeof(dp));

    // dp[i][j] denotes no. of ways to go from i,j to n,m

    // fill the last row with 1 and last col with 1
    for(int i=m-1;i>=0 and arr[n-1][i]!='#';i--)
        dp[n-1][i]=1;
    for(int i=n-1;i>=0 and arr[i][m-1]!='#';i--)
        dp[i][m-1]=1;
    // fill the remaining dp array
    for(int i=n-2;i>=0;i--){
        for(int j=m-2;j>=0;j--){
            if(arr[i][j]!='#'){
                dp[i][j]=((ll)dp[i+1][j]+(ll)dp[i][j+1])%MOD;
            }
        }
    }
    // for(int i=0;i<n;i++,cout<<endl)
    //     for(int j=0;j<m;j++)
    //         cout<<dp[i][j]<<" ";
    
    cout<<dp[0][0]<<endl;
}

int main(){
    int t=1;
    // cin>>t;
    // cin.ignore(numeric_limits<streamsize>::max(),'\n'); 
    while(t--)
        solve();
}


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

int main()
{
    int h,w,n;
    cin>>h>>w>>n;
    if(w>h)
        swap(h,w);
    int temp=h;
    int count_it=0;
    while(temp<n)
    {
        temp+=h;
        count_it++;
    }
    count_it++;
    cout<<count_it<<endl;
    return 0;
}


Measured memory_bytes: 256
def dist(x1, x2):
    d2 = (x1[0] - x2[0]) ** 2 + (x1[1] - x2[1]) ** 2
    return d2 ** 0.5

n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n - 1):
    xi = x[i]
    for j in range(i + 1, n):
        d += dist(xi, x[j])
print(2 * d / n)


Measured memory_bytes: 3060
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ans = 0;
    for i in 1..n+1 {
        if i.to_string().len() % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

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

int main(){
    int n, k; scanf("%d %d", &n, &k);
    ll ans = 0;
    vector<ll> data(k + 1, 0);

    for(int g = k; g >= 1; g--){
        ll cnt = modpow(k/g, n);
        for(int i = g; i <= k; i += g){
            (cnt += -data[i] + MOD) %= MOD;
        }
        data[g] = cnt;
        (ans += (cnt * g)%MOD) %= MOD;
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 4072
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

typedef long long ll;

int calc(int n) {
    int cnt = 0;
    while(n >= 10) {
        ll next = -1, r = 10;
        while (r < n) {
            next = max(next, ((ll)n/r) * (n%r));
            r *= 10;
        }
        n = next;
        cnt++;
    }
    return cnt;
}

int main() {
    int q,n;
    cin>>q;
    for (int i=0; i<q; ++i) {
        cin>>n;
        cout<<calc(n)<<endl;
    }
}

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

int main() {
  int N, K, r;
  cin >> N >> K;
  r = 1;
  
  for (int i = 0; i < N; i ++) {
     
    if (r * 2 < r + K) {
      r *= 2;
    }
    
    else {
      r += K;
    }
  }
  
  cout << r;
}

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

int a[100005],b[100005],o[100005],oa[100005],ob[100005];
bitset<100005> u;

int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i]>>b[i];
    long long ans=0;
    for(int i=1;i<=n;++i)oa[i]=i,ob[i]=i;
    sort(oa+1,oa+1+n,[&](const int &i,const int &j){ return a[i]+b[i]>a[j]+b[j]; });
    sort(ob+1,ob+1+n,[&](const int &i,const int &j){ return a[i]+b[i]>a[j]+b[j]; });
    long long aa=0,bb=0;
    int pa=1,pb=1;
    for(int i=1;i<=n;++i){
        if(i&1){
            while(u[oa[pa]])++pa;
            aa+=a[oa[pa]];
            u[oa[pa]]=1;
        }
        else{
            while(u[ob[pb]])++pb;
            bb+=b[ob[pb]];
            u[ob[pb]]=1;
        }
    }
    cout<<aa-bb<<endl;
}


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


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll a[n+5];
	for(ll i=0;i<=n;i++)
	{
		cin>>a[i];
	}	

	ll b[n];
	for(ll i=0;i<n;i++)
	{
		cin>>b[i];
	}

	ll ans=0;
	for(ll i=n-1;i>=0;i--)
	{
		ll Ans=min(a[i+1],b[i]);
		b[i]-=Ans;
		ans+=Ans;
		Ans=min(b[i],a[i]);
		a[i]-=Ans;
		ans+=Ans;
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;

    string s;
    cin >> s;

    int rc=0;
    vector<char> s2(s.begin(),s.end());
    rc = count(s2.begin(),s2.end(),'R');
    if(rc>n/2)
      cout << "Yes\n";
    else
      cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s; cin >> s;
  int ans = 700;
  if (s[0] == 'o') ans += 100;
  if (s[1] == 'o') ans += 100;
  if (s[2] == 'o') ans += 100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

struct Edge {
    int to, cost;
};
vector< vector<Edge> > G;

int dist[100010];

void dfs(int p, int prev) {
    rep(i,0,G[p].size()) {
        int t = G[p][i].to;
        if(t == prev) continue;
        dfs(t, p);
        dist[p] = max(dist[p], dist[t] + G[p][i].cost);
    }
}

int dfs2(int idx, int d_par, int par) {
    vector<pii> d_child;
    d_child.emplace_back(0, -1);
    rep(i,0,G[idx].size()) {
        Edge e = G[idx][i];
        if(e.to == par) d_child.emplace_back(d_par + e.cost, e.to);
        else d_child.emplace_back(dist[e.to] + e.cost, e.to);
    }
    sort(d_child.rbegin(), d_child.rend());
    int ret = d_child[0].first + d_child[1].first;
    rep(i,0,G[idx].size()) {
        Edge e = G[idx][i];
        if(e.to == par) continue;
        ret = max(ret, dfs2(e.to, d_child[d_child[0].second == e.to].first, idx));
    }
    return ret;
}

signed main() {
    int n; cin >> n;
    memset(dist, 0, sizeof(dist));
    G.resize(n);
    rep(i,0,n-1) {
        int s, t, w; cin >> s >> t >> w;
        G[s].push_back(Edge{t, w});
        G[t].push_back(Edge{s, w});
    }
    dfs(0, -1);
    cout << dfs2(0, 0, -1) << endl;
    return 0;
}

Measured memory_bytes: 32444
#include<stdio.h>
int main(){
    int d,i,x,y,s,sum=0;
    while(scanf("%d",&d) != EOF){
        for(i=d;i<600;i+=d){
            y = i*i;
            s = y*d;
            sum +=s;
        }
        printf("%d\n",sum);
        sum = 0;
    }
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

#define FOR(i,n) for (int (i) = 0; (i) < (n); i++)
typedef long long ll;

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

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

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    ll L = lcm(C,D);
    
    ll AC = A / C;
    ll BC = B / C;
    if (A % C == 0) AC--;
    ll AD = A / D;
    ll BD = B / D;
    if (A % D == 0) AD--;
    ll AL = A / L;
    ll BL = B / L;
    if (A % L == 0) AL--;

    cout << (B - A + 1) - ((BC - AC) + (BD - AD) - (BL - AL)) << "\n"; 
    
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int i, x[N], y[N], t[N], n;

int main() {
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) scanf("%d %d %d", t + i, x + i, y + i);

  for(i = 1; i <= n; ++i) //printf("%d %d %d\n", abs(x[i] - x[i - 1]), abs(y[i] - y[i - 1]), t[i] - t[i - 1]);
    if(abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]) > t[i] - t[i - 1] || (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 != (t[i] - t[i - 1]) % 2) return 0 * puts("No");

  puts("Yes");

  return 0;
}

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

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

  string s;
  cin >> s;

  int score =0;
  for(int i=0; i < n-1; i++){
    if(s.at(i) == s.at(i+1)){
      score++;
    }
  }

  cout << min(score+k*2 , n-1);
}

Measured memory_bytes: 512
// Author : Epsilon573
// If it works, don't touch it.

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

vector<ll> adj[maxn];
vector<ll> par(maxn,0);
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,m;
    cin >> n >> m;

    for(ll i=0,x,y ; i<m  ; ++i)
    {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    
    queue<ll> q;
    q.push(1);
    par[1] = 1;
    
    while(!q.empty())
    {
        ll z = q.front();
        q.pop();

        for(auto x : adj[z])
        {
            if(!par[x])
            {
                q.push(x);
                par[x] = z;
            }
        }
    }

    for(ll i=2 ; i<=n ; ++i)
    {
        if(!par[i])
        {
            cout << "No" ; return 0;
        }
    }
    
    cout << "Yes" << endl;

    for(ll i=2 ; i<=n ; ++i)
    {
        cout << par[i] << endl;
    }
    return 0;
}  

Measured memory_bytes: 12904
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 0, Max = -1, Min = 3e9+1;
  string t;
  bool ok=true; 
  cin >> n >> h;
  VL a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  sort(ALL(a));
  sort(RALL(b));
  Max = a[n-1];


  rep(i,n){
    if(Max < b[i]){
      h -= b[i];
      ans++;
    }
    if(h<=0){
      pri(ans);
      return 0; 
    }
  }
  ans += ceil((double)h/(double)Max);
  pri(ans);
  return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){ return powm(a,m-2,m); }
int main()
{
fastIO
ll n,m,i,j,k,y,z,t,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
ld aa,bb;
cin>>aa>>bb;
ld fa=aa*bb;
p=fa;
cout<<p;

}


Measured memory_bytes: 3784
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;


#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

class Point {
 public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x+p.x, y+p.y); }
  Point operator - (Point p) { return Point(x-p.x, y-p.y); }
  Point operator * (double a) { return Point(a*x, a*y); }
  Point operator / (double a) { return Point(x/a, y/a); }

  double norm() { return x*x+y*y; }
  double abs() { return sqrt(norm()); }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

typedef Point Vector;
typedef vector <Vector> Polygon;

class Segment {
 public:
  Point p1, p2;

  Segment(Point p1 = Point(), Point p2 = Point()): p1(p1), p2(p2) {}
};

double norm(Vector a) {
  return a.x*a.x+a.y*a.y;
}

double abs(Vector a) {
  return sqrt(norm(a));
}

// ?????????|a||b|cos
double cross(Vector a, Vector b) {
  return a.x*b.y-a.y*b.x;
}
// ?????????|a||b|sin
double dot(Vector a, Vector b) {
  return a.x*b.x+a.y*b.y;
}

// ?°???±:??´???s???p?????????????????????????????¨?????????????????????
Point project(Segment s, Point p) {
  Vector base = s.p2-s.p1;
  double r = dot(p-s.p1, base)/norm(base);
  return s.p1+base*r;
}

Point reflect(Segment s, Point p) {
  return p + (project(s, p)-p)*2.0;
}

int main() {
  Segment l;
  cin >> l.p1.x >> l.p1.y >> l.p2.x >> l.p2.y;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    Vector p;
    cin >> p.x >> p.y;
    Vector ans = reflect(l, p);
    cout << fixed << setprecision(20) << ans.x << " "<< ans.y << endl;
  }
}

Measured memory_bytes: 1296
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

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

	uint32_t res1 = 0, res2 = 0;
	for(uint32_t i = 0;i < S.size();++i){
		if(i & 0x01){
			if(S[i] != '1')
				++res1;

		}else{
			if(S[i] != '0')
				++res1;
		}
	}		
	for(uint32_t i = 0;i < S.size();++i){
		if(i & 0x01){
			if(S[i] != '0')
				++res2;

		}else{
			if(S[i] != '1')
				++res2;
		}
	}		
	if(res1 < res2)
		cout << res1 << endl;
	else
		cout << res2 << endl;


	return 0;
}

Measured memory_bytes: 512
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		try{
 			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 			StringBuilder sb = new StringBuilder();
 			int i=1;
 			while(true){
 				int data = Integer.parseInt(br.readLine());
 				if(data == 0){
 					break;
 				}
 				else{
 					sb.append("Case ").append(Integer.toString(i++)).append(": ").append(Integer.toString(data)).append("\n");
 				}
 			}
 			System.out.print(sb);
		}
		catch(Exception e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 30540
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    REP(i, n) cin >> s[i];
    sort(ALL(s));
    REP(i, n) cout << s[i];
    cout << endl;
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-A: Exhaustive Search

#include <cstdio>

static bool solve(const int m, const int as[], const unsigned int n)
{
  if (m == 0) {
    return true;
  } else if (m < 0 || n == 0) {
    return false;
  } else {
    return solve(m-as[0], as+1, n-1) || solve(m, as+1, n-1);
  }
}

int main()
{
  unsigned int n;
  std::scanf("%d", &n);
  int as[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &as[i]);
  }

  unsigned int q;
  std::scanf("%d", &q);
  for (auto i = 0u; i < q; ++i) {
    int m;
    std::scanf("%d", &m);
    auto is_solved = solve(m, as, n);
    std::printf("%s\n", is_solved ? "yes" : "no");
  }
}

// eof

Measured memory_bytes: 2596
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n, a, b;
	string s;
	while (cin >> n >> a >> b >> s) {
		vector<string> ans(n, "No");

		int curAll = 0;
		int curB = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'c') continue;
			if (s[i] == 'a') {
				if (curAll < a + b) {
					curAll++;
					ans[i] = "Yes";
					continue;
				}
			}
			if (s[i] == 'b') {
				if (curAll < a + b && curB < b) {
					curAll++;
					curB++;
					ans[i] = "Yes";
				}
			}
		}
		for (int i = 0; i < n; i++) cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>
#define MAX 100000
long long T[MAX];
int n,k;
 
int load(long long P) {
    int i=0,j=0;
    long long t;
    for(i = 0; i < k; i++) {
        t = 0;
        while( t+T[j] <=P) {
            t +=T[j];
            j++;
            if(j==n) return n;  
        }
    }
    return j;   
     
}
 
int solve() {
    long long right = MAX*10000,left=0,mid,s;
     
    while(right>left+1) {
        mid = (right + left)/2;
         s=load(mid);
         if(s>=n) right=mid;
         else left = mid;
    }
        return right;           
}
 
int main(void)
 
{
    int i;
    scanf("%d %d%",&n,&k);
     
    for(i=0; i < n; i++) {
        scanf("%d",&T[i]);
    }
        printf("%llu\n",solve());
        return 0;
     
         
     
     
}


Measured memory_bytes: 2636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();
        Console.WriteLine(48 - cin.nextInt());
    }

    

}



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>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, K;
    cin >> N >> K;
    int h[N];
    REP(i, N) cin >> h[i];

    int ret = 0;
    REP(i, N) if (h[i]>=K) ++ret;

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> A(N);
    long long p = 1, q = 1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        p *= 3;
        if (A[i] % 2 == 0) {
            q *= 2;
        }
    }
    cout << p-q << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

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

bool same(string s)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=s[0])return false;
	}
	return true;
}

int ch(string s,char rep)
{
	int cnt=0;
	while(!same(s))
	{
		string ns(s.length()-1,'@');
		for(int i=0;i<s.length()-1;i++)
		{
			if(s[i]==rep||s[i+1]==rep)
			{
				ns[i]=rep;
			}
			else
			{
				ns[i]=s[i];
			}
		}
		s=ns;
		cnt++;
	}
	return cnt;
}

int main()
{
	string S;
	cin>>S;
	int res=10000;
	for(char a='a';a<='z';a++)
	{
		res=min(ch(S,a),res);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

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

    int res = 0;
    rep(i,A+1) {
        rep(j,B+1) {
            rep(k,C+1) {
                if (500*i + 100*j + 50*k == X) res += 1;
            }
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2e5+5;
const long long mod=1e9+7;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x) {
    if (x < 0){
        putchar('-');
        x = -x;
    }
    if (x > 9)o(x / 10);
    putchar(x % 10 + '0');
}
long long read(){
    long long  res=0;
    long long  y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){res=(res<<1)+(res<<3)+c-'0';c=getchar();}
    return res*y;
}
long long 	ppo(long long x,long long p){
    long long t=x,res=1;
    while(p){
        if(p&1)res=(res*t)%mod;
        t=(t*t)%mod;
        p>>=1;
    }
    return res;
}
struct edge{
    long long to,next,value;
}e[maxn*2];
long long first[maxn*2],cntedge=0;
void addedge(long long fr,long long to){
    e[++cntedge]={to,first[fr]};first[fr]=cntedge;
    swap(fr,to);
    e[++cntedge]={to,first[fr],};first[fr]=cntedge;
}
long long n;
long long sons[maxn];
long long f[maxn];
void dfs(long long u){
    sons[u]=1;
    f[u]=1;
    for(long long i=first[u];i;i=e[i].next){
        long long v=e[i].to;
        if(!sons[v]){
            dfs(v);
            sons[u]+=sons[v];
            f[u]=f[u]*f[v]%mod;
        }
    }
    f[u]=f[u]*sons[u]%mod;
}
void cal(long long u,long long fa){
    for(long long i=first[u];i;i=e[i].next){
        long long v=e[i].to;
        if(v!=fa){
            f[v]=(f[u]*(n-sons[v])%mod*ppo(sons[v],mod-2))%mod;
            cal(v,u);
        }
    }
}
signed main(){
    in(n);
    long long jic=1;
    for(long long i=1;i<=n;i++)jic=(jic*i)%mod;
    for(long long i=1;i<=n-1;i++){
        addedge(read(),read());
    }
    dfs(1);
    cal(1,0);
    for(long long i=1;i<=n;i++){
        //cout<<ppo(2,mod-2)<<endl;
        o((jic*ppo(f[i],mod-2))%mod);putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 17732
while s = gets do
  cards = s.split(',').map(&:to_i)
  card_count = Array.new(13){0}
  cards.each { |c| card_count[c-1] += 1 }
  str = card_count.join
  card_count.delete(0)

  scr = 'null'
  case card_count.sort
    when [1,4]
      scr = 'four card'
    when [2,3]
      scr = 'full house'
    when [1,1,1,1,1]
      scr = 'straight' if str =~ /1{5}/ or str =~ /10{8}1{4}/
    when [1,1,3]
      scr = 'three card'
    when [1,2,2]
      scr = 'two pair'
    when [1,1,1,2]
      scr = 'one pair'
  end
  puts scr
end

Measured memory_bytes: 6100
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

    rep(i,s.size()){
        s[i] = 'x';
    }
    cout << s << endl;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int k,x;
    cin >> k >> x;
    if (k*500>=x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    // static int root=0,target=0,n;
    //static int[] tempSub,child,father;
    static HashSet<Integer>[] graph;
    public static void main(String[] args)throws IOException {
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(), W = sc.nextInt(), h =sc.nextInt(), w = sc.nextInt();
        int res = h*W+w*H-h*w;
        System.out.println(H*W-res);
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int maya[] = {20, 18, 20, 20, 13};

string mtos(string s)
{
    int a[5];
    sscanf(s.c_str(), "%d.%d.%d.%d.%d", a, a+1, a+2, a+3, a+4);
    
    ll elapsed = 0;
    rep(i, 5){
        elapsed *= maya[4-i];
        elapsed += a[i];
    }
    elapsed += 734857;
    
    int y = (elapsed / 146097) * 400 + 1;
    elapsed %= 146097;
    
    int m = 0, d = 0;
    rep(i, elapsed){
        bool leap = y%4==0 && (y%100!=0 || y%400==0);
        int days[] = {31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        
        ++d;
        if(d == days[m]){
            d = 0;
            ++m;
            if(m == 12){
                ++y;
                m = 0;
            }
        }
    }
    
    stringstream sstr;
    sstr << y << '.' << m+1 << '.' << d+1;
    return sstr.str();
}

string stom(string s)
{
    ll y, m, d;
    sscanf(s.c_str(), "%lld.%lld.%lld", &y, &m, &d);
    
    bool leap = y%4==0 && (y%100!=0 || y%400==0);
    int days[] = {0, 31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
    rep(i, 11) days[i+1] += days[i];
    
    --y; --m; --d;
    ll elapsed = 365*y + y/4 - y/100 + y/400 + days[m] + d;
    elapsed -= 734857;
    
    string ret;
    rep(i, 5){
        ret = to_string(elapsed % maya[i]) + (i ? "." : "") + ret;
        elapsed /= maya[i];
    }
    
    return ret;
}

int main()
{
    string s;
    while(cin >> s, s != "#"){
        cout << (count(s.begin(), s.end(), '.') == 4 ? mtos(s) : stom(s)) << endl;
    }
}

Measured memory_bytes: 1284