akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
using namespace std;


int main() {
	int a,b;
cin>>a>>b;
cout<<a*b<<" ";
cout<<2*(a+b)<<endl;
return 0;
}

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

int main() {
	const double pi = atan2(0, -1);
	int N;
	cin >> N;
	vector<tuple<double, ll, ll>> V(N);
	ll x, y, xi = 0, yi = 0, r, maxr = 0;
	double theta, angle;
	for (int i = 0;i < N;i++) {
		cin >> x >> y;
		theta = atan2(y, x);
		V[i] = make_tuple(theta, x, y);
	}
	sort(V.begin(), V.end());


	for (int i = 0;i < N;i++) {
		int b = -1;
		x = y = r = 0;
		for (int j = i;j < N;j++) {
			tie(ignore, xi, yi) = V[j];
			x += xi;y += yi;
			r = max(r, x * x + y * y);
		}
		for (int j = 0;j < i;j++) {
			tie(ignore, xi, yi) = V[j];
			x += xi;y += yi;
			r = max(r, x * x + y * y);
		}
		maxr = max(r, maxr);
	}
	printf("%.12f\n", sqrt(maxr));
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int d = sc.nextInt();
			int result = 0;

			for (int i = 0; i < n; i++) {
				long x = sc.nextInt();
				long y = sc.nextInt();
				if (Math.sqrt((x * x) + (y * y)) <= d) {
					result++;
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 58860
s = input()
s1 = [i % 2 for i in range(len(s))]
s2 = [(i + 1) % 2 for i in range(len(s))]
c1 = 0
c2 = 0

for i in range(len(s)):
    if int(s[i]) != s1[i]:
        c1 += 1
    else:
        c2 += 1

print(min(c1, c2))


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
int main()
{
  bool flag[31] = {0};
  int d;
  for(int i = 0;i < 28;i++) {
    cin >> d;
    flag[d] = true;
  }
  for(int i = 1;i <= 30;i++) {
    if(!flag[i])cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 3056
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <vector>

#define MAX_N (100000L)
#define MAX_SQRTM (100000L)
#define MAX_NUM_DIV (30L)
#define NUM_MOD (1000000007L)

using namespace std;

long pow_mod(long x, long k, long mod) {
  long ret = 1, p = x;
  while (k > 0) {
    if (k & 1) {
      ret = (ret * p) % mod;
    }
    p = (p * p) % mod;
    k /= 2;
  }
  return ret;
}

int main() {
  // read inputs
  long N, M;
  scanf("%ld %ld", &N, &M);

  // prime decomposition of M
  vector<pair<long, long>> num_divs;
  for (long i = 2; i <= MAX_SQRTM; i++) {
    if (M % i == 0) {
      long num_div = 0;
      while (M % i == 0) {
        num_div++;
        M /= i;
      }
      num_divs.push_back(pair<long, long>(i, num_div));
    }
  }
  if (M > 1) {
    num_divs.push_back(pair<long, long>(M, 1));
  }

  // calculate factorials and inverse factorials mod 1000000007
  long fs[MAX_N + MAX_NUM_DIV], invs[MAX_N + MAX_NUM_DIV],
      finvs[MAX_N + MAX_NUM_DIV];
  finvs[0] = 1;
  fs[0] = 1;
  for (long i = 1; i < MAX_N + MAX_NUM_DIV; i++) {
    fs[i] = (fs[i - 1] * i) % NUM_MOD;
    invs[i] = pow_mod(i, NUM_MOD - 2, NUM_MOD);
    finvs[i] = (finvs[i - 1] * invs[i]) % NUM_MOD;
  }

  // calculate answer
  long ans = 1;
  for (pair<long, long> pr : num_divs) {
    const long p = pr.first, k = pr.second;
    const long comb =
        (((fs[N + k - 1] * finvs[N - 1]) % NUM_MOD) * finvs[k]) % NUM_MOD;
    ans = (ans * comb) % NUM_MOD;
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  vi c(1, 1);
  for (int i = 1; i < n; ++i) {
    if (a[i] == a[i-1]) ++c.back();
    else c.push_back(1);
  }
  sort(c.rbegin(), c.rend());
  int res = 0;
  while (c.size() > k) {
    res += c.back();
    c.pop_back();
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,t;
  bool f = false;
  getline(cin,s);
  for(int i=0; i<s.size(); i++){
    if(s[i] == ' ' || s[i] == ',' || s[i] == '.'){
      if(t.size()>2 && t.size()<7){
	if(f) cout <<" ";
	f = true;
	cout <<t;
      }
      t = "";
    }
    else t+=s[i];
  }
  cout <<endl;
  return 0;
}

Measured memory_bytes: 1168
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto a = next<int>(in);
  out << a + a*a + a*a*a << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (m == n) {
        ll fact = 1;
        fore(i, 1, n) fact = fact * i % MOD;
        ll ans = fact * fact % MOD;
        ans = ans * 2 % MOD;
        cout << ans << '\n';
    } else if (m == n + 1) {
        ll fact = 1;
        fore(i, 1, n) fact = fact * i % MOD;
        ll ans = fact * fact % MOD;
        ans = ans * m % MOD;
        cout << ans << '\n';
    } else cout << "0\n";
}


Measured memory_bytes: 256
from math import *
n=int(input())
a=list(map(int,input().split()))
ans=100000000000000000000000000000
sum=0
c=0
b=[]
cnt=[]
for x in a:
    sum+=x
    if(x==1):
        c+=1
    b.append(sum)
    cnt.append(c)
for i in range(0,n):
    one=b[i]
    two=sum-b[i]
    res=(one+two)//2
    diff1=abs(one-res)
    diff2=abs(two-res)
    ans=min(ans,diff1+diff2)

print(ans)


Measured memory_bytes: 27300
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int sx,sy,tx,ty,x,y;
    cin>>sx>>sy>>tx>>ty;
    x = tx - sx;
    y = ty - sy;
    
    for(int i=0;i<y;i++)
        cout<<"U";
    for(int i=0;i<x;i++)
        cout<<"R";
    for(int i=0;i<y;i++)
        cout<<"D";
    for(int i=0;i<x+1;i++)
        cout<<"L";
    for(int i=0;i<y+1;i++)
        cout<<"U";
    for(int i=0;i<x+1;i++)
        cout<<"R";
    cout<<"D"<<"R";        
    for(int i=0;i<y+1;i++)
        cout<<"D";
    for(int i=0;i<x+1;i++)
        cout<<"L";
    cout<<"U";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <numeric>
#include<queue>
using namespace std;
int main(){
  long long n,m;
  std::cin >> n>>m;
  long long k;
  priority_queue<long long> a;
  long long sum=0;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    a.push(k);
  }

  for (long long i = 0; i < m; i++) {
    long long top = a.top();
 		top /= 2;
 		a.pop();
 		a.push(top);
  }

  for (long long i = 0; i < n; i++) {
    sum+=a.top();
    a.pop();
  }

  std::cout << sum << '\n';







  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

int p[50];
void init(){rep(i,26) p[i]=i;}
int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
void unite(int a,int b){a=find(a),b=find(b),p[a]=b;}
bool same(int a,int b){return find(a)==find(b);}

int main(){
	int n;
	while(cin >> n,n){
		init();
		bool used[50];
		int degree[50];
		rep(i,26) used[i]=degree[i]=0;
		int fix=0;
		rep(i,n){
			string in;
			cin >> in;
			int f=in[0]-'a',t=in[in.size()-1]-'a';
			used[f]=used[t]=true;
			degree[f]++,degree[t]--;
			unite(f,t);
			fix=f;
		}
		bool ok=true;
		rep(i,26) if(degree[i]) ok=false;
		rep(i,26) if(used[i]&&!same(fix,i)) ok=false;
		if(ok)
			puts("OK");
		else
			puts("NG");
	}
	return 0;
}

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

using namespace std;

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

inline string toStr(int x) {
  stringstream ss; ss<<x;
  return ss.str();
}

int N, K;
vector<string> v;
vector<bool> used;
set<string> st;
void rec(int cnt, string s) {
  
  if(cnt == K) {
    st.insert(s);
    return;
  }
  
  rep(i, N) {
    if(used[i]) continue;
    used[i] = 1;
    rec(cnt+1, s+v[i]);
    used[i] = 0;
  }
}

int main() {
  
  while(cin >> N >> K && N) {
    st.clear();
    v.clear(); v.resize(N);
    used.clear(); used.resize(N);
    for(int i=0; i<N; i++) cin >> v[i];
    rec(0, "");
    cout << st.size() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1464
#include <iostream>
#include <queue>
#include <cstring>
#define MAXN 100000 + 15
#define MAXX 200000 + 30
#define ll long long
using namespace std;
const ll INF = 1e18;
ll n, m, s, cnt;
ll dis[MAXN], head[MAXN];
bool vst[MAXN];
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > q;

struct Edge {
	ll to, next, cost;
}edge[MAXX];

void addEdge(ll u, ll v, ll w) {
	edge[++cnt].to = v;
	edge[cnt].cost = w;
	edge[cnt].next = head[u];
	head[u] = cnt;
}

void dijkstra() {
	dis[s] = 0;
	q.push(make_pair(0, s));
	
	while(!q.empty()) {
		ll t = q.top().second;
		q.pop();
		if(!vst[t]) {
			vst[t] = 1;
			for(ll i = head[t]; i != -1; i = edge[i].next) {
				ll e = edge[i].to;
				if(dis[e] > dis[t] + edge[i].cost) {
					dis[e] = dis[t] + edge[i].cost;
					q.push(make_pair(dis[e], e)); 
				}
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	ll u, v, w, ask, s1, s2;
	cin >> n;
	memset(head, -1, sizeof(head));
	for(int i = 0; i <= n; i++) 
		dis[i] = INF;
	for(int i = 1; i < n; i++) {
		cin >> u >> v >> w;
		addEdge(u, v, w);
		addEdge(v, u, w);
	}
	cin >> ask >> s;
	dijkstra();
	while(ask--) {
		cin >> s1 >> s2;
		cout << dis[s1] + dis[s2] << endl;
	}
	return 0;
}

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

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> board(h);
    for(int i = 0; i < h; ++i){
        cin >> board.at(i);
    }
    vector<vector<int>> dp(h,vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            int n = 10000000;
            if(i == 0 && j == 0)
                n = board.at(0).at(0) == '#' ? 1 : 0;
            if(i > 0)
                n = min(n,
                dp.at(i-1).at(j) + (board.at(i-1).at(j) == '.' && board.at(i).at(j) == '#' ? 1 : 0));
            if(j > 0)
                n = min(n,
                dp.at(i).at(j-1) + (board.at(i).at(j-1) == '.' && board.at(i).at(j) == '#' ? 1: 0));
            dp.at(i).at(j) = n;
        }
    }
    cout << dp.at(h-1).at(w-1) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
a = [list(map(int, input().split(" "))) for i in range(n)]
ans = 0
for [ix,iy], [jx, jy] in itertools.combinations(a, 2):
  ans += ((jx-ix)**2+(jy-iy)**2)**0.5*2
print(ans/n)

Measured memory_bytes: 9348
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
bool msnum(int n){
  return (n%7==1||n%7==6);
}
int main(void){
  vector<int> ms;
  vector<int> msp;
  FOR(i,2,300000)if(msnum(i))ms.push_back(i);
  bool msunp[300000]={};
  REP(i,ms.size()){
    if(!msunp[ms[i]]){
      msp.push_back(ms[i]);
      for(int k=2; ms[i]*k<300000; k++){
        msunp[ms[i]*k] = true;
      }
    }
  }
  int n;
  while(cin>>n,n-1){
    printf("%d:",n);
    REP(i,msp.size()){
      if(msp[i]>n) break;
      if(n%msp[i]==0){
        printf(" %d",msp[i]);
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1952
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String ans;
        if(A>=B) ans = "delicious";
        else if(B-A<=X) ans = "safe";
        else ans = "dangerous";
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


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

Measured memory_bytes: 256
/*
=================================
|                               |
|      WE ARE < YN > team       |
|                               |
|   learn more,more and more    |
|                               |
=================================
*/
#include<bits/stdc++.h>
#define fastio std::ios_base::sync_with_stdio(false), std::cout.tie(0), std::cin.tie(0);
#define N 1000007
#define mxx INT_MAX

typedef long long ll;

void solve() {
	int num;
	std::cin>>num;
	int n=num%10;
	if(n==3)std::cout<<"bon";
	else if(n==0||n==1||n==6||n==8)std::cout<<"pon";
	else std::cout<<"hon";


}
int main() {
	/*int t;
	std::cin >> t;
	while (t--)*/
		solve();
}




Measured memory_bytes: 3636
import sys
input = lambda : sys.stdin.readline().rstrip()

class SegmentTree:
    def __init__(self, n, ele, segfun):
        self.ide_ele = ele
        self.segfun = segfun
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)
 
    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2
 
    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret

n, q = map(int, input().split())
stx = []
for _ in range(n):
    s, t, x = map(int, input().split())
    stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(input()) for _ in range(q)]

import bisect

seg = SegmentTree(q, 10**9 + 1, lambda a, b : min(a, b))

for x, start, last in stx:
    l = bisect.bisect_left(d, start)
    r = bisect.bisect_left(d, last)
    seg.update(l, r, x)

for i, j in enumerate(d):
    res = seg.query(i)
    if res == 10**9 + 1:
        print(-1)
    else:
        print(res)
    



Measured memory_bytes: 112220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int a,b;
  int k;

  cin >> a >> b >> k;
  int cnt = 0;

  for (int i = min(a,b); i >= 1 ; --i) {
      if (a % i == 0 and b % i == 0) {
        cnt++;
        if (cnt == k) {
          cout << i << endl;
          return 0;
        }
      }
  }

}


Measured memory_bytes: 256
#include<stdio.h>
int A[45];
int fibonacci(int n){
  if(n==1 || n==0) return 1;
  if(A[n]!=0) return A[n];
  else return A[n] = fibonacci(n-1) + fibonacci(n-2);
}
int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
int main(){
	int n,i,j,k;
	scanf("%d",&n);
	int a[100]; 
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	if(i<n-1)printf("%d ",a[i]);	
	}
	printf("%d\n",a[i-1]);
	
	for(i=1;i<n;i++){
		
		int v=a[i];
		j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		for(k=0;k<n-1;k++){
			printf("%d ",a[k]);
		}
		printf("%d\n",a[k]);
	}
	return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 0;
		 for(int i = 1; i < n; i++) {
			 ans += i;
		 }
		 System.out.println(ans);
	}
}

Measured memory_bytes: 35788
// 14/05/20 // 07:34 PM //

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define endl "\n"
#define int long long

const int MOD  = (int)1e9+7;
const int MAXN = (int)1e5+10;

int n;
vector<int> graph[MAXN];
bool visited[MAXN];
int memo[MAXN][3];

void dfs(int v){

    visited[v] = 1;
    memo[v][0] = memo[v][1] = 1;

    for(int u : graph[v]){
        if(visited[u]) continue;

        dfs(u);

        memo[v][0] =  (memo[v][0] * (memo[u][0] + memo[u][1]))%MOD;
        memo[v][1] =  (memo[v][1] *  memo[u][0])%MOD;
    }
}

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

    cin >> n;

    for(int i=1; i<n; i++){
        int x, y;
        cin >> x >> y;

        graph[x].pb(y);
        graph[y].pb(x);
    }

    dfs(1);
    int resp = (memo[1][0] + memo[1][1])%MOD;

    cout << resp << endl;

    return 0;
}


Measured memory_bytes: 12288
// ARC091
// C - Flip,Flip, and Flip......

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

ll N, M;

ll solve(ll n, ll m) {
    if (n < m) {
        swap(n, m);
    }
    if (n == 1 && m == 1) {
        return 1;
    }
    if (m == 1) {
        return n - 2;
    }
    return max(0LL, n - 2) * max(0LL, m - 2);
}

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

    cout << solve(N, M) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var N = LnInt();
        var As = LnLngs();
        var nums = new long[N + 1];
        for (int i = 0; i < N; i++)
        {
            nums[As[i]]++;
        }
        var combo = new long[N + 1];
        //0~iまでの同じ数字の組み合わせの総数
        combo[0] = nums[0] * (nums[0] - 1L) / 2L;
        for (int i = 0; i < N; i++)
        {
            combo[i + 1] = combo[i] + nums[i + 1] * (nums[i + 1] - 1L) / 2L;
        }

        for (int k = 0; k < N; k++)
        {
            var remove = As[k];
            print(combo[N] - nums[remove] * (nums[remove] - 1L) / 2L + (nums[remove] - 1L) * (nums[remove] - 2L) / 2L);
        }
    }



    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}



Measured memory_bytes: 35008
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main()
{
	long N,V;
	cin >> N ; 
	if(N%2==0){
		V=N/2;
	}else{
		V=(N+1)/2;
	}		
	cout<<V<<endl;

}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str = br.readLine()) != null) {
			String ns[] = str.split(",");
			int count[] = new int[13];
			for(int i = 0; i < 5; i++) {
				count[Integer.parseInt(ns[i]) - 1]++;
			}
			boolean flag = false;
			for(int i = 0; i < 10; i++) {
				if(count[i] == 1) {
					if(count[i+1] == 1 && count[i+2] == 1 && count[i+3] == 1 && count[(i+4) % 13] == 1) {
						System.out.println("straight");
						flag = true;
						break;
					}
				}
			}
			if(flag) continue;
			int pair[] = new int[2];
			int cnt = 0;
			for(int x : count) {				
				if(x >= 2) {
					pair[cnt] = x;
					cnt++;
				}
			}
			if(pair[0] == 4) {
				System.out.println("four card");
				continue;
			} else if(pair[0] == 3 && pair[1] == 2 || pair[0] == 2 && pair[1] == 3) {
				System.out.println("full house");
				continue;
			} else if(pair[0] == 3) {
				System.out.println("three card");
				continue;
			} else if(pair[0] == 2 && pair[1] == 2) {
				System.out.println("two pair");
				continue;
			} else if(pair[0] == 2) {
				System.out.println("one pair");
				continue;
			} else {
				System.out.println("null");
			}
		}
	}
}

Measured memory_bytes: 16932
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int A[n];
	for(int i=0; i<n; i++)	cin>>A[i];
	int q;
	cin>>q;
	while(q--){
		int c,b,e;
		cin>>c>>b>>e;
		if(c==0){
			int mi=1000000000;
			for(int i=b; i<e; i++){
				if(A[i]<mi)	mi=A[i];
			}
			cout<<mi<<endl;
		}
		else if(c==1){
			int ma=-1000000000;
			for(int i=b; i<e; i++){
				if(A[i]>ma)	ma=A[i];
			}
			cout<<ma<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const mod = 1000000007;
int const N = 200010;
int const M = 1001000;
int n, m;
struct edges{ int u, next; } e[M];
int p[N], idx;
void addedge(int u, int v) {
  e[idx].u = v, e[idx].next = p[u], p[u] = idx++;
}
void init() { idx = 0; clr(p, 0xff); }
ll fac[N], inv[N];
ll C(int n, int m) {
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
ll powMod(ll a, ll b) {
  ll ret = 1LL;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
void Cinit() {
  fac[0] = inv[0] = 1LL;
  for (int i = 1; i < N; ++i) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = powMod(fac[i], mod - 2);
  }
}
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
  ll t, ret;
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  ret = ext_gcd(b, a % b, x, y);
  t = x, x = y, y = t - a / b * y;
  return ret;
}
// (b / a) % c
ll inver(ll a, ll b, ll c) {
  ll x, y;
  ext_gcd(a, c, x, y);
  return (1LL * x * b % c + c) % c;
}

int sz[N];
ll down[N];
void dfs1(int u, int pre) {
  sz[u] = 1;
  ll ret = 1;
  for (int i = p[u]; ~i; i = e[i].next) {
    int v = e[i].u;
    if (v == pre) continue;
    dfs1(v, u);
    sz[u] += sz[v];
  }
  ll cs = sz[u] - 1;
  for (int i = p[u]; ~i; i = e[i].next) {
    int v = e[i].u;
    if (v == pre) continue;
    ret *= C(cs, sz[v]); ret %= mod;
    ret *= down[v]; ret %= mod;
    cs -= sz[v];
  }
  down[u] = ret;
}

ll ans[N];
void dfs2(int u, int pre, ll up) {
  //printf("dfs(%d,%d,%lld)\n",u,pre,up);
  ans[u] = C(n - 1, n - sz[u]) * down[u] % mod;
  ans[u] = ans[u] * up % mod;
  for (int i = p[u]; ~i; i = e[i].next) {
    int v = e[i].u;
    if (v == pre) continue;
    ll z = inver(down[v], ans[u], mod);
    z = inver(C(n - 1, sz[v]), z, mod);
    dfs2(v, u, z);
  }    
}

int main() {
  init(); Cinit();
  scanf("%d", &n);
  rep(i, n - 1) {
    int a, b; scanf("%d%d", &a, &b);
    addedge(a, b);
    addedge(b, a);
  }
  dfs1(1, -1);
  dfs2(1, -1, 1);
  Rep(i, n) printf("%lld\n", ans[i]);
  return 0;
}



Measured memory_bytes: 14592
using System;
using System.Collections.Generic;

namespace AtCoder.Abc140
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            char[] s = Console.ReadLine().ToCharArray();

            if(n == 1)
            {
                Console.WriteLine(0);
                return;
            }

            //今の幸福度と、RLの並び、およびLRの並びをそれぞれ数える
            int score = 0;
            if(s[0] == 'R' && s[1] == 'R')
            {
                score++;
            }
            for(int i = 1; i < s.Length -1; i++)
            {
                if(s[i] == 'R')
                {
                    if (s[i + 1] == 'R')
                    {
                        score++;
                    }
                }
                else
                {
                    if (s[i - 1] == 'L')
                    {
                        score++;
                    }
                }
            }
            if (s[n-2] == 'L' && s[n-1] == 'L')
            {
                score++;
            }

            //操作を1度やるたびに、幸福な人が2人増える
            int result = score + (k * 2);
            //ただし、最大幸福度はn-1以上にはならない
            if(result >= n)
            {
                result = n - 1;
            }
            Console.WriteLine(result);
        }
    }
}



Measured memory_bytes: 11488
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	set<int> st;

	int n;
	cin >> n;
	VI a(n);
	rep(i, n) cin >> a[i];

	bool jud = true;

	while (jud) {
		sort(all(a));
		int mem = -1;
		int cnt = 0;
		rep(i, n) {
			if (a[i] != 0 && mem == -1) {
				mem = a[i];
			} else {
				if (a[i] == 0) {
					cnt++;
				}
				a[i] %= mem;
			}
		}

		if (cnt == n - 1) {
			jud = false;
		}
	}
	sort(all(a));
	cout << a[n - 1] << endl;
}




 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;

