akhauriyash/Code-Regression huggingface dataset:
// ※※※ 解答不能 ※※※
// tourist氏.
// https://atcoder.jp/contests/arc103/submissions/3295817
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    int N;
    scanf("%d", &N);
    vector<LL> x(N), y(N);
    for(int i = 0; i < N; i++) scanf("%lld %lld", &x[i], &y[i]);
    vector<LL> d;
    vector<string> s(N, "");
    if((x[0] & 1) == (y[0] & 1)){
        d.push_back(1);
        for(int i = 0; i < N; i++){
            s[i].push_back('U');
            y[i]--;
        }
    }
    
    LL step = 1;
    while(step < (1LL << 33)){
        d.push_back(step);
        for(int i = 0; i < N; i++){
            if((x[i] & 1) == (y[i] & 1)){
                printf("%d\n", -1);
                return 0;
            }
            if(x[i] & 1){
                if(((x[i] - 1) & 2) != (y[i] & 2)){
                    x[i]--;
                    s[i].push_back('R');
                }else{
                    x[i]++;
                    s[i].push_back('L');
                }
            }else{
                if(((y[i] - 1) & 2) != (x[i] & 2)){
                    y[i]--;
                    s[i].push_back('U');
                }else{
                    y[i]++;
                    s[i].push_back('D');
                }
            }
            x[i] /= 2;
            y[i] /= 2;
        }
        step <<= 1;
    }
    
    d.push_back(step);
    for(int i = 0; i < N; i++){
        assert(x[i] * x[i] + y[i] * y[i] == 1);
        s[i].push_back(x[i] == 1 ? 'R' : (x[i] == -1 ? 'L' : (y[i] == 1 ? 'U' : 'D')));
    }
    
    int m = (int) d.size();
    printf("%d\n", m);
    for(int i = 0; i < m; i++){
        if(i > 0) printf(" ");
        printf("%lld", d[i]);
    }
    printf("\n");
    for(int i = 0; i < N; i++){
        int l = s[i].size();
        for(int j = 0; j < l; j++) printf("%c", s[i][j]);
        printf("\n");
    }
    return 0;
    
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 20 + 5

int n, m, c, ans, B[N], A[N][N];

