akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
string str;
int p, q, r;
 
int negation( int &pt);
int prod( int x, int y );
int disj( int x, int y );
int calc( int &pt );
int getvalue( int &pt );
 
int solve(){
 
	int cnt = 0;
	cin >> str;
	if( str == "." ) { return 0; }
 
 
	for( p = 0; p < 3; p++ )
		for( q = 0; q < 3; q++ )
			for( r = 0; r < 3; r++ ) {
				int ptr = 0;
				if( calc( ptr ) == 2 )
					cnt ++;
			}
 
	cout << cnt << endl;
 
	return 1;
 
}
 
int main( void ) {
 
	while( solve() ) {}
 
	return 0;
}
 
int getvalue( int &pt ) {
	switch( str[pt] ) {
		case '0':
			return 0;
		break;
		case '1':
			return 1;
		break;
		case '2':
			return 2;
		break;
		case 'P':
			return p;
		break;
		case 'Q':
			return q;
		break;
		case 'R':
			return r;
		break;
	}
	return 0;
}
 
int negation( int &pt ) {
	if( str[pt] == '-' ) {
		pt ++;
		return 2 - negation(pt);
	}
	if( str[pt] == '(' ) {
		pt ++;
		return 2-calc(pt);
	}
	int ret = 2-getvalue(pt);
	pt ++;
	return ret;
}
 
int disj( int x, int y ) {
	//?????????
	if( x == y ) { return x; }
	if( x + y > 2 ) { return 2; }
	return x + y;
}
 
int prod( int x, int y ) {
	//?????????
	if( x == 0 || y == 0 ) { return 0; }
	if( x == 2 && y == 2 ) { return 2; }
	return 1;
}
 
int calc( int &pt ) {
 
	//?????????????????????
	int lhs;
	if( str[pt] == '-' ) {
		lhs = negation(++pt);
	} else if( str[pt] == '(' ) {
		lhs = calc(++pt);
	} else {
		lhs = getvalue(pt);
		++pt;
	}
 
 
	//????????????lhs?????????
	if( ( pt >= str.length() - 1 ) || ( str[pt] == ')' ) ) {
		++pt;
		return lhs;
	}
 
	//?????????????????????
	char op = str[pt];
	++pt;
 
	//?????????????????????
	int rhs;
	if( str[pt] == '-' ) {
		rhs = negation(++pt);
	} else if( str[pt] == '(' ) {
		rhs = calc(++pt);
	} else {
		rhs = getvalue(pt);
		++pt;
	}
 
	if( pt < str.length() && str[pt] == ')' ) {
		pt ++;
	}
 
 
	switch( op ) {
		case '+':
			return disj( lhs, rhs );
		break;
		case '*':
			return prod( lhs, rhs );
		break;
	}
 
	return -1;
 
}

Measured memory_bytes: 1192
#include <iostream> 
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::string;
#define PI 3.14159265358979323846
int main() 
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double hInMinutes = h * 5 + (m / 60.0) * 5;
    double angle = std::min(std::abs(hInMinutes - m), 60 - std::abs(hInMinutes - m)) * 6;
    angle *= (PI / 180);
    cout << std::setprecision(20) << std::sqrt((a * a) + (b * b) - (2 * a * b) * std::cos(angle)) << endl;

    

}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;

  cin >> N;

  bool can = false;

  for(int i=0;i<=25;i++){
    for(int j=0;j<=14;j++){
      int sum = 4*i + 7*j;
      if(sum==N) can = true;
    }
  }


  if(can){
   cout << "Yes" << endl;
  }

  else{
    cout << "No" << endl;
  }

 
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt();
    for(int i=n;i>=1;i--){
      if(i==2||i==4||i==8||i==16||i==32||i==64){
        System.out.println(i);
        break;
      }
      if(i==1){
        System.out.println(i);
        break;
      }
    }
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb                 push_back
#define bug(x)             cerr<<#x<<" "<<x<<endl;
#define T int time;        scanf("%d", &time); while(time--)
    vector<ll>ar;
  bool check(ll i,ll n){
    if(abs(i-n)<=1)return true;
    for(ll ii=n-1; ii>i; ii--)if(ar[ii]<ar[ii-1])
      cout<<ar[ii]<<" ";
    cout<<endl;
    return true;
  }

   int main(){
      ll h,a;
      cin>>h>>a;
      ll r=ceil(h*1.0/a*1.0);
      cout<<r<<endl;
   

     }
   

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

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0;
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

template <class T>
inline void put(T x)
{
	if (x > 9)
		put(x / 10);
	putchar(x % 10 + 48);
}

template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}

const int N = 1e5 + 5;
int n, ans;

struct seg
{
	int l, r;

	seg() {}
	seg(int L, int R):
		l(L), r(R) {}

	inline int len()
	{
		return r >= l ? r - l + 1 : 0;
	}

