akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

main()
{
    string s; string t;
    cin >> s >> t;
    int a = s.length(); int b = t.length();

    int dp[a+1][b+1];
    for(int i=0;i<=b;i++) dp[0][i]=0;
    for(int i=0;i<=a;i++) dp[i][0]=0;

    for(int i=1;i<=a;i++)
    {
        char x = s[i-1];
        for(int j=1;j<=b;j++)
        {
            char y = t[j-1];

            if(x!=y)
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
        }
    }

    string ans="";
    int i=a;int j=b;
    while( i>0 && j>0)
    {
        if(dp[i][j]==dp[i][j-1])
        {
            j--;
        }
        else if(dp[i][j]==dp[i-1][j])
        {
            i--;
        }
        else 
        {
            ans+=s[i-1];
            i--;j--;
        }
    }
    //dp[a][b] gives length of LCS
     reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


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

using namespace std;

const int max_n = 100011, inf = 1000111222;

int n, a[max_n], z[max_n], tot;
vector<int> x, y;

int go() {
    if (x.size() + y.size() == 1) {
        if (x.size()) {
            return x[0];
        }
        return y[0];
    }
    if (x.size() > 1) {
        int val = x.back();
        x.pop_back();
        x.swap(y);
        int res = go();
        printf("%d %d\n", val, res);
        return val - res;
    }
    int val = y.back();
    y.pop_back();
    int res = go();
    printf("%d %d\n", res, val);
    return res - val;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        z[i] = 1;
    }
    sort(a, a + n);
    z[0] = -1;
    for (int i = 1; i + 1 < n; ++i) {
        if (a[i] > 0) {
            break;
        }
        z[i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        tot += z[i] * a[i];
        if (z[i] == 1) {
            x.push_back(a[i]);
        } else {
            y.push_back(a[i]);
        }
    }
    printf("%d\n", tot);
    go();
    return 0;
}


Measured memory_bytes: 6264
'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(params,data) {
		var table = data.slice(0,params[0]).map(function(v) {
			var tmp = v.split(' ').slice(0,params[1]).map(Number);
			tmp.push(tmp.reduce(function(a,b){ return a + b; }));
			return tmp;
		});

		var line = [];
		for (var i = 0; i < params[1] + 1; i++) {
			var sum = 0;
			for (var j = 0; j < params[0]; j++) {
				sum += table[j][i];
			}
			line.push(sum);
		}
		table.push(line);
		return (table.join('\n').replace(/,/g,' '));


	}(
		lines.shift().split(' ').map(Number)
		,lines
		));

	console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

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

signed main() {
  vector<int> gohan(5);
  vector<int> zikan(5);
  int total = 0;
  for( int i = 0; i < 5; i++ ){
    cin >> gohan.at(i);
    if( gohan.at(i) % 10 != 0 ){
      zikan.at(i) = gohan.at(i) + (10 - (gohan.at(i) % 10));
    }else{
      zikan.at(i) = gohan.at(i);
    }
    total += zikan.at(i);
  }
  
  int ans = 100000;
  for( int i = 0; i < 5; i++ ){
    if( total - zikan.at(i) + gohan.at(i) < ans ){
      ans =  total - zikan.at(i) + gohan.at(i);
    }
  }
  cout << ans << endl;
  
    
  
}


Measured memory_bytes: 256
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *NOIP 2019 RP++                                           *
 ***********************************************************/
//#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
	char *pp = (char*)malloc(size) + size;  \
	__asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<fstream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) (((x)>(y))?(x):(y))
#define Min(x,y) (((x)<(y))?(x):(y))
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register ll a=b;a<=c;++a)
#define FORD(a,b,c) for (register ll a=b;a>=c;--a)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
	ll x=0,f=1;char c;
	for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
	for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}
