akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=1e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    loop(sz(s),i,0)
        cout<<char('A'+((s[i]-'A'+n)%26));
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<iterator>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define lli long long int
#define mp make_pair
#define FLASH ios_base::sync_with_stdio(false); cin.tie(0)
#define PI  3.141592653589793
#define fo(i,n) for(lli i=0;i<(n);i++)
#define FO(i,x,n) for(lli i=(x);i<(n);i++)
#define pb push_back
#define FI first
#define SE second
#define vi vector<lli>
#define pi pair<lli,lli>
#define vii vector<pi >
#define Endl endl
#define ITA 200005
#define ROH 100005
using namespace std;
lli mod = 1e9 +7,test; 
lli max(lli a,lli b){return a>b?a:b;}
lli min(lli a,lli b){return a>b?b:a;}

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

lli n,w;

vi a(101);
vi b(101);
vector<vi > dp(101 , vi(ROH , -1) );
lli f(lli idx,lli rem){
  if(idx == n || rem == 0){
    return 0;
  }
  if(dp[idx][rem] == -1){
  lli maxi = -1;
  if(a[idx] <= rem){
    maxi = b[idx] +  f(idx+1 , rem - a[idx]);
  }
  maxi = max(maxi , f(idx+1 , rem));
  dp[idx][rem] = maxi;
  }
  return dp[idx][rem];

}
void solve(){

cin>>n>>w;

fo(i,n){
  cin>>a[i] >> b[i];
}


cout<<f(0,w)<<endl;



}


int main(){
    FLASH;
    lli t =1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;

}





Measured memory_bytes: 80760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
各iについて、
x=h*iとして、残りの面積はh%2==0ならh/2*(w-i)が２つ
h%2!=0ならh/2*(w-i)と(h/2+1)*(w-i)
wについても同じことをやる
*/

void solve(){
    ll h,w;
    cin >> h >> w;
    ll ans = INF;
    for(ll i=1; i<w; i++){
        ll x,y,z;
        x=h*i;
        if(h%2==0) {
            y = h/2 * (w-i);
            z = y;
        }
        else{
            y = h/2 * (w-i);
            z = (h+1)/2 * (w-i);
        }
        ll tmp, tmp2;
        tmp = min(x,min(y,z));
        tmp2 = max(x,max(y,z));
        ans = min(ans,tmp2-tmp);
        //cout << i << " " << x << " " << y << " " << z << endl;
    }
    for(ll i=1; i<h; i++){
        ll x,y,z;
        x=w*i;
        if(w%2==0) {
            y = w/2 * (h-i);
            z = y;
        }
        else{
            y = w/2 * (h-i);
            z = (w+1)/2 * (h-i);
        }
        ll tmp, tmp2;
        tmp = min(x,min(y,z));
        tmp2 = max(x,max(y,z));
        ans = min(ans,tmp2-tmp);
        //cout << i << " " << x << " " << y << " " << z << endl;
    }
    //cout << h%3*w << endl;
    //cout << w%3*h << endl;

    ans = min(ans,h%3*w);
    ans = min(ans,w%3*h);
    ans = min(ans,(3-h%3)*w);
    ans = min(ans,(3-w%3)*h);
    cout << ans << endl;
}

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



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin>>S>>T;
    bool f = true;
    if(S.size()+1 != T.size()) f = false;
    rep(i,S.size()){
        if(S[i]!=T[i])f = false;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  string X; 
  rep(i,0,N){
    if(S[i]!='A') X+=S[i];
  }
  string ans="NO";
  bool flag=1;
  if(X=="KIHBR"){
  rep(i,0,N){
    if(S[i]=='A'&&i>0&&S[i-1]=='A'){
      flag=0;
      break;
    }
    if(S[i]=='K'&&S.substr(i,3)!="KIH"){
      flag=0;
      break;
    }
  }
    if(flag) ans="YES";
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N,K;
    cin >> N >> K;
    cout << min(N%K,K-(N%K)) << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    rep(0, i, N)
    {
        if (i == 0)
        {
            ans += K;
        }
        else
        {
            ans *= (K - 1);
        }
    }
    cout << ans << endl;
}

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

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

  if (B % A == 0)
    cout << A + B << endl;
  else
    cout << B - A << endl;

  return 0;
}

Measured memory_bytes: 3604
#define  REP(i, s, e) for(register int i = s; i <= e ;i++)
#define DREP(i, s, e) for(register int i = s; i >= e ;i--)

