akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string str;
    string op;

    cin >> op;
    for (int i = 0; i < op.size(); i++) {
        if (op[i] == 'B' && str.size()) str.pop_back();
        else if(op[i] != 'B') str += op[i];
    }

    cout << str << endl;

    return 0;
}


Measured memory_bytes: 256
from sys import exit
N = int(input())
w = [input()]
for i in range(N - 1):
  last = w[i] 
  word = input()
  if word in w or word[0] != last[len(last) - 1]: 
    print("No")
    exit()
  w.append(word)  
print("Yes")    

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		Points[] a = new Points[n];
		for(int i = 0; i < n; i++) a[i] = new Points();
		for(int i = 0; i < n; i++){
			str = br.readLine().split(" ");
			a[i].x = Integer.parseInt(str[0]);
			a[i].y = Integer.parseInt(str[1]);
		}
		Arrays.sort(a);
		for(int i = 0; i < n; i++) System.out.println(a[i].x + " " + a[i].y);
	}
}

class Points implements Comparable<Points>{
	int x, y;
	@Override
	public int compareTo(Points b){
		return (this.x == b.x ? this.y - b.y : this.x - b.x);
	}
}



Measured memory_bytes: 71096
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long        
using namespace std;
 
void scan()
{
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
 
}
const int N = 1e6 + 500;
const int mod = 1e9 + 7;

vector<int> g[N]; 
int was[N];
void dfs(int v)
{
	if (was[v])
	{
		return;
	}
	was[v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		dfs(g[v][i]);
	}
}
int main() 
{
    scan();     
    int n, m;
    cin >> n >> m;        
    for (int i = 1; i <= m; i++)
    {
    	int a, b, c;
    	cin >> a >> b >> c;
    	g[a].pb(b);
    	g[b].pb(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
    	if (was[i])
    	{
    		continue;
    	}
    	dfs(i);
    	ans++;
    }
    cout << ans;
}     
//JUDGE_ID: 295965SY
//Tis I

Measured memory_bytes: 33460
import sys
N=int(input())
A=[int(x) for x in sys.stdin.readline().split()]

abssum=0
negative=0
mi=100000000000000
for i in range(N):
	if A[i]<0:
		negative+=1
	abssum+=abs(A[i])
	mi=min(mi,abs(A[i]))

if negative%2==1:
	abssum-=2*mi
print(abssum)



Measured memory_bytes: 60400
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int hhmmss_to_i(int h, int m, int s) {
  return (h * 60 + m) * 60 + s;
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF && n) {
    vector<pair<int,bool>> V; // firstは時刻、boolは出発ならtrue、到着ならfalse
    for (int i=0; i<n; i++) {
      int h, m, s;
      scanf("%02d:%02d:%02d", &h, &m, &s);
      int t = hhmmss_to_i(h, m, s);
      V.push_back(make_pair(t, true));
      scanf("%02d:%02d:%02d", &h, &m, &s);
      t = hhmmss_to_i(h, m, s);
      V.push_back(make_pair(t, false));
    }
    sort(V.begin(), V.end());
    int count = 0;
    int max = 0;
    for (unsigned int i=0; i<V.size(); i++) {
      if (V[i].second) {
	count++;
	if (max < count) max = count;
      } else {
	count--;
      }
    }
    printf("%d\n", max);
  }
}

Measured memory_bytes: 1412
s = input()
flag = True
top = 0
tale = len(s)-1
ans = 0
while top < tale:
  if s[top] == 'x' and s[tale] == 'x':
    top += 1
    tale -= 1
  elif s[top] == 'x' and s[tale] != 'x':
    top += 1
  elif s[top] != 'x' and s[tale] == 'x':
    tale -= 1
  else:
    if s[top] != s[tale]:
      flag = False
      break
    else:
      top += 1
      tale -= 1
if not flag:
  print(-1)
else:
  top = 0
  tale = len(s)-1
  while top < tale:
    if s[top] == s[tale]:
      top += 1
      tale -= 1
    elif s[top] == 'x' and s[tale] != 'x':
      ans += 1
      top += 1
    elif s[top] != 'x' and s[tale] == 'x':
      ans += 1
      tale -= 1
  print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

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

  if(isupper(N)) cout << 'A' << endl;
  else cout << 'a' << endl;
}


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

int main() {
	string S;
	cin >> S;
	int cnt = 0, len = S.size();
	for (int i = 0; i < len; i++) {
		if (S.at(i) == '0') {
			cnt++;
		}
	}
	if (cnt == len) cnt = 0;
	cout << 2 * min(cnt, len - cnt) << endl;
}

Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())
total = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            money = i*500 + j*100 + k*50
            if money == x:
                total = total + 1

print(total)

