akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int A, B;
  cin >> A >> B;

  int r = B * 10 + 9;

  bool found = false;
  while (r >= 0) {
    int a = r * 8 / 100, b = r * 10 / 100;
    if (a == A && b == B) {
      // 満たす
      if (!found) found = true;
    }
    else {
      // 満たさない
      if (found) {
        r++;
        break;
      }
    }
    r--;
  }

  cout << (found ? r : -1);
}
#endif


Measured memory_bytes: 256
def calcdiff(H, W, i):
    a = i * W
    b1 = (H - i) * (W//2)
    c1 = (H - i) * (W - W//2)
    ret = max(a, b1, c1) - min(a, b1, c1)
    b2 = (H - i)//2 * W
    c2 = (H - i - (H - i)//2) * W
    ret = min(ret, max(a, b2, c2) - min(a, b2, c2))
    return ret


def main():
    H, W = map(int, input().split())
    ans = float("inf")
    for i in range(1, H):
        ans = min(ans, calcdiff(H, W, i))
    for i in range(1, W):
        ans = min(ans, calcdiff(W, H, i))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 43760
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n;
  cin >> n;
  long long a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  unsigned long long ans=1;
  
  for(int j=0; j<n; j++){
    if(a[j]<=1000000000000000000/ans){
    ans*=a[j];
  } else {
    cout << -1 << endl;
    return 0;
  }
  }
cout << ans << endl;  
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  double ans = (n+1)/2;
  ans /= n;
  cout << ans << endl;
}


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

using namespace std;

int main(){
	int N, S, W, Q;
	static int a[100000];
	while(cin >> N >> S >> W >> Q, N){
		map<int, int> mp;
		for(int i=0;i<N;i++){
			a[i] = (S/7)%10;
			if(S%2 == 0) S /= 2;
			else         S = (S/2)^W;
		}
		int res = 0, cur = 0, mul = 1, cnt = 0;
		for(int i=N-1;i>=0;i--){
			if(Q == 2 || Q == 5){
				if(a[i]%Q == 0) cnt++;
				if(a[i] != 0) res += cnt;
			} else {
				cur = (a[i]*mul+cur)%Q;
				if(!mp.count(cur)) mp[cur] = 1;
				else               mp[cur]++;
				mul = (10*mul)%Q;
				if(a[i] != 0) res += mp[cur]-(cur!=0);
			}
		}
		cout << res << endl;
	}
}

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

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

  int n, k; cin >> n >> k;
  string s; cin >> s;

  int cnt = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) ++cnt;
  }
  cout << min(n - 1, cnt + 2 * k) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      100000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, k;
ll a[100000];
ll sum[100001];
ll pra[100001];

int main(){
    cin >> n >> k;
    rep(i,n) cin >> a[i];
    rep(i,n){
        pra[i+1] = pra[i];
        sum[i+1] = sum[i]+a[i];
        if(a[i] > 0) pra[i+1] += a[i];
    }
    ll ans = 0;
    ll all = pra[n];
    for(int i = k-1; i < n; i++){
        if(i == k-1){
            ans = max(ans,all-pra[i+1]+sum[i+1]);
            ans = max(ans,all-pra[i+1]);
            continue;
        }
        ans = max(ans,all-(pra[i+1]-pra[i-k+1])+(sum[i+1]-sum[i-k+1]));
        ans = max(ans,all-(pra[i+1]-pra[i-k+1]));
    }
    cout << ans << endl;
}


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

void dfs(int v, int c, int p, int n, std::vector<int>& color, std::vector<std::vector<std::pair<int, int> > >& G) 
{
	color.at(v) = c;
	
		for (int j = 0; j < G.at(v).size(); j++)
		{
			
			if (G.at(v).at(j).first == p)
				continue;
			if (G.at(v).at(j).second == 1)
			{
				dfs(G.at(v).at(j).first, 1 - c, v, n, color, G);
			}
			else
			{
				dfs(G.at(v).at(j).first, c, v, n, color, G);
			}
		}
}


