akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    REP(i, n + 1){
        cin >> a.at(i);
    }

    const ll asum = accumulate(ALL(a), 0LL);

    vector<ll> lb(n + 1, 0), ub(n + 1, (n + 1) * asum);
    REP(i, n + 1){
        if(i == n){
            lb.at(i) = a.at(i);
            ub.at(i) = min(ub.at(i), a.at(i));
        }else{
            lb.at(i) = a.at(i) + 1;
        }
        if(i <= 60){
            ub.at(i) = min(ub.at(i), 1LL << i);
        }
    }

    REP(_, 2){
        for(ll i = n - 1; i >= 0; --i){
            lb.at(i) = max(lb.at(i), a.at(i) + lb.at(i + 1) / 2);
            ub.at(i) = min(ub.at(i), a.at(i) + ub.at(i + 1));
        }
        for(ll i = 1; i <= n; ++i){
            lb.at(i) = max(lb.at(i), lb.at(i - 1) - a.at(i - 1));
            ub.at(i) = min(ub.at(i), 2 * (ub.at(i - 1) - a.at(i - 1)));
        }
    }

    ll ans = 0;
    REP(i, n + 1){
        // cerr << i << " " << lb.at(i) << " " << ub.at(i) << endl;
        if(lb.at(i) > ub.at(i)){
            cout << -1 << endl;
            return 0;
        }
        ans += ub.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N=6e5 +10 ;
const LL MOD = 1e9+7;

int pre[N], cnt[N], a[N], n;
PII ky[N];
void PLUS(LL &a, LL b){a=(a+b)%MOD;}
void Solve0(){
	LL sum0=1, sumx=0;
	for (int i=1; i<=n; ++i)
		if ( pre[i] == pre[n]) PLUS(sumx, sum0);	else
		if ( pre[i]==0) PLUS(sum0, sumx);
	printf("%lld\n", sum0);
}
void Solve1(){
	LL ans=0;
	for (int l=0, r; l<=n; l=r){
		for (r=l; r<=n && ky[r].fi == ky[l].fi; ++r);
		if ( ky[l].fi==0 ){
			LL tmp=1;
			for (int i=1; i+1<r; ++i) tmp=(tmp<<1)%MOD, ++cnt[ky[i].se];
			for (int i=1; i<=n; ++i) cnt[i] += cnt[i-1];
			PLUS(ans, tmp);
		}	else{
			LL sum0=1, sumx=0;
			for (int i=l; i<r; ++i){
				PLUS(sumx, sum0);
				if ( i+1<r ){
					LL cnt0=cnt[ ky[i+1].se]-cnt[ky[i].se];
					PLUS(sum0, cnt0*sumx%MOD);
				}
			}
			PLUS(ans, sumx);
		}
		#ifdef che
		debug("val=%d, ans=%lld l=%d, n=%d\n", ky[l].fi,ans,l,n);
		#endif
	}
	printf("%lld\n", ans);
}

int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	
	scanf("%d", &n);
	for (int i=1; i<=n; ++i) scanf("%d", a+i);
	pre[0] = 0; ky[0] = MK(0, 0);
	for (int i=1; i<=n; ++i){
		pre[i] = pre[i-1] ^a[i];
		ky[i] = MK(pre[i] , i);
	}
	#ifdef che
	for (int i=1; i<=n; ++i) debug("%d ", pre[i]);
	debug("\n");
	#endif
	sort(ky, ky+n+1);
	if ( pre[n])	Solve0();
		else Solve1();
	return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

ll func(string s, char ch){
    ll N = s.size();
    bool f = true;
    rep(i,N){
        if(s[i] != ch)f=false;
    }
    if(f) return 0;
    string t(N-1, ch+1);
    rep(i,N-1){
        if(s[i] == ch || s[i+1] == ch){
            t[i] = ch;
        }else{
            t[i] = ch+1;
        }
    }
    return 1+func(t,ch);
}

int main(){
    string s;
    cin >> s;
    ll m = 1e10;    
    rep(i,26){
        m = min(m, func(s,'a'+i));
    }
    cout << m << endl;
}


Measured memory_bytes: 256
using System;

class Untitled
{
	static void Main(string[] args)
	{
		bool parsed = false;
		int W = 0, H = 0, x = 0, y = 0, r = 0;
		string[] strs = null;
		string s = Console.ReadLine();
		if (!String.IsNullOrEmpty (s)) {
			strs = s.Split (' ');
			if (strs.Length == 5) {
				parsed = Int32.TryParse (strs[0], out W);
				if (!parsed)
				  return;
				parsed = Int32.TryParse (strs[1], out H);
				if (!parsed)
				  return;
				parsed = Int32.TryParse (strs[2], out x);
				if (!parsed)
				  return;
				parsed = Int32.TryParse (strs[3], out y);
				if (!parsed)
				  return;
				parsed = Int32.TryParse (strs[4], out r);
				if (!parsed)
				  return;
			}
		}

		if (((x - r) >= 0 && (x + r) <= W) && 
			((y - r) >= 0 && (y + r) <= H)) {
		  System.Console.WriteLine ("Yes");
		} else {
		  System.Console.WriteLine ("No");
		}
	}
}

Measured memory_bytes: 8780
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
	int X, Y;
	cin >> X >> Y;

	if (X % Y == 0) {
		cout << -1 << endl;
	}
	else {
		cout << X << endl;
	}
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
 
int32_t main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)cout<<1;
  else if(b==0)cout<<2;
    else if(c==0)cout<<3;
  else if(d==0)cout<<4;
  else if(e==0)cout<<5;

}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main()
{
    string x;
    cin>>x;
    if (x=="SUN")
        cout<<"7";
    else if (x=="MON")
  cout<<"6";
      else if (x=="TUE")
  cout<<"5";
    else if (x=="WED")
  cout<<"4";
    else if (x=="THU")
  cout<<"3";
    else if (x=="FRI")
  cout<<"2";
    else if (x=="SAT")
  cout<<"1";





}


