akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
#define f(x,y,z) for(int x=(y),__=(z);x<=__;++x)
typedef long long ll;
#define v64 vector<ll>
//dp[i][j]：到第i个，j==1：选择此个，j==0：不选择此个，到此共选择了i/2个，得到的最大值。
/* 转移方程：
 
i为奇数时
选择(i-1)/2个 
dp[i][1]= arr[i]+max{dp[i-2][0],dp[i-2][1],dp[i-3][1],dp[i-3][0]}

dp[i][0]= max{dp[i-2][0]+arr[i-1],dp[i-3][1]+arr[i-1],dp[i-3][0]+arr[i-2],dp[i-3][0]+arr[i-1]} 
i为偶数时

*/ 
ll dp[maxn][2];
int main(){
	int n;
	scanf("%d",&n);
	v64 arr(n+1,0);
	f(i,1,n)
		cin >> arr[i];
	dp[2][1]=arr[2];
	dp[2][0]=arr[1];
	f(i,3,n){
		if(i&1){
			dp[i][1]=arr[i]+max(dp[i-2][0],dp[i-2][1]);
			dp[i][0]=max(arr[i-2]+dp[i-3][0],arr[i-1]+dp[i-2][0]);
		}
		else{
			dp[i][1]=arr[i]+dp[i-1][0];
			dp[i][0]=arr[i-1]+dp[i-2][0];
		}
	}
	printf("%lld\n",max(dp[n][1],dp[n][0]));
}

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

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n, q;
    cin >> n >> q;
    vector<int> E[200010];

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    ll cnt[200010] = {};

    rep(i, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    queue<int> que;
    que.push(0);
    bool visited[200010] = {};
    visited[0] = true;

    while (!que.empty()) {
        int q = que.front();
        que.pop();
        for (auto to : E[q]) {
            if (visited[to]) continue;
            visited[to] = true;
            que.push(to);
            cnt[to] += cnt[q];
        }
    }

    rep(i, n) cout << cnt[i] << (i == n - 1 ? "\n" : " ");

    return 0;
}


Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string N; cin >> N;
    int m = 0;
    for(auto c : N) m += c - '0';
    ATYN(m % 9 == 0)

    return 0;
}

