akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

string s;
vector<vector<string>> dp(100,vector<string> (100, "."));

bool f(string l, string r){
    if(l.length() < r.length()) return true;
    else if(l.length() > r.length()) return false;
    else{
        for (int i = 0; i < l.length(); i++) {
            if(l[i] < r[i]) return true;
            else if(l[i] > r[i]) return false;
        }
    }
    return true;
}


string dfs(int l, int r){
    if(dp[l][r] != ".") return dp[l][r];
    if(s[l] == '0'){
        if(r - l > 1) return dp[l][r] = "-1";
        else return dp[l][r] = "0";
    }
    string ret = "-1";
    bool t = true;
    for (int i = l; i < r; i++) {
        if(s[i] == 'R' || s[i] == 'L' || s[i] == '(' || s[i] == ')' || s[i] == ',') t = false;
    }
    if(t){
        ret = "";
        for (int i = l; i < r; i++) {
            if(s[i] == '?') ret += '9';
            else ret += s[i];
        }
        if(ret == "") ret = "-1";
        return dp[l][r] = ret;
    }
    if(r - l >= 6){
        t = false;
        if(s[l] == 'L' || s[l] == 'R' || s[l] == '?'){
            if(s[l+1] == '(' || s[l+1] == '?'){
                if(s[r-1] == ')' || s[r-1] == '?') t = true;
            }
        }
    }
    if(!t) return ret;
    for (int i = l+3; i < r; i++) {
        if(s[i] == ',' || s[i] == '?'){
            auto p = dfs(l+2,i), q = dfs(i+1,r-1);
            if(p == "-1" || q == "-1") continue;
            string tmp = "-1";
            if(s[l] == 'L') tmp = p;
            else if(s[l] == 'R') tmp = q;
            else if(s[l] == '?') tmp = max(p, q, f);
            if(ret == "-1") ret = tmp;
            else ret = max(ret, tmp, f);
        }
    }
    return dp[l][r] = ret;
}


int main(){
    cin >> s;
    auto r = dfs(0, s.length());
    if(r == "-1") puts("invalid");
    else cout << r << endl;
    return 0;
}



Measured memory_bytes: 3344
#include <iostream>

int A[10000], B[10000];

int main()
{
	int n, a, b;
	std::cin >> n;
	while (n != 0)
	{
		a = 0; 
		b = 0;
		for (int i = 0; i < n; i++)
		{
			std::cin >> A[i] >> B[i];
			if (A[i] > B[i])
			{
				a += A[i] + B[i];
			}
			if (A[i] == B[i])
			{
				a += A[i];
				b += B[i];
			}
			if (A[i] < B[i])
			{
				b += A[i] + B[i];
			}
		}
		std::cout << a << " " << b << std::endl;
		std::cin >> n;
	}
    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	ll n,a,b;cin>>n>>a>>b;
	if(a+b==1){
		if(a==1) cout<<n<<endl;
		else cout<<0<<endl;
	}
	else if(n/(a+b)==0){
		if(n>a) cout<<a<<endl;
		else cout<<n<<endl;
	}
	else{
		ll c=n/(a+b),d=n%(a+b);
		if(d>=0&&a>=d) cout<<n-b*c<<endl;
		else cout<<a*(c+1)<<endl;
	}
}

Measured memory_bytes: 256
n_store, n_drink = [int(i) for i in input().split()]
stores = [[int(i) for i in input().split()] for _ in range(n_store)]  # price, n_stock
stores.sort(key=lambda x: x[0], reverse=True)  # priceでソート

ans = 0
while n_drink:
    store = stores.pop()
    price, n_stock = store

    n_buy = min(n_stock, n_drink)  # stockがなくなるかn_drinkに到達するまで買う
    ans += n_buy * price
    n_drink -= n_buy
