akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,p[30];
int ans=0;
signed main(){
    cin>>n;
    rep(i,n)cin>>p[i];
    for(int i=1;i<n-1;i++){
        if(p[i]<p[i-1]&&p[i+1]<p[i])ans++;
        else if(p[i]>p[i-1]&&p[i+1]>p[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
	lli n, k;
	cin>>n>>k;
	vll A(n);
	lli sum = 0;
	loop(i, 0, n)
		cin>>A[i];
	sort(A.begin(), A.end(), greater<int>());
	loop(i, k, n)
		sum += A[i];
	cout<<sum<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10000000)

n,k = map(int,input().split())
v = list(map(int,input().split()))
ans=0
for l in range(k+1):
    for r in range(k-l+1):
        if l+r > n :break

        d=k-l-r
        now=0
        s=[]

        for i in range(l):
            now+=v[i]
            s.append(v[i])

        for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

        s.sort()
        for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

        ans=max(now,ans)
print(ans)

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>
 
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define Sort(x) sort(x.begin(),x.end()); 
#define ll long long
int mod=1e9+7;
const int INF = 1e9;
 
using namespace std;
 
int main(void) {
	int n,m,count=0,ans=0;
	vector<int> v;
	cin>>n>>m;
	rep(i,0,m){
	    int a,b;
	    cin>>a>>b;
	    if(a>=b)count++;
	    else v.push_back((b-a)/2);
	}
	sort(v.begin(),v.end());
	
	if(count>=m-1){
	    cout<<0<<endl;
	    return 0;
	}else {
	    rep(i,0,m-1-count){
	        ans+=v[i];
	    }
	}
	
	cout<<ans<<endl;
	
 
 
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  int n;

  multiset<int> mi;
  vi vals;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    mi.insert(k);
    vals.pb(k);
  }

  for (int i = 0; i < n; ++i) {
    mi.erase(mi.lower_bound(vals.at(i)));

    cout << *(mi.rbegin()) << endl;

    mi.insert(vals.at(i));
  }

  return 0;
}


Measured memory_bytes: 11764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 200100

vector<ll> divide[MAX];
void fill(){
	for(ll i=1;i<MAX;i++){
		for(ll j=1;i*j<MAX;j++){
			divide[i].pb(i*j);
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	fill();
	
	ll n;cin>>n;
	ll a[n];For(i,0,n) cin>>a[i];
	bool b[n+1];
	memset(b,0,sizeof(b));

	vector<ll> ans;

	Fod(i,n+1,1){
		ll count = 0;
		for(ll x:divide[i]){
			if(x<=n){
				count = (count+b[x])%2;
			}
		}
		if(count==a[i-1]) continue;
		else{
			b[i]=1;
		}
	}

	For(i,1,n+1){
		if(b[i]) ans.pb(i);
	}

	bool valid = 1;
 
	for(ll i=1;i<=n;i++){
		ll count = 0;
		for(ll j=1;i*j<=n;j++){
			count+=b[i*j];
		}
		count = count%2;
		if(count!=a[i-1]) valid=0;
	}
 
	if(valid){
		cout<<ans.size()<<endl;
		for(ll x:ans){
			cout<<x<<" ";
		}
		cout<<endl;
	}else{
		cout<<-1<<endl;
	}



























	
}

Measured memory_bytes: 36976
#include <iostream>

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

int main(){
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    REP(i, n){
        if(s.substr(i, n - i) == t.substr(0, n - i)){
            cout << 2 * n - (n - i) << endl;
            return 0;
        }
    }
    cout << 2 * n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1; i < n+1; i++)
    {
        ans += (n-1) / i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;

    int ans = 0;
    rep(i, S.size()) {
        for(int j = 1; i + j <= S.size(); j++) {
            bool flg = true;
            string T = S.substr(i, j);
            dump(T);
            for(char c : T) {
                if(c != 'A' && c != 'T' && c != 'G' && c != 'C') {
                    flg = false;
                    break;
                }
                // dump(c);
            }
            if(flg) {
                int L = T.size();
                ans = max(ans, L);
                dump(ans);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll mainasu(ll a,ll b,ll c){
	if(a>=b)return mainasu(a-b,b+1,c+1);
	else return c;
}
ll gojou(ll n){return pow(n,5);}
int main()
{
	ll n,ans=1,a;
	bool f=true;
	cin>>n;
	rep(i,n){
		ll tmp=ans;
		cin>>a;
		ans*=a;
		if(ans>1000000000000000000)f=false;
		if(a!=0&&tmp>ans){f=false;}
		if(a==0){ans=0;f=true;break;}
	}
	cout<<(f?ans:-1);
}


Measured memory_bytes: 3680
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a //= 2
        
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b //= 2
print(a, b)

Measured memory_bytes: 2940
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        char[] c = Console.ReadLine().ToCharArray();
        c[nk[1] - 1] = (char)(c[nk[1] - 1] + 32);
        Console.WriteLine(string.Join("", c));
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int c=0,i,j;
  string s,s1;
  cin>>s>>s1;
for(i=0;i<s.size();i++)
{
	if(s[i]==s1[i]){
		c++;
	}
}
(c==s.size())?cout<<"Yes":cout<<"No";
 
 return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
using ll = long long;

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans += a*(n/(a+b));
    n = n%(a+b);
    if(n >= a) ans += a;
    else ans += n;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t x, y;
    std::cin >> x >> y;

    std::cout << x + (y>>1) << std::endl;

    return 0;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll a,ll b){ //最大公約数 O(log(min(a,b)))
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){ //最小公倍数
    ll gc=gcd(a,b);
    ll ans=(a*b)/gc;
    return ans;
}

ll count(ll x){
    int cnt=0;
    while(x%2==0){
        cnt++;
        x/=2;
    }
    return cnt;
}

int main(){
    ll N,M; cin >> N >> M;
    ll a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        a[i]/=2;
    }
    ll tmp=count(a[0]);
    for(int i=0;i<N;i++){
        if(count(a[i])!=tmp){
            cout << 0 << endl;
            return 0;
        }
    }
    ll res=a[0];
    for(int i=1;i<N;i++){
        res=lcm(res,a[i]);
    }
    ll ans=M/res;
    ans=(ans+1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 1024
s= int(input())
num_list = []

def function_tmp(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3*n +1
tmp = s
cnt = 1
while not(tmp in num_list):
    num_list.append(tmp)
    tmp = function_tmp(tmp)
    #print(num_list)
    cnt += 1
print(cnt)


Measured memory_bytes: 2940
n = int(input())
li = list(map(int,input().split()))
m = 0
for i in range(n):
  if li[i] < 0:
    li[i] *= -1
    m += 1
if m%2 ==0:
  print(sum(li))
else:
  print(sum(li)-2*min(li))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> A(MAX), L(MAX, -1), D;
    for (int i = 0; i < N; i++) cin >> A[i];
    L[0] = A[0];
    D.push_back(INF);
    int length = 1;
    for (int i = 1; i < N; i++) {
        if (L[length - 1] < A[i]) L[length++] = A[i];
        else {
            int ind = lower_bound(L.begin(), L.begin() + length, A[i]) - L.begin();
            int d = L[ind];
            L[ind] = A[i];
            if (d == -1) { continue; }
            auto itr = lower_bound(D.begin(), D.end(), d);
            if (itr == D.begin()) {
                D.insert(D.begin(), {d});
            }
            else *(itr - 1) = d;
        }
    }
    int ans = 1;
    if (D[0] != INF) ans += D.size() - 1;
    cout << ans << '\n';
}


Measured memory_bytes: 1660
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll N;
	cin >> N;
	ll A[N];
	ll ans = 0;
	ll mi = 1<<30;
	ll n_mi = 0;
	rep(i, N){
		ll a;
		cin >> a;
		A[i] = a;
		ans += abs(a);
		chmin(mi, abs(a));
		if (a < 0) n_mi++;
	}
	if (n_mi%2==1) ans -= 2 * mi;
	cout << ans << endl;

}








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

int main() {
  int n;
  cin >> n;
  
  if (n / 100 == 1) cout << '9';
  else cout << '1';
  if (n / 10 % 10 == 1) cout << '9';
  else cout << '1';
  if (n % 10 == 1) cout << '9';
  else cout << '1';
  cout << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split(' '))
names = []
rest_time_table = {}
for _ in range(n):
    name_time = input().split(' ')
    name, time = name_time[0], int(name_time[1])
    names.append(name)
    rest_time_table[name] = time

total_time = 0
while True:
    if len(names) == 0:
        break
    name = names.pop(0)
    time = rest_time_table[name]
    rest_time = time - q
    if rest_time <= 0:
        total_time += time
        print(name, total_time)
        continue
    rest_time_table[name] = rest_time
    total_time += q
    names.append(name)


Measured memory_bytes: 11964
#include<stdio.h>
int main()
{
  int a,b,kari;
  
   scanf("%d %d",&a,&b);
      if(a==b)
        kari=a+b;
       if(a>b)
         kari=a+(a-1); 
       if(a<b)
        kari=b+(b-1);
      
    printf("%d",kari);
      return 0;
}

Measured memory_bytes: 128
open Base
open Stdio

let read_line () =
    In_channel.(input_line_exn stdin)

let mapt2 ~f (a, b) = (f a, f b)

let array_replace arr i ~f = arr.(i) <- f (arr.(i))

let n = Int.of_string @@ read_line ()

let sums = Array.create ~len:(n+1) 0
let neg_res = Array.create ~len:(n+1) 0L
let g_hd = Array.create ~len:(n+1) 0
let g_nx = Array.create ~len:(2*n) 0
let g_to = Array.create ~len:(2*n) 0
let g_len = ref 0
let g_add u v =
    g_len := !g_len + 1;
    g_nx.(!g_len) <- g_hd.(u);
    g_to.(!g_len) <- v;
    g_hd.(u) <- !g_len
let [@inline] g_adj_iter cur x0 f =
    let rec loop e acc = if e = 0 then acc else
        let ch = g_to.(e) in
        loop g_nx.(e) (f ch acc)
    in
    loop g_hd.(cur) x0

let colors = read_line () |> String.split ~on:' ' |> List.map ~f:Int.of_string
    |> List.cons 0 |> Array.of_list

let rec dfs ?(cur=1) ?(par=0) () =
    let memo = sums.(colors.(par)) in
    let tree_size = g_adj_iter cur 1 (fun ch acc ->
        acc + if ch = par then 0 else dfs ~cur:ch ~par:cur ())
    in

    array_replace sums colors.(cur) ((+) 1);
    let component_size = Int64.of_int @@ tree_size - (sums.(colors.(par)) - memo) in
    array_replace neg_res colors.(par) (fun x -> Int64.(x + component_size * (component_size + 1L) / 2L));
    sums.(colors.(par)) <- tree_size + memo;
    tree_size

let () =
    for i = 0 to n - 2 do
        let a, b = read_line () |> String.lsplit2_exn ~on:' ' |> mapt2 ~f:Int.of_string in
        g_add a b;
        g_add b a
    done

let () =
    ignore (dfs ());
    for i = 1 to n do
        let component_size = Int64.of_int @@ n - sums.(i) in
        let n64 = Int64.of_int n in
        let res = Int64.(n64 * (n64 + 1L) / 2L - component_size * (component_size + 1L) / 2L - neg_res.(i)) in
        printf "%Ld\n" res
    done


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

int main()
{
    int x,y,z,k,s;

    while(scanf("%d %d", &k, &s)!=EOF)
    {
        int cnt = 0;

        for(x=0; x<=k; x++)
        {
            for(y=0; y<=k; y++)
            {
                z = s-(x+y);

                if(z>=0 && z<=k)
                {
                    cnt++;
                }
            }
        }
        printf("%d\n", cnt);
    }

    return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  set<int> S;
  vector<int> data(K);
  for(int i=0;i<K;i++){
    cin >> data.at(i);
    for(int j=0;j<data.at(i);j++){
      vector<int> A(data.at(i));
      cin>>A.at(j);
      S.insert(A.at(j));
    }
  }
  cout << N - S.size() << endl;
    
  
}
    
    


Measured memory_bytes: 3636
import math

__DEUBG__ = 0

a, b, c, x, y = map(int, input().split())

minimum = a * x + b * y

if x > y:
    for i in range(x+1):
        N_a = i
        N_c = 2 * (x - i)
        if (y-N_c/2) < 0:
            N_b = 0
        else:
            N_b = y - int(N_c/2)
        tmp = a * N_a + b * N_b + c * N_c
        if tmp < minimum:
            minimum = tmp
            if __DEUBG__:
                print(tmp, N_a, N_b, N_c)
else:
    for i in range(y+1):
        N_b = i
        N_c = 2 * (y - i)
        if (x-N_c/2) < 0:
            N_a = 0
        else:
            N_a = x - int(N_c/2)
        tmp = a * N_a + b * N_b + c * N_c
        if tmp < minimum:
            minimum = tmp
            if __DEUBG__:
                print(tmp, N_a, N_b, N_c)

print(minimum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++) 
#define inf 10000000000000;
typedef long long ll;



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


    ll W;
    cin >> W;

    ll w[n+5];
    ll v[n+5];



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


    ll dp[n+5][W+5];

    for(int i=0;i<=W;i++){
        dp[0][i]=0;
    }


    rep(i,n){
        rep(j,W+1){

            if(j >= w[i]){
                dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][W] << endl;

return 0;
}

Measured memory_bytes: 80512
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x, 0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
int n, k;
int a[100005];
int dp[100005];

int minCost (int i)
{
    if (i == n - 1) return 0;
    if (i >= n) return mod;

    int &ret = dp[i];

    if (ret != -1) return ret;

    ret = LLONG_MAX;
    fp (j, 1, k)
    {
        ret = min (ret, minCost(i + j) + abs(a[i] - a[i + j]));
    }

    return ret;
}

void solve()
{
    cin >> n;
    cin >> k;
    f (i, n) cin >> a[i];
    f (i, n) dp[i] = -1;
    cout << minCost(0);
}  
 
signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--) solve();
  return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);
	int N, L;
	cin >> N >> L;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	deque<int> dq;
	vector<int> res(N - L + 1);
	for (int i = 0; i < N; i++) {
		while (!dq.empty() && a[dq.back()] > a[i]) {
			dq.pop_back();
		}
		dq.push_back(i);
		if (i >= L - 1) {
			res[i - L + 1] = a[dq.front()];
			if (dq.front() == i - L + 1) {
				dq.pop_front();
			}
		}
	}
	for (int i = 0; i <= N - L; i++) {
		cout << res[i] << " \n"[i == N - L];
	}
	return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int LCS(string s, string t) {
    int n = s.size();
    int m = t.size();
    s = "#" + s;
    t = "#" + t;

    vvi dp(n + 1, vi(m + 1));
    dp[0][0] = 0;

    rep2(i, 1, n + 1) {
        rep2(j, 1, m + 1) {
            if (s[i] == t[j]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
            dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }

    return dp[n][m];
}

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

    int q;
    cin >> q;
    rep(i, q) {
        string s, t;
        cin >> s >> t;
        cout << LCS(s, t) << endl;
    }

}

Measured memory_bytes: 10808
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
  ll a,b,c; cin>>a>>b>>c;
  bool can = false;
  for(int i=1; i<=b; i++) {
    ll n = a*i;
    if(n%b==c) can = true;
  }
  if(can) cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
n=input()
k=int(input())
m=len(n)

dp=[[[0]*2 for _ in range(4)] for _ in range(m+1)]

dp[0][0][0]=1
keta=int(n[0])
dp[1]=[[0,1],[1,keta-1],[0,0],[0,0]]
  
for i in range(1,m):
  keta=int(n[i])
  dp[i+1][0][0]+=dp[i][0][0]*(keta==0)
  dp[i+1][0][1]+=(dp[i][0][0]*(keta>0)+dp[i][0][1])
  for j in range(3):
    dp[i+1][j+1][0]+=dp[i][j][0]*(keta!=0)+dp[i][j+1][0]*(keta==0)
    dp[i+1][j+1][1]+=(dp[i][j][0]*max(keta-1,0)+dp[i][j][1]*9
                      +dp[i][j+1][0]*(keta>0)+dp[i][j+1][1])
    
                    
print(dp[m][k][0]+dp[m][k][1])
      

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

int n, maxv, minv;

int main() {
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	while (scanf("%d", &n) == 1) {
		maxv = -2000000000;
		scanf("%d", &minv);
		int t;
		for (int i = 1; i < n; i++) {
			scanf("%d", &t);
			maxv = max(maxv, t - minv);
			minv = min(minv, t);
		}
		printf("%d\n", maxv);
	}
	return 0;
}



Measured memory_bytes: 2744
#include<iostream>
using namespace std;
int main(){
	int N,M;
	int k1,k2;
	int K[31][31];
	int count=0;
	cin>>N>>M;
	for(int i=1;i<=N;i++){
		cin>>k1;
		for(int j=1;j<=M;j++){
			K[i][j]=0;
		}
		for(int j=0;j<k1;j++){
			cin>>k2;
			K[i][k2]=1;
		}
	}
	for(int j=1;j<=M;j++){
		for(int i=1;i<=N;i++){
			if(K[i][j]==0)break;
			if(i==N)count++;
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]

def ldec(A, d=1): return map(lambda x: x - d, A)

def solve(N, A, S):
    dp = [0]

    for i in range(N-1, -1, -1):
        #print(i, dp)
        ai = A[i]

        if S[i] == "0":
            # Pattern 1 -> TLE
            #dp += [x^A[i] for x in dp if x^A[i] not in dp]
            
            # Pattern 2 -> TLE
            #for x in dp:
            #    a = x ^ A[i]
            #    if bisect_left(dp, a) == bisect_right(dp, a):
            #        insort(dp, a)

            for d in dp:
                if ai > ai^d: ai ^= d
            if ai: dp.append(ai)

        if S[i] == "1":
            # Pattern 2 -> TLE
            #if A[i] not in dp:
            #    print("1")
            #    return

            for b in dp:
                if ai > ai^b: ai ^= b
            if ai:
                print("1")
                return

    print("0")

T = n1()
for _ in range(T):
    N = n1()
    A = nn()
    S = s1()
    solve(N, A, S)

Measured memory_bytes: 78964
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

i64 up_div(i64 numer, i64 denom) { return (numer + denom - 1) / denom; }

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

  VAR(int, N);

  vector<i64> c(N + 5), s(N + 5), f(N + 5);
  rep(i, N - 1) {
    IN(c[i], s[i], f[i]);
  }

  rep(i, N) {
    i64 t = 0;
    for (int j = i; j < N - 1; ++j) {
      i64 leave = max(s[j], f[j] * up_div(t, f[j]));
      t = leave + c[j];
    }
    OUTL(t);
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

int dp[2][2000];
int a[2000];
signed main() {
	int n, z, w; cin >> n >> z >> w;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = n - 2; i >= 0; i--) {
		//自分がとった場合の最大(小)値
		int MIN = abs(a[i] - a[n - 1]);
		for (int j = n - 2; j > i&&j >= 0; j--)MIN = min(MIN, dp[1][j]);
		dp[0][i] = MIN;
		int MAX = abs(a[i] - a[n - 1]);
		for (int j = n - 2; j > i&&j >= 0; j--)MAX = max(MAX, dp[0][j]);
		dp[1][i] = MAX;
	}
	int ans = abs(w - a[n - 1]);
	for (int i = 0; i < n - 1; i++) {
		ans = max(ans, dp[0][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
int main()
{
    int k,j,count=0;
    scanf("%d",&k);
    char a[51];
    getchar();
    gets(a);
    
    for(j=0;j<k;j++)
    {
            if(a[j]=='A'&&a[j+1]=='B'&&a[j+2]=='C')
           {
               count=count+1;
           }
    }
     printf("%d",count);

    return 0;
}

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

int main(){
string S;
cin >> S;

int zero = 0, one = 0;
for(int i = 0; i < S.size(); i++){ 
     if(S.at(i) == '0') zero++;
     if(S.at(i) == '1') one++;
}

int ans = min(zero, one) * 2;
cout << ans << endl; 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < C; i++) for (int j = 0; j < C; j++) cin >> D[i][j];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> A[i][j];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) A[i][j]--;

    vector<map<int, int>> mp(3);
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) mp[(i+j)%3][A[i][j]]++;
    int minD = INF;
    for (int c1 = 0; c1 < C - 2; c1++) {
        for (int c2 = c1+1; c2 < C - 1; c2++) {
            for (int c3 = c2+1; c3 < C; c3++) {
                vector<int> p{c1, c2, c3};
                do {
                    int cur = 0;
                    for (int i = 0; i < 3; i++)
                        for (auto m : mp[i])
                            cur += D[m.first][p[i]] * m.second;
                    minD = min(minD, cur);
                } while(next_permutation(p.begin(), p.end()));
            }
        }
    }

    cout << minD << '\n';
}


Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i;i<j;i++)
#define print(t) cout<<t<<endl
typedef long long ll;
typedef string str;

int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<w*h/2<<" ";
	if(w/2==x&&h/2==y){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc059/tasks/arc072_a
# C - Sequence
import copy
N = int(input().split()[0])
a_list = list(map(int, input().split()))

w_list_1 = copy.copy(a_list)
w_list_2 = copy.copy(a_list)
c_1, c_2 = 0, 0
s_1, s_2 = 0, 0
c_list = []

for i in range(N):  # 10 ** 5
    # 偶数項を正にする場合
    before = w_list_1[i]
    s_1 += before

    if i % 2 == 0 and s_1 < 0:
        w_list_1[i] += abs(s_1)
        c_1 += abs(s_1)
    elif i % 2 != 0 and s_1 >= 0:
        w_list_1[i] -= abs(s_1+1)
        c_1 += abs(s_1+1)

    s_1 = s_1 - before + w_list_1[i]

    if s_1 == 0:
        a = w_list_1[i]
        w_list_1[i] = a + 1 if a >= 0 else a - 1
        s_1 = 1 if a >= 0 else -1
        c_1 += 1

    # 偶数項を負にする場合
    before = w_list_2[i]
    s_2 += before

    if i % 2 == 1 and s_2 < 0:
        w_list_2[i] += abs(s_2)
        c_2 += abs(s_2)
    elif i % 2 != 1 and s_2 >= 0:
        w_list_2[i] -= abs(s_2+1)
        c_2 += abs(s_2+1)

    s_2 = s_2 - before + w_list_2[i]

    if s_2 == 0:
        a = w_list_2[i]
        w_list_2[i] = a + 1 if a >= 0 else a - 1
        s_2 = 1 if a >= 0 else -1
        c_2 += 1

ans = min([c_1, c_2])
print(ans)


Measured memory_bytes: 14844
n = int(input())
h = list(map(int,input().split()))

dp = [0]*(n+1)
dp[1] = abs(h[1] - h[0])

for i in range(2,n):
    dp[i] = min(dp[i-2] +abs(h[i] - h[i-2]),dp[i-1]+abs(h[i] - h[i-1]))
print(dp[n-1])

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

int main(){
	int m, n;
	cin >> m >> n;
	int arr[m][n] = {};
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			cin >> arr[i][j];
		}
	}
	int arr2[n];
	for(int i = 0; i < n; i++){
		cin >> arr2[i];
	}
	for(int i = 0; i < m; i++){
		int sum = 0;
		for(int j = 0; j < n; j++){
			sum += arr[i][j] * arr2[j];
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3088
#include <iostream>
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)>(y))?(y):(x))
using namespace std;
int main(void){
    int x,y;
    while(1){
        cin >> x >> y;
        if(!(x+y)) break; //because x,y>=0
        cout << MIN(x,y);
        cout << " ";
        cout << MAX(x,y);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3004
#include<iostream>
#include<ctype.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
string s;
int er,ans;
int main(){
	cin>>s;
	int l=s.length();
	for(int i=0;i<l;++i){
		if(s[i]=='S')++er;
		if(s[i]=='T' && er>0)--er,ans++;
	}
	cout<<l-ans-ans<<"\n";
	return 0;
}

Measured memory_bytes: 640
x =  [int(s) for s in input().split()]
min = x[0] + x[1]
for s in range(len(x)):
    if(s != len(x)-1):
        if(x[s] + x[s+1] < min):
            min = x[s] + x[s+1]
    elif(s == len(x)-1):
        if(x[s] + x[0] < min):
            min = x[s] + x[0]
    
print(min)
        

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){cin >> a[i];}
  int ans = 0;
  for(;;){
    int oddFlag = false;
    rep(i,n) if(a[i]%2!=0) oddFlag = true;
    if(oddFlag) break;
    rep(i,n) a[i] /= 2;
    ans++;
  }
  cout << ans << endl;
}

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

static const double pi = 3.141592653589793;
typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-6;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)


namespace std {
  bool operator<(const P a, const P b) {
  	return abs(a.X - b.X) > EPS ? a.X < b.X : a.Y < b.Y;
  }
}

D dot(P a, P b) {
  return (conj(a)*b).X;
}

D cross(P a, P b) {
  return (conj(a)*b).Y;
}
int ccw(P a, P b, P 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
}


bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  if (EQ(d2, 0)) throw "kouten ga nai";   // 交点がない
  return a1 + d1/d2 * (a2-a1);
}

int main() {
	
	/*ifstream in("Ain.txt");
	cin.rdbuf(in.rdbuf());
	ofstream ofs("Aout.txt");
	cout.rdbuf(ofs.rdbuf());
	*/
	int N;
	while(cin >> N, N) {
		vector<L> lines;
		int ans = 1 + N;
		rep(n, N) {
			double x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;
			P p1 = P(x1, y1), p2 = P(x2, y2);
			vector<P> cp;
			for (auto l : lines) {
				if(isecSS(p1, p2, l.first, l.second)) {
					cp.push_back(crosspointLL(p1, p2, l.first, l.second));
				}
			}
			sort(cp.begin(), cp.end());
			for(int i = 0; i < cp.size(); i++) {
				if (EQ(cp[i], p1) or EQ(cp[i], p2)) continue;
				if (i > 0 and EQ(cp[i], cp[i - 1])) continue;
				ans ++;
			}
			lines.push_back(make_pair(p1, p2));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3204
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5;
typedef long long ll; 
using namespace std;

int n, A, B, x[N];
ll ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (), A = read <int> (), B = read <int> ();
	for(int i = 1; i <= n; i++) x[i] = read <int> ();
	for(int i = 1; i < n; i++) ans += min(1ll * B, 1ll * A * (x[i + 1] - x[i]));
	printf("%lld\n", ans); 
	return 0; 
}


Measured memory_bytes: 3612
#include <string>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
string a, b, c;
int main() {
	cin >> a >> b >> c;
	cout << (a.back() == b[0] && b.back() == c[0] ? "YES" : "NO") << endl;
	return 0;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::string S) {
  int c = 0;

  rep(i, 3) {
    if (S.at(i) == 'R') c++;
  }

  if (S.at(1) != 'R' && c == 2) c = 1;

  cout << c << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '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() {
  int N; cin >> N;
  vector<string> s(N); REP(i, N) cin >> s[i];
  int M; cin >> M;
  vector<string> t(M); REP(i, M) cin >> t[i];
  map<string, int> m1, m2;
  REP(i, N) {
    m1[s[i]]++;
  }
  REP(i, M) {
    m2[t[i]]++;
  }
  int ans = 0;
  int res = 0;
  for(auto x: m1) {
    int a = x.second;
    int b = m2[x.first];
    ans = max(0, a - b);
    if(res < ans) res = ans;
  }
  cout << res << endl;
}

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

using namespace std;

int main() {

	int data[10];
	int kari;

	for (int i = 0; i < 10; i++) {
		cin >> data[i];
	}

	for (int j = 9; j > 0; j--) {
		for (int k = 0; k < j; k++) {
			if(data[k] > data[k+1]) {
				kari = data[k];
				data[k] = data[k+1];
				data[k+1] = kari;
			}
		}
	}

	cout << data[9] << endl << data[8] << endl << data[7] << endl;

	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    set<int>s;
    cin>>a>>b>>c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size()==2)
        cout<<"Yes\n";
    else
        cout<<"No\n";

}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] p = in.nextIntArray(N);

            Map<Integer, Double> map = new HashMap<>();
            int sum = 0;
            for (int i = 1; i <= 1000; i++) {
                sum += i;
                map.put(i, sum / (double) i);
            }

            double[] tmp = new double[N + 1];
            for (int i = 1; i <= N; i++) {
                tmp[i] = tmp[i - 1] + map.get(p[i - 1]);
            }
            double ans = 0;
            for (int i = 0; i <= N - K; i++) {
                ans = Math.max(ans, tmp[i + K] - tmp[i]);
            }
            out.printf("%.12f\n", ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 44240
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	int l1 = s1.size();
	int l2 = s2.size();
	vector<char> a(l1, 0);
	vector<char> b(l2, 0);
	for (int i = 0; i < l1;i++) {
		a[i] = s1[i];
	}
	for (int i = 0; i < l2; i++) {
		b[i] = s2[i];
	}
	for (int i = 0; i < l1; i++) {
		a.push_back(a[i]);
	}
	for (int i =0 ; i < l1 ; i++) {
		for (int j = 0; j < l2; j++) {
			if (a[i + j] != b[j])break;
			if (j == l2-1 ) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}




Measured memory_bytes: 3200