akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NOT_FOUND 0
int binarySearch(int);

int S[100000];
int T[50000];
int n;
int q;

int main()
{
  int i;
  int count=0;

  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    if(binarySearch(T[i]) != NOT_FOUND){
      count++;
    }
  }
  printf("%d\n",count);

  return 0;
}

int binarySearch(int key)
{
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key){
      return 1;
    } else if(key < S[mid]){
      right =  mid;
    } else {
      left = mid +1;
    }
  }
  return NOT_FOUND;
}
      
  



Measured memory_bytes: 3232
#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;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    vector <pair <int, int>> a(n);
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        a[i]={t,i+1};
    }
    sort(ALL(a));
    REP(i,n)cout << a[i].second << " ";

    return 0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <map>
#include <vector>
#include <functional>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1ll << 60)

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

ll n, d;
ll x[30], y[30];

void dfs(int pos, int end, P sum, vector<P> &v) {
	if (pos == end) {
		v.push_back(sum);
		return;
	}
	
	dfs(pos + 1, end, P(sum.first + x[pos], sum.second + y[pos]), v);
	dfs(pos + 1, end, P(sum.first - x[pos], sum.second - y[pos]), v);
	dfs(pos + 1, end, sum, v);
}

int main() {
    cin >> n >> d;
    REP(i,n) cin >> x[i] >> y[i];
     
	vector<P> s, u;
     
    dfs(0, n / 2, P(0, 0), s);
    dfs(n / 2, n, P(0, 0), u);
	
	sort(s.begin(), s.end(), greater<P>());
	sort(u.begin(), u.end());
	
	s.erase(unique(s.begin(), s.end()), s.end());
	u.erase(unique(u.begin(), u.end()), u.end());

	deque<int> deq;
	
	int l = 0, r = 0;
	ll ans = -INF;
	REP(i, s.size()) {
		while (r < u.size() && u[r].first <= d - s[i].first) {
			while (!deq.empty() && u[deq.back()].second <= u[r].second) deq.pop_back();
			deq.push_back(r);
			r++;
		}
		
		while (l < u.size() && u[l].first < -d - s[i].first) {
			if (!deq.empty() && deq.front() == l) deq.pop_front();
			l++;
		}
		
		if (!deq.empty()) ans = max(ans, s[i].second + u[deq.front()].second);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

struct dsu {
	vector<int> chot;
	int n;
	dsu(int n) : n(n) {
		chot.resize(n + 1,-1);
	}
	int find(int u) {
		return chot[u] < 0 ? u : chot[u] = find(chot[u]);
	}
	void combine(int u,int v) {
		u = find(u);v = find(v);
		if (u != v) {
			if (-chot[u] < -chot[v]) swap(u,v);
			chot[u] += chot[v];
			chot[v] = u;
		}
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	dsu d(n);
	for (int i = 1;i <= m;i++) {
		int x,y;
		cin >> x >> y;
		d.combine(x,y);
	}
	int ans = 0;
	for (int i = 1;i <= n;i++) {
		if (d.find(i) == i) {
			ans = max(ans,-d.chot[i]);
		}
	}
	cout << ans;
} 

Measured memory_bytes: 3980
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    string s,t;
    cin >> s >> t;
    
    cout << "A" << t[0] << "C" << ENT;
    
    return 0;
}

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


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    K = in_n()

    t = 7 % K
    x = 7 % K
    for i in range(10000000):
        if t == 0:
            print(i + 1)
            exit()
        x = (x * 10) % K
        t += x
        t = t % K

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63076
N = int(input())

# 1桁
if N < 10:
    print(N)

# 2桁
elif N < 100:
    print(9)

# 3桁
elif N < 1000:
    print(9 + (N - 99))

# 4桁
elif N < 10000:
    print(9 + 900)

# 5桁
elif N < 100000:
    print(9 + 900 + (N - 9999))

elif N == 100000:
    print(9 + 900 + 90000)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
    int i,j,k,H,W;
    while(1){
        cin >>H >>W;
        if(H==0 && W==0) break;
        for (i=1; i<=H; i++){
            if (i%2==1){
                for (j=1;j<=W;j++){
                    if (j%2==1) {
                        cout<<"#";
                    }
                    else {
                        cout<<".";
                    }
                }
            
            }
            else{
                for (k=1;k<=W;k++)   {
                    
                    if(k%2==0)  {
                        cout<<"#";
                    }
                    
                
                    else{
                        cout<<".";
                    }
        
                }
            
            }
        
        
       
        
        cout<<endl;
       
        
    }
    
    cout<<endl;
    }

    return 0;
}




Measured memory_bytes: 3088
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    com(i,n)
    {
         cin>>a[i];
    }
    sort(a,a+n);
    com(i,k) sum+=a[i];
    cout << sum << endl;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A, B;

signed main()
{
    cin >> N;
    bool isAllEq = true;
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        if(a != b) { isAllEq = false; }
        A.push_back(a);
        B.push_back(b);
    }
    if(isAllEq) {
        printf("0\n");
        return 0;
    }

    ll ans = 0;
    ll base = 0;
    REP(i, N) {
        if(A[i] < B[i]) { base += B[i] - A[i]; }
        ans += B[i];
    }
    ll ind = -1;
    ll val = LLINF;
    REP(i, N) {
        if(base <= A[i] - B[i]) {
            ind = i;
            break;
        } else if(A[i] > B[i] && val > B[i]) {
            val = B[i];
            ind = i;
        }
    }

    printf("%lld\n", ans - B[ind]);
    return 0;
}