print(ans)


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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> c.at(i).at(j);
    }
  }
  vector<vector<int>> y(10000,vector<int>(10000));
  rep(i,1<<h){
    rep(l,1<<w){
      int t=0;
      rep(j,h){
      // rep(m,w){
          rep(m,w){
            if(i>>j&1 && l>>m&1){
              if(c.at(j).at(m)=='#')++t;
            }
          }
      }
    y.at(i).at(l)=t;
    }
  }
  int z=0;
  rep(i,10000){
    rep(j,10000){
    if(y.at(i).at(j)==k)++z;
    }
  }
  cout << z << endl;
}


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

using namespace std;

int rec(int n, int A, int B, vector<int> &a)
{
    if (n == (int)a.size()) {
        return abs(A - B);
    }

    return min(rec(n + 1, A + a[n], B, a),
               rec(n + 1, A, B + a[n], a));
}

int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        cout << rec(0, 0, 0, a) << endl;
    }
    return 0;
}

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

ll lcm(ll a, ll b){
	return (a/gcd(a, b))*b;
}

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

	ll n;

	cin >> n;

	if(n%1000 == 0)
		cout << 0 << endl;
	else
		cout << 1000 - n%1000 << endl;
}

Measured memory_bytes: 3632
def solve(n)
  # 約数の列挙O(√n)
  ans = 1e13
  i = 1
  while i * i <= n
    if n % i == 0
      # res << i
      # res << n/i if i != n/i
      ans = [ans, i + n / i].min
    end
    i += 1
  end
  ans
end

n = gets.to_i

p solve(n) - 2


Measured memory_bytes: 1788
#include<stdio.h>

#define WHITE 0
#define BLACK 1
#define N 100
#define INF 200001

int d[N];
int color[N];
int w[N][N];
int pi[N];

void prim(int,int);

int t;

int main()
{
    int i,n,j;
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&w[i][j]);
        }
    }
    prim(n,0);
    
    for(i=0;i<n;i++)
    {
        if(pi[i]==-1) break;
    }
    
        printf("%d\n",t);
    
    return 0;
}