int main()
{
	int n;
	std::cin >> n;
	std::vector<std::vector<std::pair<int, int> > > G(n, std::vector<std::pair<int, int> > ());
	
	std::vector<int> color(n, -1);
	for (int i = 0; i < n - 1; i++)
	{
		int uv, vv, wv;
		std::pair<int, int> p;
		std::cin >> uv >> vv >> wv;
		uv--;
		vv--;
		wv %= 2;
	
		p.first = vv;
		p.second = wv;
		G.at(uv).push_back(p);
		p.first = uv;
		G.at(vv).push_back(p);
	}
	dfs(0, 0, -1, n, color, G);
	
	for (int i = 0; i < n; i++)
	{
		std::cout << color.at(i) << '\n';
	}

}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int N;
    cin >> N;
    int ans = N%10;
    if(ans == 0) cout << "pon" << endl;
    else if(ans == 1) cout << "pon" << endl;
    else if(ans == 2) cout << "hon" << endl;
    else if(ans == 3) cout << "bon" << endl;
    else if(ans == 4) cout << "hon" << endl;
    else if(ans == 5) cout << "hon" << endl;
    else if(ans == 6) cout << "pon" << endl;
    else if(ans == 7) cout << "hon" << endl;
    else if(ans == 8) cout << "pon" << endl;
    else if(ans == 9) cout << "hon" << endl;
    return 0;
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	long long d[200005];
	for(int i=1;i<=n;i++)
		cin >> d[i-1];
	sort(d,d+n);

	int m;
	cin >> m;
	long long t[200005];
	for(int i=1;i<=m;i++)
		cin >> t[i-1];
	sort(t,t+m);

	int count=0;

	for(int i=1;i<=n;i++)
	{
		if(t[count]==d[i-1])
			count++;
	}

	cout << (count==m ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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()
{
  ll N,M; cin>>N>>M;
  vector<vector<int>> graph(N,vector<int>(N,0));
  rep(i,M){
    ll a,b; cin>>a>>b; a--,b--;
    graph[a][b]=1;
    graph[b][a]=1;
  }
  
  ll ans=0;
  vector<ll> vec(N);
  rep(i,N) vec.at(i)=i;
  do{
    if(vec[0]!=0) break;
    ll judge=1;
    rep(i,N-1){
      ll s=vec[i],g=vec[i+1];
      if(!graph[s][g]) judge=0;
    }
    if(judge) ans++;
  }while(next_permutation(vec.begin(),vec.end()));
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define li long long int
#define FOR(i, a, b) for (li (i) = (a) ; (i) < (b) ; ++(i))
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    char X, Y;
    cin >> X >> Y;

    if (X < Y) {
        cout << "<";
    } else if (X > Y) {
        cout << ">";
    } else {
        cout << "=";
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
using namespace std;
const int MAXN=205;

int N;
vector<int> adj[MAXN];
bool vis[MAXN];
int match[MAXN];

bool aug(int u)
{
	for(int i=0;i<(int)adj[u].size();i++)
		if(!vis[adj[u][i]])
		{
			int v=adj[u][i];
			vis[v]=true;
			if(match[v]==0||aug(match[v]))
			{
				match[u]=v;
				match[v]=u;
				return true;
			}
		}
	return false;
}

int Match()
{
	int ans=0;
	for(int i=1;i<=2*N;i++)
		if(match[i]==0)
		{
			memset(vis,0,sizeof vis);
			ans+=aug(i);
		}
	return ans;
}

pair<int,int> A[MAXN],B[MAXN];

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&A[i].first,&A[i].second);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&B[i].first,&B[i].second);
		
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			if(A[i].first<B[j].first&&A[i].second<B[j].second)
			{
				adj[i].push_back(j+N);
				adj[j+N].push_back(i);
			}
	
	printf("%d\n",Match());
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n - 1) cin >> c[i];

  int rsl = b[a[0] - 1];
  rep(i, 1, n) {
      rsl += b[a[i] - 1];
      if(a[i] - a[i - 1] == 1) rsl += c[a[i - 1] - 1];
  }
  cout << rsl << endl;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define read(x) int x; cin>>x;
#define print(x) for(int i=0; i<(int) x.size(); i++) cout<<x[i]<<" "; cout<<endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;

const ll INFLL = (ll) 1e16;
const int INF = (int) 1e8;
const int nmax = 1e5+5;

vector<vector<pi> >adj(nmax);
vll dist(nmax, INFLL);
vi visited(nmax, 0);

