akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  X,Y,N;

int main(){
  cin >> N >> X  >> Y;
  ll a=X,b=Y-X-1,c=N-Y+1;
  ll R=(b+2)/2,L=b-R;//ここ
  Rep(k,1,N){
    ll Z=0;
    Z+=max(0ll,a+c-k); //aa cc ac
    Z+=max(0ll,a+R-k)-max(0ll,a-k)-max(0ll,R-k);  //aR -aa -RR
    Z+=max(0ll,c+R-k)-max(0ll,c-k)-max(0ll,R-k);  //cR -cc -RR
    if(k>1){
      Z+=max(0ll,a+1+L-k)-max(0ll,a+1-k)-max(0ll,L+1-k); //koko
      Z+=max(0ll,c+1+L-k)-max(0ll,c+1-k)-max(0ll,L+1-k); //koko
    }
    if(b%2==0 && b!=0){
      if(k<=b/2){
        if(k==1){
          Z+=b-1;
        }
        else{
          Z+=(b+2)-4;
        }
      }
      if(k==b/2+1){
        Z+=(b+2)/2-2;
      }
    }
    else{
      if(k<=(b+1)/2){
        if(k==1){
          Z+=b-1;
        }
        else{
          Z+=(b+2)-4;
        }
      }
    }
    cout << Z << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll mod = 1000000007;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int Taka = (A+D-1)/D;
  int Aoki = (C+B-1)/B;

  if(Taka>=Aoki){
  	cout << "Yes" <<endl;
  }else{
  	cout << "No" <<endl;
  }
    
  return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    ll total = 0, sqsum = 0;
    REP(i, n){
        ll d;
        cin >> d;
        total += d;
        sqsum += d * d;
    }
    ll ans = (total * total - sqsum) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void culmax(int a, int b, int *c) {
	if (a >= b) {
		*c = a;
	}
	if (a < b) {
		*c = b;
	}
}

int main(void) {
	int A, B, Max;
	scanf("%d %d", &A, &B);
	culmax(A + B, A - B, &Max);
	culmax(Max, A*B, &Max);
	printf("%d\n", Max);
	return 0;
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;


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

    string s;
    cin >> s;

    if (s[1]=='B')      s[1]='R';
    else                s[1]='B';

    cout << s;

    return 0;
}


Measured memory_bytes: 3608
import itertools
N = int(input())
l = list(map(int,input().split()))
count = 0

for i in itertools.combinations(l,3):
    a = i[0]
    b = i[1]
    c = i[2]
    if a!=b and b!=c and c!=a:
        if a+b>c and b+c>a and c+a>b:
            count +=1
print(count)



Measured memory_bytes: 9184
N,M = gets.split.map &:to_i
Edges = (0..N).map{ [] }
M.times{
  a,b = gets.split.map &:to_i
  Edges[a].push(b)
}

def dig(entry, n, edges, visited)
  return (entry == n ? [] : nil) if visited[n]
  visited[n] = true
  res = nil
  edges[n].each{ |m|
    r = dig(entry, m, edges, visited)
    if r && (!res || res.size > r.size)
      res = r
    end
  }
  return res ? [n] + res : nil
end

res = nil
(1..N).each{ |i|
  r = dig(i, i, Edges, Array.new(N+1,false))
  if r && r.size >= 2 && (!res || res.size > r.size)
    res = r
  end
}
puts res ? [res.size,res] : -1


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

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define pb push_back
#define mkp make_pair
#define mkt make_tuple
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int MOD=1e3;
const int N=1e2+5;
const ll maxn=2e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
struct Node
{
    int a,b,flag;
    bool operator < (const Node& m)const
    {
        if(a!=m.a) return a<m.a;
        else if(b!=m.b) return b<m.b;
        else return flag<m.flag;
    }
}a[N];
int n;
set<int>st;
void solve()
{
    st.clear();
    int ans=0;
    for(int i=0;i<2*n;i++)
    {
        int flag=a[i].flag;
        if(!flag)
        {
            st.insert(a[i].b);
        }
        else
        {
            auto it=st.lower_bound(a[i].b);
            if(it!=st.begin())
            {
                st.erase(--it);
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n)
    {
        rep(i,0,n)
        {
            cin>>a[i].a>>a[i].b;
            a[i].flag=0;
        }
        rep(i,n,2*n)
        {
            cin>>a[i].a>>a[i].b;
            a[i].flag=1;
        }
        sort(a,a+2*n);
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[78498];int sz;}Template;
Template P;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x){P.Primes[P.sz++]=x;}
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
int main(void)
{
  int N=IN(),A=0,invsum=0,lcm=1,x=0,box[78498]={0};ready();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MPow(A,MOD-2))%MOD;
    rep(j,P.sz){x=0;while(A%P.Primes[j]==0){A/=P.Primes[j],x++;if(box[j]<x)box[j]=x;}}
  }
  rep(i,P.sz){if(box[i])lcm=1l*lcm*MPow(P.Primes[i],box[i])%MOD;}
  return printf("%ld\n",1l*lcm*invsum%MOD),0;
}

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

int main() {

    int n, w, h;
    int imosx[100003] = {0}, imosy[100003] = {0};

    cin >> n >> w >> h;
    for(int i = 0; i < n; i++) {
        int x, y, r; cin >> x >> y >> r;
        imosx[max(0, x - r)]++, imosx[min(w, x + r)]--;
        imosy[max(0, y - r)]++, imosy[min(h, y + r)]--;
    }

    for(int i = 1; i <= h; i++) imosy[i] += imosy[i - 1];
    for(int i = 1; i <= w; i++) imosx[i] += imosx[i - 1];

    bool ret = *min_element(imosx, imosx + w);
    ret = ret || *min_element(imosy, imosy + h);

    cout << (ret ? "Yes" : "No") << endl;
}



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

public class Hello
{
    public static void Main()
    {
        Calc calc = new Calc();

        int n = int.Parse(Console.ReadLine());
        List<string> number = new List<string>();

        for (int i = 0; i < n * 2; i++)
        {
            number.Add(Console.ReadLine());
        }

        for (int i = 0; i < n; i++)
        {
            string ans = calc.Judge(number[i * 2], number[i * 2 + 1]);
            Console.WriteLine(ans);
        }
    }      
}

class Calc
{
    internal string Judge(string num1, string num2)
    {
        int digit = 80;
        string ans = Sum(num1, num2);
        if (ans.Length > digit)
        {
            ans = "overflow";
        }

        return ans;
    }

    internal string Sum(string num1, string num2)
    {
        List<char> char1 = num1.Reverse().ToList();
        List<char> char2 = num2.Reverse().ToList();
        List<string> sum = new List<string>();

        string ans;
        int digit;
        int carryup = 0;

        if (char1.Count() > char2.Count())
        {
            digit = char1.Count;
            for (int i = char2.Count(); i < digit; i++)
            {
                char2.Add(char.Parse("0"));
            }
        }
        else if (char1.Count() < char2.Count())
        {
            digit = char2.Count;
            for (int i = char1.Count(); i < digit; i++)
            {
                char1.Add(char.Parse("0"));
            }
        }
        else
        {
            digit = char1.Count;
        }

        for (int i = 0; i < digit; i++)
        {
            int sum_int = int.Parse(char1[i].ToString()) + int.Parse(char2[i].ToString()) + carryup;
            sum.Add((sum_int%10).ToString());
            if (sum_int/10 < 1)
            {
                carryup = 0;
            }
            else
            {
                carryup = 1;
            }
        }

        if (carryup == 1)
        {
            sum.Add("1");
        }

        sum = Enumerable.Reverse(sum).ToList();
        ans = string.Join("",sum);
        return ans;

    }

}


Measured memory_bytes: 14224
#include <stdio.h>
#define N_MAX 2000
void merge_sort(int *a, int l, int r) {
	int b[N_MAX + 1];
	for(int k = 1; k <= r - l; k *= 2) {
		int s = l, t = l + k;
		while(t <= r) {
			int so = t, to = t + k <= r + 1 ? t + k : r + 1;
			for(int i = s; i < to; ++i) {
				if(a[s] <= a[t]) {
					b[i] = a[s++];
					if(s == so) {
						for(int j = i + 1; j < to; ++j) {
							b[j] = a[t++];
						}
						break;
					}
				} else {
					b[i] = a[t++];
					if(t == to) {
						for(int j = i + 1; j < to; ++j) {
							b[j] = a[s++];
						}
						break;
					}
				}
			}
			s = t;
			t = s + k;
		}
		for(int i = l; i < s; ++i) {
			a[i] = b[i];
		}
	}
	return;
}
int less_bound(int *a, int l, int r, int k) {
	int s = l, t = r;
	while(s <= t) {
		int m = (s + t) / 2;
		if(a[m] < k) {
			s = m + 1;
		} else {
			t = m - 1;
		}
	}
	return t >= l ? t : 0;
}
int main(int argc, char **argv) {
	int n;
	scanf("%i", &n);
	int l[N_MAX + 1];
	for(int i = 1; i <= n; ++i) {
		scanf("%i", &l[i]);
	}
	merge_sort(l, 1, n);
	for(int i = 1; i <= n; ++i) {
	}
	int ans = 0;
	for(int i = 1; i <= n - 2; ++i) {
		for(int j = i + 1; j <= n - 1; ++j) {
			int k = less_bound(l, j + 1, n, l[i] + l[j]);
			k && (ans += k - j);
		}
	}
	printf("%i\n", ans);
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, A[100001], ans=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    ans += (A[1]/2);
    A[1] %= 2;

    ll judge;

    for(i=2; i<=N; i++){
        ans += min(A[i-1],A[i]);
        A[i] -= min(A[i-1],A[i]);
        ans += (A[i]/2);
        A[i] %= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int a, b, ans;
  cin >> a >> b;
  rep(i,2) {
    ans += max(a,b);
    if(ans == a)
      a--;
    else b--;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    int score = 0, penalty = 0;
    vector<int> wa(n, 0);
    rep(i, m)
    {
        int p;
        string s;
        cin >> p >> s;
        p--;

        if (wa[p] >= 0)
        {
            if (s[0] == 'W')
            {
                wa[p]++;
            }
            else
            {
                score++;
                penalty += wa[p];
                wa[p] = -1;
            }
        }
    }

    cout << score << " " << penalty << endl;
    return 0;
}

Measured memory_bytes: 768
n,a,b,c=map(int,input().split())
L=[int(input()) for _ in range(n)]
ans=10**9
for x in range(4**n):
    A,B,C=0,0,0
    cost=0
    for i in range(n):
        r=x%4
        x//=4
        if r==1:
            A+=L[i]
        elif r==2:
            B+=L[i]
        elif r==3:
            C+=L[i]
        if r>0:
            cost+=10
    if A==0 or B==0 or C==0:
        continue
    cost+=-30+abs(A-a)+abs(B-b)+abs(C-c)
    ans=min(ans,cost)
print(ans)


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	vector<P> def(n);
	rep(i, n) cin >> def[i].first >> def[i].second;//first = a;second = b
	sort(def.begin(), def.end());
	ll ans = 0;
	ll res = 0;
	rep(i, n) {
		while (res < m && def[i].second > 0) {
			res++; def[i].second--;
			ans += def[i].first;
		}
	}
	//rep(i, n) cout << def[i].first << def[i].second << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var q = o.a();
  var s = o.a(1);
  var d = o.m(q,1);
  var ok = n, ng = -1;
  var ans = n;
  while(ok-ng > 1){
    var m = ok+ng >> 1;
    var t = m;
    for(var i = 0; i < q; i++){
      if(s[t] === d[i][0]){
        if(d[i][1] === "L"){
          if(t === 0){
            ng = m;
            break;
          }
          t--;
        }
        else{
          if(t === n-1){
            break;
          }
          t++;
        }
      }
    }
    if(ng !== m)ok = m;
  }
  ans -= ok;
  ok = -1; ng = n;
  while(ng-ok > 1){
    var m = ok+ng >> 1;
    var t = m;
    for(var i = 0; i < q; i++){
      if(s[t] === d[i][0]){
        if(d[i][1] === "L"){
          if(t === 0){
            break;
          }
          t--;
        }
        else{
          if(t === n-1){
            ng = m;
            break;
          }
          t++;
        }
      }
    }
    if(ng !== m)ok = m;
  }
  ans += ok - n + 1;
  return ans;
}

Measured memory_bytes: 59080
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		ArrayList<Integer> lList = new ArrayList<>();

		for (int index = 1; index <= N; index++) {
			int n = sc.nextInt();
			lList.add(n);
		}

		Collections.sort(lList);

		for (int x = 0; x < (N - 1); x++) {
			if (lList.get(x).equals(lList.get(x + 1))) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 82976
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define W(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll bpow(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
vvl mat_mul(vvl mat1,vvl mat2,ll mod1){
        vvl res(sz(mat1),vl(sz(mat2[0]),0));
        far(i,0,sz(mat1)-1){
                far(j,0,sz(mat2[0])-1){
                        far(k,0,sz(mat1[0])-1){
                                res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%mod1)%mod1;          
                        }   
        }   
        }   
        return res;
}
vvl mat_exp(vvl mat,ll p,ll mod1){ 
        vvl res(sz(mat),vl(sz(mat[0]),0));
        far(i,0,sz(mat)-1) res[i][i]=1;
        while(p>0){
                if(p&1) res=mat_mul(res,mat,mod1);   
                mat=mat_mul(mat,mat,mod1);
                p>>=1;
        }   
        return res;
}
const int N=1e6+5;
ll n,m,q,t,k,x,y,z;
int main()
{
	fio;
	cin >> m >> n;
	vvi comb(20);	
	far(i,1,n){
		cin >> x;
		far(j,1,x) cin >> y,comb[i].pb(y);
	}
	vi p(20);
	far(i,1,n) cin >> p[i];
	bool tr[12];
	y=0;
	far(i,0,(1<<m)-1){
		far(j,0,m-1) tr[j+1]=(1<<j)&i;
		z=0;
		far(j,1,n){
			int cnt=0;
			for(auto it:comb[j]) cnt+=tr[it];
			if(cnt%2==p[j]) z++;
		}
		if(z==n) y++;
	}
	cout << y << nl;
}


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

int main() {
	int a,b;
	while(1){
		cin>>a>>b;
		if(a==0 && b==0) break;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(i==0||i==a-1||j==0||j==b-1){
					cout<<'#';
				} else {
					cout<<'.';
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

#input = sys.stdin.readline
#import numpy as n
import bisect



def main():

    N,M,K= map(int,input().split())

    A = list(map(int,input().split()))
    B = list(map(int, input().split()))
    cumA=[0]*(len(A)+1)
    cumB = [0] * (len(B)+1)
    tempA=0
    for i in range(1,len(A)+1):
        cumA[i]=tempA+A[i-1]
        tempA+= A[i-1]
    tempB = 0
    for i in range(1,len(B)+1):
        cumB[i] = tempB + B[i-1]
        tempB+= B[i-1]
#    print(cumB)
    ans =0
    for i in range(len(A)+1):
        res = K - cumA[i]
        if res<0:
            break
        b_read = bisect.bisect_right(cumB,res)
        ans =max( i + b_read,ans)
 #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))

    print(ans-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 115736
#include <cstdio>
#include <iostream>

int c[301000];
int a[301000], st[301000], top, n;

void add(int x) {for(int i = x; i <= n; i += i & -i) c[i]++;}
int query(int x) {int ans = 0;for(int i = x; i; i -= i & -i) ans += c[i]; return ans;}

bool check1()
{
	for(int i = 1; i <= n; i++)
	{
		if((a[i] - i) & 1) return false;
	}
	return true;
}

bool check2()
{
	for(int i = 1; i <= n - 2; i++)
	{
		if(a[i] != i && a[i + 1] != i + 1 && a[i + 2] != i + 2) return false;
	}
	return true;
}

bool check3()
{
	long long sum = 0;
	for(int i = n; i >= 1; i--)
	{
		sum += query(a[i]);
		add(a[i]);
	}
	if(sum % 3 != 0) return false;
	return true;
}

bool check4()
{
	top = 0;
	st[++top] = a[1];
	for(int i = 3; i <= n; i += 2)
	{
		if(st[top] > a[i]) st[++top] = a[i];
		else
		{
			int l = 1, r = top + 1;
			while(l < r)
			{
				int mid = l + r >> 1;
				if(st[mid] < a[i]) r = mid;
				else l = mid + 1;
			}
			st[r] = a[i];
		}
	}
	if(top > 2) return false;
	top = 0;
	st[++top] = a[2];
	for(int i = 2; i <= n; i += 2)
	{
		if(st[top] > a[i]) st[++top] = a[i];
		else
		{
			int l = 1, r = top + 1;
			while(l < r)
			{
				int mid = l + r >> 1;
				if(st[mid] < a[i]) r = mid;
				else l = mid + 1;
			}
			st[r] = a[i];
		}
	}
	if(top > 2) return false;
	return true;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	if(check1() && check2() && check3() && check4()) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

const int INF = 1001001001;

int main() {
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];
    ll ans = INF;
    for (int bit = 0; bit < (1 << d); bit++) {
        ll sum = 0, cnt = 0;
        P t = { 0, 0 };
        for (int i = 0; i < d; i++) {
            if (bit >> i & 1) {
                sum += (i + 1) * 100 * p[i] + c[i];
                cnt += p[i];
            } else {
                t = { (i + 1) * 100, p[i] - 1 };
            }
        }
        if (sum >= g) {
            ans = min(ans, cnt);
            continue;
        }
        if (t.first * t.second + sum < g) continue;
        cnt += ceil((double)(g - sum) / t.first);
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    double N;
    cin >> N;
    double plog1 = log2(N);
    double plog2 = floor(plog1);
    double ans = pow(2.0, plog2);
    cout << (int)ans << endl;

    return 0;
}

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

signed main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    int ans = 0;
    rep(i, h) cin >> s[i];

    rep(is, 1<<h)rep(js, 1<<w){
        int cnt = 0;
        rep(i, h)rep(j, w){
            if(is>>i & 1) continue; /* i行が消された場合 */
            if(js>>j & 1) continue; /* j列が消された場合 */
            if(s[i][j] == '#') cnt++;
        }
        if(cnt == k) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int H,W;
    cin >> H >> W;
    int dist[10][10];
    rep(i,0,10)rep(j,0,10)cin >> dist[i][j];
    rep(i,0,10)rep(j,0,10)rep(k,0,10)dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
    int sum = 0;
    rep(i,0,H)rep(j,0,W){
        int c;
        cin >> c;
        if(c == -1)continue;
        sum += dist[c][1];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define int long long
#define forn(i,a,b) for (int i=a; i<b; i++)
#define MOD 1000000000+7;

using namespace std;

void solve (){
	int n;
	cin>>n;
	vector <char> v(26);
	iota(all(v),'A');
	string s;
	cin>>s;
	forn(i,0,s.size()) {
		int cnt=0,j=s[i]-'A';
		while (cnt!=n) {
			j++;
			cnt++;
			if (j==26) j=0;
		}
		s[i]=v[j];
	}
	cout<<s<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   
    int t=1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

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

int n;
vector < int > V[maxN];

int col[maxN];
queue < int > q;

int ans[2];

void bfs()
{
    col[1] = 1;
    col[n] = 2;
    q.push(1);
    q.push(n);
    while (!q.empty())
    {
        int nod = q.front();
        q.pop();
        for (int son : V[nod])
            if (!col[son])
            {
                col[son] = col[nod];
                ++ ans[col[son] - 1];
                q.push(son);
            }
    }
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; ++ i)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        V[x].push_back(y);
        V[y].push_back(x);
    }

    bfs();
    if (ans[0] <= ans[1])
        printf("Snuke\n");
    else
        printf("Fennec\n");
    return 0;
}


Measured memory_bytes: 6272
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int []a = new int [n];
		
		for(int i = 0; i < n ;i++) {
			a[i] = sc.nextInt();
		}
		
		int [][]b = new int [m][2];
		
		for(int i = 0 ; i < m ;i++) {
			b[i][0] = sc.nextInt();
			b[i][1] = sc.nextInt();
		}
		
		Arrays.sort(b, (x,y) -> Integer.compare(x[1],y[1]));
		Arrays.sort(a);
		
		long sum = 0;
		
		int j = b[m-1][0];// 何回数を置き換えられるか
		int k = m-1;      // どの数を置き換えるか
		
 		for(int i = 0 ; i < n ;i++) {
 			if(b[k][1] <= a[i]){
 				sum += a[i];
 				continue;        //置き換える必要がないなら置き換えない
 			}
 			else {
 				sum += b[k][1];   //置き換えて加える、回数を減らす
 				j--;
 				if(j == 0) {
 					if(k == 0) {
 						b[0][1] = -1;    //これ以上置き換える数がないなら絶対置き換えないようにする
 						continue;
 					}
 					k--;              //これ以上減らせないなら配列の次数を一つ下げる
 					j = b[k][0];      //初期化する
 				}
 			}
		}
 		
 		System.out.println(sum);
		

	}

}


Measured memory_bytes: 96112
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		char[] c = S.toCharArray();
		Arrays.sort(c);

		if (c[0] == c[1] && c[2] == c[3] && c[1] != c[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
int N;
int cnt=0;
void check(int64_t x){
    string t=to_string(x);
    set<int>k;
    for(int i=0;i<t.size();i++){
      k.insert(t[i]);
    }
    if(k.size()<=2){return;}
    else if(x<=N){cnt++;}
    return;
  }
void dfs(int64_t x){
  check(x);
  if(x<=1000000000){
    dfs(10*x+3);
    dfs(10*x+5);
    dfs(10*x+7);
  }
}
int main(){
  cin>>N;
  dfs(0);
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;

int n, ar[300005];
long long ans;

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=3*n;i++){
        scanf("%d", ar+i);
    }
    sort(ar+1, ar+3*n+1);
    for(int i=n+1;i<=n+2*n-1;i+=2)ans += ar[i];
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <atcoder/math>

using namespace std;

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int64_t n;
    cin >> n;
    if (n == 1){
        puts("1");
        return 0;
    }
    auto res = factorize(2 * n);
    sort(res.begin(), res.end());

    int64_t ans = 1e18;
    for (const auto &x: res){
        auto y = (2 * n) / x;
        if (gcd(x, y) != 1 or y == 1)
            continue;
        ans = min(ans, (int64_t)atcoder::crt({0, y - 1}, {x, y}).first);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3740
#include <stdio.h>

int main(void)
{
	int i, j, h, hill[10];
	for(i = 0; i < 10; i++)
		scanf("%d", &hill[i]);
		
	for(i = 0; i < 3; i++){
		for(j = i+1; j < 10; j++){
			
			if(hill[i] < hill[j]){
				h = hill[i];
				hill[i] = hill[j];
				hill[j] = h;
			}
		}
	}
	for(i = 0; i < 3; i++)
		printf("%d\n", hill[i]);
	return 0;
}

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

int main(){
  ll mod=1e9+7;
  ll ans=1;
  int n;
  string s;
  cin>>n>>s;
  int vec[2*n];
  for(int i=0;i<2*n;i++){
    if(s[i]=='W'){
      vec[i]=1;
    }
    else{
      vec[i]=0;
    }
  }
  if(vec[0]==1){
    ans=0;
  }
  int nowedge=1;
  for(int i=1;i<2*n;i++){
    if((vec[i]+nowedge)%2==0){
      nowedge++;
    }
    else{
      ans*=nowedge;
      ans%=mod;
      nowedge--;
      if(nowedge<0){
        ans*=0;
      }
    }
  }
  if(nowedge!=0){
    ans=0;
  }
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4504
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<int> A(N+1);
    rep(i,N) cin >> A[i];


    rep(i,K) {
        vector<int> B(N+1);
        rep(j,N) {
            int l = max(0,j-A[j]);
            int r = min(N,j+A[j]+1);
            B[l] += 1;
            B[r] -= 1;
        }
        rep(j,N) {
            B[j+1] += B[j];
        }
        bool ok = true;
        rep(j,N) {
            if (B[j]!=N) ok = false;
        }
        if (ok) {
            rep(j,N) cout << B[i] << " ";
            cout << ln;
            return 0;
        }
        swap(A,B);
    }

    rep(i,N) cout << A[i] << " ";
    cout << ln;
}

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

N=int(input())
A=list(map(int,input().split()))

SCORE=[[None for i in range(N+1)] for j in range(N+1)]

def score(i,j,k,l):#A[i:j)が残っているときのscore,1:Xの手番,-1:Yの手番
    #print(i,j,k,l)
    
    if SCORE[i][j]!=None:
        return SCORE[i][j]+k
    if i==j:
        SCORE[i][j]=0
        return k

        

    if l==1:
        SCORE[i][j]=max(score(i+1,j,k+A[i],-l),score(i,j-1,k+A[j-1],-l))-k
        return SCORE[i][j]+k
    if l==-1:
        SCORE[i][j]=min(score(i+1,j,k-A[i],-l),score(i,j-1,k-A[j-1],-l))-k
        return SCORE[i][j]+k



hand=N%2
for i in range(N+1):
    for j in range(N-i+1):
        score(j,j+i,0,(-1)**(j+j+i+hand))

print(SCORE[0][N])

Measured memory_bytes: 173576
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

bool which(char c){
    bool wh=0;
    if(c=='1') wh=1;
    return wh;
}

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i=0;i<n;++i){
        cin >> h.at(i);
    }
    int res=0;
    int before_res=res;
    while(1){
        int i=0;
        while(i<n){
            if(h.at(i)==0) ++i;
            else{
                ++res; //区間の始まり
                while(i<n&&h.at(i)>0){
                    h.at(i)--;
                    ++i;
                }
            }
        }
        if(before_res==res)
            break;
        before_res = res;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
string s, t;

int32_t main(){_

   int n, m;
   cin >> n >> m;

   int ans = (n * (n - 1)) / 2;
   ans += (m * (m - 1)) / 2;

   cout<<ans;

   return 0;
}

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

public class prog
{
    public static void Main()
    {
       int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
       int A = input[0];
       int B = input[1];
       int C = input[2];
       
       Console.WriteLine(Math.Max(0,C-(A-B)));
    }
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll x[5];
	REP(i,5) cin >> x[i];
	ll ret = 0;
	REP(i,5) if(x[i]==0) ret = i+1;
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 998244353
using namespace std;

int n;
int h[100001];
vector <int> dp(100001, 2e9);

int main()
{
    cin>>n;

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

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i=2;i<n;i++){
        dp[i] = min(dp[i], min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])));
    }

    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, k = LI()
G = LIR(n)

def mat_mul(a, b):
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I):
        for j in range(J):
            for k in range(K):
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= mod
    return c

def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]
    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1
    return y

ans = 0
GG = mat_pow(G, k)
for i in range(n):
    for j in range(n):
        ans += GG[i][j]

print(ans % mod)










Measured memory_bytes: 107088
use std::io;
use std::str::FromStr;

const MOD: u64 = 1000000007;

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

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}


fn main() {
    let n: usize = input();
    let a_vec = input_vec();
    let mut a_bit_vec: Vec<Vec<char>> = Vec::new();
    for a in a_vec {
        let bit: String = format!("{:b}", a);
        let mut bit: Vec<char> = bit.chars().collect();
        bit.reverse();
        a_bit_vec.push(bit);
    }

    let mut sum = 0;
    for i in 0..60 {
        let mut zero = 0;
        let mut one = 0;
        for a_bit in &a_bit_vec {
            if a_bit.len() > i {
                if a_bit[i] == '0' {
                    zero += 1;
                } else {
                    one += 1;
                }
            } else {
                zero += 1;
            }
        }    
        // println!("{}, {}", zero, one);
        sum += 2u64.pow(i as u32) % MOD * zero % MOD * one % MOD;
        sum %= MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 92404
n = int(input())

l = [int(i) for i in input().split()]

ans = [0]*(n+1)
ans[1] = abs(l[0]-l[1])
for i in range(2,n):
    ans[i]=min(ans[i-1]+abs(l[i-1]-l[i]),ans[i-2]+abs(l[i-2]-l[i]))


print(ans[-2])



Measured memory_bytes: 52208
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans =0;

    rep(i,n-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ans ++;
        }
    }

    dunk(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f0(i,a,n) for(i=a;i<n;i++)
#define f1(I,a,b) for(i=a;i<=b;i++)
#define stp setprecision
#define nl endl
#define ipt(a) for(i=0;i<n;i++)cin>>a[i];
#define pll pair<ll,ll>
#define vl vector<ll>
#define mp map<ll,ll>
int main()
{
    fast;
    ll t;
    ll n;
    cin>>n;
    ll a[n],b[n],i,c=0;
    f0(i,0,n)
    {
        cin>>a[i]>>b[i];
        
    }
    for(i=0;i<=n-3;i++)
    {
        if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
        {
            c=1;
            break;
        }
    }
    if(c)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	ll sum = (ll)n * (n+1) / 2;
	// cerr << sum << endl;
	sum -= n;
	cout << sum << endl;
	return 0;
}

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

#define ll long long int
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll>
#define pll pair<ll,ll>
int main(){
     int t;
     cin>>t;
     if(t>=30)
     cout<<"Yes";
     else
     cout<<"No";
 }


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

int main(){
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB")cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

vector<pair<int, int>> D[100005];
bool U[100005];
bool I[100005];
ll x[100005];

bool check(int i)
{
	if (U[i])return true;
	U[i] = true;
	REP(j, D[i].size())
	{
		pair<int, int> n = D[i][j];
		if (I[n.first])
		{
			if (x[n.first] != x[i] + n.second)
			{
				return false;
			}
		}
		I[n.first] = true;
		x[n.first] = x[i] + n.second;

		if (!check(n.first))
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int N, M;
	cin >> N >> M;
	REP(i, M)
	{
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		D[l].push_back(pair<int, int>(r, d));
		D[r].push_back(pair<int, int>(l, -d));
	}
	I[0] = true;
	REP(i, N)
	{
		if (!check(i))
		{
			cout << "No" << endl;
			return 0;
		}
	}

	ll max = 0, min = 0;
	REP(i, N)
	{
		if (I[i])
		{
			max = std::max(max, x[i]);
			min = std::min(min, x[i]);
		}
	}
	if (max - min > 1000000000)
	{
		cout << "No" << endl;
		return 0;
	}

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

Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

ll comb(int n, int r){
  ll x = 1;
  if(2*r>n) r = n - r;
  rep(i,r){
    x *= n - i;
    x /= i + 1;
  }
  return x;
}

int main(){
  ll N;
  int A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  rep(i,N){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end(), greater<ll>());
  long double sum = 0.0;
  rep(i,A){
    sum += v.at(i);
  }
  int num = 0;
  int chosen = 0;
  bool all_equal = true;
  int index = A;
  rep(i,N){
    if(v.at(i)==v.at(A-1)){
      num++;
      if(i<A) chosen++;
    }
    if(i<A&&v.at(i)!=v.at(0)) all_equal = false;
    if(i>=A&&all_equal&&v.at(i)==v.at(A-1)){
      index = max(index,i+1);
    }
  }
  ll mtd = 0;
  if(all_equal){
    for(int i=A; i<=min(index,B); i++){
      mtd += comb(num,i);
    }
  }else{
    mtd += comb(num,chosen);
  }
  cout.precision(10);
  cout << fixed << sum/A << endl;
  cout << mtd;
  return 0;
}

Measured memory_bytes: 3732
k = int(input())
s = list(input())

S = len(s)
if S <= k:
    mojiretu = ''
    for x in s:
        mojiretu += x
    print(mojiretu)
else:
    T =s[:-(S-k)]
    mojiretu = ''
    for x in T:
        mojiretu += x
    print(mojiretu + '...')

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

int main(){

    int i,j;
    char moji[1201],ch;
    i=0; 
    
     while(1){
		 scanf("%c",&ch);
         moji[i]=ch;
         if(ch=='\n') break;
	  ++i;
	 }
	    
    for (j=0;j<i;j++){
		if (islower(moji[j])){
			moji[j]=toupper(moji[j]);
		}else if(isupper(moji[j])){
			moji[j]=tolower(moji[j]);
	    }
	}
	 
	 for(j=0;j<i;j++){
	  printf("%c",moji[j]);
     }
      printf("\n");
	  
    
	return 0;
}

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

typedef long long ll;

const int N = 1e5 + 5;
ll n, ans;
int Arr[N];
int dp[2][N][2];
// L & R - index - first or second?

void calc(int d) {
	vector <int> vec1, vec2, add;

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

		while (vec2.size() && Arr[vec2.back()] < Arr[i])
			vec2.pop_back();
		if (vec2.size())
			dp[d][i][1] = max(dp[d][i][1], vec2.back());


		while (vec1.size() && Arr[vec1.back()] < Arr[i]) {
			add.push_back(vec1.back());
			vec1.pop_back();
		}

		while (add.size()) {
			while (vec2.size() && Arr[vec2.back()] < Arr[add.back()])
				vec2.pop_back();

			vec2.push_back(add.back());
			add.pop_back();
		}

		if (vec1.size()) {
			dp[d][i][0] = vec1.back();
			if (1 < vec1.size())
				dp[d][i][1] = max(dp[d][i][1], vec1[vec1.size() - 2]);
		}
		vec1.push_back(i);
	}

	vec1.clear();
	vec2.clear();
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> Arr[i];

	calc(0);
	reverse(Arr, Arr + n);
	calc(1);
	reverse(Arr, Arr + n);
	for (int i = 0; i < n; i++)
		for (int id = 0; id < 2; id++)
			if (dp[1][i][id] != -1)
				dp[1][i][id] = n - 1 - dp[1][i][id];
	for (int i = 0, j = n - 1; i < j; i++, j--)
		swap(dp[1][i], dp[1][j]);
	
	for (int i = 0; i < n; i++) {
		ll l, r;
		if (dp[0][i][0] != -1) {
			l = dp[0][i][1] + 1;
			r = dp[1][i][0] - 1;
			if (dp[1][i][0] == -1)
				r = n - 1;

			ans += (dp[0][i][0] - l + 1) * (r - i + 1) * Arr[i];
		}
		if (dp[1][i][0] != -1) {
			l = dp[0][i][0] + 1;
			r = dp[1][i][1] - 1;
			if (dp[1][i][1] == -1)
				r = n - 1;

			ans += (i - l + 1) * (r - dp[1][i][0] + 1) * Arr[i];
		}
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5676
N = int(input())
A=[0]*100
for i in range(1,N+1):
  first=int(str(i)[0])
  last=int(str(i)[-1])
  A[first*10+last]+=1
score=0
for i in range(10):
  for j in range(10):
    score+=A[i*10+j]*A[j*10+i]
print(score)

Measured memory_bytes: 73420