akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

static const int MAX = 10; 

int N, M;
int P[MAX];
vector<int> S[MAX];
int ans = 0;

void dfs(string x) {
 
  if ( x.size() == N ) {
    int sum = 0;
      
    for ( int i = 0; i < M; i++ ) {
        int on = 0;
        
        for ( int j = 0; j < S[i].size(); j++) {
            if ( x[S[i][j]] == '1' ) {on++;}
        }
        
        if ( on % 2 == P[i] ) sum++;
    }
      if ( sum == M ) ans++;
      return;
  }
    
  string s1, s2;
  s1 = s2 = x;
  s1 += '0';
  s2 += '1';
  dfs(s1);
  dfs(s2);
}

int main() {

  scanf("%d %d", &N, &M);
   /* 電球に接続されているスイッチの入力 */
  for ( int i = 0; i < M; i++ ) {
    int k;
    scanf("%d", &k);
    for ( int j = 0; j < k; j++) {
      int s;
      scanf("%d", &s);
      S[i].push_back(s - 1);
    }
  }
  /* スイッチ状態の入力 */
  for ( int i = 0; i < M; i++ ) {
    int p;
    scanf("%d", &p);
    P[i] = p;
  }

  dfs("");
  printf("%d\n", ans);

}


Measured memory_bytes: 256
#include <map>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    map<string, int> m;
    while (n--) {
        string s; cin >> s;
        m[s]++;
    }
    for (string s : {"AC", "WA", "TLE", "RE"})
        cout << s << " x " << m[s] << endl;
}


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

int potato(int x, int y)
{
 int i;
 for(i=y-1; i<(y-1)*x; i = (y*i) / (y-1)+1);
 return(x*y-i);
 }
 int main()
{
 int x,y;
 while(cin>>x>>y, x || y)
 {
  cout<<potato(x , y)<<endl;
  }
 }

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <vector>

using v = std::vector<uint64_t>;
using vv = std::vector<v>;

int main()
{
  uint64_t n, x;
  std::cin >> n >> x;
  vv dp(n, v(n));
  for (int i = 0; i < n; i++) {
    std::cin >> dp[0][i];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int j_sub_one = j-1;
      if (j_sub_one < 0) {
        j_sub_one = n-1;
      }
      dp[i][j] = std::min(dp[i-1][j], dp[i-1][j_sub_one]);
    }
  }
  uint64_t best = ~0ull;
  for (int i = 0; i < n; i++) {
    uint64_t temp = i * x;
    for (int j = 0; j < n; j++) {
      temp += dp[i][j];
    }
    if (temp < best) {
      best = temp;
    }
  }
  std::cout << best << std::endl;
  return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;
static const cc MAX = 200000;

cc N, M, i, j, k, sub = 0, n = 0;
cc judge = 0, Ans = 0;
string S[MAX];
char vec[10];
char T;
/*
vector<cc> vec1(MAX), vec2(MAX);
vector<pair<cc, cc>> pairs(MAX);
*/



int main() {	
	cin >> N;
	for (j = 0; j < N; j++) {
	    cin >> vec;
		sort(vec, vec + 10);
		for (i = 0; i < 10; i++)
			S[j]+=vec[i];
	}

	sort(S, S + N);
	sub = 1;
	for (i = 0; i < N - 1; i++) {
		if (S[i]==S[i+1]) {
			Ans += sub;
			sub++;
		}
		else
			sub = 1;
	}
	
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n; cin >> n;
    vector<ll> h(n + 1);
    rep(i, n) cin >> h[i];
    ll count = 0;
    ll count_max = 0;

    rep(i, n){
        count = 0;
        if(h[i + 1] <= h[i]){
            while(i < n - 1 && h[i + 1] <= h[i]){
                count++;
                i++;
            }
        }
        count_max = max(count_max, count);
    }
    cout << count_max << endl;
}