void paint(int source) {
	priority_queue<pair<ll, int> > q;
	q.emplace(0, source);
	dist[source] = 0;
	
	while(!q.empty()) {
		auto nex = q.top(); q.pop();
		//cout<<"Vertex: "<<nex.S<<endl;
		if(visited[nex.S]) continue;
		visited[nex.S] = 1;
		
		for(auto nei: adj[nex.S]) {
			//cout<<"Distance: "<<nei.F<<" "<<dist[nex.F] + nei.S<<endl;
			if(dist[nei.F] > dist[nex.S] + nei.S) {
				dist[nei.F] = dist[nex.S] + nei.S;
				q.emplace(-(dist[nex.S]+nei.S), nei.F);
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	read(n)
	for(int i=0; i<n-1; i++) {
		int u, v, w;
		cin>>u>>v>>w;
		
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}
	
	paint(1);
	//for(int i=1; i<=n; i++) cout<<dist[i]<<endl;
	for(int i=1; i<=n; i++) cout<<((dist[i]%2==0) ? 1 : 0)<<endl;
	return 0;
}


Measured memory_bytes: 7680
import java.util.*;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int A = sc.nextInt();
		
		
		System.out.println(
			 (N % 500) <= A ? "Yes": "No");
	}
}


Measured memory_bytes: 23764
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

void warshall_floyd(vector<vll> &g, ll INF) {
  for (size_t k = 0; k < g.size(); k++) {
    for (size_t i = 0; i < g.size(); i++) {
      for (size_t j = 0; j < g.size(); j++) {
        if (g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
  ll H, W;
  cin >> H >> W;

  vector<vll> g(10, vll(10));

  for (int i = 0; i <= 9 ; i++) {
    for (int j = 0; j <= 9; j++) {
      cin >> g[i][j];
    }
  }

  warshall_floyd(g, -1);

  ll ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ll tmp;
      cin >> tmp;
      if (tmp == -1) continue;
      ans += g[tmp][1];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    string s;
    cin >> s;
    
    int ans = 0;
    for (int i = 1;i<s.size()/2;i++) {
        if (s.substr(0, i) == s.substr(i , i))ans = i;
    }

    cout << ans*2;
    
    return 0;

}

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

int main()
{
  int h, w, lmax = 0;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s.at(i);
  vector<vector<int>> lsum(h, vector<int>(w));
  for (int y = 0; y < h; y++) {
    int lasthash = -1;
    for (int x = 0; x < w; x++) {
      if (s.at(y).at(x) == '#') {
        lsum.at(y).at(lasthash + 1) = x - lasthash - 1;
        lsum.at(y).at(x) = lasthash + 1 - x;
        lasthash = x;
      }
    }
    if (lasthash + 1 < w) lsum.at(y).at(lasthash + 1) = w - lasthash - 1;
    int total = 0;
    for (int x = 0; x < w; x++) {
      total += lsum.at(y).at(x);
      lsum.at(y).at(x) = total;
    }
  }
  vector<vector<int>> lvsum(h, vector<int>(w));
  for (int x = 0; x < w; x++) {
    int lasthash = -1;
    for (int y = 0; y < h; y++) {
      if (s.at(y).at(x) == '#') {
        lvsum.at(lasthash + 1).at(x) = y - lasthash - 1;
        lvsum.at(y).at(x) = lasthash + 1 - y;
        lasthash = y;
      }
    }
    if (lasthash + 1 < h) lvsum.at(lasthash + 1).at(x) = h - lasthash - 1;
    int total = 0;
    for (int y = 0; y < h; y++) {
      total += lvsum.at(y).at(x);
      lsum.at(y).at(x) = total + lsum.at(y).at(x) - 1;
      if (lsum.at(y).at(x) > lmax) lmax = lsum.at(y).at(x);
    }
  }
  cout << lmax << endl;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	int ans=0,k=0;
	rep(i,n){
		if(s.at(i)=='1'){
			k++;
		}
	}
	ans = n - abs(k-(n-k));
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
int x,y;
vector<int> dir_x;
vector<int> dir_y;

bool dpx[40000][3000];
bool dpy[40000][3000];
int main(){
	cin>>s;
	//cout<<s.size()<<endl;
	cin>>x>>y;
	REP(i,40000){
		REP(j,3000){
		dpx[i][j]=false;
		dpy[i][j]=false;
		}
	}
	int count=0;
	int dir=0;
	int flag=1;
	for(int i=0;i<s.size();i++){
		if(s[i]=='F'){
			count++;
		}else{
			if(count!=0){
				if(dir){
					dir_y.push_back(count);
				}else{
					if(flag) x-=count;
					else dir_x.push_back(count);
				}
			}
			dir=~dir;
			count=0;
			flag=0;
		}
	}
	if(count!=0){
		if(dir){
			dir_y.push_back(count);
		}else{
			if(flag)x-=count;
			else dir_x.push_back(count);
		}
	}
	dpx[20000][0]=true;
	for(int i=0;i<dir_x.size();i++){
		for(int j=0;j<40000;j++){
			if(dpx[j][i]){
				dpx[j+dir_x[i]][i+1]=true;
				dpx[j-dir_x[i]][i+1]=true;
			}
		}
	}
	dpy[20000][0]=true;
	for(int i=0;i<dir_y.size();i++){
		for(int j=0;j<40000;j++){
			if(dpy[j][i]){
				dpy[j+dir_y[i]][i+1]=true;
				dpy[j-dir_y[i]][i+1]=true;
			}
		}
	}
	//cout<<x<<" "<<y<<endl;
	if(dpx[20000+x][dir_x.size()]&&dpy[20000+y][dir_y.size()]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 234624
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;
const int maxn=1e5+7;

int a[maxn];

int main()
{
//	freopen("input.txt","r",stdin);
	
	ll n;
	cin>>n;
	int ans=0,res=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]<=a[i-1]) ans++;
		else ans=0;
		res=max(res,ans);
	}
	cout<<res<<endl;

	return 0;
}

//有n个仓库，m个工人，任何 

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 5000 + 7;

int n;
int a[2][3];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, 2) forn(j, 3)
		scanf("%d", &a[i][j]);
	return true;
}

li dp1[N * N], dp2[N * N];

void solve() {
	dp1[0] = dp2[0] = 0;
	fore(k, 1, N * N){
		dp1[k] = dp1[k - 1] + 1;
		dp2[k] = dp2[k - 1] + 1;
		forn(j, 3) if (a[0][j] <= k)
			dp1[k] = max(dp1[k], dp1[k - a[0][j]] + a[1][j]);
		forn(j, 3) if (a[1][j] <= k)
			dp2[k] = max(dp2[k], dp2[k - a[1][j]] + a[0][j]);
	}
	li ans = 0;
	forn(i, n + 1){
		ans = max(ans, dp2[dp1[i] + (n - i)]);
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if (read()){
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 392064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	string S;
	cin>>S;
	string A="KIHBR";
	int j=0;
	if(S.size()>9){
			cout<<"NO"<<endl;
			return 0;
	}
	REP(i,S.size()){
		//cout<<i<<" "<<j<<endl;
		if(S[i]==A[j])j++;
		else if(S[i]=='A' && i==0)continue;
		else if(S[i]=='A' && S[i-1]!='A' && j!=1 && j!=2)continue;
		else{
			cout<<"NO"<<endl;
			return 0;
		}
		
	}
	if(j!=5)
		cout<<"NO"<<endl;
	else 
		cout<<"YES"<<endl;
	
	return 0;
}


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

int main(){
    int t[5],ft[5],p,i,max=0,ans=0;

    for ( i = 0; i < 5; i++){
        cin >> t[i];
        ft[i]=10*((t[i]+(10-1))/10);

        if((ft[i]-t[i])>max){
            max=ft[i]-t[i];
            p=i;
        }
    }
    for ( i = 0; i < 5; i++){
        if(i==p)continue;
        ans += ft[i];
    }
    ans += t[p];

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


Measured memory_bytes: 256
#include <stdio.h>

#define NOT_FOUND -1
#define MAX 100000

int BinarySearch(int [],int,int);

int main(){
  int n,S[MAX],key,q;
  int sum = 0;
  int i;
  
  scanf("%d",&n);
  for (i = 0;i < n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for (i = 0;i < q;i++){
    scanf("%d",&key);

    if (BinarySearch(S,n,key) != -1)
      sum++;
  }

  printf("%d\n",sum);
  
  return 0;
}

int BinarySearch(int A[],int n,int key){
  int left = 0,right = n,mid;

  while (left < right){
    mid = (left + right) / 2;

    if (A[mid] == key)
      return mid;

    else if (A[mid] > key)
      right = mid;

    else
      left = mid + 1;
  }

  return NOT_FOUND;
}



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

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N), sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}
	ll res = sum[N];
	for (int i = 1; i < N; i++) {
		res = min(res, abs(sum[i] * 2 - sum[N]));
	}
	cout << res << endl;
	return 0;
}


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

using namespace std;

int main() {

int N;
	cin >> N;
	vector<int> h(N);
	for(auto &x: h) cin >> x;

	vector<int> a(N - 1);
	a[0] = abs(h[0] - h[1]);
	a[1] = min(abs(h[0] - h[2]), a[0] + abs(h[1] - h[2]));
	for(int i = 2; i < N - 1; i++) {
		a[i] = min(a[i - 1] + abs(h[i] - h[i + 1]), a[i - 2] + abs(h[i - 1] - h[i + 1]));
	}
	cout << a[N-2] << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val seg = mutableListOf<Pair<Int, Int>>()
    for (i in 0 until n) {
        seg.add(sc.nextInt() to sc.nextInt())
    }
    if (n % 2 == 1) {
        seg.sortBy { it.first }
        val left = seg[n / 2].first
        seg.sortBy { it.second }
        val right = seg[n / 2].second
        println(right - left + 1)
    } else {
        seg.sortBy { it.first }
        val left1 = seg[n / 2 - 1].first
        val left2 = seg[n / 2].first
        seg.sortBy { it.second }
        val right1 = seg[n / 2].second
        val right2 = seg[n / 2 - 1].second
        val left = left1 + left2
        val right = right1 + right2
        println(right - left + 1)
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

int m[4][4];

int main(){
	int i,j;
	int n,r,p,c;
	int f[51],buf[51];
	while(cin >> n >> r,(n||r)){
		for(i=1;i<=n;i++){
			f[i]=-i+n+1;
		}
		while(r--){
			cin >> p >> c;
			for(i=1;i<p;i++) buf[i]=f[i];	//buf
			for(i=1;i<=c;i++) f[i]=f[i+p-1];
			for(i=1;i<p;i++) f[i+c]=buf[i];
		}
		cout << f[1] << endl;
	}
	return 0;
}

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

int main(void){
    ll n, m;
    cin >> n >> m;
    ll k[m], s[15][15], p[m];
    for(ll i = 0; i < m; i++){
        cin >> k[i];
        for(ll j = 0; j < k[i]; j++)
            cin >> s[i][j];
    }
    ll ans = 0;
    for(ll i = 0; i < m; i++)
        cin >> p[i];
    for(ll bit = 0; bit < (1<<n); bit++){
        bool ok = true;
        for(ll i = 0; i < m; i++){
            ll count = 0;
            for(ll j = 0; j < k[i]; j++){
                if ((bit & (1 << s[i][j]-1))) count++;
            }
            if(count%2!=p[i]) break;
            if(i==m-1) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;


double dist(double x1,double y1,double x2,double y2){

    return sqrt( (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) );

}

double deg(double a,double b,double c){

    return acos( (a*a + b*b - c*c ) / (2 * a * b ) );

}

double calc_deg(double x1,double y1,double x2,double y2,double x3,double y3){

    double x,y,z;

    x = dist(x1,y1,x2,y2);
    y = dist(x2,y2,x3,y3);
    z = dist(x3,y3,x1,y1); 

    return deg(x,y,z);

}


int main(){

    double x1,y1,x2,y2,x3,y3,x4,y4;
    char c;

    while(cin >> x1 >> c >> y1 >> c >> x2 >> c >> y2 >> c >> x3 >> c >> y3 >> c >> x4 >> c >> y4){

        double deg1,deg2,deg3,deg4;

        deg1 = calc_deg(x1,y1,x2,y2,x3,y3);
        deg2 = calc_deg(x2,y2,x3,y3,x4,y4);
        deg3 = calc_deg(x3,y3,x4,y4,x1,y1);
        deg4 = calc_deg(x4,y4,x1,y1,x2,y2);


        if(abs(deg1 + deg2 + deg3 + deg4 - 2*M_PI) < 0.00001){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }


    }
    return 0;

}


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

int main(){
  
  int N,M;
  cin >>N>>M;
  
  vector<int> K(N);
  
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    for(int j=0;j<x;j++){
      int y;
      cin >> y;
      y--;
      K[i] |= 1<<y;
    }
  }
  
  int ans = K[0];
  
  for(int i=1;i<N;i++){
    ans &= K[i];
  }
  
  int ans2 = 0;
  
  for(int i=0;i<M;i++){
    if((ans>>i)%2 == 1) ans2 ++;
  }
 
  cout << ans2 << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int n, k, cnt = 0;
	cin >> n >> k;
	for (int i = k; i <= n; i++, cnt++);
	cout << cnt;
	return 0;
}
/*
时间限制: 2秒/内存限制: 1024 MB
成绩: 100 分
问题陈述
斯努克有 N 个整数: 1, 2,..., N. 他将选择 K, 并把那些给高桥。
选择 K 连续整数的方法有多少？
约束
输入中的所有值都是整数。
1≤K≤N≤50
输入
输入由标准输入以以下格式提供:
N K
输出
打印答案。
样本输入1
3 2
样本输出1
2
有两种方法可以选择两个连续整数:
(1, 2) 和 (2, 3)。
样本输入2
13 3
样本输出2
11
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <random>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  vector<pint> v[n];
  rep(i,n){
    int x;
    cin >> x;
    rep(j,x){
      int y,z;
      cin >> y >> z;
      y--;
      v[i].push_back({y,z});
    }
  }
  int ans=-1;
  rep(bit,(1<<n)){
    vector<int> x;
    int temp=bit;
    rep(i,n){
      x.push_back(temp%2);
      temp/=2;
    }
    bool ok=true;
    rep(i,n){
      if(x[i]==0)continue;
      rep(j,v[i].size())if(((v[i][j].second)^(x[v[i][j].first])))ok=false;
    }
    if(ok){
      int temp=0;
      rep(i,n)if(x[i])temp++;
      ans=max(ans,temp);
    }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int r, D, x;
    cin >> r >> D >> x;

    int64_t ans = x;
    for(int i = 0; i < 10; i++){
        ans = r * ans - D;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, ans;
int main()
{
    cin >> n;
    for (int i = 1; i <= n / 2; i++)
    {
        ans += 1;
        if (i == n - i)
        {
            ans -= 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int result = 0;
  string temp;
  for (int i = A; i <= B; i++) {
    temp = to_string(i);
    if (temp[0] != temp[4]) {
      continue;
    }
    if (temp[1] != temp[3]) {
      continue;
    }
    result++;
  }
  cout << result << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        
        for(int i=0; i<n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        
        System.out.println(a[n-1] - a[0]);
    }
}

Measured memory_bytes: 22608
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {

	var array [][]int

	for sc.Scan() {
		tmp := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(tmp[0])
		b, _ := strconv.Atoi(tmp[1])
		if a == 0 && b == 0 {
			break
		}
		array = append(array, []int{a, b})
	}

	for _, v := range array {

		sort.Ints(v)

		fmt.Printf("%d %d\n", v[0], v[1])
	}
}



Measured memory_bytes: 1480
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<set>
using namespace std;
const long long mod=1e9+7;
int main()
{
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long ans=0;
    long long least=(0+k-1)*k/2,most=(n-k+1+n)*k/2;
    ans=(most-least+1)%mod;
    for(long long i=1;i+k<=n+1;i++)
    {
        least+=(k-1+i);
        most+=(n-k+1-i);
        ans=(ans+(most-least+1)%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;
		if(s.find(k)!=s.end())
		{
			s.erase(k);
		}
		else
		s.insert(k);
	}
	cout<<s.size()<<endl;
}

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

int main()
{
  int N;
  
  cin >> N;
  
  int n;
  int count_keta=0;
  int count_add=0;
  
  for(int i=1; i<=N; i++){
    if(i/10 == 0) count_add += 1;
    if(i/10 > 0 && i/10 < 10) count_add += 0;
    if(i/10 >= 10 && i/10 < 100) count_add += 1;
    if(i/10 >= 100 && i/10 < 1000) count_add += 0;
    if(i/10 >= 1000 && i/10 < 10000) count_add += 1;
    if(i/10 >= 10000 && i/10 < 100000) count_add += 0;
    if(i/10 >= 100000 && i/10 < 1000000) count_add += 1;
  }
  
  cout << count_add << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    int time=0;
    pair<int,int> loc(0,0);
    for(int i=0; i<n; i++){
        int t, x, y;
        cin >> t >> x >> y;
        //時間内に行けるところより遠くにいる場合
        if(t-time < abs(x-loc.first)+abs(y-loc.second)){
            cout << "No" << endl;
            return 0;
        }
        //偶奇が合わない場所にはいけない
        else if((t-time)%2==0 && (abs(x-loc.first)+abs(y-loc.second))%2 == 1){
            cout << "No" << endl;
            return 0;
        }
        else if((t-time)%2==1 && (abs(x-loc.first)+abs(y-loc.second))%2 == 0){
            cout << "No" << endl;
            return 0;
        }

        loc.first = x;
        loc.second = y;
        time = t;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3636
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  val (l, r) = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foldLeft(0, n) { (acc , e) =>
      (acc._1 max e(0), acc._2 min e(1))
    }

  val ans = (r - l + 1) max 0
  println(ans)
}

Measured memory_bytes: 44944
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
set<lli> pr(lli u){
    set<lli>s;
    s.insert(u);
    for(lli i = 2;i*i<=u;i++){
        if(u%i==0){
            s.insert(i);
            s.insert(u/i);
        }
    }
    return s;
}
int main() {
    lli n;cin >> n;
    lli ans = 0;
    auto p = pr(n);
    for(auto ss:p){
        lli m = ss-1;
        if(m && n/m==n%m)ans += m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
H,W = map(int,input().split())
s = [[c=="." for c in input()] for _ in [0]*H]

def bsf_dist_grid(grid,start):
    H = len(grid)
    W = len(grid[0])
    d = [[-1]*W for _ in [0]*H]
    d[start[0]][start[1]] = 0
    q = [start]
    while q:
        qq = []
        for xy in q:
            x,y = xy
            d0 = d[y][x]
            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                if (not 0<=x+dx<W) or (not 0<=y+dy<H): continue
                if d[y+dy][x+dx] != -1: continue
                if not grid[y+dy][x+dx]: continue
                d[y+dy][x+dx] = d0+1
                qq.append((x+dx,y+dy))
        q = qq
    return d

d = bsf_dist_grid(s,(0,0))[-1][-1]
print((sum(sum(a) for a in s)-d-1) if d>=0 else -1)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-9; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
#define LE(n,m) ((n) - (m) < EPS)
// #define GE(n,m) ((n) + EPS > (m))
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// 外積　cross(a,b) = |a||b|sinθ
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// 点の進行方向
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

// 点pの直線aへの射影点を返す
Point proj(Point a1, Point a2, Point p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

double distLP(Point a1, Point a2, Point p) {
  return abs(proj(a1, a2, p) - p);
}

// 2円の共通接線。返される各直線に含まれる頂点は円との接点となる
vector<Line> tangentLines(Point a, double ar, Point b, double br) {
  vector<Line> ls;
  double d = abs(b-a);
  rep (i,2) {
    double sin = (ar - (1-i*2)*br) / d;
    if (!LE(sin*sin, 1)) break;
    double cos = sqrt(max(1 - sin*sin, 0.0));
    rep (j,2) {
      Point n = (b-a) * Point(sin, (1-j*2)*cos) / d;
      ls.push_back(Line(a + ar*n, b + (1-i*2)*br*n));
      if (cos < EPS) break;  // 重複する接線を無視（重複していいならこの行不要）
    }
  }
  return ls;
}

int main(){
    int n;
    while(cin >>n,n){
        vector<Point> c(n);
        vector<int> r(n),m(n);
        rep(i,n){
            int x,y;
            cin >>x >>y >>r[i] >>m[i];
            c[i] = Point(x,y);
        }

        int ans = 1;
        rep(j,n)rep(i,j){
            rep(ii,2)rep(jj,2){
                vector<Line> ls = tangentLines(c[i],r[i]+ii*m[i],c[j],r[j]+jj*m[j]);
                for(const auto &l:ls){
                    int tt = 0;
                    rep(k,n){
                        double d = distLP(l.fi,l.se,c[k]);
                        if(LE(0,d-r[k]) && LE(d-r[k],m[k])) ++tt;
                    }
                    ans = max(ans,tt);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
ll arr[MAX],n,z,w;
ll ma[2010];
ll mi[2010];
ll qmi(int a);
ll qma(int a){
	if(ma[a]!=-1)	return ma[a];
	ll r=abs(arr[0]-arr[a]);
	for(int i=1;i<a;i++)	r=max(qmi(i),r);
	debug(a,r);
	return ma[a]=r;
}
ll qmi(int a){
	if(mi[a]!=-1)	return mi[a];
	ll r=abs(arr[0]-arr[a]);
	for(int i=1;i<a;i++)	r=min(qma(i),r);
	debug(a,r);
	return mi[a]=r;
}
int main(){
	IOS
	cin>>n>>z>>w;
	memset(ma,-1,sizeof ma);
	memset(mi,-1,sizeof mi);
	for(int i=n-1;i>=0;i--)	cin>>arr[i];
	arr[n]=w;
	arr[n+1]=z;
	cout<<qma(n)<< '\n';
	return 0;
}

Measured memory_bytes: 384
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

const static ul NMAX = 50;
const static ul DiMAX = 100;

static ul N;
static ul Di[NMAX];

void solve(void) {
  ul res = 0;
  FOR0(i, N) {
    FORi(j, i + 1, N) {
      res += Di[i] * Di[j];
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Di[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

// 便利関数
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;}

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

void solve(long long W, long long H, long long N, std::vector<long long> x, std::vector<long long> y, std::vector<long long> a){
    ll minX = 0, maxX = W, minY = 0, maxY = H;
    REP(i, N) {
        if (a[i] == 1) chmax(minX, x[i]);
        if (a[i] == 2) chmin(maxX, x[i]);
        if (a[i] == 3) chmax(minY, y[i]);
        if (a[i] == 4) chmin(maxY, y[i]);
    }
    if (minX >= maxX || minY >= maxY) print(0);
    else {
        ll ans = (maxX - minX) * (maxY - minY);
        print(ans);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long W;
    scanf("%lld",&W);
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&a[i]);
    }
    solve(W, H, N, std::move(x), std::move(y), std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

bool isprime(int x) {
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int main() {
  int n;
  cin >> n;
  vi v;
  for(int i = 2; i<=55555; i++) if(isprime(i) && i%5==1) v.push_back(i);
  rep(i,n) cout << v[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

const double EPS=1e-10;

int main()
{
	for(int m,n;cin>>m,m;){
		vi a(m,360);
		rep(i,m-1){
			cin>>a[i];
			a[m-1]-=a[i];
		}
		cin>>n;
		vi b(n,360);
		rep(i,n-1){
			cin>>b[i];
			b[n-1]-=b[i];
		}
		
		double sa=0,sb=0;
		rep(i,m)
			sa+=sin(a[i]*M_PI/180);
		rep(i,n)
			sb+=sin(b[i]*M_PI/180);
		
		if(abs(sa-sb)<EPS)
			cout<<0<<endl;
		else if(sa>sb)
			cout<<1<<endl;
		else
			cout<<2<<endl;
	}
	
	return 0;
}

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

int getkt(int num, int kt, int rkt){
    

}

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

    int st, en;
    if(n == 1){
        st = 0;
        en = 10;
    }
    else if(n == 2){
        st = 10;
        en = 100;
    }
    else{
        st = 100;
        en = 1000;
    }

    vector<int> s(m);
    vector<int> c(m);
    rep(i, m){
        cin >> s[i] >> c[i];
    }

    for(int i = st; i<en; i++){
        bool t = true;
        string str = to_string(i);
        rep(j, m){
            if(str[s[j]-1]-'0' != c[j]){
                t = false;
            }
        }
        if(t){
            cout << i;
            return 0;
        }
    }
    cout << "-1";

}

Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m,a,b,c;
string s,t;

int main() {
	cin >> n >> m;
	cout << (m + n - 3) / (n - 1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};

const int M = 1000005;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(M);
    for (int x : a) {
        if (cnt[x] != 0) { //すでにxを見てるなら，xの倍数も見ているので2にだけしておいてcontinue
            cnt[x] = 2;
            continue;
        }
        for (int i=x; i<M; i+=x) cnt[i]++;
    }
    int ans = 0;
    for (int x : a) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7992