akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f1 first 
#define s2 second
#define debug(x...) cerr << #x << ": [" << x << "]\n";
#define fast ios :: sync_with_stdio(); cout.tie(0); cin.tie(0);

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

bool myComp(const int &x, const int &y)
{
	return abs(x) > abs(y);
}

int const N = 2e5 + 7;
ll const mod = 1e9 + 7;
ll ar[N];

inline ll mult(ll x, ll y)
{
	return (x * y) % mod;
}

int main()
{
	fast;

	int n, k;
	cin >> n >> k;

	bool allNegative = true;
	bool zero = false;
	for (int i = 0; i < n; ++i)
	{
		cin >> ar[i];

		if (ar[i] > 0)
			allNegative = false;
		if (ar[i] == 0)
			zero = true;
	}

	ll res = 1;
	if (n == k)
	{
		for (int i = 0; i < n; ++i)
			res = mult(res, ar[i]);
		cout << (res + mod) % mod << '\n';
	}

	else if (allNegative && k % 2 == 1)
	{
		sort(ar, ar+n, greater<int>());
		for (int i = 0; i < k; ++i)
			res = mult(res, ar[i]);
		cout << (res + mod) % mod << '\n';
	}

	else
	{
		sort(ar, ar+n, myComp);
		
		bool negative = false;
		for (int i = 0; i < k; ++i)
			if (ar[i] < 0)
				negative = !negative;


		if (negative)
		{
			ll *a, *b, *c, *d; //a will be swapped with b, c will be swapped with d
			a = b = c = d = NULL;
			for (int i = k-1; i >= 0; --i)
			{
				if (a == NULL && ar[i] < 0) a = &ar[i];
				else if (b == NULL && ar[i] > 0) b = &ar[i];
			}

			for (int i = k; i < n; ++i)
			{
				if (c == NULL && ar[i] > 0) c = &ar[i];
				else if (d == NULL && ar[i] < 0) d = &ar[i];
			}

			if ((a == NULL || c == NULL) && (b == NULL || d == NULL) && zero) *a = 0;
			else if (a == NULL || c == NULL) swap(*b, *d);
			else if (b == NULL || d == NULL) swap(*a, *c);
			else if (abs(*b) * abs(*c) > abs(*a) * abs(*d)) swap(*a, *c);
			else swap(*b, *d);
		}

		for (int i = 0; i < k; ++i)
			res = mult(res, ar[i]);
		cout << (res + mod) % mod << '\n';
	}
	return 0;
}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if(b < c){ll tmp = b; b = c; c = tmp;}
    if(a < b){ll tmp = a; a = b; b = tmp;}
    
    rep(i, 1, k){a *= 2;}
    print(a+b+c)
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
#include<functional>
#include<cassert>
using namespace std;
#define ll long long
int main(){
    string S,T;
    cin >> S >> T;
    ll i;
    map <char,char> mp;
     map <char,char> mp2;
    for(i=0;i<S.size();i++){
        if(mp.count(S[i])==0){
            mp[S[i]]=T[i];
        }
        if(mp2.count(T[i])==0){
            mp2[T[i]]=S[i];
        }
        if(mp[S[i]]!=T[i]||mp2[T[i]]!=S[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

typedef long long ll;

int main() {
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  //相対座標を考えるんですよこのバカ
  //交差する回数ならどう考えても相対座標考えたほうが楽でしょこのバカ
  ll p = (a1 - b1) * t1;
  // 相対座標を考えた時にまずp動く
  ll q = (a2 - b2) * t2;
  // 次にq動く
  if (p > 0) {
    p = -1 * p;
    q = -1 * q;
  }
  // p<0についてのみ考える。
  if (p + q < 0) {
    // ずっと下にいき続ける
    // 一回も軸と交わらない
    cout << 0 << endl;
    return 0;
  }
  if (p + q == 0) {
    // 毎回軸に戻ってくる
    cout << "infinity" << endl;
    return 0;
  }
  if (p + q > 0) {
    // めんどい
    ll s = -1 * p / (p + q);
    ll t = -1 * p % (p + q);
    // 1ステップでの上がり幅の積み重ねが一回での下がり幅を超えたらよさそう
    if (t != 0) {
      cout << 2 * s + 1 << endl;
      return 0;
    } else {
      // 最後で軸にふれる場合
      cout << 2 * s << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B,C;cin >> A >> B >> C;
  YesNo(A+B>=C);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 100000000

int main(){
    int n;
    cin >> n;
    vint H(n);
    rep(i,n) cin >> H[i];
    vint ans(n);
    ans[0] = 0;
    ans[1] = abs(H[1]-H[0]);
    for(int i = 2;i<n;i++){
        if(ans[i-2] + abs(H[i-2] - H[i]) < ans[i-1] + abs(H[i-1] - H[i])){
            ans[i] = ans[i-2] + abs(H[i-2] - H[i]);
        }
        else{
            ans[i] = ans[i-1] + abs(H[i-1] - H[i]);
        }
    }
    cout << ans[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>

int main()
{
	double r,pai = 3.14159265358979323846264338;
	std::cin >> r ;
	std::cout << std::fixed;
	std::cout << std::setprecision(6) << r * r * pai << " " << r * 2 * pai;

    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int n; std::cin >> n;
    std::vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; i++) std::cin >> a[i];
    for(int i=0; i<n; i++) std::cin >> b[i];
    for(int i=0; i<n-1; i++) std::cin >> c[i];
    int sum = 0, prev = -100;
    
    for(int i=0; i<n; i++)
    {
        sum += b[a[i]-1];
        if(prev == a[i]-1)
        {
            std::cerr << c[prev-1] << std::endl;
            sum += c[prev-1];
        }
        prev = a[i];
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
v = list(map(int,input().split(" ")))
e,o = [],[]
e = v[::2]
o = v[1::2]

ec = collections.Counter(e).most_common(2)
oc = collections.Counter(o).most_common(2)

if ec[0][0] != oc[0][0]:
    print(n - ec[0][1] - oc[0][1])
else:
    if len(ec) == 1:
        print(n // 2)
    else:
        print(n - max(ec[0][1] + oc[1][1], ec[1][1] + oc[0][1]))

Measured memory_bytes: 15972
#include<iostream>
#include<cstdio>
#include<cstring>
int main()
{
    std::string tin[101],ret[202];
    int h,w;
    std::cin>>h>>w;
    int j=0;
    for(int i=0;i<h;i++){
        std::cin>>tin[i];
        ret[j]=tin[i];
        j+=2;
    }
    for(int i=1;i<2*h;i+=2){
        ret[i]=tin[i/2];
    }
    for(int i=0;i<2*h;i++){
        std::cout<<ret[i]<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(void){
    int n,d,tmp;
    cin >> n >> d;
    tmp = 2*d+1;
    if(n % tmp == 0) cout << n/tmp << endl;
    else cout << n/tmp + 1 << endl;;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
LL get(int level,LL h){
  if(level==0)return 1;
  LL s=pow(LL(2),level+2)-3;
  if(h==1)return 0;
  if(h==s)return pow(LL(2),level+1)-1;
  if(h<=(s-1)/2)return get(level-1,h-1);
  if(h==(s+1)/2)return get(level-1,(s-1)/2-1)+1;
  return get(level-1,(s-1)/2-1)+1+get(level-1,h-(s+1)/2);
}
int main(){
  int N;LL X;cin>>N>>X;
  cout<<get(N,X)<<endl;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P[i];

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

  int ans = 0;
  while (true) {
    bool flag = false;
    int i = 0;
    for (int j = 0; j < N; j++) {
      if (P[j] == -1) continue;

      if ((i == 0 && P[j] <= A) ||
        (i == 1 && P[j] > A && P[j] <= B) ||
        (i == 2 && P[j] > B)) {
        i++;
        P[j] = -1;
      }

      if (i == 3) {
        flag = true;
        break;
      }
    }

    if (flag) ans++;
    else break;
  }

  cout << ans << endl;
}

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

int h, w;
const int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
vector<string> donut;
bool visited[10][20];

inline unsigned long long hash(const string& s) {
	const unsigned long long base = 1000000007;
	long long res = 0;
	for(int i = 0; i < s.size(); ++i) {
		res *= base;
		res += s[i];
	}

	return res;
}

inline string spell(int x, int y, int d) {
	if(visited[y][x])
		return "";

	visited[y][x] = true;
	string res = donut[y][x] + spell((x + dx[d] + w) % w, (y + dy[d] + h) % h, d);
	visited[y][x] = false;
	return res;
}

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

	const string init(2, 'z' + 1);

	while(cin >> h >> w, h) {
		donut.clear();
		donut.resize(h);
		for(int i = 0; i < h; ++i)
			cin >> donut[i];

		string ans = init;
		set<unsigned long long> s;
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				for(int d = 0; d < 8; ++d) {
					const string str = spell(j, i, d);
					for(int i = ans.size(); i <= str.size(); ++i) {
						const string tmp = str.substr(0, i);
						const unsigned long long h = hash(tmp);
						if(s.find(h) == s.end())
							s.insert(h);

						else if(ans.size() < tmp.size() || (ans.size() == tmp.size() && tmp < ans))
							ans = tmp;
					}
				}
			}
		}

		cout << (ans != init ? ans : "0") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 7408
import sys

n, m = input().strip().split(" ")
n = int(n) ;m = int(m)

c = n

a = []
for line in sys.stdin :
    a.append(line)
    c -= 1
    if c == 0 :
        break
for i in range(0, len(a)) :
    a[i] = a[i].strip().split(" ")
    for j in range(0, len(a[i])) :
        a[i][j] = int(a[i][j])

for r in range(0, len(a)) :
    a[r].append(sum(a[r]))

arr = []
for c in a[0] :
    arr.append(0)
for r in range(0, len(a)) :
    for c in range(0, len(a[i])) :
        arr[c] += a[r][c]
a.append(arr)

for i in a :
    for j in range(0, len(i)) :
        if j != len(i)-1 :
            print(str(i[j]), end=" ")
        else :
            print(str(i[j]), end="")

    print()



Measured memory_bytes: 6188
var
  a,f:array[0..1000,0..1000] of longint;
  n,m,q,i,j,k,x,y:longint;
begin
  readln(n,m,q);
  for i:=1 to m do
    begin
      readln(x,y);
      inc(a[x,y]);
    end;
  for i:=1 to n do
    for j:=i to n do
      begin
        f[i,j]:=f[i,j-1];
        for k:=i to j do
          inc(f[i,j],a[k,j]);
      end;
  for i:=1 to q do
    begin
      readln(x,y);
      writeln(f[x,y]);
    end;
end.

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {

  int N;
  cin >> N;
  vector<int> a;

  for (int i=0;i<N;i++){
    int in;
    cin >> in;
    a.push_back(in);
  }

  int count = 0;
  int test;
  while(a.size()>0){
    test = a.back();
    while (test % 2 == 0){
      test = test / 2;
      count++;
    }
    a.pop_back();
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 384
def solve_b(n, d_list):
    s1 = sum(d_list)
    s2 = sum([d ** 2 for d in d_list])
    res = (s1 ** 2 - s2) // 2
    return res


def main():
    n = int(input())
    d_list = list(map(int, input().split()))
    res = solve_b(n, d_list)
    print(res)


def test():
    assert solve_b(3, [3, 1, 2]) == 11
    assert solve_b(7, [5, 0, 7, 8, 3, 3, 2]) == 312


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
using System;

namespace ITP1_1_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int num;
            var s = Console.ReadLine();
            if(int.TryParse(s,out num) == false)
            {
                num = 0;
            }
            num = (int)(Math.Pow(num, 3));
            Console.WriteLine(num.ToString());
        }
    }
}

Measured memory_bytes: 9340
#include<stdio.h>
#define MAX 100000
#define NIL -1

void print(int );
int rec(int, int);

struct Node {

  int parent,left,right;

};

struct Node Nodedata[MAX];

int n; /*ノード総数*/
int D[MAX];

int main(){

  int i,j,d,v,c,l,r,sumnode;

  l = 0;

  scanf("%d",&n);

  sumnode = n;

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

    Nodedata[i].parent = NIL;
    Nodedata[i].left = NIL;
    Nodedata[i].right = NIL;

  }

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

    scanf("%d",&v); /*ノードID*/
    scanf("%d",&d); /*ノードデータ総数*/

    for(j = 0; j < d; j++){

      scanf("%d",&c); /*ノードデータ成分入力*/

      if(j == 0){ /*ノードデータの筆頭は左の成分*/

	Nodedata[v].left = c;

      }

      else{

	Nodedata[l].right = c;

      }

      l = c;

      Nodedata[c].parent = v;

    }

  }

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

    if(Nodedata[i].parent == NIL){

      r = i;
    }
  }
    rec(r,0);

    for(i = 0; i < sumnode; i++){

      print(i);

    }

    return 0;
}

void print(int u){

  int i,c;

  printf("node %d: ",u);
  printf("parent = %d,",Nodedata[u].parent);
  printf(" depth = %d, ",D[u]);

  if(Nodedata[u].parent == NIL){

    printf("root,");

  }


  else if(Nodedata[u].left == NIL){

    printf("leaf,");

  }

  else{

    printf("internal node,");

  }

  printf(" [");

  for(i = 0, c = Nodedata[u].left ; c != NIL ; i++,c= Nodedata[c].right){
 
    if(i) {

      printf(", ");

    }

    printf("%d",c);

  }

  printf("]\n");

}

int rec (int u, int p){

  D[u] = p;

  if(Nodedata[u].right != NIL){

    rec(Nodedata[u].right,p);

  }

  if(Nodedata[u].left != NIL){

    rec(Nodedata[u].left, p+1);

  }

}

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

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

typedef int64_t ll;

const ll INF = 1e18;

const int MAXN = 3001;

int N;
vector<int> a;

ll fmemo[MAXN][MAXN];
ll smemo[MAXN][MAXN];

ll second(int, int);

ll first(int l, int r) { // inclusive
  if (l > r) return 0;
  if (fmemo[l][r] != INF) return fmemo[l][r];

  ll ret = max(second(l + 1, r) + a[l], second(l, r - 1) + a[r]);
  // cout << "first: " << l << " " << r << ", " << ret << endl;
  return fmemo[l][r] = ret;
}

ll second(int l, int r) { // inclusive
  if (l > r) return 0;
  if (smemo[l][r] != INF) return smemo[l][r];

  ll ret = min(first(l + 1, r) - a[l], first(l, r - 1) - a[r]);
  // cout << "second: " << l << " " << r << ", " << ret << endl;
  return smemo[l][r] = ret;
}
int main(){
  cin >> N;
  a.resize(N);
  REP(i,N) cin >> a[i];

  REP(i,MAXN)REP(j,MAXN) fmemo[i][j] = INF;
  REP(i,MAXN)REP(j,MAXN) smemo[i][j] = INF;

  cout << first(0, N-1) << endl;
  return 0;
}



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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const long long INF=(LL)(1e9)*(LL)(1e9);


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

    int n,m,k;
    cin>>n>>m>>k;
    bool flag=0;
    REP(i,n+1)
    REP(j,m+1)
    {
        if(i*j+(n-i)*(m-j)==k)
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

def Sieve_of_Eratosthenes(n):
  is_prime = [True] * (n+1)
  is_prime[0] = False
  is_prime[1] = False
  for i in range(2, int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2, n+1, i):
      is_prime[j] = False
  #return is_prime
  return [i for i in range(n+1) if is_prime[i] and i%5 == 1]

ans = Sieve_of_Eratosthenes(55555)

print(*ans[:N])

Measured memory_bytes: 9332
#include<cstdio>
#include<iostream>
using namespace std;

int gcm(int a,int b){
	int c=a%b;
	while(c!=0){
		a=b;
		b=c;
		c=a%b;
        }
	return b;
}

int main(){
	int x[2],y[3],sum[3];
	double ans[2];
	while(cin>>x[0]>>y[0]>>sum[0]>>x[1]>>y[1]>>sum[1]){
		if(x[0]==0){
			ans[1]=(double)sum[0]/y[0];
			ans[0]=(sum[1]-y[1]*ans[1])/x[1];
		}else if(x[1]==0){
			ans[1]=(double)sum[1]/y[1];
			ans[0]=(sum[0]-y[0]*ans[1])/x[0];
		}else if(y[0]==0){
			ans[0]=(double)sum[0]/x[0];
			ans[1]=(sum[1]-x[1]*ans[0])/y[1];
		}else if(y[1]==0){
			ans[0]=(double)sum[1]/x[1];
			ans[1]=(sum[0]-x[0]*ans[0])/y[0];
		}else{
			y[2]=y[0]*x[1]-y[1]*x[0];
			sum[2]=sum[0]*x[1]-sum[1]*x[0];
			ans[1]=(double)sum[2]/y[2];
			ans[0]=(sum[0]-y[0]*ans[1])/x[0];
		}
		printf("%.3f %.3f\n",ans[0],ans[1]);
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<vector<pair<int,int>>> vv(n, vector<pair<int, int>>());
	rep(i, n-1){
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		vv.at(u).push_back(make_pair(v, w));
		vv.at(v).push_back(make_pair(u, w));
	}
	vector<int> ans(n, -1);
	ans.at(0) = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		int p = q.front(); q.pop();
		int now = ans.at(p);
		for(auto pp : vv.at(p)){
			if(ans.at(pp.first) != -1) continue;
			q.push(pp.first);
			// cerr << pp.first << " " << pp.second << endl;
			if(pp.second % 2 == 0) ans.at(pp.first) = now;
			else ans.at(pp.first) = now^1;
		}
	}
	rep(i, n){
		cout << ans.at(i) << endl;
	}
	return 0;
}

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

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

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second

/*-------------------------------------------------*/

int main(){
  int n, ans = 0;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];

  sort(all(L));

  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n-1; j++){
      for(int k = j + 1; k < n; k++){
        if(L[k] < L[i] + L[j] &&
           L[i] != L[j] &&
           L[j] != L[k] &&
           L[k] != L[i] )
          ans++;
      }
    }
  }
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x ,ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  ll ans;
  vl vec(n);
  rep(i,n) cin >> vec[i];
  ans=vec[0];
  rep(i,n)ans=gcd(ans,vec[i]);
  cout << ans << endl;
  return 0;     
}


Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();

            out.println(Integer.toString(N, K).length());
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mv = 200003;
int h[mv], n, m, hi, a, b, c= 0;
vector<int> adj[mv];
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> hi; h[i] = hi;
    }
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i = 1; i <= n; i++){
        bool flag = false;
        if(adj[i].size() > 0){
            for(int j = 0; j < adj[i].size(); j++){
                int x = adj[i][j];
                if(h[x] < h[i])continue;
                else{
                    flag = true; break;
                }
            }
        }
        if(!flag)c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 11496
from collections import Counter
def get_prime_factors(x):
    out = []
    if x < 1:
        return out
    while not x%2:
        out.append(2)
        x //= 2
    i = 3
    while i*i <= x:
        if not x%i:
            out.append(i)
            x //= i
        else:
            i += 2
    if x != 1:
        out.append(x)
    return out
def main():
    n = int(input())
    primes = Counter(get_prime_factors(n))
    ans = 0
    for prime, num in primes.items():
        i = 1
        while num >= i:
            ans += 1
            num -= i
            i += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9360
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */
import java.util.*;
import java.io.*;

class Mod{
    static final int MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }
    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[M];
        for(int n=0; n<N; n++) A[n]=sc.nextInt();
        for(int m=0; m<M; m++) B[m]=sc.nextInt();
        Arrays.sort(A);
        Arrays.sort(B);


        int n=0;
        int m=0;
        long ans = 1;
        for(int e=N*M; e>0; e--){
            if(n<N && A[N-n-1]==e){
                if(m<M && B[M-m-1]==e){
                    n++; m++;
                    ans = Mod.mult(ans, 1);
                }
                else{
                    n++;
                    ans = Mod.mult(ans, m);
                }
            }else{
                if(m<M && B[M-m-1]==e){
                    m++;
                    ans = Mod.mult(ans, n);
                }
                else{
                    ans = Mod.mult(ans, n*m - (N*M-e));
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 45204
/**
 * File              : D-review.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 09.02.2020
 * Last Modified Date: 09.02.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> dp(10, vector<int>(10, 0));
    for (int i = 1; i <= n; i++) {
        string s = to_string(i); 
        dp[s.front() - '0'][s.back() - '0']++;
    }
    ll res = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            res += dp[i][j] * 1LL * dp[j][i];
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
n,k=input().split()
n=int(n)
k=int(k)
a=[int(x) for x in input().split()]


dp=[1e18]*n
dp[0]=0


dp[1]=abs(a[1]-a[0])

m=pow(10,10)

for i in range(2,n):
    m=pow(10,10)
    for j in range(1,k+1):
        if i-j>=0:
            m=min(m,dp[i-j]+abs(a[i]-a[i-j]))
    dp[i]=m
    
    
        

print(dp[n-1])    
        

    
    


Measured memory_bytes: 55392
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	int cnt=0;
	int ans=0;
	long long mod=(1e+9)+7;
	long long n;
	cin>>n;
	vector<string> s(n);
	string t;
	t.clear();

	for(int i=0;i<n;i++) cin>>s[i];

	for(char c='a';c<'z'+1;c++){
		int cc=INT_MAX;

		for(int i=0;i<n;i++){
			cnt=0;
			for(int j=0;j<s[i].size();j++)
				if(s[i][j]==c)cnt++;
			cc=min(cc,cnt);
		}
		if(cc!=INT_MAX)
			for(int i=0;i<cc;i++) t+=c;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    string t(w,'.'),s;
    vector<string> q;
    for(int i=0;i<h;i++){
        cin >> s;
        if(s==t){continue;}
        else q.emplace_back(s);
    }

    h=q.size();
    vector<int> p;
    int cnt=0;
    for(int i=0;i<w;i++){
        cnt=0;
        for(int j=0;j<h;j++){
            if(q[j][i]=='#'){
                break;
            }
            cnt++;
        }
        if(cnt==h){
            p.emplace_back(0);
        }
        else p.emplace_back(1);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(p[j]==0){continue;}
            else cout << q[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  long int x,y,z,a;
  cin>>x>>y;


  if(x>=0&&y>=0)
  {
      if(x>y)
     {
         z=x-y+2;
         if(y==0){cout<<x-y+1;}else{cout<<z;}
     }
     else{
        z=y-x;
        cout<<z;
     }

  }
  else if (x>=0&&y<=0){
        z=-x-y+1;
        a=x+y+1;


        if(x>=-y){cout<<a;}
        else{cout<<z;}

  }
  else if(x<=0&&y>=0){if (y>=-x){cout<<x+y+1;}else if(y==0){cout<<-x;}else{cout<<-x-y+1;}}
  else if(x<=0&&y<=0){if(x>y)
     {
         z=x-y+2;
         cout<<z;
     }
     else{
        z=y-x;
        cout<<z;
     }
     }

    return 0;
}


Measured memory_bytes: 3608
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, x] = input[0].split(" ").map((x: string): number => +x);
const l = input[1].split(" ").map((x: string): number => +x);

let result = 1;
let sum = 0;
for (let i = 0; i < n; i++) {
  sum += l[i];
  if (sum > x) break;
  result++;
}
console.log(result);


Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var q = int.Parse(Console.ReadLine());

        var flag = true;

        var list = new LinkedList<string>();
        foreach (var c in s)
        {
            list.AddLast(c.ToString());
        }

        for (var i = 0; i < q; i++)
        {
            var query = Console.ReadLine().Split();
            
            if (query[0] == "1")
            {
                flag = !flag;
                continue;
            }
            else if (query[1] == "1")
            {
                if (flag)
                    list.AddFirst(query[2]);
                else
                    list.AddLast(query[2]);
            }
            else if (query[1] == "2")
            {
                if (flag)
                    list.AddLast(query[2]);
                else
                    list.AddFirst(query[2]);
            }
        }

        var array = list.ToArray();

        var sb = new StringBuilder();
        if (flag)
        {
            for (var i = 0; i < array.Length; i++)
            {
                sb.Append(array[i]);
            }
        }
        else
        {
            for (var i = array.Length - 1; i >= 0; i--)
            {
                sb.Append(array[i]);
            }
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 41000
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 n = 100;
        char[][] ch = new char[n][n];
        for (int i = 0; i < n/2; i++) {
            Arrays.fill(ch[i], '#');
        }
        for (int i = n/2; i < n; i++) {
            Arrays.fill(ch[i], '.');
        }
        
        int h = 1;
        int w = 1;
        for (int i = 1; i < a; i++) {
            ch[h][w] = '.';
            w += 2;
            if (w >= n-1) {
                w = 1;
                h += 2;
            }
        }
        
        h = 51;
        w = 1;
        
        for (int j = 1; j < b; j++) {
            ch[h][w] = '#';
            w += 2;
            if (w >= n-1) {
                w = 1;
                h += 2;
            }
        }
        
        System.out.println("100 100");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(ch[i][j]);
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 27604
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<int,int> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int keta(int p){
  //cout<<log(p)/log(10)<<endl;
	//return log10(p);
  int d=0;
  while(p){
    p/=10;
    d++;
  }
  return d;
}
int main(){
	long long n;
	cin>>n;
	int min=keta(n);
	for(long long i=1;i*i<=n;i++){
		if(n%i!=0) continue;
			long long j;
			j=n/i;
			int tmp;
			tmp=max(keta(i),keta(j));
			if(min>tmp) {
              min=tmp;
              //cout<<i<<j<<endl;
            }
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	int max = 0;
	int x, y;
	int ans = 0;
	rep(i, n) {
		cin >> x >> y;
		if (x > max) {
			max = x;
			ans = max + y;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

	  while(true){
	     int H = sc.nextInt();
	     int W = sc.nextInt();
	     
		 if ( H == 0 && W == 0) break;
	     
		 for ( int i = 0; i < H; i++ ){
			    for ( int j = 0; j < W; j++ ){
			        if(i % 2 == 0 && j % 2 == 1 || i % 2 == 1 && j % 2 == 0){
			            System.out.print(".");
			        } else {
			            System.out.print("#");
			        }
			    }
			    System.out.println("");
		 }
	     System.out.println();	
	  }
   }
}



Measured memory_bytes: 32796
#include <iostream>

int main(void){
  int M1, D1, M2, D2;
  std::cin >> M1 >> D1 >> M2 >> D2;
  if(M1<M2 || (M1 ==12 && M2==1)){
    std::cout << 1;
  }else{
    std::cout << 0;
  }
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>

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

void Empty(int *, int *);
void swap(int *, int *);
int Cal();
int DFS(int, int, int, int, int);

int main(){
  int i, j, l;
  int x, y, a;

for(i=0;i<4;i++)
  for(i = 0 ; i < 4 ; i++){
    for(j = 0 ; j < 4 ; j++){
      scanf("%d",&Puzzle[i][j]);
    }
  }

  Empty(&x,&y);

  for(l = 0 ; l < 100 ; l++){
    for(i = 0 ; i < 4 ; i++){
      for(j = 0 ; j < 4 ; j++){
 tmp[i][j] = Puzzle[i][j];
      }
    }

    a = DFS(x, y, -1, 0, l);
    if(a != -1){
      printf("%d\n",a);
      break;
    }

    for(i = 0 ; i < 4 ; i++){
      for(j = 0 ; j < 4 ; j++){
 Puzzle[i][j] = tmp[i][j];
      }
    }

    a = -1;
    if(l == 99) printf("%d\n",a);
  }

  return 0;
}

void Empty(int *x, int *y){
  int i, j;

  for(i = 0 ; i < 4 ; i++){
    for(j = 0 ; j < 4 ; j++){
      if(!Puzzle[i][j]){
 *x = j;
 *y = i;
 return;
      }
    }
  }
}

void swap(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}


int Cal(){
  int i, a;
  int sum = 0;

  for(i = 0 ; i < 16 ; i++){
    a = Puzzle[i/4][i%4];
    if(a){
      a--;
      sum += abs(i/4 - a/4)  + abs(i%4 - a%4);
    }
  }

  return sum;
}

int DFS(int x, int y, int p, int dep, int limit){
  int i, h, nx, ny, res;

  h = Cal();

  if(h == 0) return dep;
  if(dep + h > limit) return -1;

  for(i = 0 ; i < 4 ; i++){
    nx = x + dx[i];
    ny = y + dy[i];

    if(~p && i == (p+2)%4) continue;
    if(!(0 <= nx && nx < 4 && 0 <= ny && ny < 4)) continue;

    swap(&Puzzle[y][x], &Puzzle[ny][nx]);
    res = DFS(nx, ny, i, dep+1, limit);
    if(~res) return res;

    swap(&Puzzle[y][x], &Puzzle[ny][nx]);
  }

  return -1;
}




Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

const int N = 1000000; 
int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	vi a(n); 
	vi mp(1000005); 
	multiset<int > ans; 
	set < int > st; 
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
		mp[a[i]]++; 
		ans.insert(a[i]); 
		st.insert(a[i]); 
	}	


	for(auto i : st)
	{
		for(int j = i + i; j <=  N; j += i)
			ans.erase(j); 
	}

	int fa = 0; 

	for(auto i : ans)
		if(mp[i] == 1)
			 ++fa; 
	

	cout << fa; 

	return 0;
}	

Measured memory_bytes: 31388
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int n, k;
vector<int> a;
vector<int> dp(100005, -1);

int memo_rec(int rest = k){
    if(dp[rest] != -1)  return dp[rest];
    if(rest == 0)   return dp[rest] = 0;

    int is_win = 1;
    bool is_possible = false;
    for(int i = 0; i < n; ++i){
        if(a[i] > rest) continue;
        is_possible = true;
        is_win &= memo_rec(rest - a[i]);
    }
    if(!is_possible)    return dp[rest] = 0;
    return dp[rest] = is_win ^ 1;
}

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

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

    if(memo_rec())  cout << "First\n";
    else    cout << "Second\n";
}

Measured memory_bytes: 6912
import copy
N = int(input())
As = []
for i in range(N):
    As.append(int(input()))
maxA = max(As)
instA = As.copy()
instA.remove(maxA)
secA = max(instA)
for i in range(N):
    if As[i] == maxA:
        print(secA)
    else:
        print(maxA)

Measured memory_bytes: 14560
#include <iostream>
#include<math.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    if(a==0&&b!=100){
        cout << b <<endl;
    }else if(a==0&&b==100){
        cout <<b+1<<endl;
        
    }else if(b!=100){
        cout << b*pow(100,a)<<endl;
    }else if(a==1){
        cout <<101*pow(100,a)<<endl;
    }else{
        cout <<1010000<<endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <limits.h>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const int INF=INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << ((H - h) * (W - w)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

//sに現れた文字種類
int count(string s){
    map<char,int> ans;
    rep(i,s.size())ans[s[i]]=1;
    return ans.size();
}


rpriquest func(int n){
    rpriquest ans;
    if(n==1){
        ans.push("a");return ans;
    }
    rpriquest last=func(n-1);
    while(!last.empty()){
        string now=last.top();last.pop();
        rep(i,count(now)+1){
            char k='a'+i;
            ans.push(now+k);
        }
    }
    return ans;
}

int main(){
    int n;cin >> n;
    rpriquest ans=func(n);
    while(!ans.empty()){
        cout << ans.top() << endl;
        ans.pop();
    }
}

Measured memory_bytes: 7884
#include<stdio.h>
int a[]={61,230,865,3247,12185,45719,171531,643550,2414454,9058467,33985227,127504505,478366600,794717734,733354121,261943303,776803305,580025381,51688048,44657419,737209731,604119499,159693437,858533109,639056669,549054109,996291083,531294469,23314687,783022045,855462856,649970414,68697295,409213624,604356692,88638656,978442997,534833116,763737161,785892908,123883652,639213333,181836645,998121103,124885216,501575626,39816123,113468411,799008836,775465589,256852905,664630886,971550783,751629411,51018086,702530485,725438992,696683714,792638194,221791721,149602322,414054379,986519078,981760191,305799096,515140586,406959393,975058685,245601370,324759692,673385295,191483611,570246669,427196161,781042769,569725155,842176273,25328739,847501730,206282374,353770801,323137024,371653459,940737264,123820509,915711339,847205021,252858375,718889563,866398347,738390145,133009077,333099663,170591295,329869205,616680192,597534442,388130742};main(n){scanf("%d",&n);printf("%d",a[n-3]);}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char prev = 's';

        for (char c : s.toCharArray()) {

            if (prev == c) {
                System.out.println("Bad");
                return;
            }
            prev = c;
        }
        System.out.println("Good");
    }
}


Measured memory_bytes: 23124
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
    
MOD = 10**9 + 7
N, K = map(int, input().split())
com = Combinatorics(N, MOD)
ans = 0
for i in range(min(K, N-1) + 1):
    ans += (com.binom(N, i) * com.hom(N-i, i)) % MOD
    ans %= MOD
print(ans)

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

int main() {
  string s;
  int q;
  int count = 0;
  cin >> s >> q;
  deque<char> dec;
  for(char i : s){
    dec.push_back(i);
  }
  for(int i=0;i<q;i++){
    int num;
    cin >> num;
    if (num == 1){
      count += 1;
    }
    else{
      int a;
      char b;
      cin >> a >> b;
      if ((a==1 && count%2 ==0)||(a==2 && count%2 == 1)){
        dec.push_front(b);
      }
      else if ((a==2 && count%2 ==0)||(a==1 && count%2 == 1)){
        dec.push_back(b);
      }
    }
  }
  if (count%2 == 1){
    reverse(dec.begin(),dec.end());
  }
  for(char i:dec){
    cout << i;
  }
  cout << endl;
}


Measured memory_bytes: 1024
import math
x = 0.0;
y = 0.0;
a = 90.0;
while True :
    distance, angle = map(float, input().split(","))
    if distance == 0 and angle == 0: break

    radangle = math.radians(a)

    x += math.cos(radangle) * distance
    y += math.sin(radangle) * distance
    a -= angle

print(int(x))
print(int(y))

Measured memory_bytes: 7688
#include<iostream>
#include<algorithm>
#include<cassert>
#include <vector>
#include <cstring>
using namespace std;


struct ball
{
    char name[12];
    int count;
};

int main()
{

    ball s,t;
    char ch[12];
    cin>>s.name>>t.name>>s.count>>t.count;
    cin>>ch;

    if(strcmp(ch,s.name) == 0) s.count --;
    else t.count --;

    cout<<s.count<<" "<<t.count;
}


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

int main() {
  int N, counter;
  vector<int> vec(N);
  counter = 0;
  cin >> N;
  for (int i = 0; i < N; i++){
    int a;
    cin >> a;
    vec.at(i) = a-1;
  }
  for (int i = 0; i < N; i = vec.at(i)){
    counter++;
    if (counter == N){
      counter = -1;
      break;
    }
    else if (vec.at(i) == 1){
      break;
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    cout << min((n / a + (n % a != 0)) * b, (n / c + (n % c != 0)) * d) << endl;
    return 0;
}


Measured memory_bytes: 3116