akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}  
int D;
vector<int> c(26);
vector<vector<int>> s;
struct State {
  int ans = 0;
  vector<int> t;
  vector<int> sscore;
  vector<vector<int>> cscore;
};
void score(State &st, set<int> idx, int firstday) {
  vector<int> last(26);
  REP(i, D) {
    last[st.t[i]] = i + 1;
    if(i < firstday) continue;
    st.ans += s[i][st.t[i]] - st.sscore[i];
    st.sscore[i] = s[i][st.t[i]];
    
    bool flg = false;
    for(int j : idx) {
      if(st.cscore[i][j] != c[j] * (i + 1 - last[j])) {
        st.ans -= (c[j] * (i + 1 - last[j]) - st.cscore[i][j]);
        st.cscore[i][j] = c[j] * (i + 1 - last[j]);
        flg = true;
      }
    }
    if(!flg) break;
  }
}
double TIME_LIMIT = 1980;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> D;
  REP(i, 26) cin >> c[i];
  s = vector<vector<int>>(D, vector<int>(26));
  REP(i, D) REP(j, 26) cin >> s[i][j];

  State st;
  vector<int> t(D);
  REP(i, D) t[i] = i%26;
  st.t = t;
  vector<int> sscore(D);
  st.sscore = sscore;
  vector<vector<int>> cscore(D, vector<int>(26));
  st.cscore = cscore;
  set<int> idxset;
  REP(i, 26) idxset.insert(i);
  score(st, idxset, 0);
  
  clock_t start_time = clock();
  int loop = 0;
  double start_temp = 5000, end_temp = 1;
  double time = 0;
  while(true) {
    loop++;
    clock_t now_time = clock();
    time = static_cast<double>(now_time - start_time) / CLOCKS_PER_SEC * 1000.0;
    if(time > TIME_LIMIT) break;
    
    int mode = rand() % 2;
    int tmpidx, tmptype;
    idxset.clear();
    int lastans = st.ans;
    if(mode == 0) {
      int idx = rand() % D;
      int type = rand() % 26;
      tmpidx = idx;
      tmptype = st.t[idx];
      st.t[idx] = type;
      idxset.insert(type);
      idxset.insert(tmptype);
    } else {
      int idx = rand() % (D-1);
      swap(st.t[idx], st.t[idx+1]);
      tmpidx = idx;
      idxset.insert(st.t[idx]);
      idxset.insert(st.t[idx+1]);
    }
    score(st, idxset, tmpidx);
    double temp = start_temp + (end_temp - start_temp) * time / TIME_LIMIT;
    double prob = exp((st.ans-lastans)/temp);
    if(st.ans > lastans || prob > (rand()%INF)/(double)INF) {
      ;
    } else {
      if(mode == 0) {
        st.t[tmpidx] = tmptype;
      } else {
        swap(st.t[tmpidx], st.t[tmpidx+1]);
      }
      score(st, idxset, tmpidx);
    }
    //cout << st.ans << "\n";
    //if(next < now) cout << prob << "\n";
  }
  REP(i, D) cout << (st.t[i]+1) << "\n";
  //cout << st.ans << "\n";
  //cout << loop << "\n";
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(N);
  
  int A,B;
  for(int i=0;i<M;i++){
    cin >> A >> B;
    vec.at(A-1)++;
    vec.at(B-1)++;
  }
  
  for (int i=0; i<N;i++)
  	cout << vec.at(i)<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

string A;

