akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    long long res;
    res = 0;
    res += (N / (A + B)) * A;
    if(N % (A + B) > A) {
        res += A;
    } else {
        res += N % (A + B);
    }
    cout << res << endl;
}

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

int main(void){
  string W;
  string T;
  vector<string> Ti;
  int words = 0;
  int wordCnt = 0;
  cin >> W;
  while(1){
	cin >> T;
	Ti.push_back(T);
	if(Ti[words] == "END_OF_TEXT"){
	  break;
	}
	words++;
  }
  for(int i = 0; i < W.length(); i++){
	if(isupper(W[i])){
	  W[i] = tolower(W[i]);
	}
  }
  for(int i = 0; i < words; i++){
	for(int j = 0; j < Ti[i].length(); j++){
	  if(isupper(Ti[i][j])){
		  Ti[i][j] = tolower(Ti[i][j]);
	  }
	}
  }
  for(int i = 0; i < words; i++){
	if(Ti[i] == W){
	  wordCnt++;
	}
  }
  cout << wordCnt << endl;
  
  return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n, ans=0, now, count=1;
    cin >> n;
    cin >> now;
    for (int i = 1; i < n; i++) {
        int t;
        cin >> t;
        if (now == t) count++;
        else {
            ans += count / 2;
            count = 1;
        }
        now = t;
    }
    ans += count / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
a=[0]*N
for i in range(K):
    d=int(input())
    H=list(map(int,input().split()))
    for j in H:
        a[j-1]+=1
count=0
for i in range(N):
    if a[i]==0:
        count+=1
print(count)

Measured memory_bytes: 9184
#include <stdio.h>
int n;
long long a[100001];
long long r[100001];
long long b[100001];
long long x, ans;
int main() {
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) {
		scanf("%lld", a + i);
	}
	r[n] = a[n];
	for (int i = n - 1; i >= 0; i--) {
		r[i] = r[i + 1] + a[i];
	}
	if (n == 0) {
		if (a[0] == 1)printf("1\n");
		else printf("-1\n");
		return 0;
	}
	if (a[0] != 0) {
		printf("-1\n");
		return 0;
	}
	b[0] = 1;
	for (int i = 1; i <= n; i++) {
		x = b[i - 1] * 2;
		if (x < a[i]) {
			printf("-1\n");
			return 0;
		}
		if (r[i] < x)x = r[i];
		b[i] = x - a[i];
		ans += b[i] + a[i];
	}
	printf("%lld\n", ans + 1);
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);

    float sum;
    for(int i=0; i<N; i++){
        cin >> p[i];
        sum += p[i];
    }

    float M = *std::max_element(p.begin(), p.end());
    sum -= M / 2;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/4;
    public static final int inf = Integer.MAX_VALUE/4;

    static void solve(InputReader in, PrintWriter out){
        char[][] a = new char[3][3];
        for (int i = 0; i < 3; i++) {
            a[i] = in.ns().toCharArray();
        }
        out.print(a[0][0]);
        out.print(a[1][1]);
        out.println(a[2][2]);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

using namespace std;

typedef long long ll;

ll n, m;
pair<int, int> ab[500000];
ll ans = 0;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab, ab + n);
    for (int i = 0; i < n; i++)
    {
        while (m > 0)
        {
            ans += ab[i].first;
            ab[i].second--;
            m--;
            if (ab[i].second == 0)
                break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        char[] s = sc.nextLine().toCharArray();
        sc.close();

        int[] wCnt = new int[n];
        int[] eCnt = new int[n];
        for(int i=0; i<n; i++) {
            if(s[i] == 'W') {
                wCnt[i]++;
            } else {
                eCnt[i]++;
            }
            if(i != 0) {
                wCnt[i] += wCnt[i-1];
                eCnt[i] += eCnt[i-1];
            }
        }

        int ans = 0;
        for(int i=0; i<n; i++) {
            if(i == 0) {
                ans = eCnt[n-1] - eCnt[0];
            } else if(i == n-1) {
                ans = Math.min(ans, wCnt[n-2]);
            } else {
                ans = Math.min(ans, wCnt[i-1] + (eCnt[n-1] - eCnt[i]));
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 32320
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
#define o5 100010
using namespace std;

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

    ll n, q, b, c, total = 0;
    vector<ll> A;
    vector<ll> M(o5, 0);
    cin >> n;
    A.resize(n);
    for (auto &it : A)
    {
        cin >> it;
        M[it]++;
        total += it;
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> b >> c;
        total = total + (c - b) * M[b];
        M[c] += M[b];
        M[b] = 0;
        cout << total << endl;
    }
}

Measured memory_bytes: 4680
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
const ll mod = 1e9+7;
ll dp[maxn][15];

int main()
{
    string s;
    while(cin>>s){
        int n=s.length();
        memset(dp, 0, sizeof(dp));
        for(int i=0;i<n;i++){
            if(i==0) {
                if(s[i] == '?'){
                    for(int j=0;j<10;j++){
                        dp[i][j] = 1;
                    }
                }
                else{
                    int temp = s[i] - '0';
                    dp[i][temp] = 1;
                }
            }
            else{
                if(s[i] == '?'){
                    for(int j=0;j<13;j++){
                        for(int k=0;k<10;k++){
                            int temp = (j*10 + k) % 13;
                            dp[i][temp] = (dp[i][temp] + dp[i-1][j]) % mod;
                        }
                    }
                }
                else{
                    for(int j=0;j<13;j++){
                        int temp = (j*10 + s[i]-'0') % 13;
                        dp[i][temp] = (dp[i][temp] + dp[i-1][j]) % mod;
                    }
                }
            }
        }
        cout<<dp[n-1][5]<<endl;
    }
    return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

int main(){
	//freopen("test.txt", "r", stdin);
	int n, m;
	cin >> n >> m;

	const int INF = 2<<29;
	vector<vi> edge(n, vi(n, -INF));
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		edge[a][b] = c;
	}

	queue<P> q;
	vi best(n+1, -INF);
	q.push(MP(0, 0));
	while(!q.empty()){
		int t = q.front().X;
		int pos = q.front().Y;
		q.pop();

		if(best[pos] >= t) continue;
		best[pos] = t;

		rep(i, n){
			if(edge[pos][i] == -INF)continue;
			q.push(MP(t+edge[pos][i], i));
		}
	}
	cout << best[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}


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

typedef pair<int, int> P;
vector<string> A;
int H, W;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int d[1000][1000];
int INF = 1e9+7;

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

    cin >> H >> W;

    for(int i=0; i<H; i++){
        string tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    queue<P> que;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j] == '#'){
                que.push(P(i,j));
                d[i][j] = 0;
            }else{
                d[i][j] = INF;
            }
        }
    }

    while(!que.empty()){
        P p = que.front(); que.pop();
        for(int i=0; i<4; i++){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(0 <= nx && nx < H && 0 <= ny && ny < W && d[nx][ny] > d[p.first][p.second] + 1){
                d[nx][ny] = d[p.first][p.second] + 1;
                que.push(P(nx,ny));
            }
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            ans = max(ans, d[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "E"
int n, k;
ll a[200001];
int ft[200002];
void update(int u){
    for(; u<=n; u+=u&-u) ft[u]++;
}
int get(int u){
    int res=0;
    for(; u>0; u-=u&-u) res+=ft[u];
    return res;
}
vector <pair <ll, int> > v;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(k);
    FOR(i, 1, n){
        read(a[i]);
        a[i]-=k;
        a[i]+=a[i-1];
    }
    FOR(i, 1, n) v.pb(mp(a[i], i+1));
    v.pb(mp(0, 1));
    n++;
    sort(v.begin(), v.end());
    ll ans=0;
    FFOR(i, 0, v.size()){
        ans+=get(v[i].second);
        update(v[i].second);
    }
    writeln(ans);
}

Measured memory_bytes: 7920
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

#define dbg(x) { cerr << #x << " = " << x << "\n"; } 
#define pb push_back
#define INF 0x3f3f3f3f

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int x, y;
	cin >> x >> y;
	
	int b = x, a = 0;
	
	while(b >= 0){
		if(b * 4 == y && b == x){
			cout << "Yes\n";
			return 0;
		}
		if(b * 4 < y){
			a = 1;
			while(b * 4 + a * 2 <= y && a + b <= x){
				if(b * 4 + a * 2 == y && a + b == x){
					cout << "Yes\n";
					return 0;
				}
				a++;
			}
		}
		b--;
	}
	
	cout << "No\n";

	return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string x;
    cin>>x;
    stack<char> st;
    REP(i,x.size()) {
        char p = x[i];
        if (st.size() == 0) {
            st.push(p);
        }
        else {
            if (p == 'T') {
                if (st.top() == 'S') {
                    st.pop();
                }
                else {
                    st.push(p);
                }
            }
            else {
                st.push(p);
            }
        }
    }
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 644
import math

n, d = map(int, input().split())  # 複数数値入力
li = list()
for i in range(n):
    li.append(list(map(int, input().split())))  # 複数数値入力(リスト格納)
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (li[i][k] - li[j][k]) ** 2

        if float.is_integer(math.sqrt(sum)):
            ans += 1

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define ceil(a, b) a / b + !!(a % b)
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

vector<int> divisor(int n) {
    set<int> s;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            s.insert(i);
            s.insert(n / i);
        }
    }
    vector<int> v;
    for (auto e : s) v.eb(e);
    return v;
}

bool isPrime(int x) {
    if (x == 1) return 0;
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) return 0;
    }
    return 1;
}


