akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector A(n);rep(i,n) cin>>A[i];
  ll ans=0,m=A[0];
  for(ll pos=1;pos<n;++pos) {
    if(m<=A[pos]) m=A[pos];
    else ans+=m-A[pos];
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 4748
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod7=1000000007LL;
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add(LL _x, LL _y, LL _mod=mod7){
  _x+=_y;
  return _x>=_mod ? _x-_mod : _x;
}
inline LL sub(LL _x, LL _y, LL _mod=mod7){
  _x-=_y;
  return _x<0 ? _x+_mod : _x;
}
inline LL mul(LL _x, LL _y ,LL _mod=mod7){
  _x*=_y;
  return _x>=_mod ? _x%_mod : _x;
}
LL mypow(LL _a, LL _x, LL _mod){
  if(_x == 0) return 1LL;
  LL _ret = mypow(mul(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=mul(_ret, _a, _mod);
  return _ret;
}
LL mymul(LL _a, LL _x, LL _mod){
  if(_x == 0) return 0LL;
  LL _ret = mymul(add(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=add(_ret, _a, _mod);
  return _ret;
}
void sleep(double sec = 1021){
  clock_t s = clock();
  while(clock() - s < CLOCKS_PER_SEC * sec);
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
const int N=101010;
int p[N];
int f(int x){
  return x == p[x]?x:p[x]=f(p[x]);
}
void uni(int x, int y){
  p[f(x)]=f(y);
}
void build(){

}
int n, m, per[N];
void init(){
  n=getint();
  m=getint();
  for(int i=1; i<=n; i++)
    p[i]=i;
  for(int i=1; i<=n; i++)
    per[i]=getint();
  while(m--){
    int ai=getint();
    int bi=getint();
    uni(ai, bi);
  }
}
set<int> a[N], b[N];
void solve(){
  for(int i=1; i<=n; i++){
    a[f(i)].insert(i);
    b[f(i)].insert(per[i]);
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    for(auto x: a[i])
      if(b[i].find(x) != b[i].end())
        ans++;
  }
  cout<<ans<<endl;
}
int main(){
  build();
  //__ = getint();
  while(__ --){
    init();
    solve();
  }
}


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

const int n = 50;
int A[n];

int main() {
    long long K;
    int n = 50;
    long long A[n];
    scanf("%lld", &K);
    for (int i = 0; i < n; i++) {
        int x = 0;
        if (i < K % n) x = 1;
        int y = K % n;
        if (i < K % n) y--;
        A[i] = i + K / n + n * x - y;
    }
    printf("%d\n", n);
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%lld", A[i]);
    }
    return 0;
}


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

int main(){
  int N,rN,x,y,z,s,ct,i;
  bool f;
  cin >> N;
  rN = sqrt(N);
  for(i=1;i<=N;i++){
    ct = 0;
    f = false;
    for(x=1;x<=rN;x++){
      for(y=x;y<=rN;y++){
        for(z=y;z<=rN;z++){
          s = x*x + y*y +z*z + x*y + y*z + z*x;
    //cout << i << " " << x << " " << y << " " << z << " " << s << endl;
          if (s == i){
            if (x == y){
              if (y == z) ct++;
              else        ct += 3;
            }
            else {
              if (y == z) ct +=3;
              else        ct += 6;
            }
          }
        }
      }
    }
    cout << ct << endl;
  }
  return 0;
}

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

string s, t;
int n, ans;

int main() {
	cin>>s>>t;
	n = s.size();
	for(int i = 0; i < n; i++)
		if(s[i] != t[i]) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3856
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	long double a, b;
	cin >> a >> b;
	cout <<std::setprecision(15)<< 1 / (1 / a + 1 / b) << endl;
	ll
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(n: i64);
    let x = (n - 400) / 200;
    puts!("{}\n", 8 - x);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2232
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const int Mod = 1000000007;
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var ans = 1L;

            for (var i = 1; i <= N; i++)
            {
                ans *= i;
                ans %= Mod;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
ary0 = []
ary1 = []
ary2 = []
ans1 = 0
ans2 = 0

n = gets.to_i

n.times { ary0 << gets.to_i }
ary0.sort!

ary1[0] = ary0[0]
ary2[0] = ary0[-1]

for i in 0 .. n-2

  case i%4
  when 0
    ary1.unshift( ary0[-(i/4*2+1)] )
    ary2.unshift( ary0[i/4*2] )
  when 1
    ary1 << ary0[-(i/4*2+2)]
    ary2 << ary0[i/4*2+1]
  when 2
    ary1.unshift( ary0[i/4*2+1] )
    ary2.unshift( ary0[-(i/4*2+2)] )
  when 3
    ary1 << ary0[i/4*2+2]
    ary2 << ary0[-(i/4*2+3)]
  end

end

for i in 0 .. n-2
  ans1 += ( ary1[i+1] - ary1[i] ).abs
  ans2 += ( ary2[i+1] - ary2[i] ).abs
end

puts ans1 > ans2 ? ans1 : ans2


Measured memory_bytes: 6184
#include <iostream>
using namespace std;
 
int main() {
  long long A, B, N;
  cin >> N >> A >> B;
  
  long long sumA = 0;
  
  long long div = N / (A+B);
  long long res = N % (A+B);
  
  if(res<=A) {
    sumA = A * div + res;
  } else {
    sumA = A * (div+1);
  }
  
  cout << sumA;
  
  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 repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define ALL(a) (a).begin(), (a).end()
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
#define INF 1e18
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main(){
  int a,b,t;
  cin>>a>>b>>t;
  cout << t/a*b << endl;
}


Measured memory_bytes: 256
using System;

namespace question2
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run(){
            var line = Console.ReadLine();
            var n = int.Parse(line.Split(' ')[0]);
            var d = int.Parse(line.Split(' ')[1]);
            
            Console.WriteLine(Math.Ceiling(n/(double)(2*d+1)));
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

int main(){
	ll n, a, b; cin >> n >> a >> b;
	cout << (n / (a + b))*a + min(n % (a + b), a) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#define maxn 100005
#define mid ((nl+nr)>>1)
using namespace std;
typedef long long ll;
int n;
int a[maxn];
int main()
{
	scanf("%d",&n);
	string s="ACL";
	for(int i=1;i<=n;i++)
	cout<<s;
	cout<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n-1);
    rep(i, n) cin >> a[i];
    rep(i, n-1){
        if(a[i+1] - a[i] == 0) b[i] = 0;
        else if(a[i+1] - a[i] > 0) b[i] = 1;
        else b[i] = -1;
    }
    // rep(i, n-1) cout << b[i] << endl;
    ll ans = 1, state = -2;
    rep(i, n-1){
        // cout << state << endl;
        if(b[i] == 0) continue;
        if(state == -2){
            state = b[i];
            continue;
        }
        if(b[i] == 1 && state == -1){
            ans++;
            state = -2;
        }
        else if(b[i] == -1 && state == 1){
            ans++;
            state = -2;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int a,b;
	cin >> a >> b;
	
	if(a >= 13){
		cout << b << endl;
	} else if (6 <= a && a <= 12){
		cout << b/2 << endl;
	} else{
		cout << 0 << endl;
	}
	
    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 INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define BR cout<<endl;
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 (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

double expect(int x){
    double kitai,tem=0;
    for(int i=1;i<=x;i++){
        tem += i;
    }
    kitai = tem/x;
    cout << kitai << endl;
    return kitai;
    
}

int main(){
    int n,ans = 0,sum = 0;
    cin >> n;

    int l[n];
    rep(i,n)cin >> l[i];

    rep(i,n){
        sum += l[i];
        chmax(ans, l[i]);
    }


    if(ans < sum - ans)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



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

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

int main() {
  ll n;
  cin >> n;
  ll ans;
  if (n % 2 == 0)
    ans = (n / 2) - 1;
  else
    ans = n / 2;

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


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

/* editorial */

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

    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V[i];
    }

    int ans = 0;
    for (int i = 0; i <= min(N, K); i++)
    {
        for (int l = 0; l <= i; l++)
        {
            int L = l, R = i - l;
            vector<int> tmp;
            for (int j = 0; j < L; j++)
            {
                tmp.push_back(V[j]);
            }
            for (int j = 0; j < R; j++)
            {
                tmp.push_back(V[(N - 1) - j]);
            }
            sort(tmp.begin(), tmp.end());

            int rest = K - i;
            for (int j = 0; j < rest; j++)
            {
                if (tmp.size() > 0 && tmp[0] < 0)
                {
                    tmp.erase(tmp.begin());
                }
                else
                {
                    break;
                }
            }
            ans = max(ans, accumulate(tmp.begin(), tmp.end(), 0));

            // cout << "i = " << i << ", l = " << l << endl;
            // cout << "ans: " << ans << endl;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()+"DDD"
n=len(s)-3
i=0
ac=0
c=0
while i<n:
  if s[i]=="A":
    ac+=1
    i+=1
  elif s[i:i+2]=="BC":
    c+=ac
    i+=2
  else:
    ac=0
    i+=1
print(c)

Measured memory_bytes: 67268
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<ll, ll> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, M;
    cin >> N >> M;
    vector<pii> d(N);
    ll a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        d[i] = pii(a, b);
    }
    sort(d.begin(), d.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        a = d[i].first, b = d[i].second;
        ll c = min(M, b);
        ans += a * c;
        M -= c;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;
int m[510][510];

struct mov {
  int fromY, fromX;
  int toY, toX;
};
vector<mov> hist;

int main() {
  int h, w;
  cin >> h >> w;
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> m[i][j];
    }
  }
  
  for (int i = 0; i < h; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < w - 1; j++) {
        if (m[i][j] % 2 == 1) {
          m[i][j + 1]++;
          hist.push_back({i, j, i, j + 1});
        }
      }
      if (i != h - 1 && m[i][w - 1] % 2 == 1) {
        m[i + 1][w - 1]++;
        hist.push_back({i, w - 1, i + 1, w - 1});
      }
    } else {
      for (int j = w - 1; j > 0; j--) {
        if (m[i][j] % 2 == 1) {
          m[i][j - 1]++;
          hist.push_back({i, j, i, j - 1});
        }
      }
      if (i != h - 1 && m[i][0] % 2 == 1) {
        m[i + 1][0]++;
        hist.push_back({i, 0, i + 1, 0});
      }
    }
  }
  cout << hist.size() << endl;
  for (int i = 0; i < hist.size(); i++) {
    cout << hist[i].fromY + 1 << " " << hist[i].fromX + 1 << " ";
    cout << hist[i].toY + 1 << " " << hist[i].toX + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
#define  f                     first                 
#define  s                     second                
 
const ll   N     =  2e3+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const ll   INFi  =  0x7f7f7f7f;
 
ll n,x,y,vis[N],ans[N];
vll adj[N];
queue <pll> q;
 
void bfs(ll s){
    fill_n(vis,n+2,0);
    vis[s] = 1;
    q.push(make_pair(s,0));
    while(q.size()){
        x = q.front().f;
        y = q.front().s;
        q.pop();
        ll nn = adj[x].size();
        for(int i = 0; i < nn; i++){
            ll it = adj[x][i];
            if(!vis[it]){
                vis[it] = 1;
                q.push(make_pair(it,y+1));
                ans[y+1]++;
            }
        }
    }
}

int main(){
    cin>>n>>x>>y;
    for(int i = 1; i < n; i++){
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(int i = 1; i <= n; i++) bfs(i);
    for(int i = 1; i < n; i++) cout<<ans[i]/2<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define double long double
 
using namespace std;

int main()
{
    IOS;
    int n,k;
    cin >> n >> k;
    ll arr[n+1];
    for(int i = 1; i <= n;i++)
        cin >> arr[i];
    sort(arr+1,arr+n+1);
    ll sum = 0;
    for(int i = 1;i <= max(0,n-k);i++)
        sum += arr[i];
    cout << sum;
}   

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

ll x = 1e9 + 7; 
const int INF = 1001001001;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n > 0) {
        ans++;
        n /= k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;
L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}
L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}
L W(L f){X[f]=n;S(f=H[f],O[f]=++b);f&&W(f);}
L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
  d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
     //for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;
       for(D(0);n<*Z;n++)!n|H[P[n]]-n&&W(n);//W(L f){X[f]=n;S(f=H[f],O[f]=++b);f&&W(f);}
       for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

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

using namespace std;

int main(){
    long int n,m,k,i,j;
    cin >> n >> m >> k;
    long int a[n+1],b[m+1],l;
    a[0] = 0;b[0] = 0;
    for(i=1;i<=n;i++){
        cin >> l;
        a[i] = l + a[i-1];
    }
    for(j=1;j<=m;j++){
        cin >> l;
        b[j] = l + b[j-1];
    }
    
    int ans = 0;
    j = m;
    for(i=0;i<=n;i++){
        if(a[i]>k)break;
        while(a[i] + b[j] > k){
            j--;
        }
        if(ans<=i+j)ans = i+j;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 6712
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    d = collections.defaultdict(list)
    for i in range(len(s)):
        d[s[i]] += [i]

    loop = 0
    pos = 0
    for i in range(len(t)):
        if t[i] not in d:
            print(-1)
            exit()
        else:
            pos = bisect.bisect_left(d[t[i]], pos)
            if len(d[t[i]]) == pos:
                loop += 1
                pos = 0
            pos = d[t[i]][pos] + 1
    print(loop * len(s) + pos)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 45808
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int K = sc.nextInt();
  int[] l = new int[N];
  for(int i = 0;i < N;i++)l[i] = sc.nextInt();
  Arrays.sort(l);
  int sum = 0;
  for(int i = N-1;i >= N-K;i--){
    sum += l[i];
  }
  System.out.println(sum);
}}

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

int main() {
  int N;
  long long K;
  cin >> N >> K;
  map<int, long long> map;
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    map[a] += b;
  }

  long long count = 0;
  for(auto pair : map){
    count += pair.second;
    if(K <= count){
      cout << pair.first << endl;
      return 0;
    }
  }
}

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

void trace(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (0 < i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

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

    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    trace(A,N);

    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;
        while (0 <= j && v < A[j]) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A,N);
    }
    return 0;
}



Measured memory_bytes: 3084
use std::io::*;
use std::str::FromStr;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
     
fn main() {
    let s: String = read();
    let t: String = read();
    println!("{}{}", t, s);
}

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

int main() { 
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
program forbidden
  implicit none
  integer :: x, n, ans, d, i, j
  integer,allocatable :: p(:)
  logical :: status

  read(*,*) x, n
  if (n == 0) then
     read(*,*) 
     write(*,'(i0)') x
     stop
  end if
  allocate(p(n))
  read(*,*) p
  d = 1000
  do i = 0, 101
     status = .true.
     do j = 1, n
        if ( i == p(j) ) then
           status = .false.
           exit
        end if
     end do
     if (status) then
        if (abs(i-x)<d) then
           ans = i
           d = abs(i-x)
        end if
     end if
  end do
  
  write(*,'(i0)') ans
  stop
end program forbidden


Measured memory_bytes: 2872
n = int(input())
h_map = list(map(int, input().split()))

max_count = 0
count = 0
down = 0

for i in range(n-1):
    if h_map[i] >= h_map[i+1] :
        down = 1
        count += 1
        
        if i == n-2:
            if count > max_count:
                max_count = count
            
    
    else:
        down = 0
        if count > max_count:
            max_count = count
        count = 0

print(max_count)




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

int main() {
    char b;
    cin >> b;
    if(b =='A') cout << 'T';
    if(b =='C') cout << 'G';
    if(b =='G') cout << 'C';
    if(b =='T') cout << 'A';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

struct gausselim
{
	int rank;
	pair<ll,ll> cyc[31];
	void init()
	{
		for(int i = 0; i < 31; i++)
		{
			cyc[i] = mp(0,0);
		}
		rank = 0;
	}
	void add(ll x)
	{
		int tmp = 0;
		for(int i = 30; i >= 0; i--)
		{
			if(x&(1<<i))
			{
				if(cyc[i].fi==0)
				{
					cyc[i].fi = x;
					cyc[i].se = (1<<i)^tmp;
					rank++;
					break;
				}
			}
			//x = min(x, (x^cyc[i]));
			if((x^cyc[i].fi)<x)
			{
				x^=cyc[i].fi;
				tmp^=cyc[i].se;
			}
		}	
	}
};
gausselim base;
vi vec;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int s = 0;
	for(int i = 0; i < n; i++)
	{
		int x; cin>>x;
		vec.pb(x^(x-1));
		s^=x;
	}
	//how many of vec[i] xors to x;
	for(int i = 0; i < n; i++)
	{
		base.add(vec[i]);
		//cerr<<vec[i]<<'\n';
	}
	//cerr<<s<<'\n';
	ll tmp = 0;
	int x = 0;
	for(int i = 30; i >= 0; i--)
	{
		//cerr<<i<<' '<<base.cyc[i].fi<<' '<<x<<'\n';
		if(base.cyc[i].fi==0) continue;
		if((s&(1<<i)) != (x&(1<<i)))
		{
			x^=base.cyc[i].fi;
			tmp^=base.cyc[i].se;
		}
	}
	if(x!=s) cout<<-1<<'\n';
	else cout<<__builtin_popcount(tmp)<<'\n';
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll calc(ll th, const vector<ll>& v){
  ll ret = 0;

  rep(i,v.size()){
    int lb = -1, ub = v.size();
    while(ub-lb>1){
      int mid = (lb+ub)/2;
      if(v[i] + v[mid] >= th) lb = mid;
      else ub = mid;
    }
    ret += lb+1;
  }

  return ret;
}

ll solve(ll th, ll M, const vector<ll>& v){
  vector<ll> cusum(v.size()+1, 0);
  cusum[0] = v[0];
  REP(i,1,v.size()) cusum[i] = v[i] + cusum[i-1];

  ll ret = 0;
  ll cnt = 0;
  rep(i,v.size()){
    {
      int lb = -1, ub = v.size();
      while(ub-lb>1){
        int mid = (lb+ub)/2;
        if(v[i] + v[mid] > th) lb = mid;
        else ub = mid;
      }
      if(lb >= 0){
        ret += v[i] * (lb+1);
        ret += cusum[lb];
      }
      cnt += lb+1;
    }
  }

  return ret + th * (M - cnt);
}


int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));
  reverse(ALLOF(v));

  ll lb = 0, ub = 100000000000LL;
  while(ub-lb>1){
    ll mid = (lb+ub)/2;
    if(calc(mid, v) >= M) lb = mid;
    else ub = mid;
  }
  
  cout << solve(lb, M, v) << endl;
  
  return 0;
}



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

int main()
{
    string s; cin >> s;
    int a = stoi(s);
    int b = a / 100;
    int c = a % 100;
    if(1 <= b && b <= 12 && 1 <= c && c <= 12) {
        cout << "AMBIGUOUS" << "\n";
    }
    else if(1 <= c && c <= 12) {
        cout << "YYMM" << "\n";
    }
    else if(1 <= b && b <= 12) {
        cout << "MMYY" << "\n";
    }
    else cout << "NA" << "\n";
    return 0;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


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

  int l;
  for(l=n;l>0;l--) {
    string pre = s.substr(n-l,l), suf = t.substr(0,l);
    if(pre == suf) {
      cout << 2*n-l << endl;
      return 0;
    }
  }

  cout << n*2 << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())

counter = [0 for __ in range(N)]
Nl = [i for i in range(1,N+1)]

for i,n in enumerate(Nl):
    while n%2==0:
        n /= 2
        counter[i] += 1
idx = counter.index(max(counter))
print(Nl[idx])

Measured memory_bytes: 3060
import java.util.Scanner;

class A {
    public static void main(String...args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        System.out.println(N % 2 == 0 ? N / 2 - 1 : N / 2);
    }
}
public class Main {
    public static void main(String...args) {
        A.main();
    }
}


Measured memory_bytes: 23892
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

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

    string s;
    cin >> s;
    for (auto& c : s) {
        c = 'x';
    }
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  int k;
  cin >> k;
  string str;
  getline (cin, str);
  getline (cin, str);
  if (str.length()<=k){
    cout << str<<endl;
  } else {
    for (int i=0;i < k;i++) {
      cout << str.at(i);
    }
    cout << "...\n";
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<string>s(n);
  map<string, int>mp;
  bool OK = true;
  rep(i,n) cin >> s[i];
  rep(i,n){
    mp[s[i]]++;
  }
  if(mp.size()!=n) OK = false;
  for (int i = 1; i < (n); ++i) {
    if(s[i-1].back() != s[i].front()) OK = false;
  }
  if(OK) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    int ans = 2000;
    for(int i=1; i<2000; i++){
        int tmp = i*0.08;
        int tmp2 = i*0.1;
        if(tmp==a&&tmp2==b) ans = min(ans, i);
    }

    if(ans!=2000) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD =  1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;

signed main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> sum(N+1, vector<int>(N+1));
  for( int i = 0; i < M; i++ ){
    int L, R;
    cin >> L >> R;
    sum[L][R]++;
  }

  for( int i = 1; i <= N; i++ ){
    for( int j = 1; j <= N; j++ ){
      sum[i][j] = sum[i][j]+sum[i-1][j]+sum[i][j-1] - sum[i-1][j-1];
    }
  }

  for( int i = 0; i < Q; i++ ){
    int S, T;
    cin >> S >> T;
    cout << sum[T][T]-sum[T][S-1]-sum[S-1][T]+sum[S-1][S-1] << "\n";
  }

}


Measured memory_bytes: 5560
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

map<string,int> mp;

typedef pair<int,int> P;

void bfs() {
    queue<string> que;
    que.push("01234567");
    mp["01234567"] = 0;
    int ans = 1;
    while(!que.empty()) {
        for(int size = que.size(); size; size--) {
            string cur = que.front(); que.pop();
            int pos = cur.find('0');
            //cout << cur << "\n";
            if(pos < 4) {
                string next = cur;
                swap(next[pos], next[pos + 4]);
                if(!mp.count(next)) {
                    mp[next] = ans;
                    que.push(next);
                }
            }
            else {
                string next = cur;
                swap(next[pos], next[pos - 4]);
                if(!mp.count(next)) {
                    mp[next] = ans;
                    que.push(next);
                }
            }
            if(pos != 0 && pos != 4) {
                string next = cur;
                swap(next[pos], next[pos - 1]);
                if(!mp.count(next)) {
                    mp[next] = ans;
                    que.push(next);
                }
            }
            if(pos != 3 && pos != 7) {
                string next = cur;
                swap(next[pos], next[pos + 1]);
                if(!mp.count(next)) {
                    mp[next] = ans;
                    que.push(next);
                }
            }
        }
        ans++;
    }
}

int main() {
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    bfs();
    string line;
    while (getline(cin, line)) {
        line.erase(remove(line.begin(), line.end(), ' '), line.end());
        cout << mp[line] << "\n";
    }
    return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    vi A(3); REP(i, 3) cin >> A[i];

    int ans = INF;
    REP(i, 3)
    {
        REP(j, 3)
        {
            if(i == j) continue;
            REP(k, 3)
            {
                if(i == k || j == k) continue;
                int cost = abs(A[j]-A[i]) + abs(A[k]-A[j]);
                ans = min(ans, cost);
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
  int i;
  char input;
  for (i = 0; i < 1200; i++) {
    scanf("%c", &input);
    if (isupper(input))
      printf("%c", tolower(input));
    else if (islower(input))
      printf("%c", toupper(input));
    else
      printf("%c", input);
    if (input == '\n')
      break;
  }
  return 0;
}



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

long long n, w, item[110][2];


long long dp[110][100010];

int main() {
    memset(dp, 0, sizeof dp);
	scanf("%lld %lld", &n, &w);
	for(int i = 0 ; i < n ; ++i)	scanf("%lld %lld", &item[i][0], &item[i][1]);

	for(int i = n-1 ; i >= 0 ; --i){
        for(int j = 0; j <= w ; ++j){
            long long take = (item[i][0] + j <= w) ? dp[i+1][item[i][0] + j] + item[i][1] : 0;
            long long leave = dp[i+1][j];
            dp[i][j] = max(take, leave);

        }
	}
    cout << dp[0][0];
	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

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

    S.append("*");
    ll cnt = 0;
    char ch = S[0];
    REP(i,1,N+1){
        if(S[i] != ch){
            ch = S[i];
            ++cnt;
        }
    }

    _PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 512
def main():
    N, *A = map(int, open(0).read().split())

    B = sorted(A)
    l, r = 0, N
    m, c = N // 2, N * (N + 1) // 2

    def check(x):
        b, r, y = N, 0, 0
        D = [0] * (2 * N + 1)
        for a in A:
            D[b] += 1
            if a < x:
                r += D[b]
                b += 1
            else:
                b -= 1
                r -= D[b]
            y += r
        return y

    while True:
        if check(B[m]) <= c // 2:
            if m == N - 1 or check(B[m + 1]) > c // 2:
                break
            else:
                l, m = m, (m + r) // 2
        else:
            m, r = (m + l) // 2, m + 1

    print(B[m])


if __name__ == '__main__':
    main()


Measured memory_bytes: 14332
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
A = []
B = []
for s in S:
    if s not in A:
        B.append(S.count(s)-T.count(s))
        A.append(s)
ans = max(B)
if ans < 0:
  ans = 0
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<ll> a(n); rep(i, 0, n - 1)cin >> a[i];
	int right = 1;
	ll now = a[0];
	ll ans = 0;
	rep(left, 0, n - 1)
	{
		while (right < n && (right <= left || (now ^ a[right]) == (now + a[right])))
		{
			now += a[right];
			++right;
		}
		ans += right - left;
		if (left == right)++right;
		else now -= a[left];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
N , W = map(int,input().split())
dp = [0]*(W+1)

for i in range(N):
    n , m = map(int,input().split())
    for j in range(W,m-1,-1):
        x = n + dp[j-m]
        if x >= dp[j]:
            dp[j] = x
            
print(dp[W])


Measured memory_bytes: 5916
#include <bits/stdc++.h>
#define inf 2e9
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;

int main() {
    int tmp,n,cnt;
    cin>>n;
    cnt=0;
    for (int i=0;i<n;i++){
        cin>>tmp;
        while (tmp%2==0 && tmp!=0){
            cnt++;
            tmp/=2;
        }
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
count = 0
div = 2
flag = False
while True:
  for a in A:
    if a % div != 0:
      flag = True
      break
  if flag:
    break
  else:
    count += 1
    div *= 2

print(count)


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, C[10][10];

int main(){
  cin >> H >> W;
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> C[i][j];
    }
  }
  for (int k = 0; k < 10; k++){
    for (int i = 0; i < 10; i++){
      for (int j = 0; j < 10; j++){
        C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H * W; i++){
    int A; cin >> A;
    if (A < 0) continue;
    ans += C[A][1];
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3576
fun main(args: Array<String>) {
    val (N, M, C) = readLine()!!.split(" ").map { it.toInt() }
    val B = readLine()!!.split(" ").map { it.toInt() }
    var result = 0

    for (i in 0 until N) {
        val A = readLine()!!.split(" ").map { it.toInt() }
        var s = 0
        for (j in 0 until M) s += A[j] * B[j]
        if (s + C > 0) result++
    }
    println(result)
}

Measured memory_bytes: 37688
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0, x = 0, y = 0, z = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami, mado[50];
	bool gg = true;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> d[i];
	}
	b = d[0];
	for(int j=0;j<a;j++){
		if (b == 2) {
			cout << count + 1 << endl;
			return 0;
		}
		b = d[b-1];
		count++;
		
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main { 
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		boolean[][]cards = new boolean[4][13];
		char[] mark = {'S','H','C','D'};

		int n = scan.nextInt();
		for(int i=0;i<n;i++) {
			char c = scan.next().charAt(0);
			int num = Integer.parseInt(scan.next());

			switch(c) {
			case 'S': cards[0][num-1] = true; break;
			case 'H': cards[1][num-1] = true; break;
			case 'C': cards[2][num-1] = true; break;
			case 'D': cards[3][num-1] = true; break;

			}
		}
		for (int i=0;i<4;i++) {
			for (int j=0;j<13;j++) {
				if(!cards[i][j]) System.out.println(mark[i] + " "+(j+1));
			}
		}
	}
}




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

int main()
{

   int n;
   cin>>n;
   for(int i=0;i<=n;i++)
   {
      int x = i;
      if(x*1.08>=n && x*1.08<n+1)
      {
          cout<<i<<endl;
          return 0;
      }
   }
   
   cout<<":("<<endl;

   

    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;
int main(){

  
    int n,q;
    cin>>n>>q;
    
    stack<int> Q[n];
    while(q>0){
        int a,b;
        cin>>a>>b;
        if(a==0){
            int c;
            cin>>c;
            Q[b].push(c);
        }else if(a==1){
           if(!Q[b].empty()) cout<<(Q[b].top())<<endl;
        }else if(a==2){
            if(!Q[b].empty()) Q[b].pop();
        }
        
        
        
        q--;
    }
    
    
    
return 0;
}



Measured memory_bytes: 4480
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

int n,tot,m;
int a[10005];
int b[10005];

bool fl;

pair<int,int> ans[10005];

int main()
{
	cin >> n;
	if (n <= 4)
		fl = 1;
	if (n & 1)
	{
		a[++tot] = n;
		b[tot] = 0;
		n--;
	}
	for (int i = 1;i <= n / 2;i++)
	{
		a[++tot] = i;
		b[tot] = n - i + 1;
	}
	for (int i = 1;i <= tot - fl;i++)
	{
		int nxt = i % tot + 1;
		ans[++m] = make_pair(a[i],a[nxt]);
		ans[++m] = make_pair(a[i],b[nxt]);
		ans[++m] = make_pair(b[i],a[nxt]);
		ans[++m] = make_pair(b[i],b[nxt]);
	}
	int M = 0;
	for (int i = 1;i <= m;i++)
		if (ans[i].first && ans[i].second)
			M++;
	cout << M << endl;
	for (int i = 1;i <= m;i++)
		if (ans[i].first && ans[i].second)
			cout << ans[i].first << ' ' << ans[i].second << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let N: usize = read();
    let S: Vec<char> = read::<String>().chars().collect();
    let mut east = vec![0; N];
    let mut west = vec![0; N];
    for i in 1..N {
        east[i] = east[i-1] + if S[i-1] == 'W' {1} else {0};
        let j = N-i-1;
        west[j] = west[j+1] + if S[j+1] == 'E' {1} else {0};
    }
    let mut ans = N;
    for i in 0..N {
        ans = std::cmp::min(ans, east[i] + west[i]);
    }
    println!("{}", ans);
}


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

int main() {
   string s;
   cin >> s;
   int a = s.size();

   for(int i=0; i<a; i++) {
      s.pop_back();
      if(s.size() % 2 == 0) {
         int A = s.size() / 2;
         string Q = s.substr(0, A);
         string E = s.substr(A, A);
         if(Q == E) {
            cout << s.size() << endl;
            return 0;
         }
      }
   }
}

Measured memory_bytes: 3660
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int x[4];
  int y[4];
  REP(i,2)cin>>x[i]>>y[i];
  x[2]=x[1]+(y[0]-y[1]);
  y[2]=y[1]-(x[0]-x[1]);
  x[3]=x[0]+(y[0]-y[1]);
  y[3]=y[0]-(x[0]-x[1]);
  FOR(i,2,4)cout<<x[i]<<" "<<y[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256