int main() {
    cin >> A;
    long long alen = A.length();

    long long ans = alen*(alen-1) / 2;
    map<char, long long> mcnt;
    for(int i = 0; i < alen; ++i) {
        mcnt[A.at(i)]++;
    }

    long long subcnt = 0;
    for(auto x : mcnt) {
        long long cc = x.second;
        subcnt += (cc*(cc-1)) / 2;
    }

    cout << ans-subcnt+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int M,N;
cin >> M >> N;

cout << (M*(M-1))/2 + (N*(N-1))/2 << endl;

return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{   
    ll N, K; 
    cin >> N >> K;
    string S;
    cin >> S;
    S[K-1] -= 'A'-'a';
    cout<<S<<endl;

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);
    vector<int> a(n);
    for (auto&e:a) scanf("%d",&e);
    sort(a.begin(),a.end());
    long long t=accumulate(a.begin(),a.end(),0ll);
    if (n==0) printf("0 0 0\n");
    else printf("%d %d %lld\n",a[0],a[n-1],t);
    return 0;
}



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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) FOR(i,0,a)
#define RREP(i,a) RFOR(i,a,0)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) sort(ALL(a))

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int,int> PII;

std::string S;

int main() {
    std::cin >> S;
    char p = 0;
    int section = 0;
    EACH(c, S) {
        if(*c != p) {
            p = *c;
            section++;
        }
    }
    std::cout << (section - 1) << std::endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


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);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(i % 2 == 0 && a % 2 == 1) ans++;
    }
    cout << ans;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3648
from collections import defaultdict
import bisect