Measured memory_bytes: 768
H,w,d = map(int, raw_input().split())
mat = [map(int, raw_input().split()) for i in range(H)]

h = {}
cost = {}
for i in range(len(mat)):
	for j in range(len(mat[0])):
		h[mat[i][j]] = (i,j)

import collections
cost = collections.Counter()
def f(uu,vv): return abs(uu[0] -vv[0]) + abs(uu[1] -vv[1]) 
for u in range(1,H*w + 1):
	if u - d >= 1: cost[u] = f(h[u], h[u - d]) + cost[u - d]


def g(u,v, cost,d): return cost[v] - cost[u]# if  in cost else 0) 

for qi in  range(int(raw_input())):
	u,v = map(int, raw_input().split())
	print g(u,v,cost, d)

Measured memory_bytes: 119580
#include <iostream>
#include <complex>
#include <iomanip>

using namespace std;

int main() {
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	
	complex<double> s(a, b), t(c, d);
	
	cout << fixed << setprecision(10) << sqrt(norm(s - t)) << '\n';
	
	return 0;
}


Measured memory_bytes: 3312
// https://atcoder.jp/contests/abc114/tasks/abc114_b

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

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

    int ans = 1000;
    int curr = stoi(s.substr(0, 2));
    for (int i = 2; i < s.size(); i++)
    {
        curr = (curr % 100) * 10 + (s[i] - '0');
        ans = min(ans, abs(753 - curr));
    }

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


Measured memory_bytes: 3612
#include <stdio.h>

class Dice3{
public:
	Dice3(){
		number = new int[6];
		checkTable = new int[101];
		for(int i = 0; i < 101; i++) checkTable[i] = -1;
	};
	~Dice3(){
		delete[] number;
		delete[] checkTable;
	};

	void setLabel(int index,int num){
		number[index] = num;
		checkTable[num] = index;
	};

	void roll(char dst){
		switch(dst){
		case 'E':
			setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
			break;
		case 'N':
			setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
			break;
		case 'S':
			setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
			break;
		case 'W':
			setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
			break;
		}
	};

	bool isValidMember(int inputed[]){
		for(int i = 0; i < 6; i++)
		{
			if(checkTable[inputed[i]] == -1)
				return false;
		}
		return true;
	}
	bool isSameDice(int inputed[]){
		char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < 24; i++){
			roll(order[i]);
			for(int j = 0; j < 6; j++){
				if(inputed[j] != number[j])
					break;
				if(j == 5)
					return true;
			}
		}
		return false;
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

private:
	int* number;
	int* checkTable;
};