Measured memory_bytes: 3060
O = input()
#atcoderbeginnercontest

E = input()
#atcoderregularcontest
S = []

if len(O) == len(E):
	for i in range(len(O)):
		S.append(O[i] + E[i])
else:
	for i in range(len(E)):
		S.append(O[i] + E[i])
	S.append(O[-1])
#print(S)
print("".join(S))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

int main(){
    int N, cnt = 0, ans = 0, tmp = 0;
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    ans = max(max(a[0], a[1]), a[2]);
    int mint = min(min(a[0], a[1]), a[2]);
    rep(i, 3){
        if(ans == a[i]){
            a[i] = -1;
            break;
        }
    }
    ans = ans*10 + max(max(a[0], a[1]), a[2]) + mint;
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int main()
{
	string k;
	cin>>k;
	int n=k.size();
	int d; cin>>d;
	int dp[2][10001][101]={};
	for(int i=1; i<(k[0]-'0'); i++){
		dp[1][0][i%d]+=1;
	}
	dp[0][0][(k[0]-'0')%d]+=1;
	for(int i=1; i<n; i++){
		for(int j=1; j<10; j++){
			dp[1][i][j%d]+=1;
		}
	}
	for(int i=0; i<n-1; i++){
		for(int j=0; j<d; j++){
			for(int l=0; l<10; l++){
				dp[1][i+1][(j+l)%d]+=dp[1][i][j];
				dp[1][i+1][(j+l)%d]%=MOD;
			}
			for(int l=0; l<(k[i+1]-'0'); l++){
				dp[1][i+1][(j+l)%d]+=dp[0][i][j];
				dp[1][i+1][(j+l)%d]%=MOD;
			}
			dp[0][i+1][(j+(k[i+1]-'0'))%d]+=dp[0][i][j];
			dp[0][i+1][(j+(k[i+1]-'0'))%d]%=MOD;
		}
	}
	cout<<(dp[0][n-1][0]+dp[1][n-1][0])%MOD<<endl;
	return 0;
}

Measured memory_bytes: 8192
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(M):
    if A[i]>X:
        B.append(A[i])
    elif A[i]<X:
        C.append(A[i])
print(min(len(B),len(C)))

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)


typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

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


void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

int n;
int a[2001];
void Input() {

    cin >> n;
    for(int i = 0; i < n; i++) {

        cin >> a[i];
    }
}



