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

struct Tree{
	double x, y, d;
	
	Tree(int xx, int yy, int dd){
		x = xx;
		y = yy;
		d = dd;
	}

	bool isOK(double hx, double hy, double w, double a){
		double l = w - d/2;
		double r = w + d/2;
		l += 360 * 4;
		r += 360 * 4;
		
		double kaku = atan2((hy-y),(hx-x)) * 180/M_PI;
		
		while(l > kaku){
			kaku += 360;
		}
		
		if(r < kaku){
			return false;
		}

		if(a*a >= (hy-y)*(hy-y) + (hx-x) * (hx-x)){
			return true;
		}
		return false;

	}
};

	


int main(){

	int h, r;
	while(cin >> h >> r, h != 0){
		int x[110], y[110];
		for(int i = 0;i < h;i++) cin >> x[i] >> y[i];

		int U, M, S, du, dm, ds;
		cin >> U >> M >> S >> du >> dm >> ds;

		Tree myTree(0, 0, du);
		
		vector<Tree> tree;
		for(int i = 0;i < U;i++){
			int x, y;
			cin >> x >> y;
			tree.push_back(Tree(x, y, du));
		}
		
		for(int i = 0;i < M;i++){
			int x, y;
			cin >> x >> y;
			tree.push_back(Tree(x, y, dm));
		}


		for(int i = 0;i < S;i++){
			int x, y;
			cin >> x >> y;
			tree.push_back(Tree(x, y, ds));
		}
		
		int n = U + M + S;

		int cnt[110] = {};
		
		for(int i = 0;i < r;i++){
			int w, a;
			cin >> w >> a
;			bool flag;
			for(int j = 0;j < h;j++){
				flag = false;
				for(int k = 0;k < n;k++){
					flag = (flag || tree[k].isOK(x[j], y[j], w, a));
				}
				if(!flag && myTree.isOK(x[j], y[j], w, a)){
					cnt[j]++;
				}
			}
		}

		vector<int> ans;
		int ans_num = 0;
		for(int i = 0;i < h;i++){
			if(ans_num < cnt[i]){
				ans.clear();
				ans_num = cnt[i];
				ans.push_back(i+1);
			}else if(ans_num == cnt[i]){
				ans.push_back(i+1);
			}
		}

		if(ans_num == 0){
			cout << "NA" << endl;
		}else{
			for(int i = 0;i < ans.size();i++){
				cout << ans[i];
				if(i < ans.size()-1){
					cout << " ";
				}else{
					cout << endl;
				}
			}
		}
	}

	return 0;

}



Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    vector<string> vs;
    rep(i,h){
        string t;cin>>t;
        vs.push_back(t);
    }
    rep(i,h){
        cout<<vs[i]<<endl;
        cout<<vs[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
program main
  implicit none

  character(8000) :: s
  integer :: x, y
  integer :: lenseg(8000)

  read(*, *) s
  read(*, *) x, y

  call set_of_f(s, lenseg)
  if (possible(lenseg, x, .true.) .and. possible(lenseg, y, .false.)) then
    write(*, "(A)") "Yes"
  else
    write(*, "(A)") "No"
  end if

  contains

  pure subroutine set_of_f(s, lenseg)
    implicit none
    character(8000), intent(in) :: s
    integer, intent(out) :: lenseg(8000)
    integer :: ic, iseg

    lenseg(:) = 0
    iseg = 1
    do ic = 1, len(trim(s))
      if (s(ic:ic) == "F") then
        lenseg(iseg) = lenseg(iseg) + 1
      else
        iseg = iseg + 1
        lenseg(iseg) = 0
      end if
    end do
  end subroutine set_of_f

  function possible(lenseg, dest, is_x)
    implicit none
    integer, intent(in) :: lenseg(8000), dest
    logical, intent(in) :: is_x

    logical :: possible
    logical :: grid(-8000:8000), grid_next(-8000:8000)
    integer :: i, j, st

    grid(:) = .false.
    grid_next(:) = .false.

    if (is_x) then
      grid(lenseg(1)) = .true.
      st = 3
    else
      grid(0) = .true.
      st = 2
    end if

    do i = st, 8000, 2
      grid_next(:) = .false.
      do j = -8000, 8000
        if (grid(j)) then
          grid_next(j - lenseg(i)) = .true.
          grid_next(j + lenseg(i)) = .true.
        end if
      end do
      grid(:) = grid_next(:)
    end do

    possible = grid(dest)
  end function possible

end


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,x,y,p,ans,q,r;
  cin>>a>>b>>c>>x>>y;
  p=max(x,y);
  p=p*2*c;
  if(x<y){
    q=2*c*x+(y-x)*b;
  }
  else{
    q=2*c*y+(x-y)*a;
  }
  r=a*x+b*y;
  ans=min(p,q);
  ans=min(ans,r);
  cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  	int n;
	scanf("%d", &n);
  
  	if(n % 2 == 0){
    	printf("%d", n / 2 * n / 2);
    } else {
    	printf("%d", n / 2 * (n + 1) / 2);
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int n; cin >> n;) {
		vector<int> v(n);
		rep(i,n) cin >> v[i];
		sort(v.begin(), v.end());

		for(int i = 1; i < n; i++) {
			v[i] += v[i - 1];
		}
		cout << accumulate(v.begin(), v.end(), 0) << endl;
	}
	return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  string frame = "";
  for(int j=0;j<W+2;j++){
    frame +='#';
  }
  cout << frame << endl;
  for(int i=0;i<H;i++){
    string picture;
    cin >> picture;
    picture = '#' + picture + '#';
    cout << picture << endl;
  }
  cout << frame << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

a = []
for line in sys.stdin:
    a.append(str(line))
a = ''.join(a).lower()

d = {}
for i in "abcdefghijklmnopqrstuvwxyz":
    d[i] = 0
for i in a:
    if i in "abcdefghijklmnopqrstuvwxyz":
        d[i] += 1
for i in "abcdefghijklmnopqrstuvwxyz":
    print i,':',d[i]

Measured memory_bytes: 6380
import java.util.*;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long m =sc.nextLong();
		long n =sc.nextLong();
		long ans = lcm(m,n);
		System.out.println(ans);
		
	}
		private static long lcm(long m, long n) {
		    return m * n / gcd(m, n);
		}
		private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}


	
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long K, A, B;
	cin >> K >> A >> B;

	long long ans1 = 1 + K;
	long long ans2 = A;
	if( A > 1 ) {
		K -= A - 1;
	}
	ans2 += K / 2 * (B - A);
	ans2 += K % 2;
	long long ans = max( ans1, ans2 );

	cout << ans << endl;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 3000000;