void prim(int n, int r)
{
    int i,j,u,v;
    int mincost;
    for(u=0; u<n; u++)
    {
        d[u] = INF;
        pi[u]=-1;
        color[u]=WHITE;
    }
    d[r]=0;
    while(1)
    {
        mincost=INF;
        for(i=0;i<n;i++)
        {
            if(color[i]!=BLACK && d[i]<mincost)
            {
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INF)
            break;
        
        color[u]=BLACK;
        t+=mincost;
        for(v=0;v<n;v++)
        {
            if(color[v]!=BLACK && w[u][v]<d[v] && w[u][v]>=0)
            {
                pi[v]=u;
                d[v]=w[u][v];
            }
        }
        
        
    }
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll K;
ll A[MAX_N];
ll ans;

void check(ll m) {
	vector<ll> vec;
	rep(i, 0, N) {
		vec.pb((m + A[i] % m) % m);
	}
	ll s = accumulate(all(vec), 0ll);
	int n = s / m;
	sort(all(vec));
	reverse(all(vec));
	ll k = 0;
	rep(i, 0, n) k += m - vec[i];
	if(k <= K) MAX(ans, m);
}

void solve() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	ll S = accumulate(A, A + N, 0ll);
	ans = 0;
	for(int i = 1; i * i <= S; i++) {
		if(S % i == 0) {
			check(i);
			check(S / i);
		}
	}
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Measured memory_bytes: 104620
'use strict'

const main = (input) => {
    input = input.split(' ').map(i => parseInt(i))
    const A = input[0]
    const B = input[1]
    if(A <= 8 && B <= 8){
        console.log('Yay!')
    }else{
        console.log(':(')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 1;i<n;i++){
        int cnt = 0;
        for(char c = 'a';c <= 'z';c++){
            bool r = 0,l = 0;
            rep(j,i){
                if(s[j] == c)l = 1;
            }
            for(int j = i;j < n;j++){
                if(s[j] == c)r = 1;
            }
            if(r&&l)cnt ++;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

#define MOD 1000000007

#define MAXN 200009

char s[MAXN + 10];

int main() {
    int ans = 1, n;
    fscanf(fin, "%d ", &n);
    fgets(s, MAXN + 5, fin);
    for (int i = 2; i <= n; i++) ans = 1LL * ans * i % MOD;

    int a = 0;
    for (int i = 0; i < 2 * n; i++)
        if (a % 2 == (s[i] == 'W'))
            a++;
        else {ans = 1LL * ans * a % MOD; a--;}

    if (a != 0)
        ans = 0;

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 384
A = list(map(int, input().split()))
ans = 0
if A[0] == A[1] == A[2]:
  if A[0] % 2 == 0: ans = -1
  else: ans = 0
else:
  ans = 0
  ok = True
  a = b = c = 0
  while ok:
    if A[0] % 2 != 0 or A[1] % 2 != 0 or A[2] % 2 != 0:
      ok = False
    a = (A[1] + A[2]) / 2
    b = (A[0] + A[2]) / 2
    c = (A[0] + A[1]) / 2
    if ok: 
      A = [a, b, c]
      ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C;
    cin >> A >> B >> C;
    if(C-A-B<0) cout << "No\n";
    else cout << (4*A*B<(C-A-B)*(C-A-B)? "Yes\n":"No\n");
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
set<int>paper;
  for(int i=0;i<n;i++)
  {
    int a;cin>>a;
    if(paper.count(a))
      paper.erase(a);
    else
      paper.insert(a);
  }
  cout<<paper.size();
}

Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if((a + b) <= 2 * c){
        cout << (a * x + y * b) << endl;
        return 0;
    }
    int z = min(x, y);
    x -= z;
    y -= z;
    z = 2 * z;
    if(a > 2 * c){
        z += 2 * x;
        x = 0;
    }
    if(b > 2 * c){
        z += 2 * y;
        y = 0;
    }
    cout << (a * x + y * b + c * z) << endl;

    return 0;
}				

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int c=0,f=0;
	for(int i=0;i<a.length();i++){
		if(a[i]=='C'){
			c=i+1;
		}
		if(a[i]=='F'){
			f=i+1;
		}
		if(c<f&&c!=0&&f!=0){
			cout<<"Yes";
			return 0;
		}	
	}
		cout<<"No";	
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 2019;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  int n = SZ(s);
  vi a;
  REP(i, n) {
    a.push_back(s[i] - '0');
  }
  reverse(ALL(a));

  ll now = 1;
  REP(i, n) {
    a[i] *= now;
    a[i] %= MOD;
    now *= 10;
    now %= MOD;
  }

  vi su(n+1);
  REP(i, n) {
    su[i+1] += su[i] + a[i];
    su[i+1] %= MOD;
  }

  map<int, int> mp;
  REP(i, n+1) {
    mp[su[i]]++;
  }

  ll ans = 0;
  for(auto &e: mp) {
    ans += e.second * (e.second-1) / 2;
  }

  cout << ans << endl;

}
























Measured memory_bytes: 5192
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
#define INF 0x3f3f3f3f

int N;
vector <pii> G[100005];
int mcos[100005];

void dijkstra(int s)
{
   priority_queue< pii, vector<pii>, greater<pii> > pq;
   pq.emplace( mkp(0,s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;

   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;
      for( const auto& v: G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc ) )
            pq.emplace( mkp(nc, v.se) );
      }
   }
   return;
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N){
      int u, k, c, to;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].emplace_back( mkp(c, to) );
      }
   }
   dijkstra(0);

   rep(i, N){
      cout << i << ' ' << mcos[i] << '\n';
   }
}



Measured memory_bytes: 10628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
const double EPS = 1e-10;
struct Vec2 {
  double x;
  double y;

  Vec2() : x(0.0),y(0.0){} 
  Vec2(double _x,double _y) :x(_x),y(_y){}  
  
