akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
const int mod = 1e9 + 7;

int n, w;
int dp[210][10010];
int nxt[210][10010];

int main(){
    cin >> n >> w;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    a.push_back(w + 1);
    dp[n][0] = 1;
    rep(i, 0, n){
        rep(j, 0, n + 1) rep(k, 0, w + 1) nxt[j][k] = 0;
        rep(j, 0, n + 1){
            rep(k, 0, w + 1){
                if(dp[j][k] == 0) continue;
                // not use
                if(j > i) (nxt[i][k] += dp[j][k]) %= mod;
                else (nxt[j][k] += dp[j][k]) %= mod;
                // use
                if(k + a[i] <= w) (nxt[j][k + a[i]] += dp[j][k]) %= mod;
            }
        }
        swap(dp, nxt);
    }
    int ans = 0;
    rep(i, 0, n + 1){
        rep(j, 0, w + 1){
            if(j + a[i] > w){
                (ans += dp[i][j]) %= mod;
            }
        }
    }
    cout << ans << endl;
}


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

int N;
vector<ll> a;
ll solve(int f) {
  ll ans = 0, sum = 0;
  rep(i, 0, N) {
    sum += a[i];
    if((i+f)&1) {
      if(sum < 1) {
        ll dif = 1 - sum;
        sum += dif;
        ans += dif;
      }
    } else {
      if(sum > -1) {
        ll dif = sum + 1;
        sum -= dif;
        ans += dif;
      }
    }
  }
  return ans;
}

int main() {
  cin >> N;
  a.resize(N);
  rep(i, 0, N) cin >> a[i];
  cout << min(solve(0), solve(1)) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
   vector<vector<char>> datain(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
     for (int j = 0; j < W; j++) {
       cin >> datain.at(i).at(j) ;
     }
  }  
   vector<vector<char>> dataout(H+2, vector<char>(W+2,'#'));
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          dataout.at(i+1).at(j+1) = datain.at(i).at(j);
        }
      }
  
      for (int i = 0; i < H+2; i++) {
        for (int j = 0; j < W+2; j++) {
          cout << dataout.at(i).at(j) ;
          }
        cout << endl; // 末尾なら改行
      }
}
  

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
#include<cmath>
#define pb push_back
#define ll long long
#define inf 1000000009
using namespace std;
int main(){
	int n,k;
	string str;
	cin>>n>>k;
	cin>>str;
	int grp = 1;
	for(int i=1;i<n;i++){
		if(str[i-1] != str[i])grp++;
	}
	if( grp % 2 == 1){
		int mx = (grp-1)/2;
		grp -= 2*min(k,mx);
	}
	else{
		int mx = grp/2 - 1;
		grp -= 2*min(k,mx);
		if(k>mx)grp--;
	}
	cout<<n-grp<<endl;
	return 0;
}

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

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

fn main() {
    let a: String = read();
    let b: String = read();
    let ab: f64 = (a + &b).parse().ok().unwrap();
    println!("{}",
        if ab.sqrt() == ab.sqrt().round() { "Yes" } else { "No" });
}

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

using namespace std;
int f(int x){
	if(x >= 4){
    	return 0;
    }else{
    	return 100000 * (4 - x);
    }
}

int main(){
	int x, y;
  cin >> x >> y;
  long long ans = 0;
	ans = f(x) + f(y);
  if(x == y && y == 1)
    ans += 400000;
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  int N,M;
  cin >> N >> M;
  int H[N];
  int check[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
    check[i]=0;
  }
  int M1[M];int M2[M];
  for(int i=0;i<M;i++){
    cin >> M1[i] >> M2[i];
  }
  for(int i=0;i<M;i++){
    if(H[M1[i]-1]>=H[M2[i]-1]){
      check[M2[i]-1]+=1;
      //cout <<M2[i]-1<<endl;
    }
    if(H[M1[i]-1]<=H[M2[i]-1]){
      check[M1[i]-1]+=1;
      //cout << M1[i]-1<<endl;
    }
  }
 long long int count=0;
  for(long long int i=0;i<N;i++){
    if(check[i]==0){
      count++;
    }
  }
  cout << count;
  cout << endl;
  return 0;
}


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