Measured memory_bytes: 256
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define PY printf("Yes\n")
#define PN printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;


int main()
{
	int x, n, tmp, chk_minus = 0, chk_plus = 0, c1, c2;
	cin >> x >> n;
	vector<int> p(n);
	bool flag = true;

	rep(i,n)cin >> p[i];


	if (n == 0)
  {
		cout<<x<<endl;
		return 0;
	}

	rep(i,n+1)
  {
		chk_minus = x - i;
		flag = true;
		rep(j,n)if (chk_minus == p[j])flag = false;
		if (flag == true)goto OUT1;
	}
OUT1:

	rep(i,n+1){
		chk_plus = x + i;
		flag = true;
		rep(j,n)if (chk_plus == p[j])flag = false;
		if (flag == true)goto OUT2;
	}
OUT2:

	c1 = abs(x - chk_minus);
	c2 = abs(x - chk_plus);



	if (c1 == c2)
  {
		cout << chk_minus << endl;
		return 0;
	}
	if (c1 > c2)
  {
		cout << chk_plus << endl;
		return 0;
	}
	else
  {
		cout << chk_minus << endl;
		return 0;
	}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
vector<int>a,b,c;
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int x,y,p,q,r,tmp;
	cin>>x>>y>>p>>q>>r;

	for(int i=0;i<p;i++){
		cin>>tmp;
		a.push_back(tmp);
	}
	for(int i=0;i<q;i++){
		cin>>tmp;
		b.push_back(tmp);
	}
	for(int i=0;i<r;i++){
		cin>>tmp;
		
		c.push_back(tmp);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());

	for(int i=a.size()-x;i<a.size();i++){
		c.push_back(a[i]);
	}
	
	for(int i=b.size()-y;i<b.size();i++)
		c.push_back(b[i]);
	
	sort(c.begin(),c.end());
	/*for(int i=0;i<c.size();i++)
		cout<<c[i]<<endl;
	*/long long sum = 0;
	//cout<<x-1+y-1<<' '<<c.size()<<endl;
	for(int i=c.size()-x-y;i<c.size();i++)
		sum += c[i];
		
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;

int main(){
  long long int n,x;
  cin>>n>>x;
  vector<long long int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  long long int tmp=0;

  for(int i=0;i<n;i++){
    tmp+=a[i];
    if(tmp>x){
      cout<<i<<endl;
      return 0;
    }
  }
  if(tmp==x){
    cout<<n<<endl;
    return 0;
  }
  cout<<n-1<<endl;
}


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

int main() {
	int N;
	cin >> N;

	string str;
	str = to_string(N);

	int sum = 0;

	for (int i = 0; i < str.length(); i++) {
		sum += str[i] - '0';
	}

	if (N % sum == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=3e3+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int t,n,a[N];
ll mem[N][N][2];

ll solve(int i,int j,int p){
    if(i>j) return 0;
    ll &ret=mem[i][j][p];
    if(~ret) return ret;
    if(!p){
        ret=max(a[i]+solve(i+1,j,1),a[j]+solve(i,j-1,1));
    }
    else{
        ret=min(-a[i]+solve(i+1,j,0),-a[j]+solve(i,j-1,0));
    }
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d",a+i);
    memset(mem,-1,sizeof mem);
    printf("%lld",solve(0,n-1,0));
    return 0;
}


Measured memory_bytes: 145112
#include <iostream>

using namespace std;

int main() {
  while (true) {
    int map[13][13] = {};

    for (int i = 1; i < 13; ++i) {
      for (int j = 1; j < 13; ++j) {
        char c;
        cin >> c;
        map[i][j] = (c == '1') ? 145 - ((i - 1) * 12 + j) : 0;
      }
    }

    if (cin.fail())
      break;

    for (int i = 1; i < 13; ++i) {
      for (int j = 1; j < 13; ++j) {
        if (map[i][j] == 0)
          continue;

        map[i][j] = (map[i][j] < map[i-1][j]) ? map[i-1][j] : map[i][j];
        map[i][j] = (map[i][j] < map[i][j-1]) ? map[i][j-1] : map[i][j];

        for (int k = j-1; 0 < k; --k) {
          if ((map[i][k] == 0) || (map[i][k+1] < map[i][k]))
            break;
          map[i][k] = map[i][k+1];
        }
      }
    }

    int arr[145] = {};
    for (int i = 1; i < 13; ++i)
      for (int j = 1; j < 13; ++j)
        ++arr[map[i][j]];

    int cnt = 0;
    for (int i = 1; i < sizeof(arr)/sizeof(int); ++i)
      if (arr[i])
        ++cnt;

    cout << cnt << endl;
  }
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto V=vecin(N);

	int num=0;
	int flag = false;
	while(true){
		REP(i,N){
			if(V[i]%2){
				flag = true;
				break;
			}
			V[i]/=2;
		}
		if(!flag) num++;
		else break;
	}
	
	out(num);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>

int main() {
  std::string tmp;
  std::stack<int> st;
  while(std::cin >> tmp){
    int op1, op2;
    if(tmp == "+") {
      op1 = st.top(); st.pop();
      op2 = st.top(); st.pop();
      st.push(op1 + op2);
    }else if(tmp == "-") {
      op1 = st.top(); st.pop();
      op2 = st.top(); st.pop();
      st.push(op2 - op1);
    }else if(tmp == "*") {
      op1 = st.top(); st.pop();
      op2 = st.top(); st.pop();
      st.push(op1 * op2);
    }else {
      st.push(std::atoi(tmp.c_str()));
    }
  }
  std::cout << st.top() << std::endl;
}

Measured memory_bytes: 3180
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []
for i in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)
    
S = sum(T)

for i in range(M):
    print (S + X[i] - T[P[i]-1])


Measured memory_bytes: 3060
using System;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ABC = Console.ReadLine();
            string[] abc = (ABC.Split(' '));
            int a = int.Parse(abc[0]);
            int b = int.Parse(abc[1]);
            int c = int.Parse(abc[2]);

            //?????¶????¨???\
            if (a < b && b < c)
            {                
                   Console.WriteLine("Yes");
            }
            else
            {
                   Console.WriteLine("No");
            }
            

        }
    }
}

