akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int N;
string s[10100];

void solve()
{
    int ans = 0;
    bool flag = false;
    int a = 0, b = 0, ab = 0;
    FOR(i, 0, N)
    {
        int SI = s[i].size();
        int sf = s[i].front(), sb = s[i].back();
        FOR(j, 0, SI)
        {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
                ans++;
            }
        }
        if (sf == 'B' && sb == 'A') {
            ab++;
        } else if (sf == 'B') {
            b++;
            flag = true;
        } else if (sb == 'A') {
            a++;
            flag = true;
        }
    }
    if (ab == 0)
        flag = true;
    ans += ab + min(a, b) - (int)(!flag);
    cout << ans << endl;
}

signed main()
{
    cin >> N;
    FOR(i, 0, N)
    cin >> s[i];
    solve();
    return 0;
}


Measured memory_bytes: 768
program ABC168A
    implicit none
    integer(8)::N
    read*,N
    if(mod(N,10)==3)then
        print'(A)',"bon"
    else if(mod(N,10)==0.or.mod(N,10)==1.or.mod(N,10)==6.or.mod(N,10)==8)then
        print'(A)',"pon"
    else
        print'(A)',"hon"
    end if
end program ABC168A

Measured memory_bytes: 2924
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;

void input(){
   int n;
   cin >> n;
   vector<int>a(n);
   f(i, n)cin >> a[i];
   int ans = INT_MAX;
   for(int i = 1; i <= 100; ++i){
       int eng = 0;
       f(j, n){
           eng += (a[j] - i) * (a[j] - i);
       }
       ans = min(ans, eng);
   }
   cout << ans << endl;

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

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

int main() {
	int sum = 0;
	int r, g, b; cin >> r >> g >> b;
	int n; cin >> n;
	int i=0, j=0;
	for (i = 0; i <= n / r ; i++) {
		for (j = 0; j <= n / g; j++) {
			if ((n-i * r - j * g) % b == 0 && 0 <= (n-i * r -j * g) / b) { sum = sum + 1; }
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    string s[n];
    rep(i, n)   cin >> s[i];
    
    int m;
    cin >> m;
    string t[m];
    rep(i, m)    cin >> t[i];
    
    int cnt = 0;
    int cash = 0;
    rep(i, n){
        string tmp;
        tmp = s[i];
        //cout << tmp << endl;
        rep(j, n){
            if(tmp == s[j]){
                cnt++;
            }
        }
        
        rep(j, m){
            if(tmp == t[j]){
                cnt--;
            }
        }
        cash = max(cash, cnt);
        cnt = 0;
    }
    cout << cash << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const ll INF = 1LL << 60;
ll N, W;
ll dp[110][100010] = {0};
ll weight[110], value[110];
int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> weight[i] >> value[i];
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if(j-weight[i]>=0){
                chmax(dp[i+1][j], dp[i][j-weight[i]]+value[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
        
    }
    

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81512
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(void){
  string S;
  cin >> S;
  int sl = S.size();
  int a = 0, bc = 0;
  ll ans = 0;
  for(int i = 0; i < sl; i++){
    if(S[i] == 'A'){
      a++;
    }
    else if(i+1 < sl && S[i] == 'B' && S[i+1] == 'C'){
      ans += a;
      i++;
    }else{
      a = 0;
    }
  }
  cout << ans << endl;











}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr long long LINF=334ll<<53; constexpr int INF=15<<26; constexpr long long MOD=1E9+7;
void ok(){cout << "YES" <<"\n"; exit(0);}
void fail(){cout << "NO" <<"\n"; exit(0);}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    LL n;
    cin >> n;
    if(n==1) ok();
    vector<LL> a(n),b(n),c(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    LL sum=accumulate(a.begin(),a.end(),0ll);
    if(sum%(n*(n+1)/2)!=0)fail();
    LL cnt=sum/(n*(n+1)/2);
    a.push_back(a[0]);
    LL removes=0;
    for(int i=0; i<n; ++i){
        LL dif=a[i+1]-a[i];
        if((cnt-dif)%n!=0)fail();
        else{
            b[i]=(cnt-dif)/n;
            if(b[i]<0)fail();
            removes+=b[i];
        }
    }
    if(removes!=cnt)fail();
    /*a.pop_back();
    vector<int> visited(n);
    int adddif=0,add=0;
    for(int i=0; i<2*n; ++i){
        int now=i%n;
        if(visited[now]==0){
            adddif+=b[now];
            visited[now]=1;
        }
        else {
            adddif-=b[now];
            add-=b[now]*n;
        }
        add+=adddif;
        c[(now+1)%n]+=add;
    }
    for(int i=0; i<n; ++i){
        if(c[i]!=a[i])fail();
    }*/

    ok();



    return 0;
}



Measured memory_bytes: 3456
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n,a;cin>>n>>a;
    int s = n-(n/500)*500;
    cout<<(a>=s?"Yes":"No");
}



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

struct Card {
    char suit;
    int value;
};

void bubble(struct Card A[], int N ){
    for (int i = 0; i < N; i++){
        for (int j = N - 1; j >= i+1; j--){
            if ( A[j].value < A[j - 1].value) {
                Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N){
    for (int i = 0; i < N; i++){
        int minj = i;
        for (int j = i; j < N; j++){
            if (A[j].value < A[minj].value) minj = j;
        }
        Card t = A[i]; A[i] = A[minj]; A[minj] = t;
    }
}

void print(struct Card A[], int N ){
    for (int i = 0; i < N; i++){
        if (i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
    for (int i = 0; i < N; i++){
        if (C1[i].suit != C2[i].suit) return false;
    }
    return true;
}


int main(){
    int N;
    cin >> N;
    Card C[N], C1[N], C2[N];
    for (int i = 0; i < N; i++) {
        cin >> C[i].suit >> C[i].value;
        C1[i] = C2[i] = C[i];
    }

    bubble(C1, N);
    selection(C2, N);
    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if ( isStable(C1, C2, N)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  cout << (a+b)%24 <<endl;
}

Measured memory_bytes: 256
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    AB = [x2-x1, y2-y1]
    BC = [x3-x2, y3-y2]
    CA = [x1-x3, y1-y3]
    BP = [xp-x2, yp-y2]
    CP = [xp-x3, yp-y3]
    AP = [xp-x1, yp-y1]
    v1 = AB[0]*BP[1]-AB[1]*BP[0]
    v2 = BC[0]*CP[1]-BC[1]*CP[0]
    v3 = CA[0]*AP[1]-CA[1]*AP[0]
    print(["NO", "YES"][(v1<0 and v2<0 and v3<0) or (v1>0 and v2>0 and v3>0)])




Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='1')cout<<'9';
    if(s[i]=='9')cout<<'1';
  }
  cout<<endl;
  return(0);
}


Measured memory_bytes: 256
module Main where

sumarray :: Int -> [Int] -> Int
sumarray h t = do
    let tempSum = map (*h) t
    sum tempSum

combSum :: [Int] -> Int
combSum xs
    | null xs = 0
    | otherwise = do
        let xsHead = head xs
        let xsTail = tail xs
        sumarray xsHead xsTail + combSum xsTail

main :: IO ()
main = do
    _ <- getLine
    d <- fmap read . words <$> getLine :: IO [Int]
    print $ combSum d

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n";

int main()
{
	string ch, bh;
	int coun = 0, coun2 = 0;
	cin >> ch;
	
	bh = ch;
	
	int len = ch.size();
	
	
	if(len == 1) 
	{
		cout << 0 << endl;
		return 0;
	}
	
	if(ch[0] == ch[1])
	{
		coun++;
		if(ch[0] == '0') ch[0] = '1';
		else ch[0] = '0';
	
		for(int i = 1; i < len; i++)
	{
		if(ch[i] == ch[i+1])
		{
			coun++;
			if(ch[i+1] == '0') ch[i+1] = '1';
			else ch[i+1] = '0';
		}
		}
		
		coun2++;
		if(bh[1] == '0') bh[1] = '1';
		else bh[1]= '0';
		
		for(int i = 1; i < len; i++)
	{
		if(bh[i] == bh[i+1])
		{
			coun2++;
			if(bh[i+1] == '0') bh[i+1] = '1';
			else bh[i+1] = '0';
		}
		}
		
		cout << min(coun,coun2) << "\n";
	
}
else
{
    for(int i = 1; i < len; i++)
	{
		if(ch[i] == ch[i+1])
		{
			coun++;
			if(ch[i+1] == '0') ch[i+1] = '1';
			else ch[i+1] = '0';
		}
		}
		
		cout << coun << "\n";	
}
	
	return 0;
}


Measured memory_bytes: 512
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
#define tl 1000000007
 
 
void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]%tl+v[k-1][j]%tl);
    }
  }
}
 
int main (){
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
    ll n,k;
	cin >> n >> k;
	vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
  	comb(v);
	rep(i,k){
		cout << (v[k-1][i]*v[n-k+1][i+1])%tl << endl; 
	}
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000007
#define MAX 100007

int main(){
    ll n;
    while(cin >> n){
        ll ans = LONG_LONG_MAX;
        for(int i = 1; i <= sqrt(n); i++){
            if(n%i == 0){
                ll b = n/i;
                ans = min( ans, b+i-2 );
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,q,i,j,cnt=0,re;
  
  scanf("%d",&n);
  int s[n];
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  int t[q];
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

  /*s[n],t[q]*/
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(s[j]==t[i]){
	cnt++;
	break;
      }
    }
  }

  printf("%d\n",cnt);
  return 0;
}



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

int main() {
  string str;
  cin >> str;
  if(str == "hi" || str == "hihi" || str == "hihihi" || str == "hihihihi" || str == "hihihihihi"){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> L){
    sort(L.begin(), L.end(), greater<long long>());
    long long sum = 0;
    for(long long i = 1; i < N; ++i){
        sum += L[i];
    }
    if(L[0] < sum) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	string n;
	cin >> n;
	for(int i=0; i<3; i++){
		if(n[i] == '1') n[i] = '9';
		else if(n[i] == '9') n[i] = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 764
import bisect
n=int(input())
seq=[]
for i in range(n):
    seq.append(int(input()))
seq.reverse()
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]

print(len(LIS))


Measured memory_bytes: 56152
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <deque>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int charN(char c) {
    return static_cast<int>(c) - static_cast<int>('a');
}
int main() {
    int N; cin >> N;
    long long A, B; cin >> A >> B;
    vector<long long> X(N); repp(i, 0, N) cin >> X[i];
    
    long long res = 0;
    repp(i, 1, N) res += min((X[i] - X[i-1]) * A, B);
    cout << res << endl;
}



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

    boolean[][] map;
    boolean[][] visit;
    int c;
    Stack<int[]> st;
    int[] dirX = { 1, 0, 0, -1 };
    int[] dirY = { 0, 1, -1, 0 };

    void run(){
	while(sc.hasNext()){
	    map = new boolean[12][12];
	    visit = new boolean[12][12];
	    for(int i=0; i<12; i++)
		makeMap(sc.next(), i);
	    //show();
	    c = 0;
	    solve();
	    System.out.println(c);
	}
    }

    void solve(){
	st = new Stack<int[]>();
	for(int i=0; i<12; i++)
	    for(int k=0; k<12; k++)
		if(map[i][k] && !visit[i][k]){
		    //System.out.println("------"+i+" "+k+"-----");
		    c++;
		    search(i, k);
		    //showM();
		}
    }

    void search(int y, int x){
	int[] p = new int[2];
	getGo(y, x);
	while(!st.empty()){
	    p = st.pop();
	    //System.out.println(p[1]+" "+p[0]);
	    if(!visit[p[0]][p[1]]) getGo(p[0], p[1]);
	}
    }

    void getGo(int y, int x){
	visit[y][x] = true;
	for(int i=0; i<4; i++){
	    int a = y+dirY[i];
	    int b = x+dirX[i];
	    if(a>=0 && a<12 && b>=0 && b<12 && map[a][b] && !visit[a][b]){
		//System.out.println("** "+x+" "+y+" / "+a+" "+b);
		int[] p = { a, b };
		st.push(p);
	    }
	}
    }

    void show(){
	for(int i=0; i<12; i++){
	    for(int k=0; k<12; k++)
		System.out.print(map[i][k] ? "■":"□");
	    System.out.println();
	}
    } 

    void showM(){
	for(int i=0; i<12; i++){
	    for(int k=0; k<12; k++)
		System.out.print(map[i][k] && visit[i][k] ? "■":"□");
	    System.out.println();
	}
    }

    void makeMap(String t, int i){
	for(int k=0; k<12; k++)
	    map[i][k] = t.substring(k, k+1).equals("1") ? true:false;
    }
}

Measured memory_bytes: 17216
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    string a;
    while (cin >> a)
    {

        int ans = 0;
        string b = "IVXLCDM";
        int c[] = {1, 5, 10, 50, 100, 500, 1000};
        int pre = 0;
        rep(i, a.size())
        {
            rep(j, b.size()) if (a[i] == b[j])
            {
                if (c[j] <= pre)
                {
                    ans += pre;
                    pre = c[j];
                }
                else
                {
                    ans -= pre;
                    pre = c[j];
                }
                break;
            }
        }
        ans += pre;
        cout << ans << endl;
        if (cin.eof())
        break;
    }
    return 0;
}

Measured memory_bytes: 3140
#include <stdio.h>

int main(void)          
{
	int a[10000];
	int n;
	int i;
	long long int MAX = -1000000, MIN = 1000000, sum = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);

		sum = sum + a[i];
		if (MAX < a[i]) MAX = a[i];
		if (MIN > a[i]) MIN = a[i];
	}
	
	printf("%lld %lld %lld\n", MIN, MAX, sum);

	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> f(N, false);
    vector<int> ball(N, 1);
    f[0] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        if (f[x]) f[y] = true;
        ball[x]--;
        ball[y]++;
        if (!ball[x]) f[x] = false;
    }
    int count = 0;
    for (auto i : f) if (i) count++;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<string.h>
#include<math.h>

using namespace std;



int main(){
    string in[12];
    while(cin>>in[0]){
        for(int i=1; i<12; i++){
            cin>>in[i];
        }
        int count = 0;
        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(in[i][j]=='1'){
                    count++;
                    pair<int, int> now;
                    now.first = i; now.second = j;
                    queue<pair<int, int> > qu;
                    qu.push(now);
                    in[now.first][now.second]='0';
                    while(!qu.empty()){
                        pair<int, int> top;
                        top = qu.front();
                        qu.pop();
                        if(top.first+1<12&&in[top.first+1][top.second]=='1'){
                            now.first=top.first+1;
                            now.second=top.second;
                            qu.push(now);
                            in[now.first][now.second]='0';
                        }
                        if(top.second+1<12&&in[top.first][top.second+1]=='1'){
                            now.first=top.first;
                            now.second=top.second+1;
                            qu.push(now);
                            in[now.first][now.second]='0';
                        }
                        if(top.first-1>=0&&in[top.first-1][top.second]=='1'){
                            now.first=top.first-1;
                            now.second=top.second;
                            qu.push(now);
                            in[now.first][now.second]='0';
                        }
                        if(top.second-1>=0&&in[top.first][top.second-1]=='1'){
                            now.first=top.first;
                            now.second=top.second-1;
                            qu.push(now);
                            in[now.first][now.second]='0';
                        }
                    }
                }
                
            }
        }
        cout<<count<<endl;
        
//        for(int i=0; i<12; i++){
//            cout<<in[i]<<endl;
//        }

    }
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int h, w, k;
  cin >> h >> w >> k;

  vector<vector<ll> > dp(h+1, vector<ll>(w));
  dp[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < (1 << (w-1)); j++) {
      int m = j;
      int p = 0;
      vector<int> next(w);
      for (int l = 0; l < w; l++) next[l] = l;
      bool good = true;
      while (m > 0) {
        if ((m & 3) == 3) {
          good = false;
          break;
        }
        else if (m & 1) {
          swap(next[p], next[p+1]);
        }
        p++;
        m >>= 1;
      }
      if (!good) continue;
      for (int l = 0; l < w; l++) {
        dp[i+1][next[l]] = (dp[i+1][next[l]] + dp[i][l]) % mod;
      }
    }
  }

  cout << dp[h][k-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

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

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

/*
void solve(void){
    ll n,m;
    cin >> n >> m;
    vector<ll> x(m);
    rep(i,0,m) cin >> x[i];
    sort(x.begin(),x.end());
    vector<ll> l(n-1); 
    rep(i,0,n-1) l[i] = x[i]-x[i+1];
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    rep()
    ll ans = 0;
}
*/
void solve(void){
    ll a,b,c;
    cin >> a >> b >> c;
    cout << (a*b)/2<<endl;
}

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

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long int ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
string vertex[45];
int m[45];
int power[45];
string adj[45][45];

ull graph[45];

int dfs(int cur,ull used){
	if(cur==n) return 0;
	if(used>>cur&1) return dfs(cur+1,used);

	int res=0;
	ull nused=used|(1LL<<cur);

	if(__builtin_popcountll((~used)&(graph[cur]))<=1){
		res=power[cur]+dfs(cur+1,nused|graph[cur]);
	}else{
		res=dfs(cur+1,nused);
		res=max(res,power[cur]+dfs(cur+1,nused|graph[cur]));
	}
	return res;
}

int main(void){
	while(cin >> n,n){
		rep(i,n){
			cin >> vertex[i] >> power[i];
			cin >> m[i];
			rep(j,m[i]) cin >> adj[i][j];
		}
		for(int i=1;i<n;++i){
			for(int j=i+1;j<n;++j){
				if(power[i]<power[j]){
					swap(vertex[i],vertex[j]);
					swap(power[i],power[j]);
					swap(m[i],m[j]);
					rep(k,45) swap(adj[i][k],adj[j][k]);
				}
			}
		}
		rep(i,n){
			graph[i]=0LL;
			rep(j,m[i])rep(k,n)
				if(adj[i][j]==vertex[k])
					graph[i]|=(1LL<<k);
		}
		cout << power[0]+dfs(1,graph[0]|1LL) << endl;
	}
	return 0;
}

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

int main(){
    ll x,y,z,N;
    cin >> x >> y >> z >> N;
    vector<ll> a(x),b(y),c(z);
    vector<ll> ab,ans;
    rep(i,x){cin >> a[i];}
    rep(i,y){cin >> b[i];}
    rep(i,z){cin >> c[i];}

    rep(i,x){
        rep(j,y){
            ab.push_back(a[i]+b[j]);
        }
    }
    sort(ab.begin(),ab.end(),greater<ll>());
    rep(i,min(N,x*y)){
        rep(j,z){
            ans.push_back(ab[i]+c[j]);
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());

    rep(i,N)cout << ans[i] << endl;
}

Measured memory_bytes: 43368
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#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) = (n); (i) >= (m); i--)
#define rep(...) _overload3(__VA_ARGS__, FOR, REP, )(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, FORR, REPR, )(__VA_ARGS__)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, A, B;
  cin >> N >> A >> B;

  cout << min(A * N, B) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;


int main()
{
    int n;
    cin >> n;
    string q;
    cin >> q;
    char prev = q[0];
    int total = 1;
    for (int w = 1; w < n; w++)
    {
        if (q[w]!=prev)
        {
            total++;
        }
        prev = q[w];
    }
    cout << total;
    return 0;
}


Measured memory_bytes: 512
N, K = map(int, input().split())
list_A = [int(x) for x in input().split()]

list_num = [0 for i in range(N+1)]
for i in range(N) :
    list_num[list_A[i]] += 1

list_num.sort(reverse = True)

ans = N
for i in range(K) :
    ans -= list_num[i]

if ans > 0 :
    print(ans)
else :
    print(0)


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

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#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;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    if(n % 2 == 1) {
        cout << "No" << endl;
        return;
    } else {
        for(int i = 0; i < n; i += 2){
            if(s[i] != 'h' || s[i + 1] != 'i') {
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
N = input().strip()
N = N + "."  # for removing the leading zeroes just in case
N.strip("0")
N = N[:-1]
total = 0
for i in range(1, len(N), 2):
    total += int("1"+"0"*i) - int("1"+"0"*(i-1))
if len(N) % 2 == 0:
    total += 0
else:
    total += int(N) - (int("1" + "0" * (len(N) - 1))) + 1
print(total)

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

int keisan(int x) {
  int ret_val=0;
  rep_eq(i,1,x) {
    ret_val+=i;
  }
  return ret_val;
}

int main(){
  int a,b; cin >>a >>b;
  int ans=keisan(b-a)-b;
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
from operator import itemgetter
import math
import copy
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(x):
    if visited[x] == False:
        visited[x] = True
        path.append(x)
        if x == N:
            return True
        for i in root[x]:
            if tami(i):
                return True
        else:
            del path[-1]
    return False

def nas(x):
    global cnt
    if (visited[x] == False) and (data[x] == 0):
        visited[x] = True
        cnt += 1
        for i in root[x]:
            nas(i)

N = I()
ab = [IL() for i in range(N-1)]
data = np.array([0]*(N+1))
root = [[]*(N+1) for i in range(N+1)]
visited = [False]*(N+1)

path = []
f = 0
for a,b in ab:
    root[a].append(b)
    root[b].append(a)

tami(1)
middle_No = path[math.ceil(len(path)/2)-1]
data[middle_No] = 1

visited = [False]*(N+1)
cnt = 0
nas(N)

Snuke = cnt
Fennec = N - Snuke

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 128680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t = sc.next();
			int a = sc.nextInt();
			int b = sc.nextInt();
			String u = sc.next();
			if(s.equals(u)) {
				System.out.print(a - 1);
				System.out.print(" ");
				System.out.print(b);
			} else {
				System.out.print(a);
				System.out.print(" ");
				System.out.print(b - 1);
			}
		}

	}

}


Measured memory_bytes: 22996
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,sse4,avx,avx2")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

vector<PLL> t;

void update(int v, int vl, int vr, int pos, PLL val)
{
    if (vl == vr)
    {
        t[v].F = min(val.F, t[v].F);
        t[v].S = min(val.S, t[v].S);
        return;
    }
    int mid = (vl + vr) >> 1;
    if (pos <= mid)
    {
        update(v + v, vl, mid, pos, val);
    }
    else
    {
        update(v + v + 1, mid + 1, vr, pos, val);
    }
    t[v].F = min(t[v + v].F, t[v + v + 1].F);
    t[v].S = min(t[v + v].S, t[v + v + 1].S);
}

const LL LINF = 1e18 + 7;

PLL get(int v, int vl, int vr, int l, int r)
{
    if (vl > r || l > vr)
    {
        return MP(LINF, LINF);
    }
    if (vl >= l && vr <= r)
    {
        return t[v];
    }
    int mid = (vl + vr) >> 1;
    auto p = get(v + v, vl, mid, l, r);
    auto q = get(v + v + 1, mid + 1, vr, l, r);
    return MP(min(p.F, q.F), min(p.S, q.S));
}

int main()
{       
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<PII> vec(n);
    VI igryk;
    for (auto &[x, y] : vec)
    {
        cin >> x >> y;
        igryk.PB(y);
    }

    sort(ALL(vec));
    sort(ALL(igryk));
    igryk.erase(unique(ALL(igryk)), igryk.end());

    t.assign(4 * n + 47, MP(LINF, LINF));
    LL ans = 0;
    for (int i = 0; i < n; ++i)
    {
        auto [x, y] = vec[i];
        int pos = lower_bound(ALL(igryk), y) - igryk.begin();
        update(1, 0, n - 1, pos, MP(x + y, x - y));
        LL g = get(1, 0, n - 1, 0, pos).F;
        LL h = get(1, 0, n - 1, pos, n - 1).S;
        if (g != LINF)
        ans = max(ans, abs((LL)x + y - g));
        if (h != LINF)
        ans = max(ans, abs((LL)x - y - h));
    }

    cout << ans << "\n";

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)

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

  string S[N]; int T[N];
  rep(i, N) cin >> S[i] >> T[i];
  string X; cin >> X;

  int sum = 0;
  rrep(i, N-1) {
    if (S[i] == X) {
      cout << sum << endl;
      return 0;
    }
    sum += T[i];
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;
const lint INF = mod * mod;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int x[n], cntx[100010];
    rep(i, 100010) cntx[i] = 0;
    rep(i, n){
        scanf("%d", &x[i]);
        ++cntx[x[i]];
    }

    int num[m][2];
    rep(i, m)rep(j, 2) num[i][j] = 0;
    rep(i, 100010)if(cntx[i]){
        int t = i % m;
        if(cntx[i] % 2) ++num[t][1];
        num[t][0] += cntx[i]/2*2;
    }

    int ans = 0;
    for(int i=0; i*2<=m; ++i) {
        if (i == 0 || i * 2 == m) {
            ans += (num[i][0] + num[i][1]) / 2;
            continue;
        }
        int s = i, t = m-s;
        int nums = num[s][0] + num[s][1], numt = num[t][0] + num[t][1];
        if(nums < numt) swap(s, t), swap(nums, numt);
        ans += numt;
        if(num[s][1] < numt){
            numt -= num[s][1];
            num[s][0] -= numt;
        }
        ans += num[s][0] / 2;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

    int N; cin >> N;
    int a;
    vector<int> A; REP(i, N) {cin >> a; A.push_back(a);}
    vector<int> sorted = A;
    RSORT(sorted);
    int max1 = sorted[0];
    int max2 = sorted[1];
    REP(i, N) {
        if (A[i] == max1) cout << max2 << '\n';
        else cout << max1 << '\n';
    }

    return 0;
}



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

void A(int i,int j,int k){
	printf("+ %d %d %d\n",i,j,k);
}
void C(int i,int j,int k){
	printf("< %d %d %d\n",i,j,k);
}

int main(){
	puts("19874");
	C(4,0,4);
	A(0,4,0);
	A(1,4,1);
	for(int t=0;t<=30;t++){
		C(70,3,70);
		A(70,4,70);
		for(int i=0;i<30;i++)
			A(70+i,70+i,70+i+1);
		for(int i=0;i<=30;i++)
			A(70+i,37,70+i),C(70+i,0,70+i);
		for(int i=0;i<=30;i++)
			C(70+i+1,70+i,70+i),A(6+i,70+i,6+i);
		C(37,3,37);
		for(int i=30;i>=0;i--)
			A(37,37,37),A(37,6+i,37); 
	}
	for(int t=0;t<=30;t++){
		C(70,3,70);
		A(70,4,70);
		for(int i=0;i<30;i++)
			A(70+i,70+i,70+i+1);
		for(int i=0;i<=30;i++)
			A(70+i,69,70+i),C(70+i,1,70+i);
		for(int i=0;i<=30;i++)
			C(70+i+1,70+i,70+i),A(38+i,70+i,38+i);
		C(69,3,69);
		for(int i=30;i>=0;i--)
			A(69,69,69),A(69,38+i,69);
	}
	for(int i=30;i>=0;i--){
		for(int j=0;j<=30;j++)
			C(70+j,3,70+j),A(70+j,6+j,70+j),C(70+j,38+i,70+j),C(70+j,38+i,70+j);
		C(5,3,5);
		for(int j=30;j>=0;j--)
			A(5,5,5),A(5,70+j,5);
		for(int j=0;j<i;j++)
			A(5,5,5);
		A(2,5,2);
	}
	return 0;
}

Measured memory_bytes: 3728
#include <stdio.h>
#include <float.h>

int main()
{
    long int i;
    long int n, k;
    long int min, max;
    long int sum = 0;
    scanf("%ld %ld", &n, &k);

    for(i=k; i<=(n+1); i++)
    {
        min = (i-1)*i/2;
        max = n*(n+1)/2 - (n-i)*(n+1-i)/2;
//        printf("min=%ld, max=%ld\n", min, max);
//        printf("i=%ld, add=%ld\n", i, (max-min+1));
        sum += (max - min + 1);
    };
    printf("%ld\n", sum%1000000007);

    return 0;
}


// 1からnまでの和 = n*(n+1)/2
// min: 20000100000
// max: 


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
    
typedef long long ll;
typedef unsigned long long ull;
    
#define MOD 1000000007
#define mi 18446744073709551615

int main()
{
    ll n,k,i,w;
    cin>>n>>k;
    ll wt[n],val[n];
    for(int i=0;i<n;i++)
        cin>>wt[i]>>val[i]; 
    ll kp[n+1][k+1];   
    for(i=0;i<=n;i++)
    {
        for(w=0;w<=k;w++)
        {
            if(i==0||w==0)
                kp[i][w]=0;
            else if(wt[i-1]<=w)
            {
                kp[i][w]=max(val[i-1]+kp[i-1][w-wt[i-1]],kp[i-1][w]);
            }    
            else 
                kp[i][w]=kp[i-1][w];
        }
    }
    cout<<kp[n][k];
    return 0;
}

Measured memory_bytes: 79104
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP(i, 1, n+1)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

vector<int> A(2e5+1),B(2e5+1),result(2e5+1),length(2e5+1);
vector<bool> ok(2e5+1, false);
unordered_map<int, vector<int>> mp;
queue<int> q;

void bfs(){
    // 今いる部屋
    while(q.size() != 0){
        int r = q.front();q.pop();
        // 今いる部屋につながっている部屋たち
        rep(i, mp[r].size()){
            if (ok[mp[r][i]] == false) {
                ok[mp[r][i]] = true;
                length[mp[r][i]] = length[r]+1;
                q.push(mp[r][i]);
                result[mp[r][i]] = r;
            }
        }
    }
}

int main() {
    int N,M;
    cin>>N>>M;
    rep2(i,M){cin>>A[i]>>B[i];}
    rep2(i,M){
        mp[A[i]].push_back(B[i]);
        mp[B[i]].push_back(A[i]);
    }
    result[1]=1;
    length[1]=0;
    q.push(1);
    bfs();
    
    //printv(length);
    rep2(i,N){
        if(result[i] == -1){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    rep2(i,N){
        if(i==1) continue;
        cout<<result[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 16332
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int m=(int)1e7+1;
void go()
{
    long long int n;
    cin>>n;
    vector<long long int> arr(n+1,0);
    for(int i=2;i<=n;i++)
    {
        //cout<<i<<" ";
        for(int j=i;j<=n;j+=i)
            arr[j]++;
    }
    long long int ans=0;
    for(int i=1;i<=n;i++)
        ans+=((arr[i]+1)*(i));//,cout<<arr[i]<<endl;
    cout<<ans<<endl;
}
int main()
{
    //FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}




Measured memory_bytes: 81400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

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



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

    double ans=r*2*3.1415927;

    cout<<ans<<endl;
	

	
	
	
	return 0;
}

Measured memory_bytes: 3728
#include <stdio.h>

int main()
{
	int A,B,C,D,E,f,g;
	scanf("%d%d%d%d", &A, &B,&C,&D);
	f = A + B;
	g = C + D;
	if(f>g) {
		printf("Left\n");
	}
	else if(f==g)
		printf("Balanced\n");
	else if(f<g)
		printf("Right\n");
	return 0;
}


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

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

}


Measured memory_bytes: 256