akhauriyash/Code-Regression huggingface dataset:
/*
"اله السماء يعطينا النجاح ونحن عبيده نقوم ونبني"
"تكفيك نعمتي لان قوتي في الضعف تكمل"
created by shady rafet
my face book : https://www.facebook.com/profile.php?id=100019579575853
never give up
one day i will do it ':(

*/
#include <bits/stdc++.h>
using namespace std;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
const ll oo = 1e18;
const ll N = 1e6;
const ll mod = 1e9 + 7;
#define point complex<double>
const double pi = acos(-1);
double dot(point a, point b)
{
    return (conj(a) * b).real();
}
double cross(point a, point b)
{
    return (conj(a) * b).imag();
}
ll inv[N],fact[N];
ll fb(ll x, ll y)
{
    if(y == 0)
    return 1;
   ll ans = fb(x,y/2);
   ans = (ans * ans)%mod;
   if(y % 2 !=0)
   {
       ans = (ans*(x%mod))%mod;
   }
   return ans ;
}
void pre(ll n)
{
    fact[0] = 1;
    inv[0] = 1;
    for ( int i = 1;i<=n;i++)
    {
        fact[i] = (i * fact[i-1])% mod;
        inv[i] = fb(fact[i], mod-2);
    }
}
ll ncr (ll n , ll r)
{
      return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}
ll npr (ll n,ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int main()
{
     ll n,x;
     cin>>n;
     x = n;
     map<int,char> me;
     int cnt = 1;
     for(char i = 'a';i<'z';i++)
     {
         me[cnt] =i;
         cnt++;
     }
     me[0] = 'z';
     vector<int> v;
     while(n)
     {

         v.push_back(n%26);
         bool  f = 0;
         if(n%26==0)
            f = 1;
         n/=26;
         if(f)
         n--;

     }
     string s;
    reverse(v.begin(),v.end());
for(int i = 0;i<v.size();i++)
   s+=me[v[i]];
for(int i = 0;i<s.size();i++)
{
    /*
    if(x%26==0&&i==0&&0)
        continue;
        */
    cout<<s[i];
}
    return 0;
}


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

int main() {
  int k,t; cin>>k>>t;
  vector<int> a(t);
  rep(i, t) cin>>a[i];

  bool dp[102][10002];
  dp[0][0]=true;
  rep(i, t) {
    rep(j, k+1) {
      dp[i+1][j] |= dp[i][j];
      if (j>=a[i]) dp[i+1][j] |= dp[i][j-a[i]];
    }
  }
  int mid=k/2;
  int dist=1000000000;
  rep(j, k+1) {
    int tmp=j;
    if (dp[t][j]) dist=min(dist, abs(k-2*tmp));
  }
  cout<<max(dist-1, 0)<<endl;
}


Measured memory_bytes: 1280
s = input().rstrip()
k = int(input())
result = []
for i in range(len(s)):
  for j in range(i+1,i+k+1):
    if j <= len(s) and s[i:j] not in result:
      result.append(s[i:j])
result.sort()
print(result[k-1])

Measured memory_bytes: 3944
r,g,b,n= map(int, input().split())

x=n//r
y=n//g
ans=0
for i in range(x+1):
    for j in range(y+1):
        v=n-r*i-g*j
        if v<0:
            continue
        else:
            if v%b==0:
                ans+=1
print(ans)

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

int selectionSort(vector<int> &A) {
  int sw = 0;
  int N = A.size();
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i + 1; j < N; j++) {
      if (A.at(j) < A.at(minj)) {
        minj = j;
      }
    }
    if (A.at(i) > A.at(minj)) {
      swap(A.at(i), A.at(minj));
      sw++;
    }
  }
  return sw;
}

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int sw = selectionSort(A);

  for (int i = 0; i < N; i++) {
    cout << A.at(i);
    if (i < N - 1) {
      cout << " ";
    }
    else {
      cout << endl;
    }
  }

  cout << sw << endl;
}


Measured memory_bytes: 3104
#include<stdio.h>

int main(){
  int m[101][101];
  int i,j,k,n,u,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      m[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<=k-1;j++){;
      scanf("%d",&v);
      m[u][v]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j-1)printf(" ");
      printf("%d",m[i][j]);
    }
    printf("\n");
  }
  return 0;
}

    
  
  



