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

vector<int> adj[MAX];
int visited[MAX];
int graph[MAX][MAX];

vector<int> dfs(int v, int root)
{
	vector<int> ans;
	visited[v] = 1;
	if (v != root)
	{
		for (int i : adj[v])
		{
			if (i != root && visited[i]) return ans;
		}
		if (graph[v][root])
		{
			ans.push_back(v);
			return ans;
		}
	}
	for (int i : adj[v])
	{
		vector<int> res = dfs(i, root);
		if (!res.empty())
		{
			int flag = 1;
			for (int j : res)
			{
				if (graph[v][j] && i != j)
				{
					flag = 0;
					break;
				}
			}
			if (!flag) continue;
			res.push_back(v);
			return res;
		}
	}
	visited[v] = 0;
	return ans;
}

int main(void)
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].push_back(v);
		graph[u][v] = 1;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++) visited[j] = 0;
		vector<int> res = dfs(i, i);
		reverse(res.begin(), res.end());
		if (!res.empty())
		{
			cout << res.size() << endl;
			for (int j : res) cout << j + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 7172
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; ll k; cin >> n >> k;
    int log = log2(k);
    VI a(n); cin >> a;
    auto to = vec<int>(log + 1, n);
    FOR(i, 0, n)to[0][i] = a[i] - 1;
    FOR(j, 0, log)FOR(i, 0, n) {
        to[j + 1][i] = to[j][to[j][i]];
    }

    int ans = 0;
    for (int j = 0; k; ++j, k >>= 1) {
        if (k & 1)ans = to[j][ans];
    }
    print(ans + 1);
}


Measured memory_bytes: 51932
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
  string s;
  cin>>s;
  if(s[0]=='R')
  {
    if(s[1]=='R')
    {
      if(s[2]=='R')
        cout<<3;
      else
        cout<<2;
    }
    else
      cout<<1;

  }
  else if(s[1]=='R')
  {
    if(s[2]=='R')
      cout<<2;
    else
      cout<<1;
  }
  else if(s[2]=='R')
    cout<<1;
  else
    cout<<0;

    
}
return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
typedef pair<ll, int> pli;
typedef pair<pli, pli> st;
const int MAXN = 200000;
const ll INF = (1LL<<60);
struct edge{
	int to; ll dis;
	edge *nxt;
}edges[2*MAXN + 5], *adj[MAXN + 5], *ecnt = edges;
void addedge(int u, int v, int w) {
	edge *p = (++ecnt);
	p->to = v, p->dis = w, p->nxt = adj[u], adj[u] = p;
	p = (++ecnt);
	p->to = u, p->dis = w, p->nxt = adj[v], adj[v] = p;
}
pli lnk[MAXN + 5];
int fa[MAXN + 5], clr[MAXN + 5];
ll X[MAXN + 5];
int find(int x) {
	return fa[x] = (fa[x] == x ? x : find(fa[x]));
}
bool unite(int x, int y) {
	int fx = find(x), fy = find(y);
	if( fx != fy ) {
		fa[fx] = fy;
		return true;
	}
	else return false;
}
st dp[MAXN + 5];
void update(st &a, st b) {
	if( b.fi.fi < a.fi.fi ) {
		if( b.fi.se != a.fi.se )
			a.se = a.fi;
		a.fi = b.fi;
		if( b.se.fi < a.se.fi )
			a.se = b.se;
	}
	else {
		if( b.fi.se != a.fi.se ) {
			if( b.fi.fi < a.se.fi )
				a.se = b.fi;
		}
		else if( b.se.fi < a.se.fi )
			a.se = b.se;
	}
}
void dfs1(int x, int f) {
	dp[x] = mp(mp(X[x], clr[x]), mp(INF, -1));
	for(edge *p=adj[x];p;p=p->nxt) {
		if( p->to == f ) continue;
		dfs1(p->to, x); st t = dp[p->to];
		t.fi.fi += p->dis, t.se.fi += p->dis;
		update(dp[x], t);
	}
}
void dfs2(int x, int f, st k) {
	update(dp[x], k);
	for(edge *p=adj[x];p;p=p->nxt) {
		if( p->to == f ) continue;
		st t = dp[x];
		t.fi.fi += p->dis, t.se.fi += p->dis;
		dfs2(p->to, x, t);
	}
}
int num[MAXN + 5];
int main() {
	int N; scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%lld", &X[i]), fa[i] = i;
	for(int i=1;i<N;i++) {
		int u, v, w; scanf("%d%d%d", &u, &v, &w);
		addedge(u, v, w);
	}
	ll ans = 0;
	while( true ) {
		int cnt = 0;
		for(int i=1;i<=N;i++)
			if( fa[i] == i ) num[clr[i] = (++cnt)] = i;
		if( cnt == 1 ) break;
		for(int i=1;i<=N;i++)
			clr[i] = clr[find(i)];
		dfs1(1, 0), dfs2(1, 0, mp(mp(INF, -1), mp(INF, -1)));
		for(int i=1;i<=cnt;i++)
			lnk[i] = mp(INF, -1);
		for(int i=1;i<=N;i++) {
			if( dp[i].fi.se == clr[i] )
				lnk[clr[i]] = min(lnk[clr[i]], mp(dp[i].se.fi + X[i], dp[i].se.se));
			else lnk[clr[i]] = min(lnk[clr[i]], mp(dp[i].fi.fi + X[i], dp[i].fi.se));
		}
		for(int i=1;i<=cnt;i++)
			if( unite(num[i], num[lnk[i].se]) )
				ans += lnk[i].fi;
	}
	printf("%lld\n", ans);
}

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

