akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<P> vec[100005];
	vi p(m), y(m), a(m), b(m);
	rep(i, m) {
		cin >> p[i] >> y[i];
		a[i] = p[i];
		vec[p[i]-1].pb(P(y[i], i));
	}
	rep(i, n) {
		sort(all(vec[i]));
		rep(j, vec[i].size()) {
			b[vec[i][j].second] = j;
		}
	}
	rep(i, m) {
		printf("%06d%06d\n", a[i], b[i] + 1);
	}
	return 0;
}


Measured memory_bytes: 8576
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <string.h>

using namespace std;
int a,b,c,d,k,i,m=1234567,o[110][110],l[110][110],x[4]={0,0,-1,1},y[4]={1,-1,0,0};
//long long x,y,z;
//char c[110][110];
string r;
stack<int> s;
queue<int> qx,qy;
vector<int> v[110];



int main()
{
     cin>>r;
     for(int t=0;t<r.size();t++)
     {
         if(r[t]=='S')
            a++;
         if(r[t]=='T'&&a)
         {
            b+=2;
            a--;
         }
     }
     printf("%d",r.size()-b);
     return 0;
}

Measured memory_bytes: 640
n,q=map(int,input().strip().split(' '))
P = [i for i in range(n)]
def root(x):
    path_to_root = []
    while P[x] != x:
        path_to_root.append(x)
        x = P[x]
    for node in path_to_root:
        P[node] = x
    return x
def is_same_set(x,y):
    return root(x) == root(y)
def unite(x,y):
    P[root(x)] = root(y)

for j in range(q):
    com,x,y = map(int,input().strip().split(' '))
    if com == 0:
        unite(x,y)
    else:
        if is_same_set(x,y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 5980
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

int main()
{
    char a[10];
    scanf("%s",a);
    int n=0,m=0,j;
    j=strlen(a);
    if(a[0]=='A')
    {
        if(a[1]!='C'&&a[1]<='z'&&a[1]>='a')
        {
            if(a[j-1]!='C'&&a[j-1]<='z'&&a[j-1]>='a')
            {
                for(int i=2; i<strlen(a)-1; i++)
                {
                    if(a[i]=='C')
                        n=n+1;
                    else if(a[i]<='z'&&a[i]>='a')
                        m++;
                }
                if(n==1&&m==strlen(a)-4)
                    printf("AC");
                else
                    printf("WA");
            }
            else
                printf("WA");
        }
        else
            printf("WA");

    }
    else
        printf("WA");


    return 0;

}


Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    n, q = map(int, f_i.readline().split())
    
    from collections import deque
    Q = [deque() for i in range(n)]
    
    ans = []
    
    for op in (line.split() for line in f_i):
        op_type = op[0]
        t = int(op[1])
        qt = Q[t]
        if op_type == '0':
            qt.append(op[2])
        elif qt:
            if op_type == '1':
                ans.append(qt[0])
            else:
                qt.popleft()
    print('\n'.join(ans))

solve()


Measured memory_bytes: 20796
#include <iostream>
#include <map>
#include <utility>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef map<pll, int> mpi;

const int Z = 1e9+7;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

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

    int n;
    cin >> n;

    mpi cnt;
    int cnt0 = 0;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;

        if (a == 0 && b == 0) {
            cnt0++;
        } else {
            if (b < 0) {
                a *= -1;
                b *= -1;
            }

            ll d = gcd(abs(a), abs(b));
            a /= d;
            b /= d;

            cnt[{a, b}]++;
        }
    }

    int pow2[n+1];
    for (int i = 0; i <= n; i++) {
        pow2[i] = i == 0 ? 1 : 2 * pow2[i-1] % Z;
    }

    int ans = 1;
    for (auto p : cnt) {
        ll a = p.first.first, b = p.first.second;
        if (a <= 0 && cnt.count({b, -a})) {
            continue;
        }

        int p1 = p.second;
        int p2 = cnt.count({-b, a}) ? cnt[{-b, a}] : 0;

        ans = 1ll * ans * (pow2[p1] + pow2[p2] - 1) % Z;
    }

    ans = (0ll + ans + cnt0 + Z - 1) % Z;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16792
from queue import *

q = LifoQueue()
S=input()
count=0
for s in S:
    if q.empty():
        q.put(s)
    else:
        q_1 = q.get()
        if q_1 != s:
            count+=2
        else:
            q.put(q_1)
            q.put(s)
print(count)


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

int main() {
    int N,K;
    cin >> N >> K;
    // 初期値とKを比較 小さい方を足す
    int num = 1;
    for (int i = 0; i < N; i++) {
        if (num <= K) {
            num *= 2;
        }
        else {
            num += K;
        }
    }
    cout << num << endl;
}

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