	inline void scan()
	{
		read(l);
		read(r);
	}

	inline bool operator < (const seg &a) const
	{
		return r < a.r || r == a.r && l > a.l;
	}

	inline seg operator & (const seg &a) const 
	{
		return seg(Max(l, a.l), Min(r, a.r));
	}
}p[N], pre[N], suf[N];

inline void solve()
{
	pre[0] = seg(1, 1e9);
	for (int i = 1; i <= n; ++i)
		pre[i] = pre[i - 1] & p[i];
	suf[n + 1] = seg(1, 1e9);
	for (int i = n; i >= 1; --i)
		suf[i] = suf[i + 1] & p[i];
	for (int i = 1; i < n; ++i)
		CkMax(ans, pre[i].len() + suf[i + 1].len());
	for (int i = 1; i <= n; ++i)
		CkMax(ans, (pre[i - 1] & suf[i + 1]).len() + p[i].len());
}

int main()
{
	read(n);
	for (int i = 1; i <= n; ++i)
		p[i].scan();

	std::sort(p + 1, p + n + 1);
	solve();
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
int a[15][15];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
    scanf("%d",&a[i][j]);
    for(int k=0;k<10;k++)
    for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
    {
    	if(i==j||i==k||j==k) continue;
    	if(a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j];
	}
	int ans=0;
	for(int i=0;i<n*m;i++)
	{
		int x;scanf("%d",&x);
		if(x==-1) continue;
		ans+=a[x][1];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
from collections import Counter

N = int(input())
S = [input() for i in range(N)]

C = Counter(S)

C = sorted(C.items(), key=lambda x:x[1], reverse=True)


cnt_max = C[0][1]
ans = []
for i in range(len(C)):
    if cnt_max > C[i][1]:
        break
    else:
        ans.append(C[i][0])

ans.sort()

for w in ans:
    print(w)

Measured memory_bytes: 49496
fun main(args: Array<String>) {
    val (x, y, z, k) = readLine()!!.split(" ").map(String::toLong)
    val xList = readLine()!!.split(" ").map(String::toLong).sortedDescending()
    val yList = readLine()!!.split(" ").map(String::toLong).sortedDescending()
    val zList = readLine()!!.split(" ").map(String::toLong).sortedDescending()

    val nums = mutableListOf<Long>()
    for (xi in xList.indices) {
        for (yi in yList.indices) {
            if (xi * yi > k) break
            for (zi in zList.indices) {
                if (xi * yi * zi > k) break
                val sum = xList[xi] + yList[yi] + zList[zi]
                nums.add(sum)
            }
        }
    }
    nums.sortDescending()
    for (i in 0 until k.toInt()) {
        println(nums[i])
    }
}

Measured memory_bytes: 175732
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef tuple<int,int,int,int,int,int,int> P;
map<P,int> mp;
int n,m;
int a[51],b[51];
int dfs(int al,int ar,int bl,int br,int f,int t,int s){
  if(mp.count(make_tuple(al,ar,bl,br,f,t,s)))
    return mp[make_tuple(al,ar,bl,br,f,t,s)];
  //cout<<al<<" "<<ar<<" "<<bl<<" "<<br<<" "<<f<<" "<<t<<" "<<s<<endl;
  int res;
  if(s==2){
    res=0;
  }else{
    int ta=0,tb=0;
    int ia=al,ib=bl;
    while(ia<ar||ib<br){
      if(f){
	if(ib<br){
	  if(~b[ib]) tb+=b[ib];
	  else ta=0;
	  ib++;
	}
	if(ia<ar){
	  if(~a[ia]) ta+=a[ia];
	  else tb=0;
	  ia++;
	}
      }else{
	if(ia<ar){
	  if(~a[ia]) ta+=a[ia];
	  else tb=0;
	  ia++;
	}
	if(ib<br){
	  if(~b[ib]) tb+=b[ib];
	  else ta=0;
	  ib++;
	}
      }
    }
    res=ta-tb;
    if(t) res*=-1;
    res-=dfs(ar,ar,br,br,!t,!t,s+1);
  }
  if(t==1&&br<m){
    res=max(res,-dfs(al,ar,bl,br+1,f,!t,0));
  }
  if(t==0&&ar<n){
    res=max(res,-dfs(al,ar+1,bl,br,f,!t,0));
  }
  //cout<<al<<" "<<ar<<" "<<bl<<" "<<br<<" "<<f<<" "<<t<<" "<<s<<"/"<<res<<endl;
  return mp[make_tuple(al,ar,bl,br,f,t,s)]=res;
}
signed main(){
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];
  cout<<dfs(0,0,0,0,0,0,0)<<endl;
  return 0;
}

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

#define ll long long int
#define vi vector<int>
#define ii pair< int , int >
#define vii vector<ii>
#define FOR(i, n) for(ll i = 0; i < (ll)n; i++)
int MAX(int a, int b){return (a > b) ? a:b;}
int MIN(int a, int b){return (a < b) ? a:b;}
int ABS(int x){return (x > 0) ? x:-x;}
int left(int x){return (x<<1);}
int right(int x){return (x<<1)+1;}
int lsone(int x){return (x&(-x));}

const int maxn = 3e3 + 5;

int lenA, lenB;
char strA[maxn], strB[maxn];
int ans[maxn][maxn];
bool found[maxn][maxn];

int dp(int a, int b){
	if(a == lenA || b == lenB) return 0;
	if(found[a][b]) return ans[a][b];
	found[a][b] = true;
	ans[a][b] = max(dp(a+1, b), dp(a, b+1));
	if(strA[a] == strB[b])
		ans[a][b] = max(ans[a][b], dp(a+1, b+1)+1);
	return ans[a][b];
}

void print(int a, int b){
	if(a == lenA || b == lenB) return;
	if(dp(a, b) == dp(a+1, b)) print(a+1, b);
	else if(dp(a, b) == dp(a, b+1)) print(a, b+1);
	else if(strA[a] == strB[b] && dp(a, b) == dp(a+1, b+1)+1){
		printf("%c", strA[a]);
		print(a+1, b+1);
	}
}

int main(){
	scanf("%s", strA);
	scanf("%s", strB);
	lenA = strlen(strA);
	lenB = strlen(strB);
	print(0, 0);
	printf("\n");
}

Measured memory_bytes: 44800
fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(
        |e| e.parse().ok().unwrap()
        ).collect()
}