void Solve() {


    sort(a, a+n);
    int cnt = 0;
    for(int i = 0; i < n-2; i++) {

        for(int j = i+1; j < n-1; j++) {

            int L = j, R = n;
            int k = a[i] + a[j];
            while(R-L > 1) {

                int mid = (R+L)/2;
                if(a[mid] < k) {

                    L = mid;

                }
                else R = mid;
            }

            cnt += L - j;

        }
    }

    cout << cnt << endl;


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
ll m,n,a,b;
int main(){
	scanf("%lld%lld%lld%lld",&m,&n,&a,&b);
	if (!(m%a) && !(n%b)){ puts("No"); return 0; }
	ll y=(1000000000ll*(m/a)*(n/b)+1)/(m*n-(m/a)*(n/b));
	if (y>1000000000ll) y=1000000000ll;
	y-=5;if(y<1)y=1;
	for (; ; y++){
		ll x=(y*(m*n-(m/a)*(n/b))-1)/((m/a)*(n/b));
		if (abs(x)>1000000000) break;
		if (x>y*(a*b-1)){
			puts("Yes");
			int i,j;
			for (i=1; i<=m; i++)
				for (j=1; j<=n; j++) printf("%d%c",(!(i%a) && !(j%b))?-x:y,(j<n)?' ':'\n');
			return 0;
		}
	}
	for (y=1; y<=n*m; y++){
		ll x=(y*(m*n-(m/a)*(n/b))-1)/((m/a)*(n/b));
		if (abs(x)>1000000000) break;
		if (x>y*(a*b-1)){
			puts("Yes");
			int i,j;
			for (i=1; i<=m; i++)
				for (j=1; j<=n; j++) printf("%d%c",(!(i%a) && !(j%b))?-x:y,(j<n)?' ':'\n');
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

int main() {
    ios_base :: sync_with_stdio(0);
    int n , k; cin >> n>>k;
    int arr [n];
    int dp [n];
    for (int i = 0 ; i < n ; i++){
        cin >> arr[i];}
    dp[0]= 0;
    dp [1]= abs(arr[1]-arr[0]);
    for (int i =2 ; i < n; i++){
        int m= 1000000000;
        for (int j = 1; j <= k ; j++){
            if (i-j<0)break;
            m = min ( m, dp[i-j]+abs(arr[i]-arr[i-j]));
        }
        dp[i]=m;
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,k,q,x,y,l,r,z,n,m;
    cin>>n;
    ll ans = 1000*(n/500);
	n = n%500;
	ans += 5*(n/5);
	cout<<ans; 
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,c;cin>>a>>b>>c;
    if(a+b>=c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
r,g,b,n = map(int, input().split())
cnt = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        ij = i*r+j*g
        if n<ij:
            break
        if (n-ij)%b==0:
            cnt += 1
print(cnt)

Measured memory_bytes: 2940
#include <cstdio>
#include <string>
#include <map>

using namespace std;

char s[37];

int main() {
	int n, i, j;
	long long ans = 0;
	map <pair<string, string>, long long> mp;
	
	scanf("%d", &n);
	scanf("%s", s);
	
	for (i = 0; i < (1 << n); i++) {
		string s1 = "", s2 = "";
		
		for (j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				s1 += s[j];
			} else {
				s2 += s[j];
			}
		}
		
		mp[make_pair(s1, s2)]++;
	}
	
	for (i = 0; i < (1 << n); i++) {
		string s1 = "", s2 = "";
		
		for (j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				s1 += s[n * 2 - j - 1];
			} else {
				s2 += s[n * 2 - j - 1];
			}
		}
		
		ans += mp[make_pair(s2, s1)];
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


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

using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<pair<int, int>> drink(n);

  for (int i = 0; i < n; i++) {
    int a, b; cin >> a >> b;
    drink[i] = make_pair(a, b);
  }
  sort(drink.begin(), drink.end());

  long long cnt = 0;
  long long money = 0;
  for (int i = 0; i < n; i++) {
    if (cnt == m) { break; }
    long long aa = drink[i].first;
    long long bb = drink[i].second;
    // 全部買える
    if (cnt + bb <= m) {
      cnt += bb;
      money += aa*bb;
    } else {
      money += aa*(m-cnt);
      cnt = m;
    }
  }
  cout << money << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+233;

int main(){
    
    ll x,k,d;
    cin>>x>>k>>d;
    ll ans;
    x = abs(x);
    ll s = min(k,x/d);
    k-=s;
    x-=s*d;
    if(k&1) cout<<d-x<<endl;
    else cout<<x<<endl;
    
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 100000

ll Q,S[100010];
ll prime[100010];
ll pn;
bool F[100010];
ll N,K,L;
ll ans;


int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>Q;
    prime[pn]=2;F[2]=true;pn++;
    REP(i,1e5+1){
        if(i<=2)continue;
        bool f=true;
        REP(j,pn){
            if(i%prime[j]==0){f=false;break;}
        }
        if(f){
            prime[pn]=i;
            F[i]=true;
            if((i+1)%2==0){
                if(F[(i+1)/2]){
                    S[i]=1;
                }
            }
            pn++;
        }
    }
    REP(i,1e5+1){S[i+1]+=S[i];}
    REP(i,Q){
        int a,b;
        cin>>a>>b;
        cout<<S[b]-S[a-1]<<endl;
    }

    //cout<<ans<<endl;
    return 0;
}


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

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<ll> x(m);
  vector<ll> y(m - 1);

  if (n >= m)
  {
    cout << 0 << endl;
    return 0;
  }

  for (ll i = 0; i < m; i++)
  {
    cin >> x[i];
  }
  sort(x.begin(), x.end());

  if (n == 1)
  {
    cout << abs(x[m - 1] - x[0]) << endl;
    return 0;
  }

  for (ll i = 0; i < m - 1; i++)
  {
    y[i] = abs(x[i] - x[i + 1]);
  }
  sort(y.begin(), y.end());

  ll ans = 0;
  for (ll i = 0; i < m - n; i++)
  {
    ans += y[i];
  }
  cout << ans << endl;
}


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

int main(void) {
  string S;
  cin >> S;
  int n = S.size();
  int64_t answer = 0;
  int64_t white = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (S[i] == 'W') {
      ++white;
    } else {
      answer += white;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 640
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int64 n;
  cin >> n;
  int64 prod = 1;
  int len;
  for (len = 1; ; ++len) {
    prod *= 26;
    if (prod >= n) break;
    n -= prod;
  }
  --n;
  string ret;
  for (int i = 0; i < len; ++i) {
    ret += (char)('a' + n % 26);
    n /= 26;
  }
  reverse(ret.begin(), ret.end());
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner scan = new Scanner(System.in);
        while (true) {
            int a = scan.nextInt();
            String op = scan.next();
            int b = scan.nextInt();
            int ans = 0;

            // (a op b)の形で読み込みたい
            if (op.equals("+")) {
                System.out.println(a + b);
            } else if (op.equals("-")) {
                System.out.println(a - b);
            } else if (op.equals("*")) {
                System.out.println(a * b);
            } else if (op.equals("/")) {
                System.out.println(a / b);
            } else if (op.equals("?")) {// ?の時終了する。
                break;
            }
        }
    }
}


Measured memory_bytes: 26264
# frozen_string_literal: true

a, b, h, m = gets.split.map(&:to_i)

t_h = 360.0 / (12 * 60) * (60 * h + m) * Math::PI / 180
t_m = 360.0 / 60 * m * Math::PI / 180

x_h = a * Math.cos(t_h)
y_h = a * Math.sin(t_h)

x_m = b * Math.cos(t_m)
y_m = b * Math.sin(t_m)

puts Math.sqrt((x_m - x_h)**2 + (y_m - y_h)**2)


Measured memory_bytes: 14752
#pragma region

#ifdef LOCAL
#define debug cout
#else
#define debug \
    if (0) cout
#endif

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
}

#pragma endregion

/**
 * Problem: You have n blocks, each with a weight w, durability s, and value v. You wish to stack some of these
 * blocks such that the sum of the weights above each block is not more than its durability. What is the maximum
 * total value of a valid stack of blocks?
 * 
 * Constraints: n <= 1e3, w = s <= 1e4, v <= 1e9
 * 
 * Time complexity: o(nlgn + n*w)
 * Space Complexity: o(n+w)
 */

struct block {
    int w, s;
    ll v;
    bool operator<(const block& b) const {
        return (w + s != b.w + b.s) ? (w + s < b.w + b.s) : v < b.v;
    }
};

void solve() {
    int n;
    cin >> n;
    vector<block> b(n);
    for (int i = 0; i < n; ++i) cin >> b[i].w >> b[i].s >> b[i].v;
    sort(b.begin(), b.end());
    vector<ll> dp(2e4 + 5, 0);
    for (int i = 0; i < n; ++i) {
        // Add i
        for (int t = dp.size() - 1; t >= b[i].w; --t) {
            dp[t] = max(dp[t], b[i].v + dp[min(b[i].s, t - b[i].w)]);
        }
    }
    cout << dp.back() << "\n";
}

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

#define mod 1000000007
/*ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a,b);
}*/
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a; string s; cin>>a>>s;
	cout<<(a < 3200 ? "red" : s);
	return 0; 
}

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

# define ll long long
//#define forn(i,n) for(int i = 0; i < (n); ++i)

const int N = 100001;
ll dp[N];

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

	int n, tot;
	cin >> n >> tot;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		for (int j = tot - x; j >= 0; j--) {
			dp[j + x] = max(dp[j + x], dp[j] + y);
		}
	}
	cout << dp[tot] << endl;
	return 0;
}

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	if (X > Y) {
		int Z = X;
		X = Y;
		Y = Z;
		int C = A;
		A = B;
		B = C;
	}
	int ans = INF;
	for (int c = 0; c <= 2*Y; c+=2) {
		int tmp = C*c; // tmp: total cost
		if (c/2 <= X) {
			tmp += (X - c/2)*(A + B);
			tmp += (Y - X)*B;
		}
		else {
			tmp += (Y - c/2)*B;
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;

int main()
{
    int32_t a, b, c;
    int k;
    cin >> a >> b >> c >> k;

    if(a >= k){
        cout << k << endl;
    }
    else if(a+b >= k){
        cout << a << endl;
    }
    else{
        cout << a - (k-(a+b)) << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll solve(ll n, ll a, ll b, ll c, ll d){
	ll dp[61][40][27][2]={};
	dp[0][0][0][1]=2e18;
	ll ans=1e18;
	if(n<(ll)(2e18)/d) ans=min(ans, n*d);
	for(int i=0; i<61; i++){
		for(int j=0; j<40; j++){
			for(int k=0; k<27; k++){
				if(i==0 && j==0 && k==0) continue;
				ll p=1;
				bool dame=0;
				for(int l=0; l<i; l++){
					if(p>6e18/2){
						dame=1; break;
					}
					p*=2;
				}
				if(dame) continue;
				for(int l=0; l<j; l++){
					if(p>6e18/3){
						dame=1; break;
					}
					p*=3;
				}
				if(dame) continue;
				for(int l=0; l<k; l++){
					if(p>6e18/5){
						dame=1; break;
					}
					p*=5;
				}
				if(dame) continue;
				ll r=n%p, r1=n%(p/2);
				dp[i][j][k][0]=2e18, dp[i][j][k][1]=2e18;
				if(i){
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i-1][j][k][0]+abs(r-r1)/(p/2));
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i-1][j][k][1]+abs(r+p/2-r1)/(p/2));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i-1][j][k][0]+abs(p-r+r1)/(p/2));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i-1][j][k][1]+abs(p-r-p/2+r1)/(p/2));
				}
				if(j){
					r1=n%(p/3);
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i][j-1][k][0]+abs(r-r1)/(p/3));
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i][j-1][k][1]+abs(r+p/3-r1)/(p/3));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i][j-1][k][0]+abs(p-r+r1)/(p/3));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i][j-1][k][1]+abs(p-r-p/3+r1)/(p/3));
				}
				if(k){
					r1=n%(p/5);
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i][j][k-1][0]+abs(r-r1)/(p/5));
					dp[i][j][k][0]=min(dp[i][j][k][0], dp[i][j][k-1][1]+abs(r+p/5-r1)/(p/5));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i][j][k-1][0]+abs(p-r+r1)/(p/5));
					dp[i][j][k][1]=min(dp[i][j][k][1], dp[i][j][k-1][1]+abs(p-r-p/5+r1)/(p/5));
				}
				if(((n-r)/p+dp[i][j][k][0])<(ll)(2e18)/d) ans=min(ans, ((n-r)/p+dp[i][j][k][0])*d+a*i+b*j+c*k);
				if(((n+p-r)/p+dp[i][j][k][1])<(ll)(2e18)/d) ans=min(ans, ((n+p-r)/p+dp[i][j][k][1])*d+a*i+b*j+c*k);
			}
		}
	}
	return ans;
}
int main()
{
	int t; cin>>t;
	while(t--){
		ll n, a, b, c, d; cin>>n>>a>>b>>c>>d;
		cout<<solve(n, a, b, c, d)<<endl;
	}
	return 0;
}