#define f(i,x,y)			for(int i=x; i<y; i++)
#define mp 					make_pair
#define F 					first
#define S 					second
#define N 					100005

int main()
{
	int n,w;
	cin>>n>>w;
	int wt[n+1], p[n+1];
	f(i,1,n+1)
		cin>>wt[i]>>p[i];

//cout<<"c1";
	vector <vector<long long> > dp(n+1, vector <long long> (w+1,0));

	// if(wt[1]<=w)
	// 	dp[1][wt[1]] = p[1];
	f(i,1,n+1)
	{
		f(j,0,w+1)
		{
			if(j>=wt[i])
			{
				dp[i][j] = max(dp[i-1][j-wt[i]]+p[i] , dp[i-1][j]);
			}
			else
				dp[i][j] = dp[i-1][j];
		}
	}
		
	
cout<<dp[n][w];
	

	return 0;
}

Measured memory_bytes: 80256
def main(argv)
  (n, a, b) = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp

  x = 0
  y = 0
  s.size.times do |i|
    if s[i] == 'a' then
      if x < (a + b) then
        puts 'Yes'

        x += 1
      else
        puts 'No'
      end
    elsif s[i] == 'b' then
      if ((x < (a + b)) and (y < b)) then
        puts 'Yes'

        x += 1
        y += 1
      else
        puts 'No'
      end
    else # s[i] == 'c'
      puts 'No'
    end
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll k,x,y,z,n,w,m;
ll maxi(ll x,ll y,ll z)
{
	if(x>=y && x>=z)
		return x;
	else if(y>=x &&y>=z)
		return y;
	else
		return z;
}
int main()
{
	ll sum=0;
string a,s;
string b;
cin>>a>>b;	
	n=a.size();
	m=b.size();
		vector<vector<ll >> dp(n+1,vector<ll> (m+1));
 
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <=m; ++j)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(a[i-1]!=b[j-1])
				dp[i][j]=maxi(dp[i-1][j],dp[i-1][j-1],dp[i][j-1]);
			else if(a[i-1]==b[j-1])
				{
					dp[i][j]=dp[i-1][j-1]+1;
				}
 
		}
	}
	ll i=n,j=m;
	while( i >=1 && j>=1 )
	{
		
		
			if(a[i-1]==b[j-1])
				{
					s.push_back(a[i-1]);
					i--,j--;
				}
			else if(dp[i-1][j]>=dp[i][j-1] && dp[i-1][j]>=dp[i-1][j-1])
				i--;
			else if(dp[i-1][j-1]>=dp[i][j-1] && dp[i-1][j-1]>=dp[i-1][j])
				i--,j--;
			else
				j--;

		
	}
	string s1;
	for (ll t=0;t<s.size(); ++t)
	{
		s1.push_back(s[s.size()-t-1]);
	}
	cout<<s1<<"\n";
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
#define rep(i,a,b)for(int i=(a);i<=(b);i++)
int n,m,a[MAXN];
char s[MAXN];
int main(){
    cin>>s;
    n= strlen(s);
    int cnt=0;
    rep(i,0,n-1){
        if(s[i]=='o')cnt++;
    }
    if(15-n + cnt>=8)cout <<"YES\n";
    else cout<<"NO\n";
    return 0;
}


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

int		main(void)
{
	ll h, w;

	cin >> h >> w;
	ll result = 0;

	if (h == 1 || w == 1)
		result = 1;
	else
		result = (h * w + 1) / 2;
	cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tc() int t; cin>>t; while(t--)
#define print(n) cout<<n<<"\n"
#define inp(n) int n; cin>>n
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define maxn 1000010
#define f  first
#define s  second
#define fora(var, start, end) for(int var = start; var < end; var++)
int main()
{
    inp(n);
    vector<int> v(n);
    vector<int> maxi;
    fora(i,0,n)cin>>v[i];
    fora(i,0,n-1)
    {
        fora(j,i+1,n)
        {
            maxi.pb(v[i]*v[j]);
        }
    } int sum=0;
   for(int i: maxi)sum+=i;
    print(sum);



    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i, n) cin>>a.at(i);
  
  int ans = 0;
  int f = 1;
  rep(i, n){
    if(a.at(i)==f){
      f++;
    }
    else{
      ans++;
      if(ans==n) ans=-1;
    }
  }
  cout<<ans<<endl;
}

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

using ll = long long;
using namespace std;

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