int main(){
  
  vector<int> vec(5);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2) >> vec.at(3) >> vec.at(4);
  int s = 1;
  
  for( int i=0;i<5;i++ ){
  if( vec.at(i)==0 ){
      
    s += i;
  
    }
  
  }
   
    cout << s << endl;
  
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    ll ans = 0;
    ll max_number = 1e7;
    vector<ll> era(max_number+1, 2);
    era.at(0) = 1;  era.at(1) = 1;
    for(i = 2;i <= max_number;++i){
        for(j = 2*i;j <= max_number;j += i){
            ++era.at(j);
        }
    }
    for(i = 1;i <= n;++i){
        ans += i*era.at(i);   
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 81384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int m=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    m=(abs(a.at(m))<abs(a.at(i))?i:m);
  }
  cout<<2*(n-1)<<endl;
  for(int i=0;i<n;i++)
    if(i!=m)
      cout<<m+1<<" "<<i+1<<endl;
  if(a.at(m)>0)
    for(int i=1;i<n;i++)
      cout<<i<<" "<<i+1<<endl;
  else
    for(int i=n;i>1;i--)
      cout<<i<<" "<<i-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
const ll MOD=998244353LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	string s;cin>>s;
	int n=s.length();
	vector<int> c1(2*n+10),c2(2*n+10);
	int co1=1,co2=1;
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			c1[co1]=i+1;
			co1++;
			c1[co1]=i+1;
			co1++;
		}else if(s[i]=='1'){
			c1[co1]=i+1;
			co1++;
			c2[co2]=i+1;
			co2++;
		}else if(s[i]=='2'){
			c2[co2]=i+1;
			co2++;
			c2[co2]=i+1;
			co2++;
		}
	}
	vector<vector<ll>> dp(2*n+10,vector<ll>(2*n+10));
	dp[0][0]=1;
	for(int i=1;i<=2*n;i++){
		for(int j=0;j<co1;j++){
			int k=i-j;
			if(j>0&&c1[j]<=i){
				dp[i][j]+=dp[i-1][j-1];
			}
			if(k>0&&c2[k]<=i){
				dp[i][j]+=dp[i-1][j];
			}
			dp[i][j]%=MOD;
		}
	}
	cout<<dp[2*n][co1-1]<<endl;
}


Measured memory_bytes: 126080
$n, $m, $q = gets.chomp.split.map(&:to_i)

$t = []
$q.times do
  a, b, c, d = gets.chomp.split.map(&:to_i)
  a -= 1
  b -= 1
  $t.push [a, b, c, d]
end

$res = 0

def f(i, s)
  if s.size == $n
    r = 0
    $t.each do |a, b, c, d|
      r += d if s[b] - s[a] == c
    end
    $res = [$res, r].max
    return
  end

  i.upto($m) do |j|
    ss = s.clone
    ss.push j
    f(j, ss.clone)
  end
end


f(1, [])

puts $res

Measured memory_bytes: 14960
chomp (my $N = <>);
my @X = sort { $a <=> $b } split " ", <>;
my @min = [];
for my $P (1..$X[-1]) {
    my $sum;
    for my $X (@X) {
        $sum += ($X-$P)**2;
    }
    push @min, $sum;
}
@min = sort { $a <=> $b } @min;
print $min[0];


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h> 
int main(void)
{
  int i,j,num,l;
  scanf("%d %d", &num, &l);
  char moji[num][l+1], tmp[101];
 
  for (i=0;i<num;i++) {
    scanf("%s", moji[i]);
  }
  for(i=1;i<num;i++){
    for(j=1;j<num;j++){
      if(strcmp(moji[j-1], moji[j])>0){
        strcpy(tmp, moji[j-1]);
        strcpy(moji[j-1], moji[j]);
        strcpy(moji[j], tmp);
      }
    }
  } 
  for (i=0;i<num;i++) printf("%s", moji[i]);
  printf("\n"); 
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int Ans=1;
  int H=(L-1)/2;
  for(int i=0; i<H; i++){
    if(S.at(i)!=S.at(L-1-i)){
      Ans=0;
    }
  }
  for(int i=0; i<H/2; i++){
    if(S.at(i)!=S.at(H-1-i)){
      Ans=0;
    }
    if(S.at(i+H+1)!=S.at(L-1-i)){
      Ans=0;
    }
  }
  if(Ans==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}

ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}


//入力

map<string, int> m;
int n;
string s;

int main(){

    cin >> n;
    // cin >> s;

    for(int i = 0; i < n; i++){
        cin >> s;
        m[s] += 1;
    }

    cout << m.size() << endl;

    // m["hello"] += 1;
    // m["h"] += 1;

    // cout << m.size() << endl;

    return 0;
}

Measured memory_bytes: 19268
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
S = sum(L)

ans = 0
for l in L:
    ans += l*(S-l)
    S -= l
print(ans)


Measured memory_bytes: 38256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define endl "\n"
 
#define MOD 1000000007

ll dp[1000010][2][2];