#define fr first
#define sc second

using namespace std;

const double pi = acos(-1);
const double Tr = pi/3;

char s[20];

typedef pair<double,double> poi;


int in(){
	int d,l;
	scanf("%s",s);
	scanf("%d%d",&d,&l);
	
	double t = s[0] == 'B' ? 2 * Tr : s[0] == 'C' ? Tr : 0;

	t -= d * pi / 180;
	poi p = poi ( cos(t) *l , sin(t) *l) ;
	poi q = poi ( ( p.fr * sin(Tr) - p.sc * cos(Tr) ) / sin(Tr), p.sc  / sin(Tr) );

	double x = q.fr - round( q.fr/2 )*2;
	double y = q.sc - round( q.sc/2 )*2;

	if (y<0) x*=-1, y*=-1;

	if (x<0){
		x++;
		return x + y < 1 ? 0 : 1;
	}
	return x + y < 1 ? 2 : 3;
} 
/*
juele
*/
int main(){
	int p1 = in();
	int p2 = in();
	cout << (p1 == p2 ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 3468
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int M, D, D1=0, D10=0;
      	int cnt=0;
  		M =	sc.nextInt();
  		D =	sc.nextInt();
      	
      	for(int k=1; k<=M ;k++){
      	for (int i=22; i<=D; i++){
          	D1 = i % 10;
          	if (D1 == 1 || D1 == 0) continue;
      		D10 = i / 10;
          	if (k == D10 * D1){
              	cnt++;
            }
        }
        }
      	System.out.println(cnt); 	
	}
}

Measured memory_bytes: 21588
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
for i in range(n):
  a[i] = a[i]-(i+1)
b = int(np.median(a))
ans = 10**18
ans_lis = [b-1, b, b+1]
for i in ans_lis:
  ans = min(ans, np.sum(np.abs(a-i)))
  
print(ans)

Measured memory_bytes: 34212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,d;
    string S,T,Temp;
    cin>>N;
    d=N/2;
    cin>>S;

    for(int i=0;i<d;i++)
    {
       T += S[i];

    }
    Temp=T+T;
    if(!S.compare(Temp)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }



    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<bool> done(n);
    cins(all(a));
    ll cnt = 0;
    rep(i,n) a[i]--;
    rep(i,n){
        if (done[i]) continue;
        if (i == a[a[i]]){
            cnt++;
            done[a[i]] = 1;
        }
    }
    PRINT(cnt);
}


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

ll gcd(long a, long b){
    long ans = 1;
    long n = max(a,b);

    for(int i = 1; i <= n ; i++){
        if(a%i==0&&b%i == 0){
            ans = i;
        }
    }
    return ans;
}

