akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <inttypes.h>

/* (a * b) <=> c */
int mulcmp(uint64_t a, uint64_t b, uint64_t c) {
	uint64_t ab;
	if (a != 0 && b != 0 && a > UINT64_MAX / b) return 1;
	ab = a * b;
	return ab < c ? -1 : ab > c;
}

uint64_t sumipe(uint64_t kugyu) {
	uint64_t yes = 1, no = kugyu;
	if (kugyu <= 1) return kugyu;
	while (yes + 1 < no) {
		uint64_t mid = yes + (no - yes) / 2;
		if (mulcmp(mid, mid, kugyu) <= 0) yes = mid; else no = mid;
	}
	return yes;
}

uint64_t solve(uint64_t A, uint64_t B) {
	uint64_t nyan = A * B - 1;
	uint64_t hoge, fuga, foo;
	if (A < B) {
		uint64_t t = A;
		A = B;
		B = t;
	}
	hoge = sumipe(nyan);
	if (hoge == 0) return 0;
	fuga = nyan / (hoge + 1);
	if (nyan / hoge == fuga) fuga--;
	foo = hoge + fuga;
	if (B <= hoge && foo > 0) foo--;
	return foo;
}

int main(void) {
	int Q;
	uint64_t A[128], B[128];
	int i;
	if (scanf("%d", &Q) != 1) return 1;
	for (i = 0; i < Q; i++) {
		if (scanf("%" SCNu64 "%" SCNu64, &A[i], &B[i]) != 2) return 1;
	}
	for (i = 0; i < Q; i++) {
		printf("%" PRId64 "\n", solve(A[i], B[i]));
	}
	return 0;
}


Measured memory_bytes: 128
N=int(input())
s=[[]]
for i in range(N):
  a,b=map(str,input().split()) 
  b=int(b)
  s.append([i,a,b])
  
s.pop(0)

sorted_items =sorted(s, key=lambda x:(x[1],-x[2],x[0]))

for row in sorted_items:
  print(row[0]+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;
 

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int ain;
    vector<int> b(n);
    rep(i,n-1) {
        cin >> ain; 
        ++b[ain-1];
    }
    rep(i,n) cout << b[i] << endl;
    
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
int main()
{
    int N, Y;
    
    cin >> N >> Y;
    rep(i, N + 1){
        rep(j , N - i + 1){
            if (10000 * i + 5000 * j + 1000 * (N - (i + j)) == Y){
                cout << i << " "<< j << " " << (N - (i + j)) << endl;
                return 0;
            } 
        }
    }
    
    cout << -1 << " "<< -1 << " " << -1 << endl;
    return 0;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long long int arr[n];
    long long int pr=1;
    long long int m=1e18;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]==0)
        {
            cout<<"0"<<"\n";
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        
        if(arr[i]<=m/pr)
        {
            pr = pr*arr[i];
            
        }
        else
        {
            cout<<"-1"<<"\n";
            return 0;
        }
        
        
    }
    cout<<pr<<"\n";
    
    
    
}

Measured memory_bytes: 4440
n = int(input())
l= list(map(int, input().split()))
table= {}
for num in l:
	if num in table:
		table[num]+=1
	else:
		table[num]=1

tot= 0
for num in l:
	tot+= num

