akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
vector<vector<int>> G;
ll dp[100010][2];
int flag[100010][2];

ll solve(int u,int p,int color){
	if(flag[u][color]) return dp[u][color];
	flag[u][color] = 1;

	ll res = 1;
	for(int v : G[u]){
		if(v == p) continue;
		if(color == 0){
			res *= solve(v,u,0)+solve(v,u,1);
			res %= MOD;
		}
		else{
			res *= solve(v,u,0);
			res %= MOD;
		}
	}
	return dp[u][color] = res;
}

 
int main(){
	cin >> N;
	G.resize(N);
	rep(i,N-1){
		int x,y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	ll ans = solve(0,-1,0)+solve(0,-1,1);
	ans %= MOD;
	cout << ans << endl;

}


Measured memory_bytes: 16384
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

//Range Min Query
class SegmentTree {
private:
	ll n;
	vector<ll>node;

public:
	void init(ll size) {
		n = 1;
		while (n < size) { n *= 2; }
		node.resize(2 * n - 1, INF);
	}

	// node[i] = x 
	void update(ll i, ll x) {
		i += n - 1;
		node[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = min(node[2 * i + 1], node[2 * i + 2]);
		}
	}

	// min([a, b))
	ll get_min(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) { r = n; }
		if (r <= a || b <= l) { return INF; }
		if (a <= l && r <= b) { return node[k]; }
		ll vl = get_min(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = get_min(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};

int main() {
	int a, b;
	cin >> a >> b;
	SegmentTree tree;
	tree.init(a);

	for (int i = 0; i < b; ++i) {
		int n, m, mm;
		cin >> n >> m >> mm;
		if (n == 0) { tree.update(m, mm); }
		else { cout << tree.get_min(m, mm + 1) << endl; }
	}
}



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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> L,R;
	vector<long long> K(1,0);
	int N; cin>>N;
	for(int i=0;i<N;i++){ int l,r; cin>>l>>r; L.push_back(l); R.push_back(-r); }
	sort(L.begin(),L.end());
	sort(R.begin(),R.end());
	while(!L.empty()){
		int l=L.back(); 
		int r=R.back();
		L.pop_back();
		R.pop_back();
		if(l+r>=0){
			if(min(l,r)>=0) K.front()+=l+r; 
			else{ K.push_back(max(l,r)+K.front()); K.front()+=l+r; }
		}
		else{
			K.front()+=max({0,l,r});
			break;
		}
	}
	long long res=0;
	while(!K.empty()){
		res=max(res,K.back());
		K.pop_back();
	}
	cout<<res*2<<endl;
	return 0;
}

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

int main()
{
	int n,i;
	char a[105];
	scanf("%d ",&n);
	for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
	if(n%2!=0)
		printf("No\n");
	else if(n%2==0)
	{
		for(i=1;i<=n/2;i++)
			if(a[i]!=a[i+n/2])
				break;				
		if(i>n/2)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int A=0;
  int l,r;
    
  for(int i=0;i<N;i++){
    cin >> l >> r;
    A += r-l+1;
    }
  
  cout << A<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

int count16bit(unsigned short v)
{
    unsigned short count = (v & 0x5555) + ((v >> 1) & 0x5555);
    count = (count & 0x3333) + ((count >> 2) & 0x3333);
    count = (count & 0x0f0f) + ((count >> 4) & 0x0f0f);
    return (count & 0x00ff) + ((count >> 8) & 0x00ff);
}

int main(void)
{
    int ans = 0;
    int n, m, k[10], s[10][10], p[10];

    scanf("%d%d", &n, &m);
    rep(i, m)
    {
        scanf("%d", &k[i]);
        rep(j, k[i])
        {
            scanf("%d", &s[i][j]);
            //printf("s[%d][%d]=%d ", i, j, s[i][j]);
        }
    }
    rep(i, m)
    {
        scanf("%d", &p[i]);
        //printf("p[%d]=%d ", i, p[i]);
    }
    //printf("\n");

    rep(i, 1 << n)
    {
        //printf("ibit:%d ", count16bit(i));
        int flag = 1;
        rep(j, m)
        {
            int cnt = 0;
            rep(l, k[j])
            {
                if (i >> (s[j][l] - 1) & 1)
                {
                    cnt++;
                    //printf("s[%d][%d]=%d ", j, l, s[j][l]);
                }
            }
            //printf("cnt:%d ", cnt);
            if ((cnt % 2) != p[j])
                flag = 0;
        }
        if (flag == 1)
            ans++;
        //printf("\n");
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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 int INF=1e18;
const int MOD=1e9+7;

int d[5000],e[5000],cou[5000];
int k, q;

void solve(){
    int n, x, m; cin >> n >> x >> m; x %= m;
    int sum = 0; 
    REP(i,k){
        e[i] = d[i] % m + ( d[i] % m == 0 ? m : 0 );
        sum += e[i];
    }
    sum *= (n-1) / k;
    sum += x;
    REP(i, (n-1)%k) sum += e[i];
    cout << n - 1 - (sum / m) + (x / m) <<endl;
}

signed main(){
    cin >> k >> q;
    REP(i,k) cin >> d[i];
    REP(i,q) solve();
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n;
	cin >> n;
	vector< ll > a(n);
	vector< ll > b(n);
	vector<pair<ll,ll>> v(n);
	for (ll i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i];
		v[i].first = b[i];
		v[i].second= a[i];
	}
	sort(v.begin(),v.end());
	ll c = 0;
	bool f = true;
	for (ll i = 0; i < n; ++i)
	{
		c += v[i].second;
		if(v[i].first < c)
		{
			f=false;
			break;
		}
	}
	if(f)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0; 
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
ll k, a[200200], b[200200], ans;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++) cin >> a[i], a[i] += a[i-1];
    for(int i=1;i<=m;i++) cin >> b[i], b[i] += b[i-1];
    b[++m] = 1e18;

    for(int i=0;i<=n;i++){
        if(a[i] > k) break;
        ans = max(ans, (long long)(i + (upper_bound(b+1, b+1+m, k-a[i])-b-1)));
    }

    cout << ans;
}

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int k, t;
    cin >> k >> t;
    vi a(t);
    int sum = 0;
    int MAX = 0;
    rep(i, 0, t){
        cin >> a[i];
        sum += a[i];
        MAX = max(MAX, a[i]);
    }
    int ans = 0;
    if(MAX > sum / 2){
        ans = (MAX - (sum - MAX)) - 1;
    }
    o(ans);
}

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

int main()
{
    int n,j=0,count=0,maxcount=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    while(j!=(n-1)){
        if(a[j+1]<=a[j]) {count++;
        j++;
        maxcount=max(maxcount,count);
    }
    else {count=0;
    j++;}
    }
    cout<<maxcount;
}


Measured memory_bytes: 640
p = int(input())
n = list(map(int, input().split()))

c = 0
for d in range((p-2)):
  if(d+1 < p):
    s1 = n[d]
    s2 = n[d+1]
    s3 = n[d+2]
  
    if s1 < s2 and s2 < s3:
      c += 1
    if s1 > s2 and s2 > s3:
      c += 1
  else:
    break
    
print(c)
               

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a <= b * 2 ? 0 : a - 2 * b) << endl;
  return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int sc = 0, tc = 0, xlen, d = 0;
  string x;
  cin >> x;
  xlen = x.size();
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'T' && sc) {
      sc--;
      d += 2;
    }
    if (x[i] == 'S') {
      sc++;
    }
  }
  cout << xlen - d << '\n';
  return 0;
}