#define DEBUG fprintf(stderr, "Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__)
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

#include <bits/stdc++.h>

using namespace std;
const int maxn = 205, maxm = maxn * maxn * 2, inf = (((1 << 30) - 1) << 1) + 1;

int bg[maxn], ne[maxm], to[maxm], w[maxm], e = 1;
inline void add(int x, int y, int z)
{
	e++;
	w[e] = z;
	to[e] = y;
	ne[e] = bg[x];
	bg[x] = e;
}

inline void ADD(int x, int y)
{
	add(x, y, 1);
	add(y, x, 0);
}
template <typename T> T read()
{
	T ans(0), p(1);
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-') p = -1;
		c = getchar();
	}
	while (isdigit(c))
	{
		ans = ans * 10 + c - 48;
		c = getchar();
	}
	return ans * p;
}

int m, n, k;
int x1[maxn], _y1[maxn], x2[maxn], y2[maxn];

int ans;

int d[maxn];
inline bool BFS()
{
	bool flag = 0;
	REP(i, 1, n + 2) d[i] = inf;
	d[n + 1] = 0;
	queue <int> q;
	q.push(n + 1);
	while (!q.empty())
	{
		register int x = q.front();
		q.pop();
		for (register int i = bg[x]; i; i = ne[i])
			if (w[i] > 0 && d[to[i]] == inf)
			{
				d[to[i]] = d[x] + 1;
				q.push(to[i]);
				if (to[i] == n + 2) flag = 1;
			}
	}
	return flag;
}
#define dfs DFS
#define bfs BFS
inline int DFS(int now = n + 1, int flow = inf)
{
	if (!flow || now == n + 2) return flow;
	for (register int i = bg[now]; i ; i = ne[i])
		if (d[to[i]] == d[now] + 1 && w[i] > 0)
		{
			register int temp = dfs(to[i], min(flow, w[i]));
			if (temp > 0)
			{
				w[i] -= temp;
				w[i ^ 1] += temp;
				return temp;
			}
		}
	return 0;
}

int main()
{
#ifdef CraZYali
	freopen("c.in", "r", stdin);
	freopen("c.out", "w", stdout);
#endif
	n = read<int>();
	REP(i, 1, n) x1[i] = read<int>(), _y1[i] = read<int>();
	REP(i, 1, n) x2[i] = read<int>(), y2[i] = read<int>();
//	dfs(0);
	REP(i, 1, n)
		REP(j, 1, n)
			if (x1[i] < x2[j] && _y1[i] < y2[j])
				ADD(i, j + n);
	n <<= 1;
	REP(i, 1, n / 2)
		ADD(n + 1, i);
	REP(i, n / 2 + 1, n)
		ADD(i, n + 2);
	while (BFS())
		ans += DFS();
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect
from math import factorial


def main():
    H, W = map(int, input().split())

    if H == 1 or W == 1:
        print(1)
        return
    
    odd_row_cell = W // 2 if W % 2 == 0 else (W+1) // 2
    even_row_cell = W // 2 if W % 2 == 0 else (W-1) // 2

    odd_row_num = H // 2 if H % 2 == 0 else (H+1) // 2
    even_row_num = H // 2 if H % 2 == 0 else (H-1) // 2

    num = odd_row_cell * odd_row_num\
        + even_row_cell * even_row_num

    print(int(num))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import math
t1, t2, a1, a2, b1, b2 = [int(_) for _ in open(0).read().split()]
c1 = (b1 - a1) * t1
c2 = c1 + (b2 - a2) * t2
if c1 * c2 > 0:
    print(0)
    exit()
if c2 == 0:
    print('infinity')
    exit()
if c1 < 0:
    c1 *= -1
    c2 *= -1
ans = 2 * (c1 // (-c2)) + (c1 % c2 != 0)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll n;
    string s;
    cin>>n;
    cin>>s;
    int ans=1;
    rep(i,0,n-2){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
 
int n, m, A[200005], B[200005], color[100005], ans[100005];
vector<int> G[100005];
 
 
void bfs() {
    queue<int> q;
    q.push(1);
    color[1] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v: G[u]) {
            if (color[v] == -1) {
                color[v] = 0;
                ans[v] = u;
                q.push(v);
            }
        }
    }
}
 
int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> A[i] >> B[i];
        A[i]; B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    for (int i = 1; i <= n; i++) {
        color[i] = -1;
    }
    bfs();
    bool ok = true;
    for (int i = 2; i <= n; i++) {
        if (ans[i] == 0) {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
        for (int i = 2; i <= n; i++) cout << ans[i] << endl;
    }
    else cout << "No" << endl;
    
}

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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p){
  ll n=solveLinear(a,p,1);
  n=n%p;
  if(n<0)return n+p;
  return n;
}
 