Measured memory_bytes: 8848
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.at(6) == '1' || s.at(6)== '2' || s.at(6)== '3' || s.at(6)== '4' ){
    if(s.at(5) == '0'){
      cout << "Heisei" << endl;
    }else{
      cout << "TBD" << endl;
  }
  }else{
      cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-08-29 19:57:44
 * @LastEditTime: 2020-08-30 10:24:35
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 2e5+7;
const int INF = 0x3f3f3f3f;

struct SegmentTree {
  struct TreeNode {
    int l, r, v, lazy;
  } tr[N<<2];
  void push_down(int i) {
    if (!tr[i].lazy) return;
    tr[i<<1].lazy = tr[i<<1|1].lazy = tr[i].lazy;
    tr[i<<1].v = tr[i<<1].l-tr[i].lazy;
    tr[i<<1|1].v = tr[i<<1|1].l-tr[i].lazy;
    tr[i].lazy = 0;
  }
  void build(int l, int r, int i = 1) {
    tr[i].l = l; tr[i].r = r;
    if (l == r) return;
    int mid = (l+r)>>1;
    build(l, mid, i<<1);
    build(mid+1, r, i<<1|1);
  }
  void update(int l, int r, int k, int i = 1) {
    if (l <= tr[i].l && r >= tr[i].r) {
      tr[i].v = tr[i].l-k;
      tr[i].lazy = k;
      return;
    }
    push_down(i);
    int mid = (tr[i].l+tr[i].r)>>1;
    if (l <= mid) update(l, r, k, i<<1);
    if (r >  mid) update(l, r, k, i<<1|1);
    tr[i].v = min(tr[i<<1].v, tr[i<<1|1].v);
  }
  int query(int x, int i = 1) {
    if (tr[i].l == tr[i].r) return tr[i].l-tr[i].v;
    push_down(i);
    int mid = (tr[i].l+tr[i].r)>>1;
    if (x <= mid) return query(x, i<<1);
    else return query(x, i<<1|1);
  }
};

int n, m;
SegmentTree seg;

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  seg.build(1, m);
  for (int i = 1, l, r; i <= n; ++i) {
    cin >> l >> r;
    if (l == 1) seg.update(l, r, -INF);
    else seg.update(l, r, seg.query(l-1));
    cout << (seg.tr[1].v > m ? -1 : seg.tr[1].v+i) << endl;
  }
  return 0;
}

