akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int partition(int A[],int p,int r){
    int x = A[r];
    int i = p-1;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}
 
int main(){
    int n,partition_point;
    scanf("%d",&n);
    int A[n];
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    partition_point = partition(A,0,n-1);
 
    for(int i = 0; i < n-1; i++){
        if(i == partition_point){
            printf("[%d] ",A[i]);
        }else{
            printf("%d ",A[i]);
        }
    }
    if(partition_point == n-1){
        printf("[%d]\n",A[n-1]);
    }else{
        printf("%d\n",A[n-1]);
    }
}


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

using namespace std;

typedef long long int lli;

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

    int n, k;
    cin >> n >> k;

    if ((n-1)*(n-2)/2 < k) {
        cout << -1 << endl;
        return 0;
    }

    int s = ((n-1)*(n-2)/2) - k;
    cout << (n-1) + s << endl;

    // star
    for (int i=2; i<=n; i++) cout << "1 " << i << endl;

    // short
    for (int i=2, x=0; i<=n && x<s; i++) {
        for (int j=i+1; j<=n && x<s; j++, x++) {
            cout << i << " " << j << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<math.h>

#define TORIDASI(size,data) if(str.substr(i,size) == data){\
i+=size;\
}
#define SUSUMU(doredake,mozi) for(int ssm = 0;ssm < doredake;ssm++){\
	str += mozi;\
}


using namespace std;
const long long int KIRAI = 10e9 + 7;

int main() {
	long long int s,c;
	cin >> s >> c;
	if (s * 2 > c) {
		cout << c /2  << endl;
		return 0;
	}
	cout << s + (c - 2*s) / 4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int cnt[26] = {0}, i, j;
	char c = 'a', str[1200];

	scanf("%[\x01-\xff]", str);
	for(i = 0; str[i] != '\0'; i++){
		if(65 <= str[i] && str[i] <= 90){
			cnt[str[i]-65] += 1;
		}else if(97 <= str[i] && str[i] <= 122){
			cnt[str[i]-97] += 1;
		}
	}
	
	for(j = 0; j < 26; j++){
		printf("%c : %d\n", c, cnt[j]);
		c += 1;
	}
	
	return 0;
}



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

