akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+5;
string s[N];
string t[N];
map<string,int>mp;
ll sum;
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        mp[s[i]]++;
        if(mp[s[i]]>sum) sum=mp[s[i]];
    }
    map<string,int>::iterator fir;
    fir=mp.begin();
    int j=0;
    while(fir!=mp.end())
    {
        if(fir->second==sum) t[j++]=fir->first;
        fir++;
    }
    //cout<<j<<endl;
    sort(t,t+j);
    for(int i=0;i<j;i++)
    {
        cout<<t[i]<<endl;
    }
//    sort(s,s+n);
//    string s1,t;
//    int sum=1;
//    s1=s[0];
//    cout<<endl;
//    for(int i=1;i<n;i++)
//    {
//        cout<<s[i]<<endl;
//    }
//    cout<<sum;
    return 0;
}


Measured memory_bytes: 28288
#include <bits/stdc++.h>
using namespace std;
int main(){
	int M, D;
	cin>>M>>D;
	int res = 0;
	for(int m = 1; m <= M; ++m){
		for(int d = 1; d <= D; ++d){
			int r = d % 10;
			int l = d / 10;
			if(r >= 2 && l >= 2 && r * l == m){
				res++;				
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
s = gets.chomp
count_ac = [0]
s.each_char.with_index do |c, i|
  count_ac[i + 1] = count_ac[i]
  count_ac[i + 1] += 1 if 0 < i &&  c == 'C' && s[i - 1] == 'A'
end

q.times do
  l, r = gets.split.map(&:to_i)
  puts count_ac[r] - count_ac[l]
end


Measured memory_bytes: 3452
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int idx=0;
    if((idx=s.indexOf('C'))!=-1){
      if(s.indexOf('F',idx)!=-1){
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>
int main(void){
   double q;
   while(scanf("%lf", &q)!=EOF) {
       if(q==-1)
       break;
       double x, a;      
       x=q/2;      
           while(1){
               if(fabs(x*x*x-q)<0.00001*q) 
               break;
               x=x-((x*x*x-q)/(3*x*x));
               x = x;
           }          
           printf("%.6f\n",x);    
           }
       return 0;
}


Measured memory_bytes: 2036
use proconio::input;

fn main() {
    input! {
        a: [u16; 3]
    }

    solve(&a);
}

fn solve(a: &[u16]) {
    let sum = a.iter().fold(0, |s, x| s + x);
    match sum.cmp(&22) {
        std::cmp::Ordering::Less => println!("win"),
        _ => println!("bust"),
    }
}


Measured memory_bytes: 2104
# coding: utf-8
# Your code here!
n=int(input())
d=input().split(" ")
for i in range(n):
   d[i]=int(d[i])
s=sorted(d,reverse=False)
#print(s)
ans=0
for i in range(n):
    ans=ans+s[i]
    if not i==0:
        ans=ans/2
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
 
int myabs(int a) {
    return a<0?-a:a;
}
 
int mymax(int a,int b) {
    return a>=b?a:b;
}
 
int getCost(int sx,int sy,int tx,int ty) {
    int dx=myabs(sx-tx);
    int dy=myabs(sy-ty);
    if((sx-tx)*(sy-ty)>=0) {
        return mymax(dx,dy);
    } else {
        return dx+dy;
    }
}
 
int main(void) {
    int N,i;
    int x,y;
    int answer=0;
    scanf("%*d%*d%d",&N);
    scanf("%d%d",&x,&y);
    for(i=1;i<N;i++) {
        int next_x,next_y;
        scanf("%d%d",&next_x,&next_y);
        answer+=getCost(x,y,next_x,next_y);
        x=next_x;
        y=next_y;
    }
    printf("%d\n",answer);
    return 0;
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int a,p; cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#include <iostream>

#define MAX_N 100

int n;
double x[MAX_N], y[MAX_N];

double norm( int p ) {
    double res = 0;

    for ( int i=0; i<n; ++i ) {
        res += pow( fabs( y[i] - x[i] ), p );
    }
    if ( p == 2 ) {
        res = sqrt( res );
    } else if ( p == 3 ) {
        res = cbrt( res );
    }
    return res;
}

double inftynorm() {
    double res = 0;
    for ( int i=0; i<n; ++i) {
        res = std::max( res, fabs(x[i] - y[i]) );
    }
    return res;
}

int main() {
    std::cin >> n;
    for (int i=0; i<n; ++i) std::cin >> x[i];
    for (int i=0; i<n; ++i) std::cin >> y[i];

    printf("%lf\n", norm(1));
    printf("%lf\n", norm(2));
    printf("%lf\n", norm(3));
    printf("%lf\n", inftynorm());
    return 0;
}



Measured memory_bytes: 3444
Num_seg = [[0,1,1,1,1,1,1],[0,0,0,0,1,1,0],[1,0,1,1,0,1,1],[1,0,0,1,1,1,1],[1,1,0,0,1,1,0],[1,1,0,1,1,0,1],[1,1,1,1,1,0,1],[0,1,0,0,1,1,1],[1,1,1,1,1,1,1],[1,1,0,1,1,1,1]]
while True:
    n = int(input())
    if n == -1:
        break
    num_b = int(input())
    seg = ""
    for h in range(7):
        seg = seg + str(Num_seg[num_b][h])
    
    print(seg)
    for i in range(n - 1):
        num_a = int(input())
        seg = ""
        for j in range(7):
            if Num_seg[num_b][j] == Num_seg[num_a][j]:
                seg = seg + "0"
            else:
                seg = seg + "1"
        num_b = num_a
    
        print(seg)

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

using namespace std;

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  int A[M];
  for (int i = 0; i < M; i++){
    cin >> A[i];
  }

  int ans = 0;
  for (int i = 0; i < M; i++){
    if (A[i] > X){
      ans = min(ans, M - i);
      break;
    }else{
      ans++;
    }
    
  }
  
  printf("%d\n", ans);
  
}


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <limits>

using namespace std;

int main() {
    int card_num, gate_num; cin >> card_num >> gate_num;
    vector<pair<int, int>> available;
    for (int i = 0; i < gate_num; ++i) {
        int f, s; cin >> f >> s;
        pair<int, int> range{f, s};
        available.push_back(range);
    }
    
    pair<int, int> ans_range = pair<int, int>{0, numeric_limits<int>::max()};
    for (const auto& range : available) {
        if (range.first > ans_range.first) {
            ans_range.first = range.first;
        }
        if (range.second < ans_range.second) {
            ans_range.second = range.second;
        }
    }
    
    if (ans_range.second < ans_range.first) {
        cout << 0 << endl;
        return 0;
    }
    
    cout << ans_range.second - ans_range.first + 1 << endl;
    
}

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

int main() {
  std::cout<<std::fixed<<std::setprecision(10);
  ll n,k;
  cin>>n>>k;
  ll p[n];
  ll res=0;
  ll max_res=0;
  for(int i=0;i<n;i++){
    cin>>p[i];
    res+=p[i];
    if(i>=k-1){
      max_res=max(max_res,res);
      res-=p[i-k+1];
    }
  }
  double r=(max_res+k)/2.0;
  cout<<r<<endl;
  return 0;
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, ll> s_map;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    s_map[s]++;
  }
  ll ans = 0;
  for (auto& e : s_map) {
    if (e.second > 1) {
      ans += e.second * (e.second - 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1;i <= n;i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int N;
const int MAX = 2.0e5 + 100;
int P[MAX];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> P[i];

    int ans = 1;
    int mn = P[0];
    for (int i = 1; i < N; i++) {
        if (mn >= P[i]) {
            ans++;
            mn = P[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 998244353;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int powmod(int a, int p, int mod) {
    int ans = 1;
    int mul = a;

    for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
        if ((p & 1) == 1) ans = (ans * mul) % mod;
    }

    return ans;
}

signed main() {
    int N;
    cin >> N;
    map<int, int> m;
    int mx = -1;
    for (int i =0; i < N; i++) {
        int a;
        cin >> a;

        if (i == 0) {
            if (a != 0) {
                cout << 0 << endl;
                return 0;
            }
        }

        m[a]++;
        mx = max(mx, a);
    }

    if (m[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    int ret = 1;
    for (int i = 1; i <= mx; i++) {
        ret *= powmod(m[i-1], m[i], MOD);
        ret %= MOD;
    }
    cout <<ret << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  REP(i, N) cin >> X[i];
  ll ans = 0;
  REP(i, N - 1) ans += min((X[i + 1] - X[i]) * A, B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>

std::set<std::string> all;
int main() {
    int n;
    scanf("%d",&n);
    std::string temp;
    while(n--){
        std::cin>>temp;
        if(all.find(temp)==all.end()) all.insert(temp);
    }
    printf("%d",all.size());
}

Measured memory_bytes: 19316
import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,p,d = map(int,input().split())
    MOD = 10**9+7
    N = p+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD
 
    print((comb(p+1,d+1)-comb(p+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ll j = 1;
    while (i * j <= n) {
      if (i * j < n) {
        ans++;
      }
      j++;
    }
  }

  cout << ans << '\n';
  return 0;
}

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


#define ll long long
#define MOD 1000000007



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

    vector<pair<ll,ll>> sch(n);

    ll x,l;
    for(int i=0;i<n;i++){
        cin>>x>>l;
        sch.at(i).second=x-l;
        sch.at(i).first=x+l;
    }

    sort(sch.begin(),sch.end());


    ll cd=sch.at(0).first,co=1;
    for(int i=0;i<n;i++){
        if(sch.at(i).second<cd)continue;
        cd = sch.at(i).first;
        co++;
    }

    cout<<co<<endl;


}

Measured memory_bytes: 4844
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, P; cin >> N >> P;
    bool even(false);
    REP(i, N){
        int A; cin >> A;
        if(A % 2) even = true;
    }
    if(!even){
        if(P){
            cout << 0 << endl;
        }else{
            cout << (1LL << N) << endl;
        }
    }else{
        cout << (1LL << (N-1)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int s1,s2,s3;

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int p[n];
  r(i,n){
    cin>>p[i];
    if(p[i]<=a)s1++;
    else if(b+1<=p[i])s3++;
    else s2++;
  }
  cout<<min(s1,min(s2,s3))<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10001;
int n, x;
int A[MAX], B[MAX];
bool V[MAX];

int solve()
{
    int T[VMAX];
    int ans = 0;

    for (int i = 0; i != n; ++i)
    {
        B[i] = A[i];
        V[i] = false;
    }

    sort(B, B+n);

    for (int i = 0; i != n; ++i)
    {
        T[B[i]] = i;
    }

    for (int i = 0; i != n; ++i)
    {
        if (V[i]) continue;
        int s = 0;
        int an = 0;
        int cur = i;
        int m = VMAX;

        while (true)
        {
            int v = A[cur];   
            V[cur] = true;
            ++an;
            m = min(m, v);
            s += v;
            cur = T[v];
            
            if (V[cur] == true) break;
        }
        ans += min(s +(an -2) * m, s + m + (an + 1) * x);
    }
    return ans;
}

int main()
{
    cin >> n;

    x = VMAX;

    for (int i = 0; i != n; ++i)
    {
        cin >> A[i];
        x = min(A[i], x);
    }

    cout << solve() << endl;

    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	if (S == "SUN") cout << 7 << endl;
	else if (S == "MON") cout << 6 << endl;
	else if (S == "TUE") cout << 5 << endl;
	else if (S == "WED") cout << 4 << endl;
	else if (S == "THU") cout << 3 << endl;
	else if (S == "FRI") cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

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

int main(){
    string o,e;
    cin >> o >> e;
    for(int i=0; i<e.length(); i++){
        cout << o.at(i) << e.at(i);
    }
    if(o.length()!=e.length()) cout << o.at(o.size()-1);
    cout << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b;




}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int k;
    cin >> k;
    int cnt = 1;
    int now = 7 % k;
    int copy = k +10;
    while(copy--){
        if(now == 0) break;
        now = (now * 10 + 7) % k;
        cnt++;
    }
    if(now == 0) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
  int n,m;
  while(cin >> n >> m && (n|m)){
    double a[100][100], dp[2][100];
    for(int i=0;i<n;i++){
      dp[0][i] = 1.0;
      dp[1][i] = -1.0;
      for(int j=0;j<n;j++) cin >> a[i][j];
    }

    for(int i=0;i<m-1;i++){
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          dp[1][k] = max(dp[1][k], dp[0][j] * a[j][k]);
        }
      }
      for(int j=0;j<n;j++){
        dp[0][j] = dp[1][j];
        dp[1][j] = -1.0;
      }
    }

    double ans = -1.0;
    for(int i=0;i<n;i++) ans = max(ans,dp[0][i]);
    printf("%.2f\n",ans);
  }
}

Measured memory_bytes: 1324
#include <iostream>

using namespace std;

int main(){
    int M, K;
    while(cin >> M >> K){
        if(M==1){
            cout << (K==0 ? "0 0 1 1" : "-1") << endl;
        } else if(K >= (1<<M)){
            cout << -1 << endl;
        } else {
            for(int i=0;i<(1<<M);i++){
                if(i != K) cout << i << " ";
            }
            cout << K << " ";
            for(int i=(1<<M)-1;i>=0;i--){
                if(i != K) cout << i << " ";
            }
            cout << K << endl;
        }
    }
}

Measured memory_bytes: 1792
import math
N, K = map(int, input().split())
if K == 1:
  print(1)
  exit()

ans = 0

for i in range(1, N + 1):
  if i >= K:
    ans += (1 / N)
  else:
    temp = math.log(K / i, 2)
    nu = pow(2, math.ceil(temp))
    ans += (1 / (nu * N))
print(ans)

Measured memory_bytes: 9204
#include<stdio.h>

int main(){
    int h,w,k,i,j,x,y,z,bit1,bit2,tmp1,tmp2,white=0,black=0;
    char chara,c[10][10];
    int ans = 0;
    char flag[10][10] = {0};
    // gyou,retu .. 選ぶ行、列の数
    
    scanf("%d %d %d",&h,&w,&k);
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            scanf(" %c",&c[i][j]);
        }
    }
    
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(c[i][j] == '.') white++;
            if(c[i][j] == '#') black++;
        }
    }
    tmp1 = white;
    tmp2 = black;
    for(int bit1 = 0; bit1 < (1<<h); bit1++){
        for(int bit2 = 0; bit2 < (1<<w); bit2++){
            for(i = 0; i < h; i++){
                if(bit1 & (1<<i)){
                    // 垢に塗る
                    for(x = 0; x < w; x++){
                        if(flag[i][x] != 1){ // 既に垢で塗ってなければ
                            if(c[i][x] == '.'){
                                white--;
                                flag[i][x] = 1;
                            }
                            if(c[i][x] == '#'){
                                black--;
                                flag[i][x] = 1;
                            }
                        }
                    }
                }
            }
            for(j = 0; j < w; j++){
                if(bit2 & (1<<j)){
                    // 垢に塗る
                    for(y = 0; y < h; y++){
                        if(flag[y][j] != 1){ // 既に垢で塗ってなければ
                            if(c[y][j] == '.'){
                                white--;
                                flag[y][j] = 1;
                            }
                            if(c[y][j] == '#'){
                                black--;
                                flag[y][j] = 1;
                            }
                        }
                    }
                }
            }
            if(black == k) ans++;
            white = tmp1;
            black = tmp2;
            for(i = 0; i < h; i++){
                for(j = 0; j < w; j++){
                    flag[i][j] = 0;
                }
            }
        }
    }
    
    printf("%d\n",ans);
    
    
    
    
}


Measured memory_bytes: 1736
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll k[101010];
ll b[101010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin>>N>>K;
    if(K==1)
        cout<<0<<endl;
    else
        cout<<N-K<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>
#include <cmath>

using namespace std;

int main(void)
{
	int n;

	cin >> n;

	for (int i = 0; pow(2, i) < 100; i++)
	{
		int a = pow(2, i);
		int b = 2*a;

		if (a <= n && n < b)
		{
			cout << a << endl;
			break;
		}
	}

	return 0;
}

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

int main(){

  int N;
    cin>>N;
    vector<long long int> A(N),B(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    long long int a=0,b=0;
    for(int i=0;i<N;i++){
        if(A[i]>B[i]) b+=(A[i]-B[i]);
        if(A[i]<B[i]) a+=((B[i]-A[i])/2);
    }
    if(a>=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: u32 = read();

    println!(
        "{}", 
        (0..n)
            .map(|_| read::<u32>().trailing_zeros())
            .min()
            .unwrap()
    );
}


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

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


int main(){
    int n;
    cin >> n;
    vector<pair<double, double>> v(n);

    REP(i,n){
        cin >> v[i].first >> v[i].second;
    }
    vector<int> m(n);
    REP(i,n){
        m[i] = i;
    }
    double sum = 0,ans = 0;
    double a,b,x;
    int cnt = 0;
    do{
        sum = 0;
        cnt ++;
        REP(i,m.size()-1){
            a = v[m[i]].first - v[m[i+1]].first;
            b = v[m[i]].second - v[m[i+1]].second;
            x = (a*a) + (b*b);
            x = sqrt(x);
            sum += x;
        }
        ans += sum;
        
        
        
    }while(next_permutation(m.begin(), m.end()));

    printf("%8f\n",ans/cnt);


}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vector <vector<int>> shop(n,vector <int> (10));
    vector <vector<int>> profit(n,vector <int> (11));
    for (int i=0;i<n;i++) 
    	for (int j=0;j<10;j++) cin >> shop[i][j] ; 
    for (int i=0;i<n;i++) 
    	for (int j=0;j<=10;j++) cin >> profit[i][j] ; 
    int ans=-(1<<30);
	for (int bit=1 ; bit < (1 << 10) ; bit++){
		int cur=0;
		for (int i=0;i<n;i++){
			int c=0;
			for (int j=0;j<10;j++)
				if (((bit>>j)&1) and (shop[i][j])) c++; 
			cur += profit[i][c];
		}
		ans = max(ans,cur);
	}
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
/*
2
1 1 1 1 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

*/


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

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

using namespace std;
typedef long long ll;

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

    int c = -1;

    rep(i, s.length()) {
        if (c == -1 && s[i] == 'C') {
            c = i;
            continue;
        }

        if (c != -1 && s[i] == 'F') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

string s[9], t[3][3];
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 };
int dfs(int p) {
	int res = 0;
	rep(i, 3)rep(j, 3) {
		if (!t[i][j].empty())continue;
		rep(k, 4) {
			rep(l, 4) {
				int nx = i + dx[l], ny = j + dy[l];
				if (nx < 0 || 3 <= nx || ny < 0 || 3 <= ny || t[nx][ny].empty())continue;
				if (abs(s[p][(l + k) % 4] - t[nx][ny][(l + 2) % 4]) != 'a' - 'A')goto g;
			}
			if (p == 8)res++;
			else {
				rep(l, 4)t[i][j] += s[p][(l + k) % 4];
				res += dfs(p + 1); t[i][j].clear();
			}g:;
		}
	}
	return res;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		rep(j, 9)cin >> s[j];
		printf("%d\n", dfs(0));
	}
}

Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        line=br.readLine();
    	line = line.replaceAll("apple", "藤田");
    	line = line.replaceAll("peach", "apple");
    	line = line.replaceAll("藤田", "peach");
    	System.out.println(line);
	}
}

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

using namespace std;

int a, b, c, d;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> a >> b >> c >> d;

    if(d <= a) cout << min(d, a) << "\n";
    else if (d <= a + b) cout << a << "\n";
    else cout << a - (d - (a + b)) << "\n";

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<long long >nos(n,0);
  for(int i=0;i<n;i++){
  	cin>>nos[i];
  }
  sort(nos.rbegin(),nos.rend());
  long long ans=nos[0];
  int rem=n-2,curr=1;
  int mini;
  while(rem>0){
  	mini = min(rem,2);
    ans+=nos[curr]*mini;
    rem-=mini;
    curr++;
  }
  cout<<ans;
}

Measured memory_bytes: 4792
import collections
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    coll = collections.Counter(S)
    maxval = max(coll.values())
    ans = []
    for k,v in coll.most_common():
        if v!=maxval:
            break
        ans.append(k)
    print(*sorted(ans), sep="\n")

main()


Measured memory_bytes: 45028
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        m1: usize,
        d1: usize,
        m2: usize,
        d2: usize,
    }
    
    println!("{}", if d2 == 1 { 1 } else {0});
}


Measured memory_bytes: 4352
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-7-7 21:42:46
# Powered by Visual Studio Code
#

s = gets.chomp
w = gets.to_i
ind = 0
ans = ""
while ind < s.size
  ans += s[ind]
  ind += w
end
puts ans

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


int main(){
  char s[2];
  cin >> s;
  if(s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[0]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

char str[11];
int n;

void dfs(int idx, char c, char highest) {
	str[idx] = c;
	if (idx == n-1) {
		cout << str;
		return;
	}
	for (char a = 'a'; a <= highest + 1; a++) {
		dfs(idx + 1, a, a ==highest+1? highest+1 : highest);
	}
}

int main() {
	cin >> n;
	str[n] = '\n';
	dfs(0, 'a', 'a');
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long int
using namespace std;
const int MOD = (int)1e9 + 7;

int n, l[210], ans = 0;
signed main()
{
  cin >> n;
  for(int i = 0; i < 2 * n; i++)
    cin >> l[i];
  sort(l, l + 2 * n, greater<int>());
  for(int i = 0; i < 2 * n; i += 2)
    ans += l[i + 1];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int N, x, A[105];
int main() {
	scanf("%d %d", &N, &x);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	sort(A, A + N);
	int res = 0;
	for (int i = 0; i < N - 1; i++) {
		if (A[i] > x) break;
		res++;
		x -= A[i];
	}
	if (x == A[N - 1]) res++;
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
N=int(input())
xy=[list(map(int,input().split())) for i in range(N)]
xy.sort()
inf=float("inf")
ans=inf
for i in range(N-1):
    for j in range(i+1,N):
        p=xy[j][0]-xy[i][0]
        q=xy[j][1]-xy[i][1]
        flag=[0]*N
        cnt=0
        for k in range(N):
            if flag[k]==0:
                flag[k]=1
                cnt+=1
                nx,ny=xy[k][0]+p,xy[k][1]+q
                b=bisect_left(xy,[nx,ny])
                while b<N and xy[b]==[nx,ny]:
                    flag[b]=1
                    nx,ny=nx+p,ny+q
                    b=bisect_left(xy,[nx,ny])
        ans=min(ans,cnt)
if N==1:
    print(1)
else:
    print(ans)

Measured memory_bytes: 52664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1000000][3];
int main(){
int n;
cin>>n;
vector<vector<ll>>a(n);
for(int i=0;i<n;i++)
{
    a[i]=vector<ll>(3);
    cin>>a[i][0]>>a[i][1]>>a[i][2];
}
dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];
for(int i=1;i<n;i++){
    for(int j=0;j<=2;j++){
        ll &x=dp[i][j];
        dp[i][j]=0;
        for(int z=0;z<=2;z++){
            if(z==j)continue;
            x=max(x,dp[i-1][z]+a[i][j]);
        }
    }
}
cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
return 0;    
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1e8;
const D EPS = 1e-8;

int main(){
  int n;
  cin >> n;
  vector<pii> a(n);

  rep(i,n){
    cin >> a[i].first;
    a[i].second = i+1;
  }
    
  sort(all(a));

  ll ans = 0;
  set<int> used;
  used.insert(0); used.insert(n+1);

  rep(i,n){
    ll p = a[i].second;
    auto it = used.lower_bound(p);
    ll r = *it;
    it--;
    ll l = *it;

    ans += (r-p) * (p-l) * a[i].first;
    used.insert(p);
  }
  
  cout << ans << endl;
}


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

#define ll long long

using namespace std;


int main(){
    ll N, K, R, S, P;
    string T;
    cin >>N >> K;
    cin >> R >> S >> P;
    cin >> T;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(i < K){
            if(T.at(i) == 'r' ) ans += P;
            else if(T.at(i) == 's') ans += R;
            else ans += S;
        }

        else{
            if(T.at(i) == T.at(i-K)) T.at(i) = 'O';
            else{
                if(T.at(i) == 'r' ) ans += P;
                else if(T.at(i) == 's') ans += R;
                else ans += S;
            }
        }
    }

    cout << ans << endl;

}

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

int main() {
  int N;
  cin >> N;
  rep(i,N){
    string color;
    cin >> color;
    if (color == "Y"){
      cout << "Four" << endl;
      break;
    }else if(i == N-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
//someshsingh22		
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define loop(i,n) for(int i = 0 ; i < n; i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define inp_int(n,arr) int arr[n]; loop(i,n) cin >> arr[i];
#define inp_ll(n,arr) ll arr[n]; loop(i,n) cin >> arr[i];
#define out_int(n,arr) loop(i,n) printf("%d ",arr[i]);
#define out_ll(n,arr) loop(i,n) printf("%lld ",arr[i]); cout << endl;
#define all(c) c.begin(),c.end()
// Snippets : BFS, DFS, edger, ncr, chef, inverse, sieve, lis-d*, mat_d*, pow

typedef long long ll;
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;


int main ()
{
	int a,b; cin >> a >> b;
	if(a>0 && b>0 && a<10 && b<10)
		cout << a*b;
	else
		cout << -1;

	return 0;
}

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 998244353

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N;
  cin >> N;
  ll cnt[N] = {};
  bool valid = true;
  rep(i, N){
    ll d;
    cin >> d;
    if(i == 0 && d != 0) valid = false;
    cnt[d]++;
  }
  if(cnt[0] >= 2) valid = false;
  ll ans = 1;
  repi(i, 1, N) rep(_, cnt[i]) ans = (ans * cnt[i-1]) % MOD;
  cout << (ans * valid) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
struct Edge
{
	int to;
	int nxt;
}e[400005];
int n,m,edgenum,head[200005],size[200005],pa[200005];
ll fact[200005],inv[200005],f[200005],g[200005];
void add(int u,int v)
{
	e[++edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
void dfs(int node)
{
	size[node]=1;
	f[node]=1;
	for(int hd=head[node];hd;hd=e[hd].nxt)
	{
		int to=e[hd].to;
		if(to==pa[node])continue;
		pa[to]=node;
		dfs(to);
		size[node]+=size[to];
		f[node]=f[node]*f[to]%MOD*inv[size[to]]%MOD;
	}
}
void dfs2(int node)
{
	if(node!=1)g[node]=g[pa[node]]*f[pa[node]]%MOD*quick_pow(f[node],MOD-2)%MOD*size[node]%MOD*inv[n-size[node]]%MOD;
	else g[node]=1;
	for(int hd=head[node];hd;hd=e[hd].nxt)
	{
		int to=e[hd].to;
		if(to==pa[node])continue;
		pa[to]=node;
		dfs2(to);
	}
}
int main()
{
	scanf("%d",&n);
	fact[0]=1;
	for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
	for(int i=1;i<=n;i++)inv[i]=quick_pow(i,MOD-2);
	inv[0]=1;
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1);
	dfs2(1);
	for(int i=1;i<=n;i++)printf("%lld\n",f[i]*g[i]%MOD*fact[n-1]%MOD);
	return 0;
}

Measured memory_bytes: 13824
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#pragma endregion

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for(size_t i = 1; i < s.size(); i++) {
        if(s[i - 1] == s[i]) {
            if(s[i] == '0')
                s[i] = '1';
            else
                s[i] = '0';
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#define MAX_N 100
#define INF_COST 2001
#define NO_CONN -1
#define UNKNOWN_ID -1

typedef enum { UNEXPLORED, VISITED, COMPLETED } state_t;
typedef struct { int p, d; state_t s; } vertex_t;

static int prim(int a[MAX_N][MAX_N], int size) {
  vertex_t v[MAX_N];
  int i, u, min, sum;

  for (i = 0; i < size; ++i) {
    v[i].p = UNKNOWN_ID;
    v[i].d = INF_COST;
    v[i].s = UNEXPLORED;
  }

  u = 0;
  v[u].d = 0;

  while (1) {
    min = INF_COST;
    for (i = 0; i < size; ++i) {
      if (v[i].s != COMPLETED && v[i].d < min) {
        min = v[i].d;
        u = i;
      }
    }
    if (min == INF_COST) break;
    v[u].s = COMPLETED;
    for (i = 0; i < size; ++i) {
      if (v[i].s != COMPLETED && a[u][i] != NO_CONN && a[u][i] < v[i].d) {
        v[i].d = a[u][i];
        v[i].p = u;
        v[i].s = VISITED;
      }
    }
  }

  for (sum = i = 0; i < size; ++i) {
    if (v[i].p != UNKNOWN_ID) sum += v[i].d;
  }

  return sum;
}

int main(int argc, char **argv) {
  int n, i, j, a[MAX_N][MAX_N];

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

  printf("%d\n", prim(a, n));
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count = 0;
  if(S.at(0) == '1'){
    count++;
  }
  if(S.at(1) == '1'){
    count++;
  }
  if(S.at(2) == '1'){
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3600
public class Main{
  static long mod = 1000000007;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    long m, n;

    m = sc.nextInt();
    n = sc.nextInt();
    System.out.println(power(m, n));

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static long power(long m, long n){
    long q, r;

    if(n == 1)return m;
    else{
      q = n / 2;
      r = n % 2;
      if(r == 0)return (power(((m * m) % mod), q)) % mod;
      else return ((power(((m * m) % mod), q)) * m) % mod;
    }

  }
}

Measured memory_bytes: 17236
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n, m; cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<string> b(m);
  for (int i = 0; i < m; ++i) cin >> b[i];

  for (int i = 0; i <= n - m; ++i) {
    for (int j = 0; j <= n - m; ++j) {
      bool isTemplate = true;
      for (int k = 0; k < m; ++k) {
        if (a[i + k].substr(j, m) != b[k]) isTemplate = false;
        if (!isTemplate) break;
      }

      if (isTemplate) flag = true;
      if (flag) break;
    }
    if (flag) break;
  }

  
  // cout << num << endl;
  cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)

cnt = 0
for i in range(0,N):
	if not S[i] == S[N-1-i]:
		cnt = 1

for i in range(0,(N-1)//2):
	if not S[i] == S[(N-1)//2-1-i]:
		cnt = 1
	
for i in range((N+3)//2,(N-1)//2):
	if not S[i] == S[(N+3)//2-1-i]:
		cnt = 1
		
if cnt == 1:
	print("No")
else:
	print("Yes")

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

int m, g, n;
vector<int> A, B;
long long dp[10][8000];

long long solve(int k, int sum, int goal) {
    if (0 <= dp[k][sum]) {
        return dp[k][sum];
    }
    if (sum == goal) {
        return 1;
    }
    if (goal < sum || (int)A.size() <= k) {
        return 0;
    }
    long long ret = 0;
    for (int i=0; i<=B[k]; ++i) {
        ret += solve(k+1, sum + A[k] * i, goal);
    }
    return dp[k][sum] = ret;
}

int main() {
    while (cin >> m, m) {
        A.resize(m);
        B.resize(m);
        for (int i=0; i<m; ++i) {
            cin >> A[i] >> B[i];
        }
        cin >> g;
        for (int i=0; i<g; ++i) {
            cin >> n;
            memset(dp, -1, sizeof dp);
            cout << solve(0, 0, n) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1836
#include<stdio.h>                                                 
#include<string.h>                                                
int main(void){                                                   
   char s[3];                                                     
   int cntA,cntB;                                                 
   scanf("%s",s);                                                 
                                                                  
   cntA = cntB = 0;                                               
   for(int i = 0; i < 3; i++){                                    
      if(s[i] == 'A'){                                            
         cntA++;                                                  
      }else{                                                      
         cntB++;                                                  
      }                                                           
   }                                                              
   if(cntA >= 1 && cntB >= 1){                                    
      printf("Yes");                                              
   }else{                                                         
      printf("No");                                               
   }                                                              
   return 0;                                                      
} 

Measured memory_bytes: 1736