template<typename T>
inline void write(T a){
	if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
	while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
ll n,a[mn],ans[mn];
signed main(){
	#ifdef _WIN32
		// freopen("0.in","r",stdin);
		// freopen("0.out","w",stdout);
		long double be=clock();
	#endif
	n=read();
	ll sum=0,an=0;
	FOR(i,1,n)a[i]=read(),sum+=a[i],an+=((i%2==1)?(a[i]):(0));
	ans[1]=an*2ll-sum;
	FOR(i,1,n-1)ans[i+1]=a[i]*2ll-ans[i];
	FOR(i,1,n)write_(ans[i]);
	#ifdef _WIN32
		long double en=clock();
		printf("Time: %.0Lfms\n",en-be);
		fclose(stdin);fclose(stdout);
	#endif
	return 0;
}

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

int main(){
    string str;
    getline(cin,str);
    for(int i=0;str[i]!='\0';i++){
        if(str[i]>='a'&&str[i]<='z')str[i]+='A'-'a';
        else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
    }
    cout<<str<<endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

void solve(long long K){
	const long long N = 50;
	vector<long long> a(N);
	long long q = K/N, r = K%N;
	REP(i,N){
		a[i] = N-1-i;
		a[i] += q;
		if(i<r)a[i]++;
	}
	cout<<N<<endl;
	REP(i,N){
		cout<<a[i];
		if(i<N-1)cout<<" ";
	}
}

int main(){	
	long long K;
	scanf("%lld",&K);
	solve(K);
	return 0;
}


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

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

    if (a <= 0 && b >= 0) {
        std::cout << "Zero" << std::endl;
        return 0;
    }

    if (a > 0) {
        std::cout << "Positive" << std::endl;
        return 0;
    }

    if ((b - a + 1) % 2) {
        std::cout << "Negative" << std::endl;
    } else {
        std::cout << "Positive" << std::endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  int c[26], s[n][26];
  vector<int> last(26, -1);
  for (int i = 0; i < 26; ++i)
    cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  for (int i = 0; i < n; ++i) {
    int neg(0), score(0), test(-1);
    for (int j = 0; j < 26; ++j) {
      if (last[j] >= 0) neg -= c[j];
    }
    int max_score = -1e9;
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + (last[j] >= 0 ? c[j] : 0);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    cout << rand() % 26 + 1 << endl;
    last[test] = i;
  }
  return 0;
}

Measured memory_bytes: 3668
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		 	int n = sc.nextInt();
			int m = sc.nextInt();
			int[] a = new int[n];
			double sum = 0;
			int p = 0;

			for (int i = 0;i<n ;i++ ) {
				a[i] = sc.nextInt();
				sum +=a[i];
			}

			for (int i = 0;i<n ;i++ ) {
				if ((double)(sum/(4*m))<=a[i]) {
					p++;
				}
			}

			if (p>=m) {
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}


	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int i,num;
}A[110000];
bool fun(node a,node b)
{
	return a.num<b.num;
}
int main()
{
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		int t;
		cin>>t;
		A[i].i=i;
		A[i].num=t;
	}
	sort(A+1,A+N+1,fun);
	for(int i=1;i<=N;i++)
	{
		cout<<A[i].i<<" ";
	}
} 

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    int N; cin >> N;
    string S = "";
    
    while(N!=0){
        int r=N%2;
        if(r<0) r += 2;

        N = (N-r)/(-2);
        S += (char)('0'+r);
    }
    if(S==""){
        cout << 0 << endl;
    }else{
        for(int i=0;i<S.length();i++){
            cout << S[S.length()-i-1];
        }
        cout << endl;
    }
    return 0;
}


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