Measured memory_bytes: 720
# -*- coding: utf-8 -*-
n = int(input())
th = pow(10, 18)
a = list(map(int, input().split()))

ans = 1
over = False

for i in a:
    ans *= i
    if ans > th:
        over = True
        ans %= th
    
    if i == 0:
        ans = 0
        over = False
        break

if over:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21648
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>

using namespace std;

int gcd(int a,int b)
{
     return b ? gcd(b,a%b) : a;
}
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	set<int> s;
	for(int i=0;i<n;i++)  scanf("%d",&a[i]);
	int gc=gcd(a[0],a[1]);
	for(int i=2;i<n;i++)	gc=gcd(gc,a[i]);
	if(gc!=1)
	{
		cout<<"not coprime"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)	continue;
		for(int j=1;j*j<=a[i];j++)
		{
			if(a[i]%j==0)
			{
				if((j!=1&&s.find(j)!=s.end()) || s.find(a[i]/j)!=s.end())
				{
					cout<<"setwise coprime"<<endl;
					return 0;
				}
				s.insert(j);
				s.insert(a[i]/j);
			}
		}
	}
	cout<<"pairwise coprime"<<endl;
	return 0;
}

Measured memory_bytes: 7280
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define N 8

int *r,*c,k;

void printQueen(int queen[N])
{
  int i,j,l;
    for (i = 0; i < N; i++) {
      for(j = 0 ; j < N ; j++){
	if(j == queen[i]){
	  printf("Q");
	  continue;
	}
        printf(".");
      }
      
      printf("\n");
    }
}

