akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(int yy = 0; yy < YY; ++yy)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll N; cin >> N;
    cout << N * N << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(55, vector<char>(55, ' '));
    int num = 0;
    rep(i, H) {
        rep(j, W) {
            cin >> s[i + 1][j + 1];
            if (s[i + 1][j + 1] == '.') num++;
        }
    }
    vvi dist(55, vi(55, -1));
    queue<pii> q;
    q.push(mp(1, 1));
    dist[1][1] = 1;
    while (!q.empty()) {
        pii P = q.front();
        q.pop();
        int x, y;
        tie(x, y) = P;

        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx <= 0 || nx > H || ny <= 0 ||
                    ny > W || s[nx][ny] != '.' || dist[nx][ny] != -1) {
                continue;
            }
            else {
                dist[nx][ny] = dist[x][y] + 1;
                q.push(mp(nx, ny));
            }
        }
    }
    if(dist[H][W] != -1) cout << num - dist[H][W] << endl;
    else cout << -1 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    if(a%2==0 && b%2!=0){
        ll c = (b-a+1)/2;
        if(c%2==0) ans=0;
        else if(c%2!=0) ans=1;
    }
    if(a%2==0 && b%2==0){
        ll c = (b-a)/2;
        if(c%2==0) ans=b;
        else if(c%2!=0) ans=b+1;
    }
    if(a%2!=0 && b%2!=0){
        ll c = (b-a)/2;
        if(c%2==0) ans=a;
        else if(c%2!=0) ans=a-1;
    }
    if(a%2!=0 && b%2==0){
        ll d = a^b;
        ll c = (b-a-1)/2;
        if(c%2==0 && d%2==0) ans=d;
        if(c%2!=0 && d%2==0) ans=d+1;
        if(c%2!=0 && d%2!=0) ans=d-1;
        if(c%2==0 && d%2!=0) ans=d;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int x, y;
    int i;
    int out = 0;
    scanf("%d %d", &x, &y);
    for (i = 0; i <= x; i++){
        if ((i * 2 + (x - i) * 4) == y){
            out = 1;
            break;
        }
    }
    if (out == 1){
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  // 10000円の枚数を 0 〜 N で調べる
        for (int b = 0; b + a <= N; ++b) {  // 5000円の枚数を 0 〜 N-a で調べる
            int c = N - a - b;  // 1000円の枚数は決まる
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  // 答えが見つかったら
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include <string.h>
#include<limits.h>
int main(void){
	int x, y, z, i;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	scanf("%d%d", &x, &y);
	while (x != 0 && y != 0) {
		for (i = 0; i < x; i++) {
			printf("#");
			for (z = 0; z < y-2; z++) {
				if (i == 0 || i == x-1) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("#\n");
		}
		printf("\n");
		scanf("%d%d", &x, &y);
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <typename T, typename E = T>
class LazySegmentTree
{
public:
    LazySegmentTree(int n, const T &tunit, const E &eunit) : _tunit(tunit), _eunit(eunit)
    {
        _n = 1 << __lg(2 * n - 1);
        _data.resize(2 * _n - 1, tunit);
        _lazy.resize(2 * _n - 1, eunit);
    }

    void set(int k, const T &x) { _data[k + _n - 1] = x; }

    void build(void)
    {
        for (int i = _n - 2; i >= 0; i--) _data[i] = f(_data[2 * i + 1], _data[2 * i + 2]);
    }

    void update(int a, int b, const E &x) { return _update(a, b, x, 0, 0, _n); }

    T query(int a, int b) { return _query(a, b, 0, 0, _n); }

private:
    int _n;             // 要素数
    vector<T> _data;    // データを格納する配列
    vector<E> _lazy;    // 遅延評価するデータを格納する配列
    T _tunit;
    E _eunit;

    T f(const T &a, const T &b) { return max(a, b); }
    T g(const T &a, const E &b) { return a + b; }
    E h(const E &a, const E &b) { return a + b; }

    void eval(int k)
    {
        if (_lazy[k] == _eunit) return;
        if (k < _n - 1) {
            _lazy[2 * k + 1] = h(_lazy[2 * k + 1], _lazy[k]);
            _lazy[2 * k + 2] = h(_lazy[2 * k + 2], _lazy[k]);
        }
        _data[k] = g(_data[k], _lazy[k]);
        _lazy[k] = _eunit;
    }

    void _update(int a, int b, const E &x, int k, int l, int r)
    {
        eval(k);
        if (a <= l && r <= b) {
            _lazy[k] = h(_lazy[k], x); eval(k);
        } else if (a < r && l < b) {
            _update(a, b, x, 2 * k + 1, l, (l + r) >> 1);
            _update(a, b, x, 2 * k + 2, (l + r) >> 1, r);
            _data[k] = f(_data[2 * k + 1], _data[2 * k + 2]);
        }
    }

    T _query(int a, int b, int k, int l, int r)
    {
        eval(k);
        if (r <= a || b <= l) {
            return _tunit;
        } else if (a <= l && r <= b) {
            return _data[k];
        } else {
            T left = _query(a, b, k * 2 + 1, l, (l + r) >> 1);
            T right = _query(a, b, 2 * k + 2, (l + r) >> 1, r);
            return f(left, right);
        }
    }
};

struct S {
    int l, r; ll a;
    bool operator<(const S &rhs) const { return r < rhs.r; }
};

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

    int n, m; cin >> n >> m;
    vector<S> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].l >> v[i].r >> v[i].a;
    }

    sort(v.begin(), v.end());

    LazySegmentTree<ll> seg(n + 1, 0, 0);
    for (int i = 0, j = 0; i < m && j <= n; j++) {
        seg.update(j, j + 1, seg.query(0, j));
        while (j == v[i].r) {
            seg.update(v[i].l, j + 1, v[i].a);
            i++;
        }
    }

    ll ans = seg.query(0, n + 1);
    cout << ans << endl;
    return 0;
}


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

int main()
{
  bool p[1000001];
  int n, ans;

  for(int i=0; i<=1000000; i++){
    p[i] = (i<=1)? false : true ;
  }

  for(int i=2; i<=sqrt(1000000)+1; i++){
    if(p[i]){
      for(int j=i*2; j<=1000000; j+=i){
        if(j%i == 0)
        p[j] = false;
      }
    }
  }

  while( cin >> n ){
    ans = 0;
    for(int i=0; i<=n; i++){
      if(p[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include <iostream>
#include <map>

using namespace std;

int N;
map<int, bool> a_dict;

int main() { 
  ios_base::sync_with_stdio(false);
  
  cin >> N;

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

    auto iter = a_dict.find(num);
    if (iter == a_dict.end()) {
      a_dict[num] = true;
    } else {
      iter->second = 1 - iter->second;
    }
  }

  int cnt = 0;
  for(auto &iter : a_dict) {
    if(iter.second) {
      ++cnt;
    }
  }

  cout << cnt << endl;

  
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int main(void){
    int N,J=0;
    double X,B=0;
    char S[4];
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        scanf("%lf %s",&X,S);
        if(strcmp(S,"JPY")==0){
            J=J+X;
        }
        else{
            B=B+X;
        }
    }
    printf("%lf\n",J+(B*380000));

    return 0;
}


Measured memory_bytes: 128
# https://beta.atcoder.jp/contests/abc094/tasks/abc094_b


def solve():
    N, M, X = map(int, input().split())
    A = [0 for _ in range(N + 1)]
    cost = list(map(int, input().split()))
    for i in cost:
        A[i] = 1

    print(min(sum(A[X:]), sum(A[:X])))


if __name__ == '__main__':
    solve()


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

int main() {
	long n,i,cur;
	cin >> n;
	vector<long> h(n);
	for(i=0; i<n; i++){
		cin >> h[i];
	}
	for(i=n-1; i>0; i--){
		if(h[i]-h[i-1]==-1){
			h[i-1]--;
		}else if(h[i]<h[i-1]){
			cout << "No"; return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    int n;cin >> n;
    vector<vector<int>> v(n-1, vector<int>(3, 0));
    for(int i = 0; i < n-1; i++) {
        int c,s,f;cin >> c >> s >> f;
        v[i][0]=c;
        v[i][1]=s;
        v[i][2]=f;
    }

    for(int i = 0; i < n-1; i++) {
        ll ans=v[i][1]+v[i][0];

        for(int j = i+1; j < n-1; j++) {
            if(ans<v[j][1]) ans=v[j][1]+v[j][0];
            else{
                int x=(ans-1)/v[j][2]+1;
                ans = x*v[j][2]+v[j][0];
            }
        }
        cout << ans << endl;
    }
    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 3664
#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>;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, r;
    cin >> n >> r;
    if(n < 10) r += 100*(10-n);
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


string s[10000];
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  int c = 0;
  int x = 0, y = 0, z = 0;
  for(int i = 0; i < n; i++) {
    cin >> s[i];
    int m = s[i].size();
    for(int j = 0; j < m-1; j++) {
      if(s[i].substr(j, 2) == "AB") c++;
    }
    char t = s[i].front(), u = s[i].back();
    if(t == 'B' && u == 'A') y++;
    else if(t == 'B') z++;
    else if(u == 'A') x++;
  }
  int w = min(x, z);
  if(x + z) {
    c += w;
    c += y;
  } else {
    c += max(0, y - 1);
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define pii pair<int,int>
using namespace std;
const int maxn = 4100;
ll prefcnt[maxn][3], n;
string s;

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

	for(int i=1;i<=n;i++) {
		for(int j=0;j<3;j++) {
			prefcnt[i][j] += prefcnt[i-1][j];
		}

		if(s[i-1] == 'R') prefcnt[i][0]++;
		else if(s[i-1] == 'G') prefcnt[i][1]++;
		else prefcnt[i][2]++;
	}	

	ll result = 0LL;
	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {
			if(s[i-1] == s[j-1]) continue;

			int ind = -1;
			for(int d=0;d<3;d++) {
				if(prefcnt[j][d] == prefcnt[j-1][d] && prefcnt[i][d] == prefcnt[i-1][d]) ind = d;
			}

			result += 1LL * prefcnt[i][ind];

			int diff = j - i;

			if(i - diff >= 1) {
				if(s[i-diff-1] == 'R' && ind == 0) result--;
				if(s[i-diff-1] == 'G' && ind == 1) result--;
				if(s[i-diff-1] == 'B' && ind == 2) result--;
			}
		}
	}

	cout<<result;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;



int main(){
    string S;
    cin >> S;
    string last;
    while (!(S.empty())){
        last = S.substr(S.size() - 3);
        if (last=="eam"){
            if (S.substr(S.size()-5)=="dream"){
                S.erase(S.size() - 5);
            }
            else{
                cout << "NO" << endl;
                return 0;
            }
        }
        else if (last=="mer")
        {
            if (S.substr(S.size() - 7) == "dreamer")
            {
                S.erase(S.size() - 7);
            }
            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }
        else if (last=="ase")
        {
            if (S.substr(S.size() - 5) == "erase")
            {
                S.erase(S.size() - 5);
            }
            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }
        else if (last=="ser")
        {
            if (S.substr(S.size() - 6) == "eraser")
            {
                S.erase(S.size() - 6);
            }
            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        double D = sc.nextInt();
        // スペース区切りの整数の入力
        double T = sc.nextInt();
        double S = sc.nextInt();

        double X;
        X = D/S;

      
      	if(X<=T){
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }

    }
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

bool used[250000];
int m, k;
int N;
vi inc, noc;
int main(){
	cin >> m >> k;
	N = (1<<m) - 1;
	if (m == 1 && k == 1)return cout << -1 << '\n', 0;
	if (N < k) return cout << -1 << '\n', 0;
	//cout << N << '\n';
	for (int i = m; i >= 0; --i){
		int u = (1<<i);
	//	cout << u << '\n';
		if ((k & u) > 0){
			inc.push_back(u);
			used[u] = 1;
		}
	}
	for (int i = 0; i <= N; i++) if (!used[i]) noc.pb(i);
	for (int i = 0; i < noc.size(); i++) cout << noc[i] << ' ';
	for (int i = 0; i < inc.size(); i++) cout << inc[i] << ' ';
	reverse(noc.begin(), noc.end());
	for (int i = 0; i < noc.size(); i++) cout << noc[i] << ' ';
	reverse(inc.begin(), inc.end());
	for (int i = 0, t = inc.size(); i < t; i++){
		cout << inc[i] << " \n"[i==t-1];
	}
	return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int x, y;
	char aqua[] = {'0', 'a', 'c', 'a', 'b', 'a', 'b', 'a', 'a', 'b', 'a', 'b', 'a'};
	cin >> x >> y;

	if (aqua[x] == aqua[y]) 
		cout << "Yes";
	else
		cout << "No";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    //input
    int n = sc.nextInt();

    //output
    int cost = n%1000;
    if( cost == 0 ){
      System.out.println(0);
    }else{
      System.out.println(1000-cost);
    }

  }
}


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

int main()
{
  int N;
  cin >> N;
  
  int value = N;
  while(true)
  {
    if((value % value == 0) && (value % 2 == 0))
      break;
    else
      value *= 2;
  }
  
  cout << value << endl;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,q:usize,
        a:[u64;n],
        q:[(usize,usize,usize);q],
    }

    let mut bt = BIT::<SUM>::new(3 * n + 10);
    let mut base = 5;
    for (i, &x) in a.iter().enumerate() {
        bt.add(i + base, &x);
    }
    for &(q, a, b) in q.iter() {
        if q == 1 {
            println!("{}", bt.sum(b + base - 1) - bt.sum(a + base - 1));
        } else {
            bt.add(a + base, &(b as u64));
        }
    }
}
pub trait Monoid {
    type T: Clone;
    fn id() -> Self::T;
    fn op(a: &Self::T, b: &Self::T) -> Self::T;
}
pub struct SUM {}
impl Monoid for SUM {
    type T = u64;
    fn id() -> Self::T {
        0
    }
    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        *a + *b
    }
}
/// Generic Binary Indexed Tree
pub struct BIT<M: Monoid> {
    buf: Vec<M::T>,
}
impl<M: Monoid> BIT<M> {
    pub fn new(n: usize) -> Self {
        Self {
            buf: vec![M::id(); n + 1],
        }
    }
    pub fn sum(&self, i: usize) -> M::T {
        let mut i = i;
        let mut s = M::id();
        while i > 0 {
            s = M::op(&s, &self.buf[i]);
            i -= 1 << i.trailing_zeros();
        }
        s
    }
    pub fn add(&mut self, i: usize, x: &M::T) {
        let mut i = i;
        while i < self.buf.len() {
            let t = &mut self.buf[i];
            *t = M::op(&t, x);
            i += 1 << i.trailing_zeros();
        }
    }
}


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

const int MAXN = 3010;

typedef std::bitset<MAXN> B;
char arr[MAXN << 1];
int n, L[MAXN], R[MAXN], cr[MAXN << 1];
void decode(B t, char * dst) {
	for (int i = 1; i <= n * 2; ++i)
		if (t.test(cr[i]))
			*dst++ = arr[i];
	*dst = 0;
}
bool cmp(B src, B dst) {
	static char s1[MAXN << 1], s2[MAXN << 1];
	decode(src, s1); decode(dst, s2);
	return strcmp(s1, s2) < 0;
}
void getmax(B & a, B b) { cmp(a, b) ? (a = b, 0) : 0; }
B dp[MAXN];

int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> arr + 1;
	for (int i = 1, ta = 0, tb = 0; i <= n * 2; ++i)
		arr[i] == 'a' ? L[++ta] = i : R[++tb] = i;
	for (int i = 1; i <= n; ++i) cr[L[i]] = i;
	for (int i = 1; i <= n; ++i) cr[R[i]] = i;
	for (int i = n; i; --i) {
		static B t;
		dp[i] = dp[i + 1];
		if (L[i] < R[i]) {
			int r = *std::max_element(cr + L[i], cr + R[i] + 1);
			(t = dp[r + 1]).set(i);
			getmax(dp[i], t);
		} else {
			t.reset();
			int rr = L[i];
			for (int j = R[i]; j <= n * 2 && j <= rr; ++j) {
				if (arr[j] == 'b') {
					t.set(cr[j]);
					rr = std::max(rr, L[cr[j]]);
				}
			}
			int r = *std::max_element(cr + R[i], cr + rr + 1);
			getmax(dp[i], t | dp[r + 1]);
		}
	}
	decode(dp[1], arr);
	std::cout << arr << std::endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,sol,a[20],x[20][20],y[20][20];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        for(int j=1;j<=a[i];++j) cin>>x[i][j]>>y[i][j];
    }
    for(int step=1;step<(1<<n);++step)
    {
        bool ok=1;
        for(int i=0;i<n;++i)
            if(step&(1<<i))
                for(int j=1;j<=a[i+1];++j)
                    ok&=(((step&(1<<(x[i+1][j]-1)))>0)==y[i+1][j]);
        if(ok) sol=max(sol,__builtin_popcount(step));
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, L; cin >> N >> L;
    vector<int> a(N+5, 0);
    int sum = 0;
    for(int i=1; i<=N; i++) { a[i] = L+i-1; sum += a[i]; }
    int minv = 1000000;
    bool flg = true;
    
    for(int i=1; i<=N; i++){
        if(minv > abs(a[i])){
            minv = abs(a[i]);
            if(a[i] < 0) flg = false;
        }
    }

    if(flg) cout << sum - minv << endl;
    else cout << sum + minv << endl;
    
}

Measured memory_bytes: 256
import numpy as np

def main():
    # N, M = map(int, input().split())
    # PS = {}
    # for i in range(M):
    #     row = input().split()
    #     row[0] = int(row[0])
    #     if row[0] not in PS:
    #         PS[row[0]] = [row[1]]
    #     else:
    #         PS[row[0]].append(row[1])

    # n_correct = 0
    # n_penalty = 0
    # for p in PS:
    #     if 'AC' in PS[p]:
    #         n_correct += 1
    #         for result in PS[p]:
    #             if result == 'AC':
    #                 break
    #             if result == 'WA':
    #                 n_penalty += 1
    
    # print('{} {}'.format(n_correct, n_penalty))

    N, M = map(int, input().split())
    accepted = [False] * N
    penalties = [0] * N
    for _ in range(M):
        q, res = input().split()
        q = int(q) - 1
        if res[0] == 'A':
            accepted[q] = True
        elif res[0] == 'W' and not accepted[q]:
            penalties[q] += 1

    s_acc = 0
    s_pen = 0
    for i in range(N):
        if accepted[i]:
            s_acc += 1
            s_pen += penalties[i]

    print('{} {}'.format(s_acc, s_pen))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 14016
#include <iostream>

using namespace std;

long long r[1000010],l[1000010];
int main(){
    long long i,n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    n--;
    for(i=0;i<=n;i++){
        if(a+i*c-(n-i)*d<=b && b<=a+i*d-(n-i)*c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<queue>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 100005
#define M 2005
#define ll long long
int n;
ll ans,cnt;
char s[N][15];
int arr[N];
bool cmp(int a,int b)
{
	return strcmp(s[a],s[b])<0;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%s",s[i]);
    	sort(s[i],s[i]+10);
    	arr[i]=i;
	}
	sort(arr+1,arr+n+1,cmp);
	cnt=1;
	for(int i=1;i<=n;i++)
	{
		//puts(s[arr[i]]);
		if(strcmp(s[arr[i-1]],s[arr[i]])==0)
    		cnt++;
    	else
    	{
    		ans+=cnt*(cnt-1)/2;
    		cnt=1;
		}
		//printf("%lld\n",cnt);
	}
	if(cnt) ans+=cnt*(cnt-1)/2;
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2048
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  rep(i, m)  {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < pow(10, n); i++) {
    string t = to_string(i);
    bool flag = true;
    rep(j, m) {
      if (t[s[j]] != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag && t.size() == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long n;
void bs/*Binary_search*/(long long l, long long m){
    if(((l + m) / 2) * ((l + m) / 2) <= n && ((l + m) / 2 + 1) * ((l + m) / 2 + 1) > n){
        cout << ((l + m) / 2) * ((l + m) / 2) << endl;
    }
    else if((l + m) / 2 * (l + m) / 2 < n)
        bs((l + m)/ 2, m);
    else 
    bs(l, (l + m) / 2);
}
void solve(){
    cin >> n;
    bs(1, n);
}
int main(){
    solve();
    return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
 
const int N = 1e5 + 5;
 
multiset <int> l1,l2,r1,r2;
multiset <int> :: iterator it,it2;
 
int x,y,z,n,a[N],b[N],c[N],id[N];
ll suml,sumr,sumc,ans,nice;
 
void add_l(int x){
  if (l1.size() < ::x) {
    suml += a[x];
    l1.insert(-a[x]);
  }
  else {
    it = prev(l1.end());
    if (-*it < a[x]) {
      suml += a[x];
      suml -= -*it;
      l2.insert(*it);
      l1.erase(it);
      l1.insert(-a[x]);
    }
    else
      l2.insert(-a[x]);
  }
}
 
void add_r(int x) {
  if (r1.size() < y) {
    sumr += b[x];
    r1.insert(-b[x]);
  }
  else {
    it = prev(r1.end());
    if (-*it < b[x]) {
      sumr += b[x];
      sumr -= -*it;
      r2.insert(*it);
      r1.erase(it);
      r1.insert(-b[x]);
    }
    else
      r2.insert(-b[x]);
  }
}
 
void remove_r(int x) {
  if (r2.empty() && r1.empty())
      return;
  else if (r2.empty()) {
    it = r1.find(-b[x]);
    if (it != r1.end()) {
      sumr -= -*it;
      r1.erase(it);
    }
  }
  else {
    it = r2.find(-b[x]);
    if (it != r2.end()) {
      r2.erase(it);
      return;
    }
    it = r1.find(-b[x]);
    if (it != r1.end()) {
      sumr -= -*it;
      r1.erase(it);
      if (r2.empty() == false) {
        it2 = r2.begin();
        sumr += -*it2;
        r1.insert(*it2);
        r2.erase(it2);
      }
    }
  }
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> x >> y >> z;
  n = x + y + z;
  for (int i = 1 ; i <= n ; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i] -= c[i];
    b[i] -= c[i];
    nice += c[i];
    id[i] = i;
  }
  sort(id + 1,id + n + 1,[&](int x,int y) {
    if (a[x] - b[x] == a[y] - b[y])
      return a[x] > a[y];
    return a[x] - b[x] > a[y] - b[y];
  });
  for (int i = 1 ; i <= x ; i++)
    add_l(id[i]);
  for (int i = x + 1 ; i <= n ; i++)
    add_r(id[i]);
  ans = suml + sumr;
  for (int i = x + 1 ; i <= n ; i++) {
    if (n - i < y)
      break;
    add_l(id[i]);
    remove_r(id[i]);
    ans = max(ans,suml + sumr);
  }
  cout << ans + nice << "\n";
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define long long long
using namespace std;
const long N=1e6,inf=1e9;
string s;long k;
long dp[1000+2][2][10+2];
long dfs(long p,long ck,long k)
{
  if(k<0)return 0;
  if(dp[p][ck][k]!=-1)return dp[p][ck][k];
  if(p==s.size())
  {
    if(k==0)return 1;return 0;
  }
  long nm=s[p]-'0',now=0;
  for(long i=0;i<10;i++)
  {
    if(!ck)
    {
      if(i==0)now+=dfs(p+1,0,k);else now+=dfs(p+1,0,k-1);
    }
    else
    {
      if(i>nm)continue;
      if(i==nm)
      {
        if(i==0)now+=dfs(p+1,1,k);else now+=dfs(p+1,1,k-1);
      }
      else
      {
        if(i==0)now+=dfs(p+1,0,k);else now+=dfs(p+1,0,k-1);
      }
    }
  }
  return dp[p][ck][k]=now;
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin>>s>>k;
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,1,k)<<endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{

    lli a, b, c, d;
    cin>>a>>b>>c>>d;

    bool ok = 1;
    while(a > 0 and c > 0) {
        if(ok) {
            c -= b;
            ok = 0;
        }
        else {
            a -= d;
            ok = 1;
        }
    }
    if(a <= 0) {
        cout<<"No";
    }
    else {
        cout<<"Yes";
    }
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
int N;
string S;
int check(int len) {
	if (len == 0)return 1;
	string cur;
	map<string, vector<int>>mp;
	for (int i = 0; i < len; i++)cur += S[i];
	for (int left = 0; left + len <= N; left++) {
		mp[cur].pb(left);
		if (left + len - 1 == N-1)break;
		cur.erase(cur.begin());
		cur.pb(S[left+len]);
	}
	fore(x, mp) {
		auto v = x.second;
		if (v.size() >= 2) {
			int idx1 = v[0];
			int idx2 = v.back();
			if (idx2 >= idx1 + len)return 1;
		}
	}
	return 0;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	cin >> N >> S;
	int ok = 0, ng = N + 1;
	while (ng - ok > 1) {
		int mid = (ng + ok) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	puts(ok);
 
	return 0;
}

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

using namespace std;

typedef long long ll;

vector<ll> par; ll N;

void init(){
  par.resize(N);
  for(ll i  = 0; i < N; i++){
    par[i] = i;}}

ll root(ll x){
  if( x == par[x]){ return x;}
  else{ return par[x] = root(par[x]);}}

void unite(ll x, ll y){
  if( root(x) == root(y)){ return ;}
  else{
    par[root(x)] = root(y);}
}

bool issame( ll x, ll y){
  return root(x) == root(y);}
  

int main(){
 cin >> N; init();
  
  vector<pair<ll,ll>> x(N); vector<pair<ll,ll>> y(N);
  for(int i = 0; i < N; i++){
    cin >> x[i].first >> y[i].first; x[i].second = i; y[i].second = i;}
  //xが何番目のノードのx座標なのかも保持する
  sort(x.begin(),x.end()); sort(y.begin(),y.end());
  
  vector<pair<ll,pair<ll,ll>>> Edge; Edge.clear();
  //各Edgeがどのノード同士を結んで、重みがなんなのかも持たなければいけない
  
  for(int i = 0; i < N - 1; i++){
    Edge.push_back(make_pair(x[i+1].first - x[i].first,make_pair(x[i+1].second,x[i].second)));}
  for(int j = 0; j  < N - 1; j++){
    Edge.push_back(make_pair(y[j+1].first - y[j].first,make_pair(y[j+1].second,y[j].second)));}
  //Edgeには多くても2*(N-1)本のedgeが重みと結ぶ点同士を含んで格納されている
  sort(Edge.begin(),Edge.end()); //重みについてGreedy
  
  ll ans = 0;
  
  for(int i = 0; i < Edge.size(); i++){
    ll s = Edge[i].second.first;
    ll t = Edge[i].second.second;
    if(!issame(s,t)){  ans += Edge[i].first; unite(s,t);}
  } //Greedy(Kruskal)
  cout << ans << endl; return 0;}
    
  

Measured memory_bytes: 12400
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int flag = 0;
  for(int i = 1; i < s.size() + 1; i++){
      if(i % 2 == 0){
          if(s[i - 1] == 'R'){
              cout << "No" << endl;
              flag = 1;
              break;
          }
      }
      if(i % 2 != 0){
          if(s[i - 1] == 'L'){
              cout << "No" << endl;
              flag = 1;
              break;
          }
      }
  }
  if(flag != 1){
      cout << "Yes" << endl;
  }

}

Measured memory_bytes: 256
import collections

n=int(input())
arr=list(map(int,input().split()))
ans=0
cnt=collections.defaultdict(int)
for i in range(1,n+1):
  if i-arr[i-1] in cnt:
    ans+=cnt[i-arr[i-1]]
  cnt[i+arr[i-1]]+=1
print(ans)

Measured memory_bytes: 40792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	

	int mod = 1000000007;
	int morty[1000031];

	void solve(){

		ini(n);
		vi tmp(n);
		FOR(i,0,n){
			in(tmp[i]);
			morty[tmp[i]]++;
		}
		for(int i =1000000;i>=1;i--){
			if(morty[i]){
			for (int  i1 = i+i; i1 < 1000031; i1+=i)
			{
				morty[i1]++;
			}
			}
		}
		int rick = 0;
		FOR(i,0,n){
			if(morty[tmp[i]] == 1)rick++;
		}
		out(rick);
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 12580
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2000+10;
int mabs(int x){
    if(x<0) return x*-1;
    return x;
}
int main()
{
    int n,a,b;
    while(~scanf("%d%d%d",&n,&a,&b)){
       if(mabs(a-b)%2==0) printf("Alice\n");
       else printf("Borys\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN 100
#if !testing
#define cerr if(0)cout
#endif
int A[MAXN];
int32_t main() {
	IAMSPEED
	int n; cin >> n;
	FOR(i,1,n)cin>>A[i];
	int mn = inf, mx = -inf;
	FOR(i,1,n) {
		chmin(mn,A[i]);
		chmax(mx,A[i]);
	}
	int mnidx, mxidx;
	FOR(i,1,n) {
		if(A[i]==mn)mnidx=i;
		if(A[i]==mx)mxidx=i;
	}
	vector<pi> v;
	if(abs(mx)>=abs(mn)) {
		FOR(i,1,n) {
			v.pb({mxidx,i});
			A[i]+=A[mxidx];
		}
		FOR(i,2,n) {
			v.pb({i-1,i});
			A[i]+=A[i-1];
		}
	} else {
		FOR(i,1,n) {
			v.pb({mnidx,i});
			A[i]+=A[mnidx];
		}
		DEC(i,n,2) {
			v.pb({i,i-1});
			A[i-1]+=A[i];
		}
		
	}
	dba(A,1,n);
	cout<<v.size()<<'\n';
	for(auto i : v) {
		cout<<i.f<<' '<<i.s<<'\n';
	}
}


Measured memory_bytes: 256
from collections import Counter
def solve():
    ans = 0
    mod = 10**9+7
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    for i in range(N):
        if (N-1-i)==i:
            if 0 not in c or c[0]!=1:
                return 0
        else:
            p = abs((N-1-i)-i)
            if p not in c or c[p]!=2:
                return 0
    ans = pow(2,N//2,mod)
    return ans
print(solve())

Measured memory_bytes: 20484
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int C[510], S[510], F[510];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i] >> S[i] >> F[i];
	}
	for (int i = 0; i < N - 1; i++) {
		int ans = S[i] + C[i];
		for (int j = i + 1; j < N - 1; j++) {
			if (ans <= S[j]) ans = S[j];
			else {
				if (ans % F[j] != 0) ans += F[j] - (ans % F[j]);
			}
			ans += C[j];
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int a, b, c, x;
    int ans=0;
    
    scanf("%d%d%d%d", &a, &b, &c, &x);
    
    rep(i, a+1){
        rep(j, b+1){
            rep(k, c+1){
                if (500*i+100*j+50*k==x) {
                    ans++;
                }
            }
        }
    }
    
    printf("%d", ans);
    
    return 0;
}


Measured memory_bytes: 1704
import sys
N, M = list(map(int, input().split()))
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    sys.exit()
if N > M:
    N, M = M, N
    S, T = T, S


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


L = N * M // gcd(N, M)
n = L // N
m = L // M
l = n * m // gcd(n, m)
for i in range(l, L, l):
    if S[i // n] != T[i // m]:
        print(-1)
        sys.exit()
print(L)


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, c, x, y, t, ans = 0;
	
	cin >> a >> b >> c >> x >> y;
	c <<= 1;
	t = min(x, y);
	
	if (c <= a + b)
	{
		ans += c * t;
		x -= t, y -= t;
	}//if
	else
	{
		ans += (a + b) * t;
		x -= t, y -= t;
	}//else
	
	if (c <= a)
		ans += x * c;
	else
		ans += x * a;
		
	if (c <= b)
		ans += y * c;
	else
		ans += y * b;
	
	cout << ans;
	
	return 0;
}//main


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			n /= i;
			ans[i]++;
		}
	}
	if (n != 1) ans[n]++;
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

int n, ans;
map<string, int>mp;
signed main() {
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		sort(all(s));
		mp[s]++;
	}
	for (auto p : mp) {
		int a = p.second;
		ans += a * (a - 1) / 2;
	}
	cout << ans << endl;
}

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

template<typename T>
class BIT {
    public:
    int n;
    vector<T> dat; // i: [1,n]

    BIT(int size): n(size+1), dat(vector<T>(n+1)) {}

    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += dat[i];
            i -= i & -i;
        }
        return ret;
    }

    T range(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

using ll = long long;

// i < j, (v[i] op v[j]) を満たす(i,j)の組を数える
template<typename T>
ll inversion(vector<T> v, string op) {
    assert(op == "<=" || op == ">=" || op == ">" || op == "<");
    if (op == ">=" || op == "<") {
        reverse(v.begin(), v.end());
    }

    ll size = v.size();
    vector<pair<T, int>> vp(size);
    rep(i,size) {
        vp[i] = {v[i],i};
    }
    sort(vp.begin(), vp.end());

    // 小さい順に 1..size の連番を振る
    vector<int> order(size);
    rep(i,size) {
        order[vp[i].second] = i+1;
    }

    // i < j, order[i] <= order[j] の個数を数える
    ll result = 0;
    BIT<ll> bt(size);
    rep(i,size){
        result += bt.sum(order[i]);
        bt.add(order[i], 1);
    }

    if (op == ">" || op == "<") {
        return size*(size-1)/2 - result;
    } else {
        return result;
    }
}

int main(void){
    string s;
    cin >> s;
    int n = s.size();

    map<char,int> sum;
    for (char c : s) {
        sum[c]++;
    }
    int odd_alpha = 0;
    for (auto itr : sum) {
        if (itr.second & 1) odd_alpha++;
    }
    if (odd_alpha >= 2) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> x(n); // s[i] -> sx[j]へ動くとき, x[i] = j
    int ai = 0, ci = (n+1)/2;
    map<char, int> cnt;
    string sa, sc;
    rep(i,n) {
        char c = s[i];
        if ((sum[c]&1) && cnt[c] == sum[c]/2) {
            x[i] = n/2;
        } else if (cnt[c] < sum[c]/2) {
            x[i] = ai++;
            sa += c;
        } else {
            x[i] = ci++;
            sc += c;
        }
        cnt[c]++;
    }

    int m = sa.size();
    map<char, vector<int>> pos;
    rep(i,m) pos[sa[i]].push_back(i);

    cnt.clear();
    reverse(all(sc));
    vector<int> t(m);
    rep(i,m) {
        char c = sc[i];
        t[i] = pos[c][cnt[c]];
        cnt[c]++;
    }

    cout << inversion(x, ">") + inversion(t, ">") << endl;

    return 0;
}


Measured memory_bytes: 7172
S = input()
N = len(S)
flag = 1
for i in range(N):
  if i%2 == 0:
    if S[i] == "L":
      flag = 0
  else:
    if S[i] == "R":
      flag = 0
if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int weights[] = {1,2,4,8,16,32,64,128,256,512,1024};
int main(){
	int n,a[10],b,c;
	while(cin >> n){
		b = 0;
		c = 11;
		while(n != 0){
			for(int i = 0;i < c;++i){
				if(n < weights[i]){
					n -= weights[i - 1];
					a[b] = i - 1;
					c = i;
					++b;
					break;
				}
			}
		}
		sort(a,a+b);
		for(int i = 0;i < b;++i){
			if(i == 0) cout << weights[a[i]];
			else cout << " " << weights[a[i]];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#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>;

int main() {
    string s, result = "";
    cin >> s;
    rep(i, s.length()){
    	switch(s[i]){
          case '0':
            result += "0";
            break;
          case '1':
           	result += "1";
            break;
          case 'B':
            if(result.length() != 0){
            	result.erase(result.length() - 1);
            }
            break;
        }
    }
  	cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;


int wa(int a){
    int ans = 0;
    while(a!=0){
        int num = a % 10;
        ans += num;
        a /= 10;
    }
    return ans;
}
int main() {
    int n,a,b; cin >> n >> a >> b;
    int count = 0;
    REP(i,1,n+1){
        if(wa(i)>=a && wa(i)<=b){
            count += i;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256