ll N;
vector<string> s;

void input() {
	scanf("%lld", &N);
	s.assign(N,"");
	rep(i, N) cin>>s[i];
}

void solve() {
	ll ans = 0;
	map<string,ll> m;
	rep(i,N){
		string aa=s[i];
		sort(all(aa));

		m[aa]++;
	}
	
	for(auto mm:m){
		ans+=mm.second*(mm.second-1)/2;
	}

	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 18176
program plus_minus_rectangle
  implicit none
  integer :: h, w, x, y, a(500,500), i, j
  a = 0
  read(*,*) h, w, x, y
  if (mod(h,x).eq.0.and.mod(w,y).eq.0) then
    write(*,'(a)') "No"
    stop
  end if
  write(*,'(a)') "Yes"
  do i = 1, h, x
    do j = 1, w, y
      a(i,j) = 999999
      if (i+x-1.le.h.and.j+y-1.le.w) a(i+x-1,j+y-1) = -1000000
    end do
  end do
  do i = 1, h
    call output(a(i,1:w))
  end do
  stop
contains
  subroutine output(a)
    implicit none
    integer, intent(in) :: a(:)
    integer :: n, i
    n = size(a)
    do i = 1, n
      write(*,'(i0,x)',advance='no') a(i)
    end do
    write(*,*)
    return
  end subroutine output
end program plus_minus_rectangle

Measured memory_bytes: 3200
#include<bits/stdc++.h>
const int maxs=1e9+1;
struct Node
{
    int a,b;
}s[10002];
bool cmp(Node x,Node y)
{
    return x.a<y.a;

}
using namespace std;
int main()
{

   char c[10];
    cin>>c;
    int l=strlen(c);
    if(l==2)
        cout<<c<<endl;
    else
    {
        for(int i=l-1;i>=0;i--)
            cout<<c[i];
        cout<<endl;
    }
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n;
ll dp[100100][2];
vector<int> sq[100100];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void dfs(int u,int fu)
{
	dp[u][0]=1;dp[u][1]=1;
	int len=sq[u].size();
	rep(i,0,len-1)
	{
		int v=sq[u][i];
		if (v==fu) continue;
		dfs(v,u);
		dp[u][0]=dp[u][0]*(dp[v][0]+dp[v][1])%maxd;
		dp[u][1]=dp[u][1]*dp[v][0]%maxd;
	}
}

int main()
{
	n=read();
	rep(i,1,n-1)
	{
		int u=read(),v=read();
		sq[u].pb(v);sq[v].pb(u);
	}
	dfs(1,0);
	printf("%lld",(dp[1][0]+dp[1][1])%maxd);
	return 0;
}


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

using namespace std;
typedef unsigned long long int ll;

int main()
{
    ll n,k,i;
    cin >> n >> k;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin >>arr[i];
    }
    for(i=0;i+k<n;i++)
    {
        if(arr[i]<arr[i+k])
            cout <<"Yes"<< endl;
        else
            cout <<"No"<< endl;
    }
}


Measured memory_bytes: 5176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();
		if (U.equals(S)) {
			System.out.println((A - 1) + " " + B);
		} else {
			System.out.println(A + " " + (B - 1));
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c)<<endl; 
    return 0; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A, B, C = map(int, input().split())
    for b in range(1, B + 1):
        if (A * b) % B == C:
            print('YES')
            exit(0)
    print('NO')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
using System;

namespace PrintTestCases
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 0;;i++)
            {
                string str = Console.ReadLine();
                int input = int.Parse(str);
                if (input == 0)
                    break;
                Console.WriteLine("Case {0}: {1}", i+1, input);

            }
        }
    }
}