  Vec2 operator+(const Vec2& other) const { return { x + other.x , y + other.y }; }
  Vec2 operator-(const Vec2& other) const { return { x - other.x , y - other.y }; }
  bool operator==(const Vec2& other) const { return (abs(x - other.x) < EPS && abs(y - other.y) < EPS ); }
  
  double dot(const Vec2& other) const { return x * other.x + y * other.y; }
  double cross(const Vec2& other) const { return x * other.y - y * other.x; }
  double length() const { return sqrt(x * x + y * y); }
};
// A とB のなす角θ cosθ, sinθ を返す
double Cos(const Vec2 A, const Vec2 B) { return A.dot(B) / (A.length()*B.length()); }
double Sin(const Vec2 A, const Vec2 B) { return A.cross(B) / (A.length()*B.length()); }

int main()
{
  int n; cin >> n;
  vector<Vec2> v(n);
  rep(i,n) {
    cin >> v[i].x >> v[i].y;
  }

  bool f = true;
  rep(i,n) {
    if(Sin(v[(i+1)%n] - v[i], v[(i+2)%n] - v[i]) < 0) f = false;
  }
  if(f) cout << 1 << "\n";
  else cout << 0 << "\n";
  return 0;
}



Measured memory_bytes: 3208
import java.util.*;

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

        for(int i=0;i<c.length;i++) {
            if (c[i] > 'Z' - n){
                c[i]=(char) (c[i]-('Z'-'A')+n-1);
            }else {
                c[i]=(char)(c[i]+n);
            }

        }
        s = new String(c);
        System.out.println(s);


    }
}


Measured memory_bytes: 23252
n = int(input())

ans = 0
ans_dict = {}

for i in range(n):
    s = input()
    s = ''.join(sorted(s))
    if(s in ans_dict):
        ans += ans_dict[s]
        ans_dict[s] += 1
    else:
        ans_dict[s] = 1
        
print(int(ans))


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