int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  string s1,s2;
  cin>>s1;
  cin>>s2;
  int p[n];
  for(i=0;i<n;i++){
    if(i!=n-1 && s1[i]==s1[i+1]){
      p[cnt++]=2;
      i++;
    }
    else p[cnt++]=1;
  }
  ll prod;
  if(p[0]==1)prod=3;
  else prod=6;
  for(i=1;i<cnt;i++){
    if(p[i-1]==1)prod=(prod*2)%MOD;
    else if(p[i]==2)prod=(prod*3)%MOD;
  }
  cout<<prod<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  input()
  cards = list(map(int, input().split()))
  counts = [0] * len(cards)
  values = [0] * len(cards)

  for c in cards:
    c -= 1
    values[counts[c]] += 1
    counts[c] += 1

  lengths = []
  used = 0

  for i, v in enumerate(values):
    used += v
    lengths.append(used // (i + 1))

  number = len(lengths) - 1

  for k in range(1, len(cards) + 1):
    while number >= 0 and lengths[number] < k:
      number -= 1
    print(number + 1)


if __name__ == '__main__':
  main()


Measured memory_bytes: 119060
import itertools
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

for v in itertools.combinations([a, b, c, d, e], 2):
    if (v[1]-v[0]) > k:
        print(':(')
        exit()

print('Yay!')


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100100];
int s[100100];

int solve() {
    const int m = 100001;
    for (int i = 0; i < n; i++) {
        s[a[i]]++;
    }
    int res = 0;
    vector<int> b;
    for (int i = 0; i < m; i++) {
        if (s[i] == 1) res++;
        else if (s[i] > 1) {
            b.push_back(s[i]);
        }
    }
    while (b.size() > 0) {
        int v = b.back(); b.pop_back();
        if (v == 1) {
            res++;
        } else if (v >= 3) {
            b.push_back(v-2);
        } else {
            if (b.size() > 0) {
                int u = b.back(); b.pop_back();
                if (u == 1) res++;
                else {
                    res++;
                    b.push_back(u-1);
                }
            }
        }
    }
    return res;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main()
{
	int i,n,v[21],c[21],ans=0;
	cin >> n;

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

	for(i=0;i<n;i++){
		if(v[i]>c[i]){
			ans += v[i]-c[i];
		}
	}

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

Measured memory_bytes: 256
fun main(args: Array<String>){
    val (H, W) = readLine()!!.split(" ").map { it.toInt() }
    val S = Array(H){ readLine()!! }

    val g = Array(H * W){ IntArray(H * W){ Int.MAX_VALUE / 10 } }
    for(i in 0 until H){
        for(j in 0 until W){
            if(S[i][j] == '.'){
                g[W * i + j][W * i + j] = 1
                if(j != W - 1 && S[i][j + 1] == '.'){
                    g[W * i + j][W * i + j + 1] = 1
                    g[W * i + j + 1][W * i + j] = 1
                }
                if(i != H - 1 && S[i + 1][j] == '.'){
                    g[W * i + j][W * i + j + W] = 1
                    g[W * i + j + W][W * i + j] = 1
                }
            }
        }
    }

    for (k in 0 until H * W) {
        for (i in 0 until H * W) {
            for (j in 0 until H * W) {
                g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j])
            }
        }
    }

    var max = 0
    for(i in 0 until H * W)
        for(j in 0 until H * W){
            if(g[i][j] != Int.MAX_VALUE / 10) max = Math.max(max, g[i][j])
        }
    println(max)
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

string s;

signed main()
{
	init();
	solve();
}

int a, b, c, d;

void init()
{
	cin >> a >> b >> c >> d;
}


void solve()
{
	cout << max(a*b, c*d) << endl;
}


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

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

  bool YYMM = false;
  bool MMYY = false;

  string L = {S.at(0), S.at(1)};
  int left = stoi(L);
  string R = {S.at(2), S.at(3)};
  int right = stoi(R);

  if (left >= 1 && left <= 12) MMYY = true;
  if (right >= 1 && right <= 12) YYMM = true;

  if (MMYY & YYMM){
    cout << "AMBIGUOUS" << endl;
  }
  else if (MMYY)
  {
    cout << "MMYY" << endl;
  }
  else if (YYMM)
  {
    cout << "YYMM" << endl;
  }
  else
  {
    cout << "NA" << endl;
  }
  
  
  
}