fn main()
{
    let nm :Vec<u32> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let mut l = 0;
    let mut r = n;
    for _ in 0..m {
        let lr = read_vec();
        l = if {l < lr[0]} {lr[0]} else {l};
        r = if {r > lr[1]} {lr[1]} else {r};
    }
    println!("{}", if {r>=l} {r-l+1} else {0});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXL=100050;
char S[MAXL];

int main() {
	scanf("%s",S);
	int g=0, p=0;
	int l=strlen(S);
	for(int i=0;i<l;i++)
		if(S[i]=='g') g++;
		else p++;
	cout << (g-p)/2 << endl;
	return 0;
}


Measured memory_bytes: 384
n, m = map(int, input().split())
ms = [[] for _ in range(m)]
for eachm in range(m):
    ks = list(map(int, input().split()))
    for i in range(1, ks[0]+1):
        ms[eachm].append(ks[i]-1)
ps = list(map(int, input().split()))
res = 0
for status in range(2 ** n):
    switches = [(status >> bit) % 2 for bit in range(n)]
    num_on = 0
    for eachm in range(m):
        p = ps[eachm]
        for eachs in ms[eachm]:
            p ^= switches[eachs]
        if p == 0:
            num_on += 1
    if num_on  == m:
        res += 1
print(res)

Measured memory_bytes: 3188
N = int(input())
flag = False
k = 0
if N == 1:
  print('Yes')
  print(2)
  print(1,1)
  print(1,1)
  exit()
for i in range(N+1):
    if i*(i-1)/2 == N:
        flag = True
        k = i
        break
if flag == False:
    print('No')
else:
    L = []
    cnt = 0
    dot = 1
    for j in range(k-1):
        M = []
        while cnt < j+1:
            M.append(dot)
            cnt += 1
            dot += 1
        L.append(M)
        cnt = 0
    ans = []
    for i in range(k-1):
      S = L[i]
      for j in range(i+1,k-1):
        S += [L[j][i]]
      ans.append(S)
    T = []
    for i in range(k-1):
      T.append((i+1)*(i+2)//2)
    ans.append(T)
    print('Yes')
    print(k)
    for i in range(len(ans)):
      ans[i] = [k-1]+ans[i]
      for j in range(len(ans[i])):
        if j != len(ans[i])-1:
          print(ans[i][j],end = ' ')
        else:
          print(ans[i][j],end = '')
      print()

Measured memory_bytes: 11204
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,p[200005],pw[200005],tr[2][200005],ans=0,alr,ty=0;
const int mod=998244353;
int mypow(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
int lowbit(int p){return p&-p;}
int M(int x){return x>=mod?x-mod:x;}
void modify(int p,int v)
{
	while(p<=n)
	{
		tr[ty][p]=M(tr[ty][p]+v);
		p+=lowbit(p);
	}
}
int ask(int p)
{
	//printf("%d %d %d\n",p,ty,tr[0][2]);
	int ans=0;
	while(p)
	{
		ans=M(ans+tr[ty][p]);
		//printf("!%d %d %d\n",ans,p,tr[0][p]);
		p-=lowbit(p);
	}
	return ans;
}
int main()
{
	ty=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	pw[0]=1;
	pw[1]=1ll*(k)*mypow(k-1,mod-2)%mod;
	for(int i=2;i<=n;i++)pw[i]=1ll*pw[i-1]*pw[1]%mod;
	ans=1ll*k*(k-1)/2ll%mod*mypow(2,mod-2)%mod;
	alr=1ll*(k-1)*mypow(k,mod-2)%mod*mypow(2,mod-2)%mod;
	//printf("%d\n",ans);
	for(int i=1;i<=k;i++)modify(p[i],1),ty=1,modify(p[i],1),ty=0;
	for(int i=k+1;i<=n;i++)
	{
		ans=(1ll*ans+1ll*ask(p[i])*alr%mod)%mod;
		//printf("%d %d %d %d %d %d\n",ask(p[i]),alr,ans,mypow(4,mod-2),ask(n),ask(p[i]));
		ans=(1ll*ans-1ll*(ask(n)-ask(p[i])+mod)*alr%mod+mod)%mod;
		//printf("@%d\n",ans);
		ty=1;
		ans=(1ll*ans+ask(n)-ask(p[i]))%mod;
		modify(p[i],1);
		//printf("@%d %d %d %d\n",ans,ask(p[i]),ask(n));
		ty=0;
		modify(p[i],pw[i-k]);
		alr=1ll*alr*(k-1)%mod*mypow(k,mod-2)%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4848
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(String.format("%d %d", a * b, 2 * (a + b)));
        }
    }
}



Measured memory_bytes: 26208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;

int main()
{
	int n, r;
	while (cin >> n >> r, n || r) {
		vector<PII> shuffles;
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			shuffles.push_back(make_pair(p, c));
		}
		reverse(shuffles.begin(), shuffles.end());
		int index = 0;
		for (int i = 0; i < shuffles.size(); ++i) {
			int p = shuffles[i].first, c = shuffles[i].second;
			if (index < c) {
				index += p - 1;
			} else if (index < c + p - 1) {
				index -= c;
			}
		}
		cout << n - index << endl;
	}
}

Measured memory_bytes: 1196
#include <stdio.h>

int sosuu00(int n);

int main()
{
	int n[100];
	int small[100];
	int big[100];
	int i=0,k=0,count=0;
	int ret;
	while(1){
		ret=scanf("%d", &n[i]);
		if(ret==EOF){
			break;
		}
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		for(k=n[i]+1; ; k++){
			if(sosuu00(k)){
				big[i]=k;
				break;
			}
		}
		for(k=n[i]-1; ; k--){
			if(sosuu00(k)){
				small[i]=k;
				break;
			}
		}
	}
	for(i=0; i<count; i++){
		printf("%d %d\n", small[i], big[i]);
	}
	return 0;
}

int sosuu00(int n)
{
	int i;
	for(i=2; i<n; i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int x,y;
        cin>>x>>y;
        if(y<2*x||y>4*x)
        {
            cout<<"No\n";
        }
        else
        {
            if(y%2==0)cout<<"Yes\n";
            else cout<<"No\n";
        }
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;

typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatirx;
typedef vector< string > SArray;
typedef vector< pii > PArray;

inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }
inline void modAdd(int& _a, int _b, int _MOD) { _a = (_a + _b) % _MOD; }

int m, n, k, d;
int cal[10];

// home : 0, cake : 101 ~ 106, land 1 ~ 100, D 107

struct Edge {
	int t, d, c;
	Edge(int _t, int _d, int _c) : t(_t), d(_d), c(_c) {}
};
bool operator > (const Edge& a, const Edge& b) { return a.c > b.c; }

vector< vector< Edge > > edges;
int cost[1 << 8][110];

void solve() {
	for_(i,0,1 << 8) fill(cost[i], cost[i] + 110, iINF);
	
	cost[0][0] = 0;
	priority_queue< Edge, vector< Edge >, greater< Edge > > q;
	q.push( Edge(0, 0, 0) );
	
	while (!q.empty()) {
		Edge ce = q.top(); q.pop();
		
		if (cost[ce.d][ce.t] < ce.c) continue;
		
		int e_size = size_of(edges[ce.t]);
		
		for_(i,0,e_size) {
			Edge e = edges[ce.t][i];
			
			if (101 <= e.t && e.t <= 106) {
				int ck = e.t - 100;
				if (ce.d >> ck & 1) continue;
				
				int nd = ce.d | 1 << ck;
				
				if (cost[nd][e.t] > ce.c + e.d * k - cal[ck - 1]) {
					cost[nd][e.t] = ce.c + e.d * k - cal[ck - 1];
					q.push( Edge(e.t, nd, ce.c + e.d * k - cal[ck - 1]) );
				}
			} else {
				if (cost[ce.d][e.t] > ce.c + e.d * k) {
					cost[ce.d][e.t] = ce.c + e.d * k;
					q.push( Edge(e.t, ce.d, ce.c + e.d * k) );
				}
			}
		}
	}
	
	int ans = iINF;
	for_(i,0,1<<8) ans = min(ans, cost[i][107]);
	cout << ans << endl;
}

int parse(string s) {
	if (s[0] == 'H') return 0;
	if (s[0] == 'D') return 107;
	
	if (s[0] == 'C') {
		s = s.substr(1);
		stringstream ss(s);
		int u; ss >> u;
		return u + 100;
	}
	
	s = s.substr(1);
	stringstream ss(s);
	int u; ss >> u;
	return u;
}

int main() {
	while (cin >> m >> n >> k >> d, m) {
		for_(i,0,m) cin >> cal[i];
		edges.assign(110, vector< Edge >());
		
		for_(i,0,d) {
			string u, v; int dst; cin >> u >> v >> dst;
			int uu = parse(u), vv = parse(v);
			edges[uu].push_back( Edge(vv, dst, 0) );
			edges[vv].push_back( Edge(uu, dst, 0) );
		}
		
		solve();
	}
	return 0;
}

Measured memory_bytes: 1456
N = int(input())
S = list(input())
alp = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(len(S)):
    for j in range(len(alp)):
        if alp[j] == S[i]:
            ans = int((j + N) % len(alp))
            S[i] = alp[ans]
            break
        else:
            continue
print(''.join(S))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[100010];
    rep(i, N) cin >> A[i];
    cout << (N - 1 + K - 1 - 1) / (K - 1) << endl;

    return 0;
}


Measured memory_bytes: 3960
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll tk, ao;
    tk = ceil(c / double(b));
    ao = ceil(a / double(d));
    if(tk <= ao){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
N = gets.to_i
A = gets.split.map(&:to_i)
C = N * (N + 1) / 2

class PileAccum
  def initialize
    @cursor = 0
    @tot = 0
    @h = Hash.new(0)
  end
  def add_sum(x)
    @h[x] += 1
    if @cursor < x
      while @cursor < x
        @cursor += 1
        @tot += @h[@cursor]
      end 
    elsif x < @cursor
      @tot += 1
      while x < @cursor
        @tot -= @h[@cursor]
        @cursor -= 1
      end 
    else
      @tot += 1
    end
    @tot 
  end
end 

def calc(x)
  ar = [0]
  i = 0
  A.each do |a|
    i += (a >= x ? 1 : -1)
    ar << i 
  end
  tot = 0
  b = PileAccum.new
  ar.each do |v|
    tot += b.add_sum(v) - 1
  end
  tot * 2 >= C
end

puts A.sort.reverse!.bsearch{|x| calc(x)}


Measured memory_bytes: 58104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	ll n, m;
	cin>>n>>m;
	if(n < m) swap(n, m);
	if(n == m && m == 1)
		cout<<1<<'\n';
	else
	{
		if(m == 1)
			cout<< n - 2<<'\n';
		else
			cout<<(n - 2) * (m - 2)<<'\n';
	}
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int X, Y; cin >> X >> Y;
	if(Y%2 == 0 and 2*X <= Y and Y <= 4*X){
		cout << "Yes" << ln;
	}else {
		cout << "No" << ln;
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= b)
    {
        cout << "0" << endl;
        return 0;
    }
    cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

p = int(readline())
A = np.array(read().split(),np.int64)

"""
・f_i(x) = 1 - (x-a)^{p-1} とすると、f_i(x)はx=iのみで1をとる：これは二項係数とべき乗
・sum a_if_i が答
"""

power = np.ones((p,p),dtype=np.int64)
x = np.arange(p,dtype=np.int64)
for n in range(1,p):
    power[:,n] = power[:,n-1] * x % p

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact, fact_inv = make_fact(p,p)

# p-1 C i
comb = fact[p-1] * fact_inv[0:p] % p * fact_inv[p-1::-1] % p

comb[::2] *= (-1)

F = power * comb[:,None] % p
F[:,-1] += 1

answer = ((F * A[:,None]).sum(axis=0) % p)[::-1]

print(' '.join(answer.astype(str)))

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

#define int long long

using namespace std;

const int N = 5e5 + 5;
const int base = 317;
const int mod = 1e9 + 2277;

string s;
int Hash[N], pw[N], n;
bool pref[N], suff[N];

void buildHash(){
    s = "#" + s;
    pw[0] = 1;
    for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * base) % mod;
    Hash[0] = 0;
    for (int i = 1; i <= n; i++) Hash[i] = (Hash[i - 1] * base + s[i]) % mod;
}

int get (int l, int r) {
    return ((1LL * Hash[r] - 1LL * Hash[l - 1] * pw[r - l + 1]) % mod + mod) % mod;
}

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

    cin >> s;
    n = s.length();

    bool same = true;
    for (int i = 0; i < n; i++) if (s[i] != s[0]) same = false;
    if (same) {
        cout << n << "\n" << 1;
        return 0;
    }

    buildHash();
    memset(pref, 0, sizeof(pref));
    memset(suff, 0, sizeof(suff));

    for (int i = 1; i <= n; i++) {
        for (int j = i * 2; j <= n; j = j + i) {
            if (get(1, i) == get(j - i + 1, j)) pref[j] = true;
            else break;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = n - i * 2 + 1; j >= 1; j = j - i) {
            if (get(j, j + i - 1) == get(n - i + 1, n)) suff[j] = true;
            else break;
        }
    }

    if (!pref[n]) return cout << 1 << "\n" << 1, 0;
    int ans = 0;
    for (int i = 1; i < n; i++) if (!pref[i] && !suff[i + 1]) ans++;
    cout << 2 << "\n" << ans;
    return 0;
}


