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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



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

  ll n = s.size();

  ll res = 0;

  ll l = 0;
  ll a = 0;
  ll bc = 0;
  ll sum = 0;
  for(ll i = 0; i < n; i++){
    if(s[i] == 'A') a++;    
    else if(s.substr(i, 2) == "BC"){
      bc++;
      sum += a;
      i++;
    }
    else{
      res += sum;
      l = i+1;
      a = bc = sum = 0;
    }
  }
  res += sum;

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 720
S = input()

odd = ["R", "U", "D"]
even = ["L", "U", "D"]

flag = True
for i in range(len(S)):
    if (i + 1) % 2 == 0:
        if S[i] not in even:
            print("No")
            flag = False
            break
    else:
        if S[i] not in odd:
            print("No")
            flag = False
            break

if flag:
    print("Yes")


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

void test_case(){
    
}

int main() {
    fastio
    int n, k;
    cin >> n >> k;
    int res = 0;
    while(n > 0){
		n = n/k;
		res++;
	}
	cout<<res<<endl;
	return 0;
}






Measured memory_bytes: 256
n, m = list(map(int, input().split()))
dic = {}

for _ in range(m):
  pi, si = input().split()
  pi = int(pi)
  if pi in dic:
    dic[pi].append(si)
  else:
    dic[pi] = [si]

a = 0
p = 0

for s in dic.values():
  if 'AC' in s:
    a += 1
    p += s.index('AC')

print('%s %s'%(int(a), int(p)))

Measured memory_bytes: 28104
d, n = map(int,input().split())
if d==0:
    if n==100:
        print("101")
    else:
        print(1*n)
elif d==1:
    if n==100:
        print("10100")
    else:
        print(100*n)
else:
    if n==100:
        print("1010000")
    else:
        print(10000*n)
    

Measured memory_bytes: 2940
package main

import "fmt"

func main() {
  var n, m, k, p, pass int
  fmt.Scan(&n, &m)

  // 箱の初期化
  counter := make([]int, m)
  for i := 0; i < m; i++ {
    counter[i] = 0
  }
  
  for j := 0; j < n; j++ {
    // n人目のlikeの個数
    fmt.Scan(&k)
    
    // k個分ループ
    for l := 0; l < k; l++ {
      fmt.Scan(&p)
      counter[p-1]++
    }
    
  }
  
  pass = 0
  for a := 0; a < m; a++ {
    if counter[a] == n {
      pass++
    }
  }
  
  fmt.Println(pass)
  
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for _ in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(400):
        for j in range(400):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 80476
s = gets.chomp.to_s
leng = s.length
rang = (leng + 1) / 2
sub_list = [""]

for i in 0..leng-1 do
  for j in 0..leng - 1 - i do
    sub_list.unshift(s[i..i+j])
  end
end

sub_list = sub_list.uniq
ans = -1

for str in sub_list do
  a_count = str.count("A")
  c_count = str.count("C")
  g_count = str.count("G")
  t_count = str.count("T")
  leng = str.length

  if (a_count + c_count + g_count + t_count) == leng
    s_leng = str.length
    ans = s_leng if s_leng > ans
  end
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 string s;
	 int ans=0;
	 cin>>s;
	 if(s=="RRR")
	 ans=3;
	 if(s=="SRR" || s=="RRS")
	 ans=2;
	 if(s=="SSR" || s=="SRS" || s=="RSS" || s=="RSR")
	 ans=1;
	 cout<<ans<<'\n';
	 return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////
int n;


int main(){
    cin >> n;
    string s[n];
    set<string> d;
    
    rep(i,0,n){
        cin >> s[i];
        d.it(s[i]);
    }

    if(sz(d) != n){
        No;
        ret 0;
    }
    

    set<string> se;
    
    rep(i,1,n){
       // cout << s[i-1][sz(s[i-1])-1] << " "<< s[i][0] << endl;
        if(s[i-1][sz(s[i-1])-1] != s[i][0]){
            No;
            ret 0;
        }
    }
    Yes;
	return  0;
}

Measured memory_bytes: 256
def f(n):
    result = set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            result.add(i)

    if temp != 1:
        result.add(temp)

    return result

a, b = list(map(int, input().split()))

fa = f(a)
fb = f(b)

print(len(fa & fb)+1)


Measured memory_bytes: 3060
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()

    char = [chr(i) for i in range(97, 97 + 26)]
    d = [0 for _ in range(11)]
    d[0] = 1

    def printer(d):
        s = ""
        for num in d:
            if num != 0:
                s = char[num - 1] + s

        if len(s) == n:
            print(s)
        return

    while d[n] == 0:
        printer(d)

        d[0] += 1

        for i in range(10):
            if d[i] > max(d[i + 1:]) + 1:
                d[i] = 1
                d[i + 1] += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 6388
s = input()
n = len(s)
p = []
for i in range(2 ** (n-1)):
    tmp = [' '] * (n-1)
    for j in range(n-1):
        if i >> j & 1:
            tmp[j] = "+"
    p.append(tmp)
ans = []
s = list(s)
s_ = []
for i in range(n):
  if(i == n-1):
    s_.append(s[i])
    break
  s_.append(s[i])
  s_.append(" ")

s__ = []
for i in range(len(p)):
  tmp = s_
  tmp[1::2] = p[i]
  #print(tmp)
  tmp = [a for a in tmp if a != ' ']
  temp = ''.join(tmp)
  #print(temp)
  if("+" in temp):
    ans.append(eval(temp))
  else:
    ans.append(int(temp))
print(sum(ans))


Measured memory_bytes: 39792
import java.util.*;
public class Main {
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long ac = 0;
    long wa = 0;
    long tle = 0;
    long re = 0;
    String tmp = "";
    for(int i=0;i<n;i++){
      tmp = sc.next();
      if( tmp.equals("AC") ){
        ac++;
      }else if(tmp.equals("WA") ){
        wa++;
      }else if(tmp.equals("TLE")){
        tle++;
      }else if( tmp.equals("RE")){
        re++;
      }
    }
    System.out.println("AC x "+ac);
    System.out.println("WA x "+wa);
    System.out.println("TLE x "+tle);
    System.out.println("RE x "+re);
  }
}

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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