Measured memory_bytes: 4628
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	stack<char> a;
	stack<char> b;

	string t;

	for (ll i = 0; i < n; i++)
	{
		if (s[i] == ')')
		{
			if (b.empty())
			{
				t += "(";
			}
			else
			{
				b.pop();
			}
		}
		else
		{
			b.push(s[i]);
		}
	}

	s = t + s;


	t = "";

	while (!a.empty())
	{
		a.pop();
	}

	while (!b.empty())
	{
		b.pop();
	}

	for (ll i = s.size() - 1; i >= 0; i--)
	{
		if (s[i] == '(')
		{
			if (b.empty())
			{
				t += ")";
			}
			else
			{
				b.pop();
			}
		}
		else
		{
			b.push(s[i]);
		}
	}

	s = s + t;

	println(s);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
typedef long long ll;
const int INF = 1e+9+7;

int main(){
    int N;
    cin >> N ;
    priority_queue<int,vector<int>,greater<int>> q,p;
    int tmp;
    rep(i,N){
        cin >> tmp;
        q.push(tmp);
    }

    int cur=0;
    int num=0;
    while(q.size()>0||p.size()>0){
        if(q.size()==1){
            cur=q.top();
            break;
        }

        if(p.size()==1){
            cur=p.top();
            break;
        }

        if(!q.empty()){
            cur=q.top();
            p.push(cur);
            q.pop();
            while(!q.empty()){
                num=q.top()%cur;
                q.pop();
                if(num!=0){
                    p.push(num);
                }
            }
        }else{
            cur=p.top();
            q.push(cur);
            p.pop();
            while(!p.empty()){
                num=p.top()%cur;
                p.pop();
                if(num!=0){
                    q.push(num);
                }
            }
        }
    }
    cout << cur << endl;

}

