akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll n,m,a,b,c,x,y,k;cin>>k;
  string s;cin>>s;
  a=s.size();
  if(a<=k){
    cout<<s<<endl;
  }
  else{
    cout<<s.substr(0, k)<<"..."<<endl;;
  }
}

Measured memory_bytes: 3600
#include <cstdio>
using namespace std;

int a, b, c;

void init() {
	scanf("%d%d%d", &a, &b, &c);
	return ;
}

void solve() {
	if(a+b+c >= 22) {
		printf("bust");
	}
	else printf("win");
	return ;
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 128
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;

  int answer = 0;
  answer += (N * (N - 1)) / 2;
  answer += (M * (M - 1)) / 2;

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main() {
    string s1,s2,s3,s;
    cin>>s1>>s2>>s3;
    if( s1.length(),s2.length(),s3.length()>=1&&s1.length(),s2.length(),s3.length()<=10){
        s=toupper(s1[0]);
        cout<<s;
        s=toupper(s2[0]);
        cout<<s;
        s=toupper(s3[0]);
        cout<<s;

    }    return 0;
}

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

int main(){
//	freopen("B.in","r",stdin);
	int a, b;
	while(cin >> a >> b){
		int sum = 1;
		int x = a;
		while(a < b){
			a += x - 1;
			sum++;
		}
		if(b == 1)
			sum = 0;
		cout << sum << endl;		
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
#define test(a,n) REP(i,n) cout << a[i] << " ";
using namespace std;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  deque<string> ds(len);
  REP(i,len) ds[i] = s[i];
  int q;
  cin >> q;
  string a;
  bool rev = false;
  int tmp;
  REP(i,q){
    cin >> tmp;
    if(tmp == 1) rev = !rev; 
    else{
      cin >> tmp >> a;
      if((tmp == 1 && !rev) || (tmp == 2 && rev)) ds.emplace_front(a);
      else ds.emplace_back(a);
    }
  }
  if(rev) reverse(ds.begin(),ds.end());
  REP(i,ds.size()) cout << ds[i];
  
  return 0;
}

Measured memory_bytes: 17152
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
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(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll d,n;
    cin >> d >> n;
    n+=n/100;
    cout << n*(ll)pow(100,d) << endl;
    return 0;
}

Measured memory_bytes: 384
def main():
    a, b, c, x, y = map(int, input().split())

    minPrice = 10**20

    for i in range(2 * (x + y) + 1):
        pizzaC = i * c
        pizzaB = max(0, y - i // 2) * b
        pizzaA = max(0, x - i // 2) * a

        price = pizzaA + pizzaB + pizzaC
        
        if price < minPrice:
            minPrice = price

    print(minPrice)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
















int ct[100005][2];
int main()
{
     int a,b,c;
     cin>>a>>b>>c;
     int arr[3]={a,b,c};
     sort(arr,arr+3);
     int t=arr[1];
     int dif=arr[2]-arr[1];
     int ans=0;
     ans+=dif;
     int res1=0;
     res1+=(arr[2]-arr[0]-dif);
     int res2=0;
     int num=arr[0]+dif;
     if((arr[2]-num)%2==0){
          ans+=(arr[2]-num)/2;
     }
     else
     {
          ans+=(arr[2]+1-num)/2+1;
     }
     cout<<ans;
     
     
}




















 

Measured memory_bytes: 256
import sys
x = int(input())

end = int(x / 100) + 1
start = int(x / 105)

for i in range(start, end):
    rest = x - (i * 100)
    if rest < 0 or 5 * i < rest:
        continue
    else:
        print(1)
        sys.exit()

print(0)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::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; }
using namespace std;

int N, K;

int main() {
    cin >> N >> K;
    double ans = 0.0;
    for (int i = 1; i <= N; i++) {
        double tmp = 1.0 / N;
        int now = i;
        while (now < K) {
            now *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    cout << setprecision(16) << ans << endl;
}


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

using namespace std;

short checkTable[1001][1001];

int tmp_max=0;


void calc(int index,char pattern[],char to_search[],int to_search_length){

	for(int i=to_search_length-1;i>=0;i--){
		if(to_search[i]==pattern[index]){
			checkTable[index][i]=1;
			if(pattern[index+1]!='\0' && i < to_search_length-1){
				checkTable[index][i] = checkTable[index+1][i+1] + checkTable[index][i];
			}
		}else{
			if(i != to_search_length-1){
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>checkTable[index][i+1])
							?checkTable[index+1][i]:checkTable[index][i+1];

				}else{
					checkTable[index][i]=(checkTable[index][i+1]>0)?checkTable[index][i+1]:0;
				}
			}else{
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>0)?checkTable[index+1][i]:0;
				}else{
					checkTable[index][i] = 0;
				}
			}
		}
		tmp_max = (tmp_max >= checkTable[index][i])?tmp_max:checkTable[index][i];
	}
}

int main(){

	int q,left_length,right_length;
	char left[1001],right[1001];

	scanf("%d",&q);

	for(int i=0;i<q;i++){
		left_length=0;
		right_length=0;
		scanf("%s %s",left,right);
		for(int k=0;left[k]!='\0';k++)left_length++;
		for(int k=0;right[k]!='\0';k++)right_length++;

		if(right_length>=left_length){

			for(int k=left_length-1;k>=0;k--)calc(k,left,right,right_length);
		}else{

			for(int k=right_length-1;k>=0;k--)calc(k,right,left,left_length);
		}
		printf("%d\n",tmp_max);
		tmp_max=0;
	}

    return 0;
}



Measured memory_bytes: 5152
#include <bits/stdc++.h>
#define int long long
using namespace std;
int d[51][51];
int used[51][51];
typedef pair<int,int> P;

signed main(){
  int W,H;
  std::vector<int> fans;
  while(true){
    cin>>W>>H;if(W==0&&H==0)break;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>d[i][j];
    for(int i=0;i<51;i++)for(int j=0;j<51;j++)used[i][j]=0;
    int ans=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(used[i][j]||d[i][j]==0)continue;
        used[i][j]=1;ans++;
        queue<P> que;que.push(P(i,j));
        while(que.size()){
          P p=que.front();que.pop();
          for(int k=max(0LL,p.first-1);k<=min(H-1,p.first+1);k++){
            for(int l=max(0LL,p.second-1);l<=min(W-1,p.second+1);l++){
              if(used[k][l]==0&&d[k][l]){
                used[k][l]++;que.push(P(k,l));
              }
            }
          }
        }
      }
    }
    fans.push_back(ans);
  }
  for(int i=0;i<fans.size();i++)cout<<fans[i]<<endl;
}



Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    if (s.size() < 26) {
        for (char c = 'a'; ; c++) {
            if (s.find(c) == string::npos) {
                cout << s << c << endl;
                return 0;
            }
        }
    } else if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
    } else {
        for (int i = 25; i > 0; i--) {
            if (s[i-1] < s[i]) {
                string t = s.substr(0, i-1);
                for (char c = s[i-1]+1; ; c++) {
                    if (t.find(c) == string::npos) {
                        cout << t << c << endl;
                        return 0;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    int a[n] = {};
    rep(i,n)cin >> a[i];
    int ans = 0;

    rep(i,n){
        if(i % 2 == 0 && a[i] % 2 == 1)ans++;
    }
    cout << ans << endl;
    return 0;
}




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

int ans = 1e9;

void calc(vector<int> v, vector<int> l, int a, int b, int c)
{
    int sumA, sumB, sumC, cost, cntA, cntB, cntC;
    sumA = sumB = sumC = cost = cntA = cntB = cntC = 0;
    rep(i, v.size())
    {
        if(v[i] == 3) continue;
        if(v[i] == 0)
        {
            sumA += l[i];
            cntA++;
        }
        if(v[i] == 1)
        {
            sumB += l[i];
            cntB++;
        }
        if(v[i] == 2)
        {
            sumC += l[i];
            cntC++;
        }
    }
    if(sumA == 0 || sumB == 0 || sumC == 0) return;
    cost += 10*(max(cntA - 1, 0) + max(cntB - 1, 0) + max(cntC - 1, 0));
    cost += abs(sumA - a);
    cost += abs(sumB - b);
    cost += abs(sumC - c);
    //if(cost == 120) rep(i, v.size()) cout << v[i] << endl;
    ans = min(ans, cost);
}

void dfs(int depth, vector<int> v, vector<int> l, int a, int b, int c)
{
    if(depth == v.size())
    {
       calc(v, l, a, b, c);
       return ;
    }
    rep(i, 4)
    {
        v[depth] = i;
        dfs(depth + 1, v, l, a, b, c);
    }
}

int main(void)
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n), v(n);
    rep(i, n) cin >> l[i];
    dfs(0, v, l, a, b, c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int H,W,K; cin >> H >> W >> K;
    int now = 0;
    vector<vector<int>> ans(H,vector<int>(W,-1));
    bool pretate = false;
    REP(i,H){
        string S; cin >> S;
        bool ex = false;
        REP(j,W){
            if(S[j] == '#'){
                ex = true;
                pretate = true;
            }
        }
        if(ex){
            now++;
            int itcnt = 0;
            REP(j,W){
                if(S[j] == '#'){
                    itcnt++;
                }
                if(S[j] == '#' && itcnt >= 2) now++;

                ans[i][j] = now;

                for(int k = i-1; k >= 0; k--){
                    if(ans[k][j] == -1){
                        ans[k][j] = now;
                    }
                }

            }
        }else{
            if(pretate){
                REP(j,W){
                    ans[i][j] = ans[i-1][j];
                }

            }else{
                ;
            }
        }
    }

    REP(i,H) REP(j,W){
        if(ans[i][j] == -1){
            ans[i][j] = now;
        }
    }
    REP(i,H) {
        REP(j,W){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

}


Measured memory_bytes: 1152
N = int(input())
d_list = list()
for _ in range(N):
  d = int(input())
  d_list.append(d)
d_list.sort(reverse=True)

count = 1

for i, num in enumerate(d_list):
  target = i + 1
  if target == len(d_list):
    break
  if num > d_list[target]:
    count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<vector<Int>> G(4*K, vector<Int>(4*K));//0～2K-1までのグリッド
	Int x, y;
	char c;
	for (Int i = 0; i < N; i++) {
		cin >> x >> y >> c;
		if (c=='W') {
			y += K;
		}
		x %= 2 * K;
		y %= 2 * K;
		G[x][y]++;
		G[x + 2 * K][y]++;
		G[x][y + 2 * K]++;
		G[x+2*K][y + 2 * K]++;
	}

	//二次元累積和
	vector<vector<Int>> S(4*K+1, vector<Int>(4*K+1));
	for (Int i = 0; i < 4*K; i++) {
		for (Int j = 0; j < 4*K; j++) {
			S[i + 1][j + 1] = S[i][j + 1] + S[i + 1][j] - S[i][j] + G[i][j];
		}
	}

	Int ans = -INF;
	Int temp;
	for (Int i = 0; i <= 2*K; i++) {//正方形の左下の座標
		for (Int j = 0; j <= 2*K; j++) {
			temp = S[i + K][j + K] - S[i][j + K] - S[i + K][j] + S[i][j];
			temp += S[i + 2 * K][j + 2 * K] - S[i + K][j + 2 * K] - S[i + 2 * K][j + K] + S[i + K][j + K];
			ans = max(ans, temp);
		}
	}

	cout << ans << "\n";

}


Measured memory_bytes: 250624
#include <cstdio>

int main(void){
  long long x, y;
  int ans;
  
  scanf("%lld%lld", &x, &y);
  
  ans = 0;
  while (x <= y){
    x *= 2;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
n = int(input())
r = 0

for i in range(0, n, 2):
    c = 1

    for j in range(2, i + 1, 2):
        if (i + 1) % (j + 1) == 0:
            c += 1

    if c == 8:
        r += 1

print(r)


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

typedef struct s {
	int ai, id;
} s;

int cmp(void* a,void* b)
{
	return *(int*)a - *(int*)b;
}

int main(void)
{
	int n;
	scanf("%d", &n);
	s* ss = malloc(n * sizeof(s));

	for (size_t i = 0; i < n; i++)
	{
		scanf("%d", &ss[i].ai);
		ss[i].id = i + 1;
	}

	qsort(ss, n, sizeof(s), cmp);

	for (size_t i = 0; i < n; i++)
	{
		printf("%d ", ss[i].id);
	}
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef pair<ii, int> pii;
const int MAX = 2e5+5;
int p[MAX], sz[MAX];

int find(int a) { return (p[a] == a) ? a : p[a] = find(p[a]); }

int main(int argc, char** argv) {
	int N, x, y, u, v;
	int me = (1<<30);
	vector<pii> num;
	scanf("%d", &N);
	REP(i, 1, N) {
	    scanf("%d%d", &x, &y);
	    num.pb(mk(mk(x, y), i));
	}
	rep(i, 1, MAX) sz[i] = 1;
    rep(i, 1, MAX) p[i] = i;
	sort(all(num));
	for(int i = 0, j = N; i < N; i++, j--) {
	    me = min(me, num[i].F.S);
	    if(me == j || i == N-1) continue;
	    if((u = find(num[i].S)) != (v = find(num[i+1].S))) {
	        p[u] = v;
	        sz[u] = sz[v] = (sz[u]+sz[v]);
	    }
	}
	REP(i, 1, N) printf("%d\n", sz[find(i)]);
	return 0;
}


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


void solve(long long A, long long B)
{
    bool flag=false;
    for(int i=1;i<=10000;i++)
    {
        int a=i*0.08,b=i*0.1;
        if(a==A&&b==B)
        {
            flag=true;
            cout<<i<<endl;
            break;
        }
    }
    if(!flag)
        cout<<-1<<endl;
}

int main()
{
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

def main():
    S = input()
    size = len(S)

    for bit in range(1 << (size-1)):
        exp = S[0]
        for i in range(size-1):
            if (bit & (1 << i)):
                exp += '+'
            else:
                exp += '-'
            exp += S[i+1]
        if eval(exp) == 7:
            print(exp + '=7')
            break

if __name__ == '__main__':
    main()

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector <int> r(N,0);
  

 for(int i=0 ; i < M ; i++){
	int a,b;
   cin >>a >>b;
   
	r.at(a-1)++;
	r.at(b-1)++;

 }

   for(int i=0 ; i < N ; i++){

   cout <<  r.at(i)  <<endl;
 }
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
   long long n,sum_val;
   cin >> n;
   sum_val = 0;
   for(long long i = 1;i <= n;i++){
      if(i%3==0 || i%5==0) continue;
      sum_val += i;
   }
   cout << sum_val << endl;
   return 0;
}

Measured memory_bytes: 3640
S = input()

A = "dream"
B = "dreamer"
C = "erase"
D = "eraser"

#入力が文字列でABCDを満たすならTrueとその文字数，満たさないならFalseと0を返す関数
def ABCD(moziretu):
    bool = False
    x = 0
    if moziretu[-5:] == "dream":
        bool = True
        x = 5
    elif moziretu[-7:] == "dreamer":
        bool = True
        x = 7
    elif moziretu[-5:] == "erase":
        bool = True
        x = 5
    elif moziretu[-6:] == "eraser":
        bool = True
        x = 6
    return [bool,x]

while ABCD(S)[0]:
    x = ABCD(S)[1]
    S = S[:-x]

if S == "":
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3244
n, m = list(map(int, input().split()))
par = list(range(n+1))
dis = [0] * (n+1)

def root(x):
  if x == par[x]:
    return x
  r = root(par[x])
  dis[x] += dis[par[x]]
  par[x] = r
  return r

def cost(x):
  # xからxの根までのコスト
  if x == par[x]:
    return 0
  return dis[x] + cost(par[x])

# 確かめ用
def unite(x, y, w):
  rootx = root(x)
  rooty = root(y)
  if rootx != rooty:
    if y != rooty:
      # 直接yにつなげる
      dis[rootx] = w - cost(x)
    else:
      # 根につなげる
      dis[rootx] = w - (dis[x] - dis[y])
    # ここで親を更新
    par[rootx] = y
  else:
    if w != cost(x) - cost(y):
      print("No")
      exit()


for _ in range(m):
  l, r, d = list(map(int, input().split()))
  # 根が違ってればマージ
  # 同じなら入力されたdistanceがこれまでの入力データからなる
  # 現在の木の構造から計算した数値とあっているか判断
  rootl, rootr = root(l), root(r)
  # 確かめ用
  a = unite(l, r, d)
  if a is not None:
    if a == False:
      flag = False

  """
  ちょっとなにがダメなのかわかんないので確かめる
  if rootl != rootr:
    # lをrにマージする
    if r == rootr:
      dis[rootl] = d - cost(l)
    else:
      dis[rootl] = d - (dis[l] - dis[r]) # (cost(l) - cost(r))
    par[rootl] = r
  else:
    # コストが同じかどうか
    if d == cost(l) - cost(r):
      continue
    else:
      print("No")
      exit()
  """
print("Yes")

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

using namespace std;

const int N = 5 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

struct item {
    int h, p;
    item() = default;
};

int n;
item a[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i].h >> a[i].p;

    return true;
}

void solve() {
    sort(a, a + n, [](item a, item b) { return a.h + a.p < b.h + b.p; });
    auto cmp = [](item a, item b) { return a.p > b.p; };
    multiset<item, decltype(cmp)> S(cmp);
    auto P = 0ll;

    for (int i = 0; i < n; ++i)
        if (a[i].h >= P) {
            S.insert(a[i]);
            P += a[i].p;
        } else {
            auto b = *S.begin();

            if (b.p > a[i].p) {
                S.erase(S.begin());
                S.insert(a[i]);
                P += a[i].p - b.p;
            }
        }

    cout << S.size() << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 512
N = int(input())
info = []
for i in range(N):
    a,b = map(int,input().split())
    d = a + b
    info.append([d,a,b])
info = sorted(info,reverse=True)
score = 0
for i in range(N):
    if i % 2 == 0:
        score += info[i][1]
    elif i % 2 == 1:
        score -= info[i][2]
print(score)

Measured memory_bytes: 24028
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 200010;
char str[maxn];
int n;
int cnt[26];

int main() {
	scanf("%s", str);
	n = strlen(str);
	LL ans = 1;
	for (int i = 0; i < n; i++) {
		int c = str[i] - 'a';
		ans += i - cnt[c];
		cnt[c]++;
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;


int main()
{
    int count = 0, count2 = 0;
    string str;
    cin >> str;

    // 010101...
    for (int i = 0; i < (int)str.length(); i++) {
        // even
        if (i % 2 == 0) {
            if (str[i] != '0') {
                count++;
            }
        } else {
            //odd
            if (str[i] != '1') {
                count++;
            }
        }
    }

    // 101010....
    for (int i = 0; i < (int)str.length(); i++) {
        // even
        if (i % 2 == 0) {
            if (str[i] != '1') {
                count2++;
            }
        } else {
            //odd
            if (str[i] != '0') {
                count2++;
            }
        }
    }

    if (count < count2) {
        cout << count << endl;
    } else {
        cout << count2 << endl;
    }

    return 0;

      
}

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

class Program
{
	static void Main(string[] args)
	{
		// 入力
		string[] input = Console.ReadLine().Split(' ');
        var a = long.Parse(input[0]);
		var b = long.Parse(input[1]);

        long x = a*b;
        long tmp = 0;
 
        // a > b を確認・入替 
        if(a<b){
            tmp = a;
            a = b;
            b = tmp;
        }
 
        // ユークリッドの互除法 
        long r = a % b;
        while(r!=0){
            a = b;
            b = r;
            r = a % b;
        }

        Console.WriteLine(x/b); 
	}
}

Measured memory_bytes: 13140
import collections

N=int(input())
L,R=[0]*N,[0]*N
for i,a in enumerate(input().split()):
  L[i],R[i]=i+int(a)+1,i+1-int(a)

l=collections.Counter(L)
r=collections.Counter(R)
t=0
for i in l.keys():
  t+=l[i]*r[i]

print(t)


Measured memory_bytes: 56976
import sys

if __name__ == '__main__':
    ord_a = ord('a')
    s = [ord(c) - ord_a for c in input()]
    k = int(input())
    for x in s[:-1]:
        if 25 - x < k:
            sys.stdout.write('a')
            k -= (26 - x) % 26
        else:
            sys.stdout.write(chr(ord_a + x))
    print(chr((s[-1] + k) % 26 + ord_a))


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

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string a,b;cin>>a>>b;
  int x=stoi(a+b);
  //cout<<x<<endl;
  for(int i=1;i<=1000;i++){
    if(i*i==x){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int montes[10];
    for (int i=0;i<10;i++){
    cin>>montes[i];}
    vector<int> montanas (montes, montes+10);
    sort (montanas.begin(), montanas.end());
    for (int i=9;i>6;i--){
    cout<<montanas[i]<<endl;}

    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#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 REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 200005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  ll X;
  IN(X);
  vl prime(ARRAY, 0);
  FOR(p, 2, ARRAY) {
    if (prime[p] == -1) continue;
    if (p >= X) {
      PRINT(p);
      return 0;
    }
    ll np = p;
    while(np < ARRAY) {
      prime[np] = -1;
      np += p;
    }
  }

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
using namespace std;
typedef long double LD;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using P=pair<int,int>;

int main() {
    double a,b,h,m; cin>>a>>b>>h>>m;
    double sita = (abs((h+m/60)/12-m/60)*2*M_PI); 
    sita = min(sita, 2 * M_PI - sita);
    double s = cos(sita);
    double x = sqrt(b*b+a*a-2*b*a*s);
    
    cout<<setprecision(20)<<x<<endl;
}

Measured memory_bytes: 4144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
   ll h, w; cin >> h >> w;
   if(h==1 && w==1) cout << 1 << ln;
   else if(h==1 || w==1){
       cout << max(h, w) - 2 << ln;
   }else{
       cout << (h-2) * (w-2) << ln;
   }
}


Measured memory_bytes: 3576
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b, c] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const res = _ => {
  if (b - a === c - b) return 'YES'
  return 'NO'
}

console.log(res())


Measured memory_bytes: 7372
// SeeAlso: https://atcoder.jp/contests/abc144/tasks/abc144_b

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {

    int n;
    cin >> n;

    int temp[10][10];

    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            temp[i][j]=i*j;
        }
    }

    bool flag = false;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(temp[i][j]==n) {
                flag = true;
            }
        }
    }

    print(flag?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <complex>
#include <iostream>
using namespace std;
 
typedef complex<double> P;
 
// ??¨?±?????????????????
#define EPS (1e-10)
// 2??????????????????????????????????????????
#define EQ(a,b) (abs((a)-(b)) < EPS)
 
// ?????? (cross product) : a??b = |a||b|sin??
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
 
// 2???´?????????????????? : a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}
 
int main(){
    int n;
    double x1,x2,x3,x4,y1,y2,y3,y4;
 
    cin >> n;
    for(int i=0 ; i<n ; i++){
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        P a(x1,y1), b(x2,y2), c(x3,y3), d(x4,y4);
        if( is_parallel(a,b,c,d) ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1224
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    string s;
    cin >> s;
    vector<char> trans;
    char prev = '#';
    rep(i, s.size()) {
        if (prev == 'B' && s[i] == 'C')
            trans[trans.size() - 1] = 'D';
        else
            trans.push_back(s[i]);
        prev = s[i];
    }

    bool judge = 0;
    ll cnt = 0;
    ll sum = 0;
    rep(i, trans.size()) {
        if (!judge && trans[i] == 'A')
            judge = 1, cnt++;
        else if (judge) {
            if (trans[i] == 'A')
                cnt++;
            else if (trans[i] == 'D')
                sum += cnt;
            else
                judge = 0, cnt = 0;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int  r=1e6+5;
ll ma[r];
bool pr[r];
void se(){

   pr[0]=0;
   pr[1]=0;

   for(int i=2;i<=1000000;i++){
    pr[i]=1;
   }

   for(int i=2;i<=1000000;i++){
     if(!pr[i]){
        continue;
     }
     for(int j=i;j<=1000000;j=j+i){
        pr[j]=0;
        ma[j]=i;
     }
      pr[i]=1;
   }

}

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

// Function to find gcd of array of
// numbers
int gcd(ll arr[], ll n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}


int main()
{
ll n;
cin>>n;
se();
ll arr[n+1];

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


ll k=gcd(arr,n);

if(k!=1){
    cout<<"not coprime";
}
else{
 map<ll,ll>m;
 int ok=1;
for(int i=0;i<n;i++){
   set<ll>s;
   int num=arr[i];
   while(num>1){
     s.insert(ma[num]);
     num/=ma[num];
   }

   for(auto x:s){
      if(m[x]==1){
        ok=0;
        break;
      }
      else{
        m[x]=1;
      }
   }
   if(ok==0){
    break;
   }

}

if(ok==0){
    cout<<"setwise coprime";
}
else{

    cout<<"pairwise coprime";

}


}






}


Measured memory_bytes: 20224
import collections as c
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
b = 0
mod = [0]
def s(x):
    return x*(x-1) / 2
for i in a:
    b = (b+i) % m
    mod.append(b)
counter = c.Counter(mod)
list = counter.values()
for i in list:
    ans += s(i)
print(int(ans))

Measured memory_bytes: 16540
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();

		int Y = sc.nextInt();

		int Z = sc.nextInt();

		int ans = 0;

		X -= Z;

		ans = X/(Y+Z);

		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  LL N;
  cin>>N;
  LL ans=0;
  ans += N/11*2;
  N %= 11;
  if(N>6) ans += 2;
  else if(N>0) ans += 1;

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


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

int main()
{
    ll a,b,sum=1,sum1=0;
    cin>>a;
    vector<int>v;
    for(int i=0; i<a; i++)
    {
        cin>>b;
        v.push_back(b);
    }
    for(int i=0; i<a-1; i++)
    {
        for(int j=i+1; j<a && j!=i; j++)
        {
            sum1=sum1+v[i]*v[j];

        }
    }
    cout<<sum1<<endl;
}



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

int n;
int A[2000001];
int B[2000001];
int C[10001];
int main(){
  int i,j;
  int k=10000;

  scanf("%d",&n);

  i=1;
  while(i<n+1){ 
    scanf("%d",&A[i]);
    i++;
  }



  for(i=0;i<k+1;i++) C[i]=0;

  for(j=1;j<n+1;j++) C[A[j]]++;

  for(i=1;i<k+1;i++) C[i]=C[i]+C[i-1];
 
  for(j=1;j<n+1;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<n+1;i++){
    printf("%d",B[i]);
    if(i<n)printf(" ");
    else printf("\n");

  }

  return 0;
}

Measured memory_bytes: 16268
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
map<int,int> m;

void solve(){
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	if(n%2){
		cout<<b[n/2]-a[n/2]+1<<endl;
	}
	else{
		cout<<b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1<<endl;
	}
}

int32_t main(){
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 6752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int K; cin >> K;
  string S; cin >> S;
  int N = sz(S);
  if(N<=K) cout << S << endl;
  else{
    cout << S.substr(0,K) << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void) {
    double a;
    
    while(cin >> a) {
        double s = 0;
        double A[10 + 1] = {};
        
        A[1] = a;
        
        for(int i = 2; i <= 10; ++i) {
            if(i % 2 == 0)   A[i] = A[i - 1] * 2;
            else   A[i] = A[i - 1] / 3;
        }
        
        for(int i = 1; i <= 10; ++i) {
            s += A[i];
        }
        
        printf("%.8lf\n", s);
    }
    
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

typedef struct UnionFind{
  vector<int> par;
  vector<int> treerank;
  
  UnionFind(int n){
    par.resize(n); treerank.resize(n);
    rep(i, n) par[i] = i, treerank[i] = 0;
  }
  
  int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(treerank[x] < treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) treerank[x]++;
    par[y] = x;
    return;
  }
  
  bool same(int x, int y){
    return find(x) == find(y);
  }
}UF;

int main(){
    int n, m; cin >> n >> m;
    int k[n];
    vector<int> l[n];
    rep(i, n){
        cin >> k[i];
        rep(j, k[i]){
            int tl; cin >> tl;
            l[i].push_back(tl);
        }
    }
    int ksum[n];
    ksum[0] = m;
    rep(i, n-1) ksum[i+1] = ksum[i] + k[i];
    UF uf(ksum[n-1]+l[n-1].size());
    rep(i, n)rep(j, l[i].size()){
        if(j < l[i].size()-1) uf.unite(ksum[i]+j, ksum[i]+j+1);
        uf.unite(l[i][j]-1, ksum[i]+j);
    }
    rep(i, n-1){
        if(!uf.same(ksum[0], ksum[i+1])){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<stack>
using namespace std;
int dx[8]={0,1,1,1,0,-1,-1,-1};
int dy[8]={-1,-1,0,1,1,1,0,-1};
int main()
{
	int n,m;
	while(cin>>n>>m,n) 
	{
		int f[m][n];
		for(int i = 0; i < m; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin>>f[i][j];
			}
		}

		int ans=0;
		for(int i = 0; i < m; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				if(f[i][j]==1)
				{
					ans++;
					stack<int> xs,ys;
					xs.push(j); ys.push(i);
					while(!xs.empty()) 
					{
						int x=xs.top(),y=ys.top();
						xs.pop(); ys.pop();
						f[y][x]=0;
						for(int k = 0; k < 8; ++k)
						{
							int nx=x+dx[k],ny=y+dy[k];
							if(0<=nx&&nx<n&&0<=y&&y<m&&f[ny][nx]==1)
							{
								xs.push(nx); ys.push(ny);
							}
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
int x[520][520];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>x[i][j];
		}
	}
	vector<int> a;
	vector<int> b;
	vector<int> c;
	vector<int> d;
	for(int i=0;i<n;i++){
		for(int j=0;j<m-1;j++){
			if(x[i][j]%2!=0){
				x[i][j]--;
				x[i][j+1]++;
				a.push_back(i);
				b.push_back(j);
				c.push_back(i);
				d.push_back(j+1);
			}
		}
	}
	for(int i=0;i<n-1;i++){
		if(x[i][m-1]%2!=0){
			x[i][m-1]--;
			x[i+1][m-1]++;
			a.push_back(i);
			b.push_back(m-1);
			c.push_back(i+1);
			d.push_back(m-1);
		}
	}
	cout<<a.size()<<endl;
	for(int i=0;i<a.size();i++){
		cout<<a[i]+1<<" "<<b[i]+1<<" "<<c[i]+1<<" "<<d[i]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 5348
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+10;
const ll mod=1e9+7;
ll a=1,c=0;
char s[N*4];
int main()
{
    int n,r;
    cin>>n>>r;
    if(n>=10) cout<<r<<endl;
    else cout<<100*(10-n)+r<<endl;
    return 0;
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int n;
	cin>>n;
	vector<int> d1(n);
	vector<int> d2(n);
	REP(i,n){
		cin>>d1[i]>>d2[i];
	}
	REP(i,n-2){
		if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

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

using namespace std;

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    long long N, Y;
    cin >> N >> Y;
    
    long long x, y, z;
    
    x = Y / 10000;
    y = (Y - x * 10000) / 5000;
    z = (Y - x * 10000 - y * 5000) / 1000;
    
    while (x + y + z < N) {
        long long n = x + y + z;
        
        if (x > 0) {
            x -= 1;
            if (N - n < 9) {
                y += 2;
            } else {
                z += 10;
            }
        } else if (y > 0) {
            y -= 1;
            z += 5;
        } else {
            break;
        }
    }
    
    if (x >= 0 && y >= 0 && z >= 0 && x + y + z == N) {
        cout << x << " " << y << " " << z << endl;
    } else {
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>


int main(void) {
 
	int S,h,m,s;
	
	scanf("%d", &S);

	h=S/3600;
	m=(S-h*3600)/60;
	s=(S-h*3600-m*60);
	printf("%d:%d:%d\n", h, m, s);


 
	
return 0;

}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,x;

    cin >> n >> x;

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

    vector<ll> sum(n+1,0);

    for(int i = 1; i < n+1; i++){
        sum[i] = sum[i-1] + a[i-1];
    }

    if(n == 1){
        cout << a[0]*5 + 2*x << endl;
        return 0;
    }

    ll ans = INF;

    for(int i = n-2; i >= 0; i -= 2){
        ll pn = (n - i)/2;
        ll tmpans = x*(n + pn) + (sum[n] - (i >= 0? sum[i] : 0))*5;
        ll t1 = tmpans;
        ll c = 2;
        for(int j = i; j >= 0; j -= pn){
            t1 += (5+c)*(sum[j] - (j-pn >= 0? sum[j-pn] : 0));
            c += 2;
        }
        if(t1 > 0){
            ans = min(ans,t1); //best result must be positive number
        }
        if(i > 0){
            ll t2 = tmpans + x + a[i-1]*5;
            c = 2;
            for(int j = i-1; j >= 0; j -= pn){
                t2 += (5+c)*(sum[j] - (j-pn >= 0? sum[j-pn] : 0));
                c += 2;
            }
            if(t2 > 0){
               ans = min(ans,t2); //best result must be positive number
            }
        }
    }

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

Measured memory_bytes: 3456
import itertools

N = int(input())
MARCH = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    temp = input()
    if temp[0] in MARCH.keys():
        MARCH[temp[0]] += 1
ans = 0
for comb in list(itertools.combinations(MARCH.values(), 3)):
    temp2 = 1
    for i in comb:
        temp2 *= i
    ans += temp2
    
print(ans)

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

int main(){

    unsigned int N;
    string S;
    int flag = 0;

    cin >> N;
    cin >> S;

    if(N % 2 != 0){
        cout << "No" << endl;
        return 0;
    }

    for(int i=0; i<N/2; i++){
        if(S[i] != S[i+N/2]) flag =1;
    }

    if(flag == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        dp[i][j] += dp[i-1][j-1]*p[i-1]
        dp[i][j] += dp[i-1][j]*(1-p[i-1])
print(sum(dp[-1][-(-n//2):]))


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

using namespace std;
typedef long long ll;

ll perform(ll a, ll b){
  if(a > b) swap(a,b);
  assert(a != 0);
  ll x = b / a;
  if(b % a == 0){
    return (2 * x - 1) * a;
  }
  return 2 * x * a + perform(a, b%a);
}

int main(){
  ll N; cin >> N;
  ll X; cin >> X;
  cout << N + perform(X, N-X) << "\n";
}


Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()

ans = 1
for i in range(1, n + 1):
    ans *= i
    ans %= MOD

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	double a,b;
	while(cin>>a>>b)
	{
		double s,s1;
		s=int((a+b)/2);
		s1=(a+b)/2;
		if(s==s1)cout<<s<<endl;
		else cout<<s+1<<endl;
		
	}
	 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,p,d,w,s,i;
  while(scanf("%d %d %d",&n,&m,&p),n){
    for(i=s=0;i<n;i++){
      scanf("%d",&d);
      if(i==m-1)w=d;
      s+=d;
    }
    printf("%d\n",w?s*(100-p)/w:0);
  }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main() {
  int S, h, m, s;
  scanf("%d", &S);
  h = S / 3600;
  m = (S % 3600) / 60;
  s = S % 60;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}


Measured memory_bytes: 2076