Measured memory_bytes: 9652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node {
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;
NodePointer nil;

NodePointer listSearch(int key){
  NodePointer c;
  c = nil->next;
  while( c != nil && c->key != key ){
    c = c->next;
  }
  return c;
}

void init(){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer c = nil->next;
  int isf = 0;
  while( 1 ){
    if( c == nil ) break;
    if( isf++ > 0 ) printf(" ");
    printf("%d", c->key);
    c = c->next;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  NodePointer x = (NodePointer)malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next =x;
  x->prev = nil;
}

int main(){
  int key, n, i, size=0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for( i = 0 ; i < n ; i++ ){
    scanf("%s%d",com,&key);
    if( com[0] == 'i' ){
      insert(key);
      np++;
      size++;
    }
    else if( com[0] == 'd' ){
      if( strlen(com) > 6 ){
	if( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      }
      else {
	deleteKey(key);
	nd++;
      }
      size--; 
    }
  }
  printList();
  return 0;
}



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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        m: usize
    }
    if 2 * n >= m {
        println!("{}", m / 2);
    } else {
        println!("{}", n + (m - 2 * n) / 4);
    }
}


Measured memory_bytes: 4352
import sys
S = input()
for i in range(len(S)):
    if i % 2 == 1 and S[i] == "R":
        print("No")
        sys.exit(0)
    elif i % 2 == 0 and S[i] =="L":
        print("No")
        sys.exit(0)
print("Yes")    

Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys


def solve(X: int):
    c500 = X // 500
    rem = X - c500 * 500
    c5 = rem // 5
    print(1000*c500+c5*5)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);