Measured memory_bytes: 11780
#include <iostream>
#include <vector>
#include <regex>

using namespace std;

long long calc(long long n) {
    long long result { 0 };
    for (long long i { 1 }; i < n; ++i) {
        result += i;
    }
    return result;
}

int main() {
    int N;
    cin >> N;

    vector<string> s_i {};

    for (int i {0}; i < N; ++i) {
        string tmp;
        cin >> tmp;
        vector<char> chars(tmp.begin(), tmp.end());
        sort(chars.begin(), chars.end());
        string sorted(chars.begin(), chars.end());
        s_i.push_back(sorted);
    }

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

    long long result = 0;
    long long continues { 1 };

    for (int i { 1 }; i < N; ++i) {
        string sp = s_i[i - 1];
        string sc = s_i[i];

        if (sp == sc) {
            continues++;
        } else {
            result += calc(continues);
            continues = 1;
        }
    }
    result += calc(continues);

    cout << result << endl;


    return 0;
}


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

using namespace std;

int main() {
   int n;
   cin>>n;
   vector<int>x(n);
   for(int i=0;i<n;i++){
    cin>>x[i];
   }
   int ans=1e9;
   for(int i=1;i<=100;i++){
     int s=0;
     for(int j=0;j<n;j++){
        s+=(x[j]-i)*(x[j]-i);
     }
     ans=min(ans,s);
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
/*
	Problem Statement
	
	Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.To create a Haiku, Iroha has come up with three different phrases. 
	These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
*/

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

bool helper(int a, int b, int c)
{
	int fc=0,sc=0;
	if(a==5)
		fc++;
	else if(a==7)
		sc++;
	
	if(b==5)
		fc++;
	else if(b==7)
		sc++;
	
	if(c==5)
		fc++;
	else if(c==7)
		sc++;
	return fc==2 && sc==1;
}


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(helper(a,b,c))
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int>adj[501];
int sz[501];
int store[501][501];
int bs(int l,int r,int x,vector<int>v)
{
    int ans=-1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(v[mid]<=x)
        {
            l=mid+1;
            ans=mid;
        }
        else
            r=mid-1;
    }
    return ans+1;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=0; i<m; i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(int i=0; i<=500; i++)
    {
        sz[i]=adj[i].size();
        sort(all(adj[i]));
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            store[i][j]=bs(0,sz[i]-1,j,adj[i]);
        }
    }
    while(q--)
    {
        int x,y,ans=0;
        cin>>x>>y;
        for(int i=x; i<=n; i++)
        {
            //ans+=bs(0,sz[i]-1,y,adj[i]);
            ans+=store[i][y];
        }
        cout<<ans<<endl;

    }
    return 0;
}


Measured memory_bytes: 5684
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
  long long W, H, x, y; cin >> W >> H >> x >> y;
  cout << W*H*0.5 << " ";
  if(W%2==0 && H%2==0 && W/2==x && H/2 == y) {
    cout << 1;
  } else {
    cout << 0;
  }
  
  cout << endl;
  return 0;
}


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

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double H2 = double(H*60+M)/60;
    double t = M_PI*(H2/6.0-double(M)/30.0);
    double ans = sqrt(pow(A, 2)+pow(B, 2)-2.0*A*B*cos(t));
    printf("%3.10lf", ans);
}

Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;


int main(void){
    int n;
    cin >> n;
    n%=10;
    int a[5]={2,4,5,7,9},b[4]={0,1,6,8};
    REP(i,5){
        if(n==a[i]){
            cout << "hon";
            return 0;
        }
    }
    REP(i,4){
        if(n==b[i]){
            cout << "pon";
            return 0;            
        }
    }
    cout << "bon";
    return 0;
}

Measured memory_bytes: 3512
s = gets.chomp
p = gets.chomp
ls = s.length
lp = p.length
judge = false
for i in 1..ls
  if ls - i + 1 >= lp
    t = s[i-1,lp]
  else
    lt = ls - i + 1
    t = s[i-1,lt] + s[0,lp-lt]
  end
  judge = true if t == p
end
if judge
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 6104
#ARC059D
S=input()
c={}
for i in [chr(ord('a') + i) for i in range(26)]:
	c[i]=0
for i in range(len(S)):
	if i<3:
		c[S[i]]+=1
		if c[S[i]]>=2:
			print(1,i+1)
			exit()
	else:
		c[S[i-3]]-=1
		c[S[i]]+=1
		if c[S[i]]>=2:
			print(i-1,i+1)
			exit()