int main()
{
	scanf("%d%d%d", &n, &m, &c);
	for (int i = 1; i <= m; i ++)
		scanf("%d", B + i);
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++)
			scanf("%d", A[i] + j);
	for (int i = 1; i <= n; i ++)
	{
		int sum = c;
		for (int j = 1; j <= m; j ++)
			sum += A[i][j] * B[j];
		if (sum > 0)
			ans ++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  ll n;
  cin >>n;
  string g={};
  ll f=26;
  ll w=0;
  for(int i=1;i<30;i++){
    if(n>f){n-=f;f*=26;continue;}
    else{
      rep(d,i){
        f/=26;
        ll e=(n+f-1)/f;
        n-=(e-1)*f;
        char gg=96+(int)e;
        g+=gg;
      }
      cout << g << endl;
      return 0;
    }

  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<long>a(n);
    long sum = 0;
    for(int i = 0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    unsigned long min= -1;
    for(int i = 0; i<n-1; i++){
        if(i>0)
            a[i] += a[i-1];
        long sunu = a[i];
        long arai = sum-a[i];
        long dis = abs(sunu-arai);
        if(dis<min)
            min = dis;
    }
    cout<<min;
}

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

int a[400][400], n, m;
bool played[400];
vector <int> is_in[400];

bool rem(int game)
{
    played[game] = 0;
    for (auto i : is_in[game]) {
        int cnt(0);
        while (!played[a[i][cnt]] && cnt <= m)
            cnt++;
        if (cnt > m)
            return false;
        is_in[a[i][cnt]].push_back(i);
    }
    is_in[game].clear();
    return true;
}

int ans()
{
    int best = 1e9;
    for (int i(1); i <= m; i++)
        played[i] = 1;

    for (int i(1); i <= n; i++)
        is_in[a[i][1]].push_back(i);

    while (1) {
        int pmax(0);
        for (int j(0); j <= m; j++)
            if (is_in[j].size() > is_in[pmax].size())
                pmax = j;
        best = min(best, (int)is_in[pmax].size());
        if (!rem(pmax))
            return best;
    }
}


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

    for (int i(1); i <= n; i++)
        for (int j(1); j <= m; j++)
            cin >> a[i][j];


    cout << ans();

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int count, nums[n + 1];
    memset(nums, 0, sizeof(nums));
    for (int i = 0; i < n - 1; i++)
    {
        scanf("%d", &count);
        nums[count]++;
    }
    for (int i = 1; i <= n; i++)
        printf("%d\n", nums[i]);
}

Measured memory_bytes: 4644
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

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


int main() {
	ll N,K;
	cin >> N>>K;
	vector<ll>A(N);
	rep(i,N) {
		A[i] = i;
	}
	ll B=0;
	rep(i, K) {
		ll b;
		cin >> b;
		B |= (1 << b);
	}

	for (int i = 0; i < (1 << N); ++i) {
		if ((i&(~B)) == 0) {
			vector<ll>C;
			for (int j = 0; j < N; ++j) {
				if ((i&(1 << j))) {
					C.push_back(A[j]);
				}
			}
			cout << i << ":";
			for (int j = 0; j < C.size(); ++j) {
				cout << " " << C[j];
			}
			cout << endl;
		}
	}
	return 0;
}


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

int main(){
  int H,W,N;
  cin >> H >> W >> N;
  if(W>H){
    int tmp=H;
    H=W;
    W=tmp;
  }
  int x;
  if(N%H==0) x = N/H;
  else x = N/H+1;
  cout << x;
  
  return 0;
}

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

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

using namespace std;
using ll = long long;

int main()
{
    ll N,Q;
    ll sum=0;
    cin>>N;
    map<ll,ll> m;
    rep(i,N){
        ll a;
        cin>>a;
        sum+=a;
        m[a]++;
    }
    cin>>Q;
    rep(i,Q){
        ll b,c,nb;
        cin>>b>>c;
        if(m[b]==0){
            cout << sum << endl;
        }else{
            nb = m[b];
            m[b] = 0;
            m[c] += nb;
            sum = sum - nb*b + nb*c;
            cout << sum << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 9280
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var c = [];
	c[0] = line[0].split(" ");
	c[1] = line[1].split(" ");
	c[2] = line[2].split(" ");
	var sum = 0;
	for(var i = 0; i < c.length; i++){
		for(var j = 0; j < c[i].length; j++){
			c[i][j] = Number(c[i][j]);
			sum += c[i][j];
		}
	}
	if(sum%3 !== 0){
		console.log('No');
	} else{
		var difcol = [c[0][1]-c[0][0], c[0][2]-c[0][1]];
		var difrow = [c[1][0]-c[0][0], c[2][0]-c[1][0]];
		if(c[1][1]-c[1][0] !== difcol[0] || c[1][2]-c[1][1] !== difcol[1]){
			console.log('No');
		} else if(c[2][1]-c[2][0] !== difcol[0] || c[2][2]-c[2][1] !== difcol[1]){
			console.log('No');
		} else if(c[1][1]-c[0][1] !== difrow[0] || c[2][1]-c[1][1] !== difrow[1]){
			console.log('No');
		} else if(c[1][2]-c[0][2] !== difrow[0] || c[2][2]-c[1][2] !== difrow[1]){
			console.log('No');
		} else{
			console.log('Yes');
		}
	}
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
def f(a, b):
  res = 0
  for x, y in zip(a, b):
    res += (x - y) ** 2
  res **= 0.5
  return res.is_integer()
  
N, D = [int(x) for x in input().split()]
XND = ['' for _ in range(N)]
for n in range(N):
  XND[n] = [int(x) for x in input().split()]

res = 0
for a in range(N - 1):
  for b in range(a + 1, N):
    if f(XND[a], XND[b]):
      res += 1
print(res)

Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;
ll max(ll x, ll y) {
	return x > y ? x : y;
}
ll count1(ll num, int i) {
	return (num / (1LL << (i + 1)) * (1LL << i) +
			max(0, num % (1LL << (i + 1)) - (1LL << i)));
}
int main() {
	ll a, b;
	ll ans = 0;
	scanf("%lld%lld", &a, &b);
	for (int i = 0; i < 63; i++) {
		ll cnt1 = count1(b + 1, i) - count1(a, i);
		// printf("%lld %lld\n", count1(b, i), count1(a - 1, i));
		if (cnt1 % 2 == 1) {
			ans += (1LL << i);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1712
import numpy
def func(s):
	if s % 2 == 0:
		return int(s/2)
	else:
		return 3*s + 1
s = int(input())
check = numpy.zeros(1000010)
check[s] = 1
Ind = 1
while True:
	s = func(s)
	Ind += 1
	if check[s] == 1:
		print(Ind)
		exit()
	else:
		check[s] = 1

Measured memory_bytes: 21652
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int h, w, mx = 0;
	scanf("%d %d", &h, &w);
	vector<vector<int>> a(h, vector<int>(w));
	for(int i = 0; i < h; ++i)
	{
		for (int j = 0, k; j < w; ++j)
		{
			scanf("%d", &k);
			a[i][j] = !k;
		}
	}
	for(int i = 1; i < h; ++i)
	{
		for(int j = 0; j < w; ++j)
		{
			if(a[i][j])
			{
				a[i][j] += a[i - 1][j];
			}
		}
	}
	for(int i = 0; i < h; ++i)
	{
		stack<pair<int, int>> s;
		for(int j = 0, hor = 0; j < w; hor = ++j)
		{
			for(int t, u; !s.empty(); )
			{
				t = s.top().first;
				u = s.top().second;
				if(t >= a[i][j])
				{
					mx = max(mx, t * (j - u));
					hor = min(hor, u);
					s.pop();
				}
				else
				{
					break;
				}
			}
			s.push(make_pair(a[i][j], hor));
		}
		for(; !s.empty(); mx = max(mx, s.top().first * (w - s.top().second)), s.pop());
	}
	printf("%d\n", mx);
}



Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define push_back pb

const int mod = 1000000007;

int main(){
    int N;
    cin >> N;
    int dp[N + 1], h[N + 1];
    repn(i, 1, N){cin >> h[i];}
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    rep(i, 2, N){
        dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i - 1] + abs(h[i + 1] - h[i - 1]));
    }
    cout << dp[N];
}

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

typedef long long LL;
const int MAXN=2e5+5;
const int MAXM=1e5+5;
const int mod=1e9+7;
const double pi=acos(-1);

char x[MAXN];
int n,num[30],pos[30][MAXN],vis[MAXN],y[MAXN],bit[MAXN];

void add(int p,int v){
	for(int i=p;i<=n;i+= i & (-i)) 
		bit[i]+=v;
}

int query(int p){
	int sum=0;
	for(int i=p;i>0;i-= i & (-i))
		sum+=bit[i];
	return sum;
}

int main(){
	scanf("%s",x+1);
	n=strlen(x+1);
	memset(num,0,sizeof(num));
	memset(vis,0,sizeof(vis));
	for(int i=0;i<26;i++){
		pos[i][0]=0;
	}
	for(int i=1;i<=n;i++){
		int ch=x[i]-'a';
		num[ch]++;
		pos[ch][++pos[ch][0]]=i;
	}
	int cnt=0;
	for(int i=0;i<26;i++){
		if (num[i]%2==1) cnt++;
	}
	if (cnt>1){
		puts("-1");
		return 0;
	}
	int tot=0;
	for(int i=1;i<=n;i++){
		if (vis[i]==1) continue;
		int ch=x[i]-'a';
		if (i==pos[ch][pos[ch][0]]){
			y[i]=n/2+1;
			continue;
		}
		y[i]=++tot;
		y[pos[ch][pos[ch][0]--]]=n-tot+1;
		vis[pos[ch][pos[ch][0]+1]]=1;
	}
	memset(bit,0,sizeof(bit));
	LL ans=0;
	for(int i=1;i<=n;i++){
		add(y[i],1);
		ans+=i-query(y[i]);
		//cout<<y[i]<<' '<<query(y[i])<<endl;
	}
	printf("%lld\n",ans);
    return 0;
}

/*
ataatmma
12367458
     22
12345458
abbabccaa
125384679
000102110
*/

Measured memory_bytes: 22912
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextLong()
  val a = (1..n).map { sc.nextLong() }

  val map = mutableMapOf<Long, Long>()
  for (ai in a) {
    val tmp = map.getOrElse(ai) { 0 }
    map.put(ai, tmp+1)
  }

  var sum = 0L
  for (mi in map) {
    val value = mi.value
    val tmp = value * (value-1) / 2
    sum += tmp
  }

  val ans = mutableListOf<Long>()
  for (ai in a) {
    val value = map.getOrElse(ai) { 1 }
    val tmp = value * (value-1) / 2
    val tmpSum = sum - tmp

    val tmp2 = (value-1) * (value-2) / 2
    ans.add(tmpSum + tmp2)
  }


  println(ans.joinToString("\n"))
}


Measured memory_bytes: 84456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    ll t = 0, s = 1;
    for (int i = 0; i < n; i++) {
        t += a[i] * s;
        s *= -1;
    }
    t /= 2;

    for (int i = 0; i < n; i++) {
        cout << t * 2 << " \n"[i == n - 1];
        t = a[i] - t;
    }
    cout << flush;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int w, h, x, y, r;
    
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    
    if ((x + r) <= w && (y + r) <= h && x >= r && y >= r) {
        printf("Yes\n");
    }else {
        printf("No\n");
    }
    return 0;
}



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

int main() {
	int n,m;
	cin >> n >> m;
	int ans = 0;
	if(n==1&&m==1){
	    ans = 0;
	}
	else{
	    ans = (n*(n-1))/2 + (m*(m-1))/2;
	}
	cout << ans ;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,d,i,j,sum = 0,num = 0;
	int x[100][100];
	scanf("%d %d",&n,&d);
	for(i = 0; i < n; i++){
		for(j = 0; j < d; j++){
			scanf("%d",&x[i][j]);
		}
	}
	
	for(int k = 0; k < n; k++){
	for(i = k + 1; i < n; i++){
		for(j = 0; j < d; j++){
			sum += (x[i][j] - x[k][j]) * (x[i][j] - x[k][j]);
		}
	    for(j = 0; j <= sum; j++){
			if(sum == j * j){
				num += 1;
			}
	    }
		sum = 0;
	}
	}
	printf("%d",num);
}

Measured memory_bytes: 1732
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

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

    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab_s(n);
    rep(i, n)
    {
        cin >> ab_s[i].first >> ab_s[i].second;
        ab_s[i].first;
    }
    sort(ab_s.begin(), ab_s.end());

    // 隣接リスト. {i, to}
    vector adjs(n + 1, vector<pair<int, int>>());
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        ++r;
        // ここ注意
        int l_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(l, -1)) - ab_s.begin();
        int r_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(r, -1)) - ab_s.begin();
        if (l_ == r_)
        { // 無駄な辺は無視
            continue;
        }
        adjs[l_].push_back({i, r_});
        adjs[r_].push_back({i, l_});
    }

    // 差を取るための番兵
    ab_s.insert(ab_s.begin(), {0, 0});
    ab_s.emplace_back(1000'000'002, 0);

    vector used(n + 1, false), cut(m, false);
    auto dfs = [&](auto self, int v) -> int {
        used[v] = true;
        // 差
        int ret = ab_s[v + 1].second ^ ab_s[v].second;
        for (auto &[i, u] : adjs[v])
        {
            if (used[u])
            {
                continue;
            }
            if (self(self, u))
            {
                cut[i] = true;
                ret = 1 - ret;
            }
        }
        return ret;
    };
    dfs(dfs, n);
    rep(v, n)
    {
        if (used[v])
        {
            continue;
        }
        if (dfs(dfs, v))
        {
            cout << -1 << "\n";
            return 0;
        }
    }
    int cnt = accumulate(cut.begin(), cut.end(), 0);
    cout << cnt << '\n';
    rep(i, m)
    {
        if (cut[i])
        {
            cout << i + 1 << ' ';
        }
    }

    return 0;
}


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