int main(){
  clr(dp,0);
  ll n;
  cin>>n;
  dp[0][0][0] = 1;
  rep(i,1,n+1){
    dp[i][1][1] += dp[i-1][1][1]*10;
    rep(j,0,10){
      if(j==0){
        dp[i][1][0] += dp[i-1][1][0];
        dp[i][1][0] += dp[i-1][0][0];
        dp[i][1][1] += dp[i-1][0][1];
      }
      else if(j==9){
        dp[i][0][1] += dp[i-1][0][1];
        dp[i][0][1] += dp[i-1][0][0];
        dp[i][1][1] += dp[i-1][1][0];
      }
      else{
        dp[i][0][0] += dp[i-1][0][0];
        dp[i][1][0] += dp[i-1][1][0];
        dp[i][0][1] += dp[i-1][0][1];
      }
    }
    dp[i][0][0] %= MOD;
    dp[i][1][0] %= MOD;
    dp[i][0][1] %= MOD;
    dp[i][1][1] %= MOD;
  }
  cout << dp[n][1][1] << endl;
  return 0;
}

Measured memory_bytes: 34880
A, B, C, D = map(int, input().split())
if A <= C < D <= B:
    print(D - C)
elif C <= A < B <= D:
    print(B - A)
elif A <= C <= B <= D:
    print(B - C)
elif C <= A <= D <= B:
    print(D- A)
else:
    print(0)

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string a, b;
    cin >> a >> b;
    
    int arr[a.size()+1][b.size()+1];
    
    for(int i = 0; i < a.size()+1; i++){
        for(int j = 0; j < b.size()+1; j++){
            if(i==0 || j==0) arr[i][j] = 0;
            else if(a[i-1]==b[j-1]) arr[i][j] = arr[i-1][j-1]+1;
            else arr[i][j] = max(arr[i-1][j], arr[i][j-1]);
        }
    }
    
    int j = b.size();
    vector<char> c;
    for(int i = a.size(); i > 0; i--){
        if(arr[i][j]==0) break;
            if(a[i-1]==b[j-1]){
                c.push_back(a[i-1]);
                j--;
            }else if(arr[i-1][j]>=arr[i][j-1]){
                continue;
            }else{
                i++;
                j--;
            }
    }
    for(int i = c.size()-1; i >= 0; i--){
        cout << c[i];
    }
    return 0;
}

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

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

	int n, x, t = 0;
	vector<int> s, r;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> x;
		t += x;
		s.push_back(x);
	}
	if ((t % 10) != 0){
		cout << t << "\n";
		return 0;
	}
	r.push_back(0);
	for (int i = 0; i < n; ++i){
		for (int j = i; j < n; ++j){
			x = t - s[j];
			if ((x % 10) != 0){
				r.push_back(x);
			}
		}
		t -= s[i];
	}
	sort(r.begin(), r.end(), greater<int>());
	cout << r[0] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
using namespace std;