/* (i,j)???????????????????¨????????????????????????? board ???????????????????´?????????? d???????????? */
void changeBoard(int board[N][N], int i, int j, int d)
{
    int k;
    
    for (k = 0; k < N; k++) { 
        board[i][k] += d;             /* ?¨??????? */
        board[k][j] += d;             /* ????????? */
    }
    if (i > j) {
        for (k = 0; k < N-(i-j); k++) {
            board[k+(i-j)][k] += d;   /* ???????????????????????? (i > j?????¨?????? */
        }
    } else {
        for (k = 0; k < N-(j-i); k++) {
            board[k][k+(j-i)] += d;   /* ???????????????????????? (i <= j?????¨?????? */
        }
    }
    if (i+j < N) {
        for (k = 0; k <= i+j; k++) {
            board[i+j-k][k] += d;     /* ???????????????????????????i +j < N?????¨?????? */
        }
    } else {
        for (k = i+j-N+1; k < N; k++) {
            board[i+j-k][k] += d;     /* ???????????????????????????i+j >= N?????¨?????? */
        }
    }
}

/* i ??????????????????????????????????¨????????????? setQueen(queen, board, i+1) ???????????????
??????????????? i == N ?????¨???????????????????§£??? queen ?????\??£??????????????§???????????¨?????????????????§?????? */
void setQueen(int queen[N], int board[N][N], int i)
{
  int j,flag = 0,flag1 = 0;


  for(j = 0 ; j < k ; j++){
    if(queen[r[j]] == c[j])flag++;
  }
  
    if (i == N && flag == k) {                              /* ?§£??????????????£??? */
        printQueen(queen);
    }

    if(i == N && flag == k) exit(0);
    
    for (j = 0; j < N; j++) {
        if (board[i][j] == 0) {                /* (i,j) ?????????????????????????????° */
            queen[i] = j;                      /* (i,j) ????????????????????????????????? */
            changeBoard(board, i, j, +1);      /* (i,j) ??????????¨???????????????????board??????+1?????? */
            setQueen(queen, board, i+1);       /* i+1 ??????????????????????????????????±??????? */
            changeBoard(board, i, j, -1);      /* (i,j) ??????????¨???????????????????board?????????????????? */
        }
    }
}

void findSolution()
{
    int queen[N];
    int board[N][N];
    int i;
    scanf("%d",&k);

    r = (int *)malloc(sizeof(int) * k);
    c = (int *)malloc(sizeof(int) * k);

    for(i = 0 ; i < k ; i++)
      scanf("%d %d",&r[i],&c[i]);
      
    memset(board, 0, sizeof(board));
    setQueen(queen, board, 0);
}

int main()
{
    findSolution();
    return 0;
}

Measured memory_bytes: 572
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sc_a = 0, sc_b = 0;
		for(int i = 0; i < 4; i++) {
			sc_a += sc.nextInt();
		}
		for(int i = 0; i < 4; i++) {
			sc_b += sc.nextInt();
		}
		System.out.println(sc_a > sc_b ? sc_a : sc_b);
	}
}

Measured memory_bytes: 26248
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

const int maxE = 100010;
int parent[maxE];
int parent_rank[maxE];


void init(int max_element) {
	for (int i = 0; i < max_element; i++) {
		parent[i] = i;
		parent_rank[i] = 0; 
	}
}

int find(int x) {
	if (x == parent[x]) return x;
	
	parent[x] = find(parent[x]);
	return parent[x];
}

bool isSame(int x, int y) {
	return find(x) == find(y);
}



void link(int x, int y) {
	if (parent_rank[x] > parent_rank[y]) {
		parent[y] = x;
		return;
	}
	parent[x] = y;
	if (parent_rank[x] == parent_rank[y]) {
		parent_rank[y]++;
	}
}