int main() {
    int n,a,b;
    cin >> n>>a>>b;
    
    int hoge = 0;
    
    for(int i = 1;i<=n;i++){
        int fuga = i%10 + ((i-i%10)/10)%10 + ((i-i%100)/100)%10 + ((i-i%1000)/1000)%10 + (i-i%10000)/10000;


if(fuga>=a&&fuga<=b){
    hoge+=i;
}
    }
    
    cout << hoge<<endl;
	return 0;
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 168
//A - ∴ (Therefore)
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n;

    cin >> n;

    switch (n%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon" << endl;
			break;
		default:
			cout << "bon" << endl;
			break;
	}
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n; cin >> n;
  string s; cin >> s;
  int count=0,count_max=0,pt=0;
  for(int i=0;i<n;++i){
    if(s[i]=='E') count++;
    else count--;
    if(count_max < count){
      count_max = count;
      pt = i;
    }
  }
  int ans=0;
  for(int i=0;i<pt;++i){
    if(s[i]=='W') ans++;
  }
  for(int i=pt+1;i<n;++i){
    if(s[i]=='E') ans++;
  }
  //cout << "pt = " << pt << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 720
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

int n,imem;
ll cnt,mx;
bool f[100][10];
int p[100][11],spcnt[100];

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> n;
	lp(n)
		lop(10, j)
				cin >> f[i][j];
	lp(n)
		lop(11, j)
			cin >> p[i][j];
	mx = LLONG_MIN;
	for (int i = 1; i < 1024; i++) {
		cnt = 0;
		lop(n, j)
			spcnt[j] = 0;
		imem = i;
		lop(10, j) {
			if (imem % 2 == 1) {
				lop(n, k) {
					if (f[k][j])spcnt[k]++;
				}
			}
			imem = imem >> 1;
		}
		lop(n, j) {
			cnt += p[j][spcnt[j]];
		}
//		cout << bitset<10>(i) << sp << cnt << endl;
		mx = max(mx, cnt);
	}

	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
int main(){
  int n,inindex;
  long long num,val;
  vector<int> Index;
  map<int,long long> List;
  while(true){
    scanf("%d",&n);
    if(n == 0)break;
    List.clear();
    Index.clear();
    for(int i=0;i<n;i++){
      cin >> inindex >> num >> val;
      if(!List[inindex]){
	Index.push_back(inindex);
      }
      List[inindex]+=val*num;
    }
    bool NAf=true;
    for(int i=0;i<Index.size();i++){
      if(List[Index[i]] >= 1000000){
	printf("%d\n",Index[i]);
	NAf=false;
      }
    }
    if(NAf)printf("NA\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	int l = 0, r = n - 1;
	while (l < r) {
		if (s[l] == 'W') {
			while (r > l and s[r] == 'W') --r;
			if (r > l) {
				++ans;
				++l;
				--r;
			}
		} else ++l;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3728
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class EDividingChocolate {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int H, W, K;
        in>>H>>W>>K;
        vc<string> grid(H);
        REP(i, H) in>>grid[i];
        int ans = H + W;
        REP(i, 1<<(H-1)){
            vc<int> pos = {0};
            REP(j, H-1) if(i>>j&1) pos.pb(j+1);
            pos.pb(H);
            vc<int> cnt(LEN(pos)-1, 0), ncnt(LEN(pos)-1, 0);
            int tmp = LEN(pos) - 2;
            REP(j, W){
                bool ok = true;
                REP(k, LEN(pos)-1){
                    int l = pos[k], r = pos[k+1];
                    FOR(m, l, r) if(grid[m][j]=='1') ncnt[k]++;
                    if(ncnt[k]>K) tmp = ten(6);
                    if(cnt[k]+ncnt[k]>K) ok = false;
                }
                if(ok){
                    REP(k, LEN(pos)-1) cnt[k] += ncnt[k], ncnt[k] = 0;
                }else{
                    ++tmp;
                    REP(k, LEN(pos)-1) cnt[k] = ncnt[k], ncnt[k] = 0;
                }
            }
            chmin(ans, tmp);
        }
        out<<ans<<'\n';
    }
};


int main() {
	EDividingChocolate solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
from itertools import product
c = [list(map(int, input().split())) for i in range(3)]

"""
a0 = 0 とする
すると
b0 = c00 - a0
b1 = c01 - a0
b2 = c02 - a0
"""

a = [0, None, None]
b = [c[0][i] - a[0] for i in range(3)]

a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]

f = True
for i in range(3):
    for j in range(3):
        if c[i][j] != a[i]+b[j]:
            f = False
            break
if f:
    print('Yes')
else:
    print('No')
    


Measured memory_bytes: 9148
// A C++ program that implements Z algorithm for pattern searching 
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int sex[100010];
int main(void) {
	int n;cin >> n;
	printf("%d\n",0);fflush(stdout);
	bool M;
	string s;cin >> s;
	if (s == "Vacant") {
		return 0;
	}
	else {
		if(s == "Male") sex[0] = 1;
		else sex[0] = 2;
	}

	printf("%d\n", n-1); fflush(stdout);
	cin >> s;
	if (s == "Vacant") {
		return 0;
	}
	sex[n-1] = 3 - sex[0];

	int l = 0,r = n-1;
	for (int i = 0; i < 18; i++) {
		int mid = (l+r)/2;
		printf("%d\n", mid); fflush(stdout);
		cin >> s;
		if (s == "Vacant") {
			return 0;
		}
		else {
			if(s == "Male") sex[mid] = 1;
			else sex[mid] = 2;
		}
		if (((mid - l) % 2 == 0) == ( sex[mid] == sex[l])) {
			l = mid;
		}
		else {
			r = mid;
		}
	}
}

Measured memory_bytes: 852
package main

import (
	"fmt"
)

func findMax(nums []int) (max int) {
	max = 0
	for i := 0; i < len(nums); i++ {
		if nums[i] > max {
			max = nums[i]
		}
	}
	return
}

func getSum(nums []int) (sum int) {
	sum = 0
	for i := 0; i < len(nums); i++ {
		sum += nums[i]
	}
	return
}

func main() {
	var N int
	fmt.Scan(&N)
	nums := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&nums[i])
	}
	max := findMax(nums)
	sum := getSum(nums)
	fmt.Println(sum - (max / 2))
}


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

int main()
{
auto mod = [](ll modx){modx%=mo;modx+=mo;modx%=mo;return modx;};
ll n ;
cin >> n ;
string x;
cin >> x;
ll oth=0;
vector<ll> ii;
ll tt=1;
rep(i,n){
  ii.push_back(tt);
  tt*=2;
  tt%=mo;
}
map<ll,ll> m;
for (ll i = n%2 ? n:n-1; i >= 3; i-=2)
{
  if(n%i==0 ){
    ll cou=1;
    ll tem=0;
    rep(j,(n/i)){
      if(x[j]=='1'){tem*=2;tem++;tem%=mo;}
      else {tem*=2;tem%=mo;}
    }
    tem++;
    while(1){
      bool ng=0;
      rep(j,(n/i)){
        if(cou%2&&x[j]=='1'&&x[j+cou*(n/i)]=='1'){
          ng=1;
          break;
        }
        else if(cou%2&&x[j]=='0'&&x[j+cou*(n/i)]=='0'){
          ng=1;
          tem--;
          break;
        }
        else if(cou%2==0&&x[j]=='1'&&x[j+cou*(n/i)]=='0'){
          ng=1;
          tem--;
          break;
        }
        else if(cou%2==0&&x[j]=='0'&&x[j+cou*(n/i)]=='1'){
          ng=1;
          break;
        }
      }
      if(ng)break;
      cou++;
      if(cou>=i)break;
    }
    if(tem<0)tem=0;
    for (auto j = m.begin(); j != m.end(); ++j) {
      if((n/i)%j->first==0 && ((n/i)/j->first)%2)tem-=j->second;
    }
    m[(n/i)]=tem;
    oth+=tem;
    oth%=mo;
    ans+=tem*(n/i)*2;
    ans%=mo;
    //cout << tem*(n/i)*2 <<" " << tem << endl;

  }
}

ll num=0;
rep(i,n){
  if(x[i]=='1')num+=ii[n-1-i];
  num%=mo;
}
ans+=mod(num-oth+1)*x.size()*2;

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


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

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int> 

int main(){
	int n;
	cin >> n;
	vector <int> a(n),b(n),c(n);
	for(int i=0;i<n;i++)	cin >> a[i];
	for(int i=0;i<n;i++)	cin >> b[i];
	for(int i=0;i<n;i++)	cin >> c[i];
	ll int ans = 0;
	for(int i=0;i<n;i++){
		int dish = a[i]-1;
		ans += b[dish];
		if(i>0 && a[i-1]+1 == a[i])	ans += c[a[i-1]-1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
string s;
int dp[200010];
signed main(){
    cin>>s;
    int p=1;
    dp[s.size()-1]=s[s.size()-1]-'0';
    for(int i=s.size()-2;i>=0;i--){
        p*=10;
        p%=2019;
        dp[i]=(dp[i+1]+((s[i]-'0')*p)%2019)%2019;
    }
    map<int,int>mp;
    mp[0]++;
    rep(i,s.size()){
        mp[dp[i]]++;
    }
    int ans=0;
    for(P p:mp){
        ans+=p.se*(p.se-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5316
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {

    int N, Q; cin >> N >> Q;
    string S; cin >> S;

    // 累積和
    int sum[100010];
    sum[0] = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'A' && S[i+1] == 'C') sum[i+1] = sum[i] + 1;
        else sum[i+1] = sum[i];
    }

    // 問いの入力値受け取り
    for (int i = 0; i  < Q; ++i) {
        int l, r; cin >> l >> r;
        int res = sum[r-1] - sum[l-1];
        cout << res << endl;
    }
}



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

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    string s;
    cin>>s;
    int n = s.size();
    int a[n+1]={};
    for(int i=0;i<n+1;i++) a[i]=1e9;
    if(s[0]=='<') a[0]=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='>' && s[i+1]=='<'){
            a[i+1] = 0;
        }
    }
    if(s[n-1]=='>') a[n]=0;
    for(int i=0;i<n;i++){
        if(s[i]=='<') a[i+1] = a[i]+1;
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='>') a[i] = a[i+1]+1;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='<' && a[i] >= a[i+1]){
            a[i+1] = a[i]+1;
        }
        else if(s[i]=='>' && a[i]<=a[i+1]){
            a[i] = a[i+1] + 1;
        }
    }
    for(int i=0;i<n+1;i++){
        //cerr << a[i] << " ";
        //if(i!=n) cout << s[i] << " ";
        ans += a[i];
    }
    //cerr << endl;
    cout << ans << endl;
}

Measured memory_bytes: 2844
from itertools import chain
N, T = map(int, input().split())
# A = [0]*(N+1)
# B = [0]*(N+1)
AB = [(0, 0)]
for i in range(1, N+1):
    a, b = map(int, input().split())
    # A[i] = a
    # B[i] = b
    AB.append((a, b))
AB.sort()
dp = [[-1]*(6000+1) for _ in range(N+1)]
#dp[i][t]: 注文後にt秒になっている時、i番目までを考慮したとき、
#の最大
dp[0][0] = 0
for i in range(1, N+1):
    a, b = AB[i]
    for t in range(T):
        dp[i][t+a] = max(dp[i][t+a], dp[i-1][t] + b)
        dp[i][t] = max(dp[i][t], dp[i-1][t])
print(max(chain.from_iterable(dp)))

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

#define fi first
#define se second

const int N = 100100;
const int Q = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //freopen("teleports.in", "r", stdin);
        //freopen("teleports.out", "w", stdout);
        ios_base::sync_with_stdio(0);


        int n;
        cin >> n;
        int a = 0, b = 0, c = 0, res = 0;
        for(int i = 1; i <= n; i++){
                string s;
                cin >> s;
                for(int j = 1; j < s.size(); j++){
                        res += (s[j - 1] == 'A' && s[j] == 'B');
                }
                if(s[0] == 'B' && s[s.size() - 1] == 'A'){
                        a += 1;
                } else if(s[0] == 'B'){
                        b += 1;
                } else if(s[s.size() - 1] == 'A'){
                        c += 1;
                }
        }
        int g = min(min(a / 2, b), c);
        res += 3 * g;
        a -= g * 2;
        b -= g;
        c -= g;
        g = min(min(a, b), c);
        res += 2 * g;
        a -= g;
        b -= g;
        c -= g;
        g = min(b, c);
        res += g;
        b -= g;
        c -= g;
        if(a){
                res += min(1, b + c);
                res += a - 1;
        }
        cout << res << "\n";
}


Measured memory_bytes: 256
def solve():
    from sys import stdin
    lines = stdin
    
    x1, y1 = map(float, lines.readline().split(','))
    x2, y2 = map(float, lines.readline().split(','))
    
    vx1 = x2 - x1
    vy1 = y2 - y1
    
    area = 0
    for line in lines:
        x3, y3 = map(float, line.split(','))
        
        vx2 = x3 - x1
        vy2 = y3 - y1
        
        area += abs(vx1 * vy2 - vy1 * vx2) / 2
        
        vx1, vy1 = vx2, vy2
    
    print(area)

solve()


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

ll n,m;
vector<vector<ll> > v(100009);
ll memo[100009];

ll fil(ll i)
{
    if(memo[i]!=-1)return memo[i];

    ll ans=0;
    for(ll j=0;j<v[i].size();j++)
    {
        ans=max(ans,1+fil(v[i][j]));
    }
    return memo[i]=ans;
}
int main()
{
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        ll s,e;
        cin>>s>>e;
        v[s].push_back(e);
    }
    memset(memo,-1,sizeof(memo));
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans=max(ans,fil(i));
    }
    cout<<ans<<endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int d, g, p[11], c[11];
  cin >> d >> g;
  for(int i = 0; i < d; ++i) cin >> p[i] >> c[i];

  int ans = 1e9;
  for(int i = 0; i < (1 << d); ++i){
    int s = 0, num = 0, rest_max = -1;
    for(int j = 0; j < d; ++j) {
      if(i  >> j & 1) {
        s += 100 * (j+1) * p[j] + c[j];
        num += p[j];
      } else {
        rest_max = j;
      }
    }
    if(s < g) {
      int s1 = 100 * (rest_max + 1);
      int need = (g - s + s1 -1) / s1;
      if(need >= p[rest_max]) continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll P, Q, R;

int main() {
	scanf("%lld %lld %lld", &P, &Q, &R);
	ll ans = min(P + Q, min(Q + R, R + P));
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  ll a = a1 - b1;
  ll b = a2 - b2;
  if (a * t1 + b * t2 == 0 || a == 0 || b == 0)
  {
    cout << "infinity" << endl;
    return 0;
  }

  if (a / abs(a) == b / abs(b))
  {
    cout << 0 << endl;
    return 0;
  }

  //a,bはともに0でない，かつ異符号

  if (a < 0 && b > 0)
  {
    a *= -1, b *= -1;
  }

  //上に凸

  if (a * t1 > -b * t2)
  {
    cout << 0 << endl;
    return 0;
  }

  //への字になる

  ll m1 = a * t1, m2 = b * t2;
  ll m = m1 + m2;
  ll ans = (m1 / (-m)) * 2 + 1;
  if (m1 % (-m) == 0)
    ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(_n) for _n in input().split()]
A.sort(reverse=True)
if 0 in A:
    print(0)
    exit()

res = 1
for i in range(N):
    res *= A[i]
    if res > 10**18:
        print(-1)
        exit()
print(res)

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

int main() {
    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; ++i) cin >> D[i];
    sort(begin(D), end(D));

    int res = D[0];
    int l = D[0], r = 0;
    for(int i=1; i<N; ++i) {
        if(i % 2) {
            res = min({res, D[i] - r, 24 - l - D[i]});
            r = D[i];
        } else {
            res = min({res, D[i] - l, 24 - r - D[i]});
            l = D[i];
        }
    }
    cout << res << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1000000000+7;
/*
O(K^3log N)
*/
struct Mat{
	vector< vector<ll> > mat; int N;
	Mat(int n) : N(n),mat(n,vector<ll>(n,0)){}
	Mat operator *(const Mat &tmp)const{
		Mat ans(N);
		forn(i,0,N)forn(j,0,N)forn(k,0,N){
			ans.mat[i][j] = (ans.mat[i][j] + this->mat[i][k] * tmp.mat[k][j] % mod) % mod;
		}
		return ans;
	}
};
Mat power(Mat a,ll b){
	Mat ans(a.N);
	forn(i,0,a.N)ans.mat[i][i] = 1;
	while(b){
		if(b&1) ans = ans*a;
		b >>= 1;
		a = a*a;
	}
	return ans;
}
ll N,K;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	Mat mat(N);
	forn(i,0,N)forn(j,0,N){
		int x; cin >> x;
		mat.mat[i][j] = x;
	}
	mat = power(mat,K);
	ll res = 0;
	forn(i,0,N)forn(j,0,N){
		res += mat.mat[i][j];
		res %= mod;
	}
	if(res < 0)res += mod;
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

void changeNum(int* X,int* Y){
    int buff = *Y;
    *Y = *X;
    *X = buff;
    return;
}

int main(){

    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);

    if(a>b){
        changeNum(&a,&b);
    }
    if(b>c){
        changeNum(&b,&c);
    }
    if(a>b){
        changeNum(&a,&b);
    }

    printf("%d %d %d\n",a,b,c);
}



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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}
// 75 : 3 5 5
// 75
// 3 25
// 5 15
// 3 5 5