Measured memory_bytes: 1400
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  int res = solve(i+ 1,m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int q, M, i;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll a[100010];
    rep(i,0,N){
        cin >> a[i];
    }
    ll sum[100010] = {};
    ll sum_plus[100010] = {};
    rep(i,0,N){
        sum[i+1] = sum[i] + a[i];
        if(a[i] > 0){
            sum_plus[i+1] = sum_plus[i] + a[i];
        }else{
            sum_plus[i+1] = sum_plus[i];
        }
    }
    ll ans = -INF;
    rep(i,0,N-K+1){
        ll tt = 0;
        tt += sum[K+i]-sum[i];
        tt += sum_plus[N] - sum_plus[K+i];
        tt += sum_plus[i];
        ans = max(ans,tt);
    }
    rep(i,0,N-K+1){
        ll tt = 0;
        tt += sum_plus[N] - sum_plus[K+i];
        tt += sum_plus[i];
        ans = max(ans,tt);
    }
    print(ans);
    // ll ans1 = 0;
    // rep(i,0,N){
    //     if(i < N-K){
    //         if(a[i] > 0) ans1 += a[i];
    //     }
    // }
    // if(sum[N] - sum[N-K] > 0){
    //     ans1 += sum[N] - sum[N-K];
    // }
    // ll ans2 = 0;
    // rep(i,0,N){
    //     if(i >= K){
    //         if(a[i] > 0) ans2 += a[i];
    //     }
    // }
    // if(sum[K] > 0){
    //     ans2 += sum[K];
    // }
    // ll ans3 = -INF;
    // rep(i,0,N-K+1){
    //     ans3 = max(ans3, sum[K+i] - sum[i]);
    // }
    // ll ans = max(ans1, max(ans2,ans3));
    // print(ans);
    // ll ans1 = 0;
    // rep(i,0,N-K+1){
    //     ll val = sum[i+K] - sum[i];
    //     if(val > 0){

    //     }
    // }


}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int x[100005],n,cnt[17],dp[65555],ans,b[65555];bool ok[65555];
int main()
{
    fastio;
    cin>>n;
    rap(i,1,n){
        int u,v,w;
        cin>>u>>v>>w;
        u++;v++;
        x[u]^=w;x[v]^=w;
    }
    int lim=1<<15;
    rep(i,1,n) cnt[x[i]]++;
    int fin=0;
    rep(i,1,15) {
        ans+=cnt[i]/2;
        if(cnt[i]&1) fin|=(1<<(i-1));
    }
    rap(i,0,lim) {
        int xr=0;
        rep(j,1,15) if(i&(1<<(j-1))) xr^=j;
        ok[i]=!xr;
    }
    rap(i,0,lim) b[i]=__builtin_popcount(i),dp[i]=inf;
    dp[0]=0;
    rap(i,0,lim) {
        int u=(lim-1)^i;
        for(int ii=u;ii;ii=(ii-1)&u){
            if(ok[ii])
            dp[i^ii]=min(dp[i^ii],dp[i]+b[ii]-1);
        }
    }
    printf("%d\n",dp[fin]+ans);
    return 0;
}

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