int main()
{
	int a, b, c, answer;
	bool can = false;

	cin >> a >> b >> c;
		

	for (int i = 1; i <= b; i++) {
	
		if (i * a % b == c) {
			can = true;
			break;
		}
	}

	if (can) { cout << "YES" << endl; }
	else     { cout << "NO"  << endl; }	
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s0 = input().rstrip()
s1 = input().rstrip()
v = True
index = 0
res = 3
while index < n:
    vv = s0[index] == s1[index]
    if index == 0 and vv:
        pass
    elif v:
        res *= 2
    elif not v and not vv:
        res *= 3
    index += 1 if vv else 2
    v = vv
MOD = 10**9 + 7
print(res % MOD)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int  n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    rep(i,n) v[i]-=(i+1);
    sort(v.begin(),v.end());
    ll sum = 0;
    rep(i,n) sum += abs(v[i]-v[n/2]);
    cout<< sum <<endl;
    return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int D;
  vector<int> A(N);
  map<int,int> record;
  for (int i = 0; i < K; i++) {
    cin >> D;
    for (int j =  0; j < D; j++) {
      cin >> A.at(j);
    }
    for (int x: A) {
      if (record.count(x)) {
        record[x]++;
      }
      else {
        record[x] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < N+1; i++) {
    if (record.count(i)) {
      ans += 0;
    }
    else {
      ans++;
    }
  }
  cout << ans <<endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	ll a, b, k;
	cin >> a >> b >> k;
	if (a >= k) {
	  cout << a - k << " " << b << endl;
	} else {
	  k -= a;
	  if (b >= k) cout << 0 << " " << b - k << endl;
	  else cout << 0 << " " << 0 << endl;
	}
    
    return 0;
}



Measured memory_bytes: 3656
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    if n == 1:
        print(0)
        sys.exit()
    r = defaultdict(int)
    for i1 in range(1,101):
        for i2 in range(1,101):
            for i3 in range(1,101):
                t = pow(i1, 2) + pow(i2, 2) + pow(i3, 2) + i1*i2 + i2*i3 + i1*i3
                t = int(t)
                r[t] += 1
    for i1 in range(1, n+1):
        print(int(r[i1]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 11684
#include <iostream>

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

    if (n % 10 == 7)
    {
        std::cout << "Yes" << std::endl;
        return 0;
    }
    n = n / 10;
    if (n % 10 == 7)
    {
        std::cout << "Yes" << std::endl;
        return 0;
    }
    n = n / 10;
    if (n == 7)
    {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
using namespace std;




int main() {

    int n;
    cin>>n;

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

    int count = 0;
    int min_num = arr[0];
    for(int i = 0; i < n; i++) {
        if(arr[i] <= min_num) {
            count++;
            min_num = arr[i];
        }
    }

    cout<<count<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,M,ans = 303;
    cin >> N >> M;
    vector<vector<int>> A(N,vector<int>(M));
    rep(i,N)rep(j,M){
        cin >> A[i][j];
        A[i][j]--;
    }
    // まず全てのスポーツ大会を開催する 
    // そのときの参加人数を求める
    set<int> st;
    rep(i,M)st.insert(i);
    while(st.size()){
        vector<int> cnt(M);
        // ここで現在の参加人数を出す
        rep(i,N)rep(j,M){
            if(st.count(A[i][j])){
                cnt[A[i][j]]++;
                break;
            }
        }
        int del = -1;
        int mx = 0;
        rep(i,M){
            if(mx<cnt[i]){
                mx = cnt[i];
                del = i;
            }
        }
        st.erase(del);
        ans = min(ans,mx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
inp = [int(v) for v in input().split(' ')]
k = inp[0]
x = inp[1]

minv = x - k + 1
maxv = x + k - 1
for v in range(minv, maxv + 1):
    if v != maxv:
        print(str(v) + ' ', end = "")
    else:
        print(str(v))


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


int main()
{
  int s, k, cnt=0;

  cin >> k >> s;
  for (int x=0; x<k+1; x++){
    for (int y=0; y<k+1; y++){
      if (0 <= s-x-y && s-x-y <= k) cnt++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}


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

int n,ii=0,now=0;

signed main()
{
	cin>>n;
	while (ii<=80000000)
	{
		ii++;
		now=(now*10+7)%n;
		
		if (now==0)  return cout<<ii<<endl,0;
	}
	cout<<-1<<endl;
	return 0;
}


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

string a,b;
int n, se[10];
string sed[2][10];
bool f;
int res=1000;

void bfs(string s, int ans)
{
	if(s==b)
	{
		res=min(res,ans);
		f=0;
	}
	if(s.size()>=b.size()) return;
	for (int i = 0; i < n; ++i)
	{
		if(s.size()>=sed[0][i].size())
		{
			string tmp=s;
			for (int j = 0; j <= tmp.size()-sed[0][i].size(); ++j)
			{
				bool hit=1;
				for (int k = 0; k < sed[0][i].size(); ++k)
				{
					if(tmp.at(j+k)!=sed[0][i].at(k)) hit=0;
				}
				if(hit)
				{
					for (int l = 0; l < se[i]; ++l) tmp+="a";
					for (int l = tmp.size()-se[i]-1; l > j ; --l) tmp.at(l+se[i])=tmp.at(l);
					for (int l = 0; l < sed[1][i].size(); ++l) tmp.at(j+l)=sed[1][i].at(l);
					j+=sed[1][i].size()-1;
				}
			}
			if(s!=tmp) bfs(tmp,ans+1);
		}
	}
}


int main(int argc, char const *argv[])
{
	while(cin>>n,n)
	{
		f=1,res=1000;
		for (int i = 0; i < n; ++i) cin>>sed[0][i]>>sed[1][i],se[i]=sed[1][i].size()-sed[0][i].size();
		cin>>a>>b;
		bfs(a, 0);
		cout<<((res==1000)?-1:res)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3168
N = int(input())
H_ = list(map(int,input().split()))
def dp_solver(x):
    H = H_
    dp=[float('inf')]*N
    dp[0]=0
    dp[1]=abs(H[1]-H[0])
    for i in range(N-2):
        dp[i+2] = min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))
        dp[i+2] = min(dp[i+2],dp[i+1]+abs(H[i+2]-H[i+1]))
    return dp[x-1]
print(dp_solver(N))

Measured memory_bytes: 13900
#include<iostream>
#include<string>

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

  if(s == "AAA" || s == "BBB"){
    std::cout << "No" << std::endl;
  }
  else{
    std::cout << "Yes" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
int main(void){
  int n,i,x;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    x=i;
    if ( x % 3 == 0 ){
      printf(" %d",i);
    }else{
      do{
        if ( x % 10 == 3 ){
          printf(" %d",i);
          x=0;
        }
        x /= 10;
      }while( x );
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2116
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}


int main(){
    int n;   cin >> n;
    int N = n;
    int s=0;
    while(n > 0){
        s += n%10;
        n = n/10;
    }
    int ret=0;
    ret = N%s;
    if(ret == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, W;
  cin >> N >> W;
  static int w[101010], v[101010];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
    sum += v[i];
  }

  static int dp[110][101010];
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j <= 101000; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i <= N; i++) dp[i][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= sum; j++) {
      if (j - v[i] < 0) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
      }
    }
  }

  for (int i = sum; i >= 0; i--) {
    if (dp[N][i] <= W) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 86272
import random


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


def lcm(a, b):
    return (a * b) / gcd(a, b)


n = int(input())
#a = list(map(int, input().split()))
#= map(int, input().split())
if n>=30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf -1000000000000000000
int n,k;

int main() {
	io
	int n;
	cin>>n;
	vector<int>vec(n+2,0);
	for(int i=1;i<=n;i++)
	cin>>vec[i];
	unordered_map<int,int>mp;
	for(int i=1;i<=n;i++)
	mp[i+vec[i]]++;
	long long count=0;
	for(int i=1;i<=n;i++)
	count+=mp[i-vec[i]];
	cout<<count;
	return 0;
}


Measured memory_bytes: 19316
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		vector<int>l;
		long long sum;
		for (int i = 0; i < n; i++) {
			cin >> sum;
			l.push_back(sum);
		}
		sort(l.begin(), l.end());
		sum = 0;
		for (int i = 0; i < n; i++) {
			sum += l[i] * (n - i - 1);
		}
		cout << sum << endl;
	}
	return 0;
}

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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
const LL INT32 = (LL(MAXINT) + 1) * 2;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

template <class T>
inline bool Read(T &ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), Write(x);
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

int main()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3612
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int main(){
	fastio;
	int x;
	R(x);
	cout<<(x^1)<<endl;	
	return 0;
}


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

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

template <typename T1, typename T2> void scf(T1 &x, T2 &y) {
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z) {
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar() {
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y) {
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y) {
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

int n, a, b;

int main() {
	scf(n, a, b);
	for(;;) {
		if(a - 1 < 1 || a - 1 == b) {
			++a;
			if(a > n || a == b) {
				puts("Borys");
				return 0;
			}
		}
		else {
			if(a + 1 > n || a + 1 == b) {
				--a;
			}
			else {
				if(b > a) {
					++a;
				}
				else {
					--a;
				}
			}
		}
		swap(a, b);
		if(a - 1 < 1 || a - 1 == b) {
			++a;
			if(a > n || a == b) {
				puts("Alice");
				return 0;
			}
		}
		else {
			if(a + 1 > n || a + 1 == b) {
				--a;
			}
			else {
				if(b > a) {
					++a;
				}
				else {
					--a;
				}
			}
		}
		swap(a, b);
	}
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = []
b = []

for _ in range(n):
    a += [list(input())]
for _ in range(m):
    b += [list(input())]

for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:m+j] for k in a[i:m+i]] == b:
            print('Yes')
            exit()
print('No')


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, m,a,b,cut = 0, ans = 0;;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  rep(i, m) cin >> a >> b, v[i] = {--b, --a};
  sort(v.begin(), v.end());
  for (auto x : v) if (x.second >= cut) ans++, cut = x.first;
  cout << ans << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
//#define sum(start, end) accumulate(start, end, 0)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

using namespace std;
template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

vector<int> primes;

void makePrimes(int size) {
    bool flag[55560];

    rep(i, size) {
        flag[i] = true;
    }

    int limit = sqrt(size);
    REP(i, 2, limit) {
        if(flag[i]) {
            primes.push(i);
            for(int j=i; j<size; j+=i) {
                // cout << "d" << j;
                flag[j] = false;
            }
        }
    }
    REP(i, limit, size) {
        if(flag[i]) {
            primes.push(i);
        }
    }
}

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

    ll N=in();

    // とりあえず素数の数列を作る
    makePrimes(55556);

    // 5で割って1余る素数だけ使う
    int j=0;
    vector<int> res;
    rep(i, primes.size()) {
        if(primes[i]%5 == 1)
            res.push(primes[i]);
    }

    cout << res[0];
    REP(i, 1, N) {
        cout << " " << res[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int x;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>x;
	for(int i=1;i<=3333;i++)if((i*x)%360==0){cout<<i<<'\n'; return 0;}
	return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
//解説AC
#include<iostream>
#include<string>

using namespace std;

int main(){
int N; cin >> N; string S; cin >>S;
  int need_left = 0; int pointer = 0;
  for(int i = 0;i < N; i++){
    if(S[i] == '('){ pointer++;}
    else{
      if(pointer == 0){ need_left++;}
      else{pointer--;}}}
    for(int i = 0; i < need_left; i++){
      cout << '(' ;}
    cout << S;
    for(int i = 0; i < pointer; i++){
      cout << ')';}
    return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	string s[h];
	for(int i =0;i<h; i++)
		cin>>s[i];
	for(int i = 0,j=0;i<2*h; i+=2,j++)
		cout<<s[j]<<endl<<s[j]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

int main(){
  int i,j,cnt=0;
  string s;
  cin>>s;
  int n;
  for(i=1;i<s.size();i++){
    if(s[i-1]=='B' && s[i]=='C'){
      if(i!=n-1)s=s.substr(0,i-1)+'S'+s.substr(i+1);
      else s=s.substr(0,i-1)+'S';
      i--;
    }
  }
  n=s.size();
  string c[n];
  for(i=0;i<n;i++)c[i]="";
  for(i=0;i<n;i++){
    if(s[i]=='A' || s[i]=='S'){
      c[cnt]+=s[i];
      if(i!=n-1 && s[i+1]!='A' && s[i+1]!='S')cnt++;
    }
  }
  n=cnt+1;
  ll sum=0;
  for(i=0;i<n;i++){
    cnt=0;
    for(j=0;j<c[i].size();j++){
      if(c[i][j]=='S'){
        sum+=j-cnt;
        cnt++;
      }
    }
  }
  cout<<sum;
}

Measured memory_bytes: 4172
import java.util.*


fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    solve(n, s)
}




private fun solve(n: Int, s: String) {
    val list = IntArray(s.length)
    var hasOne = false

    for (i in s.indices) {
        val d = s[i] - '0'
        list[i] = d - 1
        if(list[i] == 1) {
            hasOne = true
        }
    }
    var cnt = 0
    for(i in 0 until n) {
        val l = n - 1 - i
        val r = i
        if((l xor r) != n-1) continue
        cnt += if(hasOne) {
            if(list[i] == 1) 1 else 0
        } else {
            list[i] / 2
        }
    }
    if(cnt % 2 == 0)
        print(0)
    else {
        if(hasOne)
            print(1)
        else
            print(2)
    }
}



Measured memory_bytes: 48736
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
struct UnionFind {
  int *data;
  UnionFind(int *_data, int size, bool reset = true) : data(_data) {
    if(reset) for(int i = 0; i < size; i++) data[i] = -1;
  }
  bool unionSet(int x, int y) {
    x = find(x); y = find(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
};
int main(int argc, char *argv[])
{
  // kruskal with x being unused.
  // assumption: es is sorted
  auto kruskal = [](int n, const vector<pair<int,pair<int,int>>> &es, int *ufdata, int st, vector<bool> &used) {
    UnionFind uf(ufdata, n, false);
    int sum = 0;
    for(int i = st; i < es.size(); i++) {
      const int u = es[i].second.first;
      const int v = es[i].second.second;
      if(uf.find(u) != uf.find(v)) {
        used[i] = true;
        uf.unionSet(u, v);
        sum += es[i].first;
      }
    }
    return sum;
  };
  int n, m;
  vector<pair<int,pair<int,int>>> es;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int s, d, c;
    cin >> s >> d >> c;
    es.push_back(make_pair(c, make_pair(s-1, d-1)));
  }
  sort(es.begin(), es.end());
  int mn = -1;
  int sum = 0;
  int cnt = 0;
  vector<int> ufdata(n);
  vector<bool> used(m, false);
  UnionFind uf(&(ufdata[0]), n);
  {
    vector<int> ufdata2(n);
    for(int j = 0; j < n; j++) ufdata2[j] = ufdata[j];
    mn = kruskal(n, es, &(ufdata2[0]), 0, used);
  }
  int ksum = 0;
  for(int i = 0; i < m; i++) {
    vector<int> ufdata2(n);
    for(int j = 0; j < n; j++) ufdata2[j] = ufdata[j];
    if(used[i]) {
      int mni = ksum + kruskal(n, es, &(ufdata2[0]), i+1, used);
      if(mni != mn) {
        cnt ++;
        sum += es[i].first;
      }
    }
    const int u = es[i].second.first;
    const int v = es[i].second.second;
    if(uf.find(u) != uf.find(v)) {
      uf.unionSet(u, v);
      ksum += es[i].first;
    }
  }
  cout << cnt << " " << sum << endl;
  return 0;
}




Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int cnt = 1;
  int num;
  while(cin>>num)
  {
    if(num==0) return 0;
    cout << "Case " << cnt << ": " << num <<"\n";
    cnt++;
  }
  return 0;
}


Measured memory_bytes: 3092
#pragma once
#include <string>
#include<iostream>
#include<stack>
#include<queue>
#include <vector>

#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(container) (container).begin(),(container).end()

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int count = 0;
	rep(i, S.length()) {
		if (S[i] == T[i])count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define SQ(a) (a)*(a)you
#define f first
#define s second
#define int long long
#define PB push_back
#define MP make_pair
#define db long double
#define all(a) a.begin(), a.end()
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
#define mod 1000000007 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
      

    return (a.first<b.first); 
} 

int32_t main()
{
IOS


        int m,n;
        cin>>n>>m;

        vector<pair<int,int>>v;

        for(int i=0;i<n;i++)
        {
          int x,y;
          cin>>x>>y;
          v.PB(MP(x,y));
        }
          sort(v.begin(),v.end(),sortbysec);



            int ans=0;
            int bought=0;
            for(int i=0;i<n;i++)
            {
              if(v[i].s+bought<=m)
              {
                bought+=v[i].s;
                ans+=(v[i].s)*(v[i].f);

              }
              else
              {
                int k=m-bought;
                ans+=k*v[i].f;
                cout<<ans;
                return 0;
              }
            }
            cout<<ans;

    return 0;
    }
    
    
  

  

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

using namespace std;

int main(){

    string s;
    cin >> s;

    vector<string> ans;
    string cur = "";
    for(int i=0; i<s.size(); i++){
        if(s[i]!=',') cur += (char)s[i];
        if(s[i] == ',' || i==s.size()-1){
            ans.push_back(cur);
            cur = "";
        }
    }

    for(auto st : ans){
        cout << st << " ";
    }
    puts("");
    return 0;
}

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

void solve(long long N, std::vector<std::string> ss)
{
    ll AB = 0;
    ll B = 0;
    ll A = 0;
    ll BA = 0;
    for (auto&& s : ss) {
        auto pos = 0;
        while ((pos = s.find("AB", pos)) != string::npos) {
            AB++;
            pos += 2;
        }

        if (s.front() == 'B' && s.back() == 'A') {
            BA++;
        } else if (s.front() == 'B') {
            B++;
        } else if (s.back() == 'A') {
            A++;
        }
    }

    ll ans = AB;
    if (BA == 0) {
        ans += min(B, A);
    } else {
        if (B + A > 0) {
            ans += BA + min(B, A);
        } else {
            ans += BA - 1;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, std::move(s));
    return 0;
}


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

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    if(S[0] == 'R') {
        for(int i=0; i<N; ++i) S[i] = (S[i] == 'L' ? 'R' : 'L');
    }

    int cnt = 1;
    for(int i=0; i+1<N; ++i) {
        if(S[i] != S[i + 1]) ++cnt;
    }

    if(cnt > 1) {
        if(cnt % 2) cnt -= 2 * min(K, cnt / 2);
        else if(cnt / 2 > K) cnt -= 2 * K;
        else cnt = 1;
    }
    cout << N - cnt << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
ll ans = 0, a[114514], b[114514],d = 0,e,f = 0;
vector<ll> c;
int main() {
	int n;
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) {
		cin >> b[i];
		if (b[i] - a[i] >= 0) {
			d += b[i] - a[i];
			f++;
		}
		else c.push_back(a[i] - b[i]);
	}
	sort(ALL(c),greater<int>());
	if (d == 0) {
		cout << 0 << endl;
		return 0;
	}
	else {
		REP(i, c.size()) {
			d -= c[i];
			ans++;
			if (d <= 0) {
				cout << ans + f<< endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
}




Measured memory_bytes: 2424
#include <iostream>
using namespace std;
int main(void){
   int n,m=0,cnt=0;
   
   cin>>n;
   int h[100]={};
   
   for(int i=0;i<n;i++){
       cin>>h[i];
       if(m<h[i]) m=h[i];
   }
   
   int b[110][110]={};
   
   
   for(int j=0;j<n;j++){
       for(int k=0;k<h[j];k++){
         b[j][k]++;
       }
   }

   for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(b[i][j]==1 && b[i+1][j]==0) cnt++;
            
        }   
   }
  
   cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int AB,BC,CA;
	scanf("%d %d %d",&AB,&BC,&CA);
	if(AB>BC){
		if(CA>AB){
			printf("%d",BC*AB/2);
		}else{
			printf("%d",CA*BC/2);
		}
	}else{
		if(BC>CA){
			printf("%d",CA*AB/2);
		}else{
			printf("%d",BC*AB/2);
		}
	}
	return 0;
}

			
	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
 
int main(){
    ll K,X;
    cin>>K>>X;
    if(K*500>=X)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]

for h in range(H):
    done = [False] * W
    for w in range(W):
        if S[h][w] == '#': continue
        if done[w]: continue

        tmp = w
        cnt = 0
        while tmp < W:
            if S[h][tmp] == '#': break
            cnt += 1
            tmp += 1

        for i in range(w, tmp):
            memo[h][i] += cnt
            done[i] = True

for w in range(W):
    done = [False] * H
    for h in range(H):
        if S[h][w] == '#': continue
        if done[h]: continue

        tmp = h
        cnt = 0
        while tmp < H:
            if S[tmp][w] == '#': break
            cnt += 1
            tmp += 1

        for i in range(h, tmp):
            memo[i][w] += cnt
            done[i] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, memo[i][j] - 1)
print(ans)


Measured memory_bytes: 102232
//A.cpp
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  long long a[5] = {0};
  for(int i = 0; i < N; i++){
    cin >> S;
    if(S[0]=='M') ++a[0];
    else if(S[0]=='A') ++a[1];
    else if(S[0]=='R') ++a[2];
    else if(S[0]=='C') ++a[3];
    else if(S[0]=='H') ++a[4];
  }

  long long Ans = 0;
  for(int i = 0; i < 3; i++){
    for(int j = i+1; j < 4; j++){
      for(int k = j+1; k < 5; k++){
        Ans += a[i]*a[j]*a[k];
      }
    }
  }

  printf("%lld\n",Ans);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
#define ll long long
#define maxn 200005
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main(void)
{
	int n;
	ll a[maxn];
	priority_queue<ll,vector<ll>,greater<ll> > p;
	while(~scanf("%d",&n))
	{
		long long sum=0;
		for(int i=0;i<n;++i)
		{
			scanf("%lld",&a[i]);
		}
		sort(a,a+n,cmp);
		sum=a[0];
		for(int i=1;i<n/2;++i)
		{
			sum+=2*a[i];
		}
		if(n&1)
		sum+=a[n/2];
		printf("%lld\n",sum);
	}
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A;
    for(int i = 0; i < N; i++) {
        int num;
        cin >> num;
        A.push_back(num);
    }

    sort(A.begin(), A.end());

    vector<pair<int, int> > BC;
    int B, C;
    for(int i = 0; i < M; i++) {
        cin >> B >> C;
        BC.push_back(make_pair(C, B));
    }

    sort(BC.begin(), BC.end());

    bool flag = true;
    int offset = 0;
    for(int i = BC.size() - 1; i >= 0 && flag; i--) {
        for(int j = 0; j < BC[i].second && j + offset < A.size(); j++) {
            if(A[j + offset] >= BC[i].first) {
                flag = false;
                break;
            }
            A[j + offset] = BC[i].first;
        }
        offset += BC[i].second;
    }

    long long ans = 0;
    for(int i = 0; i < N; i++) {
        ans += A[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1784
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b;
int GCD(int a,int b)
{
    return (b == 0)?a:GCD(b,a%b);
}
int main()
{
    while(scanf("%d %d",&a,&b) != EOF)
    {
        if(a < b)
            swap(a,b);
        int gcd = GCD(a,b);
        int lcm = (a/gcd)*(b/gcd)*gcd;
        printf("%d %d\n",gcd,lcm);
    }
    return 0;
}



Measured memory_bytes: 2720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define INF 10000000000000LL
#define DIM 100007
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update> myset;
typedef  pair< long long, pair<long long, long long> > ppll;
ll n,m,c,x,x2,y2,e,h,k,res1,a1,a2,w,a3,y,z,a4,a5,a6,last,dist,LL,timer,start,finish,maxmask,newmax,reslast,tests,police,brothers;
string s,s1;
ld res;
ll dp[100007];
ll mas[107];

int main(){


    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>mas[i];
    }
    sort(mas+1,mas+1+n);
    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++){
            if(i>=mas[j]){
                if(dp[i-mas[j]]==0){dp[i]=1;break;}
            }else{
                break;
            }
        }
    }
    if(dp[k]==1){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
  long A, B, C;
  cin >> A >> B >> C;
  if(A * B * C % 2 == 0)cout << 0 << endl;
  else {
    cout << min(B * C, min(A * B, C * A)) << endl;
  }
  return 0;
}


Measured memory_bytes: 256