int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int p = sizeof(primes)/sizeof(int);
int main() {
    int n = ri();
	int res = 0;
	vector<int> prime_num;
	for (auto i : primes) {
		int d = n;
		int tmp = 0;
		while (d) {
			d /= i;
			tmp += d;
		}
		prime_num.push_back(tmp);
	}
	
	/*
	for (auto i : prime_num) {
		cout << i << endl;
	}*/
	
	// 75
	FOR(i, p) {
		if (prime_num[i] >= 74) {
			res++;
			// cout << "75:" << i << endl;
		}
	}
	
	// 3 * 25, 5 * 15
	FOR(i, p) {
		FOR(j, p) {
			if (i == j) continue;
			if (prime_num[i] >= 2 && prime_num[j] >= 24) {
				res++;
				// cout << "3-25:" << i << ":" << j << endl;
			}
			if (prime_num[i] >= 4 && prime_num[j] >= 14) {
				res++;
				// cout << "5-15:" << i << ":" << j << endl;
			}
		}
	}
	
	// 3*5*5
	FOR(i,p) {
		FOR(j,p) {
			if (i == j) continue;
		    FOR(k,j) {
				if (k == i) continue;
				if (prime_num[i] >= 2 &&
					prime_num[j] >= 4 &&
					prime_num[k] >= 4) {
						// cout << "3-5-5:" << i << ":" << j << ":" << k << endl;
						res++;
					}
			}
		}
	}
	
	cout << res << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    vec a(N);
    rep(i,N )cin>>a[i];
    if(a[0] != 0){
        cout<<-1<<endl;
        return 0;
    }
    ll last = a[N - 1], ans = a[N - 1];
    Rrep(i, N - 1){
        if(last - a[i] > 1){
            cout<<-1<<endl;
            return 0;
        }else if(last - a[i] <= 0){
            ans += a[i];
        }
        last = a[i];
    }
    cout<<ans<<endl;
}

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