int main(void) {
	int n, x, y;
	cin >> n >> x >> y;
	
	vector< vector<int> > G(n);
	for(int i = 0; i < n - 1; ++i) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	
	x--;
	y--;
	G[x].push_back(y);
	G[y].push_back(x);
	
	vector<int> res(n - 1, 0);
	
	for(int i = 0; i < n - 1; ++i) {
		vector<int> dist(n, 1e9 + 10);
		queue<int> q;
		
		dist[i] = 0;
		q.push(i);
		
		while( !q.empty() ) {
			int v = q.front();
			q.pop();
			
			for(int c : G[v]) {
				if( dist[c] > dist[v] + 1 ) {
					dist[c] = dist[v] + 1;
					q.push(c);
				}
			}
		}
		
		for(int j = i + 1; j < n; ++j) {
			res[dist[j] - 1]++;
		}
	}
	
	for(auto& ans : res) {
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype> 

char number[1001];

int main(){	
  
  while(1){
  
    scanf("%s", number);
    
    if(number[0]=='0') break;
    
    int i=0,ans=0;
    
    while(number[i]){
      
      ans+=number[i]-'0';
      
      i++;
      
      }
    
    printf("%d\n",ans);
    
    }
	 
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int> A(N); for (auto &a : A) cin >> a;
  auto m = *max_element(begin(A), end(A));
  auto o = count(begin(A), end(A), 1);
  if (o > 0) {cout << int(o == 1) << endl; return 0;}
  map<int, int> mp; for (auto a : A) ++mp[a];
  map<int, bool> bs; for (auto a : A) bs[a] = true;
  for (auto a : A)
    {--mp[a];
    for (int i = a; i <= m; i += a)
      if (mp[i]) {bs[i] = false;}
    ++mp[a];}
  int ans = 0;
  for (auto p : bs) ans += p.second;
  cout << ans << endl;}

Measured memory_bytes: 53988
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll w[maxn],v[maxn];
ll dp[101][maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,W;
	cin>>n>>W;
	REP(i,n) cin>>w[i]>>v[i];
	REP(i,n+1){
		REP(j,W+1){
			if(i==0 or j==0) dp[i][j]=0;
			else if(j<w[i-1]) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
		}
	}
	cout<<dp[n][W]<<'\n';
}

Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N,M;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> M;
  vector<ll> a[3];
  rep(i,N){
    rep(j,3){
      ll num; cin >> num;
      a[j].push_back(num);
    }
  }
  ll ret = 0;
  for(int bit = 0 ; bit < (1 << 3) ; bit++){
    vector<ll> b;
    for(int i = 0 ; i < N ; i++){
      ll tmp = 0;
      for(int j = 0 ; j < 3 ; j++){
        if(bit & (1 << j)){
          tmp += a[j][i];
        }
        else{
          tmp -= a[j][i];
        }
      }
      
      b.push_back(tmp);
    }
    sort(b.begin(),b.end(),greater<ll>());
    ll sum = 0;
    for(int i = 0 ; i < M ; i++){
      sum += b[i];
    }
    ret = max(ret,sum);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int N,K,P;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> K >> P;
        if((K%P)!=0){
            cout << K%P << endl;
        }else{
            cout << P << endl;
        }
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const ll large = 1e18;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; ll c; cin >> n >> c;
    vector<ll> h(n+1);
    deque<pi> hull;
    F0R(i,1,n) cin >> h[i];
    hull.push_back({-2*h[1],h[1]*h[1]});
    ll ans = 0;
    F0R(i,2,n){
        while(hull.size() > 1){
            if(hull[0].f*h[i] + hull[0].s >= hull[1].f*h[i] + hull[1].s) hull.pop_front();
            else break;
        }
        ans = h[i]*h[i] + c + hull.front().f*h[i] + hull.front().s;
        pi add = {-2*h[i],h[i]*h[i] + ans};
        while(hull.size() > 1){
            int fn = hull.size()-1;
            pi a = hull[fn], b = hull[fn-1];
            ll x = ((a.s-b.s)/(b.f-a.f)) + 1;
            if(add.f*x + add.s <= a.f*x + a.s) hull.pop_back();
            else break;
        }
        hull.push_back(add);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int cnt_4=0,cnt_2=0,cnt=0;
  for(int i=0;i<n;i++){
    if(a.at(i)%4==0){
      cnt_4++;
    }
    else if(a.at(i)%2==0){
      cnt_2++;
    }
    else{
      cnt++;
    }
  }
  if(cnt_2==0){
    cnt_4++;
  }
  if(cnt_4>=cnt){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = GetLongNum();

            if (x == 0)
            {
                Console.WriteLine(1);
                return;
            }

            Console.WriteLine(0);

        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 27332
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#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> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;

const int N = 100100;
void eratosthenes(bool prime[N]){
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}


int main() {
    int x;
    cin >> x;
    bool prime[N];
    eratosthenes(prime);
    
    int ans = 0;
    for (int i=x;i<N+1;i++){
        if (prime[i]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int n, a[100], s;
	while(cin >> n, n){
		s = 0;
		for(int i = 0; i < n; ++i){
			cin >> a[i];	
		}	
		sort(a, a+n);
		for(int i = 1; i < n-1; ++i){
			s += a[i];
		}
		cout << s/(n-2) << endl;
	}	
	return 0;
}

Measured memory_bytes: 3124
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n, m;
	cin >> n >> m;

	vs a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	rep(i, n - m + 1) {
		rep(j, n - m + 1) {
			bool ok = true;

			rep(k, m) {
				rep(l, m) {
					if (a[i + k][j + l] != b[k][l]) {
						ok = false;
					}
				}
			}

			if (ok) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

/*
3 3
#.#
.#.
#.#
#.#
.#.
#.#
*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
/*int main() {
	int a, b,s;
	cin >> a;
	cin >> b;
	s = (a-1)*(b-1);
	cout << s << endl;
}*/
int checkCount(int);
int main() {
	int n=0,a=0;
	cin >> n;
	for (int i = 1; i <= n; i+=2)
	{
		if (checkCount(i) == 8)	a++;
	}
	cout << a<<endl;
}
int checkCount(int n) {
	int i=1,count=0;
	while (i<=n) {
		if (n%i == 0) count++;
		i++;
	}
	return count;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

#define WH 22

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

int main(int argc, char const *argv[])
{
	int w,h;
	char f[WH][WH];

	char c;
	int cnt;

	int x,y;

	while(1){
		cin>>w>>h;
		if(w+h==0) break;

		for(int i1=0;i1<WH;i1++){
			for(int i2=0;i2<WH;i2++){
				f[i1][i2]='#';
			}
		}
		queue<pair<int,int> > q;
		cnt=1;

		for(int i1=1;i1<=h;i1++){
			for(int i2=1;i2<=w;i2++){
				cin>>f[i1][i2];
				if(f[i1][i2]=='@'){
					x=i2;
					y=i1;
				}
			}
		}

		q.push(make_pair(x,y));
		while(!q.empty()){
			x=q.front().first;
			y=q.front().second;
			q.pop();

			for(int i1=0;i1<4;i1++){
				if(f[y+dy[i1]][x+dx[i1]]=='.') {
					cnt++;
					q.push(make_pair(x+dx[i1],y+dy[i1]));
					f[y+dy[i1]][x+dx[i1]]='@';
				}
			}
		}

		cout<<cnt<<endl;


	}


	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll n, m, sum = 0;
    cin >> n >> m;
    priority_queue<ll> que;
    rep(i, n)
    {
        ll a;
        cin >> a;
        que.push(a);
    }
    rep(i, m)
    {
        ll x = que.top();
        que.pop();
        que.push(x / 2);
    }
    while (!que.empty())
    {
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1400
n = int(input())
S = [ input() for _ in range(n) ]

import collections

c = collections.Counter(S)
b = c.most_common()

ls_ans = []
ls_ans.append( b[0][0] )

a = b[0][1]

for i in range(1,len(b)):
    if b[i][1]==a:
        ls_ans.append(b[i][0])
    else:
        break
ans = sorted(ls_ans)
print("\n".join(ans))
exit()

Measured memory_bytes: 122576
def func(paths, passed_node, current_node, num_node):
    global num_route
    if len(passed_node) == num_node:
            num_route += 1
            return
    for next_path in [path for path in paths if (path[0] == current_node) and (path[1] not in passed_node)]:
        new_passed_node = passed_node + [next_path[1]]
        new_paths = paths[:]
        new_paths.pop(new_paths.index([current_node, next_path[1]]))
        new_paths.pop(new_paths.index([next_path[1], current_node]))
        new_current_node = next_path[1]
        
        func(new_paths, new_passed_node, new_current_node, num_node)
    
    return num_route
    
            


num_node, num_path = map(int, input().split())
paths = [list(map(int, input().split())) for i in range(num_path)]
for path in paths[:]:
    paths.append([path[1], path[0]])
current_node = 1
passed_node = [1]
num_route = 0

try:
    func(paths, passed_node, current_node, num_node)
finally:
    print(num_route)

Measured memory_bytes: 3064
a,b = map(int,input().split())
#if(b != 0):
c = list(map(int,input().split()))
#else:
  #print(a)
  #exit(0)

for dist in range(b+1):
  for signed in [-1,1]:
    x = a + signed*dist
    if c.count(x) == 0:
      print(x)
      exit(0)

Measured memory_bytes: 9136
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn],ans,pre[maxn],k;
map <ll,int> p;

int main()
{
	n=read(); k=read(); rep(i,1,n) a[i]=read(); p[0]++;
	rep(i,1,n) a[i]=(a[i]-1)%k,pre[i]=(pre[i-1]+a[i])%k;
	rep(i,1,n)
	{
		if(i>=k) p[pre[i-k]]--;
		ans+=p[pre[i]]; p[pre[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18432
s = input()
e = 0
if s[0] == "A":
  for i in range(2,len(s)-1):
    b = s[i]
    if b == "C":
      e = 1
      f = i
      break
  if e == 1:
    s = s[:f] + s[f+1:]
    s = s[1:]
    if s.islower():
      print("AC")
    else:
      print("WA")
  else:
    print("WA")
else:
  print("WA")
  

Measured memory_bytes: 3060
import math
A, B = map(int, input().split())
 
min_8 = math.ceil(A  * 12.5)
max_8 = math.ceil((A + 1) * 12.5) -1
min_10 = math.ceil(B * 10)
max_10 = math.ceil((B  + 1) * 10)  -1
 
if (max_10 < min_8 or max_8 < min_10):
    print(-1)
else:
    print(max(min_8,min_10))

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val m = sc.nextInt()

    val s = mutableMapOf<Int, Int>()
    (0 until m).forEach {
        val a = sc.nextInt()
        val b = sc.nextInt()
        if (s[a] != null && b != s[a]) {
            println(-1)
            return
        }
        s[a] = b
    }

    (0 until 1000).forEach { i ->
        val str = i.toString()
        if (str.length !=n) return@forEach

        var ok = true
        for ((t, u) in s.entries) {
            if (str.length < t) return@forEach
            if (str[t-1] != u.toString()[0]) {
                ok = false
            }
        }

        if (ok) {
            println(i)
            return
        }
    }
    println(-1)
}

Measured memory_bytes: 31648
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int N,M;
int S;
pair<int,int>PD[10010];
int main()
{
    while(cin>>N>>M&&N)
    {
        int d,p;
        for(int i=0;i<N;i++)
        {
            cin>>d>>p;
            PD[i]=make_pair(p,d);
        }
    sort(PD,PD+N);
    S=0;
    for(int j=0;j<N;j++)
    {
        S+=PD[j].first*PD[j].second;
    }
    for(int i=N-1;i>=0;i--)
    {
        if(M<=0)
            break;
        int guarded=min(M,PD[i].second);
        S-=PD[i].first*guarded;
        M-=guarded;
    }
    cout<<S<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            if (a <= b && b <= c)
            {
                Console.WriteLine(a + " " + b + " " + c);
            }
            else if(a <= c && c <= b )
            {
                Console.WriteLine(a + " " + c + " " + b);
            }
            else if (b <= a && a <= c)
            {
                Console.WriteLine(b + " " + a + " " + c);
            }
            else if (b <= c && c <= a)
            {
                Console.WriteLine(b + " " + c + " " + a);
            }
            else if (c <= a && a <= b)
            {
                Console.WriteLine(c +" " + a + " " + b);
            }
            else if (c <= b && b <= a)
            {
                Console.WriteLine(c + " " + b + " " + a);
            }

            
           
         

        }
    }
}

Measured memory_bytes: 5608
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int n,m,k;
int q[10005];

int main(){
	scanf("%d%d%d",&n,&m,&k);
	fore(i,0,k)scanf("%d",q+i);
	int c=0;
	fore(i,0,n){
		vector<int> r;
		fore(j,0,m){
			while(!q[c])c++;
			q[c]--;
			r.pb(c+1);
		}
		if(i%2)reverse(r.begin(),r.end());
		fore(i,0,r.size()){
			if(i)putchar(' ');
			printf("%d",r[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector< vector<int> >;

int main(){
	ll S; cin >> S;
	ll sq = 0;
	ll x1 = 1000000000;
	ll y1 = 1;
	ll x2 = (x1-S%x1)%x1;
	ll y2 = (S+x2)/x1;
	cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def nisin(a, L):
    nis = []
    for i in range(L):
        nis.insert(0, a%2)
        a = a//2
    return nis

H, W, K = map(int, input().split())
C = [list(map(str, input())) for i in range(H)]

ih = 0
ans = 0

while ih < 2**H:
    select_h = []
    bh = nisin(ih, H)
    iw = 0
    for i in range(H):
        if bh[i] == 0:
            select_h.append(i)
    while iw < 2**W:
        bw = nisin(iw, W)
        select_w = []
        for j in range(W):
            if bw[j] == 0:
                select_w.append(j)
        count = 0
        for u in range(H):
            for v in range(W):
                if u in select_h and v in select_w and C[u][v] == '#':
                    count += 1
        if count == K:
            ans += 1
        iw += 1
    ih += 1

print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    vector <int> a;
    int bob = 0, alice = 0;
    int num;
    cin >> N;

    for(int i= 0; i< N; i++){
        cin >> num;
        a.push_back(num);
    }

    std::sort(a.begin(),a.end(),std::greater<int>());

    
    for(int i = 0; i < N; i++){

        if((i % 2 == 0) || (i == 0)){
            bob += a.at(i);
        }
        else{
            alice += a.at(i);
        }
    }

    cout << bob - alice;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  vector<int> l(0);//i番目の0の塊の左端
  vector<int> r(0);//右端
  //vector<int> l(0);//i番目の1の塊のサイズ
  for(int i=0;i<N;i++){
    if(i==0){
      if(S.at(i)=='0'){
        l.push_back(i);
      }
      if(S.at(i)=='0' && S.at(i+1)=='1'){
        r.push_back(i);
      }
    }
    else if(i==N-1){
      if(S.at(i)=='0'){
        r.push_back(i);
      }
      if(S.at(i)=='0' && S.at(i-1)=='1'){
        l.push_back(i);
      }
    }
    else{
      if(S.at(i-1)=='1' && S.at(i)=='0'){
        l.push_back(i);
      }
      if(S.at(i)=='0' && S.at(i+1)=='1'){
        r.push_back(i);
      }
    }
  }
  int count=l.size();
  if(count<=K){
    cout<<N<<endl;
    return 0;
  }
  int ans=0;
  for(int i=0;i<count-K+1;i++){
    int L=l.at(i);
    int R=r.at(i+K-1);
    if(L>0){
      while(S.at(L-1)=='1'){
        L--;
        if(L==0){
          break;
        }
      }
    }
    if(R<N-1){
      while(S.at(R+1)=='1'){
        R++;
        if(R==N-1){
          break;
        }
      }
    }
    ans=max(ans,R-L+1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4348
#include <stdio.h>

int main()
{
    int Hs, Ws, Hd, Wd;
    scanf("%d %d %d %d", &Hs, &Ws, &Hd, &Wd);
    int sell=Hs*Ws;
    sell -= (Wd*Hs)+(Ws*Hd)-(Hd*Wd);
    printf("%d", sell);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    int a = s;
    list.add(a);
    while(true){
      if(list.contains(func(a))){
        System.out.println(list.size() + 1);
        break;
      }
      a = func(a);
      list.add(a);
    }
  }
  
  public static int func(int a){
    if(a % 2 == 0){
      return a / 2;
    }else{
      return 3 * a + 1;
    }
  }
}

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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
//#define modulo ll (1e9 + 7)
#define modulo ll (1e6 + 3)
const long double PI = 3.141592653589793238L;


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

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

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();
    int n;
    cin >> n;

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

    sort(arr, arr + n);

    int b = (n & 1)?arr[n / 2] : (arr[n / 2] + arr[n / 2 - 1]) / 2;
    ll sum = 0;
    for(int i = 0;i < n;i++){
        sum += abs(arr[i] - b);
    }

    cout << sum;
}

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

using namespace std;

typedef long long int64;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N, A[200000];

  cin >> N;

  int rev[200000];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    --A[i];
    rev[A[i]] = i;
  }

  int64 ret = 0;
  UnionFind tree(N);
  for(int i = N - 1; i >= 0; i--) {
    int idx = rev[i];

    int64 choku = 1, dai = 1;
    if(idx > 0 && A[idx] < A[idx - 1]) {
      choku += tree.size(idx - 1);
      tree.unite(idx - 1, idx);
    }
    if(idx + 1 < N && A[idx] < A[idx + 1]) {
      dai += tree.size(idx + 1);
      tree.unite(idx + 1, idx);
    }
    ret += 1LL * choku * dai * (i + 1);
  }
  cout << ret << endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include <queue>

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	int h, w;
	cin >> h >> w;

	vector<string> v(h);
	rep(i, h){
		cin >> v[i];
	}
	rep(i, h) {
		rep(j, w) {
			if (v[i][j] == '.') continue;

			if ((j > 0 && v[i][j - 1] == '#')) continue;
			if ((i > 0 && v[i - 1][j] == '#')) continue;
			if ((j < w - 1 && v[i][j + 1] == '#')) continue;
			if ((i < h - 1 && v[i + 1][j] == '#')) continue;

			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    K = I()
    s = S()

    if len(s) <= K:
        print(s)
    else:
        print(s[:K] + '...')


if __name__ == '__main__':
    main()


Measured memory_bytes: 68352
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
using std::swap;

double t=0.0;
double N,K;

double che(int x) {
	double n = 1;
	while (1) {
		x *= 2;
		if (x >= K)break;
		++n;
	}
	return n;
}
int main()
{	
	double p;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		if (i+1 >= K) {
			t += 1.0 / N;
		}
		else {
			p = che(i + 1);
			t += pow(0.5, p) / N;
		}
		//printf("%.12f\n", pow(0.5, p)/N);
		//printf("%d %.12f\n",i+1,t);
	}
	printf("%.12f\n", t);
	return 0;
}

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

int main(){
	long n,i,x[10000] ,mi,ma,l;
	l=0;
	cin >> n;
	mi = 1000000;
	ma = -1000000;
	for( i=0 ; i<n ; i++ ){
		cin >> x[i];
		ma=max(ma,x[i]);
		mi=min(mi,x[i]);
		l += x[i];
	}
	cout << mi <<' '<< ma <<' '<< l << endl;
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
//1-indexed
class BIT {
public:
    ll n; //データの長さ
    vector<ll> bit; //データの格納先
    BIT(ll n):n(n),bit(n+1,0){} //コンストラクタ

    //k & -kはLSB

    //bit_iにxをO(log(n))で加算する
    void add(ll i,ll x){
        if(i==0) return;
        for(ll k=i;k<=n;k+=(k & -k)){
            bit[k]+=x;
        }
    }

    //bit_1 + bit_2 + …  + bit_n をO(log(n))で求める
    ll sum(ll i){
        ll s=0;
        if(i==0) return s;
        for(ll k=i;k>0;k-=(k & -k)){
            s+=bit[k];
        }
        return s;
    }

    //a_1 + a_2 + … + a_i >= x となるような最小のiを求める(a_k >= 0)
    //xが0以下の場合は該当するものなし→0を返す
    ll lower_bound(ll x){
        if(x<=0){
            return 0;
        }else{
            ll i=0;ll r=1;
            //最大としてありうる区間の長さを取得する
            //n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
            while(r<n) r=r<<1;
            //区間の長さは調べるごとに半分になる
            for(int len=r;len>0;len=len>>1) {
                //その区間を採用する場合
                if(i+len<n && bit[i+len]<x){
                    x-=bit[i+len];
                    i+=len;
                }
            }
            return i+1;
        }
    }
};

#define MAXN 100001
ll a[MAXN];

int main() {
    int n;
    cin >> n;
    BIT tree(n);
    BIT tree2(n);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        tree.add(i, a[i]);
        tree2.add(i, a[i]);
    }
    ll count1 = 0;
    // s1が正のときを考える。
    for (int i = 1; i <= n; i++) {
        if (i % 2) {
            //正
            if (tree.sum(i) <= 0) {
                count1 += -1 * tree.sum(i) + 1; 
                tree.add(i, -1 * tree.sum(i) + 1);
            }
        }
        else {
            if (tree.sum(i) >= 0) {
                count1 += tree.sum(i) + 1; 
                tree.add(i, -1 * tree.sum(i) - 1);
            }
        }
    }
    ll count2 = 0;
    // s1が負のときを考える。
     for (int i = 1; i <= n; i++) {
        if (i % 2) {
            //ホントは負
            if (tree2.sum(i) >= 0) {
                count2 += tree2.sum(i) + 1; 
                tree2.add(i, -1 * tree2.sum(i) - 1);
            }
        }
        else {
            if (tree2.sum(i) <= 0) {
                count2 += -1 * tree2.sum(i) + 1; 
                tree2.add(i, -1 * tree2.sum(i) + 1);
            }
        }
    }
    //cout << count1 << endl << count2 << endl;
    cout << min(count1, count2) << endl;
    return 0;
}

Measured memory_bytes: 5632
import java.util.*
import java.io.PrintWriter
import java.math.*

val pw = PrintWriter(System.out)
val MOD = 1000000007L
val INF = 2147483647
val LINF = 9223372036854775807L

fun main(args: Array<String>){
    solve()
    pw.flush()    
}

fun solve(){
    val l = nextDouble()
    val e = l / 3.0
    println(e * e * e)


}

// Print
fun println(v: String){
    pw.println(v)
}
fun print(v: String){
    pw.print(v)
}

// Read
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map{ it.toInt() }
fun nextLongList() = next().split(" ").map{ it.toLong() }
fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
fun nextAryln(n: Int) = Array(n){ next() }
fun nextIntAryln(n: Int) = IntArray(n){ nextInt() }
fun nextLongAryln(n: Int) = LongArray(n){ nextLong() }
fun nextDoubleAryln(n: Int) = DoubleArray(n) { nextDouble() }

// Math
fun abs(n: Int) : Int = Math.abs(n)
fun abs(n: Long) : Long = Math.abs(n)
fun abs(n: Double) : Double = Math.abs(n)
fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!!
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong()
fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!!
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong()
fun prime(from: Long, to: Long = from) : List<Long>{
    return (from..to).filter{ i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all{ j -> i % j != 0L}
    }
}
fun gcd(a: Long, b: Long) : Long = if(a % b == 0L) b else gcd(b, (a % b))
fun lcm(a: Long, b: Long) : Long = a / gcd(a, b) * b
fun modpow(a: Long, n: Long, p:Long = MOD) : Long {
    var res = 1L
    var ar = a
    var nr = n
    while(nr > 0){
        if((nr and 1) == 1L) res = res * ar % p
        ar = ar * ar % p
        nr = nr shr 1
    }
    return res
}
fun modinv(a: Long, p: Long = MOD) : Long = modpow(a, p - 2, p)
fun ncr(n: Long, r: Long) : Long {
    var a = 1L
    var b = 1L
    for (i in 1..r) {
        a = a * (n + 1 - i) % MOD
        b = b * i % MOD
    }
    return modinv(b, MOD) * a % MOD
}


Measured memory_bytes: 29680
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
int n;
int t[4001],a[4001];
int b[4001];
int f[2001][2001];
int bit[4001];
inline void Add(int p,int x){for(;p<=n+n;p+=p&-p)bit[p]+=x;}
inline int Qur(int p){int A=0;for(;p;p-=p&-p)A+=bit[p];return A;}
int main(){ char s[3];
	scanf("%d",&n);
	F(i,1,n+n) scanf("%s%d",s,a+i), t[i]=*s=='B', b[t[i]*n+a[i]]=i;
	f[0][0]=0;
	F(i,0,n){
		memset(bit,0,sizeof bit);
		F(j,1,n+n) Add(j,1);
		F(j,1,i) Add(b[j],-1);
		F(j,i?0:1,n){
			if(j) Add(b[n+j],-1);
			f[i][j]=0x3f3f3f3f;
			if(i) f[i][j]=min(f[i][j],f[i-1][j]+Qur(b[i]));
			if(j) f[i][j]=min(f[i][j],f[i][j-1]+Qur(b[n+j]));
		}
	} printf("%d",f[n][n]);
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

string s;

int main() {
	cin>>s;
	for (int i=0;i<=s.size()-1;i++) {
		if (s[i]=='C') {
			for (int j=i+1;j<=s.size()-1;j++) {
				if (s[j]=='F') {
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
//おまじない
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    ll a,b;
    cin >> a>>b;
    if(a<b)swap(a,b);
    
    if(a==b){
        cout << 0<<endl;
    }else{
        if((a+b)%2==0){
            cout << (a+b)/2<<endl;
        }else{
            cout << "IMPOSSIBLE"<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
map = a = [ list(input()) for _ in range(h) ]
d = [[1, 0], [0, 1], [1, 1], [-1, 0], [0, -1], [-1, -1], [1, -1], [-1, 1]]

for i in range(h):
    for j in range(w):
        cnt = 0
        if map[i][j] == ".":
            for dx, dy in d:
                nx = j + dx
                ny = i + dy
                if 0 <= nx < w and 0 <= ny < h and map[ny][nx] == "#":
                    cnt += 1
        if map[i][j] != "#":
            map[i][j] = cnt

for i in range(h):
    print(*map[i],sep="")

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    REP(i, N) {
        // 出てくる回数が一番多い文字にする
        if(A[i] == B[i] && B[i] == C[i]) {}
        else if(A[i] == B[i] || B[i] == C[i] || A[i] == C[i]) { ans++; }
        else { ans += 2; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	int i;
	int a=0;
	int b=0;
	int c=0;

	char S_A[100];
	char S_B[100];
	char S_C[100];

	char next;

	scanf("%s",S_A);
	scanf("%s",S_B);
	scanf("%s",S_C);

	next = S_A[a]; 
	// printf("A :turn 0: next is %c\n",next);
	a++;
	for (i = 1; i < strlen(S_A)+strlen(S_B)+strlen(S_C); i++){
		if(next == 'a'){
			next = S_A[a];
			// printf("A: turn %d: next is %c\n",i,next);
			a++;
			if (a>strlen(S_A)){
				printf("A\n");
				return 0;
			}	
		}

		else if(next == 'b'){
			next = S_B[b];
			// printf("B: turn %d: next is %c\n",i,next);
			b++;
			if (b>strlen(S_B)){
				printf("B\n");
				return 0;
			}	
		}

		else if(next == 'c'){
			next = S_C[c];
			// printf("C: turn %d: next is %c\n",i,next);
			c++;
			if (c>strlen(S_C)){
				printf("C\n");
				return 0;
			}	
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int main() {
    int N,Y=0;
    cin>>N;
    for(int i=0;i<N;i++){
      string c;
      cin>>c;
      if((c=="Y"))Y++;
    }
    if(Y>0)cout<<"Four"<<endl;
    else cout<<"Three"<<endl;
    return 0;
}

Measured memory_bytes: 256