Measured memory_bytes: 3632
require 'set'
def f(a, c, n, prev_group_size = 0)
    g = group(a, 0, 0)
    return g.size if n == 0

    return g.size if g.size <= prev_group_size

    max = 0
    (n == 1 ? [c] : (1..6).to_a - [a[0][0]]).each do |k|
        b = (0..a.size-1).map do |i|
            (0..a[0].size-1).map do |j|
                g.include?([i, j]) ? k : a[i][j]
            end
        end
        m = f(b, c, n-1, g.size)
        max = m if m > max
    end
    max
end

def group(a, i, j)
    reached = Set[[i, j]]
    stack = [[i, j]]
    until stack.empty?
        y, x = stack.pop
        [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dy, dx|
            v, u = y + dy, x + dx
            next if v < 0 || v >= a.size || u < 0 || u >= a[0].size
            next if a[v][u] != a[i][j]
            pos = [v, u]
            next if reached.include?(pos)
            reached << pos
            stack << pos
        end
    end
    reached
end

loop do
    h, w, c = gets.split.map(&:to_i)
    break if h == 0
    a = (1..h).map { gets.split.map(&:to_i) }
    p f(a, c, 5)
end

Measured memory_bytes: 9208
#include<iostream>
#include<vector>

using namespace std;
int n;
void countingSort(short A[],short B[],int k)
{
  int C[k+1];
  for(int i=0;i<k+1;i++)
    {
      C[i]=0;
    }
  for(int j=0;j<n;j++)
    {
      C[A[j]]++;
    }
  for(int i=1;i<k+1;i++)
    {
      C[i]+=C[i-1];
    }
  for(int j=n-1;j>=0;j--)
    {
      //      cout<<"A[j]:"<<A[j]<<endl;
      B[C[A[j]]-1]=A[j];
      C[A[j]]=C[A[j]]-1;
    }
}
int main()
{
  for(;cin>>n;)
    {
      short data[n];
      short out[n];
      int k=0;
      for(int i=0;i<n;i++)
	{
	  cin>>data[i];
	  if(k<data[i])
	    k=data[i];
	}
      countingSort(data,out,k);
      for(int i=0;i<n;i++)
	{
	  cout<<out[i];
	  if(i!=n-1)
	    cout<<" ";
	  else 
	    cout<<endl;
	}
    }
}

Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main(void) {
  string t;
  cin >> t;
  ll i, j;
  
  vector<char> s;
  
  ll ans=0;
  ll f=1;
  ll a=0, d=0;
  
  for(i=0; i<t.size(); i++) {
    if(t[i]=='A') s.pb('A');
    else if(t[i]=='B' && t[i+1]=='C') {
      s.pb('D');
      i++;
    }else {
      s.pb(t[i]);
    }
  }
  
  for(i=0; i<s.size(); i++) {
    //pt(s[i]);
  }
  
  ll N=(ll)s.size();
  
  for(i=0; i<N; i++) {
    
    if(s[i]=='A') {
      ans+=a*d;
      a++;
      d=0;
    }else if(s[i]=='D') {
      d++;
    }else {
      ans+=a*d;
      a=0;
      d=0;
    }
    
  }
  
  ans+=a*d;
  pt(ans);
  
}












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

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

    long long n;
    cin >> n;
    vector<long long> A(n);
    for(long long i = 0; i < n; i++){
        cin >> A[i];
        A[i] -= i + 1;
    }

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

    long long mid = (n % 2 ? A[n / 2] : (A[n / 2] + A[n / 2 - 1]) / 2);
    long long ans = 0;
    for(long long i = 0; i < n; i++){
        ans += abs(A[i] - mid);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	string s;
	rep(i,0,m+2) s.push_back('#');
	cout<<s<<endl;
	rep(i,0,n){
		string t; cin>>t;
		t.insert(0,"#");
		t.push_back('#');
		cout<<t<<endl;
	}
	cout<<s<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
int I,J,x,y,mas[110][110]={{0}};
int dy_k[6]={-1,-1, 0, 0, 1, 1};
int dx_k[6]={ 0, 1,-1, 1, 0, 1};
int dy_g[6]={-1,-1, 0, 0, 1, 1};
int dx_g[6]={-1, 0,-1, 1,-1, 0};
int d[110][110];
int wall=0;
long long int wall_len=0;
typedef pair<int,int>P;
int bfs();
int wall_reck(int,int);
int main(){
  cin >> x >> y;
  for(int i=0;i<y+2;i++){
    for(int j=0;j<x+2;j++){
      mas[i][j]=0;
    }
  }

  for(int i=1;i<y+1;i++){
    for(int j=1;j<x+1;j++){
      cin >> mas[i][j];
    }
  }

  for(int i=0;i<y+2;i++){
    for(int j=0;j<x+2;j++){
      if(mas[i][j]==0){
	if(i==0 || j==0 || i==y+1 || j==x+1){
	  wall_reck(i,j);
	}
	else{
	  I=i;
	  J=j;
	  bfs();
	  //帰ってきた値が1（つまり、抜けられた）、または範囲外（必ず１）なら、周り(六方)の壁の数を計算。
	  if(wall == 1){
	    wall=0;
	    wall_reck(i,j);
	  }
	}
	  
 

      }
    }
  }
  cout << wall_len << endl;
}

int bfs(){
  queue<P>que;
  memset(d,-1,sizeof(d));
  que.push(P(I,J));
  d[I][J] = 0;
  while(!que.empty()){
    P p = que.front();
    que.pop();
    //外につながったか。
    if(p.first==0 || p.second==0 || p.first==y+1 || p.second==x+1){
      wall=1;
      break;
    }
    for(int i=0;i<6;i++){
      int ny,nx;
      if(!(p.first&1)){
	ny=p.first+dy_g[i];
	nx=p.second+dx_g[i];
      }
      else{
	ny=p.first+dy_k[i];
	nx=p.second+dx_k[i];
      }
      if(mas[ny][nx]==0 && d[ny][nx]==-1){
	que.push(P(ny,nx));
	d[ny][nx]=d[p.first][p.second]+1;
      }
    }

  }
}

int wall_reck(int i,int j){
  for(int k=0;k<6;k++){
    if(!(i&1)){
      if(mas[i+dy_g[k]][j+dx_g[k]]==1){
	wall_len++;
      }
    }
    else{
      if(mas[i+dy_k[k]][j+dx_k[k]]==1){
	wall_len++;
      }
    }

  }
}

Measured memory_bytes: 1308
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    #N = 100000
    #A = [i for i in range(1,100000)]
    sum_a = sum(A)% 1000000007
    ans = 0
    for i in range(N):
        sum_a = (sum_a - A[i])% 1000000007
        ans = (ans + sum_a*A[i] ) % 1000000007
        #print((sum_a-A[i])*A[i]/2 ,ans)
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 94128
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s)for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])