int mod = 1000003;
int f[N], invf[N], lg[N], d[N], a[N];
int cnt, n;
vector < int > g[N];
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int cnk(int n, int k){
    return f[n] * invf[n - k] % mod * invf[k] % mod;
}
void dfs(int v, int p = -1){
    cnt++;
    d[v] = a[cnt];
    for (auto u: g[v]){
        if (u != p) dfs(u, v);
    }
}
int check(int x){
    if (x == 0 || (n / x) != (n % x)) return 0; else{

        return x;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int ans = 0;
    for (int i = 1; i * i <= n; i++){
        if (n % i == 0){
            ans += check(i - 1);
            if (i * i != n) ans += check(n / i - 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 71936
#include <stdio.h>

int main(void) {
  int n;
  int i;
  
  scanf("%d", &n);

  for(i=0; i<n; i++) {
    int max, b, c;
    
    scanf("%d %d %d", &max, &b, &c);

    if (max < b) {
      int tmp = max;
      max = b;
      b = tmp;
    }
    if (max < c) {
      int tmp = max;
      max = c;
      c = tmp;
    }

    if (max * max == b*b + c*c) {
      puts("YES");
    } else {
      puts("NO");
    }
  }

  return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <bitset>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 110;
char s[maxn][maxn];
int n, m;
int cnt[maxn];

int main() {
#ifdef __AiR_H
    freopen("B.in", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%s", s[i]);
        for (int j = 0; j < m; ++j) {
            ++cnt[s[i][j] - 'a']; cnt[s[i][j] - 'a'] %= 4;
        }
    }
    bool flag = true;
    if (n % 2 == 0 && m % 2 == 0) {
        for (int i = 0; i < 26; ++i) {
            if (cnt[i] != 0) { flag = false; break; }
        }
    } else {
        int t1 = 0, t2 = 0;
        for (int i = 0; i < 26; ++i) {
            if (cnt[i] % 4 == 1) { ++t2; }
            else if (cnt[i] % 4 == 2) { ++t1; }
            else if (cnt[i] % 4 == 3) { ++t1; ++t2; }
        }
        if (n % 2 == 1 && m % 2 == 1) {
            if (t2 > 1) { flag = false; }
            else if (t1 > (n - 1) / 2 + (m - 1) / 2) { flag = false; }
        } else if (n % 2 == 1) {
            if (t2 > 0) { flag = false; }
            else if (t1 > m / 2) { flag = false; }
        } else {
            if (t2 > 0) { flag = false; }
            else if (t1 > n / 2) { flag = false; }
        }
    }
    if (flag) { printf("Yes\n"); } else { printf("No\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 256
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
D = int(readline())
C = list(map(int,readline().split()))
score = []
for i in range(D):
    s = list(map(int,readline().split()))
    score.append(s)
t = list(map(int,read().split()))
last = [0] * 26
S = 0
for d in range(D):
    select = t[d]-1
    S += score[d][select]
    last[select] = d+1
    for i in range(26):
        S -= C[i] * (d+1-last[i]) 
    print(S)

Measured memory_bytes: 9408
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
const int inf = (int) 1e9+7;
const long long INF = -1000000000000;
int main(){
	fastIO;
	int n,m;
	long long p;
	cin>>n>>m>>p;
	vector< vector< pair<int,long long> > > v1(5003);
	vector< vector<int> > v2(5003);
	for(int i=0;i<m;i++){
		int a,b;
		long long c;
		cin>>a>>b>>c;
		--a;--b;c-=p;
		v1[a].push_back(make_pair(b,c));
		v2[b].push_back(a); 	
	}        
	queue<int> q;
	bool alg[2600];
  	for(int i=0;i<n;i++)alg[i]=false;
	q.push(n-1);
	alg[n-1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<(int)v2[x].size();i++){
			int nxt=v2[x][i];
			if(alg[nxt] == false){
				alg[nxt]=1;
				q.push(nxt);
			}
		}
	}
	
	long long d[2600];
	for(int i=0;i<2600;i++)d[i]=-1000000000000;
	d[0]=0ll;              
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(d[j] != -1000000000000){
				for(int k=0;k<(int)v1[j].size();k++){
					int nxt = v1[j][k].first;
					if(d[j] + v1[j][k].second > d[nxt]){
		      	d[nxt] = d[j] + v1[j][k].second;
					}               
				}                 			
			}		
		}
	}
 
	/*for(int i=0;i<n;i++){
		cout<<d[i]<<" ";
	}
	cout<<'\n';*/
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)v1[i].size();j++){
			int nxt=v1[i][j].first;	
			if(d[i] == -1000000000000 || d[nxt] == -1000000000000)continue;
			if(d[i] + v1[i][j].second > d[nxt] && alg[nxt]){
				cout<<-1<<'\n';
				return 0;
			}
		}
	}	
	cout<<max(0ll,d[n-1])<<'\n';
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>

#define SIZE 200000

int  n;
long a[SIZE];
long x, y, res;

int main() {
    std::cin >> n;
    for (int i=0; i<n; ++i) {
        std::cin >> a[i];
        y += a[i];
    }
    x  = a[0];
    y -= a[0];
    res = std::abs(x - y);
    for (int i=1; i<n-1; ++i) {
        x += a[i];
        y -= a[i];
        res = std::min(res, std::abs(x-y));
    }
    std::cout << res << std::endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= 9; i++){
    if(n % i == 0 && n / i <= 9){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	int N;
	vector<int> A;

	cin >> N;

	for (auto i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}

	int index = 0;
	while (index < N - 1)
	{
		sort(A.begin(), A.end());

		for (; index < N; ++index)
		{
			if (A[index] > 0)
			{
				break;
			}
		}

		for (auto i = index + 1; i < N; ++i)
		{
			A[i] %= A[index];
		}
	}

	cout << A[N - 1] << endl;

	return 0;
}

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

int main() {
  int N, A, B;
  scanf("%d %d %d",&N,&A,&B);
  if ((A%2==0 && B%2==0) || (A%2!=0 && B%2!=0)) {
    printf("Alice\n");
  } else if ((A%2!=0 && B%2==0) || (A%2==0 && B%2!=0)) {
    printf("Borys\n");
  } else {
    printf("Draw\n");
  }
  return 0;
}


Measured memory_bytes: 256
// And in the end, the love you take is equal to the love you make.
//                      Paul McCartney (the Beatles). The End. Abbey Road.

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

namespace _buff {

const size_t BUFF = 1e5;
char buff[BUFF], *begin = buff, *end = buff;
char getc() {
    if (begin == end) {
        begin = buff;
        end = buff + fread(buff, 1, BUFF, stdin);
    }
    return begin == end ? -1 : *begin++;
}

}

ll read() {
    using namespace _buff;
    ll ret = 0; bool pos = true; char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 2e5 + 5;
using ii = pair<int, int>;
#define fi first
#define se second

int n, a[N];

bool check(int mid) {
    stack<ii> stk;
    for (int i = 1; i < n; ++i) {
        if (a[i] <= a[i - 1]) {
            if (mid == 1) {
                return false;
            }
            while (!stk.empty() && stk.top().fi >= a[i]) {
                stk.pop();
            }
            int cur = a[i] - 1;
            while (cur >= 0 && !stk.empty() && stk.top() == ii(cur, mid - 1)) {
                stk.pop(); --cur;
            }
            if (cur < 0) {
                return false;
            }
            if (stk.empty() || stk.top().fi < cur) {
                stk.emplace(cur, 1);
            } else {
                ++stk.top().se;
            }
        }
    }
    return true;
}

int main() {
    n = read();
    generate_n(a, n, read);
    int l = 0, r = n + 1;
    while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 5;
ll n, x, a[maxn];

inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){ if(ch == '-') w = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

inline void print(ll x){
    if(x < 0) x = ~x + 1, putchar('-');
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main(){
    n = read();
    for(int i = 1; i < n; i++) x = read(), a[x]++;
    for(int i = 1; i <= n; i++) printf("%lld\n", a[i]);

    return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, m; cin >> a >> b >> m;
	vector<int> c(a), d(b);
	for(auto &i:c) cin >> i;
	for(auto &i:d) cin >> i;
	int cmin = 1e9, dmin = 1e9;
	for(int i=0; i<a; ++i) cmin = min(cmin, c[i]);
	for(int i=0; i<b; ++i) dmin = min(dmin, d[i]);
	int ans = cmin + dmin;
	for(int i=0; i<m; ++i){
		int x, y, z; cin >> x >> y >> z; --x; --y;
		ans = min(ans, c[x] + d[y] - z);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;
int n,a[310][310];
bool b[310][310];
long long Floyd(){
	long long sum=0;
	for(int k=1;k<=n;++k){
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				if(i==k||k==j)continue;
				if(a[i][k]+a[k][j]<a[i][j])return -1;
				else if(a[i][k]+a[k][j]==a[i][j])b[i][j]=true;
			}
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(b[i][j]==false)sum+=a[i][j];
		}
	}
	sum/=2;
	return sum;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			scanf("%d",&a[i][j]);
		}
	}
	printf("%lld\n",Floyd());
	return 0;
}


Measured memory_bytes: 2160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

vector<pair<ll, ll>> sequence(ll x, ll A) {
  vector<pair<ll, ll>> seq;
  if (x < A) {
    seq.emplace_back(1, x);
  } else {
    if (A > 1) {
      seq.emplace_back(1, A - 1);
    }
    seq.emplace_back(A + 1, x + 1);
  }
  return seq;
}

ll maximumProduct(const ll len, const ll as, const ll bs) {
  ll L = 0, R = len - 1;
  while (R - L > 10) {
    ll m = (R - L) / 3;
    ll l = L + m, r = R - m;
    if ((as + l) * (bs - l) < (as + r) * (bs - r)) {
      L = l;
    } else {
      R = r;
    }
  }
  ll mx = 0;
  for (ll x = max(0ll, L - 10); x <= min(len - 1, R + 10); x++) {
    mx = max(mx, (as + x) * (bs - x));
  }
  return mx;
}

ll maximumProduct(const vector<pair<ll, ll>>& seqA,
                  const vector<pair<ll, ll>>& seqB) {
  ll mx = 0;
  ll as = 0;
  for (auto& a : seqA) {
    ll alen = a.second - a.first + 1;
    ll at = as + alen - 1;
    ll bs = 0;
    for (auto& b : seqB) {
      ll blen = b.first - b.second + 1;
      ll bt = bs + blen - 1;
      ll s = max(as, bs), t = min(at, bt);
      if (s <= t) {
        ll len = t - s + 1;
        // check
        mx = max(mx,
                 maximumProduct(len, a.first + (s - as), b.first - (s - bs)));
      }
      bs += blen;
    }
    as += alen;
  }
  return mx;
}

int main() {
  int Q;
  while (cin >> Q) {
    for (int q = 0; q < Q; q++) {
      ll A, B;
      cin >> A >> B;
      ll C = A * B;
      ll ok = 0, ng = C + 100;
      while (ng - ok > 1) {
        ll x = (ok + ng) / 2;
        assert(x > 0);
        auto seqA = sequence(x, A);
        auto seqB = sequence(x, B);
        reverse(seqB.begin(), seqB.end());
        for (auto& s : seqB) {
          swap(s.first, s.second);
        }
        if (maximumProduct(seqA, seqB) < C) {
          ok = x;
        } else {
          ng = x;
        }
      }
      cout << ok << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b;
  ci(a>>b);
  vec c(b),d(b-1);
  For(i,0,b)
    ci(c[i]);
  sort(c,c);
  For(i,0,b-1)
    d[i]=c[i+1]-c[i];
  sort(d,d);
  ll an=0;
  For(i,0,b-a)
    an+=d[i];
  co(an);
}

Measured memory_bytes: 1792
fn main() {
    let (n,m): (usize,usize) = read_pair();
    let a: Vec<i64> = read_vec();

    let mut a = a;
    let mut m = m;
    let mut k = 1<<30;
    while k > 0 && m > 0{
        a.sort_by(|a,b| b.cmp(a));
        for a in a.iter_mut() {
            if *a & k > 0 {
                *a >>= 1;
                m -= 1;
                if m == 0 { break }
            }
        }
        k >>= 1;
    }
    println!("{}", a.iter().fold(0, |s,&x| s+x))
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}

Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

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



int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s, t; cin >> s >> t;
	sort(all(s));
	sort(all(t), greater<char>());
	cout << (s < t ? "Yes" : "No") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll maxdiv = 0;
  sort(a.begin(), a.end(), greater<ll>());
  rep(i, n)
  {
    if (i == n - 1)
      continue;
    if (maxdiv < a[i] - a[i + 1])
    {
      maxdiv = a[i] - a[i + 1];
    }
  }
  ll d = a.front() - a.back();
  cout << min(k - maxdiv, d) << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
bool modBigNumber(string num, ll m)
{
    // Store the modulus of big number
    vector<int> vec;
    ll mod = 0;

    // Do step by step division
    for (int i = 0; i < num.size(); i++)
    {

        int digit = num[i] - '0';

        // Update modulo by concatenating
        // current digit.
        mod = mod * 10 + digit;

        // Update quotient
        int quo = mod / m;
        vec.push_back(quo);

        // Update mod for next iteration.
        mod = mod % m;
    }
    if (mod == 0)
        return true;
    return false;
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    fastio();
    int k;
    cin >> k;
    if (k % 2 == 0 or k % 5 == 0)
    {
        cout << "-1";
        return 0;
    }
    int i = 1;
    int a = 7;
    while (1)
    {
        if (a % k == 0)
        {
            cout << i;
            return 0;
        }
        a = a * 10 + 7;
        a %= k;
        i++;
    }
    cout << i;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  cout << N*X-max(0,N-K)*(X-Y) << endl;
}

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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MAX = 2e5+10;

int main(){ _

	int n; cin >> n;
	vector<pair<pair<int,int>,char>> v(n);
	vector<set<pair<int,char>>> line(MAX), col(MAX);
	for(auto& i : v) {
		cin >> i.f.f >> i.f.s >> i.s;
		line[i.f.s].insert({i.f.f, i.s});
		col[i.f.f].insert({i.f.s, i.s});
	}
	map<int,set<pair<int,char>>> mp1, mp2;

	for(int i=0; i<n; i++) {
		int a = v[i].f.f;
		mp1[v[i].f.s-a].insert({v[i].f.f,v[i].s});
	
		a = v[i].f.s;
		mp2[v[i].f.f+a].insert({v[i].f.s,v[i].s});
	}

	int ans = INF;
	for(auto u : mp1) {
		vector<int> last(4,-1); // l, r, d, u

		if(u.s.size() > 1) for(auto x : u.s) {
			if(x.s == 'L') {
				last[0] = x.f;
				if(last[3] != -1) ans = min(ans, abs(last[3]-last[0]));
			}
			if(x.s == 'R') last[1] = x.f;
			if(x.s == 'D') {
				last[2] = x.f;
				if(last[1] != -1) ans = min(ans, abs(last[1]-last[2]));
			}
			if(x.s == 'U') last[3] = x.f;
		}
	}
	for(auto u : mp2) {
		vector<int> last(4,-1); // l, r, d, u
		if(u.s.size() > 1) for(auto x : u.s) {
			if(x.s == 'L') last[0] = x.f;
			if(x.s == 'R') {
				last[1] = x.f;
				if(last[3] != -1) ans = min(ans, abs(last[3]-last[1]));
			}
			if(x.s == 'D') {
				last[2] = x.f;
				if(last[0] != -1) ans = min(ans, abs(last[2]-last[0]));
			}
			if(x.s == 'U') last[3] = x.f;
		}
	}

	if(ans != INF) ans *= 10;

	for(auto u : line) {
		int l=-1, r=-1;
		for(auto x : u) {
			if(x.s == 'L') {
				l = x.f;
				if(r != -1) ans = min(ans, (l-r)*5);
			}
			if(x.s == 'R') r = x.f;
		}	
	}
	for(auto uu : col) {
		int d=-1, u=-1;
		for(auto x : uu) {
			if(x.s == 'D') {
				d = x.f;
				if(u != -1) ans = min(ans, (d-u)*5);
			}
			if(x.s == 'U') u = x.f;
		}	
	}

	if(ans == INF) cout << "SAFE" << endl;
	else cout << ans << endl;
	
	return 0;
}


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

int main()
{
    
    double a, b, h, m;
    double arg, ans;
    cin >> a >> b >> h >> m;
    arg = (h*60-11*m)/360;
  	ans = sqrt(a*a+b*b - 2*a*b*cos(arg*3.14159265358979));
	printf("%12.12lf\n", ans);
}

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

class Program {
  public Program () { }

  Scanner cin;

  int N;

  List<int> b;

  static void Main (string[] agrs) {
    new Program ().Do ();
  }

  public void Do () {
    cin = new Scanner ();
    N = cin.nextInt ();
    b = new List<int> (cin.arrayInt ());

    int[] ans = new int[N];

    int tmpN = N;
    for (int i = 0; i < N; i++) {
      int max = -1;
      for (int j = 0; j < tmpN; j++) {
        if (b[j] == j + 1) {
          max = j;
        }
      }
      if (max != -1) {
        b.RemoveAt (max);
        ans[i] = max;
        tmpN--;
      } else {
        Console.WriteLine (max);
        return;
      }
    }

    for (int i = 0; i < N; i++) {
      Console.WriteLine (ans[N - 1 - i] + 1);
    }
  }
}

class Scanner {
  string[] s;
  int i;
  int max_i;

  public Scanner () {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString () {
    if (i >= s.Length) {
      s = Console.ReadLine ().Split (' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) {
        return "";
      }
      return s[i++];
    } else {
      return s[i++];
    }
  }

  public int nextInt () {
    return int.Parse (nextString ());
  }

  public long nextLong () {
    return long.Parse (nextString ());
  }

  public double nextDouble () {
    return double.Parse (nextString ());
  }

  public string[] arrayString () {
    return Console.ReadLine ().Split (' ');
  }

  public int[] arrayInt () {
    string[] str = Console.ReadLine ().Split (' ');
    int[] array = new int[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = int.Parse (str[i]);
    }
    return array;
  }

  public long[] arrayLong () {
    string[] str = Console.ReadLine ().Split (' ');
    long[] array = new long[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = long.Parse (str[i]);
    }
    return array;
  }

  public double[] arrayDouble () {
    string[] str = Console.ReadLine ().Split (' ');
    double[] array = new double[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = double.Parse (str[i]);
    }
    return array;
  }
}

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

int main(){
    int64_t n, k;
    cin >> n >> k;
    int64_t h[n];
    for(int64_t i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h, h + n);
    int64_t ans = 0;
    for(int64_t i = 0; i < n - k; i++){
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
n = gets.chomp!.to_i
order_list = []
n.times do
  arr = gets.chomp!.split(' ')
  order_list.push(arr)
end
linked_list = []
order_list.each do |order|
  if order[0] == "insert"
    linked_list.unshift(order[1].to_i)
  elsif order[0] == "delete"
    linked_list.each_with_index do |v, i|
      if(v == order[1].to_i)
        linked_list.delete_at(i)
        break
      end
    end
  elsif order[0] == "deleteFirst"
    linked_list.shift
  elsif order[0] == "deleteLast"
    linked_list.pop
  end
end
puts linked_list.join(' ')


Measured memory_bytes: 325600
#include<iostream>
#include<cmath>
#include<bitset>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int cnt(int n){
	int res=0;
	for(int i=0;(1<<i)<=n;i++)if(n&(1<<i))res++;
	return res;
}

int sum(int n){
	int res=0;
	for(int i=0;(1<<i)<=n;i++){
		if((n&(1<<i))>0)res+=(i+1);
	}
	return res;
}

int main(){
	int n,k,s;
	while(cin>>n>>k>>s,n||k||s){
		int ans=0;
		rep(i,pow(2,n)){
			if(cnt(i)==k && sum(i)==s)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int mod = 1e9+7;

const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

string a;
llint k;

int main() {
    cin >> a >> k;

    if (k == 1) {
        int sol = 0;
        int kol = 0;
        for (int i = 1; i < a.size(); i++) {
            if (a[i - 1] == a[i]) kol++;
            else sol += (kol + 1) / 2, kol = 0;
        }
        sol += (kol + 1) / 2;
        printf("%d\n", sol);
        return 0;
    }

    int n = a.size();
    llint sol = 0;
    int kol = 0;
    llint x = 0, y = 0;

    bool flag = true;
    for (int i = 1; i < n; i++) {
        if (a[i - 1] == a[i]) kol++;
        else x += (kol + 1) / 2, kol = 0, flag = false;
    }

    for (int i = 0; i < n; i++) {
        if (a[(i - 1 + n) % n] == a[i]) kol++;
        else sol += (kol + 1) / 2, kol = 0;
    }

    for (int i = 0; i < n; i++) {
        if (a[(i - 1 + n) % n] == a[i]) kol++;
        else y += (kol + 1) / 2, kol = 0;
    }
    y += (kol + 1) / 2;
    if (flag) printf("%lld", (llint)n * k / 2);
    else printf("%lld", x + sol * (k - 2) + y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b != c || b == c && c != a || c == a && a != b)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if ((500*a)+(100*b)+(50*c))==X:
                count+=1
print(count)

Measured memory_bytes: 39536
#include<iostream>
using namespace std;
int main() {
    int n,s;
    cin >> n >> s;
    int d=0;
    for (int i=0;i<n;i++){
        int a; cin>>a;
        if (a>=s) d++;
    }
    cout << d << "\n";
    return 0;
}

    
   
    



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char ch;
    int a=0,b=0,c=0;
    for(int i=0; i<3;i++){
        cin>>ch;

            switch (ch) {
               case 'a': a+=1;
                         break;
               case 'b': b+=1;
                         break;
               case 'c': c+=1;
                         break;

            }
    }

    if(a==1 && b==1 && c==1){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(false)
	//n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()

	ans := float64(0)
	for i, end := 0, len(a); i < end; i++ {
		ans += 1 / float64(a[i])
	}

	fmt.Fprintln(stdout, 1/ans)
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v.push_back(a);
    }
    v.push_back(0);

    bool run = false;
    int count = 0;
    int max_ = 0;
    for (int i = 0; i < v.size(); ++i) {
        if (v[i] == 1) {
            if (run) {
                count += 1;
            }
            else {
                run = true;
                count = 1;
            }
        }
        else {
            if (run) {
                max_ = max(max_, count);
                run = false;
            }
        }
    }
    cout << (max_ + 1) << endl;
}


Measured memory_bytes: 3144
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0;
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				int charge = x - i * 500 - j * 100;
				if (charge / 50 <= c && charge >= 0)
					ans++;
			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 26988
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define out(x) cout<<(x?"Yes":"No")<<endl;
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 100010
string s;
ll ant[N],bnt[N],cnt[N],dnt[N];
int main(){
    cin>>s;
    ant[0]=0,bnt[0]=0;
    lol(i,s.size()){
	ant[i+1]=ant[i]+(s[i]=='A');
	bnt[i+1]=bnt[i]+(s[i]=='?');
    }
    cnt[s.size()]=0,dnt[s.size()]=0;
    for(int i=s.size()-1;i>=0;i--){
	cnt[i]=cnt[i+1]+(s[i]=='C');
	dnt[i]=dnt[i+1]+(s[i]=='?');
    }
    ll ans=0;
    lol(i,s.size()){
	if(!(s[i]=='?'||s[i]=='B'))continue;
	ll p=(ant[i]*3+bnt[i])*(cnt[i+1]*3+dnt[i+1]);
	if(s[i]=='B')p*=3;
	ans+=p;
    }//cout<<ans<<endl;
    if(bnt[s.size()]==0)cout<<(ans/27)%mod<<endl;
    if(bnt[s.size()]==1)cout<<(ans/9)%mod<<endl;
    if(bnt[s.size()]==2)cout<<(ans/3)%mod<<endl;
    if(bnt[s.size()]>=3){
	for(int i=3;i<bnt[s.size()];i++)ans*=3,ans%=mod;
	cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a,b,k = ns()
    tmp= max(0, k-a)
    a = max(0, a-k)
    b = max(0,b-tmp)

    print(a,b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#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字くらい使った方がいいかも
*/

int main(){
    int N,M; cin >> N >> M;
    vector<ll> x(M);
    for(int i=0; i<M; i++) cin >> x[i];

    if(N >= M){
        cout << 0 << endl;
        return 0;
    }

    vector<ll> diff;

    sort(x.begin(), x.end());
    for(int i=1; i<M; i++) diff.push_back(x[i]-x[i-1]);

    sort(diff.begin(), diff.end(), greater<ll>());
    ll sum = 0;
    ll res = 0;
    for(int i=0; i<diff.size(); i++) sum += diff[i];
    for(int i=0; i<N-1; i++) res += diff[i];

    cout << sum-res << endl;

}

Measured memory_bytes: 2168
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

vector<string> dict;

namespace TRIE {
  struct node {
    int cnt;
    node *nxt[26];
  };
  node *newNode() {
    node *ret = (node*)malloc(sizeof(node));
    ret->cnt = 0;
    for (int i = 0; i < 26; i++) ret->nxt[i] = NULL;
    return ret;
  }
  node *add(node *last, string &str) {
    node *ret = newNode();
    node *cur = ret;
    if (last) cur->cnt = last->cnt + 1;
    else cur->cnt = 1;
    for (int i = str.length()-1; i >= -1; i--) {
      if (last) {
        for (int j = 0; j < 26; j++) {
          cur->nxt[j] = last->nxt[j];
        }
      }
      if (i == -1) break;
      cur->nxt[str[i] - 'a'] = newNode();
      cur = cur->nxt[str[i] - 'a'];
      if (last) last = last->nxt[str[i] - 'a'];
      if (last) cur->cnt = last->cnt + 1;
      else cur->cnt = 1;
    }
    return ret;
  }
  int chk(node *ver, string &str) {
    node *cur = ver;
    for (int i = str.length()-1; i >= 0 && cur != NULL; i--) {
      cur = cur->nxt[str[i] - 'a'];
    }
    if (cur) return cur->cnt;
    return 0;
  }
}
TRIE::node *ver[100005];
int substr(string &S, string &s) {
  if (s.length() > S.length()) return 0;
  for (int i = 0; i < s.length(); i++) {
    if (S[i] != s[i]) return 0;
  }
  return 1;
}

int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    dict.push_back(x);
  }
  sort(dict.begin(), dict.end());
  ver[0] = NULL;
  for (int i = 0; i < n; i++) {
    ver[i+1] = TRIE::add(ver[i], dict[i]);
  }
  while (q--) {
    string pre, suf;
    cin >> pre >> suf;
    int L = n, R = -1;
    int l = 0, r = n-1;
    while (l <= r) {
      int mid = (l + r) / 2;
      int val = substr(dict[mid], pre);
      if (dict[mid] > pre || val) {
        if (val) L = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    l = 0, r = n-1;
    while (l <= r) {
      int mid = (l + r) / 2;
      int val = substr(dict[mid], pre);
      if (dict[mid] < pre || val) {
        if (val) R = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    int ans = 0;
    if (L <= R) {
      ans = TRIE::chk(ver[R+1], suf) - TRIE::chk(ver[L], suf);
    }
    printf("%d\n", ans);
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

int n;
ll x;
ll a[N];

ll p5(int x) {
    return 1ll * x * x * x * x * x;
}

int main() {
    if (fopen("A.inp", "r"))
    freopen("A.inp", "r", stdin),
    freopen("A.out", "w", stdout);
    cin >> x;
    for (int i = -1000; i <= 1000; i++)
        for (int j = i + 1; j <= 2000; j++)
            if (p5(j) - p5(i) == x) {
                cout << j << " " << i << endl;
                return 0;
            }
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int a[105];
int n, ll, rr;
long res = 10005 * 10005;

long check(long value)
{
	long ret = 0;

	for (int i = 0; i < n; ++i)
		ret += (a[i] - value) * (a[i] - value);

	return ret;
}

int main()
{
	ll = 105; rr = -105;

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

	for (int i = -10000; i <= 10000; ++i)
	{
		long ret = check(i);
		if (ret < res)
			res = ret;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC147 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [LI() for _ in range(h)]
b = [LI() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
lst = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        lst[i][j] = abs(a[i][j] - b[i][j])

dp[0][0] |= 1 << (6400+lst[0][0])
dp[0][0] |= 1 << (6400-lst[0][0])
for i in range(h):
    for j in range(w):
        t = dp[i][j]
        if i+1 < h:
            dp[i+1][j] |= t << lst[i+1][j]
            dp[i+1][j] |= t >> lst[i+1][j]
        if j+1 < w:
            dp[i][j+1] |= t << lst[i][j+1]
            dp[i][j+1] |= t >> lst[i][j+1]

x = dp[-1][-1]
for i in range(6401)[::-1]:
    if (x >> i) & 1:
        print(6400 - i)
        break



Measured memory_bytes: 53724