int main(){
	long long int d,t,s,di;
	cin>>d>>t>>s;

	di = t*s;
	if(di>=d)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
vll s;
void dfs(const vvll&graph,ll v,ll p) {
    for (auto next_v:graph[v]) {
        if(next_v == p){continue;}//next_vが親pだったらダメ
        s[next_v]+=s[v];
        dfs(graph,next_v, v); //vは新たにnext_vの親になります
    }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n,i,a,b;cin>>n;
  ll q;cin>>q;vvll grap(n);
  s.resize(n);
  rep(i,n-1){cin>>a>>b;a--;b--;grap[a].pb(b);grap[b].pb(a);}
  rep(i,q){cin>>a>>b;s[a-1]+=b;}
  //caricurate
  dfs(grap,0,-1);
  //output
  aout(i,n,s);
}

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

int main(){
    char s[200010],t[200010];
    scanf("%s",s);
    scanf("%s",t);
    int count=0;
    for(int i=0;i<strlen(s);i++){
        if(s[i]!=t[i]){
            count++;
        }
    }
    printf("%d",count);
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;


int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double ans;
  if(a*a*b/2 < x){
    double h = 2*x/(a*a) - b;
    ans =atan2(b-h, a);
  }
  else{
    double h = 2*x/(a*b);
    ans = atan2(b, h);
  }
  printf("%.9f\n", ans * 180 / acos(-1));
  return 0;
}



Measured memory_bytes: 512