Measured memory_bytes: 5776
import java.util.Arrays;
import java.util.Scanner;

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

		int cal[] = new int[3];

		cal[0] = A+B;
		cal[1] = A-B;
		cal[2] = A*B;

		Arrays.sort(cal);
		System.out.println(cal[2]);
	}
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
# C - Traveling Salesman around Lake
# 標準入力の取得
K,N = list(map(int, input().split()))
A_LIST = list(map(int, input().split()))

# 各家間の距離を算出し、その最大値だけ避ける
## 要素0は、A_N～A_1の距離を入れる
diff_list = [A_LIST[i] - A_LIST[i-1] if i != 0 else A_LIST[0] + (K-A_LIST[N-1]) for i in range(N)]
print(K - max(diff_list))

Measured memory_bytes: 26420
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
bool isPrime(int x)
{
	if (x % 2 == 0)
		return false;
	for (int i = 3; i <= sqrt(x); i+=2)
		if (x%i == 0)
			return false;
	return true;
}
int main()
{
	int n;
	cin >> n;
	vector<int> res;
	int temp = n;
	if (isPrime(n))
		res.push_back(n);
	else
	{
		for (int i = 2; i <= n; i++)
		{
			while (temp%i == 0)
			{
				res.push_back(i);
				temp /= i;
			}
			if (temp == 1)
				break;
		}
	}
	cout << n << ":";
	for (int i = 0; i < res.size(); i++)
	{
		cout << " ";
		cout << res[i];
	}
	cout << endl;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
ll MOD = 998244353;
 
using vc = vector<char>;
using vi = vector<int>;
using vll = vector<ll>;

const int MAXN = 1.01e7;

vll fact (MAXN);
vll invfact (MAXN);
vll pow2(MAXN);
vll inv (MAXN);

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        res %= MOD;
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}