using pii = pair<int, int>;

const int MAX_NM = 30;
int N, M, A, C, R = 0;
int B[MAX_NM];

inline void Main() {
  // code
  int N, V[30], C[30], R;
  cin >> N;
  rep(i, N) cin >> V[i];
  rep(i, N) cin >> C[i];

  R = 0;
  rep(i, N) R += (V[i] > C[i] ? V[i] - C[i] : 0);

  cout << R << endl;
}

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


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

int X, A, B, C;

#define FOR(i, a, b) for(int i=a; i<=b; i++)

int main(void){
	int ans = 0;

	scanf("%d%d%d%d", &A, &B, &C, &X);

	FOR(i, 0, A){
		FOR(j, 0, B){
			FOR(k, 0, C){
				if(i*500+j*100+k*50 == X) ans++;
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}

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

int main() {
    int n, curr;
    cin >> n;
    
    vector<bool> isprime(1001,true);
    vector<int> primes;
    for (int i=2; i<=1000; i++) {
        if (!isprime[i]) continue;
        primes.push_back(i);
        for (int j=i+i; j<=1000; j+=i) isprime[j] = false;
    }
    
    vector<int> powers(primes.size(),0);
    for (int i=2; i<=n; i++) {
        curr = i;
        while (curr>1) {
            for (int j=0; j<primes.size(); j++) {
                while (curr%primes[j]==0) {
                    powers[j]++;
                    curr/=primes[j];
                }
            }
        }
    }
    
    long long result = 1;
    for (auto i : powers) {
        result*=i+1;
        result%=1000000007;
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 256
/*input
1 999 1000
*/
#include <bits/stdc++.h>
#define ll long long int
#define lld long double
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll x,a,b;cin>>x>>a>>b;
	if(abs(x-a)>abs(x-b)){
		cout<<"B\n";
	}
	else{
		cout<<"A\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long x, long long y) {
  if (y) return gcd(y, x % y);
  else return x;
}

int main() {
  long long a, b;
  cin >> a >> b;
  long long g = gcd(a, b);
  long long i, count = 1;
  for (i = 2; i * i <= g; i++) {
    if (g % i) continue;
    count++;
    while (g % i == 0) g /= i;
  }
  if(g >= i) count++;
  cout << count;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
#include <random>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

VVI func(VVI mas, int sum) {
    mas[2][1] = sum - mas[0][1] - mas[1][1];
    mas[2][0] = sum - mas[0][2] - mas[1][1];
    mas[2][2] = sum - mas[2][0] - mas[2][1];
    mas[1][0] = sum - mas[0][0] - mas[2][0];
    mas[1][2] = sum - mas[1][0] - mas[1][1];
    // REP(i, 3)REP(j, 3) {
    //     if (mas[i][j] < 0) return VVI(0);
    // }
    REP(i, 3) if (accumulate(ALL(mas[i]), 0) != sum) return VVI(0);
    REP(j, 3) {
        int buf = 0;
        REP(i, 3) buf += mas[i][j];
        if (buf != sum) return VVI(0);
    }
    int buf = 0;
    REP(i, 3) buf += mas[i][i];
    if (buf != sum) return VVI(0);
    buf = 0;
    REP(i, 3) buf += mas[3 - i - 1][i];
    if (buf != sum) return VVI(0);
    return mas;
}

int main(void) {
    VVI mas(3, VI(3));
    int a, b, c;
    cin >> a >> b >> c;
    mas[0][0] = a;
    mas[0][1] = b;
    mas[1][1] = c;
    VVI ans;
    FOR(i, 1, 1000) {
        mas[0][2] = i;
        int sum = a + b + i;
        ans = func(mas, sum);
        if (ans != VVI(0)) break;
    }
    REP(i, 3) {
        REP(j, 3) {
            cout << (j ? " " : "") << ans[i][j];
        }cout << endl;
    }
}


Measured memory_bytes: 256
/*
https://atcoder.jp/contests/dp/tasks/dp_m
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

int modAdd (int a, int b) {
	a += b;
	if (a >= mod) {
		a -= mod;
	}
	return a;
}
int modSub (int a, int b) {
	a -= b;
	if (a < 0) {
		a += mod;
	}
	return a;
}
template <class T>
void display (const vector <T> &arr) {
	for (T a : arr) {
		cout << a << " ";
	}
	cout << endl;
	return;
}

int getNumWays (const vector <int> &candies, int k) {
	int n = candies.size();
	vector <int> dp(k + 1);
	dp[0] = 1;
	// dp[i] - Total number of ways if i candies are used
	
	for (int i = 0; i < n; ++i) {
		vector <int> prefixSum(k + 1);
		for (int used = k; used >= 0; --used) {
			int minCandies = used + 1;
			int maxCandies = used + min(candies[i], k - used);
			// for (int j = minCandies; j <= maxCandies; ++j) {
			// 	dp[j] = (dp[j] + dp[used]) % mod;
			// }
			if (minCandies <= maxCandies) {
				prefixSum[minCandies] = modAdd(prefixSum[minCandies], dp[used]);
				if (maxCandies + 1 <= k) {
					prefixSum[maxCandies + 1] = modSub(prefixSum[maxCandies + 1], dp[used]);
				}
			}
		}
		int prefix = 0;
		for (int j = 0; j <= k; ++j) {
			prefix = modAdd(prefix, prefixSum[j]);
			dp[j] = modAdd(dp[j], prefix);
		}
	}
	return dp[k];

}

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> candies(n);
    for (int &c : candies) {
    	cin >> c;
    }
    int result = getNumWays(candies, k);
    cout << result << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll; 
using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  if(n == m){cout << "Yes" << endl; return 0;}
  cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9+5;
int main() {
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<int> dp(n,inf);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<i+3;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

int r, D, x;

int main() {
    cin >> r >> D >> x;

    for (int i = 1; i <= 10; i++) {
        x = r * x - D; 
        cout << x << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j


def num(m):
    return len(list(filter(lambda x: x >= m-1, e)))

print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


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

int main(){
    int X,A,B;
    cin>>X>>A>>B;

    if(A - B >= 0){
        cout<<"delicious"<<endl;
    }

    else {
        if(B - A > X){
            cout<<"dangerous"<<endl;
        }

        else cout<<"safe"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cctype>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <time.h>
using namespace std;
#define loop(i, st, en) for(int i = st; i <= en; ++i)
#define reverse(i, st, en) for(int i = st; i >= en; --i)
#define wh(t) while(t--)
#define mem(i, x) memset(i, x, sizeof(i))
#define ssc(x) scanf("%s", x)
#define dsc(x) scanf("%d", &x)
#define lldsc(x) scanf("%I64d",&x)
#define lfsc(x) scanf("%lf", &x)
#define csc(x) scanf("%c",&x)
#define to_(s,i) s[i]-'0'
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=1e3+10;
const ll MAXM=2e18;
const int MAX=1e9;
const int INF=0x3f3f3f3f;
const ll P=1e9+7;
const ll C=1e5;
int n;
int m;
ll ans;
int pos[MAXN];
ll val[MAXN];
ll sum[MAXN][MAXN];
ll dp[MAXN][MAXN];
struct node{
    int a,b;
}p[MAXN];
bool cmp(node x,node y){
    if(x.a<y.a) return true;
    return false;
}
int main(){
    dsc(n);
    dsc(m);

    loop(i,1,m){
        dsc(p[i].a);dsc(p[i].b);
        pos[p[i].a]=p[i].b;
        pos[p[i].b]=p[i].a;
    }
    val[0]=1;
    for(int i=2;i<=2*n;i+=2){
        val[i]=1LL*val[i-2]*(i-1);
        val[i]%=P;
    }
    for(int i=1;i<=2*n;i++) {
        for(int j=i;j<=2*n;j++) {
            sum[i][j]=sum[i][j-1]+(!pos[j]);
        }
    }
    for(int i=1;i<=2*n;i++){
         for(int j=i;j<=2*n;j++){
             ll cnt=0;
             int flag=0;
             for(int k=i;k<=j;k++){
                 if(pos[k]&&(pos[k]<i||pos[k]>j)) flag=1;
             }
             if(flag) continue;
             if(val[sum[i][j]]==0) continue;
                 for (int k = i; k < j; k++) {
                     cnt += (dp[i][k] % P * val[sum[k+1][j]]) % P;
                     cnt %= P;
                 }
             dp[i][j]=(val[sum[i][j]]-cnt+P)%P;
         }
    }
    for(int i=1;i<=2*n;i++){
        for(int j=i;j<=2*n;j++){
            ans+=dp[i][j]*val[2*n-2*m-(sum[i][j])]%P;
            ans%=P;
        }
    }
    printf("%I64d\n",ans);
    return 0;
}

Measured memory_bytes: 14464
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n, e[3];
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> e[0] >> e[1] >> e[2];
        sort(e, e+3);
        if (e[2] * e[2] == e[0] * e[0] + e[1] * e[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

ll k;
vector<vector<pair<ll, ll>>> net;
vector<ll> color;

void dfs(ll cur, ll par, ll par_col){
    ll col = 0;
    if(col == par_col){ col++; }
    for(auto p : net.at(cur)){
        if(p.first == par){
            continue;
        }
        color.at(p.second) = col;
        dfs(p.first, cur, col);
        col++;
        if(col == par_col){
            col++;
        }
    }
}

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    net.resize(N);
    REP(i, N -1){
        a.at(i)--;
        b.at(i)--;
        net.at(a.at(i)).emplace_back(b.at(i), i);
        net.at(b.at(i)).emplace_back(a.at(i), i);
    }

    k = 0;
    REP(i, N){
        k = max(k, (ll)net.at(i).size());
    }

    color.resize(N - 1, -1);
    dfs(0, -1, -1);

    cout << k << endl;
    REP(i, N - 1){
        cout << color.at(i) + 1 << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 10240
D , G = map(int,input().split())
bonus = []
question_cnt = []
for i in range(D):
    p , c = map(int,input().split())
    question_cnt.append(p)
    bonus.append(c)
ans = float('inf')
for bit in range(2 ** D):
    sum_val = 0
    tmp_ans = 0
    Flag = False
    for j in range(D):
        if bit >> j & 1:
            sum_val += question_cnt[j] * (j + 1) * 100 + bonus[j]
            tmp_ans += question_cnt[j]
    if sum_val < G:
        for j in range(D-1 , - 1 , -1):
            if Flag:
                break
            if not bit >> j & 1:
                Flag = True
                for k in range(question_cnt[j]):
                    sum_val += (j + 1) * 100
                    tmp_ans += 1
                    if sum_val >= G:
                        break
    if tmp_ans < ans and sum_val >= G:
        ans = tmp_ans
print(ans)


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

string changeLower(const string& s){
    string ret = s;
    for(auto& c : ret){
        c = tolower(c);
    }
    return ret;
}

int main(){

    string w;
    cin >> w;

    int cnt = 0;
    while(true){
        string t;
        cin >> t;
        if(t == "END_OF_TEXT"){
            break;
        }
        string tmp = changeLower(t);
        if(tmp == w){
            cnt++;
        }
    };

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3176
#include <cstdio>
#include <algorithm>
using namespace std;

#define ll long long int
#define mx 200005
ll A[mx],B[mx];

int bin_search(int time, int m){
    if(B[0]>time) return 0;
    if(B[m-1]<=time) return m;

    int l=0,r=m-1;
    while(r-l>1){
        int mid=(l+r)/2;
        if(B[mid]<=time) l=mid;
        else r=mid;
    }
    return r;
}

int main(){
    int n,m,time;
    scanf("%d %d %d",&n,&m,&time);
    for(int i=0;i<n;i++) {scanf("%lld",&A[i]); if(i>0) A[i]+=A[i-1];};
    for(int i=0;i<m;i++) {scanf("%lld",&B[i]); if(i>0) B[i]+=B[i-1];};

    int ans=bin_search(time,m);

    for(int i=0;i<n;i++) if(A[i]<=time){
        ans=max(ans,i+1+bin_search(time-A[i],m));
    }

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


Measured memory_bytes: 4856
#include <stdio.h>
#include <iostream>

int main()
{
	int n; std::cin >> n;
	int l[101];
	int count = 0;

	for (int i=0; i<n; i++) std::cin >> l[i];

	for (int i=0; i<n; i++)
	{
		for (int j=i+1; j<n; j++)
		{
			for (int k=j+1; k<n; k++)
			{
				if (l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j] && l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i])
				{
					count++;
				}
			}
		}
	}

	std::cout << count << std::endl;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define x first
#define y second
const int N = 100010;

int a , b , c , x , y;

ll mn = 1e18;

int main() {
	cin >> a >> b >>c >> x >> y;
	for(int i = 0 ; i <= 2*x+2*y ; ++i){
		int got = i/2;
		int remA = x-got;
		int remB = y-got;
		ll pr = i * c;
		if(remA>0)
			pr += a * remA;
		if(remB>0)
			pr += b * remB;
		mn = min(mn,pr);
	}	
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }
    for (int i = 0; i < n - 1; i++)
    {
        vs[i + 1] += vs[i];
    }

    map<int64_t, int64_t> freq;

    for (auto v : vs)
    {
        freq[v]++;
    }

    int64_t ans = 0;
    for (auto& v : freq)
    {
        const auto i = v.second;
        ans += i * (i - 1) / 2;
    }
    ans += freq[0];

    cout << ans << endl;
}


Measured memory_bytes: 14336
#include <iostream> 
#include <algorithm>

using namespace std;





int main() {
	int A;
	int B;
	int T;

	cin >> A >> B >> T;
	int ans = 0;


	for (int t = 1; t <= T; t++) {
		if (t % A == 0) {
			ans += B;
		}
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  vector<string> w;
  cin >> n;
  int flag = 0;
  for(int i = 0;i<n;i++){
    string s;
    char last;
    cin >> s;
    for(int j = 0;j< w.size();j++){
      if( s != w.at(j) ){
        continue;
      }
      else {
        flag = 1;
        break;
      }
    }
    w.push_back(s);
    if( i != 0 && last != s.at(0)){
      flag = 1;
      break;
    }
    last = s.at(s.size()-1);
  }
  if( flag == 1){
    cout << "No";
  }
  else {
    cout << "Yes";
  }
}

Measured memory_bytes: 256
/*
[abc135] B - 0 or 1 Swap
*/

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

const int MAX_N = 50;

int N;
int p[MAX_N];

bool check() {
    for (int i = 1; i < N; i++) {
        if (p[i - 1] > p[i]) {
            return false;
        }
    }
    return true;
}

bool solve() {
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            swap(p[i], p[j]);

            if (check()) {
                return true;
            }

            swap(p[i], p[j]);
        }
    }

    return check();
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    cout << (solve() ? "YES" : "NO") << endl;

    return 0;
}


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

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題167

            string[] line = Console.ReadLine().Split(' ');

            int N = int.Parse(line[0]);
            int M = int.Parse(line[1]);
            int X = int.Parse(line[2]);

            //Console.WriteLine("X" + X);

            int[] C = new int[N];
            int[,] A = new int[N, M];

            for (int i = 0; i < N; i++)
            {
                string[] lines = Console.ReadLine().Split(' ');
                C[i] = int.Parse(lines[0]);

                for (int j = 0; j < M; j++)
                {
                    A[i, j] = int.Parse(lines[j + 1]);

                }
            }

            //for (int i = 0; i < N; i++)
            //{
            //    Console.WriteLine(C[i]);
            //    for (int j = 0; j < M; j++)
            //    {
            //        Console.WriteLine(A[i, j]);
            //    }
            //}

            int ans = 0;
            int count = 0;

            for (int i = 0; i < (1 << N); i++)
            {
                //Console.WriteLine("i" + i);

                //かく理解度
                int[] rikai = new int[M];
                for (int j = 0; j < M; j++)
                {
                    rikai[j] = 0;
                }

                //理解度たす
                for (int j = 0; j < N; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        for (int k = 0; k < M; k++)
                        {
                            rikai[k] += A[j, k];
                        }


                        //値段
                        count += C[j];


                    }
                }

                bool flag = true;
                for (int j = 0; j < M; j++)
                {
                    if (rikai[j] < X)
                    {
                        flag = false;
                        break;
                    }

                }

                if (flag)
                {
                    if (ans == 0)
                    {
                        ans = count;
                    }

                    ans = Math.Min(ans, count);
                    //Console.WriteLine("ans" + ans);

                    //for (int j = 0; j < M; j++)
                    //{
                    //    Console.WriteLine(rikai[j]);

                    //}

                }

                count = 0;

            }

            if (ans == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(ans);
            }



        }


    }
}