Measured memory_bytes: 2108
M=998244353
N,*A=open(0)
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;a=int(a);s+=a;z*=3
	while i>=0:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
for i in range(s+1>>1,s+1):z=(z-d[i]*3)%M
print([(z+e[s//2]*3)%M,z][s%2])

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

using namespace std;

const int NS = (int)1e5+4;
int N, Q;
int cnt[NS];
char arr[NS];

int main(){
    scanf("%d %d", &N, &Q);
    scanf("%s", arr+1);
    for(int i=1;i<=N;++i) arr[i-1]=='A'&&arr[i]=='C'? cnt[i]=cnt[i-1]+1:cnt[i]=cnt[i-1];
    while(Q--){
        int l, r; scanf("%d %d", &l, &r);
        printf("%d\n", cnt[r]-cnt[l]);
    }
    return 0;
}


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

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

    int n;
    cin >> n;

    REP(i, 26){
        REP(j, 15){
            int fml = i * 4 + j * 7;
            if(fml < 0) continue;
            if(fml == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
if s[0]==s[1] and s[1]==s[2] and s[2]=='R':
  print(3)
elif (s[0]==s[1] or s[1]==s[2]) and s[1]=='R':
  print(2)
elif s[0]==s[1] and s[1]==s[2] and s[2]=='S':
  print(0)
else:
  print(1)

Measured memory_bytes: 61828
#include <iostream>
using namespace std;
int main(){
    int n, i;
    cin >> n;
    for (i=1; i<=n; i++){
        if (i%3==0 || i%10==3 || (i/10)%10==3 ||((i/10)/10)%10==3 ||(((i/10)/10)/10)%10==3){
            cout << " " << i ;
        }
    }cout << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    int A,B; cin>>A>>B;
    vi vec(3);
    rep(i,N){
        int p; cin>>p;
        if (p<=A) vec[0]++;
        else if(p<=B) vec[1]++;
        else vec[2]++;
    }
    cout<<*min_element(all(vec))<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	map<char, int> cnt[51];
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		for(int j = 0; j < s.length(); j++){
			if(cnt[i].find(s[j]) == cnt[i].end()) cnt[i][s[j]] = 1;
			else cnt[i][s[j]]++;
		}
	}
	string ans = "";
	for(int i = 0; i < 26; i++){
		int tmp = mod;
		char c = 'a' + i;
		for(int j = 0; j < n; j++){
			if(cnt[j].find(c) != cnt[j].end()) tmp = min(tmp, cnt[j][c]);
			else tmp = 0;
		}
		if(tmp < mod && tmp > 0){
			string s = string(tmp, c);
			ans += s;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll N,C;
    cin >> N >> C;
    ll D[C+1][C+1]={};
    int a=3;
    ll color[a][C+1]={};
    rep(i,C){
        rep(j,C){
            cin >> D[i+1][j+1];
        }
    }
    rep(i,N)rep(j,N){
        ll tmp;
        cin >> tmp;
        color[(i+j)%3][tmp]++;
    }
    ll res=1LL<<60,tmp=0;
    rep(i,C)rep(j,C)rep(k,C){
        tmp=0;
        if(i==j||j==k||k==i)continue;
        for(int l=1;l<=C;l++){
            tmp+=color[0][l]*D[l][i+1];
            tmp+=color[1][l]*D[l][j+1];
            tmp+=color[2][l]*D[l][k+1];
        } 
        res = min(res,tmp);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K, S int
	fmt.Scanf("%d %d", &K, &S)

	result := 0
	for x := 0; x <= K; x++ {
		for y := 0; y <= K; y++ {
			z := S - x - y
			if z >= 0 && z <= K {
				result++
			}
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

// Taken From Striver_79
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure. 


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define mod 1000000007
#define endl "\n"
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
void input(ll a[], ll sz) {for(ll i=0;i<sz;i++) cin >> a[i];}
void print(ll a[], ll sz) {for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};

ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
ll power(ll x,ll y,ll p = mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
// a+b=xor(a,b)+2*(a&b)//

bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}


void solve()
{
    string s,t;
    cin>>s>>t;
    ll maxi=0;
    for(int i=0;i<=s.size()-t.size();i++){
        ll cnt=0;
        for(int j=i;j<i+t.size();j++){
            if(s[j]==t[j-i]){
                cnt++;
            }
        }
        maxi=max(maxi,cnt);
        // cout<<maxi<<endl;
    }
    cout<<t.size()-maxi<<endl;
}


int main()
{
	fio;
// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif
 

	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if ((ans * 2) > (ans + k)) {
      ans += k;
    } else {
      ans *= 2;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int N, Q;
	string S;
	
	cin >> N >> Q;
	cin >> S;

	vector<int> l(Q), r(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> l[i] >> r[i];
	}


	vector<int> sum(N + 1, 0);
	
	//ACが出る可能性があるのは2文字目から(0-indexedで1から)
	for (int i = 0; i < N - 1; i++)
	{
		sum[i + 1] = sum[i];
		if (S[i] == 'A' && S[i + 1] == 'C') {
			sum[i + 1]++;
		}
	}

	//0 1 2 3 4 5 6
	// A C A C A C
	// 1 2 3 4 5 6

	for (int i = 0; i < Q; i++)
	{
		int ans = sum[r[i] - 1] - sum[l[i] - 1];
		cout << ans << endl;
	}
}



Measured memory_bytes: 2176
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, x; cin >> n >> x;
  vector<int> m(n); rep(i, n) cin >> m[i];
  sort(m);
  rep(i, n) x -= m[i];
  outl(n + x / m[0]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a <= b && a <= c && b <= c){
    printf("%d %d %d\n",a,b,c);
  }else if(b <= c && b <= a && c <= a){
    printf("%d %d %d\n",b,c,a);
  }else if(a <= b && a <= c && c <= b){
    printf("%d %d %d\n",a,c,b);
  }else if(b <= c && b <= a && a <= c){
    printf("%d %d %d\n",b,a,c);
  }else if(c <= a && c <= b && a <= b){
    printf("%d %d %d\n",c,a,b);
  }else if(c <= a && c <= b && b <= a){
    printf("%d %d %d\n",c,b,a);
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef unsigned us;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

const int N=100005;

int n,x,s1,s2,s3;
int main(){
	scanf("%d",&n);
	rep(i,1,n+1) {
		scanf("%d",&x);
		if (x%4==0) s2++;else if (x%2==0) s3++;else s1++;
	}
	if (s1>s2+1) {
		printf("No");
		return 0;
	}
	if (s1==s2+1 && s3>0) {
		printf("No");
		return 0;
	}
	printf("Yes");
	
	
}

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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
int n, x, y, h;
vector<int> a[N];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> h;
        a[i] = {x, y, h};
    }
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int expect = -1;
            bool ok = true;
            for (int k = 0; k < n; ++k) {
                int x0 = a[k][0], y0 = a[k][1], h0 = a[k][2];
                if (h0 == 0) continue;
                int cur = abs(i - x0) + abs(j - y0) + h0;
                if (expect == -1) {
                    expect = cur;
                } else if (expect != cur){
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            for (int k = 0; k < n; ++k) {
                int x0 = a[k][0], y0 = a[k][1], h0 = a[k][2];
                if (h0 != 0) continue;
                int cur = abs(i - x0) + abs(j - y0);
                if (cur < expect) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << i << ' ' << j << ' ' << expect << endl;
                exit(0);
            }
        }
    }
    cout << "0 0 0" << endl;
    return 0;
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

pll ps[3001];
bool m[5001][5001];

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    while(cin >> N, N){
        for(int i = 0; i < 5001;i++)for(int j = 0; j < 5001;j++) m[i][j] = false;
        vector<pll> ps(N);
        for(int i = 0; i < N; i++){
            cin >> ps[i].first >> ps[i].second;
            m[ps[i].first][ps[i].second] = true;
        }
        ll res = 0;
        for(int i = 0; i < N;i++){
            for(int j = i+1;j <N;j++){
                ll x1 = ps[i].first,y1 = ps[i].second,x2 = ps[j].first,y2 = ps[j].second;
                
                ll area = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
                if(area <= res) continue;
                ll x3 = x1 + (y1 - y2),y3 = y1 + (x2 - x1);
                if(x3 >= 0 && x3 <= 5000 && y3 >= 0 && y3 <= 5000){
                    if(m[x3][y3]){
                        ll x4 = x2 + (x3 - x1), y4 = y2 + (y3 - y1);
                        if(x4 >= 0 && x4 <= 5000 && y4 >= 0 && y4 <= 5000){
                            if(m[x4][y4]){
                                res = area;
                                continue;
                            }
                        }
                    }
                }
                x3 = x1 - (y1 - y2), y3 = y1 - (x2 - x1);
                if(x3 >= 0 && x3 <= 5000 && y3 >= 0 && y3 <= 5000){
                    if(m[x3][y3]){
                        ll x4 = x2 + (x3 - x1), y4 = y2 + (y3 - y1);
                        if(x4 >= 0 && x4 <= 5000 && y4 >= 0 && y4 <= 5000){
                            if(m[x4][y4]){
                                res = area;
                                continue;
                            }
                        }
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 27504
#
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    s = input()
    if len(set(s)) == n:
        print(0)
        return

    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = -10**4

    for i in range(n):
        for j in range(i, n):
            if i == j:
                continue
            if s[i] == s[j]:
                if i > 0 and j > 0:
                    length = dp[i-1][j-1]
                    if j - length > i:
                        dp[i][j] = dp[i-1][j-1] + 1
                else:
                    dp[i][j] = 1

    ans = 0
    for d in dp:
        ans = max(ans, max(d))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 230152
#include <algorithm>
#include <string>
#include <iostream>
#include <utility>
#include <vector>

int main () {
  
  int n;
  std::cin >> n;
  
  std::vector<std::string> strs;
  for(auto i=0; i<n; ++i) {
    std::string tmp;
    std::cin >> tmp;
    strs.push_back(tmp);
  }

  std::sort(strs.begin(), strs.end());
 
  std::vector<std::pair<int, std::string>> l;
  std::string tmp = strs.front();
  n =0;
  for(auto&& s : strs) {
    if(s == tmp)
      ++n;
   	else {
      l.emplace_back(n, tmp);
      tmp = s;
      n = 1;
    }      
  }
  l.emplace_back(n, tmp);
  
  std::sort(l.begin(), l.end(), [](auto l, auto r){ return l.first > r.first; });
  
  auto ii = l.front().first;
  
  std::vector<std::string> v;
  
  for(auto && p : l) {
    if(p.first == ii)
      v.push_back(p.second);
    else
      break;
  }
  
  std::sort(v.begin(), v.end());
  
  for(auto&& s : v) {
    std::cout << s << std::endl;
  }
}

Measured memory_bytes: 21868
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    for(int i = 0; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            cin >> c[i][j];
        }
    }
    for(int k = 0; k < 10; ++k){
        for(int i = 0; i < 10; ++i){
            for(int j = 0; j < 10; ++j){
                chmin(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    ll ans = 0;
    vector<vector<int>> a(h, vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a[i][j];
            if(a[i][j] == -1 || a[i][j] == 1)   continue;
            ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;
}

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

struct edge{int to,cost;};
vector<edge> G[100010];
vector<int> node;
const int INF = 1e9;
int V,E,r;

bool Bellman_Ford(int r){
    node = vector<int>(V,INF);
    node[r] = 0;
    for(int i=0;i<V;++i){
        for(int v=0;v<V;++v){
            for(auto e: G[v]){
                if(node[v] == INF) continue;
                if(node[e.to] > node[v] + e.cost){
                    node[e.to] = node[v] + e.cost;
                    if(i == V-1) return true;
                }
            }
        }
    }
    return false;
}

int main(){
    cin >> V >> E >> r;
    for(int i = 0;i<E;++i){
        int s,t,c;
        cin >> s >> t >> c;
        G[s].push_back({t,c});
    }

    bool negloop = Bellman_Ford(r);

    if(negloop){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    for(auto e : node){
        if(e == INF) cout << "INF" << endl;
        else cout << e << endl;
    }
}


Measured memory_bytes: 5536
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = B[i] + A[i];
    long[long] cnt;
    long ans = 0;

    foreach_reverse(i; 0..N) {
        long x = B[i];
        cnt[B[i+1]] += 1;
        if (x in cnt) ans += cnt[x];
    }

    ans.writeln;
}


Measured memory_bytes: 25868
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
	static Scanner stdIn = new Scanner(System.in);
	public static void main(String[] args) {
		while(true){
			String str = stdIn.nextLine();
			char[] ch = str.toCharArray();
			if(ch.length==1&&ch[0]=='.')
				break;
			boolean ans=true;
			AtomicInteger num = new AtomicInteger();
			for(int i= 0;i<ch.length;i++){
				num.set(i);
				if(ch[i]=='('){
					if(!func(ch,1,num)){
						ans=false;
						break;
					}
					i=num.get();
					continue;
				}
				else if(ch[i]=='['){
					if(!func(ch,2,num)){
						ans=false;
						break;
					}
					i=num.get();
					continue;
				}
				else if(ch[i]==')'||ch[i]==']'){
					ans=false;
					break;
				}
//				System.out.println(num.get());
			}			
			if(ans){
				System.out.println("yes");
			}
			else
				System.out.println("no");	
		}
	}

	static boolean func(char[] ch,int state,AtomicInteger num){
		boolean ret=false;
		num.getAndIncrement();
		for(int i= num.get();i<ch.length;i++){
			num.set(i);
			if(ch[i]=='('){
				if(!func(ch,1,num)){
					ret=false;
					break;
				}
				i=num.get();
				continue;
			}
			else if(ch[i]=='['){
				if(!func(ch,2,num)){
					ret=false;
					break;
				}
				i=num.get();
				continue;
			}
			else if(ch[i]==')'&&state==2){
				ret=false;
				break;
			}
			else if(ch[i]==']'&&state==1){
				ret=false;
				break;
			}
			else if(ch[i]==')'&&state==1){
				ret=true;
				break;
			}
			else if(ch[i]==']'&&state==2){
				ret=true;
				break;
			}
//			System.out.println(num.get());
		}
		return ret;
	}
}

Measured memory_bytes: 33952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust\n";
    else
        cout << "win\n";
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<int> ans{a + c, a + d, b + c, b + d};
    sort(ans.begin(), ans.end());
    cout << ans.at(0) << endl;
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(){
int E,Y;
cin>>E>>Y;

if(E==0)
if(1867<Y&&Y<1912)
cout<<"M"<<Y-1867<<endl;
if(1911<Y&&Y<1926)
cout<<"T"<<Y-1911<<endl;
if(1925<Y&&Y<1989)
cout<<"S"<<Y-1925<<endl;
if(1988<Y)
cout<<"H"<<Y-1988<<endl;

if(E==1)
cout<<Y+1867<<endl;

if(E==2)
cout<<Y+1911<<endl;

if(E==3)
cout<<Y+1925<<endl;

if(E==4)
cout<<Y+1988<<endl;

return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <unordered_map> //C++11
#include <queue>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	int n;
	cin >> n;
	int b;
	int res[200003];
	for (int i = 0; i < 200003; i++) res[i] = -1;
	for (int i = 0; i < n; i++) {
		cin >> b;
		if (i % 2 == 0) {
			res[100000 + i / 2] = b;
		}
		else {
			res[100000 - (i + 1) / 2] = b;
		}
	}
	bool flag = false;
	if (n % 2 == 0) {
		for (int i = 0; i < 200003; i++) {
			if (res[i] >= 0) {
				if (!flag) {
					flag = true;
					cout << res[i];
				}
				else {

					cout << " " << res[i];
				}
			}
		}
		cout << endl;
	}
	else {
		for (int i = 200002; i >= 0; i--) {
			if (res[i] >= 0) {
				if (!flag) {
					flag = true;
					cout << res[i];
				}
				else {

					cout << " " << res[i];
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
template<class T> void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> void chmin(T& a, T b) { if (a > b) a = b; }
struct position { long long x, y; };
const long long INF = INT64_MAX;

bool isin(long long l, long long r, long long d, long long u, position p) {
    return (l <= p.x && p.x <= r && d <= p.y && p.y <= u);
}

int main() {
    int n, k;
    cin >> n >> k;
    long long ans = INF;
    vector<position> data;
    vector<long long> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        data.push_back(position{x[i], y[i]});
    }
    
    sort(x.begin(), x.end()); sort(y.begin(), y.end());
    for (int l = 0; l < n; l++) for (int r = l; r < n; r++) {
        for (int d = 0; d < n; d++) for (int u = 0; u < n; u++) {
            int res = 0;
            for (auto& e : data) if (isin(x[l], x[r], y[d], y[u], e)) res++;
            if (k <= res) chmin(ans, abs(x[l] - x[r]) * abs(y[u] - y[d]));
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll l,r,ans;
  cin>>l>>r;
  if(r-l>=2019)
  {
    ans=0;
  }
  else
  {
    ll i,j;
    ans=2020;
    int f=0;
    for(i=l;i<r;i++)
    {
      for(j=i+1;j<=r;j++)
      {
     	if((i*j)%2019 <ans) ans=(i*j)%2019;
        if(ans==0) {f=1;break;}
      }
      if(f==1) break;
    }
  }
  cout<<ans;
  return  0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        long[] a = Pattern.compile(" ").splitAsStream(stdin.readLine()).mapToLong(Long::parseLong).toArray();

        long left = 0;
        long right = Arrays.stream(a).sum();
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < n - 1; i++) {
            left += a[i];
            right -= a[i];
            ans = Math.min(ans, Math.abs(left - right));
        }

        stdout.println(ans);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 58988
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL A, B;
	cin >> A >> B;
	if (A <= B) {
		for (LL b = 0; b < B; b++) {
			cout << A;
		}
		cout << "\n";
		return 0;
	}
	else if (A > B) {
		for (LL a = 0; a < A; a++) {
			cout << B;
		}
		cout << "\n";
		return 0;
	}
}


Measured memory_bytes: 256
n = gets.to_i
arr = [[0,0,0]]

n.times do
  t, a, b = gets.split.map(&:to_i)
  arr << [t,a,b]
end

i = 0
n.times do
  dt = arr[i+1][0]-arr[i][0]
  d = (arr[i][1]-arr[i+1][1]).abs + (arr[i][2]-arr[i+1][2]).abs

  unless d <= dt && (dt%2 == d%2) then
    puts "No"
    exit
  end
  i += 1
end

puts "Yes"


Measured memory_bytes: 9468
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <ctype.h>

using namespace std;
string str,str2;
int main() {
int count=0;
std::cin>>str2;
for(int i=0;i<str2.size();i++)str2[i]=tolower(str2[i]);

while(std::cin.eof()==false){
	std::cin>>str;
	if(str=="END_OF_TEXT")break;
	for(int i=0;i<str.size();i++){
		str[i]=tolower(str[i]);
	}
	if(str2==str)count++;
}
std::cout<<count<<"\n";
}


Measured memory_bytes: 3168
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

signed main()
{
  ll n;
  map< string, int > s_map;

  cin >> n;
  REP(i, n)
  {
    string s;
    cin >> s;

    s_map[s] = 1;
  }

  // uniq
  ll ans = s_map.size();

  cout << ans << endl;
}

Measured memory_bytes: 19256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int n, x; cin >> n >> x;
    vector<int> m(n);
    int total = 0;
    rep(i, n){
        cin >> m[i];
        total += m[i];
    }

    sort(all(m));
    x -= total;

    cout << x / m[0] + n << endl;

    return 0;
}


Measured memory_bytes: 3544
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k,s;
        String g;
        while(true){
            s=0;  
            g = sc.next();
            //g = String.valueOf(n);
            k = g.length();
            if(k==1&&Integer.parseInt(g)==0){
                break;
            }
            for(int i=0;i<k;i++){
                s = s + Character.getNumericValue(g.charAt(i));
            }
            System.out.println(s);
        }
        sc.close();
    }
}


Measured memory_bytes: 26452
#include<iostream>
#include<string>
using namespace std;
string matrix[2000];
int horizontal[2000][2000]={0},verticle[2000][2000]={0};
int f1[4000000][2]={0},f2[4000000][2]={0};
int main(){
    int h,w,a=0,b=0,max=-1;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>matrix[i];
        for(int j=0;j<w;j++){
            if(matrix[i][j]=='.'){
                if(j-1>=0){
                    horizontal[i][j]=horizontal[i][j-1];
                }
                horizontal[i][j]++;
                if(i-1>=0){
                    verticle[i][j]=verticle[i-1][j];
                }
                verticle[i][j]++;
                if(j==w-1){
                    f1[a][0]=i;
                    f1[a][1]=j;
                    a++;
                }
                if(i==h-1){
                    f2[b][0]=i;
                    f2[b][1]=j;
                    b++;
                }
            }
            else if(matrix[i][j]=='#'){
                if(j-1>=0){
                    f1[a][0]=i;
                    f1[a][1]=j-1;
                    a++;
                }
                if(i-1>=0){
                    f2[b][0]=i-1;
                    f2[b][1]=j;
                    b++;
                }
            }
        }
    }
    for(int i=0;i<a;i++){
        for(int j=f1[i][1]-1;j>=f1[i][1]-horizontal[f1[i][0]][f1[i][1]]+1;j--){
            horizontal[f1[i][0]][j]=horizontal[f1[i][0]][f1[i][1]];
        }
    }
    for(int i=0;i<b;i++){
        for(int j=f2[i][0]-1;j>=f2[i][0]-verticle[f2[i][0]][f2[i][1]]+1;j--){
            verticle[j][f2[i][1]]=verticle[f2[i][0]][f2[i][1]];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(horizontal[i][j]+verticle[i][j]-1>max){
                max=horizontal[i][j]+verticle[i][j]-1;
            }
        }
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 98048
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    
    
    ll n;
    cin >> n;
    ll x;
    vector<ll> vec;

    rep(i,0,n){
        cin >> x;
        vec.push_back(x);
    }

    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    cout << (((ll)vec.size() == n)?"YES":"NO") << endl;
    return 0;
}

Measured memory_bytes: 2420
n = int(input())
a = list(map(int, input().split()))

a.sort()
count = 0
for i in range(n-1, 0, -1):
    l = 0
    r = i-1
    while(l<r):
        if a[l] + a[r] > a[i]:
            count += r-l
            r -= 1

        else:
            l += 1

print(count)


Measured memory_bytes: 9344
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
string S;
int main() {
	cin >> S;
	if (S.size() >= 4 && S.substr(0, 4) == "YAKI")cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var h, w int
	fmt.Scan(&h)
	fmt.Scan(&w)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	cStarts := make([]int, w)
	light := make([][]int, h)
	for i := 0; i < h; i++ {
		light[i] = make([]int, w)
	}

	for i := 0; i < h; i++ {
		rStart := 0
		scanner.Scan()
		row := scanner.Text()
		for j := 0; j < w; j++ {
			if row[j] == '#' {
				for k := rStart; k < j; k++ {
					light[i][k] += j - rStart
				}
				for k := cStarts[j]; k < i; k++ {
					light[k][j] += i - cStarts[j] - 1
				}
				rStart = j + 1
				cStarts[j] = i + 1
			}
		}

		for k := rStart; k < w; k++ {
			light[i][k] += w - rStart
		}
	}

	for j := 0; j < w; j++ {
		for k := cStarts[j]; k < h; k++ {
			light[k][j] += h - cStarts[j] - 1
		}
	}

	var max int
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if light[i][j] > max {
				max = light[i][j]
			}
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 38144
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> N;
	int ans = 10000;
	for (int i = 1; i < N; i++) {
		int bag = i;
		int box = N - i;
		int c = 0;
		while (bag) {
			c += bag % 10;
			bag /= 10;
		}
		while (box) {
			c += box % 10;
			box /= 10;
		}
		ans = min(ans, c);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
ans = 0
def k(a,b):
    dist = 0
    for i in range(d):
        dist +=(a[i]-b[i])**2
    dist = dist**(1/2)
    while dist > 0:
        dist -= 1
        if dist == 0:
            return True
    return False
for i in range(n):
    for j in range(i+1,n):
        if k(x[i],x[j]):
            ans += 1

print(ans)

Measured memory_bytes: 39280
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



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

	map<char, int>mp;
	rep(i, 0, 4)mp[s[i]]++;

	if (mp.size() == 2) {
		vector<int>v(2);
		int cnt = 0;
		fore(x,mp){
			v[cnt] = x.second;
			cnt++;
		}
		if (v[0] == 2 && v[1] == 2) {
			puts("Yes");
			
		}
		else {
			puts("No");
		}
	}
	else {
		puts("No");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int a,b;

int main(){

    cin >> a >> b;

    P(max(0,a-(2*b)));
    
    return  0;
}


Measured memory_bytes: 256
s = input()
a = [int(c) for c in s]

for i in range(2**3):
    op = [0,0,0]
    sum = a[0]
    for j in range(3):
        if ((i >> j) & 1):
            op[-1-j] = 1
            sum += a[-1-j]
        else:
            sum -= a[-1-j]
    #print(sum)
    if sum == 7:
        string = str(a[0])
        for idx, k in enumerate(op):
            if k == 1:
                string += '+'
            else:
                string += '-'
            string += str(a[idx+1])
        string += '=7'

print(string)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;


#define MAX	10000

//入力配列
int h_input[MAX] = {0};


//k * (k + 1) / 2で表される数かどうか
bool f_check(int);

//答え出力変数
int ans = 0;



//ループで答えを求める関数
void f_ans(int);


//合否判定関数
bool f_ok(int);



//配列をずらす関数
int f_zurasu(int);




int main(void)
{
	//入力変数
	int n = 0;

	while (cin >> n && n != 0)
	{
		//答え変数初期化
		ans = 0;

		//値を入力
		for (int i = 0; i < n; i++)
		{
			cin >> h_input[i];
		}

		//まず作れるかどうか
		if (f_check(n) == false)
		{
			cout << "-1" << endl;
			continue;
		}

		//関数で求める
		f_ans(n);

		//関数で成功かどうか判断する
		cout << ans << endl;
	}

	return 0;
}




bool f_check(int n)
{
	//合計値を計算
	int sum = 0;
	//ｋを算出する変数
	int count = 2;

	for (int i = 0; i < n; i++)
	{
		sum += h_input[i];
	}

	//k * (k + 1)を計算
	int k = 1;

	//割り切れるか、値が大きくなるまで
	while (1)
	{
		//割り切れる
		if (k == sum)
		{
			return true;
		}
		//値を超えた
		if (k > sum)
		{
			return false;
		}

		k = (count * (count + 1)) / 2;

		count++;
	}
}



//ループで答えを求める関数
void f_ans(int n)
{

	//回数カウント変数
	int count = 0;

	//いくつのブロックを動かしたかを記憶する
	int move = 0;

	//成功flag
	bool flag_ok = false;

	//配列の末尾を表す
	int end = n;

	//最高回数
	while (count < 10000)
	{
		move = 0;

		//できているかのチェック
		if (f_ok(n) == true)
		{
			//flagをtrueにして抜ける
			flag_ok = true;
			break;
		}

		//番兵まで回す
		for (int i = 0; i < end; i++)
		{
			//0でないならデクリメントをして、動かしたブロックの個数を記憶する変数をインクリメント
			if (h_input[i] != 0)
			{
				h_input[i]--;
				move++;
			}
		}

		//関数でずらして戻り値を利用する
		end = f_zurasu(end);
		h_input[end] = move;
		end++;

		//1回動かした
		count++;
	}

	ans = -1;
	//okならば上書き
	if (flag_ok == true)
	{
		ans = count;
	}
}



//合否判定関数
bool f_ok(int n)
{
	//最初は1段
	int dan = 1;

	for (int i = 0; h_input[i] != 0; i++)
	{
		if (h_input[i] != dan)
		{
			return false;
		}
		dan++;
	}

	return true;
}



//配列をずらす関数
int f_zurasu(int n)
{
	//別な配列を使ったほうが楽
	int h_copy[MAX] = {0};

	//カウント変数
	int count = 0;

	for (int i = 0; i < n; i++)
	{
		if (h_input[i] != 0)
		{
			h_copy[count++] = h_input[i];
		}
	}
	for (int i = 0; i < n; i++)
	{
		h_input[i] = h_copy[i];
	}

	//配列の最後尾を表す
	return count;
}

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int count = 0;
  int rlim = N / R;
  for (int i = 0; i <= rlim; i++){
    int newN = N - (R * i);
    int glim = newN / G;
    for (int j = 0; j <= glim; j++){
      if ((newN - (G * j)) % B == 0){
        count += 1;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    if ($a[$i] === $cnt + 1) {
        $cnt++;
    }
}
$ans = $cnt ? count($a) - $cnt : -1;
echo $ans . PHP_EOL;

Measured memory_bytes: 27120