print(-1,-1)

Measured memory_bytes: 3188
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int a, b, c;

    cin >> a >> b >> c;

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

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


/*
int solve(int i){
	if(i == 0) return 0;
	if(i == 1) return 0;
	if(memo[i] != -1) return memo[i];
	int m = INT_MAX;
	for(int d = 1; d <= k; d++){
		if(i - d < 0) break;
		m = min(solve(i-d, k)+abs(h[i]-h[i-d]), m);
	}
	return memo[i] = m;
}*/


int n,k;

// first wins
bool dp[100001] = {};
int a[100];


// left i stones
int solve(int i){
	bool ret = false;
	// if take a[j] stones
	for(int j = 0; j < n; j++){
		if(a[j] <= i)
			if(dp[i-a[j]] == false){
				ret = true;
				break;
			}
	}
	return dp[i] = ret;
}


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

	for(int i = 0; i <= k; i++){
		solve(i);
	}

	cout << (dp[k] ? "First" : "Second") << endl;
	//cout << setprecision(12) << solve(k) << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    static int[] num;
    static long[] pre;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        num = new int[n];
        pre = new long[n];
        long tot = sc.nextInt();
        pre[0] = num[0] = (int)tot;
        for(int i=1;i<n;++i) {
            tot += num[i] = sc.nextInt();
            pre[i] = pre[i-1]+num[i];
        }
        int lo = 0;
        int hi = n-1;
        long best = tot/2;
        int ans = -1;
        long sol = (long)1e18;
      for(int mid = 1;mid<n-2;++mid){
                //case 1
                int m1 = div(0,mid);
                int m2 = div(mid+1,n-1);
                long diff1 = Math.max(Math.max(pre[m1],pre[mid]-pre[m1]),Math.max(pre[m2]-pre[mid],pre[n-1]-pre[m2]))
                        - Math.min(Math.min(pre[m1],pre[mid]-pre[m1]),Math.min(pre[m2]-pre[mid],pre[n-1]-pre[m2]));
                //case 2
                int x1 = div(0,mid+1);
                int x2 = div(mid+2,n-1);
                long diff2 = Math.max(Math.max(pre[x1],pre[mid+1]-pre[x1]),Math.max(pre[x2]-pre[mid+1],pre[n-1]-pre[x2]))
                        -  Math.min(Math.min(pre[x1],pre[mid+1]-pre[x1]),Math.min(pre[x2]-pre[mid+1],pre[n-1]-pre[x2]));
                sol = Math.min(sol,Math.min(diff1,diff2));


        }
        System.out.println(sol );
    }
    static int div(int start,int end){
        int lo = start;
        int hi = end;
        long rem = (start>0?pre[start - 1]:0);
        long best = (pre[end] - rem)/2;
        int ans = start;
        long d = (long)1e18;
        while(lo <= hi){
            int mid = (lo + hi)/2;
            if(best - (pre[mid]-rem) > 0){
                ans = mid;
                lo = mid + 1;
            }
            else
                hi = mid - 1;
        }
        //System.out.println(ans);
        if(ans == pre.length-1)
            return ans;
        if(Math.abs(pre[ans] - rem -
                (pre[end] - pre[ans]))< Math.abs(pre[ans+1] - rem - (pre[end] - pre[ans+1])))
            return ans;
        else
            return ans + 1;
    }
}


Measured memory_bytes: 87844
# -*- coding: utf-8 -*-

S = input()

formerYY = int(S[:2]) > 12 or int(S[:2]) == 0
latterYY = int(S[2:]) > 12 or int(S[2:]) == 0
if formerYY and latterYY:
    print("NA")
elif formerYY and not latterYY:
    print("YYMM")
elif latterYY and not formerYY:
    print("MMYY")
else:
    print("AMBIGUOUS")


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

string join(const vector<int>& v, const char* delim = 0) {
  string s;
  if (!v.empty()) {
    s += to_string(v[0]);
    for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += to_string(v[i]);
    }
  }

  return s;
}

int main()
{
  int n, x;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    a.push_back(x);
  }
  cout << join(a, " ") << endl;

  for (int i = 1; i < n; i++)
  {
    for (int j = i - 1; j >= 0; j--)
      if (a[j] > a[j + 1])
        swap(a[j], a[j + 1]);
      else
        break;
    cout << join(a, " ") << endl;
  }
  return 0;
}