void unite(int x, int y) {
	link(find(x),find(y));
}


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

	init(n);
	
	vector<vector<int> > A(n);


	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		unite(a, b);
		A[a].push_back(b);
		A[b].push_back(a);
	}




	vector< vector<int> > fs(n);
	rep(i, n) {
		int p = find(i);
		fs[p].push_back(i);
	}


	vector<set<int> > bs(n);
	rep(i, k) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		if (isSame(c, d)) {
			bs[c].insert(d);
			bs[d].insert(c);
		}

	}

	rep(i , n) {
		int ans = 0;
		int p = find(i);

		cout << fs[p].size() - bs[i].size() - 1 - A[i] .size() << " ";


	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 22016
#include<iostream>
#include<numeric>
#include<string>
#include<cmath>

using namespace std;

int main(){

    int n, cnt = 0;

    cin >> n;

    int p[n];

    for(int i = 0;i < n;i++){

        cin >> p[i];
    }

    for(int i = 1;i < n - 1;i++){

        if((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] > p[i + 1] && p[i] < p[i - 1])){

            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int N,K,count=0;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int H;
    cin >> H;
    if(H>=K){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
from fractions import gcd
N,M=(int(i) for i in input().split())
S=input()
T=input()
gcd_NM=gcd(N,M)
lcm_NM=(N*M//gcd_NM)
A=True
for i in range(gcd_NM):
  if S[(N//gcd_NM)*i]!=T[(M//gcd_NM)*i]:
    A=False 
    break
if A:
  print(lcm_NM)
else:
  print(-1)

Measured memory_bytes: 5344
import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
	int n,m,k;
	int[] A = new int[205];
	int[] B = new int[205];
	Scanner in = new Scanner(System.in);
	n = in.nextInt();
	for(int i=1;i<=2*n;i++)A[i] = i;
	m = in.nextInt();
	for(int i=0;i<m;i++)
	    {
		k = in.nextInt();
		if(k == 0)
		    {
			int d = 1;
			for(int j=1;j<=2*n;j+=2)
			    {
				if(j != 1)d++;
				B[j] = A[d];
				B[j+1] = A[n+d];
			    }		
			for(int j=1;j<=2*n;j++)A[j] = B[j];
		    }
		else
		    {
			for(int j=1;j<=2*n;j++)
			    {
				if(j<=k)
				    {
					B[(2*n-k)+j] = A[j];
				    }
				else    B[j - k] = A[j];
			    }
			for(int j=1;j<=2*n;j++)A[j] = B[j];
		    }
	    }
	for(int i=1;i<=2*n;i++)System.out.println(A[i]);
    }
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N, i;
  cin >> N >> i;
  cout << N - i + 1 <<endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
s = input()
sn = len(s)
t = input()
tn = len(t)

ss = ""
for i in range(sn-tn+1):
    match = True
    for j in range(tn):
        if s[i+j]=="?" or s[i+j]==t[j]:
            pass
        else:
            match = False
            break
    if match:
        ss = s[:i] + t + s[i+tn:]

if ss=="":
    print("UNRESTORABLE")
    exit()

print(ss.replace("?","a"))

Measured memory_bytes: 3064
//package com.company;

import java.io.*;
import java.util.*;

//public class Giveaway {
    public class Main {
    public static boolean getSum(int n)
    {
        int sum = 0;
    
        while (n != 0)
        {
            sum = n % 10;
            n = n/10;
            if(sum==7)
                return true;
        }
    
        return false;
    }
    public static void main(String[] args) {

        out = new PrintWriter(new BufferedOutputStream(System.out));
        MyScanner sc = new MyScanner();//start
        out.println(getSum(sc.nextInt())?"Yes":"No");
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
//--------------------------------------------------------

}


Measured memory_bytes: 32776
using System;
using System.Linq;
class ABC96A
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int m = int.Parse(input[0]);
        int d = int.Parse(input[1]);

        if (m > d)
            m--;


        Console.WriteLine(m);
    }
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl;
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<P> VP;
const int INF = 1LL<<60;
const int MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
  V a(3);
  cin>>a[0]>>a[1]>>a[2];
  SORT(a);
  if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
    cout<<0<<endl;
  }
  else {
    cout<<(a[1]*a[0])<<endl;
  }
  
  
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

 ll n;
 cin>>n;
 ll d=1000;
 while(d<n)
 {
     d+=1000;
 }
 cout<<d-n<<endl;
return 0;
}



Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
	int a,b,c,k;
	int flag1=0,flag2=0;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	
	while(a>=b&&k)
	{b=2*b;
	k--;
	}
	if(a<b){flag1=1;}
	while(b>=c&&k)
	{c=2*c;
	k--;
	}
	if(b<c){flag2=1;}
	if(flag1==1&&flag2==1)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 1720
def nanbanme(n, x):
    lst = [1 for i in range(n)]
    ans = 0
    for i in range(n):
        a = x[i]
        count = 0
        for j in range(a - 1):
            if (lst[j] == 1):
                count = count + 1
        tmp = 1
        for k in range(1, n - i):
            tmp = tmp*k
        ans = ans + count*tmp
        lst[a - 1] = 0
    return (ans + 1)

n = int(input())
lst1 = list(map(int,input().split()))
lst2 = list(map(int,input().split()))

a = nanbanme(n, lst1)
b = nanbanme(n, lst2)

print(abs(a - b))


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(ll, q);
    ll rmax = 0, l[q], r[q];
    REP(i, q){
        cin >> l[i] >> r[i];
        rmax = max(rmax, r[i] + 1);
    }
    ll a[100001];
    REP(i, 100001) a[i] = 1;
    a[0] = a[1] = 0;
    ll t = 2;
    while(t < rmax){
        for(ll x = t*2; x < rmax; x += t) a[x] = 0;
        t++;
        while(!a[t])t++;
    }
    ll b[100001];
    b[0] = 0;
    FOR(i, 1, rmax){
        if(i == 2017) b[i] = b[i-1] + 1;
        else{
            b[i] = b[i-1] + (a[i] && a[(i+1)/2]);
        }
    }
    REP(i, q){
        OUTL(b[r[i]] - b[l[i]-1]);
    }
RET;}


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

using namespace std;

long long mod = 1000000007;

long long mul_mod(long long x,long long y){
    return x*y%mod;
}

int main(){
    string str[2];
    int n;
    cin >> n;
    cin >> str[0];
    cin >> str[1];
    long long ans = 1;
    int did = 0;
    int last;
    if(str[0][0] == str[1][0]){
        ans = 3;
        last = 1;
        did = 1;
    }
    else{
        ans = 6;
        last = 2;
        did = 2;
    }
    while(did < n){
        if(str[0][did] == str[1][did]){
            if(last == 1) ans = mul_mod(ans,2);
            did += 1;
            last = 1;
        }
        else{
            if(last == 1) ans = mul_mod(ans,2);
            else ans = mul_mod(ans,3);
            did += 2;
            last = 2;
        }
    }
    cout << ans << endl;
}


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


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

    string N;
    int K;
    cin >> N >> K;

    int ni = N.size();
    int nj = K + 1;
    int nk = 2;
    int dp[ni+1][nj][nk] = {};

    dp[0][0][1] = 1;
    for (int i = 0; i < ni; i++) {
        for (int j = 0; j < nj; j++) {
            for (int k = 0; k < nk; k++) {
                int next_num = N[i] - '0';
                int max_num = k ? next_num : 9;
                if (j == K) max_num = 0;
                for (int h = 0; h <= max_num; h++) {
                    dp[i+1][j + (h != 0)][k && (h == next_num)] += dp[i][j][k];
                }
            }
        }
    }

    cout << dp[ni][nj-1][0] + dp[ni][nj-1][1] << endl;

    return 0;
}



Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

ll pow(ll s, ll n) {
  ll r = 1;
  while (n) {
    s *= s;
    if (n % 2)
      r *= s;
    n /= 2;
  }
  
  return r;
}

void solve() {
  in<int> N;
  vector<string> vs;
  
  string ns = to_string(N);
  REP(i, 9) {
    string tmp = to_string(i+1);
    if (stoi(tmp) > N)
      break;
    vs.push_back(tmp);
  }

  REP(k, ns.length()) {
  REP(i, 9) {
  REP(j, 9) {
    string tmp = to_string(i+1);
    REP(tmpl,k)
      tmp += '0';
    tmp += to_string(j+1);
    if (stoi(tmp) > N)
      goto SKIP;
    vs.push_back(tmp);
  }
  }
  }
  SKIP: (void)0;
  
  ll r = 0;
  string ns2 = ns;
  ns2[0] = '0';
  ns2.pop_back();
  decltype(vs) vsb = vs;
  for (auto it = vs.rbegin(); it != vs.rend(); ++it) {
    for (auto itb = vsb.rbegin(); itb != vsb.rend(); ++itb) {

    if (it->front() == itb->back() && itb->front() == it->back()) {
      ll tmp = 1;
//      if ()
      if (it->length() > 2) {
        ll t = pow(10, it->length() - 2);
        if (it->front() == ns.front() && it->length() == ns.length()) {
          t = stoi(ns2);
          if (it->back() <= ns.back())
            t++;
        }
        tmp *= t;
      }
      if (itb->length() > 2) {
        ll t = pow(10, itb->length() - 2);
        if (itb->front() == ns.front() && itb->length() == ns.length()) {
          t = stoi(ns2);
          if (itb->back() <= ns.back())
            t++;

        }

        tmp *= t;
      }
      r += tmp;
    }
  }
  }

  


  cout << r << endl;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  solve();

  return 0;
}



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

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int N;

	cin >> N;

	vector<pair<int, int>> A(N);
	int num;

	REP(i, N) {
		cin >> num;
		A[i] = make_pair(num, i + 1);
	}

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

	REP(i, N - 1) cout << A[i].second << ' ';
	cout << A.back().second << endl;

	return 0;
}

Measured memory_bytes: 1664
a,b=map(int,input().split())
if a<b:
  n=a
else:
  n=b
  
x=1

for i in range(2,n+1):
  while 1:
    if (b/x)%i==0 and (a/x)%i==0:
      x=x*i
    else:
      break
  
print(int(a*b/x))

Measured memory_bytes: 3060
#include <stdio.h>
/*
int main(void){
    int i,j,n;float m[8],e;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<8;j++){scanf("%lf",&m[j]);}
	m[2] -= m[0];
	m[3] -= m[1];
	m[6] -= m[4];
	m[7] -= m[5];
        //e=(m[3]-m[1])*(m[6]-m[4])-(m[7]-m[5])*(m[2]-m[0]);
	if(m[7] * m[2] == m[6] * m[3]) printf("YES\n");
	else printf("NO\n");
        //printf("%s\n",(e==0)?"YES":"NO");
    }
    return 0;
}
*/
int main(){
      
    int n;
      
    float x[4], y[4];
      
    scanf("%d",&n);
      int i, loop;
    for(loop = 0; loop < n; loop++){
        for(i = 0; i < 4; i++){
		scanf("%f",&x[i]);
		scanf("%f",&y[i]);
        }
        x[1] -= x[0];
        y[1] -= y[0];
        x[3] -= x[2];
        y[3] -= y[2];
        if(x[3] * y[1] == y[3] * x[1]){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
      
    return 0;
}




Measured memory_bytes: 2036
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout << setprecision(12)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cin4(x, y, z, _) cin >> x >> y >> z >> _
#define cin5(x, y, z, p, q) cin >> x >> y >> z >> p >> q
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); rep(w, 0, _t)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
struct point{    int x, y, ind;   char ch;  };
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
bool cmp(point A, point B){   if(A.x != B.x) ret(A.x < B.x);  ret(A.y < B.y);   }
// head collected
// Don't use variable name as --> prev, time, _t, w, y1

ll t, n, k, _, __,ans, re;
string str;
ll ara[100007];

start;

    cin1(t);

    //rep(i, 1, 221) cous(i*2);

    if ( t & 1 ) {
        coul("0");
        ret(0);
    }

    /*_  = 10;
    while ( 1 ){
        __ = t / _;
        if ( __ == 0 )
            break;
        _ *= 10;
        ans += __;
    }*/

    t = t /2;
    _ = 5;
    while ( 1 ){
        __ = t / _;
        if ( __ == 0 )
            break;
        _ *= 5;
        ans += __;
    }

    /*t = t *10;
    _ = 100;
    while ( 1 ){
        __ = t / _;
        if ( __ == 0 )
            break;
        _ *= 10;
        ans -= __;
    }*/


    coul(ans);

finish

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j;
    cin>>a>>b;
    if(a>b)
        for(i=0;i<a;i++)
    {
        cout<<b;
    }
    else
    {
        for(i=0;i<b;i++)
        {
            cout<<a;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u !=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int find(int k, Node u) {
    int res;
    if(u!=NIL) {
        if (u->key == k) return 1;
        if (u->key < k) res = find(k, u->right);
        else res =  find(k, u->left);
    }else {
        return 0;
    }
    return res;
}


int main(){
  int n, i, x, res;
  char com[20];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0] == 'f') {
      scanf("%d", &x);
      res =find(x, root);
      if(res == 1){
          printf("yes\n");
      }else {
          printf("no\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 19360
using System;
class Program
{
  static void Main (string[] args)
  {
    string S = Console.ReadLine();
    int maxLength = 0;
    int currLength = 0;
    for (int i = 0; i < S.Length; i++) {
      if ((S[i] == 'A') || (S[i] == 'C') || (S[i] == 'G') || (S[i] == 'T')) {
        currLength++;
      } else {
        maxLength = (maxLength < currLength) ? currLength : maxLength;
        currLength = 0;
      }
    }
    maxLength = (maxLength < currLength) ? currLength : maxLength;
    Console.WriteLine(maxLength);
  }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

bool call(int n) {
    if (n % 3 == 0) {
        return true;
    } else {
        while (n > 0) {
            int digit = n % 10;
            if (digit == 3)
                return true;
            n /= 10;
        }
    }
    return false;
}

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

    for (int i = 3; i <= n; i++) {
        if (call(i))
            cout << " " << i;
    }
    cout << endl;
}



Measured memory_bytes: 3168
#include <stdio.h>
typedef struct {
  int p,l,r; /* parent,left child,right sibling */
} Node;
Node T[100000];
int depth(int);
int PrintChild(int);
void Print(int);
int main()
{
  int n,i,j,c,id,k,pre;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].p = T[i].l = T[i].r = -1;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d %d",&id,&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d",&c);
	  T[c].p=id;
	  if(j==0) T[id].l = c;
	  else T[pre].r = c;
	  pre = c;
	}
    }
  for(i=0;i<n;i++)
    {
      Print(i);
    }
  return 0;
}
void Print(int id)
{
  int i;
  printf("node %d: parent = %d, depth = %d, ",id,T[id].p,depth(id));
  if(T[id].p == -1) printf("root, [");
  else if(T[id].l == -1) printf("leaf, [");
  else printf("internal node, [");
  PrintChild(T[id].l);
  printf("]\n");
}
int PrintChild(int id)
{
  if(id == -1) return 0;
  if(T[id].r == -1)printf("%d",id);
  else 
    {
      printf("%d, ",id);
      PrintChild(T[id].r);
    }
  return 0;
}
int depth(int id)
{
  if(T[id].p == -1) return 0;
  return 1+depth(T[id].p);
}

Measured memory_bytes: 3348
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  int ns = s.size(), nt = t.size();
  vector<vi> dp(ns + 1, vi(nt + 1, 0));

  for(int i=1;i<=ns;i++){
    for(int j=1;j<=nt;j++){
      if (s[i-1] == t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1; 
      }
      dp[i][j] = max(dp[i][j], dp[i][j-1]);
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }

    // printf("d[%d] ", i);
    // rep(j, nt+1) cout << dp[i][j] << " ";
    // cout << endl;
  }

  string ans = "";
  int i = ns, j = nt;
  while (dp[i][j] != 0){
    while (dp[i][j] == dp[i-1][j]) i--;
    while (dp[i][j] == dp[i][j-1]) j--;
    ans += s[i-1];
    i--;j--;
  }

  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 35584
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
point = 0
for i in range(N):
  if A[i]>=B[i]:
    point += B[i]
  elif A[i] < B[i]:
    point += A[i]
    B[i] -= A[i]
    if B[i] <= A[i+1]:
      point += B[i]
      A[i+1] -= B[i]
    else:
      point += A[i+1]
      A[i+1] = 0
print(point)
    
  

Measured memory_bytes: 18476
package main

import "fmt"

func main() {
        var x int
        fmt.Scan(&x)
        var (
                k     int
                kA    int
                angle = 360
        )
        for {
                k = angle / x
                kA = angle % x
                angle += 360
                if kA == 0 {
                        break
                }
        }
        fmt.Println(k)
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

const long MAX = 1000001;

void	PrimeInit(vector<long> &P) {
	P.erase(P.begin(), P.end());
	P.push_back(2);
	vector<bool> p(MAX+1, false);
	for (long i=3; i<=MAX; i +=2) {
		if (p.at(i))
			continue;
		P.push_back(i);
		for (int j=i; j<=MAX; j+=i+i)
			p.at(j)=true;
	}
}

void	getPrimes(long A, vector<long> &AP, const vector<long> &P) {
	long i=0;
	long SQ=sqrt(A);
	while(P.at(i)<=SQ) {
		if (0==A%P.at(i)) {
			AP.push_back(P.at(i));
			A /=P.at(i);
		} else
			i++;
		if (1==A)
			break;
	}
	if (1!=A)
		AP.push_back(A);
}

void	PF(long P, vector<vector<long>> &U) {
	long PP=sqrt(P)+2;
	vector<bool> PR(PP, true);
	long UU=2;
	while (true) {
		if (UU>=PP) break;
		if (PR.at(UU)) {
			for (int i=UU+UU; i<PP; i+=UU)
				PR.at(i)=false;
			if (0==P%UU) {
				U.push_back({1, UU});
				P /=UU;
				while (0==P%UU) {
					U.at(U.size()-1).at(0)++;
					P /=UU;
				}
			}
		}
		if (2==UU)
			UU=3;
		else
			UU +=2;
	}
	if (1!=P)
		U.push_back({1, P});
}

int	main() {
	ll N;
	cin >>N;
	if (1==N) {
		cout <<0 <<endl;
		return 0;
	}
	// One: PF()
	vector<vector<long>> Primes(0);
	PF(N, Primes);
	/*
	for (int i=0; i<Primes.size(); i++) 
		cout <<Primes.at(i).at(1) <<':' <<Primes.at(i).at(0) <<endl;
	// Another one for multiple P's: PrimeInit(), getPrimes()
	vector<long>	PrimesList;
	PrimeInit(PrimesList);
	vector<long> Primes2;
	getPrimes(P, Primes2, PrimesList);
	*/
	ll S=0;
	Rep0(i, Primes.size()) {
		ll PP=Primes.at(i).at(0);
		ll IX=1;
		while (PP>=IX) {
			S++;
			PP-=IX;
			IX++;
		}
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    vector <string> sv;
    string s;
    int ns,sl;
    cin>>ns>>sl;
    for(int i=0;i<ns;i++){
        cin>>s;
        sv.push_back(s);
    }
    for(int i=0;i<sv.size();i++){
        int re=0;
        for(int i2=0;i2<sv[i].length();i2++){
            if(sv[i][i2]=='.'){
                re++;
            }
        }
        if(re==sv[i].length()){
            sv.erase(sv.begin()+i,sv.begin()+i+1);
            i--;
        }
    }
    for(int i=0;i<sv[0].length();i++){
        int re=0;
        for(int i2=0;i2<sv.size();i2++){
            if(sv[i2][i]=='.'){
                re++;
            }
        }
        if(re==sv.size()){
            for(int i3=0;i3<sv.size();i3++){
                sv[i3].erase(i,1);
            }
            i--;
        }
    }
    for(int i=0;i<sv.size();i++){
        cout<<sv[i]<<endl;
    }
    return 0;
}


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

int main(){
	while (true)
	{
		int x[200] = {}, a, b;
		cin >> a >> b;
		if (cin.eof()) { break; }
		while (true)
		{
			if (a == 0) { break; }
			x[a]++;
			x[a] %= 2;
			x[b]++;
			x[b] %= 2;
			cin >> a >> b;
		}

		int count = 0;
		for(int i=1;i<101;i++){
			if (x[i] == 1) { count++; }
		}

		if(count == 2 && x[1] == 1 && x[2] == 1){
			cout << "OK" << endl;
		}
		else{
			cout << "NG" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3056
# coding: utf-8
# Your code here!
#N,X,T=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

count=0
for i in range(N-1):
    if A[i] <= A[i+1]:
        continue
    else:
        count+=abs(A[i+1]-A[i])
        A[i+1]=A[i]
print(count)

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

const ll INF = pow(10, 9) + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;
  rep(i,n){
    if(i%2==1){
      if(s[i]=='L' || s[i]=='U' || s[i]=='D') continue;
      ok = false;
    }
    else{
      if(s[i]=='R' || s[i]=='U' || s[i]=='D') continue;
      ok = false;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

const maxBuf = 300100

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Buffer(buf, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	s := sc.Text()
	n := len(s)
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())

	mp := make(map[string]struct{})
	for i := 0; i < n; i++ {
		for j := 1; j <= k; j++ {
			if i+j > n {
				break
			}
			mp[s[i:i+j]] = struct{}{}
		}
	}

	lis := make([]string, len(mp))
	i := 0
	for key := range mp {
		lis[i] = key
		i++
	}
	sort.Strings(lis)
	fmt.Println(lis[k-1])
}


Measured memory_bytes: 2304
#include<iostream>
#include<queue>

using namespace std;

int main(void){
  
  int n, ans = 0;
  priority_queue<int> p;
    
  cin >> n;
  
  for(int i = 0;i < n;i++){
    int x; cin >> x;
    p.push(x);
  }
  
  ans = p.top()/2;
  p.pop();
  
  while(!p.empty()){
    ans += p.top();
    p.pop();
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256