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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define debug(args...){string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;

void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const ll mod = 1000000007;
ll dp[1000002][2][2];
int n;

ll solve(int i, bool havezero, bool havenine){
  if(i == n)
    return (havezero+havenine) == 2;
  ll &ans = dp[i][havezero][havenine];
  if(ans != -1)
    return ans;
  ans = 0;
  for(int j = 0; j <= 9; j++)
    ans = (ans%mod+solve(i+1, havezero|(j == 0), havenine|(j == 9))%mod)%mod;
  return ans%mod;
}

int main(){
  cin >> n;
  memset(dp, -1, sizeof dp);
  if(n <= 1)
    cout << 0 << endl;
  else{
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 112756
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
using Graph = vector<vector<int>>;

int n;

vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    for (auto next_v : G[v]) {
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false;
            continue;
        }
        if (!dfs(G, next_v , 1 - cur)) return false;
    }
    return true;
}

ll cost[305][305];

void warshall_floyd(){
    rep(k, n){
        rep(i, n){
            rep(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        }
    }
}


int main(){
    cin >> n;
    Graph G(n);
    rep(i, n) rep(j, n) cost[i][j] = LINF;
    rep(i, n) cost[i][i] = 0;

    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n){
            if (s[j]=='1'){
                G[i].push_back(j);
                G[j].push_back(i);
                cost[i][j] = 1;
                cost[j][i] = 1;
            }
        }
    }

    color.assign(n, -1);
    bool is_bipartite = true;
    rep(v, n){
        if (color[v] != -1) continue;
        if (!dfs(G, v)) is_bipartite = false;
    }

    if (!is_bipartite) {
        cout << -1 << endl;
        return 0;
    }

    warshall_floyd();
    ll ans = 0;
    rep(i, n) rep(j, n) {
        if (cost[i][j] > 2000) continue;
        ans = max(ans, cost[i][j]);
    }

    cout << ans + 1 << endl;

    return 0;
}


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

int main(){
  int P, Q, R;
  cin >> P >> Q >> R;
  
  vector<int> t = {P, Q, R};
  
  sort(t.begin(), t.end());
  
  int sum = t.at(0) + t.at(1);
  
  cout << sum << endl;
 
  
  
  
  return 0;
}
    
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define __STDC_LIMIT_MACROS
#include <stdint.h>
using namespace std;
#define int long long
#define endl '\n'	 
#define pb	push_back
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
void c_p_c()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int maxSubArraySum(int a[], int size) 
{ 
    int max_so_far = INT_MIN, max_ending_here = 0, 
       start =0, end = 0, s=0; 
  
    for (int i=0; i< size; i++ ) 
    { 
        max_ending_here += a[i]; 
  
        if (max_so_far < max_ending_here) 
        { 
            max_so_far = max_ending_here; 
            start = s; 
            end = i; 
        } 
  
        if (max_ending_here < 0) 
        { 
            max_ending_here = 0; 
            s = i + 1; 
        } 
    } 
    return 1;
} 
int isPrime(int n)
{
	int a = 0;
	for(int i = 2; i*i<=n; i++)
	{
		if(n%i==0)
			return 0;
	}
	return 1;
}
int bigpower(int a,int b)
{
    int res = 1;
    while(b>0)
    {
        if(b&1)
        {
            res*=a;
        }
        a*=a;
        b>>=1;
    }
    return res;
}
int fact(int n)
{
    int a = 1;
    for(int i = 1; i<=n; i++)
    {
        a*=i;
    }
    return a;
}
struct cmp{
    bool operator() (const pair<int,int> &a, const pair<int,int> &b) const {
        int la = a.second-a.first+1;
        int lb = b.second-b.first+1;
        if(la==lb) return a.first<b.first;
        return la>lb;
    }
};

bool how(pair<int,int> a, pair<int,int> b)
{
    return a.first>b.first;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	c_p_c();
    string s,t;
    cin>>s>>t;
    int m = s.length();
    int n = t.length();
    int ans = INT_MAX;
    for(int i = 0; i<m-n+1; i++)
    {
        int x = 0;
        for(int j = 0; j<n; j++)
        {
            if(t[j]!=s[i+j])
            {
                x++;
            }
        }
        ans = min(ans,x);
    }
    cout<<ans<<endl;
}	


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

