akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;
  cin >> H >> W;
  string S[H+2];
  REP(i,W+2){
    S[0] += '#';
    S[H+1] += '#';
  }

  REP(i,H){
    cin >> S[i+1];
    S[i+1] = '#'+S[i+1]+'#';
  }

  int li[H+2][W+2][2];

  int cnt_w=1,cnt_h=1,ans = 0;
  map<int,int> di_w,di_h;

  for(int h=0;h<H+2;h++){
    for(int w=0;w<W+2;w++){
      if(S[h][w]=='#'){
        li[h][w][0]=-1;
        li[h][w][1]=-1;
        cnt_h++;
        cnt_w++;
      }else{
        if(li[h-1][w][0]==-1){
          li[h][w][0] = cnt_h;
          di_h[cnt_h] = 1;
        }else{
          li[h][w][0] = li[h-1][w][0];
          di_h[li[h][w][0]]++;
        }
        if(li[h][w-1][1]==-1){
          li[h][w][1] = cnt_w;
          di_w[cnt_w] = 1;
        }else{
          li[h][w][1] = li[h][w-1][1];
          di_w[li[h][w][1]]++;
        }
      }
      cnt_h++;
    }
  }

  for(int h=0;h<H+2;h++){
    for (int w=0; w<W+2; w++) {
      if(S[h][w]!='#'){
        ans = max(ans,di_h[li[h][w][0]]+di_w[li[h][w][1]]-1);
      }
    }
  }
  cout<<ans<<'\n';

  return 0;
}


Measured memory_bytes: 124416
#include <stdio.h>