int main(){
  int w,h,n;
  cin >> w >> h >>n;
  vector<int>l;
  vector<int>r;
  vector<int>u;
  vector<int>d;
  l.push_back(0);
  r.push_back(w);
  d.push_back(0);
  u.push_back(h);
  rep(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1)l.push_back(x);
    if(a==2)r.push_back(x);
    if(a==3)d.push_back(y);
    if(a==4)u.push_back(y);
  }
  sort(l.begin(),l.end(),greater<int>());
  sort(r.begin(),r.end());
  sort(d.begin(),d.end(),greater<int>());
  sort(u.begin(),u.end());
  if(l[0]<r[0] && d[0]<u[0]){
    cout << (r[0]-l[0])*(u[0]-d[0]) << endl;
  }
  else cout << 0 << endl; 
  return 0;
}


Measured memory_bytes: 256
my $input = <STDIN>;
chomp $input;
my ($A, $B, $C, $K) = split /\s+/, $input;
my $tmp = $A - $K;
if ($tmp >= 0) {
    print $K;
} else {
    $tmp = $B + $tmp;
    if ($tmp >= 0) {
        print $A;
    } else {
        print $A + $tmp;
    }
}

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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll a[300000];

int main(){
	int n,K;cin>>n>>K;
	bool b=0;
	rep(i,n){
		scanf("%lld",&a[i]);
		if(a[i]>=0)b=true;
	}
	if(n==K){
		ll ans=1;
		rep(i,n){
			(ans*=a[i])%=MOD;
		}
		cout<<(ans+MOD)%MOD<<endl;
		return 0;
	}
	if(!b&&(K%2==1)){
		sort(a,a+n,greater<>());
		ll ans=1;
		rep(i,K){
			(ans*=a[i])%=MOD;
		}
		cout<<(ans+MOD)%MOD<<endl;
		return 0;
	}
	priority_queue<ll>A,B;
	rep(i,n){
		if(a[i]>=0)A.push(a[i]);
		else B.push(-a[i]);
	}
	priority_queue<ll,vector<ll>,greater<ll>>usedA,usedB;
	rep(i,K){
		if(!A.empty()&&(B.empty()||A.top()>B.top()))usedA.push(A.top()),A.pop();
		else usedB.push(B.top()),B.pop();
	}
	if(!usedA.empty()&&usedA.top()==0){
		puts("0");return 0;
	}
	if(usedB.size()%2==1){
		if(!B.empty()&&!usedA.empty()&&(A.empty()||B.top()*usedB.top()>A.top()*usedA.top())){
			usedA.pop();usedB.push(B.top());
		}
		else{
			usedB.pop();usedA.push(A.top());
		}
	}
	ll ans=1;
	while(!usedA.empty())(ans*=usedA.top())%=MOD,usedA.pop();
	while(!usedB.empty())(ans*=usedB.top())%=MOD,usedB.pop();
	cout<<ans<<endl;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	REP(i, n) cin >> v[i];
	int count = 0;
	int sum = accumulate(ALL(v), 0);

	REP(i, n){
		if((double)v[i]/sum >= (double)0.25/m){
			count++;
		}
	}

	//cout << count << endl;
	if(count >= m){
		cout << "Yes" << endl;
	}
    else {
    	cout << "No" << endl;
    }
}


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