using namespace std;

#define ll long long
#define mod 1000000007

const ll INF = 1e11;

void solve(){

    int x; cin >> x;
    cout << (x >= 30 ? "Yes\n" : "No\n");
    
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A[210];
  
  // 変数Nで入力を受け取る
  cin >> N;
  for(int i =0; i<N ; ++i) cin >> A[i];
  
  int res = 0;
  
  while(true){
  	bool exist_odd = false;
    for(int i =0 ; i < N; i++){
    	if(A[i]%2 != 0) exist_odd = true;
    }
    
    if(exist_odd) break;
    
    for(int i =0 ; i <N; ++i){
    	A[i] /=2;
    }
  	++res;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()

    i = 1
    c = 26
    while n > c:
        i += 1
        n -= c
        c *= 26

    n -= 1
    r = []
    for j in range(i):
        r.append(chr(ord('a') + n % 26))
        n //= 26

    return JA(r[::-1], '')


print(main())




Measured memory_bytes: 10908
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
typedef long long ll;

ll n, val[MAXN << 1];
ll ans = 0;

bool cmp(const ll &x, const ll &y){return x > y;}

int main(){
	scanf("%lld", &n);
	for(ll i = 1; i <= n; i++) scanf("%lld", &val[i]);
	sort(val + 1, val + n + 1, cmp);
	for(ll i = n; i >= 1; i--) val[i << 1] = val[i], val[(i << 1) - 1] = val[i];
//	for(int i = 1; i <= (n << 1); i++) printf("%d ", val[i]); printf("\n");
	for(ll i = 1; i <= n; i++) ans += val[i];
	ans -= val[1];
	printf("%lld\n", ans);
	return 0;
}

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

int n, a[100010];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + n + 1);

	int last = 1;
	while(last < n && a[last + 1] == a[1]) ++last;

	for (int i = last + 1; i <= n; ++i) {
		if (a[i] != a[1] + 1) return printf("No\n"), 0;
	}

	int x = a[1];
	for (int i = last + 1; i <= n; ++i) {
		a[i] -= last;
		if (a[i] <= 0) return printf("No\n"), 0;
		x = a[i];
	} 

	if (last == n) {
		if (n == x + 1) return printf("Yes\n"), 0;
		if (n / x > 1) return printf("Yes\n"), 0;
		printf("No\n");
		return 0;
	}
	if ((n - last) / x <= 1) return printf("No\n"), 0;
	else printf("Yes\n");
}

Measured memory_bytes: 640
S = input()

l = len(S)
count = 0

for i in range(l):
    if "R" not in S:
        break
    cur_count = 1

    for j in range(i+1,l):
        if S[i] == "S":
            break
        if (S[i] != S[j]):
            break
        cur_count += 1
    if cur_count > count:
        count = cur_count

print(count)

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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/
int h,w;int s[21][21];
int out=0;