Measured memory_bytes: 3724
import Control.Applicative
import Data.List

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve = fst . foldl' f (0, 0)
  where
    f (c, mx) h
      | mx <= h = (c+1, h)
      | otherwise = (c, mx)


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

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> co(n);
    vector<ll> caldef(n);
    vector<ll> calmi(n);
    ll sum = 0;
    rep(i,n){
        co[i] = 0;
    }
    rep(i,n){
        cin>>a[i];
        co[a[i]-1]++;
    }
    rep(i,n){
        caldef[i] = co[i]*(co[i]-1)/2;
        if(co[i]==0){
            calmi[i] = 0;
        }else{
            calmi[i] = (co[i]-1)*(co[i]-2)/2;
        }
        sum += caldef[i];
    }
    rep(i,n){
        ll ans = sum - caldef[a[i]-1] + calmi[a[i]-1];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 8832
use proconio::input;

fn main() {
    input!(n:i32,m:i32);
    let mut v = vec![vec![0;0usize];n as usize];
    for _ in 0..m{
        input!(mut x:usize,mut y:usize);
        x -= 1usize;
        y -= 1usize;
        v[x].push(y as i32);
        v[y].push(x as i32);
    }
    let mut ans = vec![-1;n as usize];
    let mut q = std::collections::VecDeque::<i32>::new();
    q.push_back(0);
    while !q.is_empty() {
        let cur = q.pop_front().unwrap();
        for i in v[cur as usize].iter() {
            if ans[(*i) as usize] == -1 {
                ans[(*i) as usize] = cur;
                q.push_back(*i);
            }
        } 
    }
    println!("Yes");
    for i in ans[1..].iter(){
        println!("{}",(*i) + 1);
    }
}


Measured memory_bytes: 11316
# https://atcoder.jp/contests/abc060/tasks/abc060_b

A, B, C = gets.split.map(&:to_i)
# 7, 5, 1
# => 7 % 5, 14 % 5, 21 % 5, 28 % 5, 35 % 5, 42 % 5, 49 % 5, ...
# => 7 % 5, 14 % 5, 21 % 5, 28 % 5, 35 % 5, (35 + 7) % 5, (35 + 14) % 5, ...
# => 7 % 5, 14 % 5, 21 % 5, 28 % 5, 35 % 5, 7 % 5, 14 % 5, ...
# => 2, 4, 1, 3, 0, 2, 4, ...

multiples_of_a = (1..B).to_a.map{|b| A * b}
puts multiples_of_a.any? { |multiple| multiple % B == C } ? 'YES' : 'NO'


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
const int maxn = 100000;
ll mod = INF;

int submit[maxn];
int WA=0;
int AC=0;

int main(){
    
    int n,m;
    cin >> n>>m;
    fill(submit,submit+n,0);

    rep(i,m){
        int p;
        string s;
        cin >> p;p--;
        cin >> s;
        if(submit[p]!=INF&&s=="WA"){
            submit[p]++;
        }else if(submit[p]!=INF&&s=="AC"){
            AC++;
            WA+=submit[p];
            submit[p]=INF;
        }
    }
    cout << AC<<" "<<WA<<endl;
    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
const int limit= 1e6+1;
const int inf = 1e8;
ll m[limit];
ll h[limit];
int abs(int i)
{
    if (i < 0)
    {
        return -i;
    }
    return i;
}
int k;
int dp(int i){
    if(i<1){
        return inf;
    }
    if(i==1){
        m[i] = 0;
        return 0;
    }
    if(m[i] != -1){
        return m[i];
    }
    ll temp = inf* 10;

    for(int j=1; j<=k; j++){
        temp = min(temp, dp(i-j) + abs(h[i] - h[i-j]));
    }
    m[i] = temp;
    return m[i];
}
int main(){
    int n;
    cin>>n>>k;
    for(int i= 1; i<= n; i++){
        cin>>h[i];
    }
    ms(m, -1);
    cout<<dp(n)<<endl;
    return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long>p;
int main()
{
    int n,k;
    cin>>n>>k;
    long long a,num=0;
for(int i=1;i<=n;i++)
    {cin>>a;
      p.push(a);
    }
    for(int i=1;i<=k;i++)
    {
        if(p.empty())
            break;
        else
        p.pop();
    }
    while(p.size()>=1)
    {
        num +=p.top();
        p.pop();
    }
    cout<<num;
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
 
 
int main(){
    vector<int> cnt(200010, 0);

    int N; cin >> N;
    rep(i,N-1){
        int A; cin >> A; A--;
        cnt[A]++;
    }

    rep(i,N) cout << cnt[i] << endl;
}

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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

void printVector(vector<int> A, int N){
    for(int i = 0; i < N-1; i++)
        cout<<A[i]<<" ";
    cout<<A[N-1]<<endl;
}

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

int main(void){
    cin.sync_with_stdio(false);
    int N; cin>>N;
    vector<int> nums;
    for(int i = 0; i < N; i++){
        int tmp; cin>>tmp;
        nums.push_back(tmp);
    }

    insertionSort(nums, N);

    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
struct node{
	int v,id,nxt;
}e[200100];
int front[100100],cnt;
inline void add(int u,int v,int id){
	e[++cnt].v=v;
	e[cnt].id=id;
	e[cnt].nxt=front[u];
	front[u]=cnt;
}
int n,ans[100100];
inline void dfs(int x,int fa,int last){
	int siz=0;
	for(int i=front[x];i;i=e[i].nxt){
		int v=e[i].v;
		if(v!=fa){
			//dfs(v,x);
			siz++;
			if(siz==last)siz++;
			dfs(v,x,siz);
			ans[e[i].id]=siz;
		}
	}

}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		add(x,y,i);add(y,x,i);
	}
	dfs(1,0,0);
	int now=0;
	for(int i=1;i<n;i++)now=max(now,ans[i]);
	cout<<now<<endl;
	for(int i=1;i<n;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005,mod=998244353;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int qidian;
int huan;
int a[max_n];
int ci[max_n];
int bu;
int count1;
int ans[max_n];
vector<int>v;
int main()
{
	int n;ll k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int dang=1;ci[dang]=1;
	while(1)
	{
		dang=a[dang];
		count1++;
		ans[count1]=dang;
		if(ci[dang]==0)ci[dang]=1;
		else
		{
			qidian=dang;
			ci[dang]++;
			if(bu==0)bu=count1;
		}
		if(qidian)
		{
			huan++;
			v.pb(dang);
		}
		if(ci[dang]==3)
		{
			break;
		}
	}
	if(k<bu)
	{
		cout<<ans[k];
	}
	else
	{
		huan--;
	k-=(bu-huan);
	cout<<v[k%huan];
	}
	
}

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


const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll f(ll n,ll m){
  //k=0の時の答え
  ll ans=m;
  rep(i,n-1){
    ans*=m-1;
    ans%=MOD;
  }
  return ans;
}
int main() {
    // 前処理
    COMinit();
    ll n,m,k;cin>>n>>m>>k;
    ll answer=0;
    ll ff=f(n-k,m);
    for(int i=k;i>=0;i--){
      answer+=(COM(n-1,i)%MOD)*(ff%MOD)%MOD;
      ff=(ff*(m-1))%MOD;
      answer%=MOD;
    }
    cout << answer << endl;
    //cout<<COM(n-1,1)%MOD<<endl;
}

Measured memory_bytes: 15592
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, A := sc.nextInt(), sc.nextInt()

	fmt.Fprintln(wtr, N*N-A)
	wtr.Flush()
}


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

int gcd(int a, int b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
int sp(int a, int b, int c)
{
    return gcd(a, gcd(b, c));
}
int main()
{
    int k;
    cin >> k;
    int cnt = 0;

    for (int i = 1; i <= k; i++) {
        for (int j = 1;j <= k; j++) {
            for (int m = 1; m <= k; m++) cnt += sp(m, j, i);
        }
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 3564
#define zero(n)(fabs(n)<.01)
main(n,a,b,c,d,p,q,r,D){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d);//fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;   //won't lose generality
		p=3*a,q=2*b,r=c,D=q*q-4*p*r;  //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)&&y1*y2>0)goto one;
			puts(
				zero(x1)?(
					d==0?"1 0":"2 1"
				):zero(x2)?(
					d==0?"0 1":"1 2"
				):x1>0?(
					d>0?"2 1":d<0?"3 0":"2 0"
				):x2<0?(
					d>0?"0 3":d<0?"1 2":"0 2"
				):(
					d>0?"2 1":d<0?"1 2":"1 1"
				)
			);
		}else if(D==0)
			puts(d>0?"0 1":d<0?"1 0":"0 0");
		else one:
			puts(d>0?"0 1":d<0?"1 0":"0 0");
	}
	exit(0);
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  vector<int> a(5);
  rep(i,5) cin>>a[i];
  int k; cin>>k;

  bool ans=1;
  rep(i,4){
    for(int j=i+1;j<5;j++){
      int d=a[i]-a[j];
      // cout<<d<<endl;
      if(d<-k||k<d)
      ans=0;
    }
  }
  cout<<(ans?"Yay!":":(")<<endl;

  return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

ans = 0

for i in range(N):
    num = C
    for j in range(M):
        num += A[i][j] * B[j]
    if num > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, k;
    cin >> n >> k;
    lli ans = 0;
    for (lli i = k; i <= n + 1;i++){
        ans += i * n - i * (i - 1)+1;
        ans %= 1000000007;
    }
    out(ans);
}

Measured memory_bytes: 3572
#pragma warning( disable : 6031)
 
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
//const long long mod = 1000000007;
const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
int main() {
	char N[4];
	scanf("%s", N);
	for (int i = 0; i < 3; i++) {
		if (N[i] == '7') {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 1732
import java.util.PriorityQueue

fun main(args: Array<String>) {
    val (x, y, z, k) = readInputLine().split(" ").map { it.toInt() }
    val aList = readInputLine().split(" ").map { it.toLong() }.sortedDescending()
    val bList = readInputLine().split(" ").map { it.toLong() }.sortedDescending()
    val cList = readInputLine().split(" ").map { it.toLong() }.sortedDescending()
    
    val alreadyAdded = mutableListOf(Triple(0, 0, 0))
    
    val queue = PriorityQueue<Pair<Long, Triple<Int, Int, Int>>>(k, {x, y -> if (x.first > y.first) -1 else if (x.first == y.first) 0 else 1})
    queue.add(Pair(aList[0] + bList[0] + cList[0], Triple(0, 0, 0)))
    
    for (i in 1..k) {
        val (p, triple) = queue.poll()
        val (px, py, pz) = triple
        
        println(p)
        
        if (px < x - 1 && !alreadyAdded.contains(Triple(px + 1, py, pz))) {
            queue.add(Pair(aList[px + 1] + bList[py] + cList[pz], Triple(px + 1, py, pz)))
            alreadyAdded.add(Triple(px + 1, py, pz))
        }
        if (py < y - 1 && !alreadyAdded.contains(Triple(px, py + 1, pz))) {
            queue.add(Pair(aList[px] + bList[py + 1] + cList[pz], Triple(px, py + 1, pz)))
            alreadyAdded.add(Triple(px, py + 1, pz))
        }
        if (pz < z - 1 && !alreadyAdded.contains(Triple(px, py, pz + 1))) {
            queue.add(Pair(aList[px] + bList[py] + cList[pz + 1], Triple(px, py, pz + 1)))
            alreadyAdded.add(Triple(px, py, pz + 1))
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
ll mod = 998244353;

ll modpow(ll a, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod){
    return modpow(a, mod-2, mod);
}

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

    ll n,m,k,ans=0;
    cin >> n >> m >> k;

    ll u=1,v=1,temp;
    rep(i,k+1){
        if(i==0) ans = m * modpow(m-1,n-1-i,mod) % mod;
        else ans+= m * modpow(m-1,n-1-i,mod) % mod * (u * modinv(v,mod) % mod) % mod;
        if(abs(ans)>mod) ans %= mod;
        u = u * (n-1-i) % mod;
        v = v * (i+1) % mod;
    }
    
    print(ans);
    return 0;
}

Measured memory_bytes: 3652
import sys

a,b,c, x,y = [int(x) for x in sys.stdin.readline().split(" ")]


if a + b < c * 2:
	z = a * x + b * y
else:
	d = abs(x - y)
	e = max(x, y) - d

	zd1 = (a if x > y else b) * d
	zd2 = c * d * 2

	z = c * e * 2 + min(zd1, zd2)

print(z)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register ll
#define maxn 100
#define mod 998244353LL
#define inf 1000000007LL
namespace lib
{
	using namespace std;
	class fastio
	{
		private:
			#define _NUMLEN 111
			char _num[_NUMLEN],_ch;
			int _f,_head;
			bool _useSTD;
		public:
			inline void ioSTD()
			{
				_useSTD=1;
				ios::sync_with_stdio(false);
				cin.tie(0),cout.tie(0);
			}
			inline void gc(char & _c)
			{
				if(_useSTD)cin>>_c;
				else _c=getchar();
			}
			inline void pc(char _c)
			{
				if(_useSTD)cout<<_c;
				else putchar(_c);
			}
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_x=0;
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch);
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch);
					_f&&(_x=-_x,_f=0);
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cin>>_x;
				else
				{
					_T _k;
					if(_x==0) {pc('0'),pc(' ');return *this;}
					if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
					while(_head>0) pc(_num[_head]),--_head;
					pc(' ');
				}
				return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define endln pc('\n')
		fastio() {_f=0,_head=0,_useSTD=0,_ch=' ';}
	}io;
	inline void fileio(string _r,string _w)
	{
		if(_r[0]!='-')freopen(_r.c_str(),"r",stdin);
		if(_w[0]!='-')freopen(_w.c_str(),"w",stdout);
	}
	#define mem(_x,_set) memset(_x,_set,sizeof(_x))
}using namespace lib;

string s[maxn],t;
int a[maxn];
signed main()
{
	// fileio("tt.in","tt.out");
	io.ioSTD();
	int n,ans=0;
	io>>n;
	for(rgi i=1;i<=n;++i)
		io>>s[i]>>a[i];
	io>>t;
	bool tc=0;
	for(rgi i=1;i<=n;++i)
	{
		if(tc)ans+=a[i];
		if(s[i]==t)tc=1;
	}
	io<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node {
  int parent;
  int left;
  int right;
};

Node T[MAX];

void preParse(int u) {
  if (u == NIL) {
    return;
  }
  cout << " " << u;
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u) {
  if (u == NIL) {
    return;
  }
  inParse(T[u].left);
  cout << " " << u;
  inParse(T[u].right);
}

void postParse(int u) {
  if (u == NIL) {
    return;
  }
  postParse(T[u].left);
  postParse(T[u].right);
  cout << " " << u;
}

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

  for (int i = 0; i < N; i++) {
    T[i].parent = NIL;
  }

  int v, left, right;
  for (int i = 0; i < N; i++) {
    cin >> v >> left >> right;
    T[v].left = left;
    T[v].right = right;
    if (left != NIL) {
      T[left].parent = v;
    }
    if (right != NIL) {
      T[right].parent = v;
    }
  }

  int root = 0;
  for (int i = 0; i < N; i++) {
    if(T[i].parent == NIL) {
      root = i;
    }
  }

  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;

  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;

  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;

  return 0;
}


Measured memory_bytes: 3120
import Control.Applicative

import Control.Monad
    (replicateM)
    
import Data.List
    (intersperse)
    
type Shuffles = [Int]

type Problem = [(String, Shuffles)]

type Result = [String]

shuffle :: String -> Int -> String

shuffle text index
    = (drop index text) ++ (take index text)
    
solve :: Problem -> Result

solve problem
    = map (\(t, s) -> foldl shuffle t s) problem

output :: Result -> String

output result
    = concat $ intersperse "\n" result
    
input :: IO Problem

input
    = inputProblem []
        
inputProblem :: Problem -> IO Problem

inputProblem problem
    = do
        text <- getLine
        if text == "-"
            then return problem
            else do
                shuffles <- inputShuffles
                inputProblem $ problem ++ [(text, shuffles)]
        
inputShuffles :: IO Shuffles
    
inputShuffles
    = do
        n <- read <$> getLine
        shuffles <- replicateM n $ read <$> getLine
        return shuffles

main :: IO ()

main
    = putStrLn.output =<< solve <$> input

Measured memory_bytes: 4164
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int v1,v2,v3;
		vector<int> v;
		cin >>v1>>v2>>v3;
		v.push_back(v1);
		v.push_back(v2);
		v.push_back(v3);
		sort(v.begin(),v.end(),greater<int>());
		cout <<(v[0]*v[0] == v[1]*v[1]+v[2]*v[2]?"YES":"NO")<< endl;
	}
	return 0;
}

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

int main(){
  int a=0;
  string we1,we2;
  cin >> we1 >> we2;
  for(int i=0;i<3;i++){
    if(we1.at(i)==we2.at(i)){
      a++;
    }
  }
  cout << a << endl;
}

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

int main() {
  int a;
  int b;
  int c;
  int d;
  
  cin >> a;
  cin >> b;
  cin >> c;
  d = 0;
  
  for (int i = a; i <= b; i++) {
    int e = i;
    if (e%c == 0) {
      d++; 
    }
  }
  
  cout << d;
   
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define PI 3.1415926535

int main(void){

    int k, a, b;
    cin >> k >> a >> b;

    int aa = (a - 1) / k;
    int bb = b / k;
    if(bb-aa>0)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;

    return 0;
}


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

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> L (N);
    for (int i = 0; i < N; i++){
        cin >> L.at(i);
    }
    int place = 0;
    int count = 1;
    for (int i = 0; i < N; i++){
        place += L.at(i);
        if (place > X){
            break;
        }
        count++;
    }
    cout << count << endl;
}

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

int main() {
  int n;
  
  cin>>n; cin.ignore();
  for(int i=0; i<n; i++) {
    string str;
    getline(cin,str);
    
    int a[8], gr=0, ls=0;
    for(int j=0; j<8; j++) a[j] = str[j]-'0';
    sort(a, a+8, greater<int>());
    for(int j=0; j<8; j++) {
      gr*=10; gr+=a[j];
    }
    sort(a, a+8, less<int>());
    for(int j=0; j<8; j++) {
      ls*=10; ls+=a[j];
    }
    cout<<gr-ls<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1224
A = int(input())
B = int(input())
C = int(input())
X = int(input())

X //= 50
ans = 0
for i in range(A+1):
    for j in range(B+1):
        if 0 <= X - 10*i - 2*j <= C:
            ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())
D_X = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
b = 0
for i in range(N):
    a = 0
    while a*(A[i][0])+1 <= (D_X[0]):
        a = a+1
        b = b+1
print(b+(D_X[1]))

Measured memory_bytes: 3060
s = input()
tmp1 = 1
tmp2 = 1
yet = 0
ans = 0
for i in range(len(s)-1):
    if s[i] == '<' and s[i+1] == '<':
        tmp1 += 1
    elif s[i] == '>' and s[i+1] == '>':
        tmp2 += 1
    elif s[i] == '>' and s[i+1] == '<':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
        tmp1 = 1
        tmp2 = 1
        yet = i + 1
        if i+1 == len(s)-1:
            ans += 1
if yet != len(s)-1:
    if s[-1] == '>':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
    else:
        ans += (tmp1*(tmp1+1))//2
if len(s) == 1:
    ans = 1
print(ans)

Measured memory_bytes: 4232
s = gets.chomp
t = s.gsub(/x/, "")

def kaibun(s)
  n = s.size
  (n / 2).times do |i|
    return false if s[i] != s[n - 1 - i]
  end
  true
end

def xnum(s, t)
  a = Array.new(t.size + 1, 0)
  i = 0
  s.chars.each_with_object(a) do |c|
    if c == "x"
      a[i] += 1
    else
      i += 1
    end
  end
end

def xcount(a)
  n = a.size
  ans = 0
  (n / 2).times do |i|
    ans += (a[i] - a[n - 1 - i]).abs
  end
  ans
end

def calc(s, t)
  return -1 if !kaibun(t)
  xcount(xnum(s, t))
end

puts calc(s, t)


Measured memory_bytes: 21916
N = int(input())
S = [int(input()) for i in range(N)]
sumS = sum(S)
sortS = sorted(S)

if sumS % 10 != 0:
    ans = sumS
else:
    for i in range(N):
        if sortS[i] % 10 != 0:
            ans = sumS - sortS[i]
            break
    else:
        ans = 0

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int n,m;
int main() {
	int cnt=0,ans=0,i,flag;
	cin>>n>>m;
	for (i=1;i<=n;i++) {
		cin>>a[i];
		cnt+=a[i];
	}
	if (cnt%(4*m)==0) flag=1; else flag=0;
	for (i=1;i<=n;i++)
		if (flag&&a[i]>=cnt/4/m||!flag&&a[i]>cnt/4/m) ans++;
	if (ans>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
const ll N=4e5+6;
ll n,a,b,x;
ll par[N];
void make_par(){
   for(ll i=0;i<N;i++)par[i]=i;
}
ll find_par(ll u){
   if(par[u]==u)return u;
   return par[u]=find_par(par[u]);
}
void union_par(ll a,ll b){
   a=find_par(a);
   b=find_par(b);
   par[a]=b;
   return;
}
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         make_par();
         ll n,m;cin>>m>>n;
         for(ll i=0;i<n;i++){
            cin>>x;
            if(x==1){
               cin>>a>>b;
               a=find_par(a);
               b=find_par(b);
               if(a==b)cout<<"1\n";
               else cout<<"0\n";
               con;
            }
            cin>>a>>b;
            union_par(a,b);
         }
    }
}


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

int main(){
  int n;
  cin >> n;
  int p = 4, q = 7;
  if(n % 4 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  for(int i = 0;;i++){
    if(n % 7 == 0){
      cout << "Yes" << endl;
      return 0;
    }
    n -= 4;
    if(n <= 0){
      break;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int x;
    scanf("%d",&x);
    if (x>=400 && x<=599)
    printf("8\n");
    else if (x>=600 && x<=799)
    printf("7\n");
    else if (x>=800 && x<=999)
    printf("6\n");
    else if (x>=1000 && x<=1199)
    printf("5\n");
    else if (x>=1200 && x<=1399)
    printf("4\n");
    else if (x>=1400 && x<=1599)
    printf("3\n");
    else if (x>=1600 && x<=1799)
    printf("2\n");
    else
    printf("1\n");
    return 0;
}

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

int main(){
  long long Mod=1000000007;
  long long inv[1000000+10];
  inv[0]=0;
  inv[1]=1;
  for(int i=2; i<1000000+5; i++){
    inv[i]=((Mod/i)*(Mod-inv[Mod%i]))%Mod;
  }
  long long x,y;
  cin >> x >> y;
  long long ans=0;
  if((x+y)%3==0 && x<=2*y && y<=2*x){
    long long p=(2*y-x)/3;
    long long q=(2*x-y)/3;
    ans=1;
    for(int i=1; i<=q; i++){
      ans = (ans*(i+p))%Mod;
      ans = (ans*inv[i])%Mod;
    }
  }
  printf("%d", ans);
}


Measured memory_bytes: 8064
class Factorial:
    def __init__(self, n, mod=10**9+7):
        self.fac = [0] * (n+1)
        self.ifac = [0] * (n+1)
        self.fac[0] = 1
        self.ifac[0] = 1
        modmod = mod - 2
        for i in range(n):
            self.fac[i+1] = self.fac[i] * (i+1) % mod
            self.ifac[i+1] = self.ifac[i] * pow(i+1, modmod, mod) % mod

    def comb(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        tmp =  self.ifac[n-r] * self.ifac[r] % mod
        return tmp * self.fac[n] % mod

    def perm(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        return (self.fac[n] * self.ifac[n-r]) % mod

def make_divisors(n):
    divisors = {}
    tmp = n
    for div in range(2, int(n**0.5)+1):
        if n % div == 0:
            divisors[div] = 0
        while n % div == 0:
            n //= div
            divisors[div] += 1
        div += 1
    if n > 1:
        divisors[n] = 1
    return divisors

n,m = map(int, input().split())
mod = 10**9 + 7
divisors = make_divisors(m)
fact = Factorial(n + sum(divisors.values()) + 1)

ans = 1
for value in divisors.values():
    ans = ans * fact.comb(value+n-1,value) % mod
print(ans)


Measured memory_bytes: 10984
#include <stdio.h>

long long int max(long long int a,long long int b){
	if(a>=b) return a;
	else return b;
}

int main(void) {
	long long int N, W;
	scanf("%lu%lu",&N,&W);
    long long int weight[N], value[N];
    for(int a=0;a<N;a++) scanf("%lu%lu",&weight[a],&value[a]);
    long long int dp[N+1][W+1];
    for(long long int b=0;b<W+1;b++) dp[0][b] = 0;
    for(long long int c=0;c<N+1;c++) dp[c][0] = 0;
    
   
    
    for(long long int i=0;i<N;i++){
    	for(long long int w=0;w<=W+1;w++){
    		if(weight[i]>w) dp[i+1][w] = dp[i][w];
    		else dp[i+1][w] = max(dp[i][w],dp[i][w-weight[i]]+value[i]);
    	
    }
    }
    
    printf("%lu",dp[N][W]);
 	
	return 0;
}

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


int main(){
  int n;
  cin >> n;
  map<int , int> judge;
  rep(i,n){
    int a;
    cin >> a;
    if(judge[a] == 0){
      judge[a] = 1;
    }
    else{
      judge[a] = 0;
    }
  }
  int count = 0;
  for(auto p:judge){
    auto key = p.first;
    auto value = p.second;
    if(value == 1){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <string>
#define pii pair<int,int>
#define fi first
#define se second
#define pcc pair<char,char>

using namespace std;

typedef long long ll;

int main(){
        int n, m; cin >> n >> m;
        int e[55][55], d[55];
        memset(e,0,sizeof(e));
        memset(d,0,sizeof(d));
        while(m--){
                int u, v; cin >> u >> v;
                e[u][v] = e[v][u] = 1;
                d[u]++, d[v]++;
        }
        int ok = 1, ans = 0;
        while(ok){
                int ok = 0;
                for(int i = 1; i <= n; ++i) {
                        if(d[i] == 1) {
                                d[i]--;
                                for(int j = 1; j <= n; ++j){
                                        if(e[i][j]) {
                                                //cout << i << ' ' << j << ' ' << d[i] << endl;
                                                ok = 1;
                                                d[j]--;
                                                ans++;
                                                e[j][i] = e[i][j] = 0;
                                                break;
                                        }
                                }
                        }
                }
                if(ok == 0) break;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int a;
int h;
int m;
int mm;
int s;
scanf("%d",&a);
h = a / 3600;
mm = a - 3600 * h;
m = mm / 60;
s = a - 3600 * h - 60 * m;
printf("%d:%d:%d\n",h,m,s);
}



Measured memory_bytes: 2088
n, q = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
ans = []
time = 0
while a:
    j = a.pop(0)
    if int(j[1]) > q:
        j[1] = str(int(j[1]) - q)
        a.append(j)
        time += q
    else:
        time += int(j[1])
        ans.append([j[0], str(time)])
for i in range(n):
    print(' '.join(ans[i]))



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

int main() {
  vector<int> values(3);
  cin >> values.at(0) >> values.at(1) >> values.at(2);

  sort(values.begin(), values.end(), greater<int>());

  cout << values.at(0) * 10 + values.at(1) + values.at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
int main() {  

  std::stack<int> s;
  std::string str;

  while( std::cin >> str ) {
    if( str[0] == '+' ) {
      int right = s.top(); s.pop();
      int left  = s.top(); s.pop();
      s.push(left + right);
    }
    else if( str[0] == '-' ) {
      int right = s.top(); s.pop();
      int left  = s.top(); s.pop();
      s.push(left - right);
    }
    else if( str[0] == '*' ) {
      int right = s.top(); s.pop();
      int left  = s.top(); s.pop();
      s.push(left * right);
    }
    else {
      s.push( stoi(str) );
    }
  }

  std::cout << s.top() << std::endl;

  return 0;
}

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

int main() {
  long int ans=0,a,b,c,d;
  cin >> a>>b>>c>>d;

  ans=max(a*c,max(a*d,max(b*c,b*d)));

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

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <array>

#include <cmath>

using namespace std;

typedef long long LL;

int main() {
	int m, f, r;
	vector<array<int, 3>> students;

	while (true)
	{
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;

		array<int, 3> temp = {m, f, r};
		students.emplace_back(temp);
	}

	for (auto&& student : students) {
		if (student[0] < 0 || student[1] < 0) {
			printf("F\n");
			continue;
		}

		auto score = student[0] + student[1];
		if (score >= 80) printf("A\n");
		else if (score >= 65) printf("B\n");
		else if (score >= 50) printf("C\n");
		else if (score >= 30) {
			if (student[2] >= 50) printf("C\n");
			else printf("D\n");
		}
		else printf("F\n");
	}
	return 0;
}



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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
        return 0;
    }
    else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
        return 0;
    }
    else{
        rep(i,a.size()){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }else if(a[i]<b[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
        cout<<"EQUAL"<<endl;
    }
    return 0;
}

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

int main() {
	ll n, k;
	cin >> n >> k;
	vector<vector<ll>>graph(n, vector<ll>(2,-1));
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		graph.at(i).at(0) = x - 1;
	}
	ll pos = 0;
	vector<ll>path;
	ll loop_pos;
	while (true) {
		if (graph.at(pos).at(1) == -1) {
			path.push_back(pos);
			graph.at(pos).at(1) = 1;
			pos = graph.at(pos).at(0);
		}
		else {
			loop_pos = pos;
			break;
		}
	}
	ll head = find(path.begin(), path.end(), loop_pos) - path.begin();
	ll loop = path.size() - head;
	ll mod = (k - head) % loop;
	//cout << head << " " << loop << " " << mod << endl;
	if (k <= head) {
		cout << path.at(k) + 1 << endl;
	}
	else {
		cout << path.at(head + mod) + 1 << endl;
	}
}

Measured memory_bytes: 16248
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
int ctoi(const char c){
    switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if (N==1){
        cout << "Hello World" << endl;
    }else{
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int n, m, i, j, k, ans, c[9];
void dfs(long long s){
	int i, j, k;
	if(s > n) return;
	if(c[3]&&c[5]&&c[7]) ans++;
	for(i=3; i<=7; i+=2){
		c[i]++;
		dfs(s*10+i);
		c[i]--;
	}
}
int main(){
	scanf("%d", &n);
	dfs(0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
const long long maxn = 1e6;
struct Node{
	int ai,bi;
}node[maxn];
bool cmp(Node a,Node b)
{
	if(a.bi == b.bi) return a.ai < b.ai;
	return a.bi < b.bi;
}
int main(void)
{
	scanf("%d",&n);
	for(int i = 1;i<=n;i++)
		scanf("%d %d",&node[i].ai,&node[i].bi);
	sort(node+1,node+1+n,cmp);
//	int ans = 0;
//	for(int i = 1;i<=n;i++)
//	{
//		if((ans + node[i].ai) <= node[i].bi) ans += node[i].ai;
//		else{
//			puts("NO");
//			return 0;
//		}
//	}
//	puts("Yes");
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(ans+node[i].ai<=node[i].bi)
			ans+=node[i].ai;	
		else
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;

int main() {
	int N, H, W;
	cin >> N >> H >> W;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int A, B;
		cin >> A >> B;
		if (A >= H && B >= W) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>

using namespace std;
int main() {
	int n;
	int count = 0;
	string s;

	
	cin >> n >> s;

	for (int i = 0; i <= n-3; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			count++;
		}
	}
		
	cout << count;

	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    cout<<s[0]<<s.length()-2<<s[s.length()-1]<<endl;
    
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    for(int c = 0 ; c <=x ; c++){
        int t = x - c;
        int asi = c*2 + t*4;
        if(asi == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int main(){
    int n,q,i;
    int cnt=0;
    cin>>n;
    vector<int> S(n+1);
    for(i=0; i<n; i++) cin>>S[i];
    
    cin>>q;
    vector<int> T(q+1);
    for(i=0; i<q; i++) cin>>T[i];
    
    for(i=0; i<q; i++){
        S[n]=T[i];
        int j=0;
        while(S[j]!=T[i]) j+=1;
        if(j!=n) cnt+=1;
    }
    
    printf("%d\n", cnt);
    
    return 0;   
}





Measured memory_bytes: 3224
#include<string>
#include<iostream>
using namespace std;
string s;
int cnt = 0;
int main()
{
    cin >> s;
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == s[i + 1])
        {
            cnt++;
            if(s[i + 1] == '0')
            {
                s[i + 1] = '1';
            }
            else
                s[i + 1] = '0';
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;
const int maxn = 3005;
int dp[maxn][maxn];
ll pre[maxn][maxn];

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    dp[1][1] = 1;
    ll ans = 0;
    for (int len = 2; len <= n; len++){
        for (int i = 1; i <= len - 1; i++){
            pre[len - 1][i] = (pre[len - 1][i - 1] + dp[len - 1][i]) % mod;
        }
        for (int lst = 1; lst <= n; lst++){
            int L, R;
            if (s[len - 2] == '<'){
                L = 1, R = lst - 1;
            } else {
                L = lst, R = len - 1;
            }
            if (L <= R){
                dp[len][lst] += (dp[len][lst] + (pre[len - 1][R] - pre[len - 1][L - 1]) + mod) % mod;
                dp[len][lst] %= mod;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        ans = (ans + dp[n][i]) % mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 104320
### main

nd = gets.to_i

nd.times do
  pn, qn = gets.split.map(&:to_i)
  #p [pn, qn]

  p2q2 = pn * pn + qn * qn

  count = 0
  m = 0
  while m * m <= p2q2
    n2 = p2q2 - m * m
    n = 0
    while n * n <= n2
      m2n2 = m * m + n * n
      if (m != 0 || n != 0) &&
         (m * pn + n * qn) % m2n2 == 0 && (m * qn - n * pn) % m2n2 == 0
        count += 1
      end
      
      n += 1
    end
    m += 1
  end

  puts (count <= 4 ? 'P' : 'C')
end

Measured memory_bytes: 6108