int main() {
	string s;
	int k;
	cin >> s >> k;
	set<string> st;
	for (int i = 1; i <= 5 && i <= s.size(); i++) {
		for (int j = 0; j < s.size() - i + 1; j++) {
			st.insert(s.substr(j, i));
		}
	}
	auto it = st.begin();
	while ((--k) > 0) {
		it++;
	}
	cout << *it << endl;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    string S;
    cin>>N;
    cin>>S;
    for(int i=0; i<S.size(); i++){
        if(S[i] + N > 90){
            cout<<(char)(S[i] + N - 26);
        }
        else{
            cout<<(char)(S[i] + N);
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    int a[N];
    int ava=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        ava+=a[i];
    }
    float aa=(float)ava/4.0/M;
    int n=0;
    for(int i=0;i<N;i++){
        if(a[i]>=aa){
            n++;
            if(n>=M){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main() {


	int n;
	string s, t, ans, w1, w2;

	cin >> n;
	cin >> s >> t;

	const char* cs = s.c_str();
	const char* ct = t.c_str();


	for (int i = 0; i < n; i++)
	{
		w1 = { cs[i] };
		w2 = { ct[i] };
		ans += (w1 + w2);
	}

	std::cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int a,b;
    cin >> a >> b;

    if(a+b>=10)
    {
        cout << "error" << endl;
    }
    else
    {
        cout << a+b <<endl;
    }
    
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: usize = input();
    let b: usize = input();

    let mut s = vec![0; 100000];
    for i in 10000..100000 {
        s[i] = s[i - 1];
        let t = i.to_string();
        let r: String = t.chars().rev().collect();
        if t == r {
            s[i] += 1;
        }
    }
    println!("{}", s[b] - s[a - 1]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for(int i=0;i<s.length();i++){
	    if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    
    if(n == 1){
        cout << m << endl;
        return 0;
    }
    int ret = 1;
    for(int i=2;i*i<=m;++i)if(m%i == 0){
        int num = m/i;
        if(i >= n) ret = max(ret,num);
        if(num >= n) ret = max(ret,i);
    }
    cout << ret << endl;
    return 0;
}

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

ans = 0
a = b = b_a = 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        b_a += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] == "A":
        a += 1

if b_a > 0:
    if a > 0 and b > 0:
        ans += b_a + 1
        ans += min(a-1, b-1)
    elif a > 0 or b > 0:
        ans += b_a
    else:
        ans += b_a - 1
elif a > 0 and b > 0:
    ans += min(a, b)

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main()
{
	int N;
	static int A[100000];
	static int ans[100000];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	int x = 0;
	int le = 0;
	int ri = A[x];
	while (1) {
		int md = (le + ri) / 2;

		memset(ans, 0, sizeof(ans));
		ans[(x + 1) % N] = md;
		for (int i = 0; i < N - 1; i++) {
			ans[(x + 2 + i) % N] = A[(x + 1 + i) % N] - ans[(x + 1 + i) % N];
		}
		if (ans[x] + ans[(x + 1) % N] == A[x]) {
			break;
		}
		else if (ans[x] + ans[(x + 1) % N] < A[x]) {
			le = md + 1;
		}
		else {
			ri = md - 1;
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d%c", ans[i] * 2, (i == N - 1) ? '\n' : ' ');
	}

	return 0;
}


Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class Main {
	public void exec() throws IOException {
		InputUtil input = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int a,b;
		char op;
		LOOP:
		while(true){
			a = input.nextInt();
			op = input.nextChar();
			b = input.nextInt();
			switch(op){
			case '+':
				out.println(a+b);
				break;
			case '-':
				out.println(a-b);
				break;
			case '*':
				out.println(a*b);
				break;
			case '/':
				out.println(a/b);
				break;
			case '?':
			default:
				break LOOP;
			}
		}
		out.flush();
		input.close();
	}

	public static void main(String[] args) throws IOException {
		new Main().exec();
	}
}

/**
 * --------------------------------------------------
 * Input Utility
 * --------------------------------------------------
 */
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(int bufsiz) {this(System.in,bufsiz);}
	public InputUtil(InputStream in) {this(in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//String Input Reader/Parser
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
	
	public BufferedReader getReader() {return br;}
	
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }
	private void next() throws IOException {ptr++; readBuf();}

	public char nextChar() throws IOException {
		readBuf();
		if(ptr < max) {
			return buf[ptr++];
		}else{
			return (char)-1;
		}
	}

	public int nextInt() throws IOException {return nextInt(new int[1])[0];}
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			int sign = 1;
			int res = 0;
			char c;
			while (!isNum(c=buf[ptr]) && !isMinus(c)) 
				next();
			if (isMinus(buf[ptr])) {
				sign = -1;
				next();
			}
			while (isNum(c=buf[ptr])) {
				res *= 10;
				res += c - '0' ;
				next();
			}
			next();
			result[i] = sign * res;
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 24468
#include <cstdio>
#include <cstring> 
#include <algorithm>
using namespace std;

const int MAXN = 300000;
const int MOD = int(1E9) + 7;

const int trans[2][8] = {
{1, 3, 5, 1, 1, 6, 5, 7},
{2, 4, 7, 1, 2, 2, 5, 7}
};

int f[2][8], n; char s[MAXN + 5];
int main() {
	scanf("%s", s), n = strlen(s);
	f[0][0] = 1;
	for(int i=0;i<n;i++) {
		for(int j=0;j<8;j++)
			f[1][j] = f[0][j], f[0][j] = 0;
		if( s[i] != '0' ) {
			for(int j=0;j<8;j++)
				f[0][trans[1][j]] = (f[0][trans[1][j]] + f[1][j]) % MOD;
		}
		if( s[i] != '1' ) {
			for(int j=0;j<8;j++)
				f[0][trans[0][j]] = (f[0][trans[0][j]] + f[1][j]) % MOD;
		}
	}
	printf("%d\n", (f[0][2] + f[0][7]) % MOD);
}

Measured memory_bytes: 512
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 310000;

int n;
string s;
const ll MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n;
	cin >> s;
	int cc[3] = {};
	ll ans = 1;
	for (int i = 0; i < 3 * n; ++i) {
		int c = 0;
		if (s[i] == 'R')
			c = 0;
		else if (s[i] == 'B')
			c = 1;
		else
			c = 2;
		int mn = *min_element(cc, cc + 3);
		int mx = *max_element(cc, cc + 3);
		int md = cc[0] + cc[1] + cc[2] - mn - mx;
		if (cc[c] == mx) {
			++cc[c];
			ans = (ans * (n - mx)) % MOD;
		}
		else if (cc[c] == md) {
			++cc[c];
			ans = (ans * (mx - md)) % MOD;
		}
		else {
			++cc[c];
			ans = (ans * (md - mn)) % MOD;
		}
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 720
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (ll i = 0; i < n; i++)
#define forr(i,a,b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const ll MX = 300005;
const ll inf = 2e18;

#define ptr nodo*
#define tam 301000
int main () 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,a,b;
    cin>>n>>a>>b;
    if ((b-a)%2==0)
        cout<<(b-a)/2<<endl;
    else
    {
        ll b1,a1;
        b1=b-(a-1);
        b1--;
        ll res=(a-1+(b1-1)/2+1);
        a1=a+(n-b); 
        a1++;
        res=min(res,(n-b)+(n-a1)/2+1);
        cout<<res<<endl;
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
const int INF = 1 << 30;
string S, T;
int ans = INF;
int main()
{
	int cnt;
	cin >> S >> T;
	for(int i = 0; i < S.size(); ++ i)
	{
		cnt = 0;
		if(i + T.size() > S.size()) break;
		else
		{
			for(int j = 0, k = i; j < T.size(); ++ k, ++ j)
			{
				if(T[j] != S[k]) ++ cnt;
			}
		}
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int n = s.size();
  s += s;
  vector<int> vs[26];
  rep(i,s.size()) vs[s[i]-'a'].push_back(i);
  
  ll ans = 0; int idx = -1;
  rep(i,t.size()){
    int c = t[i]-'a';
    if(vs[c].empty()){
      cout << -1 << endl;
      return 0;
    }
    idx = *upper_bound(vs[c].begin(),vs[c].end(),idx);
    if(idx>=n){
      idx -= n;
      ans += n;
    }
  }
  ans += idx + 1;
  cout << ans << endl;
}


Measured memory_bytes: 1788
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    string s;cin >> s;
    ll ans=0;
/*    for(int i = 0;i<s.size();i++){
        if(s[i]=='B'&&s[i+1]=='W'){
            swap(s[i],s[i+1]);
            i=-1;
            ans++;
        }
    }
*/
    int o=0;
    rep(i,0,s.size()){
        if(s.at(i)=='W'){
            ans+=i-o;
            o++;
        }
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr double EPS = 1e-8; 

int main(){
  int64 n;
  cin >> n;
  map<int64, int> mp;
  for(int64 i = 2; i * i <= n; ++i){
    while(n % i == 0){
      mp[i]++;
      n /= i;
    }
  }
  if(n != 1) mp[n]++;
  int ans = 0;
  for(auto i : mp){
    for(int j = 1; j <= i.second; ++j){
      ans++;
      i.second -= j;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#Input
N,A,B= map(int, input().split())

#Process
nokori = 0
na = int(N / (A + B))
if((A+B)*na + A > N):
    nokori = N % (A + B)
else:
    nokori = A
Ans = A * na + nokori

#Output
print(Ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
char c[10001],s[10001];
int top;
int main()
{
// 	freopen(".in","r",stdin);
// 	freopen(".out","w",stdout);
	gets(c);
 	for(int i=0;i<strlen(c);i++)
 	{
 		if(c[i]=='B'&&top)
 		top--;
 		else if(c[i]!='B')
 		s[top++]=c[i];
 	}
 	for(int i=0;i<top;i++)
 	cout<<s[i];
 	return 0;
}


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

int main() {
  int64_t N,K,Q;
  cin >> N >> K >> Q;
  vector<int64_t> A(Q);
  vector<int64_t> B(N,0);
  for (int i = 0; i < Q; i++){
     cin >> A.at(i);
    B.at(A.at(i)-1)++;
    } 
  int64_t J = Q-K;
    for (int i = 0; i < N; i++) {
      cout << ((B.at(i) > J) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=610;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,a[N],b[N],f[N][N],g[N][N],h[N],ans=0;
int main() {
    n=gi(),m=gi();
    for(int i=1;i<=m;i++) a[i]=gi(),b[i]=gi();
    h[0]=1;
    for(int i=1;i<=n;i++) h[i]=1ll*h[i-1]*(2*i-1)%mod;
    for(int l=2*n;l;l--)
        for(int r=l+1;r<=2*n;r+=2) {
            int fl=1,in=0,out=0;
            for(int i=1;i<=m;i++) {
                int op=(l<=a[i]&&a[i]<=r)+(l<=b[i]&&b[i]<=r);
                if(op==1) { fl=0;break; }
                if(op==2) ++in;
            }
            if(fl) {
                in=(r-l+1)/2-in,out=n-m-in;
                f[l][r]=g[l][r]=h[in];
                for(int i=l+1;i<r;i+=2) dec(f[l][r],1ll*f[l][i]*g[i+1][r]%mod);
                inc(ans,1ll*f[l][r]*h[out]%mod);
            }
        }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int numA = scanner.nextInt();
		int numB = scanner.nextInt();
		int ans;
		if(numB % numA ==0){
			ans = numA + numB;
		}else{
			ans = numB - numA;
		}
		System.out.println(ans);
		scanner.close();
	}
	
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define N 55 
int n,m,q,nw,ans,a[N],b[N],c[N],d[N],z[N];
struct Node {int a,c,d;};vector<Node> vc[N];
void dfs(int u,int lst)
{
	if(nw<=ans) return;if(u>n) {ans=nw;return;}int tmp;
	for(int i=lst;i<=m;++i)
	{
		z[u]=i;tmp=nw;
		for(int j=0;j<vc[u].size();++j) if(i-z[vc[u][j].a]!=vc[u][j].c) nw-=vc[u][j].d;
		dfs(u+1,i);z[u]=0;nw=tmp;
	}
}
int main()
{
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=q;++i)
	{
		scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
		vc[b[i]].push_back((Node) {a[i],c[i],d[i]});nw+=d[i];
	}dfs(1,1);printf("%d\n",ans);return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, H, i, j, k, stx, sty, sth=0; cin >> N; int x[N], y[N], h[N];
for(i=0; i<N; i++){cin >> x[i] >> y[i] >> h[i]; if(h[i]){sth=h[i]; stx=x[i]; sty=y[i];}}
for(i=0; i<101; i++){ for(j=0; j<101; j++){
for(k=0, H=sth+abs(stx-i)+abs(sty-j); k<N; k++){
  if(h[k]!=max(H-abs(x[k]-i)-abs(y[k]-j),0)){ break; }
}
if(k==N){ cout << i << " " << j << " " << H << "\n"; return 0; }
}}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

i64 f(i64 x, i64 y) {
    return y >= x ? y - x : -1;
}

int main() {
    i64 x, y;
    cin >> x >> y;
    i64 ans = 1e10;
    for (int i = 0; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
            cerr << x << ' ' << y << endl;
            i64 a = f(x, y);
            if (a != -1) {
                a += i + j;
                ans = min(ans, a);
            }
            y = -y;
        }
        x = -x;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define moduloP 1e9 + 7

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

    string s;
    cin>>s;
    
    int n=(int)s.size(), count=0;
    
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i])
            count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll a, b;
  cin >> a>> b;
  ll c = __gcd(a,b);
  ll ans = a * b / c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(){
	int a, b;
	char op;

	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op=='?'){
			break;

		}else if(op=='+'){
			printf("%d\n", a+b);
		}

		else if(op=='-'){
			printf("%d\n", a-b);
		}

		else if(op=='*'){
			printf("%d\n", a*b);
		}

		else if(op=='/'){
			printf("%d\n", a/b);
		}
	}

	return 0;
}

Measured memory_bytes: 600
function main(arg) {
	arg = arg.split("\n")
	var N = Number(arg[0])
	var L = arg[1].split(" ").map(e => Number(e))

	L = L.sort((a,b) => (a - b))
	var max = L.pop()

	var sum = 0
	L.forEach(e => {
		sum += e
	})
	// console.log([sum , max])
	if (max < sum) {
		console.log("Yes")
	} else {
		console.log("No")
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
# inputを高速化する。
import sys
input = sys.stdin.readline

n = int(input())

balls = list(map(int, input().split()))

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)


for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)

Measured memory_bytes: 25912
#include <stdio.h>

int main() {
        const int N = 8;
        char mass[N][N + 1];

        while (scanf("%8s", &mass[0]) != EOF) {
                for (int i = 1; i < N; i++) {
                        scanf("%8s", &mass[i]);
                }
                int a, b;
                bool isFind = false;
                for (a = 0; a < N; a++) {
                        for (b = 0; b < N; b++) {
                                if (mass[a][b] == '1') {
                                        isFind = true;
                                        break;
                                }
                        }
                        if (isFind) {
                                break;
                        }
                }
                char ans;
                if (mass[a][b + 1] == '1' && mass[a + 1][b] == '1' &&
                                mass[a + 1][b + 1] == '1') {
                        ans = 'A';
                } else if (mass[a + 1][b] == '1' && mass[a + 2][b] == '1') {
                        ans = 'B';
                } else if (mass[a][b + 1] == '1' && mass[a][b + 2] == '1') {
                        ans = 'C';
                } else if (mass[a + 1][b - 1] == '1' && mass[a + 1][b] == '1') {
                        if (mass[a + 2][b - 1] == '1') {
                                ans = 'D';
                        } else {
                                ans = 'G';
                        }
                } else if (mass[a][b + 1] == '1' && mass[a + 1][b + 1] == '1') {
                        ans = 'E';
                } else if (mass[a + 1][b] == '1' && mass[a + 1][b + 1] == '1') {
                        ans = 'F';
                }
                printf("%c\n", ans);
        }

        return 0;
}

Measured memory_bytes: 2576
n = int(input())
A = list(map(int, input().split()))

ans = 10**9
for i in range(n) :
    ans1 = 0
    while A[i]%2 == 0 :
        A[i] //= 2
        ans1 += 1
    ans = min(ans, ans1)
print(ans)


Measured memory_bytes: 2940
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    N = int(sys.stdin.readline().strip())
    pq = []
    for _ in range(N):
        X, L = map(int, sys.stdin.readline().strip().split())
        heapq.heappush(pq, (X + L, X - L))
    ans = 0
    while pq:
        ans += 1
        right, _ = heapq.heappop(pq)
        if pq:
            _, next_left = pq[0]
            while next_left < right:
                heapq.heappop(pq)
                if not pq:
                    break
                _, next_left = pq[0]

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 16912
N,Q = map(int,input().split())
bit = [0]*(N+1)
'''
def add(a,w):
    ret = 0
    for i in range(a,0,-(i&-i)):ret += bit[i]
    return ret
'''
def add(a,w):
    x = a
    while x<=N:
        bit[x]+=w
        x+=x&-x
def bsum(a):
    ret = 0
    x = a
    while x>0:
        ret+=bit[x]
        x-=x&-x
    return ret

for i in range(Q):
    l = list(map(int,input().split()))
    if l[0] == 0:
        add(l[1],l[2])
    else:
        print(bsum(l[2])-bsum(l[1]-1))


Measured memory_bytes: 7944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    ll x; cin >> x;
    ll a, b;
    for (ll i = -1000; i <= 1000; i++) {
        for (ll j = -1000; j <= 1000; j++) {
            ll cal = (ll)pow(i, 5LL) - pow(j, 5LL);
            if (cal == x) {
                a = i;
                b = j;
            }
        }
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int V, E, s, t, Q, a, b, G[10000];
bool B[10000];
vector<int>v[10000], r[10000], u;

void dfs(int x) {
	B[x] = true;
	for (int i = 0; i != v[x].size(); ++i) {
		if (!B[v[x][i]])
			dfs(v[x][i]);
	}
	u.push_back(x);
}
void rdfs(int x, int k) {
	G[x] = k;
	for (int i = 0; i != r[x].size(); ++i) {
		if (!G[r[x][i]])
			rdfs(r[x][i], k);
	}
}
int main() {
	cin >> V >> E;
	for (int i = 0; i != E; ++i) {
		cin >> s >> t;
		v[s].push_back(t);
		r[t].push_back(s);
	}
	for (int i = 0; i != V; ++i) {
		if (!B[i])
			dfs(i);
	}
	int k = 1;
	for (int i = u.size() - 1; i != -1; --i) {
		if (!G[u[i]])
			rdfs(u[i], ++k);
	}
	cin >> Q;
	for (int i = 0; i != Q; ++i) {
		cin >> a >> b;
		cout << (G[a] == G[b]) << endl;
	}
	return 0;
}


Measured memory_bytes: 4716
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


inline void print(){
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest){
    cout << first << ' ';
    print(rest...);
}


const long long MOD = 1000000007;


long long mod_pow(long long x, long long n, long long mod) {
    if (n == 0) return 1;
    long long res = mod_pow(x * x % mod, n / 2, mod);
    if (n & 1) res = res * x % mod;
    return res; 
}


long long com(long long n, long long k) {
    long long mul = 1;
    long long div = 1;
    for (long long i = 0; i < k; i++) {
        mul = (mul * (n - i)) % MOD;
        div = (div * (i + 1)) % MOD;
    }
    div = mod_pow(div, MOD-2, MOD);
    return (mul * div) % MOD;
}


void solve() {
    long long n, a, b; cin >> n >> a >> b;
    long long ans = mod_pow(2, n, MOD) - 1;
    ans -= com(n, a);
    ans = (ans<0 ? ans+MOD : ans);
    ans -= com(n, b);
    ans = (ans<0 ? ans+MOD : ans);
    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-26 21:04:44
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

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;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];

    map<string, int> cnt;
    for (int i = 0; i < n; i++)
        cnt[s[i]]++;

    int ans = 0;
    for (const auto &x : cnt) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 25176
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    double sum = 0;
    for (int i = 0; i < n; ++i) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "BTC") sum += 380000.0 * x;
        else sum += x;
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int h, w;
    cin >> h >> w;
    int a[h][w];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j];
    ll ans = 1e10;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ll sum = 0;
            for (int k = 0; k < h; k++) {
                for (int r = 0; r < w; r++) {
                    ll t = min(abs(k - i), abs(r - j));
                    sum += t * a[k][r];
                }
            }
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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 dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

constexpr ll mod = 998244353;

ll dp[3005][3005][2];

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  dp[a][b][0] = 1;

  for (int i = a; i <= c; i++) {
    for (int j = b; j <= d; j++) {
      dp[i+1][j][0] = (dp[i+1][j][0] + dp[i][j][0] * j) % mod;
      dp[i][j+1][1] = ((dp[i][j+1][1] + dp[i][j][0] * i)) % mod;
      dp[i+1][j][0] = (dp[i+1][j][0] + dp[i][j][1]) % mod;
      dp[i][j+1][1] = (dp[i][j+1][1] + dp[i][j][1] * i) % mod;
    }
  }

  cout << (dp[c][d][0] + dp[c][d][1]) % mod << endl;

  return 0;
}


Measured memory_bytes: 144520
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld  long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll a[2], b[2], ans=-2e18;
int main()
{
    IO
    cin>>a[0]>>a[1]>>b[0]>>b[1];
    if((a[0]*a[1]<=0) || b[0]*b[1]<=0)
        ans=0;
    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++)
            ans=max(ans,a[i]*b[j]);
    cout<<ans;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5010][5010];

void chmax(ll &a, ll b){ if( a < b){ swap(a,b);} return ;}

int main(){
  ll N; cin >> N; string S; cin >> S;
  
  for(int i = 0; i < 5010; i++){
    for(int j = 0; j < 5010; j++){ dp[i][j] = 0;}}
  
  for(ll i = N-1; i >= 0; i--){
    for(ll j = N-1; j >= 0; j--){
      if(S[i] != S[j]){ dp[i][j] = 0;}
      else{
        chmax(dp[i][j],dp[i+1][j+1]+1);}
    }
  }
  
  ll ans = 0;
  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < N; j++){
      chmax(ans, min(dp[i][j],abs(j-i)));}}
  
  cout << ans << endl; return 0;}
            

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

int main() {
	string S;
	cin >> S;
  int len = S.size();
	bool ans = true; 
	rep(i,len){
		if(i&1 && S[i] == 'R'){
			ans = false;
		} else if(!(i&1) && S[i] == 'L'){
			ans = false;
		} else {
			continue;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
}

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

using namespace std;

#define debug(x) cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) for (auto i : v) cerr << i << " "; cerr << endl;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);

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

    string s, t;

    cin >> s >> t;

    int ans = 0;
    
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] != t[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3820
n = int(input())
l = list(map(int,input().split()))

c = 0
f = 0
s = 0
t = 0

for i in range(n):
    for j in range(i, n):
        for k in range(j,n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and l[i] < l[j] +l[k] and l[j] < l[i]+l[k] and l[k] < l[i]+l[j]:
                c+=1

print(c)

Measured memory_bytes: 9200
#include <stdio.h>
int main()
{
    int H,W,i,j;
    scanf("%d %d",&H,&W);
    char P[H][W+1];
    for(i=0;i<H;i++){
            scanf("%s",P[i]);
    }
    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            if(i==0||i==H+1||j==0||j==W+1) printf("#");
            else if(j==1){
                printf("%s",P[i-1]);
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n,m;
  cin >> n >> m;
  if (n == 1) {
    cout << m << endl;
    return 0;
  }
  map<int,int> div;
  for (int i = 1;i*i <= m;i++){
    if (m%i == 0){
      div[i]++;
      div[m/i]++;
    }
  }
  int ans = 0;
  for (auto q:div){
    //cout << q.first << ":" << q.second << endl;;
    if (q.first <= m/n) ans = max(ans,q.first);
  }
  cout << ans << endl;

}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000

int main(){
	int n;
	int m;
	int x;
	int ans=0;
	int a2 = 0;
	int a4 = 0;
	int a14 = 0;
	int a24 = 0;
	int a74 = 0;
	vector<int>a;
	scanf("%d", &n);
	a.push_back(2);
	a.push_back(3);
	a.push_back(5);
	a.push_back(7);
	a.push_back(11);
	a.push_back(13);
	a.push_back(17);
	a.push_back(19);
	a.push_back(23);
	a.push_back(29);
	a.push_back(31);
	a.push_back(37);
	a.push_back(41);
	a.push_back(43);
	a.push_back(47);
	f(i, a.size()){
	m = n;
	x = 0;
	while (m > 0){
		m = m / a[i];
		x += m;
	}
	if (x > 1)a2++;
	if (x > 3)a4++;
	if (x > 13)a14++;
	if (x > 23)a24++;
	if (x > 73)a74++;
}
	ans += (((a4)*(a4 - 1)*(a2 - 2)) / 2);
	ans += (a14*(a4 - 1));
	ans += (a24*(a2 - 1));
	ans += a74;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256