Measured memory_bytes: 3236
if __name__ == "__main__":
    while True:
        N = int(input())
        if N == 0:
            break
        # 左, 下, 右, 上
        wak = {0: [0, 0]}
        ml = float("inf")
        md = float("inf")
        mr = -float("inf")
        mu = -float("inf")
        for i in range(1, N):
            n, d = map(int, input().split())
            if d == 0:
                wak[i] = [wak[n][0] - 1, wak[n][1]]
            elif d == 1:
                wak[i] = [wak[n][0], wak[n][1] - 1]
            elif d == 2:
                wak[i] = [wak[n][0] + 1, wak[n][1]]
            elif d == 3:
                wak[i] = [wak[n][0], wak[n][1] + 1]
        for k, v in wak.items():
            ml = min(v[0], ml)
            md = min(v[1], md)
            mr = max(v[0], mr)
            mu = max(v[1], mu)
        print(abs(mr - ml) + 1, abs(mu - md) + 1)
        # print(wak)
        # print("--------------------")



Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	int n;
	cin >> n;
	std::vector<int> x(n);
	rep(i,n) cin >> x[i];

	sort(ALL(x));
	int min=INF;
	int min_index=0;
	for(int i=x[0]; i<=x[n-1]; i++){
		int sum=0;
		rep(j,n){
			sum += (x[j]-i)*(x[j]-i);
		}
		if (sum <= min) min=sum;
	}
	cout << min << endl;


  return 0;
}


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