Measured memory_bytes: 1024
/*線形探索*/
#include <stdio.h>
#define N 10000
#define Q 500
int main(){
  int s[N], t[Q], n, q, i, j, count=0;

  scanf("%d", &n);

  for (i=0; i<n; i++){
    scanf("%d", &s[i]);
  }
  
  scanf("%d", &q);
  
  for (i=0; i<q; i++){
    scanf("%d", &t[i]);
    /*探索*/
    for (j=0; j<n; j++){
      if (t[i] == s[j]){
	count++;
	break;
      }
    }
  }

  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

int strtoi(string& s) {
  if (s == "Vacant") return 0;
  if (s == "Male") return 1;
  return 2;
}

// l~u の範囲を探す
void solve(vector<int>& seats, const int& l, const int& u) {
  int mid = l + (u - l) / 2;
  cout << mid << endl;
  string s;
  cin >> s;
  seats[mid] = strtoi(s);
  if (seats[mid] == 0) return;
  if ((mid - l) % 2 == 0 && seats[l] != seats[mid]) solve(seats, l, mid);
  else solve(seats, mid, u);
}

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

  int n;
  cin >> n;
  vector<int> seats(n, -1);

  cout << 0 << endl;
  string s;
  cin >> s;
  seats[0] = strtoi(s);
  if (seats[0] == 0) return 0;
  cout << n - 1 << endl;
  cin >> s;
  seats[n-1] = strtoi(s);
  if (seats[n-1] == 0) return 0;

  int l = 0;
  int u = n-1;

  rep(i, 18) {
    int mid = l + (u - l) / 2;
    cout << mid << endl;
    string s;
    cin >> s;
    seats[mid] = strtoi(s);
    if (seats[mid] == 0) return 0;
    if ((mid % 2 == l % 2 && seats[mid] != seats[l]) || (mid % 2 != l % 2 && seats[mid] == seats[l])) {
      u = mid;
    } else {
      l = mid;
    }
  }

  return 0;
}


Measured memory_bytes: 3800
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		int x = sc.nextInt();
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}

		int bigger = x;
		int smaller = x;
		while (true) {
			boolean hasBigger = set.contains(bigger);
			boolean hasSmaller = set.contains(smaller);
			
			if (hasBigger && hasSmaller) {
				smaller--;
				bigger++;
			} else {
				if (hasSmaller) {
					System.out.println(bigger);
				} else {
					System.out.println(smaller);
				}
				break;
			}
		}
	}
}


Measured memory_bytes: 35796
# C
x, n = map(int, input().split())
p = list(map(int, input().split()))
# print(p)
ans = 0
if n == 0:
    print(x)
elif x not in p:
    print(x)
else:
    for i in range(102):
        if i not in p:
            if abs(x - i) < abs(x - ans):
                ans = i
    print(ans)


Measured memory_bytes: 9180
#include <algorithm>
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::string;

int main(void) {
    char a;
    cin >> a;
    // int a, b;
    // cin >> a >> b;

    // int ans;
    // // int ans = ;
    // cout << ans << '\n';

    const string ans[2] = {"a\n", "A\n"};
    cout << ans[a <= 'Z'] << '\n';
    return 0;
}

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

using namespace std;

int main()
{
    long long a, b;

    cin >> a >> b;

    bitset <32> bita(a), bitb(b);

    cout << (bita & bitb) << endl;
    cout << (bita | bitb) << endl;
    cout << (bita ^ bitb) << endl;

    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>

#define N_MAX 100000
#define INF 1 << 33
typedef long long ll;
using namespace std;

int G[101][101];
struct edge { int from, to; };
int main() {
	int n; cin >> n;
	vector<edge> a;
	if (n % 2 == 0) {
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				if (i + j == n + 1) G[i][j] = 0;
				else G[i][j] = 1;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				if (G[i][j] == 1) {
					a.push_back({ i,j });
				}
			}
		}

	}
	else {

		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				if (i + j == n) {
					G[i][j] = 0;
				}
				else {
					G[i][j] = 1;
				}
			}
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				if (G[i][j] == 1) {
					a.push_back({ i,j });
				}
			}
		}
	}
	int s = a.size();
	cout << s << endl;
	for (int i = 0; i < s; i++)
	{
		cout << a[i].from << " " << a[i].to << endl;
	}

}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int t[7],n,a;
int main(){
  while(cin>>n&&n){

    for(int i=0;i<7;i++)t[i]=0;

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

      for(int j=0;j<7;j++){
	if(j*10<=a&&a<=j*10+9){
	  t[j]++;
	  break;
	}
	if(j==6)t[6]++;
      }

    }
    for(int i=0;i<7;i++){
      cout<<t[i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int units[] = {10, 50, 100, 500};

vector<int> change(int x) {
    vector<int> ret(4, 0);
    rrep(i, 4) {
        ret[i] = x / units[i];
        x %= units[i];
    }
    return ret;
}

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

    int m;
    int flag = 0;
    while (cin >> m, m) {
        if (flag++ > 0) cout << endl;

        vector<int> v(4);
        int num_coin = 0;
        int sm = 0;
        rep(i, 4) {
            cin >> v[i];
            num_coin += v[i];
            sm += units[i] * v[i];
        }

        auto ret = change(sm - m);
        rep(i, 4) {
            int n = v[i] - ret[i];
            if (n > 0) cout << units[i] << " " << n << endl;
        }
    }
}

Measured memory_bytes: 3176
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int d[] = new int[n];
        
        for(int i = 0; i < n; i++){
            d[i] = sc.nextInt();
        }

        Arrays.sort(d);

        int ans = 1;

        for(int i = 1; i < n; i++){
            if(d[i]!=d[i-1]) ans++;
        }
        
        System.out.println(ans);
    }
}


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