Measured memory_bytes: 27764
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    int n, k;
    cin>>n>>k;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    int sum=0;
    for(int i=0; i<n; i++){
        
        sum+=min(a[i], k-a[i])*2;
        
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), fprintf(), scanf()

const char NUL = '\0';
unsigned char hash_t[1 << 22] = { 0 };
char key[256] = { 0 };

int
hash(const char* s)
{
	int u = 1;
	while (*s != NUL)
	{
		u = u * 4 + key[(int)*s];
		s++;
	}

	return u;
}

int
main(int argc, char** argv)
{
	char command[8];
	char str[14];
	int n;

	key['A'] = 0;
	key['C'] = 1;
	key['G'] = 2;
	key['T'] = 3;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%s %s", command, str);
		int h = hash(str);
		int u = h >> 3;
		int v = 1 << (h & 7);
		switch (command[0])
		{
		case 'i':
			hash_t[u] |= v;
			break;

		case 'f':
		default:
			if ((hash_t[u] & v) != 0)
				printf("yes\n");
			else
				printf("no\n");
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 768
def solve():
	arr=[int(i)for i in input().split()]
	n=abs(arr[0]);k=arr[1];d=arr[2]
	diff=n//d
	
	if(diff>k):
		print(n-(d*k))
		return
	else:
		if((k-diff)%2==0):
			print(n-(diff*d))
			
		else:
			print(abs((n-(diff*d))-d))





	


	   
	    
	
	
#test=int(input())
test=1
while test:

	solve()
	test-=1    
    
    
    
        

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    vector<string> c(2);
    rep(i,2) cin >> c[i];
    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;

void solve()
{
    ll n,cnt=0,ans=0;
  cin>>n;
  string s;
  cin>>s;
  fo(i,0,n)
  {
    if(s[i]=='R') cnt++;
  }
  fo(i,0,cnt) ans+=(s[i]=='W');
  cout<<ans;
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3732
#include <stdio.h>
int main() {
	int I, N, m;
	unsigned long int sum;
	scanf("%d", &N);
	sum = 0;
	for(I = 0; I < N; ++ I) {
		scanf("%d", &m);
		sum += m;
	}
	printf("%lu\n", sum / N);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

bool f;
void dfs(int a[10], int n) {
  if (n == 1) {
    // FOR(i, 1, 10) cout << a[i] << " "; cout << endl;
    FOR(i, 1, 8) if (a[i] == 1 && a[i + 1] == 1 && a[i + 2] == 1) f = true;
    FOR(i, 1, 10) if (a[i] == 3) f = true;
    return;
  }

  //???????????¨??¨??????
  FOR(i, 1, 8) if (a[i] >= 1 && a[i + 1] >= 1 && a[i + 2] >= 1) {
    int tmp[10];
    REP(j, 10) tmp[j] = a[j];
    --tmp[i];
    tmp[i + 1]--;
    --tmp[i + 2];
    dfs(tmp, n - 1);
  }
  //???????????????
  FOR(i, 1, 10) if (a[i] >= 3) {
    int tmp[10];
    REP(j, 10) tmp[j] = a[j];
    tmp[i] -= 3;
    dfs(tmp, n - 1);
  }
}

signed main(void) {
  string s;
  while (cin >> s) {
    int cnt[10] = {0};
    REP(i, s.size()) cnt[s[i] - '0']++;
    VI ans;
    FOR(k, 1, 10) {
      bool g = false;
      if (cnt[k] < 4) {
        cnt[k]++;
        g = true;
      }
      f = false;
      // cout << k << endl;
      FOR(i, 1, 10) if (cnt[i] >= 2) {
        int tmp[10];
        REP(j, 10) tmp[j] = cnt[j];
        tmp[i] -= 2;
        dfs(tmp, 4);
      }
      if (g)
        cnt[k]--;
      if (f)
        ans.push_back(k);
    }

    if (ans.size() == 0)
      cout << 0;
    REP(i, ans.size()) {
      cout << ans[i];
      if (i != ans.size() - 1)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 2972
#include <stdio.h>
#include <string.h>

int main()
{
	char str[100] = {0};
	_Bool flag = 1;
	int count = 0;
	
	scanf("%s", str);
	for(char ch = 97; ch < 'z'; ch++){
		for(int i = 0; i < strlen(str); i++){
			if(str[i] == ch){
				count++;
			}
		}
		
		if(count % 2){
			flag = 0;
			break;
		}
		count = 0;
	}
	
	if(flag)
		printf("Yes\n");
	else
		printf("No\n");
		
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int h, w, n;
int a[10000];
int ans[100][100];

int main(){
  cin >> h >> w >> n;
  rep(i, n) cin >> a[i];
  int color = 1;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[color-1]) ans[i][j] = color;
      else{
        ans[i][j] = color+1;
        color++;
      }
      a[color-1]--;
    }
  }
  for(int i = 1; i < h; i+=2){
    reverse(ans[i], ans[i] + w);
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << ans[i][j]<<" ";
    }
    cout<<endl;
  }
  int i = 0;
}
        

Measured memory_bytes: 384
n = int(input())
ai = {}
max1 = 0
max2 = 0
for i in range(1, n+1):
    tmp = int(input())
    ai.setdefault(i, tmp)
    if tmp > max1:
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(1, n+1):
    if ai[i] == max1:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 32732
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b;
    
    scanf("%d %d", &a,&b);
    
    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2036
while True:
  n = int(input())
  if n == 0:break
  solvers = set()
  for i in range(1, int(n ** (1 / 2)) + 2):
    if n % i == 0:
      solvers.add(i)
      solvers.add(n // i)
  score = sum(solvers) - n
  if n < score:
    print("abundant number")
  elif n == score:
    print("perfect number")
  else:
    print("deficient number")


Measured memory_bytes: 5644
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

pair<LL, VI> solve(VI A)
{
	VI res;
	LL sum = 0;
	int cnt = 0;

	bool left = false;

	for (int i = SZ(A) - 1; i >= 0; i -= 2)
	{
		if (A[i] >= 0)
		{
			sum += A[i];
			cnt++;
			left = true;
		}
		else
		{
			res.PB(i+1);
			if (!left) res.PB(i);
			else if (i == 0) res.PB(1);
		}
	}

	if (cnt == 0) return MP(-LINF, VI());

	if (SZ(A) % 2 == 0) res.PB(1);

	FOR (it, 0, cnt - 1) res.PB(2);

	return MP(sum, res);
}

int main(int argc, char* argv[])
{
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	VI A(n);
	PII mx = MP(-INF, -INF);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
		mx = max(mx, MP(A[i], i));
	}
	int add = 0;

	if (mx.first < 0)
	{
		add = mx.first;
		A[mx.second] = 0;
	}

	pair<LL, VI> a = solve(A);
	A.pop_back();
	pair<LL, VI> b = solve(A);
	reverse(ALL(b.second));
	b.second.PB(n);
	reverse(ALL(b.second));

	if (a.first < b.first) swap(a, b);

	cout<<a.first + add<<endl;
	cout<<SZ(a.second)<<endl;
	FOR (i, 0, SZ(a.second))
	{
		cout<<a.second[i]<<endl;
	}

}

Measured memory_bytes: 256
x = []
f  = 1
for _ in range(3):
    x.extend(list(map(int,input().split())))
cnt = [0]*4
for i in range(6):
    cnt[x[i]-1] += 1
for a in cnt:
    if a > 2:
        f = 0
if f:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if( T[u].p == NIL ) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i = 0, c = T[u].l; c != NIL; i++, c =T[c].r ){
    if(i) cout << ", ";
    cout << c;
  }
  cout  << "]" << endl;
}

void rec(int u, int p){
  D[u] = p;
  if( T[u].r != NIL ) rec(T[u].r, p);
  if( T[u].l != NIL ) rec(T[u].l, p + 1); 
}


int main(){
  int i, j, d, v, c, l, r;
  cin >> n;

  for (int i = 0; i < n; ++i){
    T[i].p = T[i].l = T[i].r = NIL;
  }

  for (int i = 0; i < n; ++i){
    cin >> v >> d;
    for (int j = 0; j < d; ++j){
      cin >> c;
      if( j == 0 ) T[v].l = c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for (int i = 0; i < n; ++i){
    if(T[i].p == NIL) r = i;
  }

  rec(r, 0);

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

  return 0;
}

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

int main() {
  int N; cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  map<string, int> cnt;
  rep(i, N) {
    if (cnt.count(s[i])) cnt[s[i]]++;
    else cnt[s[i]] = 1;
  }
  ll ans = 0;
  for (auto p : cnt) {
    ll n = p.second;
    ans += n * (n-1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 18176
#include "bits/stdc++.h"
using namespace std;
const long long mod = 1000000007;
const int maxn = 100100;
int deg[maxn], cnt[16];
int dp[1<<16], xo[1<<16];
int main(){
    int n;
    cin >> n;
    for(int e = 0; e < n - 1; e++){
        int u, v, w;
        cin >> u >> v >> w;
        deg[u] ^= w;
        deg[v] ^= w;
    }
    for(int e = 0; e < n; e++){
        cnt[deg[e]]++;
    }
    int ans = cnt[0];
    for(int e = 1; e < 16; e++){
        ans += cnt[e] / 2;
        cnt[e] %= 2;
    }
    for(int e = 1; e < 1<<16; e++){
        xo[e] = 0;
        for(int f = 0; f < 16; f++)
            if(e & (1<<f)) xo[e] ^= f;
    }
    dp[0] = 0;
    for(int e = 1; e < 1<<16; e++){
        for(int f = e; f > 0; f = (f - 1) & e){
            if(xo[f] == 0) dp[e] = max(dp[e], dp[f] + 1);
        }
    }
    int msk = 0;
    for(int e = 1; e < 16; e++)
        if(cnt[e]) msk |= (1<<e);
    ans += dp[msk];
    cout << n - ans << endl;
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		//String[][] array = new String[100][500];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list_origin=new ArrayList<Integer>();
		int a= sc.nextInt();
		int b = sc.nextInt();

		int count = 1;
		int answer =0;

		while(true) {
			if(count >= b)
				break;
			count=count-1;
			count=count+a;
			answer++;
			if(count >= b)
				break;
		}

		System.out.println(answer);
	}

}

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

using namespace std;

int main (){

    int x;
    string s;

    cin  >> x;
    cin >> s ;

    if(s.size() <= x){
        cout << s;
    } else{
        cout << s.substr(0,x) << "...";
    }

    return 0;   
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    string S;
    cin >> S;
    if ( S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3) )
      printf("Bad\n");
    else printf("Good\n");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
#define N 100
L n,P;
L a[N],b[N];
int t;
int main(){
	cin>>n>>P;
	for(L i=2;i*i<=P;++i){
		if(P%i<1){
			a[++t]=i;
			for(;P%i<1;P/=i)++b[t];
		}
	}
	a[++t]=P,b[t]=1;
	L an=1;
	for(int i=1;i<=t;++i){
		b[i]/=n;
		while(b[i]--)an*=a[i];
	}
	cout<<an;
}

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h,w,i,j,k,t,a[10][10],b[10]={0},c[200][200],ans=0;
	cin>>h>>w;
	for (i=0;i<10;i++){
		for(j=0;j<10;j++){
			cin>>a[i][j];
		}
	}
	for (i=0;i<h;i++){
		for (j=0;j<w;j++){
			cin>>c[i][j];
		}
	}
	for (k=0;k<10;k++){
		for (i=0;i<10;i++){
			for (j=0;j<10;j++){
				a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
			}
		}
	}
	for (i=0;i<h;i++){
		for (j=0;j<w;j++){
			if (c[i][j]!=1&&c[i][j]!=-1){
				ans+=a[c[i][j]][1];
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define maxn 1004
#define maxw 10004
using namespace std;

int h, n;
int a[maxn], b[maxn];
int dp[maxn][maxw], vis[maxn][maxw];

int fnc(int pos, int baki)
{
    if(baki <= 0) return 0;

    if(pos >= n) return 1e9;

    if(vis[pos][baki]) return dp[pos][baki];

    vis[pos][baki] = 1;

    int p = 1e9;

    p = min(p, fnc(pos, baki - a[pos]) + b[pos]);
    p = min(p, fnc(pos + 1, baki));

    return dp[pos][baki] = p;
}

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

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

    cout << fnc(0, h) << endl;

    return 0;
}


Measured memory_bytes: 78720
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

const long long sqrtN = 512;
struct SqrtDecomposition {
  long long N, K;
  vector<long long> data;
  vector<long long> bucketAdd;
  SqrtDecomposition(long long n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  void add(long long s, long long t, long long x) {
    for (long long k = 0; k < K; ++k) {
      long long l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (long long i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  long long get(long long i) {
    long long k = i / sqrtN;
    return data[i] + bucketAdd[k];
  }
};

int main() {
    long long n,q,que,s,t,x;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> q;
    SqrtDecomposition qq(n);
    rep(i,q) {
        cin >> que;
        if(que) {
            cin >> x;
            cout << qq.get(x) << endl;
        } else {
            cin >> s >> t >> x;
            qq.add(s,t+1,x);
        }
    }
    return 0;
}


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  char a, b;
  cin >> a >> b;

  if(a == 'H'){
    cout << b << endl;
  }
  else{
    if(b == 'H'){
      cout << 'D' << endl;
    }
    else{
      cout << 'H' << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        while(sc.hasNext()){  
            int sum = sc.nextInt();
            int answer = 0;
            for(int a = 0; a < 10; a++){
                for(int b = 0; b < 10; b++){
                    for(int c = 0; c < 10; c++){
                        for(int d = 0; d < 10; d++){
                            if(a+b+c+d==sum){
                                answer++;
                            }
                        }
                    }
                }
            }
            System.out.println(answer);
        }
 
    }
}

Measured memory_bytes: 19048