int main()
{
	for(int n;cin>>n && n;){
		vector<string> ps(n);
		vector<int> ts(n);
		for(int i=0;i<n;i++){
			cin>>ps[i];
			int w,s; cin>>w>>s;
			ts[i]=(w*24*60+s/100*60+s%100)%(7*24*60);
		}
		int m; cin>>m;
		vector<int> fs(n);
		for(int i=0;i<m;i++){
			string s; cin>>s;
			fs[find(begin(ps),end(ps),s)-begin(ps)]=1;
		}
		
		for(int i=0;i<n;i++)
			ts.push_back(ts[i]+7*24*60);
		vector<int> is(n*2);
		iota(begin(is),end(is),0);
		sort(begin(is),end(is),[&](int i,int j){return ts[i]<ts[j];});
		
		int res=-1;
		for(int l=0,r=7*24*60;l<30;l++,r++){
			vector<int> dp(r+1);
			int p=0;
			for(int i:is){
				int t=ts[i];
				if(l<=t && t+30<=r){
					for(;p<t;p++) dp[t]=max(dp[t],dp[p]);
					dp[t+30]=max(dp[t+30],dp[t]+(fs[i]?1000:1));
				}
			}
			for(;p<r;p++) dp[r]=max(dp[r],dp[p]);
			if(dp[r]/1000!=m) continue;
			res=max(res,dp[r]/1000+dp[r]%1000);
		}
		
		cout<<res<<endl;
	}
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll n;

int main()
{
    _FastIO;
    cin >> n;
    ll k = sqrt(n);
    for(ll i = k; i >= 1; i--){
        if(n % i == 0){
            cout << i + n / i - 2 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
d = s // 2
t = 0
i = -1
while(t <= d):
    i += 1
    t += a[i]
t2 = t - a[i]
# print(t,t2,s)
# print(t-(s-t),(s-t2)-t2)
print(min(t - (s - t),(s - t2) - t2))

Measured memory_bytes: 26060
#include <iostream>
#include <numeric>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

	int A,B;
	cin >> A>>B;
	string s;
	cin >> s;
	int k = 0;
	for (int i = 0; i < A; i++) {
		if (s.at(i) == '-' ) {
			k++;
		}
	}
	if (s.at(A) != '-') {
		k++;
	}
	for (int i = A+1; i < A+B+1; i++) {
		if (s.at(i) == '-') {
			k++;
		}
	}
	string an = "No";
	if (k == 0) {
		an = "Yes";
	}
	cout << an << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
String s=scan.next();
String[] ss=s.split("");
  
if(ss[2].equals(ss[3])&&ss[4].equals(ss[5])){
System.out.println("Yes");
}else{
System.out.println("No");
}

}
}

Measured memory_bytes: 22228
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll INM = 114514;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll dp[214514][26];

int main() {
	IOS();
	string s, t;
	cin >> s >> t;
	string s2 = s + s;
	int n	 = s.size();
	int m	 = t.size();
	Fill(dp, INF);

	for (int i = 2 * n - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			char c = 'a' + j;
			if (s2[i] == c) {
				dp[i][j] = 1;
			} else {
				dp[i][j] = dp[i + 1][j] + 1;
			}
		}
	}
	ll ans = 0;
	ll tmp = 0;
	for (int i = 0; i < m; i++) {
		int j = t[i] - 'a';
		ans += dp[tmp][j];
		tmp = ans % n;
		if (ans >= INF) {
			dump(-1);
			return 0;
		}
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 44368
import math

X, K_kai, D = map(int, input().split())

if (abs(X) >= K_kai * D):
    ans = abs(abs(X) - abs(K_kai * D))

else:
    times_low = math.floor(abs(X) / D)
    times_hig = times_low + 1
    
    
    if ((K_kai - times_low) % 2 == 0):
        ans = abs(abs(X) - times_low * abs(D))
            
    else:
        ans = abs(abs(X) - times_hig * abs(D))

print(ans)


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

int occ[256], dp[1111][1111];
string s1, s2;

int main() {
    cin >> s1 >> s2;
    for(int j = 1; j <= sz(s2); j ++)
        dp[0][j] = j;
    for(int i = 1; i <= sz(s1); i ++)
        dp[i][0] = i;
    for(int i = 1; i <= sz(s1); i ++) {
        for(int j = 1; j <= sz(s2); j ++) {
            occ[s2[j - 1]] = j;
            dp[i][j] = dp[i - 1][j - 1] + (1 ? s1[i - 1] != s2[j - 1] : 0);
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
            if(occ[s1[i - 1]])
                dp[i][j] = min(dp[i][j], dp[i][occ[s1[i - 1]]] + j - occ[s1[i - 1]]);
            // cout << "dp[" << i << "][" << j << "]: " << dp[i][j] << ' ' << occ[s1[i - 1]] << '\n';
        }
        memset(occ, 0, sizeof occ);
    }
    cout << dp[sz(s1)][sz(s2)] << '\n';
    return 0;
}



Measured memory_bytes: 7496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

double eps = 1e-8;

int main() {
    int n; cin >> n;
    for (int x = 1; x <= 50000; x++) {
        double v = x * 1.08;
        v = int(v);
        if (v == n) {cout << x << endl; return 0;}
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

class data_queue{
	public:
	 string name;
	 ll times;
};

int main(){
	static queue<data_queue> tasks;
	ll n,m;
	cin >> n >> m;
	REP(i,n){
		data_queue task;
		cin >> task.name >> task.times;
		tasks.push(task);
	}
	ll ans = m;
	while(!tasks.empty()){
		data_queue task = tasks.front();
		tasks.pop();
		task.times -= m;
		if(task.times>0){
			tasks.push(task);
		}else{
			ans += task.times;
			cout << task.name << " " << ans << endl;
		}
		ans += m;
	}
	return 0;
}


Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll a, b, c;
    cin >> a >> b >> c;

    ll mx = max({a, b, c});
    ll mn = min({a, b, c});
    ll md = a + b + c - mx - mn;

    ll ans = 0;
    ans += mx - md;
    if((md - mn) % 2 == 0) ans += (md - mn)/2;
    else ans += (md + 1 - mn)/2 + 1;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 200003
#define MOD 1000000007
typedef int FLOW;

int main(){
  int N;
  cin>>N;
  vector<int> count(3);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    count[a-1]++;
  }

  vector<vector<vector<double>>> dp(N+1,vector<vector<double>>(N+1,vector<double>(N+1,0.0)));
  for(int k=0;k<=N;k++){
    for(int j=0;j<=N;j++){
      if(j+k>N){
        break;
      }
      for(int i=0;i<=N;i++){
        if(i+j+k>N){
          break;
        }
        if(i+k+j==0){
          continue;
        }
        double ii=(double)i;
        double jj=(double)j;
        double kk=(double)k;
        dp[i][j][k]=(double)N/(ii+jj+kk);
        if(i>0){
          dp[i][j][k]+=ii/(ii+jj+kk)*dp[i-1][j][k];
        }
        if(j>0&&i<N){
          dp[i][j][k]+=jj/(ii+jj+kk)*dp[i+1][j-1][k];
        }
        if(j<N&&k>0){
          dp[i][j][k]+=kk/(ii+jj+kk)*dp[i][j+1][k-1];
        }
      }
    }
  }

  printf("%.10lf\n",dp[count[0]][count[1]][count[2]]);

}


Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
int main(){
	string s;
	cin>>s;
	string u="keyence";
	if(s==u){
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=0;i<s.size();i++){
		for(int j=i;j<s.size();j++){
			string t="";
			for(int k=0;k<s.size();k++){
				if(i<=k&&k<=j){
					continue;
				}else{
					t.push_back(s[k]);
				}
			}	
			if(t==u){
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int>a(N);
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        if(a[i]%4 == 0) {
            cnt1++;
        }
        else if(a[i]%2 == 0) {
            cnt2++;
        }
        else {
            cnt3++;
        }
    }
    if(cnt3+min(1,cnt2)-1 <= cnt1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    static int mod = 1000000007;

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

        int n, a, b;

        n = cin.nextInt();
        a = cin.nextInt();
        b = cin.nextInt();

        long sum = pow(2, n) - 1;

        sum -= choose(n, a);
        if (sum < 0) {
            sum += mod;
        }

        sum -= choose(n, b);
        if (sum < 0) {
            sum += mod;
        }

        System.out.println(sum);
    }

    public static long pow(long n, int m) {
        long prod = 1;
        while (m > 0) {
            if ((m & 1) == 1) {
                prod = (prod * n) % mod;
            }
            n = (n*n) % mod;
            m >>= 1;
        }
        return prod;
    }

    public static long choose(int a, int b) {
        long numerator = 1;
        long denominator = 1;
        for (int i = 1; i <= b; i++) {
            numerator *= a - i + 1;
            denominator *= b - i + 1;
            numerator %= mod;
            denominator %= mod;
        }
        return (numerator * pow(denominator, mod - 2)) % mod;
    }
}


Measured memory_bytes: 22996
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

a,b = i2()
print(a*b - (1*a + 1*b - 1))

Measured memory_bytes: 3060
c=[[0 for i in range(9)] for i in range(9)]

n=int(input())
for i in range(1,n+1):
    I=str(i)
    if I[0]!="0" and I[len(I)-1]!="0":
        c[int(I[0])-1][int(I[len(I)-1])-1]+=1

s=0
for i in range(9):
    for j in range(9):
        s+=c[i][j]*c[j][i]

print(s)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,m,t[110],p[110],x[110],i,j,k,result[110]= {0};
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&t[i]);
    }
    scanf("%lld",&m);
    for(i=1; i<=m; i++)
    {
        scanf("%lld%lld",&p[i],&x[i]);
    }
    for(j=1; j<=m; j++)
    {
        for(i=1; i<=n; i++)
        {
            if(i!=p[j])
            {
                result[j]+=t[i];
            }

        }
    }
    for(i=1;i<=m;i++)
    {
        result[i]+=x[i];
    }
     for(i=1;i<=m;i++)
    {
        printf("%lld\n",result[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

const int MAX_V = 1000010;
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;     //帰りがけの順の並び
bool used[MAX_V];
int cmp[MAX_V];     //属する強連結成分のトポロジカル順序
int dp[MAX_V];

void add_edge(int from, int to){
    G[from]. push_back(to);
    rG[to]. push_back(from);
}

void dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) dfs(G[v][i]);
    }
    vs. push_back(v);
}

void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i = 0; i < rG[v].size(); i++){
        if(!used[rG[v][i]]) rdfs(rG[v][i], k);
    }
}

int scc(){
    memset(used, 0, sizeof(used));
    vs.clear();
    for(int v = 0; v < V; v++){
        if(!used[v]) dfs(v);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for(int i = vs.size() - 1; i >= 0; i--){
        if(!used[vs[i]]){
            rdfs(vs[i], k++);
        }
    }
    return k;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    V = n * n;
    rep(i, 0, n){
        vector<int> a(n - 1);
        rep(j, 0, n - 1){
            cin >> a[j];
            a[j]--;
        }
        rep(j, 0, n - 2){
            int u = i, v = a[j];
            if(u > v) swap(u, v);
            int x = i, y = a[j + 1];
            if(x > y) swap(x, y);
            add_edge(u * n + v, x * n + y);
            // cout << u * n + v << ' ' << x * n + y << endl;
        }
    }
    int c = scc();
    // cout << c << endl;
    if(c != n * n){
        cout << -1 << endl;
        return 0;
    }
    for(int i = vs.size() - 1; i >= 0; i--){
        int v = vs[i];
        if(dp[v] == 0) dp[v] = 1;
        for(int j = 0; j < G[v].size(); j++){
            dp[G[v][j]] = max(dp[G[v][j]], dp[v] + 1);
        }
    }
    int ans = 0;
    rep(i, 0, V) ans = max(ans, dp[i]);
    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    stack<pair<char,int>> st;
    st.push({'+',0});
    string s;
    int now=0;
    rep(i,n){
      cin >> s;
      while(s.length()<=now){
        int p = st.top().second;
        st.pop();
        if(st.top().first=='+'){
          st.top().second+=p;
        }else{
          st.top().second*=p;
        }
        now--;
      }
      if(s[now]=='+'){
        st.push({'+',0});
        now++;
      }else if(s[now]=='*'){
        st.push({'*',1});
        now++;
      }else{
        if(st.top().first=='+'){
          st.top().second+=s[now]-'0';
        }else{
          st.top().second*=s[now]-'0';
        }
      }
    }
    while(st.size()>1){
      int p = st.top().second;
      st.pop();
      if(st.top().first=='+'){
        st.top().second+=p;
      }else{
        st.top().second*=p;
      }
    }
    cout << st.top().second << endl;
  }
  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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 long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    vector<int> alpha(26, 0);
    rep(i, S.size()) {
        alpha[S[i] - 'a']++;
    }

    int kind = 0, mi = 1e9, ma = 0;
    rep(i, 26) {
        if (alpha[i] > 0) {
            kind++;
            chmin(mi, alpha[i]);
            chmax(ma, alpha[i]);
        }
    }

    if ((int)S.size() == 1) cout << "YES" << endl;
    else if (kind <= 2) {
        if (kind == 2 && (int)S.size() == 2) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if (ma - mi <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for(int i = 0; i < n; i++)
#define repj(n) for(int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;

class Timer {
	clock_t start;
public:
	Timer() {start = clock();}
	~Timer() {cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";}
};

class MST {
	vector<vector<int>> T;
	int n;
public:
	MST(const vector<int>& A) {
		n = A.size();
		T.assign(2*n, vector<int>());
		for(int p = n; p < 2*n; p++)
			T[p].push_back(A[p - n]);
		for(int p = n - 1; p > 0; p--) {
			T[p].resize(T[p<<1].size() + T[p<<1|1].size());
			merge(all(T[p<<1]), all(T[p<<1|1]), T[p].begin());
		}
	}

	int query(int l, int r) {
		int thresh = l, ret = 0;
		for(l += n, r += n + 1; l < r; l>>=1, r>>=1) {
			if(l & 1) { 
				ret += lower_bound(all(T[l]), thresh) - T[l].begin();
				l++;
			}
			if(r & 1){
				--r;
				ret += lower_bound(all(T[r]), thresh) - T[r].begin();
			}
		}
		return ret;
	}
};

void solve() {
	int n, Q;
	cin >> n >> Q;
	vi c(n); rep(n) cin >> c[i], c[i]--;
	vi cur(n, -1), prevOcc(n, -1);
	for(int i = 0; i < n; i++) {
		prevOcc[i] = cur[c[i]];
		cur[c[i]] = i;
	}
	MST mst(prevOcc);
	while(Q--) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << mst.query(l, r) << endl;
	}
}

signed main() {
	Timer ti;
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int T = 1;
	#ifdef TEST_CASES
	cin >> T;
	#endif
	for(int t = 1; t <= T; t++) {
		#ifdef CASE_INFO
		cout << "Case #" << t << ": ";
		#endif
		solve();
	}
	return 0;
}


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

const int N = 1e5 + 6;
vector<int> a(N);

int main() {
    int n, q, b, c;
    long long sum = 0ll;
    cin >> n;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        sum += (long long)x;
        ++a[x];
    }
    
    cin >> q;
    while (q--) {
        cin >> b >> c;
        sum += (long long)((c-b) * a[b]);
        a[c] += a[b];
        a[b] = 0;
        cout << sum << '\n';
    }
    return 0;
}


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

using ll = long long;
const int mod = 1e9 + 7;

const int nax = 1e5 + 5;
vector<int> edges[nax];

int mul(int a, int b) {
    return (ll) a * b % mod;
}

// returns {num_ways to paint this white, num_ways to paint this black}
pair<int, int> dfs(int a, int parent) {
    int all_white = 1;
    int some_black = 0;
    for(int b: edges[a]) {
        if(b != parent) {
            pair<int, int> p = dfs(b, a);
            int memo_all_white = all_white;
            all_white = mul(all_white, p.first);
            some_black = (mul(memo_all_white, p.second) + mul(some_black, p.first+p.second)) % mod;
        }
    }
    return make_pair((all_white + some_black)%mod, all_white);
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    pair<int, int> p = dfs(1, -1);
    int ans = (p.first+p.second) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12672
import itertools

def cal(N, target_num, keta):
    answer = float('inf')
    for p in itertools.product(target_num, repeat=keta):
        temp = 0
        for i, num in enumerate(p):
            temp += num * 10**i
            
        if temp >= N:
            answer = min(answer, temp)

    return answer

if __name__ == "__main__":
    N, K = map(int, input().split()) # N円の品物、K個の嫌いな数字
    D = set(list(map(int, input().split()))) # 嫌いな数字のリスト
    base = set(range(10))

    target_num = base - D
    keta = len(str(N))

    answer = min(cal(N, target_num, keta), cal(N, target_num, keta+1))

    print(answer)

Measured memory_bytes: 9212
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int L = sc.nextInt();

		ArrayList<Integer> taste = new ArrayList<Integer>();
		ArrayList<Integer> taste2 = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			taste.add(L + i);
			taste2.add((L + i) * (L + i));
		}
		int index = taste2.indexOf(Collections.min(taste2));
		taste.remove(index);
		int ans = 0;
		for (Integer num : taste) {
			ans += num;
		}
		System.out.println(ans);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 21204
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
if x==sum(a):
    ans=n
elif x>sum(a):
    ans=n-1
else:
    for i in range(n):
        if x>=a[i]:
            ans+=1
            x-=a[i]
        else:
            break
print(ans)


Measured memory_bytes: 38384
H, W, K = map(int, input().split())
M = [input() for _ in range(H)]
ans = 0
for h in range(1 << H):
    hse = set()
    for hh in range(H):
        if h&(1<<hh):
            hse.add(hh)
    for w in range(1 << W):
        cnt = 0
        wse = set()
        for ww in range(W):
            if w&(1<<ww):
                wse.add(ww)
        for hhh in range(H):
            for www in range(W):
                if hhh in hse: continue
                if www in wse: continue
                if M[hhh][www] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
   while(cin >> s){
         int cnt  = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '-')cnt--;
        else cnt++;
    }
    cout<<cnt<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    ll N; cin >> N;
    ll ans = 0;
    REP(i, N - 1) {
        ans += (i + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> G[n];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> c(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    sum += c[i];
  }
  sort(c.begin(), c.end(), greater<int>());
  sum -= c[0];
  queue<int> q;
  vector<int> costs(n, -1);
  q.push(0);
  int count = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    costs[v] = c[count];
    count++;
    for (auto i : G[v]) {
      if (costs[i] == -1) {
        q.push(i);
      }
    }
  }
  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    cout << costs[i] << endl;
  }
}


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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  if (b <= n) {
    cout << a * (b-1) / b << endl;
  } else {
    cout << a * n / b << endl;
  }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
int main(){
    int i;
    int h,w,hi,wi; cin>>h>>w>>hi>>wi;




    cout<<h*w-hi*w-wi*h+hi*wi <<endl;
    return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  REP(i, k, n) {
    if (a.at(i - k) < a.at(i))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 4812
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h> 
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	int mcd(int a,int b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}		
	lli pre[MaxN];
	lli suf[MaxN];	
	lli arr[MaxN];
int main(){
	lli N,K,i,j,p,q;
	double res;
	cin>>res;
	res=res/3;
	res=res*res*res;
	printf("%.6f",res);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int q,l;
void prime(int x)
{
    long long int i,j,count=0;
    long long int visited[x+1];
    visited[1]=1;
    fill(visited,visited+x+1,0);
    for(i=2;i<=sqrt(x);i++)
    {
        if(!visited[i])
        {
            for(j=2*i;j<=x;j+=i)
            {
                if(!visited[j])
                    visited[j]=1;
            }
        }
    }
    long long int sum=0;
    vector<int>v;
    v.erase(v.begin(),v.end());
    for(i=2;i<=x;i++)
    {
        if(!visited[i])
            v.push_back(i);
    }
    for(i=0;i<v.size();i++)
    {
        sum=0;
        for(j=i;j<v.size();j++)
        {
            sum+=v[j];
            if(sum==x)
                {
                    count++;
                    break;
                }
            else if(sum>x)
                break;
        }
    }
    cout<<count<<endl;
}
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        prime(n);
        cin>>n;
    }
    return 0;
}

Measured memory_bytes: 3244
cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
}
n = int(input())
for _ in  range(n):
     (s, r) = input().split()
     cards[s][int(r) - 1] = 1

for s in('S','H','C','D'):
    for r in range(13):
        if cards[s][r] == 0:
            print(s, r + 1)

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a1,a2,a3; cin>>a1>>a2>>a3;
  if(a1+a2+a3>=22) cout<<"bust"<<endl;
  else cout<<"win"<<endl;
}


Measured memory_bytes: 256
import math

a, b, c = map(int, input().split())
sin_c = math.sin(math.radians(c))
cos_c = math.cos(math.radians(c))

s = (a*b*sin_c) / 2
l = math.sqrt(a**2+b**2-2*a*b*cos_c) + a + b
h = b*sin_c

print(s)
print(l)
print(h)



Measured memory_bytes: 5712
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(N: int, K: int):
    ns = []
    for i in range(1, N + 1):
        if N < i * i:
            break
        ns.append(i)
        ns.append(N // i)
    ns = sorted(list(set(ns)))

    m = {n: i for i, n in enumerate(ns)}
    l = [1] * len(ns)
    for i, (s, b) in enumerate(zip(ns, ns[1:])):
        l[i] = (N // s) - (N // b)

    dp = [[0] * len(ns) for _ in range(K+1)]
    dp[0][m[N]] = 1

    for i in range(K):
        for j in range(len(ns) - 2, -1, -1):
            dp[i][j] += dp[i][j + 1]
        for j, nn in enumerate(ns):
            nj = m[N // nn]
            dp[i+1][j] = (dp[i+1][j] + dp[i][nj] * l[j]) % MOD

    return sum(dp[-1]) % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(N, K)
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 120772
#include <assert.h>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <limits.h>
#include <mutex>
#include <thread>
#include <vector>

int main(){
  int K;
  int X;
  scanf("%d", &K);
  scanf("%d", &X);
  if (500*K>=X){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 760
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        try (PrintWriter writer = new PrintWriter(System.out); InputReader reader = new InputReader(System.in)) {
            solve(writer, reader);
        }
    }

    private static void solve(PrintWriter writer, InputReader reader) throws IOException {
        int[] ints = reader.readIntsSplitByDelimiter(" ");
        int area = ints[0] * ints[1] - ints[0] - ints[1] + 1;
        writer.println(area);
        writer.flush();
    }
}

class Util {
    static int gcd(int m, int n) {
        int min = Math.min(m, n);
        int max = Math.max(m, n);
        while (min != 0) {
            int tmp = min;
            min = max % tmp;
            max = tmp;
        }

        return max;
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.readLine());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(this.readLine());
    }

    String[] readStringsSplitByDelimiter(String delimiter) throws IOException {
        return this.readLine().split(delimiter);
    }

    int[] readIntsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        int[] ints = new int[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        long[] longs = new long[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    double[] readDoublesSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        double[] doubles = new double[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            doubles[i] = Double.parseDouble(strings[i]);
        }

        return doubles;
    }

    @Override
    public void close() throws IOException {
        this.br.close();
    }
}


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

const int N = 3e5 + 10;

int a[N];

bool cmp(const int& x, const int& y){
	return x > y;
}

int main(){
	int n, p1, p2;
	long long sum;
	scanf("%d",&n);
	for (int i = 1; i <= n * 3; i++) scanf("%d",&a[i]);
	sort(a + 1, a + n * 3 + 1, cmp); 
	sum = 0; p1 = 0; p2 = n * 3 + 1;
	while (p2 - p1 > 1){
		++p1;
		sum += a[++p1];
		p2--;
	} 
	printf("%lld\n", sum);
	return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


int check(string s, char c) {
    vector<int> match(s.size() + 1, -1);
    match.back() = 0;
    rep(i, s.size()) if (s[i] == c) match[i] = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (match[i] == 0) continue;
        else match[i] = match[i + 1] + 1;
    }
    int ans = *max_element(match.begin(), match.end());
    return ans;
}

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

    int ans = INT_MAX;
    for (char c : s) cmin(ans, check(s, c));
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
//typedef vector<int> vec;
typedef vector<char> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};


const int block[8][7][4] ={
    {{1,1,0,0},
     {1,1,0,0},
     {0,0,0,0},
     {0,0,0,0}},
    {{1,0,0,0},
     {1,0,0,0},
     {1,0,0,0},
     {1,0,0,0}},
    {{1,1,1,1},
     {0,0,0,0},
     {0,0,0,0},
     {0,0,0,0}},
    {{0,1,0,0},
     {1,1,0,0},
     {1,0,0,0},
     {0,0,0,0}},
    {{1,1,0,0},
     {0,1,1,0},
     {0,0,0,0},
     {0,0,0,0}},
    {{1,0,0,0},
     {1,1,0,0},
     {0,1,0,0},
     {0,0,0,0}},
    {{0,1,1,0},
     {1,1,0,0},
     {0,0,0,0},
     {0,0,0,0}}
};

int main(){
    while(1){
        int field[8][8];
        int i=0, j=0;
        string row;
        while(cin >> row){
            for(j=0;j<8;j++){
                field[i][j] = (int)(row[j]-'0');
            }
            i++;
            if(i==8)break;
        }
        if(i!=8)break;

        bool found = false;
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                for(int n=0;n<7;n++){
                    bool fit = true;
                    for(int k=0;k<4;k++){
                        for(int l=0;l<4;l++){
                            if(block[n][k][l]==0)continue;
                            if(i+k>=8 || j+l>=8 || field[i+k][j+l]==0){
                                fit = false;
                                break;
                            }
                        }
                        if(!fit)break;
                    }
                    if(fit){
                        printf("%c\n", 'A'+n);
                        found = true;
                        break;
                    }
                }
                if(found) break;
            }
            if(found) break;
        }
    }

    return 0;
}

Measured memory_bytes: 1184
s = gets.chomp.split('')
t = gets.chomp.split('')
check = 0
n = s.size
if s.join('') != t.join('')
  n.times do
    tmp = s.pop
    s.unshift(tmp)
    check += 1 if s.join('') == t.join('')
  end
else
  check += 1
end
if check > 0
  puts :Yes
else
  puts:No
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int num;
	cin >> num;
	vector<int> height(num);
	for (int i = 0; i < num; i++) {
		cin >> height[i];
	}
	int water = 0;
	for (int h = 1; h <= *max_element(height.begin(), height.end()); h++) {
		vector<int> exist(num, 0);
		if (height[0] >= h) {
			water++;
			exist[0] = 1;
		}
		for (int n = 1; n < num; n++) {
			if (height[n] >= h) {
				exist[n] = 1;
				if (exist[n - 1] == 0) {
					water++;
				}
				
			}
		}
	}
	cout << water << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define SX(x) (x).begin(), (x).end()
typedef pair<int, int> P;

int main()
{
  int n;	cin >> n;
  vector<P> a(n), b(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  rep(i,n) cin >> b[i].first >> b[i].second;
  sort(SX(a));
  sort(SX(b));
  
  int ans=0;
  rep(i,n) {
    int res=-1, tmp =-1;
    rep(j, a.size())
    {
      if (a[j].first < b[i].first && a[j].second < b[i].second)
      {
        if (a[j].second > res)
        {
          tmp = j;
          res = a[j].second;
        }
      }
    }
    if (res != -1)
    {
      a.erase(a.begin() + tmp);
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    bool ok = true;
    for(int i = 0; i < 3; i++)  if(s[i] == s[i+1])  ok = false;
    if(ok)  cout << "Good" << endl;
    else    cout << "Bad" << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, C;
  cin >> A >> B >> C;

  if(A%2==0 || B%2==0 || C%2==0){
    cout << "0" << "\n";
    return 0;
  }

  cout << min(A*B, min(B*C, C*A)) << "\n";

  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main ()
{
	int n,sum=0;
  cin>>n;
  if (n<105)
    printf ("%d\n",0);
  else
    {
      for (int i=105;i<=n;i=i+2)
	      {
	      	int s=0;
	      	  {
	      	  	for (int j=1;j<=i;++j)
	      	         if (i%j==0)
	      	             s++;
			  }
			if (s==8)
			   sum++;
		  }	
	  printf ("%d\n",sum);
	}	
} 

Measured memory_bytes: 256