int main() {
  int N,K;
  cin>>N>>K;
  int A[N]={};
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a-1]++;
  }
  sort(A,A+N);
  int ans=0;
  for(int i=0;i<N-K;i++) ans+=A[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>
 
using namespace std;
const int NIL = -1;
 
struct node {
    int parent;
    int left;
    int right;
};
 
vector<int> pre;
vector<int> ino;
int n;
 
void reconstruct(int l, int r)
{
    static int k = 0;
    if (l >= r) return;
    int c = pre[k];
    k++;
    int i = 0;
    for (i = 0; i < n; ++i) {
        if (ino[i] == c) break;
    }
    reconstruct(l, i);
    reconstruct(i + 1, r);
    static int m = 0;
    if (m++ > 0) printf(" ");
    printf("%d", c);
 
}
 
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int v;
        scanf("%d", &v);
        pre.push_back(v);
    }
    for (int i = 0; i < n; ++i) {
        int v;
        scanf("%d", &v);
        ino.push_back(v);
    }
    reconstruct(0, n);
    printf("\n");
}

Measured memory_bytes: 2784
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
//#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int main(){
	
	/*string s;
	int f=1,f1=1,co=0;
	cin>>s;
	/*char a='Z';
	cout<<(int)a<<endl;*/
	/*
	if(s[0]!='A')f=0;
	if(s[s.size()-1]=='C')f=0;
	for(int i=1;i<s.size();i++){
		if(65<=(int)s[i] && (int)s[i]<=90 && s[i]!='A' && s[i]!='C')f=0;
		if(s[i]=='C')co++;
		if(co!=1)f=0;
		cout<<f;
	}
	cout<<endl;
	if(f)cout<<"AC"<<endl;
	else cout<<"WA"<<endl;*/
	int n,l[1111],r[1111];
	int co=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];
		co+=r[i]-l[i]+1;
	}
	cout<<co<<endl;
	
	
}

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

using namespace std;

int main() {
  
  int n;
  while( 1 ) {
    cin >> n;
    if( !n ) { break; }

    if( n == 1 ) {
      cout << "deficient number" << endl;
      continue;
    }
    int sum = 1;
    for( int i = 2; i * i < n; i++ ) {
      if( n % i == 0 ) { 
        sum += i;
        if( i * i != n ) {
          sum += n / i;
        }

        if( sum > n ) { break; }
      }
    }

    cout << (
      ( sum  < n ) ? "deficient number" :
      ( sum == n ) ? "perfect number"   :
                     "abundant number"
    ) << endl;
  }

  return EXIT_SUCCESS;
}

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

int main(){
    //入力
    int N;
    cin >> N;

    //計算
    int64_t ans=1;

    for(int i=0;i<N;i++){
        ans*=(i+1);
        ans%=((int)pow(10,9)+7);
    }

    //出力
    cout << ans << endl;

}


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