int main(void)
{
	int x[10000],y[10000];
	int i=0;
	int howmany;
	
	for(i=0;i<10000;i++)
	{
		scanf("%d %d",&x[i],&y[i]);
		if(x[i] == 0 && y[i] == 0)
		{
			howmany = i;
			
			goto next;
		}
	}
	
	next:
	
	for(i=0;i<howmany;i++)
	{
		if(x[i] >= y[i])
		{
			printf("%d %d",y[i],x[i]);
		}
		else
		{
			printf("%d %d",x[i],y[i]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
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 long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    string s; cin>>s;
    if(s == "Sunny") cout<<"Cloudy"<<endl;
    else if(s == "Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll N,M;
  cin>>N>>M;
  ll b=1,e=N;
  FORi(M){
    ll L,R;
    cin>>L>>R;
    if(b<L)b=L;
    if(e>R)e=R;
  }
  cout<<max(0ll,e-b+1)<<endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int x, a;
    cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	if (x - r<0 || x + r>w || y - r<0 || y + r>h)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ll long long int
#define F first
#define S second
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define REP(i,a,n) for(i=a;i<(n);i+=1)
#define REPL(i,a,n) for(i=(a);i<=(n);i+=1)
#define REPr(i,a,n) for(i=(n);i>=(a);i-=1)

typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int>::iterator sit;
typedef unordered_set<int>::iterator usit;
typedef multiset<int>::iterator msit;
typedef unordered_multiset<int>::iterator umsit;
typedef vector<ll>::iterator vllit;

//cin.ignore(numeric_limits<streamsize>::max(),'\n');

ll MAX3(ll x, ll y, ll z){
    ll temp = max(x,y);
    return max(temp,z);
}

const ll W = 1000000001;
// vll dp(W);
// vector<pair<ll, ll>> items;

/*void solve(){
    int i,k,x;
    REPL(i,0,w) {
        dp[i]=0;
    }
    ll max_with_curr;
    REPL(k,1,n){
        max_with_curr=0;
        REPr(x,1,n){
            if(x-items[k].F >=0){
                max_with_curr= items[k].S + dp[x-items[k].F];
            }
            dp[x] = max(dp[x], max_with_curr);
        }
    }
        
}*/

//int dp[1000000001];


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, W;
    cin>>n>>W;

    vll weight, value;
    ll w,v,i;

    REP(i,0,n){
        cin>>w>>v;
        weight.PB(w);
        value.PB(v);
    }

    vll dp(W+1, 0);
    REPL(i,0,W){
        dp[i]=0;
    }

    int k,x;
    REP(k,0,n){
        REPr(x,1,W){
            ll max_without_curr = dp[x];
            ll max_with_curr = 0;

            if(x-weight[k]>=0){
                max_with_curr = value[k] + dp[x-weight[k]];
            }

            dp[x] = max(max_with_curr, max_without_curr);
        }
    }
    
    cout<<dp[W]<<endl;
    return 0;
}

Measured memory_bytes: 1024
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = int(1e9 + 7)

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := getInts(N)

	if N == K {
		ans := 1
		for i := 0; i < K; i++ {
			ans *= a[i]
			ans %= mod
			if ans < 0 {
				ans += mod
			}
		}
		out(ans)
		return
	}

	plus := make([]int, 0)
	minus := make([]int, 0)
	for i := 0; i < N; i++ {
		if a[i] >= 0 {
			plus = append(plus, a[i])
		} else {
			minus = append(minus, -a[i])
		}
	}
	// out(K, N)
	// out(len(plus), len(minus))

	sort.Sort(sort.Reverse(sort.IntSlice(plus)))
	sort.Sort(sort.Reverse(sort.IntSlice(minus)))

	if len(minus) == N && K%2 == 1 {
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		ans := 1
		for i := 0; i < K; i++ {
			ans *= a[i]
			ans %= mod
			if ans < 0 {
				ans += mod
			}
		}
		out(ans)
		return
	}

	posP := 0
	posM := 0
	for i := 0; i < K; i++ {
		if len(plus) == posP {
			posM++
			continue
		}
		if len(minus) == posM {
			posP++
			continue
		}
		if plus[posP] >= minus[posM] {
			posP++
		} else {
			posM++
		}
	}

	// out(K, N)
	// out(plus)
	// out(len(plus), len(minus))
	// out(posP, posM)

	if posM%2 == 1 {
		if len(minus) == posM {
			posM--
			posP++
		} else if len(plus) == posP {
			posP--
			posM++
		} else {
			if posP == 0 {
				posP++
				posM--
			} else {
				if minus[posM-1]*minus[posM] > plus[posP-1]*plus[posP] {
					posM++
					posP--
				} else {
					posM--
					posP++
				}
			}
		}
	}

	// out(posP, posM)

	ans := 1
	for i := 0; i < posP; i++ {
		ans *= plus[i]
		ans %= mod
	}
	for i := 0; i < posM; i++ {
		ans *= -minus[i]
		ans %= mod
		if ans < 0 {
			ans += mod
		}
	}
	out(ans)
}


Measured memory_bytes: 9860
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL MOD=10e8+7;
int N,M;
LL l[401];
LL r[401];
LL x[401];
typedef pair<int,int> P;
vector<P>v;
LL dp[401][401];
LL dp2[401][401];
int main(){
    cin>>N>>M;
    REP(i,M){
        cin>>l[i]>>r[i]>>x[i];
        v.push_back(make_pair(r[i],i));
    }
    sort(v.begin(),v.end());
    REP(i,301){
        REP(j,301){
            dp[i][j]=0;
            dp2[i][j]=0;
        }
    }
    int count=0;
    while(v.size()>count&&v[count].first==1){
       if(x[v[count].second]!=1){
          cout<<0<<endl;
          return 0;
       }
       count++;
    }
    dp[0][0]=3;
    dp2[0][0]=3;
    for(int i=2;i<=N;i++){
        //iとi-1が同じ場合はすでに加算済み
        //iとi-1が違う場合
        REP(j,301){
            REP(k,301){
                dp2[i-1][j]+=dp[j][k];//kの方の色を入れた
                dp2[i-1][k]+=dp[j][k];//jの方の色を入れた
            }
        }
        //条件の確認
        while(v.size()>count&&v[count].first==i){
           //cout<<"aa"<<endl;
           int num=v[count].second;
           //1色
           if(x[num]==1){
              REP(j,301){
                  REP(k,301){
                      if(l[num]<=j|| l[num]<=k){
                         dp2[j][k]=0;
                      }
                  }
              }
           }
           if(x[num]==2){
              REP(j,301){
                  REP(k,301){
                      if(l[num]>j&& l[num]>k){
                         dp2[j][k]=0;
                      }
                      if(l[num]<=j&& l[num]<=k){
                         dp2[j][k]=0;
                      }
                  }
              }
           }
           if(x[num]==3){
              REP(j,301){
                  REP(k,301){
                      //cout<<"aaaaa"<<l[num]<<" "<<j<<" "<<k<<endl;
                      if((l[num]>j)|| (l[num]>k)){
                      //cout<<"bb"<<endl;
                         dp2[j][k]=0;
                      }
                  }
              }
           }
           count++;
        }
    
        REP(j,301){
            REP(k,301){
                dp2[j][k]=dp2[j][k]%MOD;
                dp[j][k]=dp2[j][k];
            }
        }
        
        /*
        REP(j,5){
            REP(k,5){
               //cout<<j<<" "<<k<<"dp"<<dp[j][k]<<endl;
            }
        }
        cout<<endl;
        */
    }
    
    LL ans=0;
    
    REP(i,301){
        REP(j,301){
            if(i==0&&j==0){
               ans+=dp[i][j];
            }else{
               ans+=dp[i][j];
            }
            ans=ans%MOD;
        }
    }
    //cout<<MOD<<endl;
    cout<<ans%MOD<<endl;
    return(0);
}

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


int main() {
  int n,m;
  cin>>n>>m;
  if(n>1&&m>1)cout<<n*(n-1)/2+m*(m-1)/2;
  if(n<=1)cout<<m*(m-1)/2;
  if(m<=1&&n>1)cout<<n*(n-1)/2;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int a, b;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	cout << (a+b)%24 << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import heapq

    n, m, s = map(int, input().split())
    if s >= 2500:
        s = 2499

    edges = [[] for _ in range(n)]
    for _ in range(m):
        from_, to, cost, time = map(int, input().split())
        edges[from_-1].append((to-1, cost, time))
        edges[to-1].append((from_-1, cost, time))

    banks = []
    for i in range(n):
        coin, time = map(int, input().split())
        banks.append((coin, time))

    INF = float('INF')
    DP = [[INF] * 2500 for _ in range(n)]
    DP[0][s] = 0
    ans = [INF] * n

    def push_todo(node, coin, time):
        if coin < 0:
            return
        if time >= DP[node][coin]:
            return
        heapq.heappush(todo, (time, node, coin))
        DP[node][coin] = time

    def charge(node, current_coin, current_time):
        coin, time = banks[node]
        new_coin = current_coin + coin
        if new_coin >= 2500:
            new_coin = 2499
        push_todo(node, new_coin, current_time+time)

    todo = [(0, 0, s)]  # time, node, coin
    while todo:
        current_time, node, current_coin = heapq.heappop(todo)
        if current_time > DP[node][current_coin]:
            continue

        if current_time < ans[node]:
            ans[node] = current_time

        charge(node, current_coin, current_time)

        for to, cost, time in edges[node]:
            push_todo(to, current_coin-cost, current_time+time)

    for a in ans[1:]:
        print(a)


if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

struct edge{int to; ll cost;};

int main()
{
  int n; cin >> n;
  vector<vector<edge>> g(n+1);
  rep(i, n-1) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    edge x = {b, c};
    edge y = {a, c};
    g[a].push_back(x);
    g[b].push_back(y);
  }
  int q, k; cin >> q >> k;
  vector<int> x(q), y(q);
  rep(i, q) cin >> x[i] >> y[i];
  vector<ll> dist(n+1, INF64);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;

  dist[k] = 0;
  pq.push(make_pair(0ll, k));
  while(!pq.empty()) {
    auto p = pq.top(); pq.pop();
    int u = p.second;
    if(dist[u] < p.first) continue;
    for(auto next : g[u]) {
      int v = next.to;
      if(chmin(dist[v], dist[u]+next.cost)) pq.push(make_pair(dist[v], v));
    }
  }
  rep(i, q) {
    cout << dist[x[i]] + dist[y[i]] << endl;
  }
}


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

const ll mod = 1e9;

int main(){
    int n;
    cin >> n;
    map<int,int> a;
    ll x;
    rep(i,n){
        cin >> x;
        a[x]++;
    }
    int ans = 0;
    for (auto x:a){
        if (a[x.first]%2!=0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 18 12:05:59 2019

@author: ctiuser
"""
import sys
sys.setrecursionlimit(10**6)

N, M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(M)]

if M % 2 == 1:
    print(-1)
    sys.exit()

class UnionFind():
    def __init__(self,size):
        self.table = [-1 for i in range(size+1)]
    def find(self,x):
        if self.table[x] < 0:
            return x
        else:
            return self.find(self.table[x])
    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return False
        if self.table[s1] < self.table[s2]:
            self.table[s1] = self.table[s1] + self.table[s2]
            self.table[s2] = self.find(x)
        else:
            self.table[s2] = self.table[s1] + self.table[s2]
            self.table[s1] = self.find(y)
        return True

UF = UnionFind(N)
ans = []
T = [[-1] for i in range(N+1)]
color = [-1 for i in range(N+1)]
counta = [0 for i in range(N+1)]
B = []
C = [[] for i in range(N+1)]
for c in A:
    if UF.union(c[0],c[1]):
        B.append(c)
        C[c[0]].append(c[1])
        C[c[1]].append(c[0])
    else:
        ans.append(c)
        counta[c[0]] += 1

def b(x):
    color[x] = 1
    for c in C[x]:
        if color[c] == -1:
            T[c][0] = x
            T[x].append(c)
            b(c)
b(1)

edge_leaf = []
for i in range(1,N+1):
    if len(T[i]) == 1:
        edge_leaf.append(i)

def a(x):
    p = T[x][0]
    if p == -1:
        return 0
    if counta[x] % 2 == 0:
        ans.append([p,x])
        counta[p] += 1
    else:
        ans.append([x,p])
    return p

for c in edge_leaf:
    point = c
    while color[point] == len(T[point]):
        point = a(point)
        color[point] += 1


for c in ans:
    print(' '.join(map(str,c)))


Measured memory_bytes: 124392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;
	cin >> x >> y >> m;
	cout<<m<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#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;

const int D=365;
int csum;
int c[26];
int s[D][26];
int last[26];

set<int>se[26];

int ans[D];

int cur_score;

int score(){
	memset(last,-1,sizeof(last));
	int sum=0;
	int diff=0;
	rep(i,D){
		sum+=s[i][ans[i]];
		diff+=csum;
		diff-=(i-last[ans[i]])*c[ans[i]];
		sum-=diff;
		last[ans[i]]=i;
	}
	cur_score=sum;
	return sum;
}

inline int SUM(int b,int n){
	return (b*(n-1))*n/2;
}
int update(int pos,int d){
	int x=ans[pos];
	auto it=se[x].find(pos);
	int diff=0;
	diff-=s[pos][x];
	diff+=s[pos][d];

	int prv=*prev(it),nx=*next(it);
	diff+=SUM(c[x],pos-prv);
	diff+=SUM(c[x],nx-pos);
	diff-=SUM(c[x],nx-prv);

	it=se[d].lower_bound(pos);
	prv=*prev(it),nx=*it;
	diff+=SUM(c[d],nx-prv);
	diff-=SUM(c[d],pos-prv);
	diff-=SUM(c[d],nx-pos);

	cur_score+=diff;
	return cur_score;
}

int main(){
	rep(i,26){
		se[i].insert(-1);
		se[i].insert(D);
	}
	scanf("%*d");
	rep(i,26)scanf("%d",&c[i]),csum+=c[i];
	rep(i,D)rep(j,26)scanf("%d",&s[i][j]);
	rep(i,D){
		ans[i]=max_element(s[i],s[i]+26)-s[i];
		se[ans[i]].insert(i);
	}
	random_device rnd;
	mt19937 mt(rnd());
	uniform_real_distribution<double>Real(0,1);
	int Max=score();
	double stmp=10000,etmp=0;
	int upd=0;
	int LOOP=8000000;
	rep(loop,LOOP){
		int pos=mt()%D;
		int sum=0;
		rep(i,26)sum+=s[pos][i];
		int ch,d=-1;
		do{
			ch=mt()%sum;
			rep(i,26){
				ch-=s[pos][i];
				if(ch<0){d=i;break;}
			}
		}while(d==ans[pos]);
		int old=ans[pos],old_score=cur_score;
		int nx=update(pos,d);
		double tmp=stmp+(etmp-stmp)/LOOP*loop;
		double p=exp(-double(abs(Max-nx))/tmp);
		if(Max<nx||Real(mt)<p){
			se[old].erase(pos);
			se[d].insert(pos);
			ans[pos]=d;
			Max=nx;upd++;
		}
		else{
			cur_score=old_score;
		}
	}
	cerr<<upd<<endl;
	rep(i,D){
		cout<<ans[i]+1<<endl;
	}
	cerr<<"score: "<<Max<<' '<<score()<<endl;
}

Measured memory_bytes: 4364
class UnionFind:
    """素集合を木構造として管理する"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.cnt = n

    def root(self, x):
        """頂点xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """頂点xを含む集合と頂点y含む集合を結合する"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1

    def is_same(self, x, y):
        """頂点xと頂点yが同じ集合に属するかどうかを返す"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        """頂点xを含む集合の要素数を返す"""
        return -self.parent[self.root(x)]

    def get_cnt(self):
        """集合の個数を返す"""
        return self.cnt

import sys
input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]

info2 = [list(map(int, input().split())) for i in range(k)]


graph = [[] for i in range(n)]
uf = UnionFind(n)
for i in range(m):
    a, b = info[i]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    uf.merge(a, b)

graph2 = [[] for i in range(n)]
for i in range(k):
    a, b = info2[i]
    a -= 1
    b -= 1
    if uf.is_same(a, b):
        graph2[a].append(b)
        graph2[b].append(a)

ans = [0] * n
for i in range(n):
    ans[i] = uf.get_size(i) - len(graph[i]) - 1 - len(graph2[i])
print(*ans)

Measured memory_bytes: 131420
#include<cstdio>
#include<algorithm>
using namespace std;
int n, m;
long long Mod = 1000000007, D[401000], S[401000];
char p[301000];
long long DD[401000][2][2];
int main() {
	int i, j;
	scanf("%d%d", &n, &m);
	scanf("%s", p);
	int ck = 0;
	for (i = 0; p[i]; i++) {
		if (p[i] == 'R')ck |= 1;
		if (p[i] == 'B')ck |= 2;
	}
	if (ck!=3) {
		DD[1][0][0] = 1;
		DD[1][1][1] = 1;
		for (i = 2; i <= n; i++) {
			DD[i][0][0] = (DD[i - 1][0][0] + DD[i - 1][0][1]) % Mod;
			DD[i][0][1] = (DD[i - 1][0][0]) % Mod;
			DD[i][1][0] = (DD[i - 1][1][0] + DD[i - 1][1][1]) % Mod;
			DD[i][1][1] = (DD[i - 1][1][0]) % Mod;
		}
		printf("%lld\n", (DD[n][0][0] + DD[n][0][1] + DD[n][1][0]) % Mod);
		return 0;
	}
	if (n % 2 == 1) {
		puts("0");
		return 0;
	}
	if (p[0] == 'B') {
		for (i = 0; i < m; i++) {
			p[i] = 'R' + 'B' - p[i];
		}
	}
	int c = 0, Mn = 1e9;
	ck = 0;
	for (i = 0; i < m; i++) {
		if (p[i] == 'R') {
			c++;
			if (p[i + 1] == 'B') {
				if (!ck) {
					if (c % 2 == 0)Mn = min(Mn, c + 1);
					else Mn = min(Mn, c);
				}
				else {
					if (c % 2 == 1)Mn = min(Mn, c);
				}
				ck = 1;
			}
		}
		else c = 0;
	}

	int K = (Mn + 1) / 2;
	D[0] = 1;
	S[0] = 1;
	for (i = 1; i <= n; i++) {
		long long t = S[i - 1];
		if (i - K - 1 >= 0)t -= S[i - K - 1];
		D[i] = (t + Mod) % Mod;
		S[i] = (S[i - 1] + D[i]) % Mod;
	}
	long long res = D[n / 2];
	for (i = 1; i <= Mn && i<=n; i+=2) {
		res = (res + 1ll*i*D[(n - i - 1) / 2])%Mod;
	}
	printf("%lld\n", res);

}

Measured memory_bytes: 10368
#include <stdio.h>

int n, k;

int main(){
  int i, min;
  scanf("%d%d", &n, &k);
  printf("%d\n", 1 + (n-k+k-2)/(k-1));
/*
  for(i=0;i<n;i++){
    int z;
    scanf("%d", &z);
    if(z == 1) min = i;
  }
//  printf("%d\n", (min-1+k-2)/(k-1) + (n-min-1+k-2)/(k-1));
*/
  return 0;
}


Measured memory_bytes: 128
n = int(input())
values =list(map(int, input().split()))
a=1
t = 10**18
for i in range(n):
  if values[i] == 0:
    a = 0
    break
  if a > t:
    continue
  else:
    a=a*values[i]
 
if a <= t:
  print(a)
else:
  print(-1)

Measured memory_bytes: 21580
#include <bits/stdc++.h>
#include <string.h>
#include <math.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359

int main(void)
{
	int a,b,c;
	double h,rad,s,l;

	cin >> a >> b >> c;

	rad = c * PI / 180.0;
	h = b * sin(rad);
	s = 0.5 * a * h;
	l = a + b + sqrt(a * a + b * b - 2.0 * a * b * cos(rad));
	cout << fixed << setprecision(10) << s << endl;
	cout << fixed << setprecision(10) << l << endl;
	cout << fixed << setprecision(10) << h << endl;
}



Measured memory_bytes: 3480
#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i<n?0:1][i-(i<n?0:n)];fill(p[1],p[1<<n],1e9);;R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)p[B|1<<i][k]=min(p[B|1<<i][k],p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

Measured memory_bytes: 52480
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100001;
int a[maxn][3],dp[maxn][3];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}

   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   return 0;
}
	

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

#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------


int n,arr[50];
void solve()
{
	cin>>n;rep(i,1,n+1)cin>>arr[i];

	int ans=0;
	rep(i,2,n)
	{
		vi temp=vi({arr[i],arr[i-1],arr[i+1]});sort(all(temp));
		if (temp[1]==arr[i])ans++;
	}
	cout<<ans;

}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    clock_t qwertyuiop = clock();
    #endif


    int t=1;
    //cin>>t;
    
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


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

//mintを使って定義すれば、modを常に取り続けてくれる。

const int mod = 1000000007;
struct mint {
    ll x; //typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        //tが0なら1を返す
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    //逆元を求める、mod-2乗
    mint inv() const {
        return pow(mod-2);
    }
    //逆元をかける
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint f(int n) {
    if (n == 0)  return 1;
    mint x = f(n/2);
    x *= x;
    if (n%2 == 1) x *= 2;
    return x;
}

mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

ll sum(ll l,ll r) {
    return (l+r)*(r-l+1)/2;
}

int main(){
    int n, k;
    cin >> n >> k;
    mint ans = 0;
    for(int i = k; i <= n+1; ++i){
        ll l = sum(0,i-1); ll r = sum(n-i+1,n);
        ans += r-l+1;
    }
    cout << ans.x << "\n";
    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, ac, wa, tle, re int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		switch scanner.Text() {
		case "AC":
			ac++
		case "WA":
			wa++
		case "TLE":
			tle++
		default:
			re++
		}
	}

	fmt.Println("AC x", ac)
	fmt.Println("WA x", wa)
	fmt.Println("TLE x", tle)
	fmt.Println("RE x", re)
}


Measured memory_bytes: 1848
def main():
    o, e = input(), input()
    ans = ""

    for i in range(len(o) + len(e)):
        if i % 2 == 0:
            ans += o[i // 2]
        else:
            ans += e[i // 2]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61968
#include <stdio.h>
int main(void){
    int n,ans=0,flag;
    scanf("%d",&n);
    int h[n];
    for(int i=0; i<n; i++){
        scanf("%d",&h[i]);
        flag=0;
        for(int j=0; j<i; j++){
            if(h[j]>h[i])
                flag=1;
        }
        if(flag==0)
            ans++;
    }
    printf("%d",ans);
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
 
using namespace std;
 
ll tc, cnt = 0, number, many, total = 0;
int rmove[4] = {0, 0, -1, 1};
int cmove[4] = {1, -1, 0, 0};



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test

    cin >> number >> many;

    bool arr[105];
    memset(arr, false, sizeof(arr));
    for(int i = 0; i < many; i++)
    {
        int temp;
        cin >> temp;
        arr[temp] = true;
    }

    int answer = -1e9, left = number, right = number;
    for(int i = 0; answer == -1e9; i++)
    {
        // cout << left << " " << right << endl;

        if(arr[left - i] == false)
        {
            answer = left - i;
            break;
        }
        else if(arr[right + i] == false)
        {
            answer = right + i;
            break;
        }
    }

    cout << answer << endl;
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main (void) {
  int i, n, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++){
    x = i;
    if ( x % 3 == 0) printf(" %d",i);
    else {
      while (x != 0){
	if (x % 10 == 3){printf(" %d",i);
	  break;}
	else x = x / 10;
      }
    }
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){

	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d\n", (n - 1) * (m - 1));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
//解答写し
int main() {
  string s;
  cin >> s;
  int n=s.size();
  int p=2019;
  if (10%p == 0) { // 2,5
    long long ans = 0;
    rep(r,n) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
 
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  long long ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4448
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)
#define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

int rand16() {
    return rand() & (TWO(16) - 1);
}
int my_rand() {
    return rand16() << 15 | rand16();
}

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9) << boolalpha;
    int a, b, c;
    while (cin >> a >> b >> c) {
        int res = 0;
        while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
            ++res;
            if (res > 1000111) {
                break;
            }
            int x = b / 2 + c / 2;
            int y = a / 2 + c / 2;
            int z = a / 2 + b / 2;

            a = x;
            b = y;
            c = z;
        }
        if (res > 1000111) cout << -1 << endl;
        else cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
// #include <numeric>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
#define endl '\n'

void solve(){
    int n;
    cin >> n;
    int ac_count = 0 , wa_count = 0 , tle_count = 0 , re_count = 0 ;
    string a;
    f( i , 0 , n){
        cin >> a;
        if (a == "AC")
        ac_count++;
        else if (a== "WA")
        wa_count++;
        else if (a == "TLE")
        tle_count++;
        else
        re_count++;
    }
    cout << "AC" << " x " << ac_count << endl;
    cout << "WA" << " x " << wa_count << endl;
    cout << "TLE" << " x " << tle_count << endl;
    cout << "RE" << " x " << re_count << endl;

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int t = 1;
    // cin >> t;
    
    while(t--){    
        solve();
    }
}

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

using namespace std;

static const double EPS = 1e-10;

struct Point{
    double x,y;
    Point(double x, double y): x(x), y(y) {}
    Point operator + (Point p) const { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) const { return Point(x-p.x, y-p.y); }
    double norm() const { return x*x + y*y; }
    double abs() const { return sqrt(norm()); }
    double dot(Point p) const { return x*p.x + y*p.y; }
};

typedef Point Vector;

double cosine(Vector u, Vector v){
    return u.dot(v) / u.abs() / v.abs();
}

int main(){
    int n;
    cin >> n;
    double x[8];
    for(int i=0;i<n;i++){
        for(int j=0;j<8;j++) cin >> x[j];
        double cos_ = cosine(Point(x[2], x[3]) - Point(x[0], x[1]), Point(x[6], x[7]) - Point(x[4], x[5]));
        if(fabsl(cos_) < EPS){
            cout << 1 << endl;
        }else if(fabsl(cos_ - 1) < EPS || fabsl(cos_ + 1) < EPS){
            cout << 2 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3224
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
  int A,B,C,D;
    int x;
    cin >> x;
    A=x/1000;
    x=x%1000;

    B=x/100;
    x=x%100;

    C=x/10;
    x=x%10;

    D=x;

    int k[4];
    k[1] = B;
    k[2] = C;
    k[3] = D;
    int ans = A;

    string s[10];
    //8通り全て試してみる
 for(int bit = 0; bit < (1 << 3); ++bit){//x<<n でX*(2^n)
        for(int i =0 ; i<3;i++){
            if(bit & (1<<i)){//＆演算子
                ans +=k[i+1];
                s[bit] += '+';
            }else{
                ans -=k[i+1];
                s[bit] += '-';
            }
        }
            if(ans == 7){
            cout << A << s[bit][0] << B << s[bit][1] << C << s[bit][2] << D << "=7" <<endl;
            return 0;
            }
 
            ans = A;
    }

 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    b *= 2;
    if(a-b <= 0)cout<<0<<endl;
    else{
    cout << abs(a-b) << endl;
    }
}


Measured memory_bytes: 256
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMOD = 998244353;

if __name__ == "__main__":
    # sys.stdin = open("input.txt","r")  # <<<  ^o^  Comment this line  ^_^  >>>
    n = int(input())
    lia = []
    lib = []
    for i in range(n):
        a, b = get_ints()
        lia.append(a)
        lib.append(b)
    lia.sort()
    lib.sort()
    if n % 2 == 0:
        ind1 = n//2 - 1
        ind2 = n//2
        m1 = (lia[ind1] + lia[ind2]) / 2
        m2 = (lib[ind1] + lib[ind2]) / 2
        print(int((m2 - m1)*2 + 1))
    else:
        ind = ((n+1)//2) - 1
        m1 = lia[ind]
        m2 = lib[ind]
        print(m2-m1+1)
# #############################################################################
'''
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
>>> DO NOT PLAGIARISE.
TESTCASES:
'''

Measured memory_bytes: 92256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    int n, k;
    cin >> n >> k;
    n -= 2;

    int ans = 0;
    int x = 4;
    REP(i,5){
        int m = n;
        int y = x;
        while (y != k) {
            y = (y+8) % 11;
            m--;
        }
        m--;
        if (m >= 0) ans += 1 + m / 11;

        x = (x+9) % 11;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int X = in(),A = in(),B = in();
    cout << (B <= A ? "delicious" : (B <= A + X ? "safe" : "dangerous")) << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;;
using ll = long long;

int main() {

	int N,M;
	cin >> N >> M;

	vector<int> C(N, 0);
	vector<int> flag(N, 0);
	vector<int> flag2(N, 0);
	C[0] = 1;

	rep(i, M) {
		int x;
		cin >> x;
		cin >> C[x - 1];
		if (flag[x - 1] == 1) { if (C[x - 1] != flag2[x - 1]) {
				cout << -1 << endl;
				return 0;
			} }
		flag2[x - 1] = C[x - 1]; 
		flag[x - 1] = 1;
		
	}
	if (N != 1) {
		if (C[0] == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (N == 1&&M==0) {
		C[0] = 0;
	}

	rep(i, N)cout << C[i];

	cout << endl;
	return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

bool is_acgt(char c) {
    return (c == 'A' || c == 'C' || c == 'G' || c == 'T');
}

void solve() {
    string s;
    cin >> s;

    int r, max_length = 0;
    for (int i = 0; i < s.size(); i++) {
        r = i;
        while (r < s.size() && is_acgt(s[r])) r++;
        max_length = max(max_length, (r - i));
    }

    cout << max_length << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>

using namespace std;


bool saiki(vector<int> ball,stack<int> B,stack<int> C){

    if(ball.size() == 0) return true;
    int temp = ball.front();
    bool flag1=false,flag2=false;
    ball.erase(ball.begin());
    if(temp > B.top()){
	B.push(temp);
       	flag1 = saiki(ball,B,C);
	B.pop();
    }
    if(temp > C.top()){
	C.push(temp);
	flag2 = saiki(ball,B,C);
    }
    return flag1 || flag2;
}


int main(){

    int N,temp;
    vector<int> ball;
    stack<int>B,C;
    B.push(0);
    C.push(0);
    cin >> N;
    for(int i=0;i<N;i++){
	for(int j=0;j<10;j++){
	    cin >> temp;
	    ball.push_back(temp);
	}
	if(saiki(ball,B,C)) cout << "YES" << endl;
	else cout << "NO" << endl;
	ball.clear();
    }
    return 0;
}

Measured memory_bytes: 1228
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n"); // 'A B'
	tmp = input[0].split(" "); // [A,B]
	//文字列から10進数に変換するときはparseIntを使います
	var A = parseInt(tmp[0], 10); // A(int)
	var B = parseInt(tmp[1], 10); // B(int)
  	var ans = Math.max(2*A-1,A+B,2*B-1);
	//出力
	console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <cstdio>

using namespace std;

int main(void){
	int i,l[10],v1,v2, sum;
	double t, dist;
	while(scanf("%d%*c",&l[0]) != EOF){
		sum = l[0];
		for(i = 1;i < 10;i++){
			scanf("%d%*c",&l[i]);
			sum += l[i];
		}
		scanf("%d%*c%d",&v1,&v2);
		t = (double)sum / (v1 + v2);
		dist = v1 * t;
		sum = 0;
		for(i = 0;sum < dist && i < 10;i++){
			sum += l[i];
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables **************/
string s;
/**********************************************/

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

    cin >> s;
    sort(all(s));
    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int m;
	cin >> m;
	cout << 48 - m << endl;

	return 0;
}

Measured memory_bytes: 256