void bfs(int I, int J) {
	int temp=0;
	vector<vector<bool>> vis(h,vector<bool>(w,false));
	queue<tuple<int,int,int>> q;
	vis[I][J]=true;
	q.push(make_tuple(I,J,0));
	while(!q.empty()) {
		tuple<int,int,int> tp=q.front();
		q.pop();
		int i=get<0>(tp);
		int j=get<1>(tp);
		int len=get<2>(tp);
		int cnt=0;
		if (i+1<h&&s[i+1][j]==0&&!vis[i+1][j]) {
			vis[i+1][j]=true;
			q.push(make_tuple(i+1,j,len+1));
			cnt++;
		}
		if (i-1>=0&&s[i-1][j]==0&&!vis[i-1][j]) {
			vis[i-1][j]=true;
			q.push(make_tuple(i-1,j,len+1));
			cnt++;
		}
		if (j+1<w&&s[i][j+1]==0&&!vis[i][j+1]) {
			vis[i][j+1]=true;
			q.push(make_tuple(i,j+1,len+1));
			cnt++;
		}
		if (j-1>=0&&s[i][j-1]==0&&!vis[i][j-1]) {
			vis[i][j-1]=true;
			q.push(make_tuple(i,j-1,len+1));
			cnt++;
		}
		if (cnt==0) {
			temp=max(temp,len);
		}
	}
	out=max(out,temp);
}