int main() {
    int x, y, t;
    while(1){
        cin >> x >> y;
        if ( x == 0 && y == 0) break;
        if ( x > y ) {
            t = x; x = y; y = t;
        }
        cout << x << " " << y << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    ll m, k;
    cin >> m >> k;
    if(k >= (1 << m))   return cout << -1, 0;
    if(m == 1)
    {
        if(!k)  cout << "0 0 1 1";
        else    cout << -1;
        return 0;
    }
    REP(i, 0, 1 << m)
        if(i != k)
            cout << i << ' ';
    cout << k << ' ';
    for(int i = (1 << m) - 1;i >= 0;i--)
            if(i != k)
                cout << i << ' ';
    cout << k;
    return 0;
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[1]==s[2]||
     s[1]==s[2]&&s[2]==s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll town, blood, f_n, r_n, cap, hos;
	while (cin >> town >> blood >> f_n >> r_n >> cap >> hos, town) {
		vector<bool>freezer(town, false);
		REP(i, f_n)freezer[in()] = true;
		freezer[cap] = freezer[hos] = true;
		vector<vector<ll>>road(town, vector<ll>(town));
		REP(i, town) {
			REP(j, town) {
				road[i][j] = i == j ? 0 : INFLL;
			}
		}
		REP(i, r_n) {
			ll x = in(), y = in(), t = in();
			road[x][y] = road[y][x] = t;
		}
		REP(k, town) {
			REP(i, town) {
				REP(j, town) {
					road[i][j] = min(road[i][k] + road[k][j], road[i][j]);
				}
			}
		}
		REP(i, town) {
			REP(j, town) {
				if (!freezer[i] || !freezer[j] || road[i][j] > blood) {
					road[i][j] = INFLL;
				}
			}
		}
		REP(k, town) {
			REP(i, town) {
				REP(j, town) {
					road[i][j] = min(road[i][k] + road[k][j], road[i][j]);
				}
			}
		}
		ll dis = road[cap][hos];
		if (dis == INFLL) {
			cout << "Help!" << endl;
		} else {
			ll rem = dis - blood;
			cout << dis + max(0LL, rem) << endl;
		}
	}
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int a,b;
    cin >> a >> b;

    int ans[4] = {};

    ans[a] = 1;
    ans[b] = 1;

    for(int i = 1; i <= 3; i++){
        if(ans[i] == 0){
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = []
    B = []
    BA = []
    cnt = 0
    for i in range(N):
        s = input()
        l = list(s)
        if l[0] == 'B' and l[-1] == 'A':
            BA.append(i)
        elif l[0] == 'B':
            B.append(i)
        elif l[-1] == 'A':
            A.append(i)
        cnt += s.count('AB')
    # print(A, B, BA, cnt)
    la = len(A)
    lb = len(B)
    lba = len(BA)

    if la > 0 and lb > 0:
        cnt += min(la, lb) + lba
    elif la == 0 and lb == 0:
        if lba > 1:
            cnt += lba - 1
    else:
        cnt += lba
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9404
#include <iostream>
using namespace std;
int main(void){
   int E,Y;
   cin >> E >> Y;
   if(E==0){
       if(1868 <= Y && Y <= 1911){
           cout << "M" << Y-1868+1  << endl;
       }
       else if(1912 <= Y && Y <= 1925){
           cout << "T" << Y-1912+1 << endl;
       }
       else if(1926 <= Y && Y <= 1988){
           cout << "S" << Y-1926+1 << endl;
       }
       else if(1989 <= Y && Y <= 2016){
           cout << "H" << Y-1989+1 << endl;
       }
   }
   else if(E==1){
       cout << 1868+Y-1 << endl;
   }
   else if(E==2){
       cout << 1868+44+Y-1 << endl;
   }
   else if(E==3){
       cout << 1868+44+14+Y-1 << endl;
   }
   else if(E==4){
       cout << 1868+44+14+63+Y-1 << endl;
   }
} 


Measured memory_bytes: 3104
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60

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

def main():
    N = int(readline())
    a = prime_factorize(N)
    
    ans = 0
    for power in a.values():
        ans += int(((1 + 8 * power) ** 0.5 - 1 ) / 2)
        
    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main () {

    int N;
    cin>>N;

    int A=N/100;
    int O=N%100;
    int B=O/10;
    int P=O%10;

    if (A==7||B==7||O==7||P==7){

        cout<<"Yes"<<endl;
    }

    else {
        
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;

  return 0;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x; cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <deque>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	string s;
	cin>>s;
	int i=0;
	deque<char> Q;
	int lNums=0;
	int rNums=0;
	for (i=0;i<N;i++){
		Q.push_back(s[i]);
	}
	for (i=0;i<N;i++){
		if (s[i]==')'){
			rNums++;
			if (rNums>lNums){
				Q.push_front('(');
				lNums++;
			}
		}else if (s[i]=='('){
			lNums++;
		}
	}
	while (lNums>rNums){
		Q.push_back(')');
		rNums++;
	}
	for (i=0;i<Q.size();i++){
		cout<<Q[i];
	}
	cout<<endl;
	Q.clear();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    vector<ll> list(3);
    cin >> list[0] >> list[1] >> list[2];
	sort(all(list));
	ll dif1 = list[2]-list[0], dif2 = list[2]-list[1];
	if((dif1 % 2) == (dif2 % 2)){
        cout << (dif1 + dif2) / 2 << endl;
    }else{
        cout << (3 + dif1 + dif2) / 2 << endl;
    }
}



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

int n = 0;

int main() {
    int hight[10];

    for (int i = 0; i < 10; i++) {
        cin >> hight[i];
    }
    
    for (int a = 1; a <= 10; a++) {
        for (int x = 0; x < 10; x++) {
            if (hight[x] < hight[x+1]) {
                n = hight[x];
                hight[x] = hight[x+1];
                hight[x+1] = n;
            }
        }
    }
    
    cout << hight[0] << endl;
    cout << hight[1] << endl;
    cout << hight[2] << endl;
    
    return 0;
}

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

public struct Edge
{
    public int to { get; set; }
    public int d { get; set; }
}

public class C
{
    public const int INF = 999999999;
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var m = int.Parse(Console.ReadLine().Trim());
            var r = new List<Edge>[n];
            var minc = new int[n];
            for (int i = 0; i < n; i++)
            {
                r[i] = new List<Edge>();
                minc[i] = C.INF;
            }
            for (int i = 0; i < m; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(',');
                var a = int.Parse(line2[0]);
                var b = int.Parse(line2[1]);
                var d = int.Parse(line2[2]) / 100;
                r[a].Add(new Edge { to = b, d = d });
                r[b].Add(new Edge { to = a, d = d });
            }
            goPrim(r, minc, 0);
            Console.WriteLine(minc.Sum() - n + 1);
        }
    }
    public static void goPrim(List<Edge>[] r, int[] minc, int targ)
    {
        var n = minc.Length;
        var xL = new List<int>();
        xL.Add(targ); minc[targ] = 0;
        while (xL.Count() <= n)
        {
            foreach (var x in r[targ])
                if (!xL.Contains(x.to) && x.d < minc[x.to]) minc[x.to] = x.d;
            var mint = C.INF; var minb = -1;
            for (int i = 0; i < n; i++)
                if (!xL.Contains(i) && minc[i] < mint) { mint = minc[i]; minb = i; }
            xL.Add(minb);
            targ = minb;
        }
    }
}

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

int N;
vector<string> s;

int main() {
    cin>>N;
    s.resize(N);
    for (int i=0; i<N; i++) cin>>s[i];
    sort(s.begin(), s.end());
    int cnt=1;
    for (int i=0; i<N-1; i++) {
        if (s[i]!=s[i+1]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define OUT(x) cout<<(x)<<"\n"
const int INF = 114514;


int main(){
    char s;
    cin >> s;
    string vv="aiueo";
    rep(i, vv.size()) if(vv[i] == s) {
        OUT("vowel");
        return 0;
    }
    OUT("consonant");

    return 0;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
x = []
y = []
z = [[0 for i in range(c)] for j in range(a)]
for i in range(a):
    x.append(list(map(int,input().split())))
for i in range(b):
    y.append(list(map(int,input().split())))

for i in range(a):
    for j in range(c):
        tmp = 0
        for k in range(b):
            tmp += x[i][k] * y[k][j]

        z[i][j] = tmp

for i in range(a):
    for j in range(c):
        print(z[i][j],end="")
        if j != c-1:
            print(" ",end="")
    print("")


Measured memory_bytes: 7148
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<set>
using namespace std;
int a_b[3000+100];
int c_d[3000+100];
int main()
{
	set<int >Sab;
	set<int>Scd;
	int a,b,c,d,e,f;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	a_b[0]=1;
	c_d[0]=1;
	Sab.insert(0);
	Scd.insert(0);
	for(int i=a*100;i<=f;i+=100)
	{
		if(a_b[i-a*100]==1)
		{
			Sab.insert(i);
			a_b[i]=1;
		}
	}
	for(int i=b*100;i<=f;i+=100)
	{
		if(a_b[i-b*100]==1)
		{
			Sab.insert(i);
			a_b[i]=1;
		}
	}
	for(int i=c;i<=f;i++)
	{
		if(c_d[i-c]==1)
		{
			Scd.insert(i);
			c_d[i]=1;
		}
	}
	for(int i=d;i<=f;i++)
	{
		if(c_d[i-d]==1)
		{
			Scd.insert(i);
			c_d[i]=1;
		}
	}
	double max=-1;
	int maxts=0;
	int maxt=0;
	set<int> ::iterator  itab=Sab.begin();
	for(;itab!=Sab.end();itab++)
	{
	//	printf("%d\n",*itab);
		set<int> ::iterator itcd=Scd.begin();
		int xl=0;
		while(*itcd+*itab<=f && *itcd<=*itab/100*e)
		{
			itcd++;
			xl++;
		}
		itcd--;
		xl--;
		if(xl>=0)
		{
			int ts=*itab+*itcd;
			int t=*itcd;
			double lv=t*1.0/ts;
			if(lv>=max)
			{
				max=lv;
				maxts=ts;
				maxt=t;
			}
		}
	}
	printf("%d %d\n",maxts,maxt);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define ALL(x) (x).begin(),(x).end()

int A, B, Q;
vector<long long> ss, ts;
vector<long long> sc, tc;

#define INF (1LL << 60)

int main(void) {
  while (cin >> A >> B >> Q && Q) {
    ss = vector<long long>(A);
    for (int i = 0; i < A; i++) cin >> ss[i];
    sort(ss.begin(), ss.end());

    ts = vector<long long>(B);
    for (int i = 0; i < B; i++) cin >> ts[i];
    sort(ts.begin(), ts.end());

    sc = vector<long long>(A, 0);
    for (int i = 0; i < A; i++) {
      int index = lower_bound(ALL(ts), ss[i]) - ts.begin();
      sc[i] =
        min(
            index == B ? INF : abs(ts[index] - ss[i]),
            index == 0 ? INF : abs(ss[i] - ts[index - 1]));
      //cout << i << ": " << sc[i] << endl;
    }

    tc = vector<long long>(B, 0);
    for (int i = 0; i < B; i++) {
      int index = lower_bound(ALL(ss), ts[i]) - ss.begin();
      tc[i] =
        min(
            index == A ? INF : abs(ss[index] - ts[i]), 
            index == 0 ? INF : abs(ts[i] - ss[index - 1]));
      //cout << i << ": " << tc[i] << endl;
    }

    for (int i = 0; i < Q; i++) {
      long long x;
      cin >> x;

      int tindex = lower_bound(ALL(ts), x) - ts.begin();
      long long min_b =
        min(
            tindex == B ? INF : abs(ts[tindex] - x) + tc[tindex],
            tindex == 0 ? INF : abs(x - ts[tindex - 1]) + tc[tindex - 1]
           );
      //cout << "tindex: " << tindex << endl;

      int sindex = lower_bound(ALL(ss), x) - ss.begin();
      long long min_a =
        min(
            sindex == A ? INF : abs(ss[sindex] - x) + sc[sindex],
            sindex == 0 ? INF : abs(x - ss[sindex - 1]) + sc[sindex - 1]
           );
      //cout <<  "sindex: " << sindex << endl;

      cout << min(min_a, min_b) << endl;
    }
  }
}


Measured memory_bytes: 4480
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 056 HonestOrDishonest a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  char a, b;
  cin >> a >> b;
  if (a == 'H') {
    cout << b << endl;
  } else {
    cout << (b=='H' ? 'D' : 'H') << endl;
  }
  return 0;
}



Measured memory_bytes: 256
s=[]
while True:
    n,x = map(int, input().split())
    if n==0 and x==0:
        break
    res=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            z=x-i-j
            if j<z<=n:
                res+=1
    s.append(res)
                


for i in range(len(s)):
    print(s[i])




Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

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

    /*int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }*/

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

    bool approved = true;
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 != 0 && a[i] % 5 != 0) {
                approved = false;
                break;
            }
        }
    }

    if (approved) {
        cout << "APPROVED" << "\n";
    }
    else {
        cout << "DENIED" << "\n";
    }


    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
	while(true) {
		int a,b;
		if(scanf("%d%d", &a, &b)<2)break;
		a+=b; b=0;
		while(a)b++,a/=10;
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,W; cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];

    vector<ll> dp(W+1);
    rep(i,n){
        rrep(j, W+1){
            if(j >= w[i])chmax(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << endl;
}

Measured memory_bytes: 1024
#include <iostream>

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

using namespace std;

int main(void)
{
  int H, W, N;
  int n;
  int ans;

  cin >> H >> W >> N;

  n = (H > W) ? H : W;

  ans = (N / n) + ((N % n != 0) ? 1 : 0);

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


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define x first
#define y second

ll m[20][20];
int a,b,n;

int main() {
    while(cin>>a>>b){
        rep(i,20) rep(j,20) m[i][j]=0;

        if(a==0 && b==0)break;
        cin>>n;
        rep(i,n){
            int a,b;
            cin>>a>>b;
            a--;b--;
            m[a][b]=-100;
        }
    
        m[0][0]=1;
        rep(i,a){
            rep(j,b){
                if(m[i][j]!=-100){
                    if(i-1>=0 && m[i-1][j]!=-100)m[i][j]+=m[i-1][j];
                    if(j-1>=0 && m[i][j-1]!=-100)m[i][j]+=m[i][j-1];
                }
            }
        }
        
        cout<<m[a-1][b-1]<<endl;
    }
    
    return 0;
}

        
        

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int M; cin >> M;
  vector<pair<int,int>> ab(M);// first->endpoint, second->startpoint
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(b, a);
  }
  sort(ab.begin(), ab.end());
  int ans = 0, cur = 1;
  for(auto i:ab) {
    if(cur <= i.second) {
      cur = i.first;
      ++ans;
    }
  }
  cout << ans << endl;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	string s; cin >> s;
	int depth = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '('){
			depth++;
		}
		else if(s[i] == ')'){
			depth--;
		}
		else if(s[i] == '*'){
			cout << depth << endl;
			return 0;
		}
	}


	return 0;
}




Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[100];
  cin>>n;
  a[0]=2;
  a[1]=1;
  for(int i=2;i<=n;i++){
    a[i]=a[i-1]+a[i-2];
  }
  cout<<a[n]<<endl;
  return(0);
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	ll n, a, b;
	cin >> n >> a >> b;

	if ((b - a) % 2 == 0)
	{
		cout << (b - a) / 2 << endl;
		return;
	}

	ll move_cnt = 0;
	if (a - 1 < n - b)
	{
		move_cnt += a;
		b -= a;
		a = 1;
	}
	else
	{
		move_cnt += n - b + 1;
		a += n - b + 1;
		b = n;
	}
	
	cout << move_cnt + (b - a) / 2 << endl;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int m,n,i,j,tmp;
  int a[100];
  int all_vote=0;
  
  do{
    scanf("%d %d",&n,&m);
  }while(m<=0 || n<m || 101<=n);
  
  for(i=0; i<n; i++){
    do{
      scanf("%d",&a[i]);
    }while(a[i]<1 || a[i]>1000);
    all_vote+=a[i];
  }
  
  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      if(a[i] < a[j]){
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  
  if(4*m*a[m-1] >= all_vote){
    printf("Yes");
  }
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1696
while gets
  a, b, c, d, e, f = $_.chomp.split.map(&:to_f)
  x = (c * e - b * f) / (a * e - b * d)
  y = (c - a * x) / b
  puts sprintf("%.3f %.3f", x.zero? ? 0 : x, y.zero? ? 0 : y)
end

Measured memory_bytes: 6140
#[test]
fn check_solve() {
    println!("input:\n6\nooxoox\noutput:\n{}\n", solve("6\nooxoox\n"));
    println!("input:\n3\noox\noutput:\n{}\n", solve("3\noox\n"));
    println!(
        "input:\n10\noxooxoxoox\noutput:\n{}\n",
        solve("10\noxooxoxoox\n")
    );
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);
    let n: usize = sc.read();
    let s: Vec<_> = sc.get().chars().collect();

    'lp: for &(t0, t1) in [('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')].iter() {
        let mut t = Vec::new();
        t.push(t0);
        t.push(t1);
        for i in 2..n+1 {
            if (s[i-1] == 'o') ^ (t[i-1] == 'W') {
                let nxt = t[i-2];
                t.push(nxt);
            } else if t[i-2] == 'S' {
                t.push('W');
            } else {
                t.push('S');
            }
        }
        if t[0] != t[n] {
            continue;
        }
        if ((s[0] == 'o') ^ (t[0] == 'W')) != (t[n-1] == t[1]) {
            continue 'lp;
        }
        for i in 0..n-1 {
            if ((s[i+1] == 'o') ^ (t[i+1] == 'W')) != (t[i] == t[i+2]) {
                continue 'lp;
            }
        }
        t.pop();
        return t.into_iter().collect();
    }

    format!("-1\n")
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w;cin>>h>>w;
    int n;cin>>n;
    int sh,sw;cin>>sh>>sw;
    string s,t;cin>>s>>t;
    int wl=1,wr=w,hl=1,hr=h;
    rrep(i,n-1,0){
        if(t[i]=='R'){
            wl=max(1,wl-1);
        }
        if(t[i]=='L'){
            wr=min(w,wr+1);
        }
        if(t[i]=='D'){
            hl=max(1,hl-1);
        }
        if(t[i]=='U'){
            hr=min(h,hr+1);
        }
        if(s[i]=='R'){
            wr--;
        }
        if(s[i]=='L'){
            wl++;
        }
        if(s[i]=='D'){
            hr--;
        }
        if(s[i]=='U'){
            hl++;
        }
        if(hl>hr||wl>wr){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(sh>=hl&&sh<=hr&&sw>=wl&&sw<=wr)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
int h,w;
char c[511][511];
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			scanf(" %c",&c[i][j]);
	for(int i=1;i<=h;++i)
	{
		for(int j=1;j<=w;++j)
			putchar(((c[i][j]=='#'||i==1||(j&1)==1)&&i!=h)?'#':'.');
		putchar('\n');
	} 
	putchar('\n');
	for(int i=1;i<=h;++i)
	{
		for(int j=1;j<=w;++j)
			putchar(((c[i][j]=='#'||i==h||(j&1)==0)&&i!=1)?'#':'.');
		putchar('\n');
	} 
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1024
(let ((x (read))
      (y (read))
      (lst1 '(1 3 5 7 8 10 12))
      (lst2 '(4 6 9 11))
      (lst3 '(2)))

  (format t "~A~%"
          (cond ((and (member x lst1) (member y lst1)) "Yes")
                ((and (member x lst2) (member y lst2)) "Yes")
                ((and (member x lst3) (member y lst3)) "Yes")
                (t "No"))))


Measured memory_bytes: 7268
for i in [0]*input():
  s=raw_input()
  n=(len(s)-4)/2
  if n>0 and s==">'"+"="*n+"#"+"="*n+"~": t="A"
  elif n>0 and s==">^"+"Q="*n+"~~": t="B"
  else: t="NA"
  print t

Measured memory_bytes: 4204
#include <stdio.h>
#include <stdlib.h>
int main(void) {int a,b,i;int *c;scanf("%d",&b);c=(int*)calloc(b,sizeof(int));for(i=0;i<b;++i){scanf("%d",&a);c[i]=a;}while(--b){printf("%d ",c[b]);}printf("%d\n",*c);free(c);return 0;}

Measured memory_bytes: 608
#include<cstdio>
using namespace std;

int binarySearch(int S[],int key,int n){
	int left = 0,right = n;
	int mid;
	while(left<right){
		mid = (left + right)/2;
		if(key == S[mid]){
			return 1;
		}else if(key < S[mid]){
			right = mid;
		}else{//key???S[mid]????????§????????´????????????????????§?????£???????????????????????£?????´???
			left = mid + 1;
		}
	}
	return 0;
}

int main(){
	int n,S[100000];
	int q,T;
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&T);
		if(binarySearch(S,T,n)) sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1420
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>

using namespace std;

const int SIZE = 1 << 10;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

map<int, int> seen;

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        seen[x]++;
    }
    int answer = 0;
    for (auto &it : seen)
        if (it.second < it.first)
            answer += it.second;
        else
            answer += it.second - it.first;
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 4736