akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        var input = MyUtil.ReadintArray();

        var hoge = 1;
        var i = 0;

        for (i = 0; ; i++)
        {
            if (input[0] < hoge)
            {
                break;
            }

            hoge *= input[1];
        }

        WriteLine(i);
        ReadKey();
    }
}


static class MyUtil
{
    /// <summary>
    /// 指定の桁のビットを取得します。
    /// </summary>
    /// <param name="num"></param>
    /// <param name="count">取得する桁。</param>
    /// <returns></returns>
    public static int GetBit(this int num, int count)
    {
        int mask = (int)Math.Pow(2, count - 1);
        return (num & mask) == 0 ? 0 : 1;
    }

    /// <summary>
    /// <c>int</c>を2進数ビット配列に変換します。
    /// </summary>
    /// <param name="num"></param>
    /// <returns></returns>
    public static int[] ToBitArray(this int num)
    {
        const int size = sizeof(int) * 8;
        var array = new int[size];
        for (int i = 0; i < size; i++)
        {
            array[i] = num.GetBit(size - i);
        }
        return array;
    }

    public static long[] ReadlongArray()
    {
        return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static int[] ReadintArray()
    {
        return ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }

    public static void WriteToDebugConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        System.Diagnostics.Debug.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		sc.close();
		int r = 0;
		for(int i = 0; i < S.length; i++) {
			if(S[i] == T[i]) r++;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 24020
a=list(map(int,input().split()))
b=(a[0]*(a[0]+1))%2019
if (a[1]//2019)-(a[0]//2019) != 0:
  print(0)
else:
  for i in range(a[0],a[1]):
    for j in range(i+1,a[1]+1):
      if b>(i*j)%2019:
        b=(i*j)%2019
    if b==0:
      break
  print(b)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{   int m,d,ans=0;
    scanf("%d%d",&m,&d);
    for(int i=1;i<=m;i++){
        for(int j=11;j<=d;j++){
            int d10=j/10,d1=j%10;
            if(d1>=2&&d10>=2&&d10*d1==i){
                ans++;
                //printf("%d/%d%d\n",i,d10,d1);
            }
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  char x[200],y[101],z[101];
  scanf("%s %s",x,y);
  strcpy(z,x);
  strcat(x,z);
  if (strstr(x,y)==NULL){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0; 
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
typedef vector<i64> vi;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

i64 n,m;
vvi g;
vi path;

i64 search(i64 a){
  if(path[a] != -1) return path[a];
  i64 res = 0;
  for(auto itr : g[a])
    chmax(res,search(itr)+1);
  path[a] = res;
  return res;
}

void Main()
{
  cin >> n >> m;

  g.resize(n,vi());
  i64 x,y;
  rep(i,m){
    cin >> x >> y;
    x--; y--;
    g[x].pb(y);
  }

  path.resize(n,-1);
  i64 ans = 0;

  rep(i,n)
    chmax(ans,search(i));

  cout << ans << endl;
}

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


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

int main(){
	int n,ans=0,mx=0,x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>=mx){
			ans++;
			mx=x;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)


void solve() {
}

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

Y, X = map(int,input().split())
# sy, sx = map(int, input().split())
# gy, gx = map(int, input().split())
sy,sx = 1,1
gy,gx = Y,X
s = [["#"]*(X+2) for _ in range(Y+2)]
for y in range(Y):
    s[y+1] = list("#"+input()+"#")
inf = Y*X
c = [[inf]*X for _ in range(Y)]
c[sy-1][sx-1] = 0
drs = [(-1,0),(1,0),(0,-1),(0,1)]
q = deque([(sy-1, sx-1)])

while q:
    y,x = q.pop()
    cost = c[y][x]
    for dx,dy in drs:
        x2 = x+dx
        y2 = y+dy
        if s[y2+1][x2+1] == "." and c[y2][x2] > cost+1:
            c[y2][x2] = cost+1
            q.append((y2,x2))
if c[gy-1][gx-1] == inf:
    print("-1")
else:
    dots = 0
    for s1 in s:
        dots +=s1.count(".")
    print(dots-c[gy-1][gx-1]-1)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}


void add_self(int &a, int b)
{
    a += b;
    if(a >= mod) a -= mod;
}


void sub_self(int &a, int b)
{
    a -= b;
    if(a < 0) a += mod;
}







int countWays(vector<int> a, int n, int k)
{

    vector<vector<int>> dp(n+1, vector<int>(k+1, 0));

    for(int i = 0; i<=n; i++) dp[i][0] = 1;

    for(int i = 1; i<=n; i++)
    {
        vector<int> prefix(k+1);

        prefix[0] = dp[i-1][0];

        for(int in = 1; in<=k; in++) 
            prefix[in] = ((prefix[in-1]%mod) + (dp[i-1][in]%mod))%mod;

        for(int j = 1; j<=k; j++)
        {
            
            int index = j - min(a[i-1], j);
            if(index == 0) add_self(dp[i][j], prefix[j]);
            else
            {
                dp[i][j] += (prefix[j] + mod - prefix[index-1])%mod;
            }
        }
    }

    return dp[n][k];

}



int32_t main()
{
    IOS;
    fileIO();
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n, k;
        cin>>n>>k;

        vector<int> a(n);

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


        cout<<countWays(a, n, k)<<"\n";


    }
    
    return 0;
}



Measured memory_bytes: 83084
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n;
int ma_id;
Vi va;

void init()
{
	cin >> n;
	va.resize(n);
	int ma = -1;
	REP(i, n)
	{
		int a; cin >> a;
		va[i] = a;
		if (chmax(ma, a)) ma_id = i;
	}

	sort(ALL(va));
}


int main()
{
	init();

	REP(i, n)
	{
		if (i != ma_id)
			cout << va[n - 1] << endl;
		else
			cout << va[n - 2] << endl;
	}
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template
int n,k,sum;
priority_queue <int> q;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int l; cin>>l; q.push(l);
    }
    for(int i=1;i<=k;i++){
        sum+=q.top();q.pop();
    }
    cout<<sum<<newl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int A, B;
	cin >> A >> B;
	
	for (int i = 0; i < 1010; ++i) {
		if ( (i * 8)/100 == A && (i * 10)/100 == B) {
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W,A,B; cin>>H>>W>>A>>B;
  vector<vector<int>> Z(H,vector<int>(W,0));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i<B && j<A) Z[i][j]=1;
      if(i>=B && j>=A) Z[i][j]=1;              
      cout<<Z[i][j];
      if(j==W-1) cout<<endl;
    }
  }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;

int main(void) {
    set<int> nums;
    rep(i, 3) {
        int tmp;
        cin >> tmp;

        nums.insert(tmp);
    }

    if(nums.size() == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

string s;

int main(void) {
    cin >> s;
    
    ll i;
    stack<char> sta;
    
    ll ans=0;
    for(i=0; i<s.size(); i++) {
        
        if(sta.size()==0) {
            sta.push(s[i]);
        }else if(s[i]!=sta.top()) {
            sta.pop();
            ans+=2;
        }else {
            sta.push(s[i]);
        }
    }
    
    pt(ans);
}





Measured memory_bytes: 512
import math
from itertools import permutations, combinations,combinations_with_replacement,product
n = int(input())
p = [[0,0] for i in range(n)]
a = [i for i in range(n)]
a = list(permutations(a))
ans = 0
kai = math.factorial(n)

for i in range(n):
    x , y = map(int,input().split())
    p[i][0] = x
    p[i][1] = y

for i in range(kai):
    for j in range(n-1):
        ans += ((p[a[i][j]][0]-p[a[i][j+1]][0])**2+(p[a[i][j]][1]-p[a[i][j+1]][1])**2)**0.5

print(ans/kai)

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int a;cin>>a;
    if(a==7||a==5||a==3)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int a,b;cin>>a>>b;
  int cnt=0;
  repi(i,a,b+1){
   string s=to_string(i);
    bool flag=true;
    rep(j,s.size()/2)if(s[j]!=s[s.size()-1-j])flag=false;
    if(flag==true)cnt++;
  }
  cout<<cnt<<endl;
    return 0;
}

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


int selectionSort(int a[], int n) {
    int Min, count = 0, sw_tmp;
    rep(i,n-1) {
        Min = a[i];
        for(int j=i; j<n; ++j) {
            if(a[j] < Min) {
                Min = a[j];
                sw_tmp = j;
            }
        }
            if(a[i] != Min) {
                swap(a[i], a[sw_tmp]);
                count++;
            }
            
        
    }
    return count;
}


int main() {
    int n, a[100], count;
    cin >> n;
    rep(i,n) cin >> a[i];
    count = selectionSort(a, n);
    for(int i=0; i<n; ++i) {
        if(i) {
            cout << " " ;
        }
        cout << a[i];
    }
    cout << endl;
    cout << count << endl;
    
    return 0;
}


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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int n;
    cin >> n;
    long double ans = 0, otoshidama;
    string unit;
    for (int i = 0; i < n; i++){
        cin >> otoshidama >> unit;
        if(unit == "BTC") ans += 380000.0 * otoshidama;
        else ans += otoshidama; 
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
# 0がX個、1がY個ある(ただしX+Y=N)とき、Xorの組み合わせ自体は N*(N-1)//2 通りある。
# しかし、それらの和をとることを考えてみた時
# (0,0)と(1,1)を選んだ場合はそのXORは0になることに注意すると、(0,1)の組み合わせの個数だけ数えれば良い。
# これは、たとえば　〇〇〇●●●●(X=3,Y=4)から〇と●を選ぶ組み合わせは何個あるか、という問いと同じことなので
# Nの値には依存することはなく、単純にX*Y通りとなる。
# よって
# ΣΣ A_i Xor A_j = X*Y
# この処理によって、O(N^2)が、O(N)(=Aの各数字を一通り調べる)に減らせる。
# これを各ケタについて計算し、合計すれば良い。
# ケタ数が60まで定まっているので 計算量は O(Nlog(max(A)))≦ O(N*60)
# あるケタのbitを取り出すには ビットシフト「>>」でずらして下1ケタだけを見ると便利。


N=int(input())
A=list(map(int,input().split()))
p=10**9+7

ans=0
for k in range(60):
    cnt_z=0
    cnt_o=0
    #print(A)
    for i in range(N):
        s=A[i]%2
        if s==0:
            cnt_z +=1
        else:
            cnt_o +=1
        A[i] >>= 1
    ans += ((2**k)*cnt_z*cnt_o)%p
       
print(ans%p)

Measured memory_bytes: 122808
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;


char st[200];



int main()
{
    int ans=0;
    scanf("%s",st);
    int len=0;while(st[len]) ++len;
    --len;
    for (int i=0;i<=len;++i,--len){
        if (st[i]!=st[len])
            ++ans;
    }
    printf("%d\n",ans);



}









Measured memory_bytes: 128
#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<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	ll n, ans=999999999999999;
	cin >> n;
	for (ll i = 1; i < sqrt(n) + 1; i++) {
		if (n%i == 0) {
			string a = to_string(i);
			string b = to_string(n / i);
			ans = min(ans, (ll)max(a.size(), b.size()));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    even = sum(1 for i in range(N) if a[i]%2==0)
    odd = sum(1 for i in range(N) if a[i]%2==1)
    four = sum(1 for i in range(N) if a[i]%4==0)

    if odd-four == 1:
        ans = (odd+four == N)
    elif odd <= four:
        ans = True
    else:
        ans = False

    print('Yes' if ans else 'No')
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 86592
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    lli r,g,b,n;
    cin>>r>>g>>b>>n;
    lli ans = 0;
    for(lli i=0;i<=n;i++){
        for(lli j=0;j<=n;j++){
            lli p1 = i*r;
            lli p2 = j*g;
            lli p3 = n - (p1+p2);
            if(p3>=0 && p3%b == 0){
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
n, x=map(int, input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]>x:
    ans+=a[i]-x
    a[i]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    ans+=(a[i]+a[i+1]-x)
    a[i+1]=x-a[i]
print(ans) 

Measured memory_bytes: 63984
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(X) X[X.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int r, D, x;
	cin >> r >> D >> x;
	rep(i, 10) {
		cout << r * x - D << endl;
		x = r * x - D;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;
int main() {
  int n, a; cin >> n >> a;
  cout << n*n - a << endl;
  return 0;
}




// EOF


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	ans := "No"
	for n > 0 {
		r := n % 10
		if r == 7 {
			ans = "Yes"
			break
		}
		n /= 10
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1760
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
using namespace std;
const int num = 100000;
int n;
const int NIL = -1;
struct Node {
	int p, r, l;
};
Node T[num];
int D[num];
inline void rec(int u, int p) {
	D[u] = p;
	if (T[u].l != NIL)rec(T[u].l, p+1);
	if (T[u].r != NIL) rec(T[u].r, p);
}

void print(int u){
	int i;
		printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);
		if (T[u].p == NIL)printf("root, [");
		else if (T[u].l == NIL) printf("leaf, [");
		else printf("internal node, [");
		int c;
		for (i = 0, c = T[u].l; c != NIL; c = T[c].r, i++) {
		
			if (i) printf(", ");
			printf("%d", c);
		}
		
		printf("]\n");
}
int main(){
	int  numn, numc, v, parentnum, c, i, j, a;
	cin >> n;
	for (i = 0; i < n; i++)
		T[i].p = T[i].l = T[i].r = NIL;
	for (i = 0; i < n; i++) {
		scanf("%d%d", &numn, &numc);
		for (j = 0; j < numc; j++) {
			scanf("%d", &c);
			if (j == 0)T[numn].l = c;
			else  T[v].r = c;
			v = c;
			T[c].p = numn;
		}
	}
	for (i = 0; i < n; i++)
		if (T[i].p == NIL) parentnum = i;
	rec(parentnum, 0);
	//for (i = 0; i < n; i++) print(i);
	for (a = 0; a < n; a++) {
		printf("node %d: parent = %d, depth = %d, ", a, T[a].p, D[a]);
		if (T[a].p == NIL)printf("root, [");
		else if (T[a].l == NIL) printf("leaf, [");
		else printf("internal node, [");
		for (i = 0, c = T[a].l; c != NIL; c = T[c].r, i++) {
			if (i) printf(", ");
			printf("%d", c);
		}
		printf("]\n");
	}
	return 0;

}

Measured memory_bytes: 4724
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

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

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



/*****************************************************************************/
signed main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vi a(n);
	f_vI(a, n);
	qi ans1;
	si ans2;
	bool f = true;
	for (int i = n - 1; i >= 0;i--) {
		if (f) {
			ans1.push(a[i]);
			f = false;
		}
		else {
			ans2.push(a[i]);
			f = true;
		}
	}
	while (!ans1.empty()) {
		cout << ans1.front() << " ";
		ans1.pop();
	}
	while (!ans2.empty()) {
		cout << ans2.top() << " ";
		ans2.pop();
	}
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>

int main()
{
	int K, A, B;

	std::cin >> K >> A >> B;

	if (A % K == 0 || (A/K) != (B/K))
	{
		std::cout << "OK" << std::endl;
	}
	else
	{
		std::cout << "NG" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
using namespace std;

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

     if((A+B)%2==0){
         cout<<(A+B)/2<<endl;
     }else{
         cout<<"IMPOSSIBLE"<<endl;

     }

    return 0;
}

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 14.08.2020 17:21:25
**/

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

int main() {

    int n,h;
    cin >> n >> h;
    vector<tuple<int,char>> atc(2*n);
    int a,b;
    rep(i,n){
        cin >> a >> b;
        atc.at(2*i)=make_tuple(a,'a');
        atc.at(2*i+1)=make_tuple(b,'b');
    }
    sort(atc.begin(),atc.end(),greater<>());

    int num=0;
    int count=0;
    while(h>0){
        if(get<1>(atc.at(num))=='b'){
            h-=get<0>(atc.at(num));
            num++;
            count++;
        }
        else{
            count+=(h-1+get<0>(atc.at(num)))/get<0>(atc.at(num));
            h=0;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int>P;
typedef vector<P>VP;
typedef priority_queue<P,VP>PQ;
int main(void){
	int n,r,l;
	int d,t,x;
	P   nn;
	int a,b,m;
	int i,j;
	int box[100001];
	int time[100001];
	int MAX,ans;
	PQ que;
	cin>>n>>r>>l;
	for(i=1;i<=n;i++)	box[i]=time[i]=0;
	cin>>d>>t>>x;
	a=t;
	box[d]+=x;
	que.push(P(box[d],-d));
	m=d;
	for(i=0;i<r-1;i++){
		cin>>d>>t>>x;
		box[d]+=x;
		que.push(P(box[d],-d));
		//cout<<d<<" "<<x<<endl;
		while(1){
			nn=que.top();
			que.pop();
			nn.S*=-1;
			if(nn.F==box[nn.S])	break;
		}
		//cout<<nn.F<<" "<<nn.S<<" "<<m<<endl;
		time[m]+=t-a;
		m=nn.S;
		a=t;
		nn.S*=-1;
		que.push(nn);
	}
	time[m]+=l-a;
	MAX=-1;
	ans=0;
	for(i=1;i<=n;i++){
		//cout<<time[i]<<endl;
		if(MAX<time[i]){
			MAX=time[i];
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}
		
		
		


Measured memory_bytes: 11888
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    map<lint, lint> mp;
    
    for(int i=0; i<n-1; i++) {
        lint a;
        cin >> a;
        mp[a-1]++;
    }

    for(int i=0; i<n; i++) {
        cout << mp[i] << endl;
    }
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define all int i=0; i<n; i++
#define pb push_back
#define pf push_front
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int> >
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f3f
#define mp make_pair
#define pii pair<int,int>
#define T int t;cin>>t;while(t--)
#define I 
#define think 
#define we 
#define should 

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}
int abso(int k){
	if(k==0)return 0;
	else if(k<0) return -1*k;
	else return k;
}
int32_t main() 
{ 
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int dp[n][2];
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[1][0] = abso(arr[1] - arr[0]);
	dp[1][1] = abso(arr[1] - arr[0]);
	for(int i=2; i<n; i++){
		dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + abso(arr[i] - arr[i-1]);
		dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + abso(arr[i] - arr[i-2]);
	}
	cout<<min(dp[n-1][0], dp[n-1][1])<<endl;
}




Measured memory_bytes: 2560
hash = {AC: 0, WA: 0, TLE: 0, RE: 0}
n = gets.chomp.to_i
i = 0
while i < n
  j = gets.chomp
  case j
  when "AC"
    hash[:AC] += 1
  when "WA"
    hash[:WA] += 1
  when "TLE"
    hash[:TLE] += 1
  else
    hash[:RE] += 1
  end
  i += 1
end
hash.each { |k,v|
  puts "#{k} x #{v}"
}

Measured memory_bytes: 14344
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
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; }

ll dp[100010];

int main() {

    int n;
    vector<int> L;
    vector<int> A; // A, B, C

    cin >> n;
    
    A.resize(3);
    for (int i = 0; i < 3; i++)
        cin >> A[i];
    
    L.resize(n);
    for (int i = 0; i < n; i++)
        cin >> L[i];
    
    int res = 1 << 29;
    vector<int> bit(3);

    for (bit[0] = 1; bit[0] < (1 << n); bit[0]++) {
        for (bit[1] = 1; bit[1] < (1 << n); bit[1]++) {
                //共通要素だったらとばす
            if (bit[0] & bit[1]) continue;
            for (bit[2] = 1; bit[2] < (1 << n); bit[2]++) {
                //共通要素だったらとばす
                if (bit[0] & bit[2]) continue;
                if (bit[1] & bit[2]) continue;

                // sums:A~Cに選んだ丈の長さの合計、nums:A~Cに選んだ竹の本数
                vector<int> sums(3, 0), nums(3, 0);
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (bit[j] & (1 << i)) {
                            sums[j] += L[i];
                            nums[j]++;
                        }
                    }
                }

                // costを求める
                int cost = 0;
                for (int i = 0; i < 3; i++) {

                    cost += abs(sums[i] - A[i]);
                    cost += (nums[i] - 1) * 10;
                }
                chmin(res, cost);
            }
        }
    }

    cout << res << endl;

    return 0;
}

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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;
void solve()    {
    int x,y,a,b,c;      cin>>x>>y>>a>>b>>c;
    ll p[a+2],q[b+2],r[c+1];
    fl(i,1,a+1)   cin>>p[i];
    fl(i,1,b+1)   cin>>q[i];
    fl(i,1,c+1)   cin>>r[i];
    sort(p+1,p+a+1);    sort(q+1,q+b+1);    sort(r+1,r+c+1,greater<int>());
    p[a+1]=LLONG_MAX; q[b+1]=LLONG_MAX;
    int ind1=a-x+1;
    int ind2=b-y+1;
    ll ans=0;
    fl(i,ind1,a+1)  ans+=p[i];
    fl(i,ind2,b+1)  ans+=q[i];
    int cnt=1;
    while(cnt<=c and r[cnt]>min(p[ind1],q[ind2]))    {
        if(p[ind1]<=q[ind2])    {
            ans-=p[ind1];
            ans+=r[cnt];
            ind1++;
            cnt++;
        }
        else    {
            ans-=q[ind2];
            ans+=r[cnt];
            ind2++;
            cnt++;
        }
    }
    cout<<ans;
}
/*  Integer Overflow  */
int main()  {
    fast;
    //test()
        solve();
}

Measured memory_bytes: 2560
import java.sql.SQLOutput;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        double x = x2-x1;
        double y = y2-y1;
        System.out.printf("%f",Math.sqrt((x*x)+(y*y)));
    }
}



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

int main(){
    ll N,M;
    cin >> N >> M;
    ll k[M];
    ll p[M];
    vector<vector<ll>> s;
    rep(i,M){
        cin >> k[i];
        vector<ll> tmp;
        rep(j,k[i]){
            ll t;
            cin >> t;
            tmp.push_back(t);
        }
        s.push_back(tmp);
    }
    rep(i,M){
        cin >> p[i];
    }

    ll count=0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<N); ++bit)
    {
        // bit の表す集合を求める
        vector<int> S(N,0);
        for (int i = 0; i < N; ++i) {
            S[i] = (bit & (1<<i)) >> i;
            //cout << S[i] << ' ';
        }
        //cout << endl;

        bool fail=false;
        for(ll i=0;i<M;i++){
            ll swcount=0;
            for(ll j=0;j<k[i];j++){
                //cout << "S[s[" << i << "][" << j << "]]=" << S[s[i][j]-1] << endl;
                if(S[s[i][j]-1] == 1){
                    swcount++;
                }
            }
            //cout << swcount << endl;
            if(swcount%2!=p[i]){
                //cout << "fail" << endl;
                fail=true;
                break;
            }
        }
        if(!fail) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.11 20:50:43
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int n;
    string s[10010];
    cin >> n;
    rep(i, n) cin >> s[i];

    int afin = 0;
    int bsta = 0;
    int ba = 0;
    int ret = 0;
    rep(i, n) {
        string st = s[i];
        int sl = st.size();
        bool isBsta = false;
        bool preA = false;
        rep(j, sl) {
            if (j == 0 && st[j] == 'B') {
                bsta++;
                isBsta = true;
            } else if (j == sl - 1 && st[j] == 'A' && !isBsta) {
                afin++;
            } else if (j == sl - 1 && st[j] == 'A' && isBsta) {
                bsta--;
                ba++;
            }

            if (st[j] == 'A') {
                preA = true;
            } else if (st[j] == 'B' && preA) {
                preA = false;
                ret++;
            } else {
                preA = false;
            }
        }
    }

    if (bsta == 0 && afin == 0) {
        ret += ba > 0 ? ba - 1 : 0;
    } else if (bsta == afin) {
        ret += bsta;
        ret += ba;
    } else if (bsta > afin) {
        if (ba + afin >= bsta) {
            ret += bsta;
            ret += ba + afin - bsta;
        } else {
            ret += ba + afin;
        }
    } else if (bsta < afin) {
        if (ba + bsta >= afin) {
            ret += afin;
            ret += ba + bsta - afin;
        } else {
            ret += ba + bsta;
        }
    }

    cout << ret << '\n';

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 768
def palindromic(n):
	n = str(n)
	return all(x == y for x, y in zip(n[:len(n) / 2], n[::-1]))
def solve(n):
	for i in xrange(10001 - n + 1):
		if n - i >= 0 and palindromic(n - i):
			return n - i
		elif palindromic(n + i):
			return n + i
print solve(input())

Measured memory_bytes: 4232
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a="AC";
	string b="TLE";
	string c="WA";
	string d="RE"; 
	int n;
	int ac=0,re=0,tle=0,wa=0;
	cin>>n;
	string e;
	for(int i=1;i<=n;i++)
	{
	cin>>e;
	if(e==a)
	ac++;
	if(e==b)
	tle++;
	if(e==c)
	wa++;
	if(e==d)
	re++;
}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3196
#include<cstdio>
using namespace std;
const int N=200200;
int i,j,k,n,m,ch,x,En;
int a[N],b[N],f[N],fa[N],z[N],h[N],d[N],du[N],sz[N];
struct edge { int s,n;} E[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
}
void dfs(int x) {
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) dfs(E[k].s);
	for (int k=h[x];k;k=E[k].n) if (du[E[k].s]!=1) z[a[E[k].s]]=x;
	a[x]=0;
	while (z[a[x]]==x) a[x]++;
	if (du[x]==1) {
		b[x]=a[x]+1;
		while (z[b[x]]==x) b[x]++;
	}
}
int main() {
	R(n);
	for (i=1;i<=n;i++) {
		R(x);du[x]++;fa[i]=x;
		E_add(x,i);
	}
	for (i=1;i<=n;i++) if (du[i]==0) d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		if (--du[fa[d[i]]]==0) d[++j]=fa[d[i]];
	}
	for (i=1;i<=n;i++) if (du[i]==1) dfs(i);
	j=0;
	for (i=1;i<=n;i++) if (du[i]==1) break;
	d[++j]=i;
	i=0;
	while (i<j) {
		i++;
		for (k=h[d[i]];k;k=E[k].n) if (du[E[k].s]==1 && E[k].s!=d[1]) d[++j]=E[k].s;
	}
	f[d[j]]=a[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]!=f[d[j]]) return puts("POSSIBLE"),0;
	f[d[j]]=b[d[j]];
	for (i=j-1;i;i--) {
		if (a[d[i]]==f[d[i+1]]) f[d[i]]=b[d[i]];
		else f[d[i]]=a[d[i]];
	}
	if (f[d[1]]==a[d[j]]) return puts("POSSIBLE"),0;
	puts("IMPOSSIBLE");
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string ans = "APPROVED";
    int N;
    cin >> N;
    while(N--) {
        int a;
        cin >> a;
        if(a % 2 != 0) continue;
        if(a % 3 != 0 and a % 5 != 0) ans = "DENIED";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean flag = false;
        for (int a = 0; N - a >= 0; a += 7) {
            if ((N - a) % 4 == 0) {
                flag = true;
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}

Measured memory_bytes: 22612
using System;

class main
{
    static void Main(string[] args)
    {
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            int sa = 0;
            int d = int.Parse(s);
            for (int i = 0; i < 600; i += d)
            {
                sa += i*i*d;
            }
            Console.WriteLine(sa);
        }
    }
}

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

typedef long long ll;
int n, a[100000];
ll cnt1, cnt2, sum;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    
    for (int i = 0; i < n; i++) {
        sum += a[i];
        //make 1
        if (i % 2 == 0 and sum <= 0) {
            cnt1 += 1 - sum;
            sum = 1;
        }
        if (i % 2 == 1 and sum >= 0) {
            cnt1 += sum + 1;
            sum = -1;
        }
    }
    sum = 0;
    
    for (int i = 0; i < n; i++) {
        sum += a[i];
        
        if (i % 2 == 0 and sum >= 0) {
            cnt2 += sum + 1;
            sum = -1;
        }
        if (i % 2 == 1 and sum <= 0) {
            cnt2 += 1 - sum;
            sum = 1;
        }
    }
    cout << min(cnt1, cnt2) << endl;
    
    
    return 0;
}




Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans += r - l + 1;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 23504
#include <bits/stdc++.h>
using namespace std;
int dfs( int BambooNum, int aRaw, int bRaw, int cRaw, vector<int> &L, int A, int B, int C ){

    if ( BambooNum == L.size() ){
        if ( min( aRaw, min( bRaw, cRaw ) ) > 0 )
            return abs( aRaw - A ) + abs( bRaw - B ) + abs( cRaw - C ) - 30; // 伸縮延長魔法
        else return 276447231;
    }

    int ret0, ret1, ret2, ret3;

    ret0 = dfs( BambooNum + 1, aRaw, bRaw, cRaw                   ,L,A,B,C ); // どれも使わない
    ret1 = dfs( BambooNum + 1, aRaw + L.at(BambooNum), bRaw, cRaw ,L,A,B,C ) + 10; // Aの材料にする
    ret2 = dfs( BambooNum + 1, aRaw, bRaw + L.at(BambooNum), cRaw ,L,A,B,C ) + 10; // Bの材料にする
    ret3 = dfs( BambooNum + 1, aRaw, bRaw, cRaw + L.at(BambooNum) ,L,A,B,C ) + 10; // Cの材料にする

    return min( ret0, min( ret1, min(ret2, ret3) ));


}

int main(){
    int N,A,B,C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    for ( int i = 0; i < N; i++ )
        cin  >> L.at(i);
    
    cout << dfs(0,0,0,0,L,A,B,C) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,max=-1000000,min=1000000,i;
  long sum=0;
  long a;

  cin >> n;
  for(i = 0; i < n; i++){
    cin >> a;
    if (a > max) max = a;
    if (a < min) min = a;
    sum += a;
}

  cout << min << " " << max << " " << sum << endl;


  return 0;
}

Measured memory_bytes: 1164
from collections import defaultdict

S = list(input())
T = list(input())
ds = defaultdict(int)
dt = defaultdict(int)
cnt_s = []
cnt_t = []
for s, t in zip(S, T):
    ds[s] += 1
    dt[t] += 1
    cnt_s.append(ds[s])
    cnt_t.append(dt[t])
print('Yes' if cnt_s == cnt_t else "No")


Measured memory_bytes: 28028