void solve() {
	FOR(i,0,h) {
		FOR(j,0,w) {
			if (s[i][j]==1) continue;
			bfs(i,j);
			// FOR(k,0,h) {
			// 	FOR(l,0,w) {
			// 		if (s[i][j]==1||s[k][l]==1||(i==k&&j==l)) continue;
			// 		bfs(i,j,k,l);
			// 	}
			// }
		}
	}
	cout<<out;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>h>>w;
	FOR(i,0,h) {
		string st;cin>>st;
		FOR(j,0,w) {
			if (st[j]=='.') {
				s[i][j]=0;
			} else {
				s[i][j]=1;
			}
		}
	}
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;
 
typedef int Weight;
//typedef
//------------------------------------------
 
typedef int Weight;
//typedef
//------------------------------------------

int main(){
    int N;
    string A,B,C;
    cin>>N>>A>>B>>C;
    string str="";
    REP(i,N){
        int cnt[26];
        memset(cnt, 0, sizeof cnt);
        cnt[A[i]-'a']++;
        cnt[B[i]-'a']++;
        cnt[C[i]-'a']++;
        bool flag=0;
        REP(j,26){
            if(cnt[j]>1){
                str+='a'+j;flag=1;
            }
        }
        if(!flag)str+=A[i];
    }
    int res=0;
    REP(i,N){
        if(A[i]!=str[i])res++;
        if(B[i]!=str[i])res++;
        if(C[i]!=str[i])res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[100001],m,ans=2147483647;
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for (int i=1;i<=n-m+1;++i) ans=min(ans,a[i+m-1]-a[i]);
    printf("%d",ans);
}

Measured memory_bytes: 640
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll digit_sum(ll n) {
    if (n < 10) return n;
    return digit_sum(n / 10) + n % 10;
}
#endif

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string A, B; cin >> A >> B;
    string S; cin >> S;

    regex re("\\d{" + A + "}-\\d{" + B + "}");

    string ans = "No";
    if (regex_match(S, re)) ans = "Yes";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
vector<vector<int>> g;
vector<bool> vis;
void dfs(int node)
{
	vis[node]=1;
	for(auto u:g[node])
	{
		if(!vis[u])dfs(u);
	}
}
int32_t main()
{
	int n=in();int m=in();int u,v;
	vector<pair<int,int>>edg;
	for(int i=0;i<m;i++)
	{u=in();v=in();u--;v--;edg.push_back({u,v});}
	int cmp=0;
	int ans=0;
	for(int leave=0;leave<m;leave++)
	{
		cmp=0;
		g=vector<vector<int>>(n);
		vis=vector<bool>(n);
		for(int i=0;i<m;i++)
		{
			if(i==leave)continue;
			g[edg[i].first].push_back(edg[i].second);
			g[edg[i].second].push_back(edg[i].first);
		}
		
		for(int i=0;i<n;i++)
		{
			if(!vis[i]){cmp++;dfs(i);}
		}
		if(cmp>1)ans++;
	}
	cout<<ans;
	
	
	
}

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

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll a,b,n;
    cin>>n>>a>>b;
    ll ans=min(n%(a+b),a)+a*(n/(a+b));
    cout<<ans;
}

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

int main(){
    int k, x;
    cin >> k >> x;
    if(500*k >= x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val stones = Array.fill(n){
    val Array(r, c) = readLine.trim.split(' ').map(_.toInt)
    (r - 1, c - 1)
  }.sortBy(_._1)
  val rowCount = Array.fill(n){0}
  val columnCount = Array.fill(n){0}
  for ((r, c) ← stones) {
    rowCount(r) += 1
    columnCount(c) += 1
  }
  if (rowCount.exists(_ > 1) || columnCount.exists(_ > 1)) {
    println(-1)
  }else {
    val columnPosition = stones.map{_._2}
    var count = 0
    for (i ← columnPosition.indices) {
      while (columnPosition(i) != i){
        count += 1
        val temp = columnPosition(i)
        columnPosition(i) = columnPosition(columnPosition(i))
        columnPosition(temp) = temp
      }
    }
    println(count)
  }
}



Measured memory_bytes: 206064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100000 +117;
const int MM=1000000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
struct edge{
	int to,rem,xt;
}e[MM];
int ecnt=1;
int p[2*NN]={};
void ADD(int x,int y,int rem){
	e[++ecnt].to=y;
	e[ecnt].rem=rem;
	e[ecnt].xt=p[x];
	p[x]=ecnt;
}
void add(int x,int y,int rem){
	ADD(x,y,rem);
	ADD(y,x,0);
}
int st,fin;
int g[2*NN]={};
int ht[2*NN]={};
int q[2*NN]={};
bool bfs(int x){
	int std=ht[fin]+10;
	ht[st]=std;
	int hd=0,tl=0;
	q[tl++]=st;
	while(hd!=tl){
		int x=q[hd++];
		if(x==fin)break;
		for(int pos=p[x];pos;pos=e[pos].xt){
			int cur=e[pos].to;
			if(e[pos].rem&&ht[cur]<std){
				ht[cur]=ht[x]+1;
				q[tl++]=cur;
			}
		}
	}
	return ht[fin]>=std;
}
int dfs(int x,int rem){
	if(x==fin)return rem;
	int res=0;
	for(int &pos=g[x];pos;pos=e[pos].xt){
		int cur=e[pos].to;
		if(e[pos].rem&&ht[cur]==ht[x]+1){
			int tp=dfs(cur,min(rem,e[pos].rem));
			if(tp){
				e[pos].rem-=tp;
				e[pos^1].rem+=tp;
				rem-=tp;
				res+=tp;
			}
			if(!rem)break;
		}
	}
	return res;
}
int getf(){
	int res=0;
	while(bfs(st)){
		for(int i=1;i<=fin;++i)g[i]=p[i];
		res+=dfs(st,1e9);
	}
	return res;
}
int match[NN]={};
vector<int> t[NN]={};
int ans[NN][2]={};
int anscnt=0;
bool vis[NN]={};
void getres(int x){
	for(int i=0;i<t[x].size();++i){
		int cur=t[x][i];
		if(!vis[cur]){
			++anscnt;
			vis[cur]=1;
			ans[cur][0]=x;
			ans[cur][1]=match[cur];
			getres(match[cur]);
		}
	}
}
int main(){
	//open();
	n=read();
	st=2*n;
	fin=st+1;
	for(int i=1;i<=n;++i)add(st,i,1);
	for(int i=1;i<n;++i){
		add(n+i,fin,1);
		int k=read();
		for(int j=1;j<=k;++j){
			int x=read();
			t[x].push_back(i);
			add(x,n+i,1);
		}
	}
	int k=getf();
	if(k!=n-1){
		printf("-1\n");
		return 0;
	}
	int rt=0;
	for(int i=1;i<=n;++i){
		bool fl=1;
		for(int pos=p[i];pos;pos=e[pos].xt){
			int cur=e[pos].to;
			if(cur>n&&cur<2*n&&!e[pos].rem){
				match[cur-n]=i;
				fl=0;
			}
		}
		if(fl)rt=i;
	}
	getres(rt);
	if(anscnt!=n-1){
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n-1;++i){
		printf("%d %d\n",ans[i][0],ans[i][1]);
	}
	close();
	return 0;
}

Measured memory_bytes: 24704
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
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; }
//#define int long long

void solve() {
    int ans = 0;
    string s, t; cin >> s >> t;
    rep(i, 3) {
        if(s[i] == t[i]) ans ++;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
#define int long long
using namespace std;

unordered_map<int, char>U;
int g(int a, int b) {
	if (a<b) {
		swap(a, b);
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
signed main() {
	int n, m; cin >> n >> m;
	int l = g(n, m);//最大公約数
	int k = n*m / l;//最小公倍数
	string s, t; cin >> s >> t;
	for (int i = 0; i < n; i++) {
		U[m / l*i] = s[i];
	}
	for (int i = 0; i < m; i++) {
		if (U[n / l*i] && U[n / l*i] != t[i]) {
			puts("-1");
			return 0;
		}
	}
	cout << k << endl;
}

Measured memory_bytes: 7624