int main() {
    int n;
    cin >> n;
    
    auto v = divisor(n);
    
    rep(i, sz(v)) {
        if (isPrime(v[i]) == 0) {
            v.erase(v.begin() + i);
            i--;
        }
    }
    
    // for (auto vi : v) cout << vi << " "; cout << endl;
    
    int ans = 0;
    rep(i, (1 << sz(v))) {
        int div = 1;
        rep(j, sz(v)) {
            if (i & (1 << j)) {
                // cout << "j " << j << endl;
                div *= v[j];
            }
        }
        int sum = n / div;
        // cout << div << " " << sum << endl;
        if (__builtin_popcount(i) % 2 == 0) { // 足す
            ans += sum;
        } else {
            ans -= sum;
        }
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

int main(){
	int N,M;
	cin>>N>>M;
	
	unionfind uf(N);
	
	for(int i=0;i<M;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		uf.unite(a,b);
	}
	
	set<int> S;
	for(int i=0;i<N;i++){
		S.insert(uf.find(i));
	}
	
	cout<<S.size()<<endl;
	
	return 0;
}


Measured memory_bytes: 5748
n,m = map(int,input().split(" "))
gates = []
for i in range(m):
    gates.append(list(map(int,input().split(" "))))

result = [1, n]

for card in gates:
    if result[0] < card[0]:
        result[0] = card[0]
    if result[1] > card[1]:
        result[1] = card[1]

tmp = result[1] - result[0] + 1 
if tmp >= 0:
    print(tmp)
else:
    print(0)

Measured memory_bytes: 27340
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.nextLine());
        sc.close();

        long minA = 1;
        long minB = 1;

        long rootN = (long) Math.sqrt(Double.parseDouble(String.valueOf(N)));

        minA = 1;
        for (long i = minA; i <= rootN; i++) {
            if (N % i == 0) {
                minA = i;
            }
        }

        minB = N / minA;

        System.out.println(minA + minB - 2);
    }

}