int main(void) {
    long a,b;
    cin >> a >> b;

    cout << a*b/gcd(a,b) << endl;
   
    return 0;
    
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, P, ans=0, tmp1=0, tmp2=0;
string S;
vector<ll> A;

signed main(){
    cin >> N >> P >> S;
    A.resize(P,0);
    A[0]++;
    tmp1 = 1;
    if(10%P==0) {
        for(int i=0;i<N;i++) {
            ll num = S[N-1-i]-'0';
            if(num%P==0) ans += N-i;
        }
        cout << ans << endl;
        return 0;
    }
    for(int i=0;i<N;i++) {
        ll num = S[N-1-i]-'0';
        num *= tmp1;
        tmp2 += num;
        tmp2 %= P;
        A[tmp2]++;
        tmp1 *= 10;
        tmp1 %= P;
    }
    for(int i=0;i<P;i++) {
        ans += A[i]*(A[i]-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
function Main (N) {
  N = parseInt(N.split("\n")[0], 10);
  while (true) {
    if (primeNumber(N)) {
      console.log(N);
      break;
    }
    else {
      N++;
    }
  }
}
function primeNumber (num) {

    //2 は素数なので true を返す
    if(num === 2) {
        return true;
    } else {

        for(i = 2; i < num; i++) {

        //2以上の数で割ったとき余りが0になれば false を返す。つまり素数ではない。
            if(num % i === 0) {
                return false;
                break;
            }

            //ループが最後まで行く、つまり割れる数がなかったら true を返す。つまり素数。
            if(i + 1 === num) {
                return true;
            }
        }
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 23092
// 課題3_2 AtCoder Beginner Contest 168 A- (Therefore)
// nk777
 
#include <stdio.h>
 
int main(void){
    // 入力される整数Nを表すnum, Nの小数第1位を表すnum_1
    int num, num_1;
 
    // numを受け取る
    scanf("%d", &num);
 
    // numの少数第1位を計算
    num_1 = num % 10;
 
    if (num_1 == 3)
    {
        // Nの少数第1位が3
        printf("bon\n");
    }
    else if (num_1 == 0 || num_1 == 1 || num_1 == 6 || num_1 == 8)
    {
        // numの少数第1位が0,1,6,8
        printf("pon\n");
    }
    else
    {
        // numの少数第1位が2,4,5,7,9
        printf("hon\n");
    }
 
    return 0;
}

Measured memory_bytes: 1588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,ans;

int main(){
	cin>>n;
	for(ll i=2;i*i<=n;i++){
		int cnt=0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		int x=1;
		while(cnt>=x){
			ans++;
			cnt-=x;
			x++;
		}
	}
	if(n>1)ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
int checkATCG(char c){
  if(c=='A'||c=='T'||c=='C'||c=='G'){
    return 1;
  }
  return 0;
}

int main(void){
  int i,j;
  int ohowlong=0;
  int chowlong=0;
  char S[11];
  scanf("%s",&S[0]);
  if(S[0]=='A'||S[0]=='T'||S[0]=='C'||S[0]=='G'){ohowlong=1;}
  for(i=1;i<10;i++){
  	if(checkATCG(S[i])==1){ohowlong+=1;}
    else{
      if(chowlong<ohowlong){chowlong=ohowlong;}
      ohowlong=0;
  	}
  }
  if(chowlong<ohowlong){chowlong=ohowlong;}
  printf("%d",chowlong);
  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/python3
import math

# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [0 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        x -= 1
        # update
        a[x] += y
        # update b
        index = x // b_size
        #b[index] = min(a[index * b_size:(index + 1) * b_size])
        b[index] += y

    else:
        x -= 1
        y -= 1
        # find
        target = []
        x_index = x // b_size
        y_index = y // b_size
        x_mod = x % b_size
        y_mod = y % b_size
        if x_index == y_index:
            target.extend(a[x:y + 1])
        else:
            if x_mod == 0:
                target.append(b[x_index])
            else:
                target.extend(a[x:(x_index + 1) * b_size])

            if y_mod == b_size - 1:
                target.append(b[y_index])
            else:
                target.extend(a[y_index * b_size:y + 1])

            if x_index + 1 <= y_index - 1:
                target.append(sum(b[x_index + 1 : y_index]))
        print(sum(target))

Measured memory_bytes: 9648
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int x[66],y[66],z[66],m=0;
void adde(int a,int b,int c)
{
	m++;
	x[m]=a;
	y[m]=b;
	z[m]=c;
}
int main()
{
	int n,l,now=1,k;
	n=20;
	scanf("%d",&l);
	for(int i=1;l;i++)
	{
		if(i>1)
		{
			adde(i-1,i,0);
			adde(i-1,i,now/3);
			adde(i-1,i,now/3*2);
		}
		k=(l%(now*3))/now;
		for(int j=0;j<k;j++)
		{
			l-=now;
			adde(i,n,l);
		}
		now*=3;
	}
	printf("%d %d\n",n,m);
	for(int i=1;i<=m;i++)
		printf("%d %d %d\n",x[i],y[i],z[i]);
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char canvas[h][w];
  bool ans[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> canvas[i][j];
      ans[i][j] = false;
    }
  }
  int mx[4] = {1, 0, -1, 0}, my[4] = {0, 1, 0, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (canvas[i][j] == '#') {
        bool yes = false; 
        for (int z = 0; z < 4; z++) {
          if (0 <= i+my[z] && i+my[z] < h && 0 <= j+mx[z] && j+mx[z] < w) {
            if (canvas[i+my[z]][j+mx[z]] == '#') {
              yes = true;
              break;
            }
          }
          if (yes) break;
        }
        if (yes) ans[i][j] = true;
      }
    }
  }
  bool answer = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (canvas[i][j] == '#' && ans[i][j] == false) answer = false;
      if (canvas[i][j] == '.' && ans[i][j] == true) answer = false;
    }
  }
  if (answer) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  
}


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

#define MAX 1000000
#define SQRT_MAX (int)sqrt((double)MAX)

int main(void)
{
	char isprime[MAX];
	int num, ans;
	register int i, j;

	/* isprimeの初期化 */
	memset(isprime, 1, sizeof(isprime));
	isprime[1] = 0;

	/* 素数判定(エラトステネスの篩) */
	for (i = 2; i < SQRT_MAX; i++) {
		if (isprime[i])
			/* 素数ならばその倍数は合成数 */
			for (j = i + i; j < MAX; j += i)
				isprime[j] = 0;
	}

	while(scanf("%d", &num) != EOF) {
		ans = 0;
		for (i = 1; i <= num; i++)
			ans += isprime[i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1576
#include<bits/stdc++.h>
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{

long long a,b,c,d,e,f,x,y,n,h=0,k;
    cin >> n >> k >> x >> y;

    if(n<k)
    {
        f=n*x;
        cout << f << endl;
    }
    else{

       d=k*x+max((n-k)*y,h);
    cout << d << endl;

    }






}

Measured memory_bytes: 3592
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");


  //   String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

if(A+B>=C){
System.out.println("Yes");
}else{
System.out.println("No");

}





	}
}

Measured memory_bytes: 23252
use std::cmp::min;
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (a, b, q) = parse!(it, 3);
    let s = (0..a).map(|_| parse!(it)).collect::<Vec<_>>();
    let t = (0..b).map(|_| parse!(it)).collect::<Vec<_>>();
    let diff = |x: usize, y: usize| if x >= y { x - y } else { y - x };
    let getni = |x: usize, v: &Vec<usize>| match v.binary_search(&x) {
        Ok(i) => (i, None),
        Err(i) => match i {
            0 => (0, None),
            i if i == v.len() => (i - 1, None),
            i => {
                if diff(v[i], x) <= diff(v[i - 1], x) {
                    (i, Some(i - 1))
                } else {
                    (i - 1, Some(i))
                }
            }
        },
    };
    let st: Vec<usize> = s.iter().map(|&x| diff(x, t[getni(x, &t).0])).collect();
    let ts: Vec<usize> = t.iter().map(|&x| diff(x, s[getni(x, &s).0])).collect();
    for _ in 0..q {
        let x = parse!(it);
        let (si, si2) = getni(x, &s);
        let (ti, ti2) = getni(x, &t);
        let mut ret = min(diff(x, s[si]) + st[si], diff(x, t[ti]) + ts[ti]);
        if let Some(si) = si2 {
            ret = min(ret, diff(x, s[si]) + st[si]);
        }
        if let Some(ti) = ti2 {
            ret = min(ret, diff(x, t[ti]) + ts[ti]);
        }
        println!("{}", ret);
    }
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main(){
    int n,k;
    cin >> n >> k;
    int p=0;
    for (int i=1;i<n-1;i++){
        p+=i;
    }
    if (k>p) {cout << -1 << endl;return 0;}
    int m=n-1+p-k;
    cout << m << endl;
    for (int i=0;i<n-1;i++){
        cout << 1 << " " << i+2 << endl;
    }
    int u=0;
    for (int i=2;i<n;i++){
        for (int j=i+1;j<n+1;j++){
            if (u==p-k) return 0;
            cout << i << " " << j << endl;
            u++;
        }
    }
}

Measured memory_bytes: 256
N, X = map(int, input().split())
x = list(map(int, input().split()))

y = [x[0]]
for i in range(N-1):
    x[i+1] += x[i]
    y.append(x[i+1])

ans = 10**21
for k in range(1, N+1):
    num = N
    memo = k * X + X * N
    i = 0
    while num > k:
        memo += max(i+3, 5) * (y[num-1] - y[num-1-k])
        num -= k
        i += 2
    memo += max(i+3, 5) * (y[num-1])
    ans = min(ans, memo)

print(ans)


Measured memory_bytes: 98128
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
int key;
Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
while (u != NIL && k != u->key) {
if (k<u->key ) u= u->left;
else u = u->right;
}
return u;
}

void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;

z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;

while ( x != NIL ) {
y = x;
if ( z->key < x->key ) {
x = x->left;
} else {
x = x->right;
}
}

z->parent = y;
if ( y == NIL ) {
root = z;
} else {
if ( z->key < y->key ) {
y->left = z;
} else {
y->right = z;
}
}
}

void inorder(Node *u) {
if ( u == NIL ) return;
inorder(u->left);
printf(" %d", u->key);
inorder(u->right);
}

void preorder(Node *u) {
if ( u == NIL ) return;
printf(" %d", u->key);
preorder(u->left);
preorder(u->right);
}

int main() {
int n, i, x;
string com;

scanf("%d", &n);

for(i= 0; i< n; i++ ){
cin >> com;
if ( com[0] == 'f' ) {
scanf("%d", &x);
Node *t = find(root, x);
if(t != NIL ) printf("yes\n");
else printf("no\n");
} else if ( com == "insert" ) {
scanf("%d", &x);
insert(x);
} else if ( com == "print" ) {
inorder(root);
printf("\n");
preorder(root);
printf("\n");
}
}
return 0;
}


Measured memory_bytes: 21940
s=int(input())

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


# modを考慮した組み合わせ
# nCrを高速に出力
# 上の２つが必要(egcd,modinv)
def combination(n, r, mod=10**9+7):
    r = min(r, n- r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res




def devide_into_n_piece(n):
    remain=s-3*n
    return combination(remain+n-1, n-1)

ans=0
mod=10**9+7
for i in range(1,s//3+1):
    ans+=devide_into_n_piece(i)
    ans=ans%mod

print(ans)



Measured memory_bytes: 76068
n = int(input())
A = [0]*n
for i in range(n):
    count = 0
    flg_odd = 0
    l = i
    i = i+1
    while(True):
        if ( i%2 != 0):
            flg_odd = 1
        if ( flg_odd == 1):
            A[l] = count
            break
        i = i//2
        count += 1
m = A.index(max(A))
print(m+1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    map<int,int> dp;
    int k=0,l=1;
    dp[0]=1;
    rep(i,n){
        k = (k+l*ctoi(s[n-1-i]))%2019;
        dp[k]++;
        l = l*10%2019;
    }
    ll ans =0;
    for(auto p:dp){
        ans += p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3732
#include <stdio.h>
#include <math.h>
double f(int q, double x){
    return (x * x * x - q) / (3 * x * x);
}
 
double root(int q){
    double x = q / 2.0;    
    while (fabs(x * x * x - q) >= 0.00001 * q) {
        x = x - f(q, x);
    }
    return x;
}
 
int main(void){
    int q;
    while(scanf("%d\n", &q) != EOF) {
        if(q == -1) break;
        printf("%.6f\n", root(q));
    }
    return 0;
}


Measured memory_bytes: 2104
#include <cstdio>

int main() { 
  char s[20];
  char t[20];

  scanf("%s", s);

  for (int i = 0; i < 20; ++i) {
    if (s[i] == ',')
      t[i] = ' ';
    else
      t[i] = s[i];
  }

  printf("%s\n", t);

  return 0;
}


Measured memory_bytes: 128
open System
open System.Collections.Generic
open System.Linq
open System

let Puts = Console.WriteLine : 'a -> unit
let Put = Console.Write : 'a -> unit
let Read() = Console.ReadLine()
let Reads () = Console.ReadLine().Split()
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])

let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ReadIntTriple () = ReadTriple () |> FuncTriple int int int
let ReadIntDouble () = ReadDouble () |> FuncDouble int int

let ensmallen l = l % 1000000007L

let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)


let sayYESNO b = if b then Puts "YES" else Puts "NO"

// main code

let s = Read()
Seq.head s |> Put
s.Length - 2 |> Put
Seq.last s |> Puts


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int, int> mp;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += mp[i - a[i]];
        mp[i+a[i]]++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 21052
def main():
    a,b,c = map(int, input().split())
    f = 1
    if a > b or a == b:
        f = 0
    else:
        if b > c or b == c:
            f = 0

    if f == 0:
        print("No")
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 7752
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll N, M;
ll cnt[100010];
bool used[100010];
ll ans;

int main()
{
  std::cin >> N >> M;

  rep( i, N )
    cnt[i] = 1;

  used[0] = true;

  rep( i, M )
  {
    ll x, y;
    std::cin >> x >> y;

    --x, --y;
    
    --cnt[x];
    ++cnt[y];

    if( used[x] )
      used[y] = true;

    if( !cnt[x] )
      used[x] = false;
  }

  rep( i, N ) if( used[i] )
    ++ans;

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
ordered_set st;
bool check(ll mid, ll arr[], ll n, ll k)
{
    vector<ll> less,more;
    ll ans = 0;
    rep(n)
    {
        ll temp;
        if(arr[i]>0)
        {
            temp = floor(((ld)mid)/arr[i]);
            /*if(mid%arr[i] == 0)
                temp--;*/
            if(arr[i]<=temp)
                ans--;
            less.pb(temp);    
        }
        else if(arr[i]<0)
        {
            temp = ceil(((ld)mid)/arr[i]);
            /*if(mid%arr[i] == 0)
                temp++;*/
            if(arr[i]>=temp)
                ans--;
            more.pb(temp); 
        }
        
        else
        {
            if(arr[i]<=mid)
                ans+=n-1;
        }
    }
    
    sort(less.begin(),less.end());
    sort(more.begin(),more.end(),greater<ll>());
    
    ll p1 = 0;
    rep(less.size())
    {
        while(p1<n && arr[p1]<=less[i])
            p1++;
        ans+=p1;    
    }
    
    p1 = n-1;
    rep(more.size())
    {
        while(p1>-1 && arr[p1]>=more[i])
            p1--;
        ans+=n-1-p1;    
    }
    ans/=2;
    //cout<<"for "<<mid<<" = "<<ans<<"\n";
    if(ans>=k)
        return 0;
    return 1;    
    
    
}

int main()
{
   FAST/**/
   
   ll n,k;
   cin>>n>>k;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   sort(arr,arr+n);
   rep(n)
        st.insert(mp(arr[i],i));         
   
   ll start = -inf;
   ll end = inf;
   
   while(end - start > 1)
   {
       ll mid = start + (end - start)/2;
       ///cout<<"At "<<mid<<"\n";
       bool temp = check(mid,arr,n,k);
       if(temp == 0)
            end = mid;
       else start = mid+1;
   }
   
   ll hi;
   if(check(start,arr,n,k) == 0)
        hi = start;
   else hi = end;        
   cout<<hi;
   return 0;        
}  
   

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

typedef pair<int, int> pii;

bool cmp(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			int num, t = 0;
			cin >> num;
			for (int j = 0; j < 4; j++){
				int m, s;
				cin >> m >> s;
				t += m * 60 + s;
			}
			p[i] = make_pair(num, t);
		}
		
		sort(p.begin(), p.end(), cmp);
		
		cout << p[0].first << endl << p[1].first << endl << p[n - 2].first << endl;
	}
	
	return (0);
}

Measured memory_bytes: 1236
// ALDS1_2_A Bubble Sort
import java.io.*;

class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
      try {
         int N = Integer.parseInt(br.readLine());
         int[] A = new int[N];
         String[] inputAry = br.readLine().split(" ");
         for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(inputAry[i]);
         }
         bubblesort(A, N);
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static void bubblesort(int[] A, int N) {
      int cnt = 0;
      int tmp;
      boolean flag = true;
      while (flag) {
         flag = false;
         for (int j = N - 1; j >= 1; j--){
            if (A[j] < A[j - 1]) {
               tmp = A[j];
               A[j] = A[j - 1];
               A[j - 1] = tmp;
               cnt++;
               flag = true;
            }
         }
      }
      for (int i = 0; i < N; i++) {
         if (i == N - 1) {
            System.out.println(A[i]);
         } else {
            System.out.print(A[i] + " ");
         }
      }
      System.out.println(cnt);
   }
}

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

int main()
{
    int i, start, max, num;
    char S[3];
    start = 0;
    max = 0;
    num = 0;
    scanf("%s", S);
    for (i = 0; i < 3; i++)
    {
        if (S[i] == 'R')
        {
            if (i > 0 && S[i - 1] != 'R')
            {
                max = num;
                num = 0;
            }
            num++;
        }
    }
    max = num;
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 1692
import java.util.*;
import java.lang.*;

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

    long limit = (long) Math.pow(10,18);
    long sum = 1;
    long [] c = new long[a];
    for (int i=0;i<a;i++){
      long b = scan.nextLong();
      if (b==0){
        System.out.println(0);
        return;
      }
      c[i] = b;
    }

    for (int j=0;j<a;j++){
      if (Math.log10(sum)+Math.log10(c[j])>18){
        System.out.println(-1);
        return;
      }
      sum*=c[j];
    }

    if (sum>limit){
      System.out.println(-1);
      return;
    }
    System.out.println(sum);
  }
}


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

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s;
  else cout << "red";
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = H * W
ans = float('inf')
for h in range(1, H):
    Sa = h * W
    Sb = (H - h) // 2 * W
    Sc = S - Sa - Sb
    diff1 = max(abs(Sa-Sb), abs(Sb - Sc), abs(Sc - Sa))
    Sb = (H - h) * (W // 2)
    Sc = S - Sa - Sb
    diff2 = max(abs(Sa-Sb), abs(Sb - Sc), abs(Sc - Sa))
    ans = min(ans, diff1, diff2)
for w in range(1, W):
    Sa = H * w
    Sb = (W - w) // 2 * H
    Sc = S - Sa - Sb
    diff1 = max(abs(Sa - Sb), abs(Sb - Sc), abs(Sc - Sa))
    Sb = (W - w) * (H // 2)
    Sc = S - Sa - Sb
    diff2 = max(abs(Sa - Sb), abs(Sb - Sc), abs(Sc - Sa))
    ans = min(ans, diff1, diff2)
print(ans)


Measured memory_bytes: 44528
import numpy as np
'''
K = 2
H, W = 5, 5
a = np.array([
	[0, 0, 0, 0, 1],
	[0, 0, 0, 1, 1],
	[0, 0, 1, 1, 1],
	[0, 1, 1, 1, 1],
	[1, 1, 1, 1, 1]
])
'''

def conv(c):
	#print(c)
	return int(c=='#')
H, W, K = map(int, input().split())
a = np.array([list(map(conv, input())) for _ in range(H)])
count = 0
for i in range(2 ** H - 1):
	b = np.delete(a.copy(), [j for j in range(H) if ((i >> j) & 1)], 0)
	blen = b.shape[1]
	for i in range(2 ** W - 1):
		c = np.delete(b, [j for j in range(blen) if ((i >> j) & 1)], 1)
		#print(np.sum(c))
		if K==np.sum(c):
			count += 1
print(count)
print()

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

int main(){
    double a, b;
    cin >> a >> b;
    if(a > b)   swap(a, b);
    if(b-a < 180){
        a += (b-a)/2;
        if(a > 360) a -= 360.0;
    }else{
        a -= (360-b+a)/2;
        if(a < 0)   a += 360.0;
    }
    cout << fixed << setprecision(10) << a << endl;
    return 0;
}


Measured memory_bytes: 3276
{-# LANGUAGE RecordWildCards #-}
import Data.ByteString.Char8 as BC (getLine, words, readInt)
import Prelude hiding (getLine, words)
import Data.List hiding (words)
import Data.Function (on)
import qualified Data.Map.Strict as M
import Data.Maybe (fromJust)
import Control.Monad
import Control.Arrow

main = do
    n <- readLn
    xs <- map (fst . fromJust . readInt) . words <$> getLine
    mapM_ print . fill n . solve . groupMnts $ xs
    where
        fill n xs = let filler = M.fromAscList . zip [1..n] $ repeat 0
                        filled = (M.fromAscList xs) `M.union` filler
                        in M.elems filled

type Stones = Int
type Index = Int

data Group = Group { _leftMost :: Index, _stones :: Stones, _mnts :: Int }
           deriving (Show)

groupMnts :: [Stones] -> [Group]
groupMnts = joinMountains . groupByStones . attachIndex
    where
        attachIndex = flip zip [1..]
        groupByStones
            = groupBy ((==) `on` fst) . sortBy (compare `on` first negate)
        joinMountains
            = map (\ xs@((s,i):_)  -> Group i s (length xs))

mergeGroups :: Group -> Group -> Group
mergeGroups (Group i s m) (Group i' s' m')
    = if s == s'
         then Group (min i i') s (m+m')
         else error "cannot merge and I was too lazy to use Maybe"

solve :: [Group] -> [(Int,Int)]
solve = join . consume
    -- fixme
    where
        join = foldl f []
        f [] n = [n]
        f acc@((i,n):r) x@(i',n') = if i == i' then (i,n+n'):r else x:acc
        consume [] = []
        consume [Group{..}] = [ (_leftMost, _stones * _mnts) ]
        consume (g0:g1:rest) =
            (_leftMost g0, (_stones g0 - _stones g1)* _mnts g0)
                : consume (mergeGroups g0{_stones=_stones g1} g1:rest)


Measured memory_bytes: 72572
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) + n != 0){
		int four = 1;
		
		while (four < n){
			four *= 4;
		}
		if (n !=0 && four > n){
			four /= 4;
		}
		while (four > 0){
			printf("%d", n / four);
			n %= four;
			four /= 4;
		}
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 612
#include<stdio.h>
int main () {
  int m,f,r;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1){
      printf("F\n");
    }else if(m + f >= 80){
      printf("A\n");
    }else if(m + f >= 65 && m + f < 80){
      printf("B\n");
    }else if(m + f >= 50 && m + f < 65){
      printf("C\n");
    }else if(m + f >=30 && m + f < 50){
      if(r >= 50){
	printf("C\n");
      }else if(r < 50){
	printf("D\n");
      }
      }else if(m + f < 30){
	printf("F\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
//#include<stdlib.h>
using namespace std;
int main() {
	int r,d,x;
	cin >> r >> d>>x;
	for (int a = 1; a < 11; a++)
	{
		x = r * x - d;

		cout << x<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
void dfs(string s,char c){
  if(s.length()==n) cout<<s<<endl;
  else for(char d='a'; d<=c; ++d) dfs(s+d,(c==d? (char)(c+1):c));
}
int main(void){
  cin>>n;
  dfs("",'a');
  return 0;
}

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

using namespace std;

int main()

{

    //    string in;

    //  getline(cin,in);

    //  cout<<in;

   

   

 



        long long num;

        string str;

        cin >> num;

        char temp;

        while (num > 0)

        {

            temp = num % 26;

            if (temp == 0)

            {

                if (num / 26 != 0)

                {

                    str.push_back('z');

                    num--;

                }

            }

            else

            {

                temp = temp + 96;

                str.push_back(temp);

                //cout<<temp;

            }

            temp = 0;

            num /= 26;

        }

        reverse(str.begin(), str.end());

        cout << str << endl;

        

    

}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
map<ll,ll> prime_factor(ll x){
    map<ll,ll> m;
    ll sq=(ll)sqrt(x) + 1;
    vector<ll> v_prime=vectorprime(sq);
    
    ll tmp=x;
    rep(i,sz(v_prime)){
        ll count=0;
        while(tmp % v_prime[i] == 0){
            tmp /= v_prime[i];
            count++;
        }
        if(count != 0) m[v_prime[i]]=count;
        if(tmp==1) break;
    }
    
    if(tmp != 1) m[tmp]=1;
    return m;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M,K; cin>>N>>M>>K;
    bool ans=false;
    rep(i,N+1)rep(j,M+1){
        if(i*j+(N-i)*(M-j) == N*M-K) ans=true;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int n, m;
vector<vector<char>> G1;
vector<vector<char>> G2;

bool check(int x, int y)
{
	for(int i = 0; i < m; i++){
		for(int j = 0; j < m; j++){
			if((i==0&&j==0) && (x+m>n || y+m>n)) break;
			if(G1[x+i][y+j] != G2[i][j]) return 0; 
		}
	}
	return 1;
}

int main()
{
	cin >> n >> m;
	G1.resize(n+5);
	rep(i,n+5) G1[i].resize(n+5);
	rep(i,n)rep(j,n){
		cin >> G1[i][j];
	}
	G2.resize(m+5);
	rep(i,m+5) G2[i].resize(m+5);
	rep(i,m)rep(j,m){
		cin >> G2[i][j];
	}

	rep(i,n)rep(j,n){
		if(check(i,j)){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

typedef pair<int, int> pxy;

char map[20][20];

int W, H, start_x, start_y, ans = 0;

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

void dfs(int sx, int sy)
{
  stack<pxy> s;
  s.push(pxy(sx, sy));
  while(!s.empty()){
    int x, y;
    x = s.top().first;
    y = s.top().second;
    s.pop();
    if(map[x][y] != '#'){
      ans++;
      map[x][y] = '#';
      for(int i = 0; i < 4; i++){
	int next_x = x + dx[i], next_y = y + dy[i];
	if(next_x < W && next_x >= 0 && next_y < H && next_y >= 0){
	  s.push(pxy(next_x, next_y));
	}
      }
    }
  }
}

int main()
{
  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0){
      break;
    }else{
      for(int i = 0; i < H; i++){
	for(int j = 0; j < W; j++){
	  cin >> map[j][i];
	  if(map[j][i] == '@'){
	    start_x = j;
	    start_y = i;
	  }
	}
      }
      dfs(start_x, start_y);
      cout << ans << endl;
      ans = 0;
    }
  }
}

Measured memory_bytes: 1220
#Boost Force  / Backtracking
import sys
input = sys.stdin.readline
d = []
f = []
time = 0
#ทำการ search
def search(r):
    global d,f,time,s
    if d[r] == 0:
        time += 1
        d[r] = time
    else:
        return
    for x in s[r]:
        search(x)
    time += 1
    f[r] = time


n = int(input()) #รับค่าจำนวน node ทั้งหมด
s = [[] for i in range(n+1)]
for _ in range(n):
    d = list(map(int,input().split())) #รับข้อมูลทีละบรรทัด split เก็บเป็น int
    #ตน d[0] คือ node ตน 1 คือ ดีกรี ตนตั้งแต่ 2ไป คือ vertex
    s[d[0]] = d[2:]

d = [0 for _ in range(n+1)]
f = [0 for _ in range(n+1)]

for i in range(1,n+1):
    if d[i] == 0:
        search(i)

#แสดง node เวลาที่เจอ และ เวลา finish
for i in range(1,n+1):
    print (i,d[i],f[i])



Measured memory_bytes: 5664
#include <iostream>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
int main(){
    // Your code here!
    int n,i;
    cin>>n;
    set<string> s;
    
    for(i=0; i<n; i++){
        string order,str;
        cin>>order>>str;
        
        if(order=="insert") s.insert(str);
        else{
            if(s.find(str)==s.end()) cout<<"no"<<endl;
            else cout<<"yes"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 32160
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int d = s.size();
	string ans = "AC";
	if (s.at(0) != 'A') ans = "WA";
	int cnt = 0;
	for (int i = 1; i < d; i++) {
		if (isupper(s[i])) {
			if (i == 1 || i == d - 1 || s.at(i) != 'C') {
				ans = "WA";
			}
			cnt++;
		}
	}
	if (cnt != 1) ans = "WA";
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,j,k,n,ans=0,now=0;
	cin>>n;
	for(i=1;i<=n;++i){
		char c;
		cin>>c;
		if(c=='I')now++;
		else now--;
		ans=max(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[10005];

int main(void){
	scanf("%d%d",&n,&m);
	int sum=0;
	for(int i=0;i<m;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum>n){
		printf("%d\n",-1);
	}else{
		printf("%d\n",n-sum);
	}
	return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
    return 0;
}

Measured memory_bytes: 256