Measured memory_bytes: 5604
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <map>
#include <limits>
#include <fstream>
#include <iomanip>
#include <queue>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> water(N + 10, 1), red(N + 10, 0);

  red[1] = 1;

  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    --water[x];
    ++water[y];
    if (red[x] == 1) {
      if (water[x] == 0) {
        red[x] = 0;
      }
      red[y] = 1;
    }
  }

  int ans = 0;
  for (auto&& v : red) {
    if (v == 1) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}

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

#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

int whtcnt,blkcnt,blk,lasti,lastj;
char G[105][105];

struct point{int x,y;}p[505];

inline void add(int x,int y){
	for(int i=-1;i<=1;++i){
		for(int j=-1;j<=1;++j)
			G[x+i][y+j]='#';
	}
	G[x][y]='.';
}

//					  blkcnt
inline void build(int cnt){
	for(int i=3;i<=98;i+=4){
		for(int j=3;j<=98;j+=4){
			p[++blk]=(point){i,j};
			add(i,j);
			if(--cnt==0){
				lasti=i,lastj=j;
				return;
			}
		}
	}
}

inline void deal_more(){
	int dta=blkcnt+1-whtcnt;
	if(dta>0){
		for(int i=1;i<=dta;++i)
			G[p[i].x][p[i].y]='#';
	}
	else if(dta<0){
		lasti+=4,lastj+=4;
		int tmp=0;
		for(int j=lastj;j<=98;j+=4){
			p[++blk]=(point){lasti-4,j};
			add(lasti-4,j);
			++tmp;
			if(++dta==0){
				break;
			}
		}
		if(dta<0){
			for(int i=lasti;i<=98;i+=4){
				for(int j=3;j<=98;j+=4){
					p[++blk]=(point){i,j};
					add(i,j);
					++tmp;
					if(++dta==0){
						goto nex;
					}
				}
			}
			nex:;
		}
		//debug("%d\n",blk);
		for(int i=3;i<=95;i+=4){
			for(int j=3;j<95;j+=4){
				G[i][j+2]='#';
				//debug("%d\n",tmp);
				if(--tmp==0) return;
			}
			G[i+2][3]='#';
			if(--tmp==0) return;
		}
	/*	for(int i=3;i<95;i+=4){
			for(int j=3;j<=98;j+=4){
				G[i+2][j]='#';
				if(--tmp==0) return;
			}
		}*/
	}
}