int main(){
  long long int n,x,y;
  int sum = 0;
  long long int dn,d;
  cin >> n >> d;
  d = d*d;
  
  for(int i=0;i<n;i++){
    cin >> x >> y;
    dn = abs(x*x) + abs(y*y);
    if(d >= dn)
      sum += 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class20
    {
        static void Main()
        {
            string S = Console.ReadLine();
            List<char> list = new List<char>();
            for(int i = 0; i < S.Length; i++)
            {
                if (!list.Contains(S[i]))
                    list.Add(S[i]);
            }
            bool frag = true;
            for(int i = 0; i < list.Count(); i++)
            {
                if (list[i] == 'N')
                    frag = list.Contains('S') ? frag : false;
                else if (list[i] == 'S')
                    frag = list.Contains('N') ? frag : false;
                else if (list[i] == 'W')
                    frag = list.Contains('E') ? frag : false;
                else if (list[i] == 'E')
                    frag = list.Contains('W') ? frag : false;
            }
            Console.WriteLine(frag ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=105,INF=1<<30;

int V,cmp[MAX];
vector<int> G[MAX],rG[MAX],vs;//vsがトポソの逆順になってる
bool used[MAX];

void init(){
    for(int i=0;i<V;i++){
        G[i].clear();
        rG[i].clear();
        cmp[i]=0;
        used[i]=0;
    }
    vs.clear();
}

void add_edge(int from,int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void DFS(int v){
    used[v]=1;
    for(int i=0;i<G[v].size();i++){
        if(used[G[v][i]]==0) DFS(G[v][i]);
    }
    vs.push_back(v);
}

void rDFS(int v,int k){
    used[v]=1;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++){
        if(used[rG[v][i]]==0) rDFS(rG[v][i],k);
    }
}

int scc(){
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++){
        if(used[v]==0) DFS(v);
    }
    
    memset(used,0,sizeof(used));
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        if(used[vs[i]]==0) rDFS(vs[i],k++);
    }
    return k;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        V=N;
        init();
        vector<double> p(N),q;
        for(int i=0;i<N;i++){
            cin>>p[i];
            int k;cin>>k;
            for(int j=0;j<k;j++){
                int a;cin>>a;
                a--;
                add_edge(i,a);
            }
        }
        int k=scc();
        set<int> need;
        
        for(int i=0;i<k;i++) need.insert(i);
        
        for(int i=0;i<N;i++){
            for(int to:G[i]){
                if(cmp[i]!=cmp[to]){
                    if(need.count(cmp[to])) need.erase(cmp[to]);
                }
            }
        }
        
        q.assign(k,1.0);
        
        for(int i=0;i<N;i++){
            if(need.count(cmp[i])){
                q[cmp[i]]*=p[i];
            }
        }
        
        double ans=1.0;
        
        for(int i=0;i<k;i++){
            if(q[i]!=1.0) ans*=(1.0-q[i]);
        }
        
        cout<<fixed<<setprecision(9)<<ans<<endl;
    }
}



Measured memory_bytes: 3376
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int INF=2147483647;
int n,m;
struct edge{
	int u,v;
}e[100005];
int p[100005];
ll ans[100005],sum[100005];
int find(int a){
	if(p[a]==a) return a;
	else return p[a]=find(p[a]);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>e[i].u>>e[i].v;
	for(int i=1;i<=n;i++)
		p[i]=i,sum[i]=1;
	ans[m]=(ll)n*(n-1)/2;
	for(int i=m;i>0;i--){
		int x=find(e[i].u),y=find(e[i].v);
		if(x==y)
			ans[i-1]=ans[i];
		else{
			ans[i-1]=ans[i]-sum[x]*sum[y];
			sum[x]+=sum[y];
			p[y]=x;
		}
	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4096
($n,$k) = split/ /,<>;
chomp($a = <>);
@a = split/ /,$a;

foreach (@a){
    $hash{$_}++;
}
$ans = 0;
foreach (sort {$hash{$b} <=> $hash{$a}}keys %hash){
	$cnt++;
    if($cnt > $k){
    	$ans += $hash{$_};
    }
}
print $ans;

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

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N,Q;
    cin >> N >> Q;
    rep(i,Q){
        int a,b;
        cin >> a >> b;
      	if(N==1)cout << min(a,b) << endl;
      	else{
        while(a!=b){
            if(a>b){
                int num=a;
                a=b;
                b=num;
            }
            b=(b+N-2)/N;
        }
        cout << a << endl;
        }
    }

    


}

/*



 */



Measured memory_bytes: 1280
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;

    REP(i, n) {
        int sum = 0;

        for (char ch = 'a'; ch <= 'z'; ch++) {
            bool r = false, l = false;
            for (int j = 0; j <= i; j++) {
                if (s[j] == ch)
                    l = true;
            }

            for (int j = i + 1; j < n; j++) {
                if (s[j] == ch)
                    r = true;
            }
            if (l && r)
                sum++;
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
struct Node
{
    double x, y;
    Node(double xx = 0, double yy = 0){
        x = xx; y = yy;
    }

    Node operator + (Node b){
        return Node(x+b.x, y+b.y);
    }
    Node operator - (Node b){
        return Node(x-b.x, y-b.y);
    }
    Node operator * (double a){
        return Node(a*x, a*y);
    }
    Node operator / (double a){
        return Node(x/a, y/a);
    }

    double norm(){return x*x+y*y;}
    double len(){
        return sqrt(norm());
    }

    bool operator < (const Node &p) const{
        return x!=p.x ? x<p.x : y<p.y;
    }

    bool operator == (const Node &p) const {
        return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
    }
};

bool equals(double a, double b) {
    return fabs(a)-fabs(b) < eps;
}

typedef Node vtr;

struct line{
    Node a, b;
    line(Node x, Node y){
        a = x, b = y;
    }
};

//向量点积
double dot(vtr a, vtr b){
    return a.x*b.x+a.y*b.y;
}

//向量叉积
double cross(vtr a, vtr b){
    return a.x*b.y-a.y*b.x;
}

//判断向量a,b是否正交(垂直)
bool isOrthogonal(vtr a, vtr b){
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Node a1, Node a2, Node b1, Node b2){
    return isOrthogonal(a1-a2, b1-b2);
}

bool isOrthogonal(line s1, line s2){
    return equals(dot(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//判断向量a,b是否平行
bool isParallel(vtr a, vtr b){
    return equals(cross(a, b), 0.0);
}

bool isParallel(Node a1, Node a2, Node b1, Node b2){
    return isParallel(a1-a2, b1-b2);
}

bool isParallel(line s1, line s2){
    return equals(cross(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//投影 求垂足坐标
//点p在直线p1p2上的投影
Node project(line s, Node p)
{
    vtr base = s.b-s.a;
    //算出比例
    double r = dot(p-s.a, base)/base.norm();
    return s.a+base*r;
}

//映象 求p以直线s为对称轴的对称点
Node reflect(line s, Node p){
    return p+(project(s, p)-p)*2.0;
}

int ccw(Node p0, Node p1, Node p2)
{
    vtr a = p1-p0, b = p2-p0;
    //b在a的逆时针方向
    if(cross(a, b) > eps) return 1;
    //顺时针方向
    if(cross(a, b) < -eps) return -1;
    //共线但反向
    if(dot(a, b) < -eps) return 2;
    //共线同向
    //b更长一点
    if(a.norm() < b.norm()) return -2;
    //a更长一点
    return 0;
}

//判断两线段是否相交
bool intersect(Node p1, Node p2, Node p3, Node p4){
    bool t1 = ccw(p1, p2, p3)*ccw(p1, p2, p4)<=0;
    bool t2 = ccw(p3, p4, p1)*ccw(p3, p4, p2)<=0;
    return t1&&t2;
}
bool intersect(line s1, line s2){
    return intersect(s1.a, s1.b, s2.a, s2.b);
}

//求线段交点
Node getCrossPoint(line s1, line s2)
{
    vtr base = s2.b-s2.a;
    double d1 = abs(cross(base, s1.a-s2.a));
    double d2 = abs(cross(base, s1.b-s2.a));
    double t = d1/(d1+d2);
    return s1.a+(s1.b-s1.a)*t;
}

int main()
{
    Node p0, p1, p2, p3;
    int q; cin >> q;
    while(q--)
    {
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        line s1 = line(p0, p1);
        line s2 = line(p2, p3);
        Node p = getCrossPoint(s1, s2);
        printf("%.10f %.10f\n", p.x, p.y);
    }
    return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define MP make_pair
#define PB push_back
#define in int
#define ll long long
#define ull unsigned long long
#define vc vector
#define SQ(j) (j)*(j)
#define x first
#define y second
//
//#define ld long double
#define dbl  long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pdd pair<dbl,dbl>
#define sz(xxx) ((int)(xxx.size()))
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

//#define printf(...) (0)
#define db(x) if(DEBUG) {cout << #x << " = " << x << endl;}
#define dbCont(x) if(DEBUG) {cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout<<endl;}

using namespace std;

template<class K, class V>
ostream &operator<<(ostream &out, pair<K, V> &elem) {
    out << "{" << elem.first << "," << elem.second << "}";
    return out;
}

// 4:13

int DEBUG = 0;

using namespace std;

const int N = 100 * 1000 + 5;
const ll MOD = 1000 * 1000 * 1000 + 7;
ll INF = 1000 * 1000 * 1000 ;



int main() {

    int n,k,s;

    cin >> n >> k >> s;

    loop(i,k) cout << s << ' ';

    if(s == INF) INF--;

    loop(i,n-k) cout << INF << ' ';
    cout << endl;

    return 0;
}

/*



 */

Measured memory_bytes: 1280
#include<stdio.h>
#define M 45
int f[M]; 
int F(int);
  
int main(int argc,char *argv[]){
  int n,i;
  f[0] = 1;
  f[1] = 1;
    
  scanf("%d",&n);
    
  for(i = 2; i < M; i++){
    f[i] = -1;
  }
    
  printf("%d\n",F(n));
     
  return 0;
}
 
int F(int n){
  int x;
    
  if(f[n] != -1) return f[n];
  x = F(n-1) + F(n-2);
  f[n] = x;
  return x;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;



//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    int ans;
    ans=n/2;
    if(n%2>0){
        ans=ans+1;
    }
    cout << ans;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

        ll n;
        cin>>n;
        map<string ,int>m;

        while(n--)
        {
            string s;
            cin>>s;
            m[s]++;
        }
        map<string ,int>::iterator itr;
        int temp=0;
        for(itr=m.begin();itr!=m.end();itr++)
        {
            if(itr->second>temp)
                temp=itr->second;

        }
        for(itr=m.begin();itr!=m.end();itr++)
        {
            if(itr->second==temp)
            {
                cout<<itr->first<<endl;
            }
        }


}



Measured memory_bytes: 25216
from scipy.sparse import*
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])[::-1]
f=find(c)[0]
f[csgraph.depth_first_order(csr_matrix((f[1:],(t[:-n:2],t[1:-n:2])),[n+1]*2),1,0,0)-1]=c
print(sum(c[1:]),*f)

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

const int N = 5e5+7;
int a[N];

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

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

    for (int i=1; i<=n; i++)
        if (s[i-1] == '<')
            a[i] = max(a[i], a[i-1]+1);


    for (int i=n-1; i>=0; i--)
        if (s[i] == '>')
            a[i] = max(a[i], a[i+1]+1);

    long long ans = 0;
    for (int i=0; i<=n; i++) {
        ans += a[i];
//        cout<<a[i]<<" ";
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 2844
import java.util.*;
import java.lang.*;

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

        int ans = (A*3 + P)/2;
        System.out.println(ans);

   }
}


Measured memory_bytes: 23636
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
vector<P> vec[200010], peo[200010];
ll bit[100010], num;
ll par[100010], sz[100010];
ll n;

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	for (int i = 0; i <= 300010; i++)
	{
		d[i] = INF;
	}
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (ll i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n;
	if (n == 3)
	{
		cout << "Yes" << endl;
		for (int i = 1; i < 6; i++)
		{
			cout << i << ' ' << i + 1 << endl;
		}
		return 0;
	}
	ll two_pow = 1;
	while (two_pow < n)
	{
		two_pow *= 2;
	}
	if (two_pow == n)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
		two_pow /= 2;
		for (int i = 1; i < two_pow - 1; i++)
		{
			cout << i << ' ' << i + 1 << endl;
		}
		cout << two_pow - 1 << ' ' << 1 + n << endl;
		for (int i = 1; i < two_pow - 1; i++)
		{
			cout << i + n << ' ' << i + n + 1 << endl;
		}
		for (int i = two_pow + 1; i <= n; i++)
		{
			cout << i - two_pow << ' ' << i << endl;
		}
		for (int i = two_pow + 2; i <= n; i++)
		{
			cout << i - 1 << ' ' << i + n << endl;
		}
		cout << 1 << ' ' << two_pow << endl;
		cout << two_pow << ' ' << n + two_pow + 1 << endl;
		cout << two_pow + 1 << ' ' << n + two_pow << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 21760