ll inverse(ll n) {
    return binpow(n, MOD-2);
}

ll choose(ll n, ll k) {
    return fact[n] * invfact[k] % MOD * invfact[n-k] % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll N; cin >> N;

    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = fact[i-1] * i % MOD;

    inv[1] = 1;
    FOR(i, 2, MAXN) inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

    invfact[0] = 1;
    FOR(i, 1, N+1) invfact[i] = invfact[i-1] * inv[i] % MOD;

    pow2[0] = 1;
    FOR(i, 1, N+1) pow2[i] = 2 * pow2[i-1] % MOD;

    ll ans = binpow(3, N);
    FOR(i, N/2+1, N+1) {
        ans -= 2 * choose(N, i) * pow2[N-i];
        ans = ((ans % MOD) + MOD) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 315904
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n=int(input())
    graph=[[]for _ in range(n)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        graph[u-1].append((v-1,w))
        graph[v-1].append((u-1,w))
    D=[-1]*n
    D[0]=0
    que=deque([0])
    while que:
        q=que.popleft()
        qw=D[q]
        for nn,w in graph[q]:
            if D[nn]==-1:
                D[nn]=qw+w
                que.append(nn)
    for d in D:
        if d%2==0:
            print(0)
        else:
            print(1)


if __name__=='__main__':
    main()

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	int count=0;
	for(int i=0;i<n;i++)
	{
	    if((i+1)%2!=0&&arr[i]%2!=0)
	    {
	        count++;
	    }
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, m, x;
    cin >> n >> m >> x;
    vector<vector<long>> l(n, vector<long>(m+1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m+1; j++){
            cin >> l[i][j];
        }
    }
    long mm = 99999999999999;
    for(int i = 0; i < pow(2, n); i++){
        long price = 0;
        bool z = true;
        vector<long> sum(m+1, 0);
        for(int j = 0; j < n; j++){
            if(!((i >> j) & 0x01)) continue;
            price += l[j][0];            
            for(int o = 1; o < m+1; o++){
                sum[o] += l[j][o];
            }
        }
        for(int o = 1; o < m+1; o++){
            if(sum[o] < x) z = false;
        }
        if(z){
            mm = min(mm, price);
        }
    }
    if(mm == 99999999999999) cout << "-1" << endl;
    else cout << mm << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=3;
    if(a==b)cnt--;
    if(b==c)cnt--;
    if(a==c && cnt==3)cnt--;
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

const int N = 1e2+7;

int n, sum, res;
int a[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 1; i <= n; ++i) {
        res += a[i]*(sum-a[i]);
    }
    cout << res/2 << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N,M = map(int,input().split())
A = list(map(int,input().split()))

sumA = [0] + [0]*N
for i in range(N):
  sumA[i] = (sumA[i-1]+A[i])%M

cnt = Counter(sumA).values()
ans = sum(i*(i-1)//2 for i in cnt)

print(ans)

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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    int dif = 0;
    for(int i=0;i<n;i++){
        if(p[i] != i+1){
            dif++;
        }
    }
    if(dif == 0 || dif == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

all_lis = []

for i in range(N):
    A = list(map(int, input().split()))
    A.pop(0)
    all_lis.extend(A)

ans = 0
ans_lis2 = []

for j in set(all_lis):
    ans = all_lis.count(j)
    ans_lis2.append(ans)

ans2 = 0 
for k in ans_lis2:
    if k == N:
        ans2 = ans2 + 1

print(ans2)
        

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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;
int h,w;
int temp;


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

    cin >> h >> w >> n;

    temp = max(h,w);

    cout << (n+temp-1)/temp << endl;
    


    return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
struct node{int l,r;
}a[300010];
bool cmp(node x,node y){return x.r-x.l<y.r-y.l;}

int tree[100010];
void add(int id,int x){for(;id<=m;id+=id&-id) tree[id]+=x;}
int query(int id){int re=0;for(;id;id-=id&-id) re+=tree[id];return re;}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+n+1,cmp);
    for (int i=1,j=0;i<=m;i++)
    {
        int cnt=0;
        for (int t=i;t<=m;t+=i) cnt+=query(t);
        printf("%d\n",cnt+n-j);
        while (j<n&&a[j+1].r-a[j+1].l<=i)
        {
            add(a[j+1].l,1);
            add(a[j+1].r+1,-1);
            j++;
        }
    }
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

map<char, int> mp[100005];

void solve()
{
  int N;
  cin >> N;
  vector<string> a(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      mp[i][s[j]]++;
    }
    dump(mp[i]);
    for (auto& m : mp[i]) {
      a[i] += string(1, m.first) + to_string(m.second - 1);
    }
    dump(a[i]);
  }
  sort(a.begin(), a.end());
  dump(a);
  ll ans = 0;
  ll cmb = 0;
  int first = true;
  for (int i = 0; i < N - 1; i++) {
    if (a[i].compare(a[i + 1]) == 0) {
      if (first) {
        cmb += 2;
        first = false;
      } else {
        cmb++;
      }
    } else {
      first = true;
      ans += (cmb * (cmb - 1) / 2);
      cmb = 0;
    }
  }
  if (cmb) {
    ans += (cmb * (cmb - 1) / 2);
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 52352
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;typedef vector<int> ivec;typedef vector<string> svec;
int main(){
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			cout << i << "x" << j << "=" << j*i <<"\n";
		}
	}
	return 0;
}



Measured memory_bytes: 2892