q= int(input())
for _ in range(q):
	b,c= map(int, input().split())
	if b in table:
		if c in table:
			table[c]+= table[b]
			tot+= table[b]*(c-b)
		else:
			table[c]=table[b]
			tot+= table[b]*(c-b)
	table[b]=0
	print(tot)

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  string s;

  while(cin >> s){
    if(find(ALL(s), '7') != s.end()){
      pout("Yes");
    }else{
      pout("No");
    }
    
  }


  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
    int l, r, largest;
    l = 2*i;
    r = 2*i + 1;

    //左の子、自分、右の子で値が最大のノードを選ぶ
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;

    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;

    for(int i=1; i<=H; i++) cin >> A[i];

    for(int i=H/2; i>=1; i--) maxHeapify(i);

    for(int i=1; i<=H; i++){
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 5016
n = int(input())
array = [int(x) for x in input().split(' ')]
maxa = max(array)
mina = min(array)
if maxa - mina > 1:
    print('No')
elif maxa == mina:
    if n >= 2 * maxa:
        print('Yes')
    elif maxa == n-1:
        print('Yes')
    else:
        print('No')
else:
    sum = 0
    for j in array:
        if j == mina:
            sum += 1
    if sum >= maxa:
        print('No')
        exit()
    if 2*(maxa - sum) <= n - sum:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

ll modfact(ll x){
  if(x==1) return 1;
  else return (x*modfact(x-1))%mod;
}

int main(){
  int N;
  cin>>N;
  int a;
  deque<int> dq;
  for(int i=0;i<N;i++){
    cin>>a;
    if(i%2) dq.push_back(a);
    else dq.push_front(a);
  }

  if(N%2==0){
    reverse(dq.begin(),dq.end());
  }
  for(auto i:dq){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    vector<int> s;
    vector<int> ord(n+1, -1);
    int p = 1, f = 0;
    {
        int v = 1;
        while (ord.at(v) == -1) {
            ord.at(v) = s.size();
            s.push_back(v);
            v = a.at(v-1);
        }
        p = s.size() - ord.at(v);
        f = ord.at(v);
    }

    if (k < f) {
        cout << s.at(k) << endl;
    } else {
        k -= f;
        k %= p;
        cout << s.at(f+k) << endl;
    }
    return 0;
}

Measured memory_bytes: 5904
import Control.Monad
import qualified Data.IntSet as S

main = do
  li <- getLine
  let [n,k] = map read $ words li
  ass <- forM [1..k] (\_ -> do
    getLine -- di
    li <- getLine
    let as = map read $ words li
    return as
    )
  let ans = compute n k ass
  print ans

compute :: Int -> Int -> [[Int]] -> Int
compute n k ass = n - (S.size $ S.fromList $ concat ass)

Measured memory_bytes: 6536
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	S := Read()

	groups := []int{}
	prev := byte(' ')
	for i := 0; i < len(S); i++ {
		if S[i] == prev {
			groups[len(groups)-1]++
		} else {
			groups = append(groups, 1)
		}
		prev = S[i]
	}

	ans := 0
	for _, group := range groups {
		ans += group - 1
	}
	fmt.Println(Min(ans+2*K, N-1))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 200005;
int a[N];

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", sum ^ a[i]);
    }
	return 0;
}


Measured memory_bytes: 4528
n = int(input())
b = list(map(int, input().split()))

a = [0 for _ in range(n)]

a[0] = b[0]
a[-1] = b[-1]
for i in range(n - 2):
    ai_1 = min(b[i],b[i+1])
    a[i+1] = ai_1