int main(){
	Dice3 dice3;
	int tmp,inputed[6];
	for(int i = 0; i < 6; i++){
		scanf("%d",&tmp);
		dice3.setLabel(i,tmp);
	}
	for(int i = 0; i < 6; i++) scanf("%d",&inputed[i]);

	if(dice3.isValidMember(inputed) && dice3.isSameDice(inputed))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



Measured memory_bytes: 2700
#include<stdio.h>
struct card
{
  char num[2];
  char mark;
  int value;
};
int n;
char isStable(struct card in[], struct card out[])
{
  int i;
  for(i = 0; i < n; i++)
    {
      if(in[i].mark != out[i].mark)
	{
	  return 0;
	}
    }
  return 1;
}
int main()
{
  int i, j, minj, k;
  struct card c[36], a[36], b[36], tmp;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%s", a[i].num);
      if(a[i].num[0] == 'H')
	{
	  a[i].mark = 'H';
	}
      else if(a[i].num[0] == 'S')
	{
	  a[i].mark = 'S';
	}
      else if(a[i].num[0] == 'C')
	{
	  a[i].mark = 'C';
	}
      else
	{
	  a[i].mark = 'D';
	}
      if(a[i].num[1] == '1')
	{
	  a[i].value = 1;
	}
      else if(a[i].num[1] == '2')
	{
	  a[i].value = 2;
	}
      else if(a[i].num[1] == '3')
	{
	  a[i].value = 3;
	}
      else if(a[i].num[1] == '4')
	{
	  a[i].value = 4;
	}
      else if(a[i].num[1] == '5')
	{
	  a[i].value = 5;
	}
      else if(a[i].num[1] == '6')
	{
	  a[i].value = 6;
	}
      else if(a[i].num[1] == '7')
	{
	  a[i].value = 7;
	}
      else if(a[i].num[1] == '8')
	{
	  a[i].value = 8;
	}
      else
	{
	  a[i].value = 9;
	}
      b[i] = a[i];
      c[i] = a[i];
    }
  for(i = 0; i <= n-1; i++)
    {
      for(j = n - 1; j >= i + 1; j--)
	{
	  if(c[j].value < c[j-1].value)
	    {
	      tmp = c[j];
	      c[j] = c[j-1];
	      c[j-1] = tmp;
	    }
	}
    }
    
  for(i = 0; i <= n-1; i++)
    {
      minj = i;
      for(j = i; j <= n-1; j++)
	{
	  if(b[j].value < b[minj].value)
	    {
	      minj = j;
	    }
	}
      tmp = b[i];
      b[i] = b[minj];
      b[minj] = tmp;
    }

    
  for(i = 0; i < n - 1; i++)
    {
      printf("%c%d ", c[i].mark, c[i].value);
    }
  printf("%c%d\n", c[n-1].mark, c[n-1].value);
  printf("Stable\n");

    
  for(i = 0; i < n - 1; i++)
    {
      printf("%c%d ", b[i].mark, b[i].value);
    }
  printf("%c%d\n", b[n-1].mark, b[n-1].value);
  if(isStable(b, c) == 1)
    {
      printf("Stable\n");
    }
  else
    {
      printf("Not stable\n");
    }
    
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

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

  int i, j, k;
  ll l;
  int X[n][d];

  rep(i,n){
    rep(j,d){
      cin >> X[i][j];
    }
  }
  
  int ans = 0;
  ll tmp = 0;

  rep(i,n-1){
    repd(j,i+1,n){
      tmp = 0;
      rep(k,d){
        tmp += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
      }
      for(ll l=1;l<1000;l++){
        if((ll)l*l == tmp){ans++;break;}
        if((ll)l*l > tmp){break;}
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, mi1,mi2,sum;
LL ans,a;
LL no;
string s,t;

int main() {
	cin >> N;
	cin >> M;
	if (M == 1) {
		cout << 0 << endl;
		return 0;
	}
	no = N;
	ans = 1;
	while (no < M) {
		no = no - 1 + N;
		ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    ll n,m;cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    vl v(m),ans(m-1);
    rep(i,m)cin >> v[i];
    sort(all(v));
    rep(i,m-1)ans[i]=v[i+1]-v[i];
    sort(all(ans));
    ll count=0;
    for(ll i=0;i<m-n;i++){
        count+=ans[i];
    }
    cout << count << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;

ll dig(ll n) {
    if(n <= 9) return 1;
    else if(n%9 == 0) return (n/9);
    else return ((n/9) + 1);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T = 1;
    // cin >> T;
    
    while(T--) {
        string s;
        cin >> s;

        ll consec = 0;
        ll max = 0;

        for(ll i = 0; i < 3; i++) {
            if(s[i] == 'R') consec++;
            else consec = 0;
            if(max < consec) max = consec;
        }
        cout << max << endl;
    }
    return 0; 
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

// #define int long long

signed main(){
  int d[5];
  int N=5;
  int ans = 0;
  int an = 10;
  LOOP(i,N){
    cin >> d[i];
    an = min(an, (d[i]%10 ? d[i]%10 : 10));
    ans += (d[i]%10 ? 10-d[i]%10 : 0) + d[i];
  }
  cout << (ans-10)+an << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    rep(i,1000){
        if(a * i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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

ll gcd(int a,int b){
    ll r;
    while(b != 0){
        if(a < b)swap(a,b);
        r = a%b;
        a=b;
        b=r;
    }
    return a;
}
ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}

int main(){
  ll x,y;
  cin>>x>>y;
  ll ans;
  ans = lcm(x,y);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int sum[200005];
void dfs(int u, int p){
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v == p) continue;
        sum[v] += sum[u];
        dfs(v, u);
    }
}
int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i=1;i<=n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    for(int i=1;i<=q;i++){
        int p, x;
        scanf("%d%d", &p, &x);
        sum[p] += x;
    }
    dfs(1, 0);
    for(int i=1;i<=n;i++) printf("%d ", sum[i]);
}

Measured memory_bytes: 27868
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main () {
    input!{
        n: usize,
        d:[(usize, usize); n],
    }
    let mut count = 0;
    for i in 0..d.len() {
        if d[i].0 == d[i].1 {
            count += 1;
        }else {
            count = 0;
        }
        if count == 3 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

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

int main(){
  string S,T;
  int a = 0;
  cin >> S >> T;
  
  for(int i=0;i<S.size();i++){
    if(S.at(i) != T.at(i))
      a++;
  }
  
  cout << a << endl;
}

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

template <typename T>
class BIT {
  int n;
  vector<T> bit;
public:
  BIT(int _n) {
    n = _n;
    bit = vector<T>(n+1,(T)0);
  }
  T sum(int i) {
    T s = 0;
    while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
  }
  void add(int i, T x) {
    while(i <= n){
    bit[i] += x;
    i += i & -i;
    }
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  int c[n];
  rep(i,n) {
    cin >> c[i];
    c[i]--;
  }
  int l[q], r[q], ord[q];
  rep(i,q) {
    cin >> l[i] >> r[i];
    l[i]--; r[i]--;
    ord[i] = i;
  }
  sort(ord,ord+q,[&](int a, int b){return r[a] < r[b];});
  vector<int> last(n,-1);
  BIT<int> bit(n+1);
  int ans[q];
  int pos = 0;
  rep(i,q) {
    while(pos <= r[ord[i]]) {
      if(last[c[pos]] != -1) bit.add(last[c[pos]],-1);
      last[c[pos]] = pos+1;
      bit.add(pos+1,1);
      pos++;
    }
    ans[ord[i]] = bit.sum(r[ord[i]]+1) - bit.sum(l[ord[i]]);
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 17392
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  map<string,int> dic;
  int mx;
  rep(i,n){
    string s;
    cin >> s;
    dic[s]++;
    if( i==0 ){
      mx = dic[s];
    }else{
      mx = max(dic[s],mx);
    }
  }
  
  for( auto p : dic ){
    if( p.second == mx ){
      cout << p.first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;
    int n,x,y;
    cin>>n>>x>>y;
    int freq[n]={0};
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int dp;
            if(j<=x)
            {
                dp=j-i;
                freq[dp]++;
            }
            else
            {
                dp=min(j-i,abs(x-i)+1+abs(y-j));
                freq[dp]++;
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        cout<<freq[i]<<endl;
    }
}   

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

int main(){
    int n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    // cnt1 = aの方に足しても大丈夫な回数
    // cnt2 = bに足す必要のある回数
    ll cnt1 = 0, cnt2 = 0;
    rep(i,n){
        if(a[i] > b[i]) cnt2 += a[i]-b[i];
        else if(a[i] < b[i]) cnt1 += (b[i]-a[i])/2;
    }
    if(cnt1 >= cnt2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <stack>
using namespace std;

int N;
char S[205];
int bra;
stack<int> s;

int main() {
    scanf("%d%s", &N, S);
    for (int i = 0; i != N; ++i) {
        switch (S[i]) {
        case '(':
            s.push('(');
            break;
        case ')':
            if (s.empty()) ++bra;
            else s.pop();
            break;
        }
    }
    while (bra--) putchar('(');
    printf("%s", S);
    while (!s.empty()) {
        putchar(')');
        s.pop();
    }
    putchar('\n');
    return 0;
}


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

int main(){
    int m1,d1,m2,d2; cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2) cout << "1" << endl;
    else cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
//
// Created by moono on 2019/01/31.
//

#include <string.h>
#include <iostream>
#include <queue>
#include <map>

using namespace std;

bool is_all_arrived(vector<bool> bools){
  for(bool b: bools){
    if(!b) return false;
  }
  return true;
}



int main() {
  //
  int N, M;
  cin >> N >> M;


  //
  vector<int> graph[N];
  for (int i = 0; i < M; ++i) {
    int from, to;
    cin >> from >> to;
    graph[--from].push_back(--to);
    graph[to].push_back(from);
  }

  //
  vector<bool> *is_arrive = new vector<bool>(N);
  fill(is_arrive->begin(), is_arrive->end(), false);
  queue<pair<int, vector<bool>*>> Q({make_pair(0, is_arrive)});

  //
  int num = 0;
  while(!Q.empty()){
    auto pair = Q.front(); Q.pop();
    int position = pair.first;
    vector<bool> is_arrive = *pair.second;

    //
    is_arrive[position] = true;
    if(is_all_arrived(is_arrive)){
      num++;
    }else{
      vector<int> next_candidate = graph[position];
      for (int i : next_candidate) {
        if(!is_arrive[i]){
          vector<bool> *is_arrive2 = new vector<bool>(is_arrive);
          Q.push(make_pair(i, is_arrive2));
        }
      }
    }
  }

  cout << num << endl;

  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

/**
 * https://beta.atcoder.jp/contests/abc070/tasks/abc070_c
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		long[] time = new long[N];
		for(int i=0; i<N; i++)  time[i] = sc.nextLong();
		sc.close();
		
		long ans = time[0];
		for(int i=1; i<N; i++){
			ans = (ans/getGcd(ans,time[i]))*time[i];
		}
		
		System.out.println(ans);

	}
	
	private static long getGcd(long a, long b){
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b;
	        a = temp;
	    }
	    return a;
	}

}

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

int main() {
  char c;
  cin >> c;
if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  cout << "vowel" << endl;
}
  else {
    cout << "consonant" << endl;
  }
}



Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WvNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int n, m, u, v, ans;
vector<int> adjList[N];
int dp[N];

int dfs(int i) {
    if (~dp[i])return dp[i];
    dp[i] = 0;
    //cout << i << endl;
    for (auto it : adjList[i]) {
        dp[i] = max(dp[i], dfs(it) + 1);
    }
    return dp[i];
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        u--, v--;
        adjList[u].push_back(v);
    }
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) {
        if (dp[i] == -1)
            ans = max(ans, dfs(i));
    }
    cout << ans;
    return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionE
    {
        public class XY : IEquatable<XY>
        {
            public int X;
            public int Y;

            public override bool Equals(object obj)
            {
                return this.Equals(obj as XY);
            }

            public bool Equals(XY p)
            {
                if (Object.ReferenceEquals(p, null)) {
                    return false;
                }

                if (Object.ReferenceEquals(this, p)) {
                    return true;
                }

                if (this.GetType() != p.GetType()) {
                    return false;
                }

                return (X == p.X) && (Y == p.Y);
            }

            public static bool operator ==(XY lhs, XY rhs)
            {
                if (Object.ReferenceEquals(lhs, null)) {
                    if (Object.ReferenceEquals(rhs, null)) {
                        return true;
                    }

                    return false;
                }
                return lhs.Equals(rhs);
            }

            public static bool operator !=(XY lhs, XY rhs)
            {
                return !(lhs == rhs);
            }

            public override int GetHashCode()
            {
                return X * 0x1000 + Y;
            }
        }

        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //N = 1対策用今回の問題上大きさが0のベクトルはないので問題なし
            var dic = new Dictionary<XY, long> {
                { new XY{ X = 0, Y = 0 }, 0 }
            };

            // 整数の入力
            var n = long.Parse(Console.ReadLine());

            var xy = new XY[n];

            for(int i = 0; i < n; i++) {
                // 整数配列の入力
                var a = Console.ReadLine().Split(' ').Select(q => int.Parse(q)).ToArray();
                xy[i] = new XY { X = a[0], Y = a[1] };
            }

            //N(i)からN(i+1)のベクトルが事前に設定したベクトル(p,q)とどれだけ乖離していようが
            //別ベクトルならコストは1かかる（同じベクトルなら0かかる）
            //つまり各点から各点へのベクトルの分類し、一番多いベクトルを(p,q)とすれば最短コストとなる
            foreach (var q in xy) {
                foreach (var w in xy) {
                    if(q.Equals(w)) {
                        continue;
                    }

                    var aa = q.X - w.X;
                    var bb = q.Y - w.Y;

                    var d = new XY { X = aa, Y = bb };

                    if (dic.ContainsKey(d)) {
                        dic[d]++;
                    } else {
                        dic[d] = 1;
                    }
                }
            }

            var max = dic.Max(x => x.Value);

            var result = n - max;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13408
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

string S, T, U;
int A, B;
signed main(){
	cin >> S >> T >> A >> B >> U;
	if(S == U){
		cout << A-1 << " " << B << endl;
	}
	else{
		cout << A << " " << B-1 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    ll x=t1*a1-t1*b1;
    ll y=t2*a2-t2*b2;
    if(x+y==0) {
        cout<<"infinity"<<endl;
        return 0;
    }
    
    if(max(x,y)<=0 || min(x,y)>=0 || abs(x)>abs(y)) {
        cout<<0<<endl;
        return 0;
    }
    
    ll ans=(abs(x))/(abs(x+y))*2+1;
    ans-=((abs(x))%(abs(x+y))==0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  [n,a,b] <- map read . words <$> getLine 
  print $ f n a b

f :: Int -> Int -> Int -> Int
f n a b = sum [ m | m <- [1..n]
                  , a   <= g m
                  , g m <= b ]
  where
    g = sum . int2lst

int2lst :: Int -> [Int]
int2lst n
  | q == 0 = [r]
  | otherwise = r: int2lst q
  where
    (q,r) = quotRem n 10

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}
template <typename T> auto make_vector(int n, int m, int l, const T &value){return make_vector<vector<T>>(n, m, vector<T>(l, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;




int main(){
  string s;
  while(cin >> s){
    vector<int> N;
    N.push_back(0);
    for(auto x : s) N.push_back(x - '0');
    N.push_back(0);

    auto dp = make_vector<LLI>(N.size()+1, 2, INT_MAX);
    const int LOWER = 0;
    const int UPPER = 1;

    dp[0][0] = 0;

    REP(i,N.size()){
      const auto x = N[i];
      REP(j, 2){
        if(dp[i][j] == INT_MAX) continue;
      
        if(j == LOWER){
          chmin(dp[i+1][LOWER], dp[i][LOWER] + min(x, 1 + 10 - x));
          chmin(dp[i+1][UPPER], dp[i][LOWER] + min(x + 1, 1 + 10 - (x + 1)));
        }else{
          chmin(dp[i+1][LOWER], dp[i][UPPER] + min(10 - x, 1 + x));
          chmin(dp[i+1][UPPER], dp[i][UPPER] + min(10 - (x + 1), 1 + x + 1));
        }
      }

      dump(dp[i]);
    }

    dump(dp[N.size()]);
    
    int ans = dp[N.size()][LOWER];    


    puts_all(ans);
  }
  
  return 0;
}


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

int main() {
    int K; cin >> K;
    ll now = 0;
    ll now7 = 7;
    for (int i = 1; i <= 1000000; i++){
        now += now7;
        if(now % K == 0){
            cout << i << endl;
            return 0;
        }
        now %= K;
        now7 *= 10;
        now7 %= K;
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3620
import Data.List

main :: IO ()
main = do
  line1 : c_board <- return . lines =<< getContents
  let [h, w] = map read (words line1)
      board = map (map (== '#')) c_board
      blankRow = take w (repeat False)
      brdU = blankRow : init board
      brdD = tail board ++ [blankRow]
      brdR = map (\x -> False : init x) board
      brdL = map (\x -> tail x ++ [False]) board
      jdg = all f $ transpose (map concat [board, brdU, brdD, brdR, brdL])
  putStrLn (if jdg then "Yes" else "No")

  where f (x : bs) = not x || any id bs


Measured memory_bytes: 1276
using System;

class Bmondai
{
    static void Main()
    {
       var str = Console.ReadLine();
        const int num = 753;
        var length = str.Length - 2;
        var min = int.MaxValue;
        for (int i=0;i<length;++i) {
            var n = Int32.Parse(str.Substring(i, 3));
            var sa = Math.Abs(num - n);
            if (min > sa) min = sa;
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 11092
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x, y, z = [int(_) for _ in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

for j in range(n-1):
    t = 0
    for i in range(j, n-1):
        if t < s[i]:
            t = s[i]
        elif (t - s[i]) % f[i] != 0:
            t += f[i] - (t - s[i]) % f[i]
        t += c[i]
    print(t)
print(0)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int n,x,a,b,c,k;
    while(1){
        scanf("%d %d",&n,&x);
        if(n+x==0) break;
        k=0;
        for(a=1;a<=n;a++){
            for(b=a+1;b<=n;b++){
                for(c=b+1;c<=n;c++){
                if(a+b+c==x) 
                    k++;
                }
            }
        }
    printf("%d\n" ,k);
    }
    return 0;
}
        


Measured memory_bytes: 2044
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

long long gcd(long long a, long long b) {
    return b ? gcd(b, a%b) : a;
}

void solve() {
    int T;
    cin >> T;
    while (T--) {
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        auto res = [&] {
            if (A < B || D < B)RT 0;
            if (C >= B) RT 1;
            ll g = gcd(B, D);
            ll ma = B - g + A % g;
            if (ma > C) {
                RT 0;
            } else {
                RT 1;
            }
        }();
        cout << (res ? "Yes" : "No") << endl;
    }
	
}

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

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

using namespace std;

#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
  double x, y;
  Point() {};
  Point(double x, double y): x(x), y(y) {}

  Point operator + (const Point &p) { return Point(x + p.x, y + p.y); }
  Point operator - (const Point &p) { return Point(x - p.x, y - p.y); }
  Point operator * (double d) { return Point(d * x, d * y); }
  Point operator / (double d) { return Point(d / x, d / y); }

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

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

  friend ostream& operator << (ostream &os, Point &p) {
    return os << "Point(" << p.x << ", " << p.y << ")";
  }
};

struct Segment {
  Point p0, p1;
};

double cross (Point p1, Point p2) {
  return p1.x * p2.y - p1.y * p2.x;
}

double dot(Point p1, Point p2) {
  return p1.x * p2.x + p1.y * p2.y;
}

double norm(Point p) {
  return p.x * p.x + p.y * p.y;
}

int ccw(Segment s, Point p2) {
  if (cross(s.p1 - s.p0, p2 - s.p0) > EPS) return -1;
  if (cross(s.p1 - s.p0, p2 - s.p0) < -EPS) return 1;
  if (dot(s.p1 - s.p0, p2 - s.p0) < -EPS) return 2;
  if (norm(s.p1 - s.p0) < norm(p2 - s.p0)) return 4;
  return 0;
}

void debug(Segment s0, Segment s1) {
  cout << ccw(s0, s1.p0) << ' '
       << ccw(s0, s1.p1) << ' '
       << ccw(s1, s0.p0) << ' '
       << ccw(s1, s0.p1) << endl;
  cout << ccw(s0, s1.p0) * ccw(s0, s1.p1) << ' '
       << ccw(s1, s0.p0) * ccw(s1, s0.p1) << endl;
}

bool intersect(Segment s0, Segment s1) {
//  debug(s0, s1);

  if (
      (ccw(s0, s1.p0) * ccw(s0, s1.p1) <= 0 &&
       ccw(s1, s0.p0) * ccw(s1, s0.p1) <= 0
       ) ||
      ccw(s0, s1.p0) * ccw(s0, s1.p1) == 8 ||
      ccw(s1, s0.p0) * ccw(s1, s0.p1) == 8
      )
    return true;

  return false;
}

int main() {
  int xs[4];
  int ys[4];
  Segment ss[2];

  int q; cin >> q;

  while (q--) {
    for (int i = 0; i < 4; i++) {
      cin >> xs[i];
      cin >> ys[i];
    }

    Segment s0;
    s0.p0 = Point(xs[0], ys[0]);
    s0.p1 = Point(xs[1], ys[1]);

    Segment s1;
    s1.p0 = Point(xs[2], ys[2]);
    s1.p1 = Point(xs[3], ys[3]);

    cout << intersect(s0, s1) << endl;
  }
}

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

#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 fore(i,l,r) for(int i = (int)l; i <= (int)r; i++)
#define ford(i,n) for(int i = (int)n; i >= 0; i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define LOG(x) std::cout << x << "\n"
using namespace std;

typedef long long int i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vii;
typedef vector<vi64> vii64;
typedef double ld;
template <typename T> T max3 (T num1, T num2, T num3) {return max(num1, max(num2,num3)); }
template <typename T> T min3 (T num1, T num2, T num3) {return min(num1, min(num2,num3)); }

struct Item
{
	i64 weight;
	i64 profit;
};
int N, W;
i64 dp[101][(int)1e5 + 1];
i64 sol(vector<Item> items, int W, int N)
{
	for (int i = 0 ; i <= N ; i++) dp[i][0] = 0;
	for (int i = 0 ; i <= W ; i++) dp[0][i] = 0;
	for (int i = 1 ; i <= N ; i++) 
	{
		for (int j = 1 ; j <= W ; j++) 
		{
			if (items[i-1].weight > j) dp[i][j] = dp[i-1][j];
			if (items[i-1].weight <= j) dp[i][j] = max(items[i-1].profit + dp[i-1][j - items[i-1].weight],dp[i-1][j]);	
		}
	}
	return dp[N][W];
}

int main()                             
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> W;
	vector<Item> items(N);
	for (int i = 0 ; i < N ; i++) 
	{
		cin >> items[i].weight >> items[i].profit; 
	}
	cout << sol(items,W,N) << "\n";
	return 0;
}

Measured memory_bytes: 79232
#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;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e7+5;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int spf[MAX];
void sieve()
{
    spf[1]=1;
    //marking smallest prime factor for every number
    for(int i=2; i<MAX; i+=2)
        spf[i]=2;
    for(int i=3; i<MAX; i+=2)
        spf[i]=i;
    int root=sqrt(MAX);
    for(int i=3; i<=root; i+=2)
    {
        if(spf[i]==i)
        {
            for(int j=i*i; j<MAX; j+=i)
            {
                // marking spf[j] if it is not previously marked
                if(spf[j]==j)
                    spf[j]=i;
            }
        }
    }
}
ll primefactors(int n)
{
    ll last=-1,cnt=0,ans=1;
    while(n!=1)
    {
        int cur=spf[n];
        if(last==-1)
        {
            last=cur;
            cnt++;
        }
        else if(last==cur)
            cnt++;
        else
        {
            ans*=(cnt+1);
            last=cur;
            cnt=1;
        }
        n/=spf[n];
    }
    ans*=(cnt+1);
    return ans;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    sieve();
    int n;
    cin>>n;
    ll sum=0;
    for(ll i=1; i<=n; i++)
    {
        ll cur=primefactors(i);
        sum+=cur*i;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 42704
#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
#define INPUT freopen("travel_restrictions_validation_input.txt", "r", stdin);
using namespace std;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int main(){SLAY
	int _=1 , tc=1;
	// cin>>_;
	while(_--){
		ll n=0,a,b,c;
		string str , str2;
		cin>>str>>str2;
		for(int i = 0 ; i < str.length(); i++){
			if(str[i]!=str2[i])n++;
		}
		cout<<n;
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define llong long long


int main(){
    llong a, b, x;
    llong ans;
    cin >> a >> b >> x;

    if(a != 0)
        ans = (b / x) - ((a - 1) / x);
    else
        ans = b / x + 1;
    cout << ans << endl;

    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),L=in();
	vector<pair<int,int>> P(N);
	REP(i,N){
		P[i].first = abs(L+i);
		P[i].second = L+i;
	}
	sort(ALL(P),[](pair<int,int>& l,pair<int,int>& r){return l.first<r.first;});
	int sum = 0;
	for(int i=1;i<N;i++){
		sum += P[i].second;
	}

	cout << sum << endl;
	return 0;
}


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

int N,M;
vector<int>G[100000];
bool used[100000];

bool dfs(int v,int p){
    used[v]=true;
    bool ret=true;

    for(int i=0;i<G[v].size();i++){
        int to=G[v][i];
        if(to==p)continue;
        if(used[to])return false;
        ret&=dfs(to,v);
    }
    return ret;
}

int main(){
    while(cin>>N>>M,N||M){
        fill_n(G,N,vector<int>());
        for(int i=0;i<M;i++){
            int a,b;cin>>a>>b;
            a--;b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        if(M>=N){
            cout<<"no"<<endl;
            continue;
        }
        fill_n(used,N,false);
        bool ret=true;

        for(int i=0;i<N;i++){
            if(G[i].size()>2)ret=false;
            if(G[i].size()>=2)continue;
            if(used[i])continue;
            ret&=dfs(i,-1);
        }

        for(int i=0;i<N;i++)if(!used[i])ret=false;
        if(ret)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){
  int N, M, X, Y;
  vector<int> vx;
  vector<int> vy;
  cin >> N >> M >> X >> Y;
  for(int i=0; i<N; i++){
    int x; cin >> x;
    vx.push_back(x);
  }
  vx.push_back(X);
  for(int i=0; i<M; i++){
    int y; cin >> y;
    vy.push_back(y);
  }
  vy.push_back(Y);
  sort(vx.begin(), vx.end(),greater<int>());
  sort(vy.begin(), vy.end());
  if(vx[0]+1>vy[0]){
    cout << "War" << endl;
    return 0;
  }
  cout << "No War" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a = sorted(a)[::-1]

ans = a[0]
for i in range(1, n - 1):
    ans += a[(i + 1) // 2]
    # print(a[(i + 1) // 2], (i + 1) // 2)

print(ans)

Measured memory_bytes: 31436
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int minv = 1000000;
    for (int i = 0; i < N; i++) {
        int count = 0;
        while (A[i] % 2 == 0) {
            A[i] /= 2;
            count++;
        }
        minv = min(minv, count);
    }

    cout << minv << endl;
    
    return 0;
}

Measured memory_bytes: 256