int room[4][3][10];

int main(){
  int n; cin >> n;
  for(int i=0; i<n; i++){
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    room[b-1][f-1][r-1] += v;
  }
  for(int i=0; i<4; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<10; k++){
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    if(i!=3) cout << "####################" << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;


namespace Main{

class Program{

static void Main(string[] args){

int n = int.Parse(Console.ReadLine());
var lineH = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

int sum = lineH[0];
int subNum = 0;
int abs = 0;
for(int i = 0;i < n-1; i++){

abs = Math.Abs(lineH[i] - lineH[i + 1]);

if(lineH[i] < lineH[i + 1]){
sum += abs;

}

}
Console.WriteLine(sum);
}

}

}

Measured memory_bytes: 13396
S = input()

ans = 0
tmp = 0
ATCG = ["A", "T", "C", "G"]

for i in range(len(S)):
    if S[i] in ATCG:
        tmp = tmp + 1
        if i == len(S)-1:
            ans = max(ans, tmp)
    else:
        ans = max(ans, tmp)
        tmp = 0

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	char input[16];
	int i, j;

	while(scanf("%s", input) != EOF) {
		for(i = 0; i < 10; i++) {
			for(j = 0; j < 9 - i; j++) {
				input[j] = (input[j] + input[j + 1] - 2 * '0') % 10 + '0';
			}
		}

		printf("%c\n", input[0]);
	}

	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	

	string s;
	cin >> s;
	sort(ALL(s));
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[3])
		cout << "Yes";
	else
		cout << "No";
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  string acgt = "ACGT";
  int cnt = 0;
  rep(i, s.length()) {
    bool isacgt = false;
    rep(j, acgt.length()) {
      if (s[i] == acgt[j]) isacgt = true;
    }
    if (isacgt)
      cnt++;
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N, x, count = 0;
    cin >> N >> x;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < N; i++){
        if(x < a[i] || (x > a[i] && i == N - 1)) break;
        x -= a[i];
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

const int inf=1000000009;

typedef double db;
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

ll n,A,B,C,D,dis,p,t,l,r,mid,da,L,R;

int main() {
	n=rd()-1,A=rd(),B=rd(),C=rd(),D=rd();
	dis=abs(B-A),p=D-C;
	
	l=0,r=n/2;
	while (l<=r) {
		mid=l+r>>1;
		da=mid*2+(n&1);
		L=da*C-p*((n-da)/2);
		R=da*D+p*((n-da)/2);
		if (L<=dis && dis<=R)
			return puts("YES"),0;
		else if (R<dis) l=mid+1;
		else r=mid-1;
	}
	return puts("NO"),0;
}






Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        if(a>b) swap(a,b);
        ll ans=a-1;
        ll tar=sqrt(a*b);
        if(tar*tar==a*b) tar--;
        ll ta=tar;
        if(tar*(tar+1)<a*b) ta++;
        //dbg(ta,tar);
        ans+=min(ta-a,b-1-tar);
        if(ta==a&&(ta+1)*tar<a*b) ans++;
        ans+=tar-1;
        print(ans);
    }
}

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