print(sum(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b;
  	ci(a>>b);
  if(a*b%2==0) co("Even")
    else co("Odd")
    }

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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    
    int n;
    cin >> n;
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    vl num(n + 1);
    num[1] = 1;
    vi primes(n + 1, -1);
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            num[i] = 2;
            for (int j = 2; i * j <= n; j++) {
                is_prime[i * j] = false;
                primes[i * j] = i;
            }
        }
        else {
            int mo = i / primes[i];
            int cnt = 0;
            int mm = mo;
            while (mm % primes[i] == 0) {
                cnt++;
                mm /= primes[i];
            }
            num[i] = num[mo] / (cnt + 1) * (cnt + 2);
        }
    }

    ll ans = 0;
    rep1 (i, n) {
        ans += num[i] * i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 160804
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  int a[100001];

  cin >> N;
  for(int i = 1; i < N + 1; i++)
    cin >> a[i];

  int count = 0, next = 1;
  for(int i = 0; i < N; i++) {
    if(a[next] == 2) {
      cout << count + 1 << endl;
      return 0;
    }
    next = a[next];
    count++;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  vll dq(n);
  rep(i, n) cin >> dq[i];

  ll ans = 0;
  rep(ge, min(n + 1, k + 1)) {
    rep(lf, ge + 1) {
      ll ta = k - ge;
      ll rg = max(0LL, ge - lf);
      ll tmp = 0;
      priority_queue<ll, vll, greater<ll>> pque;
      rep(i, lf) {
        tmp += dq[i];
        pque.emplace(dq[i]);
      }
      rep(i, rg) {
        tmp += dq[n - 1 - i];
        pque.emplace(dq[n - 1 - i]);
      }
      while (!pque.empty() && pque.top() < 0 && ta > 0) {
        tmp -= pque.top();
        pque.pop();
        ta--;
      }  // while
      chmax(ans, tmp);
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int N; cin>>N;
  string A,B,C; cin>>A>>B>>C;
  int ans=0;
  rep(i,N){
    if(A[i]!=B[i]&&A[i]!=C[i]&&B[i]!=C[i]) ans+=2;
    else if(A[i]==B[i]&&A[i]==C[i]) continue;
    else ans+=1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=4e5+7;
const int mod=1e9+7;
using namespace std;
int p[MX],k[MX];
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
int M,res;
int a[MX],b[MX];
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int N,K;
  cin>>N>>K;
  int top=0;
  int j;
  for(int i=1;i<=N;i=j+1)
  {
      j=N/(N/i);
      a[++top]=j-i+1;
      b[top]=N/i;
  }
  for(int i=2;i<=K;i++)
  {
      for(int i=1;i<=top;i++)
      {
          b[i]=1ll*a[i]*b[i]%mod;
      }
      for(int i=1;i<=top;i++)
      {
          b[i]=(b[i-1]+b[i])%mod;
      }
      for(int i=1;i<=top/2;i++)
      {
          swap(b[i],b[top-i+1]);
      }
  }
  cout<<b[1]<<endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int 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;
	}
}
int COMB(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;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int n, m;
int h[114514];
int a[114514], b[114514];
int memo[114514];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	rep(i, n)cin >> h[i];
	rep(i, m)cin >> a[i] >> b[i];
	rep(i, m) {
		if (h[a[i] - 1] < h[b[i] - 1]) {
			memo[a[i] - 1] = -1;
			memo[b[i] - 1] = min(memo[b[i] - 1], (int)1);
		}
		else if (h[a[i] - 1] == h[b[i] - 1]) {
			memo[a[i] - 1] = -1;
			memo[b[i] - 1] = -1;
		}
		else {
			memo[a[i] - 1] = min((int)1, memo[a[i] - 1]);
			memo[b[i] - 1] = -1;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (memo[i] != -1)ans++;
	}
	cout << ans << endl;
	ggr
}


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

void sort(int a[]);
void swap(int *a, int *b);

int n;

int main(void)
{
	int taro[200];
	int hanako[200];
	int t_count, h_count;
	int flag;
	int bord;
	int i, j;
	int list[200];

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		memset(taro, 0, sizeof(taro));
		memset(hanako, 0, sizeof(hanako));
		memset(list, 0, sizeof(list));

		for (i = 0; i < n; i++){
			scanf("%d", &taro[i]);
		}

		sort(taro);

		for (i = 0; i < n; i++){
			list[taro[i]] = 1;
		}

		j = 0;

		for (i = 1; i <= 2 * n; i++){
			if (list[i] == 0){
				hanako[j] = i;
				j++;
			}
		}

		bord = 0;
		t_count = h_count = n;

		for (i = 0; i < 2 * n; i++){
			flag = 0;
			for (j = 0; j < n; j++){
				if (bord < taro[j]){
					bord = taro[j];
					taro[j] = 0;
					t_count--;
					break;
				}
				flag++;
			}
			if (t_count == 0){
				break;
			}
			if (flag == n){
				bord = 0;
			}
			flag = 0;
			for (j = 0; j < n; j++){
				if (bord < hanako[j]){
					bord = hanako[j];
					hanako[j] = 0;
					h_count--;
					break;
				}
				flag++;
			}
			if (flag == n){
				bord = 0;
			}
			if (h_count == 0){
				break;
			}
		}

		printf("%d\n", h_count);
		printf("%d\n", t_count);
	}

	return (0);
}

void sort(int a[])
{
	int i, j;

	for (i = 0; i < n - 1; i++){
		for (j = i; j < n; j++){
			if (a[i] > a[j]){
				swap(&a[i], &a[j]);
			}
		}
	}
}

void swap(int *a, int *b)
{
	*a += *b;
	*b = *a - *b;
	*a -= *b;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
const int N = 1000010;
int arr[N];
//vector<bool> isPrime;
//vector<ll> sFactor;
//void sieve(int n)
//{
//	isPrime.assign(n+1,true);
//	sFactor.assign(n+1,0);
//	isPrime[0]=isPrime[1]=false;
//	for(ll i=2;i<=n;i++)
//	{
//		if(isPrime[i])
//		{
//			sFactor[i]=i;
//			for(ll j=i*i;j<=n;j+=i)
//			{
//				if(isPrime[j])
//				{
//					isPrime[j]=false;
//					sFactor[j]=i;
//				}
//			}
//		}
//	}
//}
void solve()
{
	int n;
	cin>>n;
	ll ones = 0;
	ll x = 0;
	REP(i, n)
	{
		cin>>x;	
		arr[x]++;
		if(x==1)
		{
			ones++;
		}
	}
	if(ones==1)
	{
		cout<<1<<"\n";
		return;
	}
	if(ones>1)
	{
		cout<<"0\n";
		return;
	}
	ll cnt = 0;
	for(ll i=1; i<N;i++)
	{
		if(arr[i]>=1)
		{
			if(arr[i]==1)
				cnt++;
			for(ll j = 2*i; j<N;j+=i)
			{
				arr[j] = 0;
			}
		}
	}
	cout<<cnt<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(arr,0, sizeof(arr));
//    sieve(N);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 7556
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

js = [None for _ in range(n)] # 周期とスコア増分

for s in range(n):
    if js[s]:
        continue
    m = s
    tmp = 0
    memo = [[] for _ in range(n)]
    i = 0
    while True:
        m = p[m] - 1
        tmp += c[m]
        memo[m].append((i, tmp))
        if len(memo[m]) > 1:
            js[m] = (memo[m][1][0] - memo[m][0][0], memo[m][1][1] - memo[m][0][1])
        if len(memo[m]) > 2:
            break
        i += 1

ans = -100000000000
for s in range(n):
    m = s
    tmp = 0
    visited = [0] * n
    for i in range(k):
        m = p[m] - 1
        if visited[m]:
            break
        visited[m] = 1
        tmp += c[m]
        if js[m] and js[m][1] > 0:
            ans = max(ans, tmp + js[m][1] * ((k - i - 1) // js[m][0]))
        else:
            ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 83344
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll N, K, ans;
VV<ll> edges;

ll calc(ll now, ll pre) {
    ll ret = 1;
    bool cut = false;
    for(ll nxt : edges[now]) {
        if(nxt == pre) continue;
        ll tmp = calc(nxt, now);
        chmax(ret, tmp);
        if(now != 0 && pre != 0 && K != 1 && tmp == K && !cut) {
            DEBUG(now, pre, nxt, tmp);
            ans++;
            cut = true;
        }
    }
    if(K == 1 && pre != 0 && now != 0) ans++;
    if(cut) ret = 0;
    return ret + 1;
}

int main() {
    cin >> N >> K;
    edges.resize(N);
    for(ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        a--;
        if(i == 0) {
            ans += !!a;
            continue;
        }
        edges[i].push_back(a);
        edges[a].push_back(i);
    }

    calc(0, -1);
    cout << ans << endl;
    return 0;
}


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

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 dp[200020];

int main(){
  COMinit();
  ll n,m,k;
  cin >> n >> m >> k;
  ll ans=0;
  dp[0]=1;
  rep(i,200020)dp[i+1]=(dp[i]*(m-1))%mod;
  rep(i,k+1){
    ans+=(COM(n-1,i)*dp[n-i-1])%mod;
    ans%=mod;
  }
  ans*=m;
  ans%=mod;
  cout << ans << endl;
return 0;}

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

int main()
{
	int a,b;
	cin>>a>>b;
	
	if(a<b)
	{
		for(int i=1; i<=b; i++)
		{
			cout<<a;
		}
	}
	else if(a==b)
	{
		for(int i=1; i<=a; i++)
		{
			cout<<b;
		}
	}
	else
	{
		for(int i=1; i<=a; i++)
		{
			cout<<b;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();

	int n, m; cin>>n>>m;vector<int> a(n);
	long long sum = 0;
	for(int i = 0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int flag = 1;
	sort(rall(a));
	for(int i = 0; i<m; i++){
		if(a[i]*4LL*m<sum){
			flag = 0;
			break;
		}
	}
	if(flag){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
L=[A[0]]
R=[A[-1]]
for i in range(1,n-1):
    l=L[i-1]+A[i]
    L.append(l)
    r=R[i-1]+A[-(i+1)]
    R.append(r)
c=2*10**14
for i in range(n-1):
    s=abs(L[i]-R[-(i+1)])
    c=min(c,s)
print(c)

Measured memory_bytes: 30960
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 10000000
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;

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

    vector<int> x(m), sa(m - 1);
    rep(i, m)
    {
        cin >> x[i];
    }
    sort(all(x));
    rep(i, m)
    {
        if (i == 0)
        {
            continue;
        }
        sa[i - 1] = x[i] - x[i - 1];
    }
    sort(all(sa), greater<int>());
    int diff = x[m - 1] - x[0];
    rep(i, n - 1)
    {
        diff -= sa[i];
    }
    cout << diff << endl;
    return 0;
}

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

string S;
string T;
void input(){
cin >> S >> T;
}

void solve() {
    T.pop_back();
    if(S == T) cout << "Yes"<< endl;
    else cout << "No"<< endl;
}

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


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <vector>
using namespace std;

bool fizzbuzz(int n,string s){
	if(n%15==0)return (s != "FizzBuzz");
	if(n%3==0)return  (s != "Fizz");
	if(n%5==0)return  (s != "Buzz");
	
	for(int i=0;i<s.length();i++){
		if(s[i]<'0'||s[i]>'9')return true;
	}
	
	/*ツつ「ツづォツつ「ツづォツ妥篠催エ*/
	/*int zero = 0;
	for(int i=0;i<s.length();i++){
		if(s[i] == '0')zero++;
		else break;
	}
	s = s.substr(zero,s.length()-zero);
	if(s.length()>8)return true;
	*/
	return (atoi(s.c_str()) != n);
}

int main(){
	int n,m;
	string s;
	
	while(scanf("%d %d\n",&m,&n), m){
	
		vector<int> rem(m);
		for(int i=0;i<m;i++){
			rem[i] = i+1;
		}
		int c = 0;
		for(int i=1;i<=n;i++){
			getline(cin,s);
			if(rem.size() == 1)continue;
			if( fizzbuzz(i,s) ){
				rem.erase(remove(rem.begin(),rem.end(),rem[c]),rem.end());
				c %= rem.size();
			}else{
				c =(c+1)%rem.size();
			}
		}
		for(int i=0;i<rem.size();i++){
			cout << (i?" ":"") << rem[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
bool vis[30005];
int ans[30005];
int main(){
	int n=read(),tot=0,sum=0;
	for(int i=2;i<=30000;i++)if(i%2==0||i%3==0||i%5==0){
		ans[++tot]=i; sum+=i; vis[i]=1;
		if(tot==n-1){
			for(int j=2;j<=30000;j++)if(!vis[j]&&(sum+j)%2==0&&(sum+j)%3==0&&(sum+j)%5==0&&__gcd(sum,j)!=1){
				ans[++tot]=j; for(int j=1;j<=tot;j++)cout<<ans[j]<<" "; return 0;
			}
			vis[ans[tot]]=0; sum-=ans[tot];
			tot--;
		}
	}
}

Measured memory_bytes: 512
//by The_One_Solver
#include<bits/stdc++.h>
using namespace std;
long long n,l,p,c,z;
bool a;
int main()
{
    set<long long>st;
   set<long long >::iterator it;
    cin>>n;

    for(long long i=-120;i<=120;i++)
   {
     for(long long j=-120;j<=120;j++)
     {       c=(i*i*i*i*i);
             p=(j*j*j*j*j);
            if(c-p==n)return cout<<i<<" "<<j,0;

     }
   }
    return 0;
}


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

int data[100];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n * (n - 1) / 2; i++){
		int b[4];
		for(int k=0;k<4;k++) scanf("%d",&b[k]);
		if(b[2]>b[3]) data[b[0]-1]+=3;
		if(b[2]<b[3]) data[b[1]-1]+=3;
		if(b[2]==b[3]){ data[b[0]-1]++; data[b[1]-1]++; }
	}
	for(int i=0;i<n;i++){
		int res=1;
		for(int j=0;j<n;j++){
			if(data[i]<data[j]) res++;
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1188
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int sumofdigit(int n){
int ans = 0;
while(n!=0){
    ans += n % 10;
    n /= 10;
}
return ans;
}

int main(){
    int n;
    cin >> n;
    string ans;
    if(n % sumofdigit(n) == 0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int res=0;
    for(auto it:a){
        if(it>=k)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
//	-*- mode: C++ -*-
//	Grading
//		Write a program which reads a list of student test scores and evaluates the performance for each student.
//
//		The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.
//
//		The final performance of a student is evaluated by the following procedure:
//
//		If the student does not take the midterm or final examination, the student's grade shall be F.
//		If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.
//		If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.
//		If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.
//		If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.
//		If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
//	Input
//		The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.
//
//		The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.
//
//		The number of datasets (the number of students) does not exceed 50.
//
//	Output
//		For each dataset, print the grade (A, B, C, D or F) in a line.
//
//	Sample Input
//		40 42 -1
//		20 30 -1
//		0 2 -1
//		-1 -1 -1
//	Sample Output
//		A
//		C
//		F

#include <iostream>
#include <vector>
#include <tuple>

typedef std::tuple<int, int, int>	score;

char evaluate(score	s)
{
	int&	m	= std::get<0>(s);
	int&	f	= std::get<1>(s);
	int&	r	= std::get<2>(s);

	if((m == -1) || (f == -1)){
		return	'F';
	}

	int	sum	= m + f;
	if(sum >= 80){
		return	'A';
	}
	else if(sum >= 65){
		return	'B';
	}
	else if(sum >= 50){
		return	'C';
	}
	else if(sum >= 30){
		if(r >= 50){
			return	'C';
		}
		else{
			return	'D';
		}
	}
	else{
		return	'F';
	}
}

int	main(int	argc,
		 char*	argv[])
{
	std::vector<score> 	Grade	{0};

	while(true){
		int	m	{0};
		int	f	{0};
		int	r	{0};

		std::cin >> m >> f >> r;

		if((m == -1) && (f == -1) && (r == -1)){
			break;
		}

		Grade.push_back(std::make_tuple(m, f, r));
	}

	for(auto s : Grade){
		std::cout << evaluate(s) << '\n';
	}

    return 0;
}



Measured memory_bytes: 3016
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    if s[1]==s[2]==s[3]
        println("No")
    else
        println("Yes")
    end
end
main()

Measured memory_bytes: 166412
import numpy as np

N = int(input())

cnt_AB = 0
xA = 0
Bx = 0
BA = 0
xx = 0
for i in range(N):
  s = input()
  cnt_AB += s.count('AB')
  if s[0] == 'B':
    if s[-1] == 'A':
      BA += 1
    else:
      Bx += 1
  else:
    if s[-1] == 'A':
      xA += 1
    else:
      xx += 1

A = xA + BA
B = Bx + BA
ans = cnt_AB

if A > B:
  ans += B
elif A < B:
  ans += A
elif A > 0:
  ans += A
  if xA == 0:
    ans -= 1

print(ans)


Measured memory_bytes: 20760
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
l = []
for i in range(n) :
	Min = 10**9
	ans = 0
	for j in range(m) :
		if abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]) < Min :
			Min = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1])
			ans = j + 1
	l.append(ans)
for i in l :
	print(i)

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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0
#define all(v) begin(v),end(v)
#define inf 1LL<<55

lli gcd(lli a,lli b){
	if(b==0)return a;
	return gcd(b,a%b);
}

lli gcdstart(lli a,lli b){
	return gcd(max(a,b),min(a,b));
}

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	vector<lli> b(n),c(n);

	REP(i,n)cin>>a[i];

	b[0]=a[0];
	c[n-1]=a[n-1];

	/*bにて最大公約数の累積をとる*/
	for(lli i=1;i<n;i++){
		b[i] = gcdstart(b[i-1],a[i]);
	}

	/*cにて最大公約数の累積をとる*/
	for(lli i=n-2;i>=0;i--){
		c[i] = gcdstart(c[i+1],a[i]);
	}
	if(DEBUG){
		cout<<"b="<<endl;
		REP(i,n){
			cout<<"i="<<i<<" b[i]="<<b[i]<<endl;
		}
		cout<<"c="<<endl;
		REP(i,n){
			cout<<"i="<<i<<" c[i]="<<c[i]<<endl;
		}
	}
	lli ans = c[1];

	/*答えは見ている箇所の数字を除いた数のgcdの累積和*/
	for(lli i=1;i<n-1;i++){
		ans = max(ans,gcdstart(b[i-1],c[i+1]));
	}
	ans = max(ans,b[n-2]);

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2560
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = (1e9 + 7);

int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

struct Combi
{
	vector<int> fact;
	vector<int> ifact;
	vector<int> inv;
	vector<int> pow2;
	int choose(int a, int b)
	{
		if(a<b) return 0;
		if(b==0) return 1;
		if(a==b) return 1;
		return mult(fact[a],mult(ifact[b],ifact[a-b]));
	}
	int inverse(int a)
	{
		return modpow(a,MOD-2);
	}
	void init(int _n)
	{
		fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
		fact.resize(_n+1);
		ifact.resize(_n+1);
		inv.resize(_n+1);
		pow2.resize(_n+1);
		pow2[0]=1;
		ifact[0]=1;
		fact[0]=1;
		for(int i=1;i<=_n;i++)
		{
			pow2[i]=add(pow2[i-1],pow2[i-1]);
			fact[i]=mult(fact[i-1],i);
		}
		ifact[_n] = inverse(fact[_n]);
		for(int i=_n-1;i>=1;i--)
		{
		    ifact[i] = mult(ifact[i + 1], i + 1);
		}
		for(int i=1;i<=_n;i++)
		{
		    inv[i] = mult(fact[i-1],ifact[i]);
		}
	}
};

Combi combi;
int dp[2111][2111];
int sum[2111][2111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	combi.init(4010);
	int n,k; cin>>n>>k;
	if(n==1)
	{
		cout<<1<<'\n';
		return 0;
	}
	int coeff=1;
	if(k<n) coeff=combi.pow2[n-k-1];
	for(int i=1;i<=n-1;i++) dp[0][i]=1;
	for(int i=1;i<k;i++)
	{
		for(int j=n-i-1;j>=(i==n-1?0:1);j--)
		{
			if(j==n-i-1) dp[i][j]=dp[i-1][j+1];
			else dp[i][j]=dp[i][j+1];
			dp[i][j]=add(dp[i][j],dp[i-1][j]);
		}
	}
	int ans=dp[k-1][(k==n?0:1)];
	ans=mult(ans,coeff);
	cout<<ans<<'\n';
}


Measured memory_bytes: 18816
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

fn main() {
    let n: usize = input();
    let a: Vec<usize> = input_vec();

    let mut ans = 1;
    let mut tmp = Ordering::Equal;

    for (i, j) in a.windows(2).map(|x| (x[0], x[1])) {
        match (tmp, i.cmp(&j)) {
            (Ordering::Equal, now) => {
                tmp = now;
            }
            (Ordering::Less, Ordering::Greater) => {
                ans += 1;
                tmp = Ordering::Equal;
            }
            (Ordering::Greater, Ordering::Less) => {
                ans += 1;
                tmp = Ordering::Equal;
            }
            _ => {}
        }
    }
    
    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}



Measured memory_bytes: 6396