akhauriyash/Code-Regression huggingface dataset:
(defmacro read-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))


(defun count-happy-people (s)
  (labels ((inner (s &optional (cnt 0))
             (cond
               ((null (cdr s)) cnt)
               ((char-equal
                 (first s)
                 (second s))
                (inner (rest s) (1+ cnt)))
               (t
                (inner (rest s) cnt)))))
    (inner s)))

(defun solve (n k s)
  (let ((start (count-happy-people s)))
    (min (+ start (* k 2))
         (1- n))))


(defun main ()
  (let* ((n (read))
         (k (read))
         (s (concatenate 'list (read-line))))
    (format t "~a~%" (solve n k s))))

(main)


Measured memory_bytes: 27380
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {

  int N; cin >> N;
  string s = to_string(N);
  for(auto &c: s){
    if(c == '1')
      cout << 9;
    else
      cout << 1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

struct Edge {
    int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue;
        if (k == c) k++;
        ans[ei] = k;
        k++;
        dfs(u,ans[ei],v);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 11056
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str = scan.next();
        //System.out.println(str);
        boolean check = false;

        for(int i = 0; i < str.length(); i++){
            if(i % 2 == 1){
                if(str.charAt(i) != 'L' && str.charAt(i) != 'U' && str.charAt(i) != 'D'){
                    check = false;
                    break;
                }
                else{
                    check = true;
                }
            }
            else{
                if(str.charAt(i) != 'R' && str.charAt(i) != 'U' && str.charAt(i) != 'D'){
                    check = false;
                    break;
                }
                else{
                    check = true;
                }
            }
        }
        if(check == true){
            System.out.print("Yes");
        }
        else{
            System.out.print("No");
        }

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> R_X(N);
    rep(i, N) cin >> R_X.at(i);
    vector<int> R_Y(M);
    rep(i, M) cin >> R_Y.at(i);

    bool war;
    repi(Z, X + 1, Y + 1) {
        war = false;
        rep(i, N) {
            if(R_X.at(i) >= Z) {
                war = true;
            }
        }
        rep(i, M) {
            if(R_Y.at(i) < Z) {
                war = true;
            }
        }
        if(war == false) {
            dump(Z);
            break;
        }
    }

    cout << (war ? "War" : "No War") << endl;
}


Measured memory_bytes: 256
/*input
10 4 8 5
7 2 3 6 1 6 5 4 6 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll n,m,v,p;
ll a[maxn];

vector<int> vv;
bool check(int j){
	ll mx=a[j]+m;
	vv.clear();
	REP(i,n-(p-1)) if(i!=j){
		if(a[i]>mx) return 0;
		vv.pb(mx-a[i]);
	}
	ll cnt=max(0LL,v-p);
	sort(ALL(vv));
	ll ans=INF64;
	ll sum=0;
	REP(i,SZ(vv)){
		sum+=vv[i];

		if(cnt-(SZ(vv)-(i+1))>0) ans=min(ans,sum/(cnt-(SZ(vv)-(i+1))));
	}
	if(ans>=m) return 1;
	else return 0;
}

int main(){
	IOS;
	cin>>n>>m>>v>>p;
	REP(i,n) cin>>a[i];
	sort(a,a+n);

	int l=-1,r=n-p;
	while(l!=r-1){
		int mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid;
	}
	cout<<n-r<<'\n';
	return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll n;
  cin>>n;
  string s;
  P a[n];
  vector<P> b,c;
  ll s1,s2;
  
  rep(i,n){
    s1=0;
    s2=0;
    cin>>s;
    rep(j,s.size()){
      if(s[j]=='('){
        s1++;
      }
      else if(s[j]==')'&&s1==0){
        s2++;
      }
      else{
        s1--;
      }
    }
    a[i]=P(s1,s2);
    if(s1-s2>=0) b.push_back(P(s2,s1));
    else c.push_back(P(s1,s2));  
  }
  
  sort(all(b));
  sort(all(c));
  
  s1=0;
  s2=0;
  int ch=0;
  
  rep(i,b.size()){
    s2+=b[i].fi;
    
    if(s1<s2) ch++;
    s1+=b[i].se;
    
    if(s1<s2) ch++;
  }
  
  rep(i,c.size()){
    int j=c.size()-i-1;
    s2+=c[j].se;
    
    if(s1<s2) ch++;
    s1+=c[j].fi;
    
    
    if(s1<s2) ch++;
  }
  
  Ans(ch==0&&s1==s2);
  
  
  
}
  






Measured memory_bytes: 34664
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    double a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<double> v;
    vector<double> u;
    for (int i = 0; i <= 30; i++)
    {
        for (int j = 0; j <= 30; j++)
        {
            int sum = 100 * (a * i + b * j);
            if (sum!=0&&sum <= f)
            {
                v.push_back(sum);
            }
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=0; i<=f; i++){
        for(int j=0; j<=f; j++){
            int sum=c*i+d*j;
            if(sum<=f){
                u.push_back(sum);
            }
        }
    }
    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    double k=e/100;
    double ma=-1;
    int x,y;
    for(int i=0; i<v.size(); i++){
        for(int j=0; j<u.size(); j++){
            if(v[i]+u[j]>f){continue;}
            double g=u[j]/v[i];
            if(g>k){continue;}
            if(g>ma){
                ma=g,x=v[i]+u[j],y=u[j];
            }
        }
    }
    cout<<x<<" "<<y<<endl;
}


Measured memory_bytes: 2420
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
import math
from sys import stdin
input = stdin.readline


def main():
  a, b, x = list(map(int, input().split()))

  # y = 2*(b-(x/a**2))/a
  # yd = 2*x/(a*b**2)
  # print(y, yd)
  if x > 0.5*a*a*b:
    print(math.degrees(math.atan( 2*(b-(x/a**2))/a )))
  else:
    print(90 - math.degrees(math.atan( (2*x/(a*b**2)) )))


if(__name__ == '__main__'):
  main()


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


int main(){
	string s;
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]=='(')ans+=')'!=s[s.size()-1-i];
		else if(s[i]==')')ans+='('!=s[s.size()-1-i];
		else ans+=s[i]!=s[s.size()-1-i];
	}
	if(s.size()%2&&(s[s.size()/2]=='('||s[s.size()/2]==')'))ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int maxI = scanner.nextInt();
		
		for(int i = 0; i < maxI; i ++){
			int a[] = new int[10];
			
			for(int j = 0; j < 10; j ++){
				a[j] = scanner.nextInt();
			}
			int min1 = 0;
			int min2 = 0;
			int j;
			
			for(j = 0; j < 10; j ++){
				if(min1 < a[j])
					min1 = a[j];
				else if(min2 < a[j])
					min2 = a[j];
				else
					break;
			}
			if(j == 10)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
}

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

using namespace std;

int main(){
    int N;
    int color[8] = {0};
    
    int over = 0;
    cin >> N;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a < 3200){
            color[a/400]++;
        }else{
            over++;
        }
    }
    int min = 0, max = 0;
    for(int i=0;i<8;i++){
        if(color[i] > 0)min++; 
    }
    max = min + over;
    if(min == 0) min++;

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int vis[100010];
int main()
{
	for(int i=1;i<=100000;i<<=1)vis[i]=1;
	cin>>n;
	if(vis[n])return puts("No")==2333;
	puts("Yes");
	printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n",n+1,n+1,n+2,n+2,n+3);
	for(int i=4;i<n;i+=2)
	{
		printf("%d %d\n",1,i);printf("%d %d\n",1,i+1);
		printf("%d %d\n",i,n+i+1);printf("%d %d\n",i+1,n+i);
	}
	if(n%2==0)for(int i=2,p;i<=n;++i)
		{
			p=i^1^n;
			if(1<p&&p<n)
			{
				if(i==2)printf("%d %d\n",n,n+i);
				else printf("%d %d\n",n,i);
				printf("%d %d\n",p,n+n);
				break;
			}
		}
	return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int num = r * 100 + g * 10 + b;
        boolean judge = num % 4 == 0;
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 20820
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
Max = 0

for i in range(N):
    sumA1 = sum(A1[:i+1]) 
    sumA2 = sum(A2[i:N])
    tmpMax = sumA1 + sumA2
    if tmpMax > Max:
        Max = tmpMax

print(Max)

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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int Sign(double x) {
        if (x > 0) return 1;
        if (x < 0) return -1;
        return 0;
    }

    static string Calc(Vec2f a, Vec2f b, Vec2f c) {
        var ab = b - a;
        var ac = c - a;

        var q = ab.Cross(ac);
        if (q > 0) return "COUNTER_CLOCKWISE";
        if (q < 0) return "CLOCKWISE";

        // when q = 0

        // |ab||ac|cos(pi) ??§???cos(pi) = -1 ????????§??????????????????
        if (ab.Dot(ac) < 0) return "ONLINE_BACK";

        if (ab.SqrMagnitude() >= ac.SqrMagnitude()) {
            return "ON_SEGMENT";
        }
        return "ONLINE_FRONT";
    }

    static void Main() {
        var xs = ReadInts();
        var p0 = new Vec2f(xs[0], xs[1]);
        var p1 = new Vec2f(xs[2], xs[3]);

        int q = ReadInt();
        for (int i = 0; i < q; i++) {
            var xy = ReadInts();
            var p2 = new Vec2f(xy[0], xy[1]);
            var ans = Calc(p0, p1, p2);
            Console.WriteLine(ans);
        }
    }
}

struct Vec2f {
    public double X { get; private set; }
    public double Y { get; private set; }

    public Vec2f(double x, double y) : this() {
        X = x;
        Y = y;
    }

    public override string ToString() {
        return string.Format("({0}, {1})", X, Y);
    }

    public static Vec2f operator+(Vec2f a, Vec2f b) {
        return new Vec2f(a.X + b.X, a.Y + b.Y);
    }

    public static Vec2f operator-(Vec2f a, Vec2f b) {
        return new Vec2f(a.X - b.X, a.Y - b.Y);
    }

    public static Vec2f operator*(Vec2f a, double t) {
        return new Vec2f(a.X * t, a.Y * t);
    }

    public static Vec2f operator*(double t, Vec2f a) {
        return new Vec2f(a.X * t, a.Y * t);
    }

    // a???b = |a||b|cos??
    public double Dot(Vec2f other) {
        return X * other.X + Y * other.Y;
    }

    public double Cross(Vec2f other) {
        return X * other.Y - Y * other.X;
    }

    public Vec2f Normalized() {
        var m = Magnitude();
        if (m != 0 && m != 1) {
            return new Vec2f(X / m, Y / m);
        }
        return this;
    }

    public double Magnitude() {
        return Math.Sqrt(X * X + Y * Y);
    }

    public double SqrMagnitude() {
        return X * X + Y * Y;
    }

    public static double Distance(Vec2f a, Vec2f b) {
        return (a - b).Magnitude();
    }
}

Measured memory_bytes: 9524
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;++i)cin>>a[i];
  int dp[n];
  for(int i=0;i<n;++i)dp[i]=999999;
  
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;++i){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1];
  return 0;
}



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

using namespace std;

int n,x,y,a[3000];

int main(){
	scanf("%d%d%d",&n,&x,&y);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (n==1) printf("%d\n",abs(a[1]-y));
	else printf("%d\n",max(abs(a[n]-y),abs(a[n-1]-a[n])));
	
	return 0;
}
			

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

int k, size;
int num[1001];
int64_t dp[1001][2][4];
// dp[ 決めた桁数 ][ 未満フラグ ][ 0以外(1-9)==K個 ] :[size][0-1][K] 総数
// 未満フラグ == 0 : ちょうどその数の時。今回は以下なので含む、未満の時は含まない。

bool add(int i, bool smaller, int current_k, int x)
{
  int64_t now = dp[i][smaller][current_k];

  if (x < num[i])
    smaller = true;

  if (x != 0)
    current_k++;

  if (current_k > k)
    return false;

  dp[i + 1][smaller][current_k] += now;
  return true;
}

int main()
{
  string s;
  cin >> s >> k;
  size = s.size();
  
  // cout << s << endl;
  // cout << size << endl;

  rep(i, size)
      num[i] = s[i] - '0';

  //初期条件
  dp[0][0][0] = 1;

  rep(i, size)
  {
    rep(smaller, 2)
    {
      rep(kk, k + 1)
      {
        int max;
        if (smaller)
          max = 9;
        else
          max = num[i];

        rep(x, max + 1)
        {
          add(i, smaller, kk, x);
        }
      }
    }
  }
  // rep(i, size + 1)
  // {
  //   rep(smaller, 2)
  //   {
  //     rep(kk, k + 1)
  //     {
  //       cout << "i" << i << "smaller" << smaller << "kk" << kk << " = " << dp[i][smaller][kk] << endl;
  //     }
  //   }
  // }
  int64_t cnt = dp[size][0][k] + dp[size][1][k];
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int w = scanner.nextInt();
		int h = scanner.nextInt();
		int n = scanner.nextInt();
		int[] y = new int[n];
		int[] x = new int[n];
		int[] sy = new int[n];
		int[] sx = new int[n];
		for (int i = 0; i < n; i++) {
			sx[i] = x[i] = scanner.nextInt();
			sy[i] = y[i] = scanner.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);
		int ax = 0;
		int ay = 0;
		long ans = Long.MAX_VALUE;
		int m = (n - 1) / 2;
		int nm = n/2;
		int[] xx = {x[m],x[nm]};
		int[] yy  ={y[m],y[nm]};
		for (int i = 0; i <= 1; i++) {
			for (int j = 0; j <= 1; j++) {
				long res = 0;
				long max = 0;
				for (int k = 0; k < n; k++) {
					long dis = Math.abs(sx[k] - xx[i]) + Math.abs(sy[k] - yy[j]);
					res += dis * 2;
					max = Math.max(max, dis);
				}
				res -= max;
				if (res < ans) {
					ans = res;
					ax = xx[i];
					ay = yy[j];
				}
			}
		}
		System.out.println(ans);
		System.out.println(ax + " " + ay);
	}
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    for (int i = 0; i < N; i++) cin >> W[i];

    int sum = 0;
    for (int i = 0; i < N; i++) sum += W[i];

    int min = inf;
    for (int i = 1; i < N; i++)
    {
        int s1 = 0;
        for (int j = 0; j < i; j++)
        {
            s1 += W[j];
        }
        if (abs(sum - 2 * s1) < min) min = abs(sum - 2 * s1);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> num(N, -1);
    for(size_t i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        if((N != 1 && s == 1 && c == 0) ||
           (c != num[s - 1] && num[s - 1] != -1)) {
            cout << -1 << endl;
            return 0;
        }
        num[s - 1] = c;
    }
    for(size_t i = 0; i < N; i++) {
        if(i == 0 && num[i] == -1 && N!=1) {
            cout << 1;
        } else if(num[i] == -1) {
            cout << 0;
        } else {
            cout << num[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys
 
def main():
  H,W,K = map(int,input().split())
  a = []
  for i in range(H):
    a.append(sys.stdin.readline())
    
  ans = 0
  for i in range(2**H):
    for j in range(2**W):
      cnt = 0
      for s in range(H):
        for t in range(W):
          if(i >> s) & 1 and (j >> t) & 1 and a[s][t] == "#":
            cnt += 1
      if cnt == K :
        ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 9176
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
long long dp[61][2511];
int main(){
	int n,k;
	cin>>n>>k;
	lol(i,n+1){
		lol(j,2501){
			dp[i][j]=0;
		}
	}dp[0][0]=1;
	lol(u,n){
		int a;cin>>a;
		for(int i=n-1;i>=0;i--){
			lol(j,2501){
				if(i+1<=n&&j+a<2501){
					dp[i+1][j+a]+=dp[i][j];
				}
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		ans+=dp[i][i*k];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
using namespace std;
long long m = 1e9 + 7;
int main() {
    long long n, k;
    cin>>n>>k;

    long long ans = 0;
    long long maxsum = (n*(n+1))/2;

    for(long long i=k;i<=n+1;i++) {
        long long minsum = (i*(i-1))/2;


        long long remaining = n + 1 - i;
        long long remaining_sum = (remaining * (remaining - 1))/2;

        long long current_max_sum = maxsum - remaining_sum;

        ans = (ans + (current_max_sum - minsum + 1)%m) % m;
    }


    cout<<ans%m;
}

Measured memory_bytes: 3168
from sys import stdin

lines = stdin.readlines()
k, n = [int(x) for x in lines[0].rstrip().split()]
a = [int(x) for x in lines[1].rstrip().split()]

diffs = [int(a[x+1]-a[x]) for x in range(len(a)-1)]
diffs.append(k - a[-1] + a[0])

print(k - max(diffs))

Measured memory_bytes: 24944
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int INF = 100000;
typedef pair<int, int> P;
int w, h;
int ny,nx;
int main()
{
    while (cin >> w >> h)
    {
        int dis[h][w];
        bool wall[2][h][w];
        if (w == 0 && h == 0)
            return 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                dis[i][j] = INF;
            }
        }
        for (int i = 0; i < 2 * h - 1; i++)
        {
            //横
            if (i % 2 == 0)
            {
                for (int j = 0; j < w - 1; j++)
                {
                    cin >> wall[0][i / 2][j];
                }
            }
            //縦
            else
            {
                for (int j = 0; j < w; j++)
                {
                    cin >> wall[1][i / 2][j];
                }
            }
        }
        dis[0][0] = 0;
        queue<P> que;
        que.push(P(0, 0));
        while (!que.empty())
        {
            P p = que.front();
            que.pop();
            ny = p.first;
            nx = p.second;
            if (ny - 1 >= 0 && wall[1][ny - 1][nx] == 0 && dis[ny-1][nx] == INF)
            {
                dis[ny - 1][nx] = dis[ny][nx] + 1;
                que.push(P(ny - 1, nx));
            }
            if (ny + 1 < h && wall[1][ny][nx] == 0 && dis[ny + 1][nx] == INF)
            {
                dis[ny + 1][nx] = dis[ny][nx] + 1;
                que.push(P(ny + 1, nx));
            }
            if (nx - 1 >= 0 && wall[0][ny][nx - 1] == 0 && dis[ny][nx - 1] == INF)
            {
                dis[ny][nx - 1] = dis[ny][nx] + 1;
                que.push(P(ny, nx - 1));
            }
            if (nx + 1 < w && wall[0][ny][nx] == 0 && dis[ny][nx + 1] == INF)
            {
                dis[ny][nx + 1] = dis[ny][nx] + 1;
                que.push(P(ny, nx + 1));
            }
        }
        if (dis[h - 1][w - 1] == INF)
            cout << 0 << endl;
        else
            cout << dis[h - 1][w - 1]+1 << endl;
    }
}


Measured memory_bytes: 3064
n, k, l = [int(item) for item in input().split()]
pq = [[int(item) for item in input().split()] for _ in range(k)]
rs = [[int(item) for item in input().split()] for _ in range(l)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UFA = UnionFind(n)
UFB = UnionFind(n)
for p, q in pq:
    UFA.union(p-1, q-1)
for r, s in rs:
    UFB.union(r-1, s-1)

par = []
for i in range(n):
    par.append([UFA.find(i), UFB.find(i), i])
par = sorted(par, key=lambda x:(x[0], x[1]))
prev_a, prev_b = -1, -1
ans = [0] * n
count = 0
member = []
for a, b, index in par:
    if prev_a != a or prev_b != b:
        for mem in member:
            ans[mem] = count
        count = 1
        member = [index]
        prev_a = a
        prev_b = b
    else:
        member.append(index)
        count += 1
for mem in member:
    ans[mem] = count
print(" ".join([str(item) for item in ans]))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

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

  vector<int> ps(n), qs(n);
  for (int i = 0; i < n; i++) {
    cin >> ps[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> qs[i];
  }

  int index = 0;

  int pi = -1;
  int qi = -1;
  if (xs == ps) pi = 0;
  if (xs == qs) qi = 0;

  while (next_permutation(xs.begin(), xs.end())) {
    index++;
    if (xs == ps) pi = index;
    if (xs == qs) qi = index;
  }
  cout << abs(pi - qi) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> c(n,0);
  ll ans=1;
  c[0]=3;
  rep(i,n){
    if(!c[a[i]]){
      puts("0");
      return 0;
    }
    ans=(ans*c[a[i]])%MOD;
    c[a[i]]--;
    c[a[i]+1]++;
  }
  cout << ans%MOD << endl;
  return 0;
}


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

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define base 402653189
#define mod 998244353
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define MX 200005

int main(){
	optimize();
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string S,T;
	cin>>S>>T;
	bool flag=true;
	for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]) flag= false;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

long long int N, T, t, lt = -1, rt = -1, a;

int main(){
    scanf("%lld%lld", &N, &T);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &t);
        if(rt < t){
            a += rt - lt;
            lt = t;
            rt = t + T;
        }else{
            rt = t + T;
        }
    }
    a += rt - lt;
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e9

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<int> seg, delay;
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
	}
	void init(){
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i] = -inf;
			delay[i] = 0;
		}
	}
	void eval(int l, int r, int k){
		if(delay[k]){
			seg[k] += delay[k];
			if(l < r){
				delay[k*2] += delay[k];
				delay[k*2+1] += delay[k];
			}
			delay[k] = 0;
		}
	}
	void update(int i, int val){
		i += (1<<size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}
	void add(int a, int b, int k, int l, int r, int val)
	{
		eval(l, r, k);
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			delay[k] += val;
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		seg[k] = max(seg[k*2], seg[k*2+1]);
	}
	void add(int a, int b, int val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}
	int query(int a, int b, int k, int l,int r){
		eval(l, r, k);
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		int lval = query(a, b, k*2, l, (l+r)/2);
		int rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	int query(int a, int b){
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, m;
llint l[200005], r[200005];
SegTree seg(19);

vector<llint> Lvec, Rvec;
vector<llint> comp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];
	
	for(int i = 1; i <= n; i++) comp.push_back(l[i]), comp.push_back(r[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= n; i++){
		l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin() + 1;
		r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() + 1;
	}
	llint M = comp.size();
	
	seg.init();
	seg.add(1, M, inf);
	for(int i = 1; i <= n; i++) seg.add(l[i], r[i], 1);
	llint amax = seg.query(1, M);
	
	//cout << amax << endl;
	
	llint ans = (amax-1)*m;
	if(amax % 2 == 0){
		for(int i = 1; i <= M; i++){
			if(seg.query(i, i) == amax){
				ans += m - comp[i-1];
				cout << ans << endl;
				return 0;
			}
		}
	}
	else{
		for(int i = M; i >= 1; i--){
			if(seg.query(i, i) == amax){
				ans += comp[i-1];
				cout << ans << endl;
				return 0;
			}
		}
	}
	
	return 0;
}



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

using namespace std;
typedef long long ll;

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

struct stx {
    ll s, t, x;

    stx(ll s, ll t, ll x) : s(s), t(t), x(x) {}
};

int main() {
    ll n, q;
    cin >> n >> q;
    vector<stx> v;
    rep(i, n) {
        ll s, t, x;
        cin >> s >> t >> x;
        stx temp(s, t, x);
        v.emplace_back(temp);
    }
    set<pair<ll, ll>> set1;
    rep(i, q) {
        ll d;
        cin >> d;
        set1.insert(pair<ll, ll>(d, i));
    }
    auto comp = [](stx &a, stx &b) {
        if (a.x == b.x) {
            if (a.s == b.s) return a.t < b.t;
            return a.s < b.s;
        }
        return a.x < b.x;
    };
    sort(v.begin(), v.end(), comp);

    vector<ll> ans(q, -1);
    rep(i, n) {
        ll s = v[i].s, x = v[i].x, t = v[i].t;
        auto it = set1.lower_bound(pair<ll, ll>(s - x, -1));
        while (it != set1.end()) {
            if (t - x <= it->first) break;
            ans[it->second] = x;
            set1.erase(it++);
        }
    }
    rep(i, q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 20716
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> key(m);
  rep(i, m) {
    int b, c, S = 0;
    cin >> key[i].first >> b;
    rep(j, b) {
      cin >> c;
      S |= (1 << (c - 1));
    }
    key[i].second = S;
  }
  sort(key.begin(), key.end());

  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  rep(i, m) {
    rep(S, (1 << n)) {
      int t = S | key[i].second;
      int cost = dp[S] + key[i].first;
      dp[t] = min(dp[t], cost);
    }
  }

  cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int N,M,X,Y,i,xmax=-200,ymin=200,a;
	cin>>N>>M>>X>>Y;
	for (i=0;i<N;i++)
	{
		cin>>a;
		xmax=max(xmax,a);
	}
	for (i=0;i<M;i++)
	{
		cin>>a;
		ymin=min(ymin,a);
	}
	//printf("x%dy%d\n",xmax,ymin);
	if (xmax<ymin&&ymin>X&&xmax<Y) puts("No War");
	else puts("War");
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100010;
ll n;
ll a[200], b[200];

//这题我是真的不会，直接抄了
int main()
{
	cin >> n;
	int p1 = 0, p2 = 0, m = 100;
	++n;
	while (n > 1)
	{
		if (n & 1) a[++p1] = m--, --n;
		else b[++p2] = m--, n >>= 1;
	}
	printf("%d\n", p1 + p2 << 1);
	for (int i = 1; i <= p1; ++i)
		printf("%d ", a[i]);
	for (int i = p2; i >= 1; --i)
		printf("%d ", b[i]);
	for (int i = 101 - p1 - p2; i <= 100; ++i)
		printf("%d ", i);
	puts("");
	return 0;
}

Measured memory_bytes: 256
import sys, re
import math
import numpy as np
from decimal import Decimal
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.maxsize = 10 ** 15
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

x = INT()
if x >= 30:
  print("Yes")
else:
  print("No")

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

int keta(int n){
  int i, j, l, m;
  m = n%10;
  n /= 10;
  l = n%10;
  n /= 100;
  j = n%10;
  n /= 10;
  i = n%10;
  if(i == m && j == l){
    return 1;
  }else{
    return 0;
  }
}
int main(){
  int A, B;
  cin >> A >> B;
  int count = 0;
  for(int n = A; n <= B; n++){
    if(keta(n) == 1){
      count++;
    }
  }
  cout << count << endl;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

int n, m;
bool b;

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m;
	if (n & 1)
	{
		for (int i = 0; i < m; i++)
			cout << i + 1 << " " << n - i << endl;
	}
	else
	{
		for (int i = 0; i < m; i++)
		{
			if (!b && n - 2 * i - 1 <= n / 2)
			{
				b = 1;
				n--;
			}
			cout << i + 1 << " " << n - i << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long LL;
const int K = 1e9 + 7;
const int MAXN = 1e5 + 10;
int n, b[MAXN] = {0}, fac[MAXN];

int power(int x, int k) {
	int t = 1;
	for (; k; x = (LL)x * x % K, k >>= 1)
		if (k & 1)
			t = (LL)t * x % K;
	return t;
}

int inv(int x) {
	return power(x, K - 2);
}

int main() {
//	freopen("input.txt", "r", stdin);
	int px = -1, py = -1, cnt;
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1, x; i <= n + 1; ++i) {
		cin >> x;
		if (!b[x])
			b[x] = i;
		else
			px = b[x], py = i;
	}
	assert(~px);
	cnt = px - 1 + n + 1 - py;
	fac[0] = 1;
	for (int i = 1; i <= n + 1; ++i)
		fac[i] = (LL)fac[i-1] * i % K;
	for (int i = 1; i <= n + 1; ++i) {
		int ans = (LL)fac[n+1] * inv(fac[i]) % K * inv(fac[n+1-i]) % K;
		if (i - 1 <= cnt)
			ans = (ans - (LL)fac[cnt] * inv(fac[i-1]) % K * inv(fac[cnt-i+1]) % K + K) % K;
		cout << ans << endl;
	}
	return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1000000013
using namespace std;
typedef long long ll;
string dp[2][3010];

int main(){
  string s,t;
  cin >> s >> t;
  int n=s.size(),m=t.size();
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      int ki=i&1,ni=ki^1;
      if(dp[ni][j].size()>dp[ki][j-1].size()) dp[ki][j]=dp[ni][j];
      else dp[ki][j]=dp[ki][j-1];
      if(s[i-1]==t[j-1]){
        dp[ki][j]=dp[ni][j-1]+s[i-1];
      }
    }
  }
  cout << dp[n&1][m] << endl;
}

Measured memory_bytes: 16816
#include <iostream>
#include <algorithm>
using namespace std;
int maxtime(int x) {
	return (x+9)/10*10;
}
int remtime(int x) {
	return maxtime(x)-x;
}
int main() {
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	int sum=maxtime(a)+maxtime(b)+maxtime(c)+maxtime(d)+maxtime(e);
	sum-=max({remtime(a),remtime(b),remtime(c),remtime(d),remtime(e) });
	cout << sum << endl;
}


Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 4/13/2019, 9:04:58 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

string S;
string T;
string U;

int main()
{
  cin >> S;
  int N = S.size();
  T = "", U = "";
  for (auto i = 0; i < N; i++)
  {
    if (i % 2 == 0)
    {
      T = T + "0";
      U = U + "1";
    }
    else
    {
      T = T + "1";
      U = U + "0";
    }
  }
  int ans = N;
  int t_ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (S[i] != T[i])
    {
      t_ans++;
    }
  }
  ans = min(ans, t_ans);
  t_ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (S[i] != U[i])
    {
      t_ans++;
    }
  }
  ans = min(ans, t_ans);
  cout << ans << endl;
}

Measured memory_bytes: 872
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],ans,num;
char str[N];
signed main(){
	scanf("%s",str+1);n=strlen(str+1);
	F(i,1,n) a[i]=(str[i]=='B');
	D(i,n,1){
		if (a[i]) ans+=n-i-num,num++;
	}
	wrn(ans);
	return 0;
}

Measured memory_bytes: 4096
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N,M;
int A[100005];
int R[100005];
signed main(){
    scanf("%lld %lld",&N,&M);
    map<int,int> Rmap;
    int ans=0;
    rep(i,N){
        scanf("%lld",&A[i]);
        if(i==0)R[i]=A[i];
        else R[i]=R[i-1]+A[i];
        R[i]%=M;
        if(R[i]==0)ans++;
        if(Rmap[R[i]]>0){
            ans+=Rmap[R[i]];
            Rmap[R[i]]+=1;
        }else{
            Rmap[R[i]]=1;
        }
    }
    printf("%lld\n",ans);
    
}

Measured memory_bytes: 8752
N,A,B = map(int,input().split())
if (N == 1):
  if (A != B):
    print(0)
  else:
    print(1)
else:
  if (A > B):
    print(0)
  elif (A == B):
    print(1)
  else:
    if (N == 2):
      print(1)
    else:
      print((B*(N-1)+A)-(B+(N-1)*A)+1)

Measured memory_bytes: 3064
s = input()
q = int(input())

tmp = 1
a = ''
b = ''
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        tmp *= -1
    else:
        if tmp > 0:
            if query[1] == '1':
                a = ''.join((query[2], a))
            else:
                b = ''.join((b, query[2]))
        else:
            if query[1] == '1':
                b = ''.join((b, query[2]))
            else:
                a = ''.join((query[2], a))
res = ''.join((a, s, b))
if tmp > 0:
    print(res)
else:
    print(res[::-1])


Measured memory_bytes: 4680
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max=0;
    Map<String,Integer> map = new TreeMap<String,Integer>();
    for (int i=0; i<n; i++){
      String key =sc.next();
      if (map.containsKey(key)) {
        int xx = (int)map.get(key)+1;
        max = chmax(max,xx);
        map.put(key,new Integer(xx));
      } else {
        map.put(key,new Integer(1));
        max = chmax(max,1);
      }
    }
      for (String key :map.keySet()) {
        if (map.get(key)==max) {
        System.out.println(key);
        }
      }
  }
  private static int chmax(int a, int b) {
    return Math.max(a,b);
  }
}




Measured memory_bytes: 80792
#include<stdio.h>

int solve(int, int, int);

 int A[2000];

int main(){
  int n,q,m,i,count=0;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&m);
      if(solve(0, m, n)) printf("yes\n");
      else printf("no\n");
      }

  return 0;
}

int solve(int i, int m, int n){
  int res;
  
  if(m == 0) return 1;
  if(i >= n) return 0;

  res = solve(i + 1, m, n) || solve(i + 1, m - A[i], n);

  return res;
}



Measured memory_bytes: 2108
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            
            if(A < 10 & B < 10)
            {
                Console.WriteLine(A * B);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>  
#include <vector>
#include <map> 

using namespace std;
#include <math.h>    // for sqrt
#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int main() {
    int n; cin >> n;
    if (n%2==0) {
      cout << "0.5" << endl;      
    } else {
      cout << (double)(n/2+1)/(double)n << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long> buffer(n);
	int128_t ans=1;
	bool zero = false;
	for(int i=0; i<n; i++)
	{
		cin >> buffer[i];
		if(buffer[i]==0)
			zero = true;
	}
	if(zero)
	{
		cout << 0;
		return 0;
	}
	for(int i=0; i<n; i++)
	{
		if((ans*buffer[i]) > 1000000000000000000)
		{
			cout << -1;
			return 0;
		}
		ans *= buffer[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int main(){
	int a,b;
	cin>>a>>b;
	int ans=max(0,(-1*a+4)*100000)+max(0,(-1*b+4)*100000);
	if(a==1&&b==1)
	ans+=400000;
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;


int main()
{
	ll A;
	long double B;
	cin >> A >> B;
	cout << (ll)((long double)A*B);
}

Measured memory_bytes: 3728