int main() {
	int a,b,c,d,e,i,count;
	count =  0;
	cin >>  a ;
  vector<int> vec(a);
	while(true){
  for (i = 0; i < a; i++) {
    cin >> vec.at(i);
  if ( vec.at(i) %2==1) {
      cout << count << endl;
	return 0;
	}
	 vec.at(i) = vec.at(i)/2;
  }
	count =count+1;
	}
}


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

typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main(){
	speed;
	int n, x, t;
	cin >> n >> x >> t;
	int k = n / x;
	int m = n % x;
	cout << k * t + bool(m > 0) * t;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void) {
	int n; scanf("%d",&n);
	int ary[n+1];
	for (int i=1; i<=n; i++) {
		int num; scanf("%d",&num);
		ary[num] = i;
	}
	for (int i=1; i<=n; i++) {
		printf("%d ",ary[i]);
	}
	
	return 0;
}


Measured memory_bytes: 1152
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>

using namespace std;
using namespace boost::multiprecision;

void solve() {
	int a, b;
	cin >> a >> b;
	int n = b - a;
	cout << (n - 1)*n / 2 - a << endl;
	return;
}

Measured memory_bytes: 256
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 ans = 0;
	
		
		if(A+B>A-B) {
			if(A+B>A*B) {
				ans = A+B;
			}else {
				ans = A*B;
			}
		}else {
			if(A-B>A*B) {
				ans = A - B;
			}else {
				ans = A*B;
			}
		}
		
		
		System.out.println(ans);

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> v;
  for(Int i=2;i<55555;i++)
    if(isprime(i)&&i%5==3) v.emplace_back(i);
  
  vector<Int> p(5e5,0);
  for(Int i=2;i<5e5;i++)
    p[i]=isprime(i);

  while(1){
    //random_shuffle(v.begin(),v.end());
    bool flg=0;
    for(Int i=0;i<n;i++)
      for(Int j=0;j<i;j++)
	for(Int k=0;k<j;k++)
	  for(Int s=0;s<k;s++)
	    for(Int t=0;t<s;t++)
	      flg|=p[v[i]+v[j]+v[k]+v[s]+v[t]];
    //cout<<flg<<endl;
    if(flg) continue;
    for(Int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<v[i];
    }
    cout<<endl;
    return 0;
  }
  
  return 0;
}


Measured memory_bytes: 4224
import math
N, H = map(int, input().split())

katana = [tuple(map(int, input().split())) for _ in range(N)]

katana = sorted(katana, key=lambda x: (-x[0], x[1]))  # 振った時のダメージでソート

max_a, sonob = katana.pop(0)
#
# print(max_a, sonob)
# print(katana)

target = H
cnt = 0
# いらない刀を全部投げる
katana = sorted(katana, key=lambda x: -x[1])

for i in range(len(katana)):
    if target <= 0:
        print(cnt)
        exit()
    if max_a > katana[i][1]:  # 最大の刀を振った方が良いなら終了
        break
    target -= katana[i][1]
    cnt += 1

target -= sonob
cnt += 1
print(cnt+int(math.ceil(target/max_a)))


Measured memory_bytes: 28312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,k,upp;
vpii ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    upp = ((n-1)*(n-2)) / 2;

    if(k>upp){
        cout<<-1<<newl;
    }
    else{
        int need = upp-k;
        for(int i=2;i<=n;i++){
            ans.pb(mp(1,i));
        }
        int idx = 1;
        while(need>0){
            idx ++;
            for(int i=idx+1;i<=n;i++){
                need--;
                ans.pb(mp(idx,i));
                if(need<=0)break;
            }
        }
        cout<<ans.size()<<newl;
        for(int i=0;i<ans.size();i++){
            cout<<ans[i].fi<<" "<<ans[i].se<<newl;
        }
    }
}


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

typedef pair<int, int> P;

int W,H,S,A;
int field[35][35];
int dp0[35][35][35];
int dp[35][35][35][35];
P memo[35][35][35][35];

P dfs(int l, int t, int r, int b)
{
	if(memo[l][t][r][b].first != 0) return memo[l][t][r][b];

	P res = make_pair(1, S-(A-dp[l][t][r][b]));
	for(int i=l; i<r; i++){
		if(A-dp[l][t][i][b] > S || A-dp[i+1][t][r][b] > S) continue;

		P left = dfs(l,t,i,b);
		P right = dfs(i+1,t,r,b);

		P lr = make_pair(left.first + right.first, min(left.second, right.second));
		res = max(res, lr);
	}

	for(int i=t; i<b; i++){
		if(A-dp[l][t][r][i] > S || A-dp[l][i+1][r][b] > S) continue;

		P top = dfs(l,t,r,i);
		P bot = dfs(l,i+1,r,b);

		P mid = make_pair(top.first + bot.first, min(top.second, bot.second));
		res = max(res, mid);
	}

	memo[l][t][r][b] = res;

	return memo[l][t][r][b];

	
}