inline void rev(){
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j){
			if(G[i][j]=='#') G[i][j]='.';
			else G[i][j]='#';
		}
	}
}

int main(){
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)
			G[i][j]='.';
	}
	scanf("%d%d",&whtcnt,&blkcnt);
	bool flag=false;
	if(whtcnt<blkcnt) swap(whtcnt,blkcnt),flag=true;
	build(blkcnt);
	deal_more();
	if(flag) rev();
	puts("100 100");
	for(int i=1;i<=100;++i){
		for(int j=1;j<=100;++j)
			putchar(G[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int h[100];
int main()
{
	int n,m,a,k,c=0,i,j;
	cin>> n>>m;
	for(i=0;i<n;i++)
	{
		cin>>k;
		for(j=0;j<k;j++)	
			{
			cin>> a;
			h[a]++;	}
			
	}
	
	for(i=1;i<=m;i++)
	if(h[i]==n)
	c++;
	
	cout<<c;
	


		
}


Measured memory_bytes: 384
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for a,b,c in zip(A, B, C):
    if a == b == c:
        continue
    if a == b:
        ans += 1
        continue
    if a == c:
        ans += 1
        continue
    if b == c:
        ans += 1
        continue
    ans += 2
print(ans)
    

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int flg[1000];
  REP(i,1000) flg[i] = 0;
  FOR(i,4,1000) if(i%2==0) flg[i] = -1;
  flg[2] = 0;
  flg[3] = 0;
  for(int i = 2; i < 100; i++){
	if(flg[i] < 0) continue;
	for(int j = i + 1; j < 1000; j++){
	  if(j%i==0) flg[j] = -1;
	}
  }
  int n;
  ll int ans = 1;
  cin >> n;
  for(int k = 1; k <= n; k++){
	int t = k;
	for(int i = 2; i < 1000; i++){
	  if(t == 1) break;
	  if(flg[i] < 0) continue;
	  int cnt = 0;
	  while(1){
		if(t % i != 0) break;
		t /= i;
		flg[i]++;
	  }
	}
  }
  
  FOR(i,2,1000){
	if(flg[i] > 0) ans *= (flg[i] + 1);
	ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>


void test_case()
{
    ll n;
    cin>>n;
    cout << 1000*((n+999)/1000)-n << "\n";
}

int main()
{
    fastio
//    int t;
////    cin>>t;
//    while(t--)
    test_case();

}


Measured memory_bytes: 3604
#include<iostream>

int main() {
	int k, s;
	std::cin >> k >> s;

	int ans = 0;
	for (int x = 0; x <= s; x++) {
		for (int y = 0; y <= s - x; y++) {
			int z = s - x - y;
			if (x + y + z == s && x <= k && y <= k && z <= k)ans++;
		}
	}
	printf("%d", ans);
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<998244353>;

//--------------------------- Solve ---------------------------//

void solve() {
    int N, S; cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<mint> F(S+1);    // F[i]：x^iの係数

    mint ans = 0;
    for (int i = 0; i < N; i++) {
        F[0] += 1;
        vector<mint> F_copy = F;
        for (int s = 0; s <= S-A[i]; s++) {
            F[s+A[i]] += F_copy[s];
        }
        ans += F[S];
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3652
K, N = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
Adif = []
for i in range(1, len(A)):
    dif = A[i] - A[i-1]
    Adif.append(dif)
Adif.append(K - A[-1] + A[0])
Adif.remove(max(Adif))
ans = sum(Adif)

print(ans)

Measured memory_bytes: 24908
/**
 * author:    Ziel
 * created:   15.04.2020 21:14:09
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	ll h;
	cin >> h;
	
	ll ans = 0;
	ll cur = 1;
	while (h) {
		ans += cur;
		cur <<= 1;
		h >>= 1;
	}
	
	cout << ans;
	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
#define int long long
typedef long double ld;
const long double pi= 3.14159265358979323846264338327950288;
signed main() {
	int n, a, b;
	ld c[51];
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++)
		cin >> c[i];
	sort(c+1, c + n+1);
	reverse(c+1, c + n+1);
	ld sum = 0, ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i < a)
			sum += c[i];
		else if (i <= b) {
			sum += c[i];
			ans = max(ans, sum / i);
		}
	}
	printf("%LF\n", ans);
	sum = 0;
	int s = 0;
	for (int i = 1; i <= n; i++) {
		if (i < a)
			sum += c[i];
		else if (i <= b) {
			sum += c[i];
			if (sum / i == ans) {
				int j = i, d = 0, e = 0, f = 1;
				while (i > 0 && c[i] == c[j]) {
					d++;
					j--;
				}
				j = i + 1;
				while (j <= n&&c[i] == c[j]) {
					e++;
					j++;
				}
				e += d;
				for (int j = 0; j < d; ) {
					f *= (e--);
					f /= (++j);
				}
				s += f;
			}
		}
	}
	cout << s << endl;
	cin >> s;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='0') a++;
    else b++;
  }
  cout<<min(a,b)*2<<endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Art[] arts = new Art[n];
        for (int i = 0; i < n; i++) {
            arts[i] = new Art(sc.nextLong(), sc.nextInt());
        }
        Arrays.sort(arts);
        long[] values = new long[n + 1];
        long max = Long.MIN_VALUE;
        long min = Long.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            values[i] = arts[i - 1].value + values[i - 1];
            min = Math.min(min, values[i - 1] - arts[i - 1].size);
            max = Math.max(max, values[i] - arts[i - 1].size - min);
        }
        System.out.println(max);
    }
    
    static class Art implements Comparable<Art> {
        long size;
        int value;
        
        public Art(long size, int value) {
            this.size = size;
            this.value = value;
        }
        
        public int compareTo(Art another) {
            if (size == another.size) {
                return 0;
            } else if (size < another.size) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}


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

double eps = 1e-9;
double pi = acos(-1);

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	int n, x;
	cin >> n;

	ll ans = 0;

	if(n >= 500)
	{
		x = n / 500;
		ans += 1000 * x;
		n = n - x * 500;
	}
	
	if(n >= 5)
	{
		x = n/5;
		ans += 5 * x;
	}

	cout << ans << en;

	return 0;
}

Measured memory_bytes: 3644
#include<string.h>
#include<stdio.h>
int main(void)
{
	char S[4];

	scanf("%s", S);

	if(strcmp(S, "SSS") == 0)
	{
		printf("0");
	}
	else if(strcmp(S, "SSR") == 0 || strcmp(S, "RSS") == 0 || strcmp(S, "RSR") == 0|| strcmp(S, "SRS") == 0)
	{
		printf("1");
	}
	else if(strcmp(S, "SRR") == 0 || strcmp(S, "RRS") == 0)
	{
		printf("2");
	}
	else
	{
		printf("3");
	}
	return 0;
}

Measured memory_bytes: 1660
#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);

	int ans=1;
	rep(g,sqrt(m)+1) if(g>0 && m%g==0) {
		if( g <=m/n) ans=max(ans, g );
		if(m/g<=m/n) ans=max(ans,m/g);
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 128
N,K =  list(map(int,input().split()))
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
now = 0
listA.sort()
for i in range(N):
    if now <= K <= now+listA[i][1]:
        print(listA[i][0])
        exit()
    else:
        now += listA[i][1]

Measured memory_bytes: 29448
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

int main()
{

   
    ll n,k;
    cin>>n>>k;

    ll ans = 0;
    while(n){
        ans ++;
        n/=k;
    }
    cout<<ans<<endl;   
    return 0;
}

Measured memory_bytes: 256
def cmb(n,k,p):
    x,y = 1,1
    for i in range(k):
        x = x * (n-i) % p
        y = y * (i+1) % p
    res = x * pow(y,p-2,p) % p
    return res

N,A,B = map(int,input().split())
mod = 10**9+7
print((pow(2,N,mod)-cmb(N,A,mod)-cmb(N,B,mod)-1)%mod)

Measured memory_bytes: 38512
import sys
input = sys.stdin.readline


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def modInverse(a, p):
    return pow(a, p - 2, p)
def nCr(n, r, p=10**9+7):
    x = 1
    for i in range(r):
        x = (x * (n - i)) % p
    d = 1
    for i in range(1, r + 1):
        d = (d * i) % p
    return (x * modInverse(d, p)) % p


N = int(input())
import collections
A = []
for i in range(2, N+1):
    A.extend(prime_factorize(i))
P = collections.Counter(A)


def f(n):
    return len([k for k, v in P.items() if v >= n])


def main():
    ans = 0
    ans += f(74)
    ans += f(24) * (f(2)-1)
    ans += f(14) * (f(4)-1)
    ans += nCr(f(4), 2) * (f(2)-2)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
  string s;
  int i;
  bool f;
  while(getline(cin,s),s[0]!='.'){
    stack<char> st;
    f=true;
    for(i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	st.push(s[i]);
      }else if(s[i]==')'||s[i]==']'){
	if(!st.empty()&&(st.top()+1==s[i]||st.top()+2==s[i]))st.pop();
	else f=false;
      }
    }
    puts(f&&st.empty()?"yes":"no");
  }
}

Measured memory_bytes: 892
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        String s = sc.next();
        char[] arr = s.toCharArray();

        for (int i=0; i<s.length()/2; i++) {
            if (arr[i]!=arr[s.length()-1-i]) {
                out.print("No");
                out.flush();
                return;
            }
        }

        for (int i=0; i<s.length()/2-1; i++) {
            if (arr[i]!=arr[(s.length()/2)-1-i]) {
                out.print("No");
                out.flush();
                return;
            }
            if (arr[(s.length()/2)+1+i]!=arr[s.length()-1-i]) {
                out.print("No");
                out.flush();
                return;
            }
        }

        out.print("Yes");
        out.flush();
    }

}


Measured memory_bytes: 21972
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	s := getString()
	k := getInt()

	ans := "1"
	for i, r := range s {
		if i >= k {
			break
		}

		if r != '1' {
			ans = string(r)
			break
		}
	}

	fmt.Println(ans)
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  vector<int> m(n+1);
  rep(i,n) m[i+1] = (m[i]+a[i])%k;
  rep(i,n+1) m[i] = (m[i]-i+i*k)%k;

  ll ans = 0;
  map<int,int> cnt;
  int l = 0;
  rep(r,n+1){
    if(r-l+1>k){
      cnt[m[l]]--;
      ++l;
    }
    ans += cnt[m[r]];
    cnt[m[r]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int x, y;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> x >> y;
	if (abs(x) == abs(y)) cout << 1 << endl;
	// else if (x == 0 && y > 0) cout << y << endl;
	// else if (x == 0 && y < 0) cout << -y+1 << endl;
	// else if (y == 0 && x > 0) cout << x+1 << endl;
	// else if (y == 0 && x < 0) cout << -x << endl;
	else if (abs(x) < abs(y)) {
		if (y < 0) cout << min(-y-x+1, -y+x+2) << endl;
		else cout << min(y-x, y+x+1) << endl;
	}
	else {
		if (x < 0) {
			if (y <= 0) cout << y-x << endl;
			else cout << -y-x+1 << endl;
		}
		else {
			if (y <= 0) cout << y+x+1 << endl;
			else cout << -y+x+2 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
long answer = 0;
    //AとBの差が偶数なら差/2でOK
    if((B-A)%2==0){
      System.out.println((B-A)/2);
      return;
    }
    //差が奇数なら壁に近い側の人間が壁で一回やり過ごして間に向かう
    if((N-B)<=(A-1)){
      //Bのほうが壁に近いか同じ
      answer=answer+(N-B);//Bが壁まで移動

      A=A+(N-B);//Aも同じだけ移動
            B=N;
      answer = answer+1;//Bが勝つ
      A=A+1;
      answer = answer + (B-A)/2;//間に向かっていく
    }else{
      //Aのほうが壁に近い
      answer = answer + (A-1);

      B=B-(A-1);//Bも同じだけ移動
            A=1;
      answer=answer+1;//Aがわざと負ける
      B=B-1;
      answer = answer +(B-A)/2;//間に向かっていく
    }
    System.out.println(answer);
    
  }
  

  
}

Measured memory_bytes: 23124