Measured memory_bytes: 23124
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)

#define mp make_pair
#define P pair<int,int>
#define ll __int64

int n,m;
int t[1005][1005];
int memo[1005][1005];
priority_queue<pair<int,P>,vector<pair<int,P> >,greater<pair<int,P> > >se;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
			set<P>sett;
void dfs(int y,int x){
		
	rep(i,4){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<0||ny<0||nx>=m||ny>=n||sett.find(mp(ny,nx))!=sett.end())continue ;
		if(t[y][x]<t[ny][nx]){
			memo[ny][nx]++;
			dfs(ny,nx);
			sett.insert(mp(ny,nx));
		}
	}

	return ;
}
	map<P,bool>ta;
int main(){
	cin>>n>>m;
	rep(i,n){
		rep(j,m){
			cin>>t[i][j];
			se.push(mp(t[i][j],mp(i,j)));
		}
	}

	while(!se.empty()){
			pair<int,P>T=se.top();
			se.pop();
			int ny=T.second.first,nx=T.second.second,value=T.first;
			if(memo[ny][nx]!=0)continue;
			

			dfs(ny,nx);
			sett.clear();

	/*		cout<<value<<" "<<ny<<" "<<nx<<endl<<endl;
	rep(i,n){
		rep(j,m){
			cout<<memo[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/


	}
	int ans=0;
	rep(i,n){
		rep(j,m)if(memo[i][j]>=2)ans++;
	}	
	cout<<ans<<endl;

	return 0;
}


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


#include <vector>

class UnionFindTree {
  private:
    vector<int> par;   // 親
    vector<int> depth; // 木の深さ

  public:
    // n要素で初期化
    UnionFindTree(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
            depth.push_back(0);
        }
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (depth[x] < depth[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) { return find(x) == find(y); }
};


int main(){
    int n, m;
    cin >> n >> m;
    UnionFindTree uft = UnionFindTree(m);
    set<int> spoken_languages;
    for(int i=0;i<n;++i){
        int k;
        cin >> k;
        int l;
        cin >> l;
        spoken_languages.insert(l-1);
        for(int j=1;j<k;++j){
            int lj;
            cin >> lj;
            uft.unite(l-1, lj-1);
            spoken_languages.insert(lj-1);
        }
    }

    vector<int> v;
    for(auto e : spoken_languages)v.push_back(e);

    bool ok = true;
    for(int i=1;i<v.size();++i){
        if(!uft.same(v[i-1], v[i])){
            ok = false;
            break;
        }
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


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

vector<long long> f(long long n) {
    vector<long long> v;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            if (i != 1) v.push_back(i);
            if (i != n) v.push_back(n / i);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n;
    cin >> n;
    vector<long long> ans = f(n - 1);
    vector<long long> v = f(n);
    for (auto k : v) {
        long long nn = n;
        while (nn % k == 0) nn /= k;
        if (nn % k == 1) ans.push_back(k);
    }
    cout << ans.size() << '\n';
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    bool N = false;
    bool W = false;
    bool S = false;
    bool E = false;
    string s;
    cin >> s;
    REP(i,s.length()){
        if(s[i] == 'N') N = true;
        else if(s[i] == 'W') W = true;
        else if(s[i] == 'S') S = true;
        else if(s[i] == 'E') E = true;
    }
    if(N == S && W == E) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

def f(N, i):
    if i == 1:
        return False
    while N%i == 0:
        N //= i
    if N%i == 1:
        return True
    else:
        return False
        
ans = 0
i = 1
while i <= N**0.5:
    if N%i > 0:
        i += 1
        continue
    if f(N, i):
        ans += 1
    if i%(N//i) == 1:
        ans += 1
    i += 1

i = 1
while i <= (N-1)**0.5:
    if (N-1)%i > 0:
        i += 1
        continue
    if N%i == 1 and N//i != i:
        ans += 1
    if N%((N-1)//i) == 1:
        ans += 1
    i += 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  ll a=0, b=0;
  for (auto c:s) {
    int x = c-'0';
    if (x == 0) a++;
    else b++;
  }
  cout << min(a,b)*2 << endl;

  return 0;
}


Measured memory_bytes: 512
n = int(input())
S = input()

num2alpha = lambda c: chr(c+64)
alpha2num = lambda c: ord(c) - ord('A') + 1

ans = []

for s in S:
    num = alpha2num(s)
    new = num + n
    if new >= 27:
        new -= 26
    ans.append(num2alpha(new))

print(''.join(ans))

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

  int N , M , L ;
  int ans = 0 ;
  cin >> N >> M >> L ;
  vector<int> A(M) ;
  rep(i,M) cin >> A.at(i) ;
  int countR = 0 ;
  int countL = 0 ;
  rep(i,M){
    if(A.at(i) < L) countL++ ;
    else countR++ ;
  }
  cout << min(countR,countL) << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    int ans = 1;
    for (int i = 0; i < (N - 1); i++){
        if (S.at(i) != S.at(i + 1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9596
def main():
    n = int(input())
    max_diff = 1 - pow(10, 9)
    min_rate = int(input())
    # t > 0 以降の場合
    for t in range(n-1):
        rate = int(input())
        diff = rate - min_rate
        max_diff = max(max_diff, diff)
        min_rate = min(min_rate, rate)
    print(max_diff)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define vll vector<ll>

ll ti[100001];


ll n,a[100001],k;

ll func(ll pre)
{
   if(pre<0) return 1e16;
   if(pre==0) return 0;
   if(ti[pre]!=-1) {return ti[pre];}
ll mn=1e16;
   for(ll i=1;i<=k;i++){
        if(pre-i<0) break;
      mn=min(mn,abs(a[pre-i]-a[pre])+func(pre-i));
   }
   return ti[pre]=mn;
}


int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    memset(ti,-1,sizeof ti);
	//ll n;
	cin>>n>>k;

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

      cout<<func(n-1)<<endl;
      //cout<<mn<<endl;;

	return 0;
}



Measured memory_bytes: 6528
N = int(input())

pipes = []
pipes.append(int(input()))
pipes.append(int(input()))
pipes.append(int(input()))
pipes.append(int(input()))
pipes.append(int(input()))

min_pipe = 10**16
for pipe in pipes:
    if pipe < min_pipe:
        min_pipe = pipe

max_time, mod = divmod(N, min_pipe)
if mod != 0:
    max_time += 1

max_time += 4
print(max_time)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 1000 + 5;
string s1,s2,s3;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<=20000;i++)
    {
        if((i*a)%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	LL n,m;
	int i,j,k;
	LL a,b,c;
	string sa;
	cin>>n;
	n--;
	a=1;
	for(i=1;;i++){
		a*=26;
		if(n>=a){
			n-=a;
			continue;
		}
		for(j=0;j<i;j++){
			a/=26;
			b=n/a,n%=a;
			sa.push_back((char)((int)'a'+b));
		}
		break;
	}
	cout<<sa<<endl;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))
counter = 0
queue = 0
L =[]
for h in range(N) :
    if A[h] % 2 != 0 :
        print(0)
        queue += 1
        break
if queue == 0 :
    while len(A) >= 1 :
        if A[0] % 4 == 0 :
            A[0] = A[0] // 2
            counter += 1
        else :
            A.pop(0)
            L.append(counter)
            counter = 0
    print(min(L)+1)
    
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int P,Q,R;
    cin >> P >> Q >>R;
    int a = P+Q,B=Q+R,C= P+R;
    int ans = min(a,B);
    ans = min(ans,C);
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int var = 26;	// the number of charactor
int trans(char c) {
	return c - 'a';
}

struct node {
	node *fail;
	vector<node*> next;
	vector<int> ok;
	node() : fail(nullptr), next(var, nullptr) {}
};

node* getnext(node* p, char c) {
	while (p->next[trans(c)] == nullptr) p = p->fail;
	return p->next[trans(c)];
}

class Aho_Corasick {
	vector<int> unite(const vector<int>& a, const vector<int>& b) {
		vector<int> res;
		set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
		return res;
	}
	int K;
	node *root;
public:
	Aho_Corasick(const vector<string>& Ts) : K(Ts.size()), root(new node) {
		node *now;
		root->fail = root;
		for (int i = 0; i < K; i++) {
			auto &T = Ts[i];
			now = root;
			for (auto c : T) {
				if (now->next[trans(c)] == nullptr) {
					now->next[trans(c)] = new node;
				}
				now = now->next[trans(c)];
			}
			now->ok.push_back(i);
		}
		queue<node*> q;
		for (int i = 0; i < var; i++) {
			if (root->next[i] == nullptr) {
				root->next[i] = root;
			}
			else {
				root->next[i]->fail = root;
				q.push(root->next[i]);
			}
		}
		while (!q.empty()) {
			now = q.front(); q.pop();
			for (int i = 0; i < var; i++) {
				if (now->next[i] != nullptr) {
					node *nx = now->fail;
					while (nx->next[i] == nullptr) {
						nx = nx->fail;
					}
					now->next[i]->fail = nx->next[i];
					now->next[i]->ok = unite(now->next[i]->ok, nx->next[i]->ok);
					q.push(now->next[i]);
				}
			}
		}
	}
	node* getroot() const {
		return root;
	}
	vector<int> count(const string& S) const {
		vector<int> res(K);
		node *now = root;
		for (auto c : S) {
			now = getnext(now, c);
			for (auto k : now->ok) res[k]++;
		}
		return res;
	}
};

int main()
{
	string S;
	cin >> S;
	int n = S.size();
	int N;
	cin >> N;
	vector<string> ps(N);
	for (int i = 0; i < N; i++) {
		cin >> ps[i];
	}
	sort(ps.begin(), ps.end(), [](const string& a, const string& b) {
		return a.size() < b.size();
	});
	Aho_Corasick ac(ps);
	auto it = ac.getroot();
	vector<pii> vs;
	for (int i = 0; i < n; i++) {
		it = getnext(it, S[i]);
		if (!it->ok.empty()) {
			vs.emplace_back(i + 1 - ps[it->ok[0]].size(), i + 1);
		}
	}
	sort(vs.begin(), vs.end());
	vs.emplace_back(1e9, 0);
	priority_queue<int,vector<int>,greater<int>> q;
	int p = 0;
	int res = 0;
	for (int i = 0; i < n; i++) {
		while (vs[p].first == i) {
			q.push(vs[p].second);
			p++;
		}
		if (!q.empty() && q.top() == i + 1) {
			res++;
			q = priority_queue<int, vector<int>, greater<int>>();
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 26956
#include <iostream>

using namespace std;
int n,k;
long long cnt(int rest)
{
    long long v=0;
    for(int i=rest;i<=n;i+=k)
        v++;
    return (1LL*v*v*v);
}
int main()
{
    cin>>n>>k;
    long long ans=0;
    ans=cnt(k);
    if(k%2==0)
        ans+=cnt(k/2);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
n, a, b = input().split()
s = input()
n = int(n)
a = int(a)
b = int(b)
passed = 0
ovrank = 0
def isPassed(i, a, b, passed, rank=-1):
    if (i == 0):
        if (a + b > passed):
            return "Yes"
        else:
            return "No"
    else:
        if (a + b > passed and rank<=b):
            return "Yes"
        else:
            return "No"

for i in range(len(s)):
    if (s[i] == "a"):
        tmp = isPassed(0, a, b, passed)
        if (tmp == "Yes"):
            passed += 1
        print(tmp)
    elif (s[i] == "b"):
        ovrank+=1
        tmp = (isPassed(1, a, b, passed, ovrank))
        if (tmp == "Yes"):
            passed += 1
        print(tmp)
    else:
        print("No")


Measured memory_bytes: 4016
#include<stdio.h>

int main() {
    int n;
    scanf("%d", &n);

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

    if(n > 1) {
        a[0] = b[0];
        a[1] = b[0];
        for(int i = 1; i < n - 1; i++) {
            if(b[i-1] < b[i]) {
                a[i+1] = b[i];
            } else if(b[i-1] >= b[i]) {
                a[i] = b[i];
                a[i+1] = b[i];
            }
        }
    } else {
        a[0] = b[0];
        a[1] = b[0];
    }

    int sum = 0;
    for(int i = 0; i < n; i++) {
        sum += a[i];
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,a[109],b[109],dp[109][100009];
ll best(ll d,ll sum)
{
    if(sum<0) return LLONG_MIN;
    if(d==n)  return 0;
    ll &r=dp[d][sum];
    if(r!=-1) return r;
    return r=max(best(d+1,sum),best(d+1,sum-a[d])+b[d]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(ll i=0;i<n;i++)
cin>>a[i]>>b[i];
memset(dp,-1,sizeof dp);
cout<<best(0,k);
return 0;
}


Measured memory_bytes: 88772
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {  
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		
		
		
		long step;
		long i;
		for(i=(long) Math.sqrt(n);i>=1;i--) {
			if(n%i==0) {
				step = i + n/i;
				System.out.println(step-2);
				break;
			}
		}
	}
}

Measured memory_bytes: 25044
import java.math.BigInteger;
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    BigInteger n = new BigInteger(sc.next());
    BigInteger sqrt = BigInteger.ONE;
    for (BigInteger i = BigInteger.ONE; i.compareTo(n) <= 0; i = i.add(BigInteger.ONE)) {
      if (i.multiply(i).compareTo(n) > 0) {
        sqrt = i.subtract(BigInteger.ONE);
        break;
      }
    }
    for (BigInteger i = sqrt; i.compareTo(BigInteger.ZERO) > 0; i = i.subtract(BigInteger.ONE)) {
      if (n.remainder(i).compareTo(BigInteger.ZERO) == 0) {
        System.out.println(i.subtract(BigInteger.ONE).add(n.divide(i).subtract(BigInteger.ONE)));
        break;
      }
    }
  }
}


Measured memory_bytes: 149852
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, m) = (line[0], line[1]);

    if m == 1 && n == 1{
        println!("{}", 1);
        return;
    }

    let (n, m) = if m == 1{
        (m, n)
    }else{
        (n, m)
    };

    //m is more than 1
    if n == 1{
        println!("{}", m-2);
        return;
    }

    println!("{}", (n-2)*(m-2));
}


Measured memory_bytes: 4352
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans;
char S[300005];
int N;
// W     E
// <----->

int main(void) {
    scanf("%d", &N);
    scanf("%s", S);
    
    int x = 0;
    REP(i, 1, N) if (S[i] == 'E') x++;
    ans = x;
    REP(p, 1, N) {
      if (S[p-1] == 'W') x++;
      if (S[p] == 'E') x--;
      ans = min(ans, x);
    }
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 512
local h,w=io.read("n","n")
local n=io.read("n")
local grid={}
for i=1,n do
    local a=io.read("n")
    while a>0 do
        table.insert(grid,i)
        a=a-1
    end
end

for i=1,h do
    local g={}
    if i%2==1 then
        for j=1,w do
            g[j]=grid[j+w*(i-1)]
        end
    else
        for j=1,w do
            g[w-j+1]=grid[j+w*(i-1)]
        end
    end
    print(table.concat(g," "))
end

Measured memory_bytes: 1400
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
s = input()
t = input()
if t[:-1] == s:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27180
#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,i,j;
cin>>n;
int a[n][3];
for(i=0;i<n;i++) {
	for(j=0;j<3;j++) {
		cin>>a[i][j];
	}
	
}
int f[n][3];
f[0][0]=a[0][0];
f[0][1]=a[0][1];
f[0][2]=a[0][2];
for(i=1;i<n;i++)
{ f[i][0]=a[i][0]+max(f[i-1][1],f[i-1][2]);
f[i][1]=a[i][1]+max(f[i-1][0],f[i-1][2]);
f[i][2]=a[i][2]+max(f[i-1][0],f[i-1][1]);

}
cout<<max({f[n-1][0],f[n-1][1],f[n-1][2]});


	
	
	
	
	
	}	

Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,M;
	cin>>N>>M;
	vector<int> X(M);
	FDS(i,M){
		cin>>X[i];
	}
	VSORT(X);
	vector<int> aida(M-1);
	FDS(i,M-1){
		aida[i]=X[i+1]-X[i];
	}
	VSORT(aida);
	int ans=0;
	FDS(i,M-N){
		ans+=aida[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  map<int, int> mp;
  for (char c : s) ++mp[c];
  cout << (mp.size() == 2 && (*mp.begin()).second == 2 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int cost=0, sumcost=0, soldnum=0,sumsoldnum=0;
    int num=0;
    char t;
    while(cin >> cost >> t>>soldnum)
    {
        
        sumcost+= cost*soldnum;
        sumsoldnum += soldnum;
        num += 1;
    }
    printf("%d\n%d\n",sumcost,(int)( (float)sumsoldnum/(float)num +0.5) );

    return 0;
}

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

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

	map<string, bool> Dic;
	string com, word;

	while( n-- ) {
		cin>>com>>word;
		if(com[0] == 'i' ) Dic[word]=true;
		else {
			if( Dic[word] ) cout << "yes" << endl;
			else cout << "no" <<endl;
		}
	}
}


Measured memory_bytes: 52572
import java.io.*;
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String line = in.readLine();
    if (line == null) {
      return;
    }
    char ch = 0;
    for (int i = 0; i < line.length(); i++) {
      char input = line.charAt(i);
      if (ch == input) {
        System.out.println("Bad");
        return;
      }
      ch = input;
    }
    System.out.println("Good");
    in.close();
  }
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
  {
    int minn = min(p[i], min(p[i - 1], p[i + 1]));
    int maxx = max(p[i], max(p[i - 1], p[i + 1]));
    if (p[i] != minn && p[i] != maxx)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n;
    cin>>n;
    if(n<11){cout<<"Yes" el; return;}
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0 and n/i<10){
            cout<<"Yes" el;
            return;
        }
    }
    cout<<"No" el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!



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

int main() {
	ll n, k; cin >> n >> k;
	ll res = 0;
	for (ll i = k; i <= n + 1; i++) {
		ll mini = (i - 1) * i / 2;
		ll maxi = (2 * n - i + 1) * i / 2;
		res += (maxi - mini + 1);
		res %= MOD;
	}
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 3644
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        return self.fact[n] * self.fact_inv[n-r] % mod

from collections import deque
n,k = map(int,input().split())
mod = 10**9 + 7
es = [[] for _ in range(n+1)]
d = [0]*(n+1)
for _ in range(n-1):
    a,b = map(int,input().split())
    es[a].append(b)
    es[b].append(a)
    d[a] += 1
    d[b] += 1

root = -1
for i in range(1, n+1):
    if d[i] == 1:
        root = i
        break

num_child = [0]*(n+1)
que = deque([])
for c in es[root]:
    que.append((root, c))

while que:
    p,c = que.pop()
    num_child[p] += 1
    for nx in es[c]:
        if nx!=p:
            que.append((c, nx))

c = Cmb(N=k)
ans = k

for e,child in enumerate(num_child[1:]):
    if e+1==root:
        cand = k-1
    else:
        cand = k-2
    if child==0:
        continue
    else:
        ans = ans*(c(cand, child)) % mod

print(ans%mod)

Measured memory_bytes: 88736