#define MAX_N 2503
#define edge pair<int ,int>
#define to first
#define we second
#define INF 0x3f3f3f3f

int n ,m ,p;
vector <edge> adj[MAX_N];

bool vis[MAX_N] ,in_rch1[MAX_N];
void dfs(int u){
    in_rch1[u] = 1;
    for(edge e : adj[u]) if(!in_rch1[e.to])
        dfs(e.to);
}
int reach(int u){
    if(u == n){
        printf("-1\n");
        exit(0);
    }
    vis[u] = 1;
    for(edge e : adj[u]) if(!vis[e.to])
        reach(e.to);
}

int main()
{
    scanf("%d%d%d",&n,&m,&p);
    for(int a,b,c,i=0; i<m; i++){
        scanf("%d%d%d",&a,&b,&c);
        adj[a].push_back({b ,p-c});
    }

    vector <int> dist(n+1 ,INF);
    dist[1] = 0;
    for(int o=1; o<n; o++){
        for(int i=1; i<=n; i++)
        for(auto e : adj[i])
            if(dist[e.to] > dist[i]+e.we)
                dist[e.to] = dist[i]+e.we;
    }

    dfs(1);
    for(int i=1; i<=n; i++)
    for(auto e : adj[i])
        if(dist[e.to] > dist[i]+e.we && in_rch1[i])
            reach(e.to);

    printf("%d\n",max(0 ,-dist[n]));
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read() {
	int x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')f=-f;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+ch-'0';
	return x*f;
}
#define _ read()
const int N=1e5+5;
int x[N],b[N],n,m,ans;
inline bool cmp( int a,int b ) { return a>b; }
main() {
	n=_; m=_;
	if(n>=m) return puts("0"),0;
	for( int i=1;i<=m;i++ ) x[i]=_;
	sort(x+1,x+m+1);
	for( int i=2;i<=m;i++ ) b[i]=x[i]-x[i-1];
	sort(b+1,b+m+1,cmp);
	for( int i=n;i<=m;i++ ) ans+=b[i];
	cout<<ans;
}

Measured memory_bytes: 1792
from collections import defaultdict
A = input()
Alphabet = defaultdict(int)

for i in range(len(A)):
    Alphabet[A[i]] += 1
Total = (len(A) - 1) * len(A) // 2 + 1
for key in Alphabet:
    if Alphabet[key] > 1:
        double = (Alphabet[key] - 1) * Alphabet[key] // 2
        Total -= double
print(Total)

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> A(n);
	ll res = 0;
	int cur_max = 0;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		cur_max = max(cur_max, A[i]);
		res += cur_max - A[i];
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int Q;

int judge(P p0,P p1,P p2,P p3)
{
	P a = P(p1.first - p0.first,p1.second - p0.second);
	P b = P(p3.first - p2.first,p3.second - p2.second);
	double sa = sqrt(a.first*a.first + a.second*a.second);
	double sb = sqrt(b.first*b.first + b.second*b.second);
	double cs = (a.first*b.first+a.second*b.second)/sa/sb;
	if(1-cs < EPS || 1+cs < EPS){
		return 2;
	}else if(abs(cs) < EPS){
		return 1;
	}else{
		return 0;
	}
}

int main()
{
	scanf("%d",&Q);
	rep(i,Q){
		int a,b,c,d,e,f,g,h;
		scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
		printf("%d\n",judge(P(a,b),P(c,d),P(e,f),P(g,h)));
	}
	return 0;
}

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

int main(){
	int dp[100001][3], a[100001][3];
	int N; cin >> N;

	for(int i = 0; i < 100001; ++i){
		for(int j = 0; j < 3; ++j){
			dp[i][j] = 0;
		}
	}

	for(int i = 0; i < N; ++i){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}

	for(int i = 0; i < N; ++i){
		for(int j = 0; j < 3; ++j){
			for(int k = 0; k < 3; ++k){
				if(j == k) continue;
				if(dp[i+1][k] < dp[i][j] + a[i][k]){
					dp[i+1][k] = dp[i][j] + a[i][k];
				}
			}
		}
	}

	int tmp = max(dp[N][0], dp[N][1]);
	cout << ((tmp < dp[N][2]) ? dp[N][2] : tmp) << endl;

	return 0;
}


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

int main(){

    int a,n;
    cin >> n >> a;

    vector<ll> x(n);

    ll ma=0;
    rep(i,n){
        cin >> x[i];
        x[i]-=a;
        ma=max(ma,abs(x[i]));
    }

    vector<vector<ll> > dp(n+1,vector<ll>(2*n*ma+1,0));

    dp[0][n*ma]=1;

    for(int i=1;i<=n;i++){
        for(ll j=0;j<2*n*ma+1;j++){
            dp[i][j]=dp[i-1][j];
            if(j-x[i-1]>=0&&j-x[i-1]<2*n*ma+1){
                dp[i][j]+=dp[i-1][j-x[i-1]];
            }
        }
    }

    cout << dp[n][n*ma]-1 << endl;

    return 0;
}

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

int main(){
    int n, m;
    //red
    cin >> n;
    string s[n];
    rep(i, n) cin >> s[i];
    //blue
    cin >> m;
    string t[m];
    rep(i, m) cin >> t[i];
    int  y = 0;
    rep(i,n){
        int x = 0;
        string u = s[i];
        rep(j,n){
            if(u==s[j]){
                x++;
            }
        }
        rep(j,m){
            if(u==t[j]){
                x--;
            }
        }
        if(x>y){
            y = x;
        }
    }
    cout << y << endl;
}

Measured memory_bytes: 256