void solve()
{
	memset(dp, 0, sizeof(dp));
	for(int i=0; i<H; i++)
	for(int j=0; j<W; j++){
		dp[j][i][j][i] = field[j][i];

		for(int y=i-1; y>=0; y--)
			dp[j][y][j][i] = dp[j][y+1][j][i] + field[j][y];

		for(int y=i; y>=0; y--) {
			int sum = 0;
			for(int x=j; x>=0; x--) {
				sum += dp[x][y][x][i];
				dp[x][y][j][i] = sum;
			}
		}
	}

	memset(memo, 0, sizeof(memo));
	A = dp[0][0][W-1][H-1];
	P res = dfs(0,0,W-1,H-1);
	cout << res.first << " " << res.second << endl;
}

int main()
{
	while(cin >> H >> W >> S,(W||H||S)) {
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++) {
			cin >> field[j][i];
		}

		solve();
	}
}

Measured memory_bytes: 18000
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[110000];

int main()
{
  vector<int> aa;
  int i,j,n;
  _int64 ans;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  sort(a,a+n);
  aa.clear();
  for (i=0;i+1<n;i++)
    if (a[i]==a[i+1])
    {
      aa.push_back(a[i]);
      i++;
    }
  reverse(aa.begin(),aa.end());
  if (aa.size()>=2) ans=(_int64)aa[0]*aa[1];
  else ans=0;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

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

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

void trace(vector<int> &A,int N){
    for(int i=0;i<N-1;i++){
        cout << A.at(i) << " ";
    }
    cout << A.at(N-1) << endl;
}

void insertionSort(vector<int> &A,int N){
    for(int i=1;i<N;i++){
        int v=A.at(i);
        int j=i-1;
        while(j>=0&&A.at(j)>v){
            A.at(j+1)=A.at(j);
            j--;
        }
        A.at(j+1)=v;
        trace(A,N);
    }
}

int main(void){
    int N;
    cin >> N;
    std::vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    trace(A,N);
    insertionSort(A,N);
    
    return 0;
}


Measured memory_bytes: 3092
n=int(input())
m=10**9+7
a=1
b=1
c=1

for i in range(n):
    a*=10
    a%=m
    b*=9
    b%=m
    c*=8
    c%=m
ans = a-2*b+c+2*m
ans%=m
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	string s;
	cin >> s;
	ll n = s.size();
	vll c(26, 0);
	rep(i, n) c[s[i]-'a']++;
	ll ans = n*(n-1)/2 + 1;
	rep(i, 26) ans -= c[i]*(c[i]-1)/2;
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_V = 2e5;
vector<int> es[MAX_V];
ll dp[MAX_V];
int ans[MAX_V];
ll A[MAX_V];

void dfs(int now, int pre){
    int j = lower_bound(dp, dp+MAX_V, A[now])-dp; 
    ll memo = dp[j];
    dp[j] = A[now];
    ans[now] = lower_bound(dp, dp+MAX_V, INF)-dp;
    for(auto &e: es[now]){
        if(e == pre) continue;
        dfs(e, now);
    }
    dp[j] = memo;
}

int main(){
    int N;
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N-1){
        int a, b; cin >> a >> b; a--, b--;
        es[a].pb(b), es[b].pb(a);
    }
    fill(dp, dp+MAX_V, INF);
    dfs(0, -1);
    rep(i, N){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 32748
#include<iostream>
using namespace std;
int p = 1000000007;
int main()
{
  long long n,k,t,i,res=0;
  cin >> n >> k;
  for(i=k;i<=n+1;i++){
    res+=(n-i+1)*i+1;
    res%=p;
  }
  cout << res << endl;
  return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
//typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> s;
  n = sz(s);

  if (s[n-1] == '1' || s[0] == '0') {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i * 2 < n; i++) {
    if (s[i] != s[n - i - 2]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int now = 1;
  vector<pair<int,int>> v;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == '1') {
      v.pb({now, i+2});
      now = i + 2;
    } else {
      v.pb({now, i+2});
    }
  }
  REP(i,sz(v)) {
    cout << v[i].fi << " " << v[i].se << endl;
  }
  return 0;
}


Measured memory_bytes: 2372
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll n=s.size();
	vvl dp(n+1,vl(2,LINF));
	dp[0][0]=0;
	dp[0][1]=1;
	rep(i,n){
		chmin(dp[i+1][0],min(dp[i][0]+(s[i]-'0'),dp[i][1]+10-(s[i]-'0')));
		chmin(dp[i+1][1],min(dp[i][0]+(s[i]-'0')+1,dp[i][1]+10-(s[i]-'0')-1));
	}
	cout<<dp[n][0]<<endl;
}


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

int main(void) {
    long long L, R;
    cin >> L >> R;
    long long ans = 0;
    if (R - L < 2019) {
        ans = L * (L + 1) % 2019;
        for (long long i = L; i < R; i++) {
            for (long long j = i + 1; j <= R; j++) {
                ans = min(ans, i * j % 2019);
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int h, w;	bool vis[50][50] = {0};

int bfs(int x, int y) {
	bool used[h][w] = {0};		int dist[h][w], mx = 0;		memset(dist, 0, sizeof(dist));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			used[i][j] = vis[i][j];
	queue <pair <int, int>> q;
	q.push({x, y});		used[x][y] = true;
	while (!q.empty()) {
		pair<int, int> z = q.front();
		int u = z.first;	int v = z.second;
		q.pop();
		if (v + 1 < w && !used[u][v + 1]) {	//right
			q.push({u, v + 1});
			used[u][v + 1] = true;
			dist[u][v + 1] = dist[u][v] + 1;
		}
		if (u - 1 >= 0 && !used[u - 1][v]) {	//up
			q.push({u - 1, v});
			used[u - 1][v] = true;
			dist[u - 1][v] = dist[u][v] + 1;
		}
		if (v - 1 >= 0 && !used[u][v - 1]) {	//left
			q.push({u, v - 1});
			used[u][v - 1] = true;
			dist[u][v - 1] = dist[u][v] + 1;
		}
		if (u + 1 < h && !used[u + 1][v]) {	//down
			q.push({u + 1, v});
			used[u + 1][v] = true;
			dist[u + 1][v] = dist[u][v] + 1;
		}
	}
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			mx = max(mx, dist[i][j]);
	return mx;
}

int main() {
	cin >> h >> w;
	char temp;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> temp;
			if (temp == '#')	vis[i][j] = true;
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (!vis[i][j]) {
				int x = bfs(i, j);
				//cout << x << endl;
				ans = max(ans, x);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,K = list(map(int,input().split()))
matrix = [[0 for _ in range(K)] for _ in range(N)]
box = [input() for _ in range(2*K)]

for i in range(int(len(box)/2)):
    j = 2*i+1
    candy = list(map(int,box[j].split()))
    for k in candy:
        matrix[k-1][i] = 1

count = 0
for line in matrix:
    if sum(line) == 0:
        count += 1
print(count)


Measured memory_bytes: 9196
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
a = np.array(LIST())
#print(a)
a = np.bincount(a)
#print(a)
b = a.copy()
#print(b)
b[1:] += a[:-1]
#print(b)
b[:-1] += a[1:]
#print(b)
print(b.max())


Measured memory_bytes: 24436
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String s1 = scanner.next();
		String s2 = scanner.next();
		checkLength(n, s1, s2);
	}
	
	public static void checkLength(int n,String s1,String s2){
		for (int j = 0; j < n; j++) {
			if (s1.substring(j)
					.equals(s2.substring(0, n - j))) {
				System.out.println( n + j);
				return;
			}
		}
		System.out.println(2 * n);
	}
}


Measured memory_bytes: 9684
#include<iostream>
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn = 2e5+7;
vector<int> g[maxn];
int cnt[maxn];
int ans[maxn];
bool vis[maxn];
void dfs(int root,int acc)
{
    ans[root] = cnt[root] + acc;
    vis[root] = 1;
    for(int ch:g[root])
    {
        if(!vis[ch])
        {
            dfs(ch,ans[root]);
        }
    }
}
int main()
{
    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i=0;i<q;++i)
    {
        int p,x;
        cin>>p>>x;
        cnt[p] += x;
    }
    dfs(1,0);
    for(int i=1;i<=n;++i)
    {
        cout<<ans[i]<<" ";
    }
}

Measured memory_bytes: 21120
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
k = int(input())
a, b = map(int,input().split())
for i in range(a,b+1):
    if i%k==0:
        print ('OK')
        exit()
print ('NG')


Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

#define MOD 1000000007

int main() {
        int i, t, k, r;
        long long m, m1;
        long long mm[33];
        long n, bt = 1, m2 = 1;

        cin >> m >> n;
        mm[0] = m1 = m;
        for (i = 1; i < 33; i++) {
                m1 = m1 * m1;
                m1 = m1 % MOD;
                mm[i] = m1;
        }
        for (i = 0; i < 33; i++) {
                if (n & bt) {
                        m2 = m2 * mm[i];
                        m2 = m2 % MOD;
//                      cout << i << endl;
                }
                bt <<= 1;
        }

        cout << m2 << endl;

        return 0;
}



Measured memory_bytes: 3132
#include <stdio.h>
int main(void){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a<b) {
       if(b<c) printf("%d %d %d\n",a,b,c);
       else if(a<c) printf("%d %d %d\n",a,c,b);
       else printf("%d %d %d\n",c,a,b);
   }
   else if(a<c) printf("%d %d %d\n",b,a,c);
   else if(b<c) printf("%d %d %d\n",b,c,a);
   else printf("%d %d %d\n",c,b,a);
   return 0;
}



Measured memory_bytes: 2104
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/

 const ll N=1e5+ 5;
 ll dp[N];

int main()
{
   fast;
   memset(dp,0,sizeof(dp));
   ll n,k;
   cin>>n>>k;
   ll a[n+1];
   for(int  i=1;i<=n;i++)
   {
       cin>>a[i];
   }
   dp[1]=0;
    for(int i=2;i<=min(n,k);i++)
    {
        dp[i]=abs(a[i]-a[1]);
    }
   for(int i=k+1;i<=n;i++)
   {     ll mi=INT_MAX;
        for(int j=1;j<=k;j++){
       mi=min(dp[i-j]+ abs(a[i]-a[i-j]),mi);
   }
   dp[i]=mi;
   }
   cout<<dp[n]<<endl;



}


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

int main() {
  int x;cin>>x;
  int ans=1;
  for(int i=2;i<=sqrt(x);i++){
    int a=1;
    while(a<=x){
      ans=max(ans,a);
      a*=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3572
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    R = ni()
    if R < 1200:
        print('ABC')
    elif 1200 <= R < 2800:
        print('ARC')
    else:
        print('AGC')


if __name__ == '__main__':
    main()


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

int main(){
 	int N,ans(0);
  	string ABC;
  	cin >> N >> ABC;
  	for(int i = 0 ; i < N - 2 ; i ++){
     	if(ABC[i] == 'A' && ABC[i + 1] == 'B' && ABC[i + 2] == 'C') ans ++;
    }
  	cout << ans << endl;
}

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

class Node:
    def __init__(self):
        self.parent_id = -1
        self.sib = -1
        self.left = -1
        self.right = -1
        self.deg = 0
        self.height = 0
        self.depth = 0
        self.children = []

def cal_depth (node,x):
    node.depth = x

    for children_id in node.children:
        cal_depth(nodes[children_id],x+1)

def cal_height(node):

    h1 = 0
    h2 = 0
    if node.left != -1:
       h1 = cal_height(nodes[node.left]) + 1
    if node.right != -1:
       h2 = cal_height(nodes[node.right]) +1

    node.height = max(h1,h2)

    return max(h1,h2)



nodes = []
for i in range(n):
    nodes.append(Node())

for i in range(n):
    deg = 0
    table = list(map(int,input().split()))
    node_id = table[0]
    nodes[node_id].left = table[1]
    nodes[node_id].right = table[2]
    if table[1] == -1 and table[2] == -1:
        nodes[node_id].deg = 0
    elif table[1] == -1 or table[2] == -1:
        nodes[node_id].deg = 1
        if table[1] != -1:
            nodes[table[1]].parent_id = node_id
            nodes[node_id].children.append(table[1])
        else:
            nodes[table[2]].parent_id = node_id
            nodes[node_id].children.append(table[2])
    else:
        nodes[node_id].deg = 2
        nodes[table[1]].parent_id = node_id
        nodes[table[2]].parent_id = node_id
        nodes[table[1]].sib = table[2]
        nodes[table[2]].sib = table[1]
        nodes[node_id].children.append(table[1])
        nodes[node_id].children.append(table[2])

for node in nodes:
    if node.parent_id == -1:
        cal_depth(node,0)
        cal_height(node)
        break



for i in range(n):

    print("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "%(i,nodes[i].parent_id,nodes[i].sib,nodes[i].deg,nodes[i].depth,nodes[i].height),end = "")

    if nodes[i].parent_id == -1:
        print("root")
    else:
        if len(nodes[i].children) == 0: #葉
            print("leaf")
        else: #節
            print("internal node")



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

int main()
{
  int K, S;
  int count = 0;

  cin >> K >> S;
  for (int i = 0; i <= K; i++)
  {
    for (int j = 0; j <= K; j++)
    {
      if (S - i - j <= K && i + j <= S)
        count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;



int main() {
	int a, b;
	int h, m;

	cin >> a >> b;
	cin >> h >> m;

	double ar, br;

	br = double(360) / double(60) * m;

	ar = double(360) / 720 * (double(60) * h + m);

	double rad = abs(ar - br) / 180 * M_PI;

	double c;

	c = sqrt(a * a + b * b - 2 * a * b * cos(rad));

	cout << fixed << setprecision(10) << c << endl;
	
}

Measured memory_bytes: 4136
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(a>b*c){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  int n,m;cin>>n>>m;
  UnionFind uf(n+m);
  rep(i, n){
    int k;cin>>k;
    rep(j, k){
      int l;cin>>l;l--;
      uf.unite(m+i, l);
    }
  }

  bool f=true;
  rep(i, n)if(!uf.same(m, m+i))f=false;

  if(f)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}



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

int main() {
	int n, a, ans;
	double t, x, y, z, k = 1000000000;
	cin >> n >> t >> a;
	double h;
	for(int i = 0; i < n; i++){
		cin >> h;
		x = t - h * 0.006;
		y = min(abs(a - x), k);
		if(y != k){
			k = y;
			ans = i + 1;
		}
		
	}
	cout << ans << endl;
	
 	return 0;
}

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

int main()
{
	int N;
	while(scanf("%d", &N), N)
	{
		int hei=0;
		bool f[5005][5]={0};
		
		while(N--)
		{
			int d,p,q;
			scanf("%d%d%d", &d,&p,&q);
			p--; q--;
			
			int h=hei+1;
			while(1)
			{
				if(h==0) break;
				bool g=true;
				for(int i=q; i<=q+(d==1?p:0); i++)
				{
					if(f[h-1][i]) 
					{
						g=false;
						break;
					}
				}
				if(!g) break;
				h--;
			}
			hei=max(hei, h+(d==1?0:p));
			for(int i=h; i<=h+(d==1?0:p); i++)
			for(int j=q; j<=q+(d==1?p:0); j++)
			{
				f[i][j]=1;
			}
			
			for(int i=h; i<=hei; i++)
			{
				while(1)
				{
					bool g=true;
					for(int j=0; j<5; j++)
					{
						if(f[i][j]==0)
						{
							g=false;
							break;
						}
					}
					if(!g) break;
					
					for(int k=i; k<=hei+1; k++)
					for(int j=0; j<5; j++)
					{
						f[k][j]=f[k+1][j];
						f[k+1][j]=0;
					}
					hei--;
				}
			}
			

		}
		
		int cnt=0;
		for(int i=0; i<5; i++)
		for(int j=0; j<=hei; j++)
		{
			if(f[j][i]) cnt++;
		}
			
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 0
import java.util.*;

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

        int N = sc.nextInt();

        sc.nextLine();

        String[] words = new String[N];
        for (int i = 0; i < N; i++) {
            words[i] = sc.nextLine();
        }

        ArrayList<String> store = new ArrayList<>();

        char lastChar = words[0].charAt(words[0].length() - 1);

        for (int i = 0; i < N; i++) {
            if (i == 0) {
                store.add(words[i]);
                continue;
            }

            if (lastChar != words[i].charAt(0)) {
                System.out.println("No");
                return;
            }

            for (String word : store) {
                if (word.equals(words[i])) {
                    System.out.println("No");
                    return;
                }
            }

            lastChar = words[i].charAt(words[i].length() - 1);
            store.add(words[i]);
        }

        System.out.println("Yes");

    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define maxn 500005
using namespace std;
bool same(string s) {
	char base = s[0];
	for(char c : s)
		if(c != base)
			return false;
	return true;
} 
int f[2][maxn];
bool good[2][maxn];
void kmp(string s,int *f,bool *good) {
	f[0] = -1;
	for(int i=1,j=-1;i<(int)s.size();i++) {
		while(j!=-1 && s[i] != s[j+1])	j = f[j];
		if(s[i] == s[j+1])	j++;
		f[i] = j;
	}
	good[0] = true;
	for(int i=1;i<(int)s.size();i++)
		if(f[i] == -1 || (i+1) % (i-f[i]) != 0)
			good[i] = true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	if(same(s)) {
		cout << (int)s.size() << endl << 1 << endl;	
	}
	else {
		kmp(s,f[0],good[0]);
		if(good[0][(int)s.size()-1]) {
			cout << 1 << endl << 1 << endl;	
		}
		else {
			reverse(s.begin(),s.end());
			kmp(s,f[1],good[1]);
			int ans = 0;
			for(int i=0;i<(int)s.size()-1;i++)
				if(good[0][i] && good[1][(int)s.size()-1-(i+1)])
					ans++;
			cout << 2 << endl << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6064
package main

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

func main() {
	// 入力文字列の読み込み
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	input, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	var output int
	// a<= √Nとなるため
	aLimit := int(math.Sqrt(float64(input)))
	a := 1
	b := 1
	for i := aLimit; i > 0; i-- {
		if input%i == 0 {
			a = i
			b = input / i
			break
		}
	}
	if b == 1 {
		a = input
	}
	output = a + b - 2

	fmt.Println(output)
}


Measured memory_bytes: 640
#include  <stdio.h>
int main(void){
  int h,w,i;
  char t[100];
  scanf("%d%d\n",&h,&w);
  for (i=0;i<w+2;i++) printf("#");
  printf("\n");
  for (i=0;i<h;i++){
    scanf("%s",t);
    printf("#%s#\n",t);
  }
  for (i=0;i<w+2;i++) printf("#");
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  string t;
  cin>>t;
  int k;
  cin>>k;
  set<int> s;
  for(int i=0;i<k;i++){
    int x;
    cin>>x;
    s.insert(x);
  }
  vector<int> v;
  for(int i=t.length()-1;i>=0;i--){
    v.push_back(t[i]-'0');
  }
  int ind=-1;
  for(int i=v.size()-1;i>=0;i--){
    bool flag=true,flag2=false;
    if(s.find(v[i])!=s.end()){
      for(int j=v[i]+1;j<=9;j++){
        if(s.find(j)==s.end()){
          v[i]=j;
          flag=false;
          flag2=true;
          ind=i-1;
          break;
        }
      }
      if(flag){
        if(i==v.size()-1){
          for(int j=1;j<=9;j++){
            if(s.find(j)==s.end()){
              v.push_back(j);
              flag2=true;
              break;
            }
          }
        }else{
          v[i+1]++;
          i+=2;
        }
        ind=i;
      }
    }
    if(flag2) break;
  }
  if(ind!=-1){
    for(int i=0;i<=9;i++){
      if(s.find(i)==s.end()){
        for(int j=0;j<=ind;j++){
          v[j]=i;
        }
        break;
      }
    }
  }
  for(int i=v.size()-1;i>=0;i--){
    cout<<v[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct tree{
	int r;
	int l;
	int p;
}T[10001];
int D[10001],H[10001];
void setdepth(int u,int d){
//	D[u]=v;
//	if(T[u].l!=-1)setdepth(T[u].l,v+1);
//	if(T[u].r!=-1)setdepth(T[u].r,v+1);
	if(u==-1)return;
	D[u]=d;
	setdepth(T[u].l,d+1);
	setdepth(T[u].r,d+1);
}
int setheight(int u){
	int h1=0,h2=0;
	if(T[u].l!=-1)h1=setheight(T[u].l)+1;
	if(T[u].r!=-1)h2=setheight(T[u].r)+1;
	return H[u]=max(h1,h2);
}
int getsibing(int u){
	if(T[u].p==-1)return -1;
	if(T[T[u].p].l!=u&&T[T[u].p].l!=-1)return T[T[u].p].l;
	if(T[T[u].p].r!=u&&T[T[u].p].r!=-1)return T[T[u].p].r;
	return -1;
}
void print(int i){
	printf("node %d: ",i);
	printf("parent = %d, ",T[i].p);
 	printf("sibling = %d, ",getsibing(i));
 	int degree=0;if(T[i].l!=-1)degree++;
 	if(T[i].r!=-1)degree++;
 	printf("degree = %d, ",degree);
 	printf("depth = %d, ",D[i]);
 	printf("height = %d, ",H[i]);
 	if(T[i].p==-1)printf("root\n");
 	else if(T[i].l==-1&&T[i].r==-1){
 		printf("leaf\n");
		 	 }
		 	 else printf("internal node\n");
}
int main(){
	int n,id,left,right;scanf("%d",&n);
	for(int i=0;i<n;i++){
	T[i].p=-1;//	T[i].l=T[i].r=
	}
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&id,&left,&right);
		T[id].l=left;T[id].r=right;
		if(left!=-1){
			T[left].p=id;
		}
		if(right!=-1){
			T[right].p=id;
		}
	}
	int root;
	for(int i=0;i<n;i++){
		if(T[i].p==-1)root=i;
	}
	setdepth(root,0);
	setheight(root);
	for(int i=0;i<n;i++){
		print(i);
	}
	return 0;
}


Measured memory_bytes: 3212
//
// Created on 2020/04/27.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans = LINF;
    ll l,r;
    cin>>l>>r;

    if(r-(l-1) >= 2019){
        ans = 0;
    }else{
        for (ll j = l; j < r; ++j) {
            for (ll i = j+1; i <= r; ++i) {
                ans = min((j*i)%2019,ans);
                if(!ans) break;
            }
        }
    }

    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    int n,i,cnt=0,ans=0;
    vector<int>vec;
    cin>>n;
    string s;
    cin>>s;
    for(i=0; i<n; i++)
    {
        if(s[i]=='W')
        {
            vec.push_back(i);
        }
    }
    for(i=n-1; i>=0; i--)
    {
        if(cnt==vec.size())
            break;
        if(s[i]=='R')
        {
            swap(s[vec[ans]],s[i]);
            ans++;
            cnt++;
        }
        else
        {
            cnt++;
        }

    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4404
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,m,q = inpm()
    ans = 0
    abcd = []
    for _ in range(q):
        a,b,c,d = inpm()
        abcd.append((a,b,c,d))
    for e in itertools.combinations_with_replacement(range(m),n):
        cnt = 0
        for i in range(q):
            [a,b,c,d] = abcd[i]
            if e[b-1] - e[a-1] == c:
                cnt += d
        ans = max(ans,cnt)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 10864
/*
2017_03_02_AC
??????????????????
????¬????????????????????????????i???A?????§????????????????????????????????§???????????????*i???A????¶??????????????????§?????????
????´???????????????????????????????????????£??????(a/b)+(c/d)??????(a*d+c*b)/(b*d)??¨??????????????§?????????
???????????????????????¨LTE???
????????????????????????????????´??\?????????????????§??????????????§?¢?????????????
??????????????°?????????????¨????????????????
???(sum/pro) + (1/i) = (sum*d+pro)/(pro*i)
	?????????????????§???????§???????????????¨??????????????????
????????????
???pair???????????????????????????
????´??????????????????¬????????§?????????
?????????????????¨???????????????????????????????????°?????????????????????A??\?????¨???????????¶????????§???
????????????pro??????????´???????????????????????????§???????????????????????????
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int P,Q,A,N,ans;

void dfs(int term, int minnum, int prod, int sum){
  if(A < prod || N < term) return;
	if(sum*Q == prod*P){  /* (sum/prod) = (P/Q) ????????????????????? */
	  ans++;
		return;
	}
	for(int i=minnum; prod*i <= A; i++){ /* ?¬?????¶???????????????°????????????????°??????????????????????????????????????????????minnum??\??? */
    dfs(term + 1, i, prod*i, sum*i + prod); /* ????????§??? (sum/prod)+(1/i)=(sum*i+prod)/(prod*i) ??????????????? */
  }
  return;
}

int main() {
  while(1){
    cin>>P>>Q>>A>>N;
    if(P==0&&Q==0&&A==0&&N==0) break;
    ans = 0;
    REP(i,1,A+1){   /* ?????????(????°???????)???????±????????????? */
      dfs(1,i,i,1);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3004
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const int MAXN=1e4+9;
const double eps=1e-8;
const long double pi=3.1415926535897932384626433832795;
const long double e=2.71828182845904523536028747135266;
vector<string> ans;
map<string,int> mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    while(t--){
        int n,maxn=-1;
        string s;
        cin >> n;
        for (int i=0;i<n;i++){
            cin >> s;
            int f=++mp[s];
            if(maxn<f){
                maxn=f;
                ans.clear();
                ans.push_back(s);
            }
            else if(maxn==f){
                ans.push_back(s);
            }
        }
        sort(ans.begin(),ans.end());
        for(auto v:ans) {
            cout << v << endl;
        }
    } 
    return 0;
}


Measured memory_bytes: 25456