def divisor(n):  # nの約数を全て求める
    i = 1
    div_set = set()
    while i * i <= n:
        if n % i == 0:
            div_set.add(i)
            div_set.add(n//i)
        i += 1
    return div_set


def divisor2(n):  # 既存のリストからnの約数だけを返す
    div_set = set()

    for i in kouho:
        if i > n:
            return div_set
        if n % i == 0:
            div_set.add(i)
    return div_set


N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()
max_index = bisect.bisect_left(A_list, A_list[-1])
# print(max_index)
times = max_index

divcount = defaultdict(int)
for n in A_list[:2]:
    # print(n)
    for i in divisor(n):
        divcount[i] += 1

kouho = list(divcount.keys())
kouho.sort()
# print(kouho)

for n in A_list[2:max_index+1]:
    # print(n)
    for i in divisor2(n):
        divcount[i] += 1

# print(divcount)
max_divisor = 0
for key, value in divcount.items():
    if value >= max_index and key > max_divisor:
        max_divisor = key

print(max_divisor)


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

using ll = long long;
using namespace std;

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

template<typename T>
bool is_prime(T x) {
	for(int i = 2; i * i <= x; ++i) {
		if( x % i == 0 ) return false;
	}
	
	return true;
}

int main(void) {
	int x;
	cin >> x;
	
	int ans = 0;
	for(int i = x; i <= 1e5 + 10; ++i) {
		if( is_prime(i) ) { 
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
n,m=gets.chomp.split(" ").map(&:to_i)
a,b=[],[]
n.times do|i|
  a[i],b[i]=gets.chomp.split(" ").map(&:to_i)
end
c,d=[],[]
m.times do|i|
  c[i],d[i]=gets.chomp.split(" ").map(&:to_i)
end
n.times do|i|
  min=999999999
  idx=0
  m.times do|j|
    if min>((a[i]-c[j]).abs+(b[i]-d[j]).abs)
      min=(a[i]-c[j]).abs+(b[i]-d[j]).abs
      idx=j
    end
  end
  puts idx+1
end


Measured memory_bytes: 1788
import pprint
n,w=map(int,input().split())
V=[]
W=[]
for _ in range(n):
    x,y=map(int,input().split())
    V.append(x)
    W.append(y)
dp=[[0]*(w+1) for _ in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if W[i]>j:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-W[i]]+V[i])

# pprint.pprint(dp)
print(dp[n][w])


Measured memory_bytes: 26272
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m,x,y;
  cin>>n>>m>>x>>y;
  vector<long long int> hoge(n);
  for(long long int i=0; i<n; i++){
    cin>>hoge.at(i);
  }
  vector<long long int> huga(m);
  for(long long int i=0; i<m; i++){
    cin>>huga.at(i);
  }
  sort(hoge.begin(),hoge.end());
  sort(huga.begin(),huga.end());
  long long int rightx=hoge.at(n-1);
  long long int lefty=huga.at(0);
  if(rightx<lefty&&rightx<y&&x<lefty){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
    ll k,a,b;
    cin>>k>>a>>b;
    if(b<=a){
    cout<<(k+1);}
    else
    {
        ll ans=0;
        if(k<(a+1))
        cout<<(k+1);
        else
        {
            if(b-a>1)
            {
                ans = b;
                k=k-(a+1);
                ll p = k/2;
                ll r = k%2;
                ans = ans + p*(b-a) + r;
                cout<<ans;
            }
            else if((b-a) == 1)
            {
                cout<<(k+1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._800problems
{
    class ARC059_E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long[] nc = ReadLongs();
            long n = nc[0];
            long c = nc[1];
            long[] aArray = ReadLongs();
            long[] bArray = ReadLongs();
            long mask = 1000000000 + 7;
            long[,] sums = new long[c+1, 401];
            for (int i = 0; i <= 400; i++) sums[0, i] = 1;
            for (int i = 1; i <= c; i++)
            {
                for (long j = 0; j <= 400; j++)
                {
                    sums[i, j] = j;
                    if (i > 0) sums[i, j] *= sums[i-1, j];
                    sums[i, j] %= mask;
                }
            }
            for(int i = 0; i <= c; i++)
            {
                for(long j = 1; j <= 400; j++)
                {
                    sums[i, j] += sums[i, j - 1];
                    sums[i, j] %= mask;
                }
            }

            long[,] dp = new long[n+1, c + 1];
            dp[0, 0] = 1;
            for (int i = 0; i < n; i++)
            {
                for(long j = 0; j <= c; j++)
                {
                    long sum = sums[j, bArray[i]] - sums[j, aArray[i]-1];
                    if (sum < 0) sum += mask;

                    for(long k = 0; j + k <= c; k++)
                    {
                        dp[i + 1, j + k] += dp[i, k] * sum;
                        dp[i + 1, j + k] %= mask;
                    }
                }
            }
            WriteLine(dp[n, c]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13408
#include <cstdio>
#include <cstring>
#include <vector>
#include <limits>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()
#define clr(a,v) memset((a),(v),sizeof(a))

using ll = long long;

constexpr int MAX_N = 100010;
constexpr ll INF = std::numeric_limits<ll>::max()>>2;

ll N, K;
std::vector<ll> G[MAX_N];
ll L[MAX_N], R[MAX_N], A[MAX_N];
bool used[MAX_N];
bool fl = true;

bool dfs( int v, int prv )
{
  used[v] = true;

  //printf( "(%d,%d)\n", v, prv );

  for( auto &u : G[v] ) if( !used[u] )
  {
    /*if( R[u] < L[v]-1 || R[v]+1 < L[u] )
    { fl = false; return false; }

    L[u] = std::max( L[u], L[v]-1 );
    R[u] = std::min( R[u], R[v]+1 );*/

    if( !dfs( u, v ) )
      return false;
  }

  if( R[prv] < L[v]-1 || R[v]+1 < L[prv] )
  { fl = false; return false; }

  L[prv] = std::max( L[prv], L[v]-1 );
  R[prv] = std::min( R[prv], R[v]+1 );

  return true;
}

void calc( int v, int prv )
{
  used[v] = true;

  //printf( "{%d}\n", v+1 );

  if( v == prv )
    A[v] = L[v];
  else if( L[v] <= A[prv]+1 && A[prv]+1 <= R[v] )
    A[v] = A[prv]+1;
  else if( L[v] <= A[prv]-1 && A[prv]-1 <= R[v] )
    A[v] = A[prv]-1;
  else
    fl = false;

  for( auto &u : G[v] ) if( !used[u] )
    calc( u, v );

  return;
}

int main()
{
  scanf( "%lld", &N );
  rep( i, N-1 )
  {
    ll a, b;
    scanf( "%lld%lld", &a, &b );
    --a; --b;
    G[a].emplace_back( b );
    G[b].emplace_back( a );
  }

  scanf( "%lld", &K );

  std::fill( L, L+N, -INF );
  std::fill( R, R+N, INF );

  rep( i, K )
  {
    ll V, P;
    scanf( "%lld%lld", &V, &P );
    --V;
    L[V] = R[V] = A[V] = P;
  }

  clr( used, false );

  dfs( 0, 0 );

  //rep( i, N )
    //printf( "[%d] [%d,%d]", i+1, L[i], R[i] );

  //puts( fl ? "[Yes]" : "[No]" );

  clr( used, false );

  calc( 0, 0 );

  //rep( i, N )
    //printf( "[%d] %lld\n", i+1, A[i] );

  if( !fl )
  {
    puts("No");

    return 0;
  }


  puts("Yes");

  rep( i, N )
    printf( "%lld\n", A[i] );
  
  return 0;
}

Measured memory_bytes: 13568
main = do
  n_m <- readLn :: IO Int
  loop n_m 0

loop :: Int -> Int -> IO ()
loop n_max n | xn > n_max = putStrLn ":("
             | xn == n_max = print n
             | xn < n_max = loop n_max (n+1)
  where xn = (n*108)`div`100 

Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inS = Console.ReadLine().Split(' ');
            int R = int.Parse(inS[0]);
            int G = int.Parse(inS[1]);
            int B = int.Parse(inS[2]);
            int N = int.Parse(inS[3]);

            int result = 0;

            for (int r = 0; r <= N; r += R)
            {
                for(int g = 0; r + g <= N; g+= G)
                {
                    int remain = N - r - g;

                    if ( remain % B == 0 )
                    {
                        result++;
                    }
                }
            }

            Console.WriteLine("{0}", result);
        }
    }
}


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

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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() {
    ll H;
    cin >> H;


ll monsters=1;
ll res = 0;
while (monsters>=0) {
    res += monsters;
    if (H == 1) {
        break;
    } else {
        monsters *= 2;
        H *=0.5;
    }
}
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
#include <iostream>

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int32_t sheep, wolf;
  std::cin >> sheep >> wolf;
  std::cout << ((wolf >= sheep) ? "unsafe" : "safe") << std::endl;
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
	int n=0;
	int m=0;
	int i=0;
	int j=0;
	int s=1;
	int a[1000];
	int b[1000];
	while(cin>>n && cin>>m && n!=0 && m!=0){
		s=1;
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<m;i++){
			cin>>b[i];
		}
		for(i=0;i<m;i++){
			s=s+b[i];
			s=s+a[s-1];
			if(s>=n){
				j=i+1;
				i=m-1;
			}
		}
		cout<<j<<endl;
	}
}

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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 int n;
 float d;
 cin>>n>>d;
 int ans=0;
 for(int i=0;i<n;i++){
  ll x,y;
  cin>>x>>y;
  long double dist=sqrt((x*x)+(y*y));
  if(dist<=d)
   ans++;
 }
 cout<<ans<<"\n";
 return 0;
}


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

using namespace std;
int main() {
	int n; cin>>n;
	vector<int>vd(n);
	vector<int>vv(n);
	vector<int>vc(n);
	for(int i=0; i<n; ++i) { cin>>vv[i]; }
	for(int i=0; i<n; ++i) { cin>>vc[i]; }
	for(int i=0; i<n; ++i) { vd[i]=vv[i]-vc[i]; }
	sort(vd.begin(), vd.end());

	int ans=0;
	for(int i=n-1; i>=0; --i) {
		if(vd[i]>0)ans+=vd[i];
		else break;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		m[s]++
	}

	if len(m) == 3 {
		fmt.Println("Three")
	} else {
		fmt.Println("Four")
	}
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

void solve() {
  ll n, x;
  cin >> n >> x;
  cout << 3 * (n - __gcd(n, x)) << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int MAX = 10000;

int main () {
  int count, n, q, A[MAX], Q[500];

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

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

  count = 0;

  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (A[j] == Q[i]) {
        count++;
        break;
      }
    }
  }

  printf("%d\n", count);

}

Measured memory_bytes: 3184
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = (ll)(1LL << 31) - 1;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}

int main() {
	int s;
	cin >> n >> s;
	hei(int)a(n);
	rep(i, 0, n)cin >> a[i];
	whei(llint) dp(n + 1, hei(llint)(s + 1, 0));
	dp[0][0] = 1;
	rep(i, 0, n) {
		rep(j, 0, s + 1) {
			if (j >= a[i])dp[i + 1][j] += dp[i][j - a[i]]% 998244353;
			dp[i + 1][j] += dp[i][j] * 2 % 998244353;
			dp[i + 1][j] %= 998244353;
		}
	}
	cout << dp[n][s] << endl;
	return 0;
}

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

public class Main {
  private static long solve(int n) {
    long l0 = 2;
    long l1 = 1;
    for (int i = 2; i <= n; i++) {
      long l2 = l1 + l0;
      l0 = l1;
      l1 = l2;
    }
    return l1;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

using namespace std;

int main(){
	float n, t, a, min, min_h;
	float h[1000];
	cin >> n;
	cin >> t >> a;
	for(int i = 0; i < n; i++){
		cin >> h[i];
		if(i == 0) {
			min = i; 
			min_h = abs((t - h[i] * 0.006) - a);
		}
		if(abs((t - h[i] * 0.006) - a) < min_h) {
			min = i;
			min_h = abs((t - h[i] * 0.006) - a);
		}
	}
	cout << min + 1;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NMAX 2000000
#define VMAX 10000

int main(){
    unsigned short *A, *B;
    int C[VMAX+1];
    int n, i, j;

    scanf("%d", &n);

    A = malloc(sizeof(short)*n+1);
    B = malloc(sizeof(short)*n+1);

    //initialize the count table
    for(i = 0; i<=VMAX; i++) C[i] = 0;
    //input
    for(i = 0; i<n; i++) scanf("%hd", &A[i]);
    //making frequency table
    for(i = 0; i<n; i++) C[A[i]]++;
    //making scheme 
    for(i = 1; i<=VMAX; i++) C[i] += C[i-1];
    //sort
    for(i = n-1; i>=0; i--){
	B[C[A[i]]] = A[i];
	C[A[i]]--;
    }
    //print
    for(i = 1; i<n+1; i++){
	printf("%d", B[i]);
	if(i < n) printf(" ");
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 9572
//@author yash
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	fast();
	int n;
	cin>>n;
	int arr[n];
	int mini=INT_MAX;
	int maxi=INT_MIN;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		mini=min(mini,arr[i]);
		maxi=max(maxi,arr[i]);
	}
	int x=(mini+maxi)/2;
	ll ans=10000000000;
	for(int j=mini;j<=maxi;j++)
	{
	ll s=0;
	for(int i=0;i<n;i++)
	{
		s=s+(arr[i]-j)*(arr[i]-j);
	}
	ans=min(ans,s);
}
	cout<<ans<<endl;	
}



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

int main()
{
  string A,B,AA,BB;
  int a,b,i,ans;
  cin>>a>>b;
  
  A=to_string(a);
  B=to_string(b);
  AA="\0";
  BB="\0";
 // cout<<A<<" "<<B<<"\n";
  for(i=0;i<a;i++) BB+=B;
  for(i=0;i<b;i++) AA+=A;
  
  a=stoi(AA);
  b=stoi(BB);
  ans=max(a,b);
  cout<<ans;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(Math.abs(a-c) <= d)
			System.out.println("Yes");
		else if((Math.abs(b-c)<=d && Math.abs(b-a) <= d))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

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

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

vector<int> v[101];
vector<int> dist;
queue<int> q;

int bfs() {
    dist[1] = 0;
    q.push(1);

    while (!q.empty()) {
        int c = q.front();
        q.pop();
        for (int i = 0; i < v[c].size(); i++) {
            if (dist[v[c][i]] == -1) {
                dist[v[c][i]] = dist[c] + 1;
                q.push(v[c][i]);
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    dist.resize(n + 1, -1);

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            v[u].push_back(a);
        }
    }

    bfs();

    for (int i = 1; i <= n; i++) {
        cout << i << " " << dist[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<string.h>
int main()
{
    int i,d;
    char S[7];
    scanf("%s",S);
    char a[3][7]={"Sunny","Cloudy","Rainy"};
    for(i=0;i<3;i++)
    {
        if(strcmp(S,a[i])==0)
        {
            d=i;
            break;
        }

    }
    if(d==2)
        printf("%s",a[0]);
    else
        printf("%s",a[d+1]);
        return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int multiply1 = sc.nextInt();
          int multiply2 = sc.nextInt();
          int sum = multiply1 * multiply2;
          if(sum % 2 == 0) {
            System.out.println("Even");
          } else {
            System.out.println("Odd");
          }
          }
  }

Measured memory_bytes: 21332
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long

long long min(long long a, long long b){
    if(a < b) return a;
    else return b;
}

int compare(const void *a, const void *b){
  return (*(ll int *)a)- (*(ll int *)b);
} 

int main(){
  int n,k;
  scanf("%d %d",&n,&k);
  ll int s[n],ans=1000000001;
  for(ll int i=0;i<n;i++) scanf("%lld",&s[i]);
  qsort(s,n,sizeof(ll int),compare);
  for(int i=0;i<=n-k;i++){
    if(ans>s[i+k-1]-s[i]){
      ans=s[i+k-1]-s[i];
    }
  }
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 1788
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

// void dfs(vv tree, int v, vector<bool> seen){
    
// }

int main(){
    int N, M;
    cin >> N >> M;
    vv tree(N);
    for(int i = 0; i < M ; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<bool> seen(N, false);
    for(int i = 0; i < N; ++i){
        cout << tree[i].size() << endl;
    }
    return 0;
}




Measured memory_bytes: 3608
#include <stdio.h>
  
int main(){
    int d,n;
    int ans=1;
    scanf("%d %d",&d,&n);
    for(int i=0;i<d;i++){
        ans*=100;
    }
    if(n<100) ans*=n;
    else ans*=101;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
n,m,l = map(int,input().split())
YEAH = [list(map(int,input().split())) for i in range(n)]
FUCK = [list(map(int,input().split())) for i in range(m)]

for i in range(n):
    for j in range(l):
        GOMI = 0
        for k in range(m):
            GOMI += FUCK[k][j]*YEAH[i][k]
        if j!=l-1:
            print(GOMI,end=" ")
        else:
            print(GOMI,end="")
    print()
         



Measured memory_bytes: 6576
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

a,b=getints()
print(max(a+b,a-b,a*b))

Measured memory_bytes: 38496
def check(P):
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=P:
   s+=w[i];i+=1
   if i==n: return n
 return i
n,k=map(int,input().split())
w=[int(input())for _ in[0]*n]
l=0;r=n*100000
while r-l>1:
 m=(l+r)//2
 if check(m)>=n:r=m
 else:l=m
print(r)


Measured memory_bytes: 10344
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int S,h,m,s;
    h=0;
    m=0;
    s=0;
    scanf("%d",&S);
    h=S/3600;
    m=(S%3600)/60;
    s=S%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
import java.util.*;

/**
 * Created by chinalife on 2019/7/31.
 */
public class Main{

    public static Map<String,Integer> map = new HashMap<>();
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        bfs();
        while(scanner.hasNext()){
            String input = scanner.nextLine();
            input = input.replaceAll(" ","");
            int result = map.get(input);
            System.out.println(result);
        }
    }
    public static void bfs(){
        String s = "01234567";
        map.put(s,0);
        int[] direction = new int[]{1,-1,4,-4};
        Queue<String> queue = new LinkedList<>();
        queue.add(s);
        while (!queue.isEmpty()){
            String curr = queue.poll();
            int index = findZeroIndex(curr);
            int value = map.get(curr);
            for(int i = 0;i<direction.length;i++){
                int newIndex = index+direction[i];
                if(index == 3 && i == 0){
                    continue;
                }
                if(index == 4 && i == 1){
                    continue;
                }
                if(newIndex <0 || newIndex>=8){
                    continue;
                }
                String temp = swap(curr,index,newIndex);
                if(!map.containsKey(temp)){
                    map.put(temp,value+1);
                    queue.add(temp);
                }
            }
        }
    }
    public static int findZeroIndex(String s){
        int index = -1;
        for(int i = 0;i<s.length();i++){
            if(s.charAt(i) == '0'){
                index = i;
                break;
            }
        }
        return index;
    }
    public static String swap(String curr,int index,int newIndex){
        char[] chars = curr.toCharArray();
        char temp = chars[index];
        chars[index] = chars[newIndex];
        chars[newIndex] = temp;
        return new String(chars);
    }
}



Measured memory_bytes: 40140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	set<int> s;
	cin >> n >> m;
	REP(i, 10) s.insert(i);
	REP(i, m) {
		int x;
		cin >> x;
		s.erase(x);
	}
	for (int i = n;; i++) {
		if ([&]() {
			int x = i;
			while (x) {
				if (!s.count(x % 10)) return 0;
				x /= 10;
			}
			return 1;
		}()) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  VI a(n);
  int one_pos;
  rep(i, n) {
    cin >> a[i];
    if(a[i] == 1) {
      one_pos = i + 1;
    }
  }
  out(ceil((double)(n-1) / (k-1)));
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

ll solve(int N) {
    ll res = 0;
    ll a = 0, b = 0, both = 0;
    vector<string> A(N);
    rep(i,N) {
        string s; cin >> s;
        A.at(i) = s;
        int n = s.size();
        for (int j = 0; j < n-1; j++) {
            if (s[j] == 'A' && s[j+1] == 'B') res++, j++;
        }
        if (s[0] == 'B' && s[n-1] == 'A') both++;
        else if (s[0] == 'B') b++;
        else if (s[n-1] == 'A') a++;
    }

    if (a > 0) {
        if (both > 0) res += both, a--;
    } else if (both > 0) res += both - 1;
    if (both > 0 && b > 0) {
        res++, b--;
    }
    res += min(a,b);
    return res;
}

ll solve2(int N) {
    vector<string> A(N);
    vector<int> a, b, ab;
    rep(i, N) {
        string S; cin >> S;
        A[i] = S;
        int e = S.size() - 1;
        if (S[0] == 'B' && S[e] == 'A') ab.push_back(i);
        else if (S[0] == 'B') b.push_back(i);
        else if (S[e] == 'A') a.push_back(i);
    }
    string T;
    set<int> used;
    if (a.size() > 0) {
        used.insert(a.back());
        T += A[a.back()]; a.pop_back();

    } 
    while (ab.size() > 0) {
        used.insert(ab.back());
        T += A[ab.back()]; ab.pop_back();
    }
    if (b.size() > 0) {
        used.insert(b.back());
        T += A[b.back()]; b.pop_back();
    }

    while (b.size() > 0 && a.size() > 0) {
        used.insert(a.back());
        used.insert(b.back());
        T += A[a.back()]; a.pop_back();
        T += A[b.back()]; b.pop_back();
    }

    rep(i,N) {
        if (used.count(i) == 0) T += A[i];
    }
    
    ll res = 0;
    for (int i = 0; i < T.size() - 1; i++) {
        if (T[i] == 'A' && T[i+1] == 'B') res++, i++;
    }
    return res;
}

int main() {
    int N; cin >> N;
    cout << solve(N) << endl;
}


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

vector<int> divisor(int N) {
    vector<int> RES;
    for (int I = 1; I*I <= N; I++) {
        if (N%I == 0) {
            RES.push_back(I);
            if (I != N/I) RES.push_back(N/I);
        }
    }
    return RES;
}

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    int a[n]; rep(i,n) cin >> a[i];

    int s = 0;
    rep(i,n) s += a[i];
    vector<int> d = divisor(s);
    sort(d.begin(), d.end());

    int ans = 1;

    for (auto di : d) {
        vector<int> b;
        rep(i,n) b.push_back(a[i]%di);
        sort(b.begin(),b.end());
        int s = 0;
        rep(i,n) s += b[i];
        int cmax = s / di;
        int c = 0;
        rep(i,n-cmax) c += b[i];
        if ((ll)c <= k) ans = di;

        //rep(i,n-1) printf("%d ",b[i]);
        //printf("%d\n",b[n-1]);
    }

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


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int cntl = 0, cntr = 0;
    rep(i, N) {
        if (S[i] == '(') {
            cntl++;
        } else {
            if (cntl == 0) {
                cntr++;
            } else {
                cntl--;
            }
        }
    }

    rep(i, cntr) cout << "(";
    cout << S;

    cntl = cntr = 0;
    for (int i = N - 1; i >= 0; --i) {
        if (S[i] == ')') {
            cntr++;
        } else {
            if (cntr == 0) {
                cntl++;
            } else {
                cntr--;
            }
        }
    }

    rep(i, cntl) cout << ")";
    cout << endl;
}

Measured memory_bytes: 256
#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>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q;
ll A[100001];
ll B[100001];
ll ans;
string S;
ll K;
map<ll, ll> m;
char ansmap[102][102];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	ll A, B;
	cin >> A >> B;
	A--; B--;
	rep(i, 0, 100) {
		rep(j, 0, 100) {
			if (i < 50)ansmap[i][j] = '.';
			else ansmap[i][j] = '#';
		}
	}
	rep(i, 0, 49) {
		if (B == 0)break;
		rep(j, 0, 100) {
			if (B == 0)break;
			if (i % 2==0 && j % 4==0) {
				ansmap[i][j] = '#';
				B--;
			}
			if (i % 2==1 && j % 4 == 2) {
				ansmap[i][j] = '#';
				B--;
			}
		}
	}
	rep(i, 51, 100) {
		if (A == 0)break;
		rep(j, 0, 100) {
			if (A == 0)break;
			if (i % 2==0 && j % 4==0) {
				ansmap[i][j] = '.';
				A--;
			}
			if (i % 2==1 && j % 4 == 2) {
				ansmap[i][j] = '.';
				A--;
			}
		}
	}
	cout << 100 << " " << 100 << endl;
	rep(i, 0, 100) {
		rep(j, 0, 100) {
			cout << ansmap[i][j];
		}
		cout << endl;
	}
	cin >> ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,m;sc(n);sc(m);
 pr((1900*m+100*(n-m))*llpow(2,m));
return 0;}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>


int n;
int memo[101010];
std::vector<int> p;

int dp(int i) {
  if (i == 0) return 0;
  if (~memo[i]) return memo[i];

  int res = std::numeric_limits<int>().max();
  for (auto&& e : p) {
    if (i < e) continue;
    res = std::min(res, dp(i - e) + 1);
  }
  return memo[i] = res;
}

int main() {
  std::cin >> n;
  std::fill(memo, memo + 101010, -1);
  {
    int i = 1;
    while (true) {
      int a = (int)std::pow(6, i);
      int b = (int)std::pow(9, i);
      p.emplace_back(a);
      p.emplace_back(b);
      ++i;
      if (a > n && b > n) break;
    }
    p.emplace_back(1);
  }

  std::cout << dp(n) << std::endl;
}


Measured memory_bytes: 1408