#define pb push_back
#define ppp pop_back
#define fi first
#define se second
#define pii pair<int,int>

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
    string s;
    int w;
    cin >> s >> w;
    string ans;
    for (int i=0; i<s.length(); i++) {
        if (i % w == 0) ans += s[i];
    }
    cout << ans;
}


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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int a[N];
set<int>v;
int main()
{
    Run();
   int n;
   cin>>n;
   n%=10;
   if(n==2||n==5||n==4||n==7||n==9)
    cout<<"hon";
   else if(n==0||n==1||n==6||n==8)
    cout<<"pon";
   else
    cout<<"bon";
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, m, X, Y; cin>>n>>m>>X>>Y;
    vector<int> x(n), y(m);
    for(int i=0; i<n; i++) cin>>x[i];
    for(int i=0; i<m; i++) cin>>y[i];

    int zmax=-1000, zmin=1000;
    for(int i=0; i<n; i++){
        zmax=max(zmax, x[i]);
    }
    for(int i=0; i<m; i++){
        zmin=min(zmin, y[i]);
    }
    
    for(int i=zmax+1; i<=zmin; i++){
        if(X<i && i<=Y){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

llong gcd( llong m, llong n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
llong lcm( llong m, llong n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm



int main(){
    llong N;
    string S;
    cin >> S;
    llong ans=0;
    for(int i=0;i<S.length();i++){
        if(i%2==0){
            ans+=(S[i]=='g'?0:-1);
        }else{
            ans+=(S[i]=='g'?1:0);
        }
    }
    cout << ans<<endl;
       
    
    
    return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    string s;
    cin >> len >> s;
    if(len >= s.length()) cout << s;
    else {
        s.erase(len, s.length() - len);
        cout << s << "...";
    }
}



Measured memory_bytes: 3640
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
d = gets.chomp.to_i
c = gets.chomp.split.map(&:to_i)
s = []
d.times do
  s.push gets.chomp.split.map(&:to_i)
end

t = []
d.times do |i|
  t.push gets.chomp.to_i
end

score = 0
lasts = Array.new(26, 0)
d.times do |i|
  type = t[i] - 1
  score += s[i][type]
  lasts[type] = i + 1

  26.times do |j|
    score -= c[j] * (i + 1 - lasts[j])
  end
  puts score
end



Measured memory_bytes: 14712
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $md = 10 ** 9 + 7;

my $k1 = 1;
my $k2 = 1;
my $k3 = 1;

for(my $i=0;$i<$n;$i++){
  $k1 = ( $k1 * 10 ) % $md;
  $k2 = ( $k2 * 9 ) % $md;
  $k3 = ( $k3 * 8 ) % $md;
}

my $r = (10*$md + $k1 - 2 * $k2 + $k3) % $md;

print "$r\n";




Measured memory_bytes: 4820
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

x = ni()
print('ABC' if x < 1200 else "ARC")







Measured memory_bytes: 3896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

ll LCM(ll a, ll b){
    return a*modinv(GCD(a,b),MOD) * b%MOD;
}

vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>> div;
    ll d = n;
    for(ll i = 2; i*i <= n; i++){
        pair<ll,int> p;
        if(d % i == 0){
            p = make_pair(i,0);
            while(d % i == 0){
                d /= i;
                p.second++;
            }
            div.emplace_back(p);
        }
    }
    if(d != 1) div.emplace_back(d,1);
    return div;
}

ll modpow(ll a, ll n, ll m){
    if(n == 0) return 1;
    ll half = modpow(a,n/2,m);
    ll res = half * half % m;
    if(n & 1) res = res * (a%m) % m;
    return res;
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    ll seki = 1;
    rep(i,N){
        seki *= A[i];
        seki %= MOD;
    }
    ll sum2 = 0;
    rep(i,N){
        sum2 += seki*modinv(A[i],MOD)%MOD;
        sum2 %= MOD;
    }

    ll M = 1;
    vector<int> c(1000100);
    rep(i,N){
        vector<pair<ll,int>> div = factorize(A[i]);
        for(auto u :div){
            c[u.first] = max(c[u.first],u.second);
        }
    }
    rep(i,1000100){
        M *= modpow(i,c[i],MOD);
        M %= MOD;
    }
    ll ans = sum2*modinv(seki,MOD)%MOD*M%MOD;
    cout << ans << endl;

}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}


int main() {
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    rep(i, h) {
        rep(j, w){
            if((i+1) <= b &&  (j+1) <= a )
            cout<<0;
            else if ((i+1) > b &&  (j+1) > a)
            cout<<0;
            else  cout<<1;
        }
        cout<<endl;
    }

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100005];
int b[100005];
int c[100005];
int d[100005];
int p[100005];
int s[100005];

int f(int x)
{
    if (p[x] == x)
        return x;
    return p[x] = f(p[x]);
}

void u(int x, int y)
{
    int a = f(x);
    int b = f(y);
    if (a == b) return;
    p[a] = b;
    s[b] += s[a];
}

vi block[100005];
vi frend[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; ++i)
    {
        p[i] = i;
        s[i] = 1;
    }
    for (int i = 0; i < m; ++i)
    {
        cin >> a[i] >> b[i];
        frend[a[i]].push_back(b[i]);
        frend[b[i]].push_back(a[i]);
        u(a[i], b[i]);
    }
    for (int i = 0; i < k; ++i)
    {
        cin >> c[i] >> d[i];
        block[c[i]].push_back(d[i]);
        block[d[i]].push_back(c[i]);
    }
    for (int i = 1; i <= n; ++i)
    {
        int sol = s[f(i)] - 1 - frend[i].size();
        for (int y : block[i])
            if (f(i) == f(y))
                sol--;
        cout << sol << ' ';
    }
}


Measured memory_bytes: 14840
#include<stdio.h>
#define N 100

void selectionSort(int[],int);

int main(){
  int n,i;
  int A[N];
  
  scanf("%d",&n);

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

void selectionSort(int A[],int n){
  int i,j,minj;
  int swap,count = 0;

  for(i = 0; i <= n - 1; i++){
    minj = i;
    for(j = i; j <= n - 1; j++){
      if(A[j] < A[minj]) {
	minj = j;
      }
    }
    if(i != minj) count++;
     swap = A[i];
     A[i] = A[minj];
     A[minj] = swap;
     
  }
  
  for(i = 0; i < n; i++){
     if(i == n - 1) printf("%d",A[i]);
     else printf("%d ",A[i]);
  }
  printf("\n%d\n",count);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> s;
	n = s.size();
	ll cnt[30];
	memset(cnt, 0, sizeof(cnt));
	rep(i, 0, n){
		int a = s[i]-'a';
		cnt[a]++;
	}
	ll ans = 1 + n*(n-1)/2;
	
	rep(j, 0, 30){
		ans -= cnt[j]*(cnt[j]-1)/2;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 720
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int t = 2 * d + 1;
        writer.println(n / t + (n % t == 0 ? 0 : 1));

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<class T> class Dijkstra {
public:
	int N;
	T inf;
	vector<T> cost;
	vector<vector<pair<T, int>>> edge;

	Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
	}

	void make_edge(int from, int to, T w) {
		edge[from].push_back({ w,to });
	}

	void solve(int start) {
		for(int i = 0; i < N; ++i) cost[i] = inf;

		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		cost[start] = 0;
		pq.push({ 0,start });

		while (!pq.empty()) {
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for (auto u : edge[from]) {
				T w = v + u.first;
				int to = u.second;
				if (w < cost[to]) {
					cost[to] = w;
					pq.push({ w,to });
				}
			}
		}
		return;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, r;
    cin >> N >> M >> r;
    Dijkstra<ll> dijk(N, LINF);
    REP(i,M){
        ll c, d, e;
        cin >> c >> d >> e;
        dijk.make_edge(c, d, e);
    }
    dijk.solve(r);
    REP(i,N){
        if(dijk.cost[i] == LINF) cout << "INF" << endl;
        else cout << dijk.cost[i] << endl;
    }
}


Measured memory_bytes: 19264
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
#define MOD 1000000007

int main(){
  ll n; cin >> n;
  ll sum = 0;
  vector<ll> a(n);

  for(ll i=0;i<n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }

  ll ans = 0;

  for(ll i=0;i<n;i++){
    ans += ((a.at(i)%MOD)*((sum-a.at(i))%MOD))%MOD;
    sum -= a.at(i);
  }

  cout << ans%MOD << endl;

}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
using namespace std;
char c[19];
string s;
int n=0;
int main(){
  cin>>s;
  for(int i=0;i<s.length();i++){
    if(s[i]!='B'){
      c[n]=s[i];
      n++;
    }
    else if(n>0)n--;
  }
  for(int i=0;i<n;i++)cout<<c[i];
  cout<<endl;
}

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

int mem[100];
int n;

void Print()
{
	cout << "show" << endl;
	for(int i = 0; i < n; i++)
		printf("%d ", mem[i]);
	printf("\n");
}

int solve()
{
	int cnt = 0;
	for(int i = 0; i < n-2; i++)
	{
		if((mem[i+1] > mem[i] && mem[i+1] < mem[i+2]) || (mem[i+1] < mem[i] && mem[i+1] > mem[i+2]))  cnt++;
	}
	return cnt;
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> mem[i];
	}
	//Print();
	printf("%d\n", solve());
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int ans = s.size() + t.size();
    for(int i = s.size() - 1; i >= 0; i--)
    {
        string a = s.substr(i);
        string b = t.substr(0, (int)a.size());
        if(a == b) ans = min(ans, (int)(s.size() + t.size() - a.size()));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1e5 + 5; 
using namespace std; 

int a[N], c[N], n, ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++) c[a[i] = read <int> ()]++;
	for(int i = 1; i <= 100000; i++) ans = max(ans, c[i - 1] + c[i] + c[i + 1]);
	printf("%d\n", ans); 
	return 0; 
}


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

#define ll long long

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

ll lcm(ll a, ll b) {
   return a / gcd(a, b) * b;
}

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

   ll ans = 1;
   for (int i = 0; i < n; i++) {
      ll t;
      cin >> t;
      ans = lcm(ans, t);
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// OURL: https://atcoder.jp/contests/abc132/tasks/abc132_a

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  // char a,b;
  // int a,b,c,d;
  bool ans = false;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ans = true;
  else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ans = true;
  else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) ans = true;


  if (ans) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}

		boolean flg = false;

		a:for(int i = 0;i < a.length;i++ ){
			if(a[i] % 2 == 0){
				if(a[i] % 3 == 0 || a[i] % 5 == 0){

				} else {
					flg = true;
					break a;
				}
			}
		}

		if(flg){
			System.out.println("DENIED");
		} else{
			System.out.println("APPROVED");
		}
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
const int MAX = 2200000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll k;
  string s;
  cin >> k >> s;
  
  ll n = s.size();
  
  COMinit();
  
  ll ans = 0;
  for (ll i = 0; i <= k; i++) { // i: sと異なる文字の数
    ll keep = power(25, i, MOD);
    keep *= COM(k + n, i);
    keep %= MOD;
    ans += keep;
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 56000
# 2020/07/25
# AtCoder Beginner Contest 050 - B

# Input
n = int(input())
t = list(map(int,input().split()))
m = int(input())
tsum = sum(t)

for i in range(m):
    p, x = map(int,input().split())
    # Output
    print(tsum - t[p-1] + x)


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

int main(){
  double N,K;
  cin>>N>>K;
  vector<double> p(N),sum(N);
  double E=0;
  for(int i=0;i<N;i++){
    cin>>p.at(i);
    p.at(i)=(p.at(i)+1.0)/2.0;
    if(i==0){
      sum.at(i)=p.at(i);
    }else{
      sum.at(i)=sum.at(i-1)+p.at(i);
    }
  }
  for(int i=K;i<N;i++){
    if(sum.at(i)-sum.at(i-K)>E){
      E=sum.at(i)-sum.at(i-K);
    }
  }
  cout<<setprecision(16)<<max(E,sum.at(K-1))<<endl;
    
}

Measured memory_bytes: 3328
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
 
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]
 
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]
 
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())
 
def log(*args):
    print("DEBUG:", *args, file=sys.stderr)
 
r = int(input())
print(2 * r * 3.141519)

Measured memory_bytes: 67700
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;


unordered_map<int, int>penki;
int main(){
	int p[3];
	
	for(int i = 0; i < 3; i++){
		cin>>p[i];
		penki[p[i]]++;
	}
	cout<<penki.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String p = scan.next();
		boolean check = false;
		for(int i = 0 ; i < s.length() ; i++) {
			String fs = s.substring(i,i+1);
			String fp = p.substring(0,1);
			if(fs.equals(fp)){
				String sort = s.substring(i,s.length());
				String c = s.substring(0,i);
				check = search(sort+c,p);
				if(check == true) {
					System.out.println("Yes");
					break;
				}
			}
		}
		if(check == false) {
			System.out.println("No");
		}
	}
	public static boolean search(String s , String p) {
		for(int i = 0 ; i < p.length() ; i++) {
			String fs = s.substring(i,i+1);
			String fp = p.substring(i,i+1);
			if(!fs.equals(fp)){
				return false;
			}
		}

		return true;
	}
}



Measured memory_bytes: 26288
n = input()
V = input().split(" ")
C = input().split(" ")

n = int(n)
V_tmp = []
for v in V:
    V_tmp.append(int(v))
V = V_tmp
C_tmp = []
for c in C:
    C_tmp.append(int(c))
C = C_tmp
SA = []
for i in range(n):
    SA.append(V[i]-C[i])
max_ = 0
for i in range(n):
    if SA[i] >= 0:
        max_ += SA[i]
print(max_)

Measured memory_bytes: 3064