akhauriyash/Code-Regression huggingface dataset:
int G(x,y){return y?G(y,x%y):x;}
main(x,y,z,t,f){for(;scanf("%d%d",&x,&y),y;printf("%d %d\n",z>f?z:f,t)){
y/=G(x,y);
for(z=0;y%2==0;y/=2)z++;
for(f=0;y%5==0;y/=5)f++;
if(y==1)t=0;else{x=1;t=0;do{x=x*10%y;t++;}while(x!=1);}
}exit(0);}

Measured memory_bytes: 600
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long k, n,en=0;
	cin >> n >> k;
	while (n)
	{
		n /= k;
		en++;
	}
	cout << en << endl;
}
 
 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int day,ass,sum=0;
    cin>>day>>ass;
    int noa[ass];
    for(int i=0;i<ass;i++)
    {
        cin>>noa[i];
    }
    for(int i=0;i<ass;i++)
    {
        sum=sum+noa[i];
    }
    int temp=day-sum;
    if(day<sum)
    {
        cout<<-1;
    }
    else if(sum==day)
    {
        cout<<0;
    }
    else
    {
        cout<<temp;
    }
}

Measured memory_bytes: 3232
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

//int solve() {
//	ll a;
//	double b;
//	cin >> a >> b;
//
//	ll ll_b = ll(b * 100.0);
//	ll ll_b0 = ll_b / 100LL;
//	ll ll_b1 = (ll_b - ll_b0 * 100LL) / 10LL;
//	ll ll_b2 = ll_b - ll_b0 * 100LL - ll_b1 * 10LL;
//
//	ll res = 0;
//	res += a * ll_b1 * 10LL + a * ll_b2;
//	res /= 100LL;
//	res += a * ll_b0;
//
//	cout << res << endl;
//
//	return 0;
//}

int solve() {
	ll n;
	cin >> n;
	
	vector<ll> as(n);
	bool exist0 = false;
	for (ll i = 0; i < n; ++i) {
		cin >> as[i];
		if (as[i] == 0) exist0 = true;
	}
	if (exist0) {
		cout << 0 << endl;
		return 0;
	}
	
	ll const_val = 1000000000000000000LL;
	ll res = 1LL;
	for (ll i = 0; i < n; ++i) {
		if (const_val % res == 0LL) {
			if (const_val / res < as[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			if (const_val / res < as[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
		res *= as[i];
	}
	
	cout << res << endl;
	
	return 0;
}

//main function
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;
}


Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int n, q;
	cin >> n >> q;
	vector<ll> a(n), x(q);
	FOR(i, n)cin >> a[i];

	FOR(i, q){
		ll ans = 0, sum = 0, x;
		cin >> x;
		int r = 0;
		FOR(l, n){
			while (r < n&&sum + a[r] <= x){
				sum += a[r];
				r++;
			}
			ans += r - l;
			if (l == r)r++;
			else sum -= a[l];
		}
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3548
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

ll inp[N + N];

int main(){
  int n, m;
  ll sum = 0;
  fastScan(n);
  fastScan(m);
  for(int i = 0; i < n; i++){
    fastScan(inp[i]);
  }
  sort(inp, inp + n, greater < ll > ());
  for(int i = m; i < n; i++){
    sum += inp[i];
  }
  printf("%lld\n", sum);
}


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

int main(){
  ll N, W;
  cin >> N >> W;
  vector<ll> v(N + 1), w(N + 1);
  for(int i = 1; i <= N; i++){
    cin >> w[i] >> v[i];
  }
  vector<vector<ll>> dp(N + 1, vector<ll> (W + 1));
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= W; j++){
      if(j - w[i + 1] < 0){
        dp[i + 1][j] = dp[i][j];
      }
      else{
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i + 1]] + v[i + 1]);
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
map<int,bool> ma;
int main(){
	int x;
	cin>>x;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int c;
		cin>>c;
		ma[c]=true;
	}
	int i=0;
	while(true){
		if(!ma[x-i]){
			cout<<x-i<<'\n';
			return 0;
		}
		else if(!ma[x+i]){
			cout<<x+i<<'\n';
			return 0;
		}
		i++;
	}
	return 0;
}

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

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

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

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

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,n;
	cin>>a>>b>>n;
	ll ans=(n>=b?b-1:n)*a/b;
	puta(ans);
}



Measured memory_bytes: 3588
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define LIM 301
int h, w, d;
vector<vector<int>>a;
int q;
vector<int>l, r;
vector<pair<int, int>>p;
vector<ll>c(h*w + 1, -1);
pair<int, int> cord(int v) {
	if (p[v].first != -1)return p[v];
	else {
		rep(i, h)rep(j, w) {
			p[a[i][j]] = { i,j };
		}
		return p[v];
	}
}
ll dist(int x, int y, int i, int j) {
	return abs(x - i) + abs(y - j);
}
ll cost(int v) {
	if (c[v] != -1)return c[v];
	else if (v <= d) return 0;
	else {
		auto cur = cord(v - d);
		auto next = cord(v);
		c[v] = cost(v - d) + dist(next.first, next.second, cur.first, cur.second);
		return c[v];

	}

}
int main() {
	cin >> h >> w >> d;
	a = vector<vector<int>>(h, vector<int>(w));
	rep(i, h)rep(j, w)cin >> a[i][j];
	cin >> q;
	l = vector<int>(q);
	r = vector<int>(q);
	rep(i, q)cin >> l[i] >> r[i];
	p = vector < pair<int, int>>(h*w + 1, { -1,-1 });
	c = vector<ll>(h*w + 1, -1);
	rep(i, q) {
		cout << cost(r[i]) - cost(l[i]) << endl;
	}
	return 0;
}





Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  vector<ll> ABC(3);
  for(auto&& i : ABC){
    cin >> i;
  }
  sort(ABC.begin(), ABC.end());
  if(ABC == vector<ll>{5LL, 5LL, 7LL}){
    cout << "YES" << rt;
  }
  else{
    cout << "NO" << rt;
  }
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    q,h,s,d = LI()
    n = I()
    print(min(d,s<<1,h<<2,q<<3)*((n<<2)>>3)+min(s,h<<1,q<<2)*(((n<<2)&((1<<3)-1))>>2)+min(h,q<<1)*(((n<<2)&((1<<2)-1))>>1)+q*((n<<2)&((1<<1)-1)))
    return
#B
def B():
    a = input()
    n = len(a)
    f = defaultdict(lambda : 0)
    for i in a:
        f[i] += 1
    ans = 1+(n*(n+1)>>1)
    for i in f.values():
        ans -= i*(i+1)>>1
    print(ans)
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 40688
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = 0;
    for(int i=a;i<=b;i++){
      if(i/10000 == i%10 && (i%10000)/1000 == (i%100)/10)ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

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

  ll n;
  cin >> n;
  vector<ll> v(n+1), w(n+1);
  for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];

  ll MAX_W = 100001LL;
  vector<vector<ll>> dp(1LL<<10, vector<ll>(MAX_W, 0));

  for (ll i = 1; i < 1LL<<10; i++) {
    if (i > n) break;
    for (ll j = 1; j < MAX_W; j++) {
      dp[i][j] = max(dp[i][j-1], dp[i/2][j]);
      if (j - w[i] >= 0) {
        dp[i][j] = max(dp[i][j], dp[i/2][j-w[i]] + v[i]);
      }
    }
  }
  //cout << dp[1][40000] << endl;
  //cout << "struct" << endl;
  //return 0;
	
  ll query;
  cin >> query;
  for (ll q = 0; q < query; q++) {
    ll val, lim;
    cin >> val >> lim;
    if (val < (1LL<<10)) {
      cout << dp[val][lim] << endl;
      continue;
    }
    
    ll ans = 0;
    int len = (int)(log2(val)) - 10 + 1;
    for (int i = 0; i < (1<<len); i++) {
      ll vtemp = 0, wtemp = 0, index = val;
      for (int j = 0; j < len; j++) {
        if ((i>>j) & 1) {
          vtemp += v[index];
          wtemp += w[index];
        }
        index /= 2;
        if (index < 1LL<<10) {
          //compare
          if (lim - wtemp < 0) break;
          ans = max(ans, vtemp + dp[index][lim - wtemp]);
          break;
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 811064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

struct Guidebook
{
    string townname;
    int point;
    int id;

    bool operator<( const Guidebook& right ) const {
        return townname == right.townname ? point > right.point : townname < right.townname;
    }
};

int main(){

    int N; cin >> N;
    vector<Guidebook> g(N);

    for (int i = 0; i < N; i++)
    {
        cin >> g[i].townname >> g[i].point;
        g[i].id=i+1;
    }

    sort(g.begin(),g.end());

    for (int i = 0; i < N; i++)
    {
        printf("%d\n",g[i].id);
    }
    
    return 0;
}

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

int main(){
	double t[2];
	int num[2][4];
	memset(num,0,sizeof(num));
	while(cin >> t[0] >> t[1]){
		for(int i=0;i<2;i++){
			if(t[i] < 0.2){
				num[i][3]++;
			}else if(t[i] < 0.6){
				num[i][2]++;
			}else if(t[i] < 1.1){
				num[i][1]++;
			}else{
				num[i][0]++;
			}
		}
	}
	for(int i=0;i<4;i++){
		cout << num[0][i] << " " << num[1][i] << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int N = 1e5+1;
using ll = long long;
int cnt[N];

int main(){
	int n,k,q;
	scanf("%d%d%d", &n, &k, &q);
	for(int i=0;i<q;++i){
		int x;
		scanf("%d", &x);
		++cnt[x];
	}
	for(int i=1;i<=n;++i){
		if(k+cnt[i]-q > 0) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){

    int N; cin >> N;
    vector<int> X(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
    }
    ll mi = INF;
    for(int i=1;i<=100;i++){
        ll cnt=0;
        for(int j=0;j<N;j++){
            cnt += (X[j]-i) * (X[j]-i);
        }
        if(mi>cnt) mi = cnt;
    }
    cout << mi << endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int d[N];

    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d,d+N);

    int count=0;

    if(d[(N/2)-1] != d[N/2]){
        count = d[N/2]-d[(N/2)-1];
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<long long>minus(1,0);
	vector<long long>plus(1,0);
	for(int i=0; i<n; i++){
		int a;
		cin>>a;
		if(a>=0) plus.push_back(a);
		else minus.push_back(-1*a);
	}
	sort(minus.begin(),minus.end());
	sort(plus.begin(),plus.end());
	long long mindist = numeric_limits<long long>::max();
	for(int i=0; i<plus.size(); i++){
		if(i>k) break;
		int pick = k-i;
		if(pick>=minus.size() || pick<0) continue;
		
		long long dist = plus[i]*2+minus[pick];
		mindist = min(mindist,dist); 
		dist = plus[i]+2*minus[pick];
		mindist = min(mindist,dist);
	}
	cout<<mindist;
}

Measured memory_bytes: 4580
n, W = map(int, input().split())
w = [0] * n
v = [0] * n
for i in range(n):
    w[i], v[i] = map(int, input().split())

dp = [[0 for i in range(W + 1)] for j in range(n + 1)]

for i in range(n):
    for j in range(W + 1):
        if w[i] <= j:
            dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][W])

Measured memory_bytes: 171912
from decimal import Decimal
import math
a, b, c = map(int, input().split())

A = Decimal(str(a))**Decimal('0.5')
B = Decimal(str(b))**Decimal('0.5')
C = Decimal(str(c))**Decimal('0.5')
if A + B < C:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5460
#include <iostream>
#include <math.h>
using namespace std;

int kaijou(int _x) {
	int num = 1;
	for (int i = 1; i <= _x; i++)
		num *= i;

	return num;
}

int main() {
	int n, p[8], q[8], p_b = 0, q_b = 0, ans;
	cin >> n;

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

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

	for (int i = 0; i < n; i++) {
		p_b += (p[i] - 1) * kaijou(n - 1 - i);
		q_b += (q[i] - 1) * kaijou(n - 1 - i);

		for (int j = 0; j < n; j++) {
			if (p[i] < p[j])
				p[j]--;
			if (q[i] < q[j])
				q[j]--;
		}
	}

	if (p_b - q_b > 0)
		ans = p_b - q_b;
	else
		ans = q_b - p_b;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#define     mod             (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vector<int> , greater<int> >
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

bool comparator(ii a, ii b)
{
   if(a.F == b.F)
   {
      return (a.S < b.S);
   }
   else
   {
      return (a.F > b.F);
   }
}  


int32_t main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;
   

   int n;
   cin>>n;

   int x, y, z;

   map<ll int, int> m;

   for(int i=1; i<=sqrt(n); i++)
   {
      for(int j=1; j<=sqrt(n); j++)
      {
         for(int k=1; k<=sqrt(n); k++)
         {
            ll x = i*i + j*j + k*k + i*j + j*k + k*i;

            m[x]++;
         }
      }
   }

   for(int i=1; i<=n; i++)
   {
     cout<<m[i]<<endl;
   }
}
            

    
    



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

int Hash[244140625];
char s[13];

int getChar(char ch){
  if(ch=='A'){
    return 1;
  }else if(ch=='C'){
    return 2;
  }else if(ch=='G'){
    return 3;
  }
  return 4;
}

int getKey(){
  int sum=0,p=1;
  for(int i=0;i<strlen(s);i++){
    sum+=p*(getChar(s[i]));
    p*=5;
  }
  return sum;
}

int main(){
  int n;
  char com[7];
  scanf("%d",&n);
  while(n--){
    scanf("%s %s",com,s);
    if(com[0]=='i'){
      Hash[getKey()]=1;
      // printf("%d\n",getKey());
    }else{
      if(Hash[getKey()]){
        puts("yes");
      }else{
        puts("no");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 39036
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

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

void Comuse() {
  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;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(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;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

int A,B,C;

void solve() {
  cin >> A >> B >> C;
  cout << C << " " << A << " "<< B;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    if A <= B:
        r = (B+ W*T) - (A + V*T)
        if r <= 0:
            print("YES")
        else:
            print("NO")
    else:
        r =   (B- W*T)-(A - V*T)
        if r >= 0:
            print("YES")
        else:
            print("NO")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main(){
    int k, x;
    cin >> k >> x;
    if(500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,m,ans=0; cin>>n>>m;
    vector<ll> h(n,0);
    rep(i,n) cin>>h[i];
    vector<vector<ll>> path(n);
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    rep(i,n){
        rep(j,path[i].size()){
            if(h[path[i][j]]>=h[i]) break;
            if(j==path[i].size()-1) ans++;
        }
        if(path[i].size()==0) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9860
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
i = 1
Nin = [ i for i in range(1,N+1)]
for li in itertools.permutations( Nin ):
  li = list(li)
  if li == P:
    pnum = i
  if li == Q:
    qnum = i
  i += 1
print(abs(pnum-qnum) )


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

using namespace std;


void solve() {
    int n, H;
    cin >> n >> H;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int keep = *max_element(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<int>());
    long long once=0;
    int cnt = 0;
    for (int x: b) {
        if (x <= keep) break;
        once += x;
        cnt++;
        if (once >= H) {
            cout << cnt; return;
        }
    }
    int res = cnt + (H-once+keep-1)/keep;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
n = int(input())
*w, = map(int, input().split())

ans = 100000
for i in range(n-1):
    w1 = w[:i+1]
    w2 = w[i+1:]
    d = abs(sum(w1)-sum(w2))
    if d < ans:
        ans = d
print(ans)

Measured memory_bytes: 3060
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll n,v=1;
  cin >> n;
  if(n==1){
    cout << "1\n";
    return 0;
  }
  for(int i=0;;i++){
    v*=2;
    if(v>n){
      cout << v/2 << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX_V = 21100;
const int INF = 1001001001;
const ll LINF = 23456789123456789;
struct edge { ll to, cap, rev;};

vector<edge> G[MAX_V];
ll level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, ll cap){
    G[from].push_back((edge){to, cap, (ll)G[to].size()});
    G[to].push_back((edge){from, 0, (ll)G[from].size() - 1});
}

// sからの最短距離をBFSで計算する
void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスをDFSで探す
ll dfs(int v, int t, ll f){
    if(v == t)return f;
    for(int &i = iter[v]; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
ll max_flow(int s, int t){
    ll flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0)return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, INF)) > 0){
            flow += f;
        }
    }
}
 
 
int main(){

    int h, w;
    cin >> h >> w;

    string s[h];
    rep(i,h)cin >> s[i];

    int S, T;

    rep(i,h){
        rep(j,w){
            if(s[i][j] != '.'){
                int x = i * 100 + j;
                add_edge(x, x+10000, 1);
                rep(k,h){
                    if(i == k)continue;
                    if(s[k][j] != '.'){
                        int y = k * 100 + j;
                        add_edge(y+10000,x,1);
                        add_edge(x+10000,y,1);
                    }
                }
                rep(k,w){
                    if(j == k)continue;
                    if(s[i][k] != '.'){
                        int y = i * 100 + k;
                        add_edge(y+10000,x,1);
                        add_edge(x+10000,y,1);
                    }
                }
            }
            if(s[i][j] == 'S')S = i * 100 + j;
            if(s[i][j] == 'T')T = i * 100 + j;
        }
    }

    if(S % 100 == T % 100 || S / 100 == T / 100){
        cout << -1 << endl;
        return 0;
    }
    
    // 3. 出力.
    cout << max_flow(S+10000, T) << endl;
    return 0;

}


Measured memory_bytes: 247296
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n: String = read();
    let ch: Vec<char> = n.chars().collect();
    let mut count: i32;
    for i in 0..ch.len(){
	count = 0;
	for j in 0..ch.len(){
	    if ch[i]==ch[j] {
		count+=1;
	    }
	}
	if count != 2 {
	    println!("No");
	    return;
	}
    }
    println!("Yes");
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a >= 10) System.out.println(b);
        else System.out.println(b + 100 * (10 - a));
    }
}

Measured memory_bytes: 22996
S = input()
n = len(S)
T = ['dreamer', 'eraser', 'dream', 'erase']
idx = n
res = 'YES'
while idx > 0:
    for t in T:
        if S[idx-len(t):idx] == t:
            idx -= len(t)
            break
    else:
        res = 'NO'
        idx = -1
print(res)

Measured memory_bytes: 9040
N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort(key = lambda x: x[0])
res = 0
#print(a)
for i in range(N):
  if M - a[i][1] < 0:
    res += a[i][0] * M
    break
  else:
    res += a[i][1] * a[i][0]
    M -= a[i][1]
print(res)

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

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

    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; ++i) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; ++i) {
        cin >> B.at(i);
    }
    for (int i = 0; i < N; ++i) {
        cin >> C.at(i);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long ans = 0;
    for (int j = 0; j < N; ++j) {
        auto itr1 = lower_bound(A.begin(), A.end(), B.at(j));
        auto itr2 = upper_bound(C.begin(), C.end(), B.at(j));
        ans += distance(A.begin(), itr1) * distance(itr2, C.end());
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
//  const long long INF = 1LL << 60;

int main(){
   ll n;
   cin >> n;
   ll money = 1000;
   ll h=0;
   vector<ll> a(n);
   rep(i,n) cin >> a[i];
   int last = -1;
   ll nax = a[n-1];
   for(int i=n-2;i>=0;i--){
      nax = max(nax,a[i]);
      if(nax>a[i]){
         last = i;
         break;
      }
   }

   // cout << last << endl;
   //lastは最後に買う日 ただしlast==n-1ならなにもしない
   // cout << last << endl;
   // if(last==n-1){
   //    cout << 1000 << endl;
   //    return 0;
   // }
   //その次が今より高い→b かえるだけかう s なにもしない
   //ただしそのあと一生上がり続けるならかわない
   //その次が今より安い→b なにもしない s うれるだけうる

   rep(i,n-1){
      // b
      if(a[i]<a[i+1]){
         if(i>last);
         else{
            h += money / a[i];
            money %= a[i];
         }
      }
      // s
      if(a[i]>a[i+1]){
         money += h*a[i];
         h=0;
      }
   }
   money+=h*a[n-1];
   cout << money << endl;
   return 0;
}

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

int main(){
  int n,k; cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin >> h[i];
  sort(h.begin(), h.end());
  int ans=1000000001;
  for(int i=0;i+k-1<n;i++) ans = ans > h[i+k-1] - h[i] ? h[i+k-1] - h[i] : ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

struct Dice{
    int num1;
    int num2;
    int num3;
    int num4;
    int num5;
    int num6;
};

int main(){

    int n[6];
    int i;
    char c;
    for (i = 0; i < 6; i++) {
        scanf("%d", &n[i]);
    }
    struct Dice dice1 = {n[0],n[1],n[2],n[3],n[4],n[5]};
    struct Dice dice2;
    c = getchar();//一時もじ取っておかないと改行ブレークでwhileから抜けてしまう
    //printf("%d", dice1.num1);

    while (1) {
        c = getchar();
        if (c == '\n') {
            break;
        }
        dice2 = dice1;
        if(c == 'E'){
            dice1.num3 = dice2.num1;
            dice1.num6 = dice2.num3;
            dice1.num4 = dice2.num6;
            dice1.num1 = dice2.num4;
        }else if (c == 'W') {
            dice1.num6 = dice2.num4;
            dice1.num3 = dice2.num6;
            dice1.num1 = dice2.num3;
            dice1.num4 = dice2.num1;
        }else if (c == 'S') {
            dice1.num6 = dice2.num2;
            dice1.num2 = dice2.num1;
            dice1.num1 = dice2.num5;
            dice1.num5 = dice2.num6;
        }else if (c == 'N') {
            dice1.num6 = dice2.num5;
            dice1.num2 = dice2.num6;
            dice1.num1 = dice2.num2;
            dice1.num5 = dice2.num1;
        }
    }

    printf("%d\n", dice1.num1);
    return 0;
}



Measured memory_bytes: 2064
#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 mp make_pair
typedef long long ll;
typedef pair<ll,int> ii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
pbds pos,neg;
int timer;
ll len[100011];
ll shiftpos,shiftneg;
void addpos(ll x){pos.insert(mp(x-shiftpos,timer++));}
void addneg(ll x){neg.insert(mp(x-shiftneg,timer++));}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll m=0; ll c=0;
	for(int i=0;i<n;i++)
	{
		ll l,r; cin>>l>>r;
		len[i]=r-l;
		if(i>0){shiftpos+=len[i-1];	c-=len[i-1]*m;}
		shiftneg-=len[i];addpos(l); addpos(l);
		auto it=pos.begin();
		ll res=it->fi+shiftpos;
		pos.erase(pos.begin()); addneg(res);
		ll neglas=prev(neg.end())->fi+shiftneg;
		ll posles=pos.begin()->fi+shiftpos;
		if(!neg.empty()&&neglas>posles)
		{
			neg.erase(prev(neg.end())); pos.erase(pos.begin());
			addpos(neglas); addneg(posles);
		}
		m++; c-=l;
	}
	while(m>0)
	{
		c+=(*prev(pos.end())).fi+shiftpos; m--; pos.erase(prev(pos.end()));
	}
	cout<<c<<'\n';
}


Measured memory_bytes: 13568
#include <iostream>

using namespace std;

int main()
{
  int n, a, b; cin >> n >> a >> b;
  int sum = 0;

  for (int i = a; i <= n; i++) {
    int x = 0;
    int target = i;
    while(target) {
      x += target % 10;
      target /= 10;
    }
    if (x >= a && x <= b) sum += i;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize "trapv"

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int> 
#define vll vector<ll> 
#define vpll vector<pair<ll ,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define MAP map<ll ,ll>
#define UMAP unordered_map<ll , ll>
#define endl "\n"
#define SET set<ll> 
#define SETC set<char>
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define fastcout ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcases int tt = 1 ; cin >> tt ; for(int i = 1 ; i <= tt ; ++i)
#define codejam cout << "Case #"<<i <<": "; 
#define FOR(i,a,n) for(int i = a ; i <= n ; ++i)
#define FORback(i,a,n) for(int i = n ; i >= a ; --i)
#define time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define ll long long int
const ll INF = 1e13+7;
const ll mod = 1e9+7;

vvi dp ;

void solv(){
    ll n  , k ;
    cin >> n  >> k;

    vll arr(n+1);
    FOR(i , 1 , n){
        cin >> arr[i];
    }
    dp.assign(n+2 , vi(k+2 , 0));

    FOR(i , 0 , k){
        if(arr[1] < i){
            dp[1][i] = 0; 
        }
        else{
            dp[1][i] = 1;
        }
    }

    FOR(i , 2 , n){
        FOR(j , 0 , k){
            if(j == 0){
                dp[i][j] = dp[i-1][j];
            }
            else{
                if(j >= arr[i]+1){
                    dp[i][j] = (mod + dp[i][j-1] + dp[i-1][j] - dp[i-1][j-arr[i]-1])%mod;
                }
                else{
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
                }
            }
        }
    }

    // for(auto x : dp){
    //     for(auto y : x){
    //         cerr << y << " ";
    //     }
    //     cerr << endl;
    // }
    cout << dp[n][k] << endl;
}

int main(){
    fast ;    
    // testcases{
        // codejam ;
        solv();
    // } 
    time;
}




Measured memory_bytes: 43548
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int ans,used[1000010];
vector<P>in[1000010];
int n,m;

void check(int pos){
  if(used[pos]||!ans)return;
  used[pos]=1;
  for(int i=0;i<in[pos].size();i++){
    int nx=in[pos][i].first,idx=in[pos][i].second;
    if(used[nx])ans=0;
    in[pos].erase(in[pos].begin()+i);
    in[nx].erase(in[nx].begin()+idx);
    check(nx);
    i=-1;
  }
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<=n;i++)in[i].clear(),used[i]=0;

    ans=1;
    for(int i=0,a,b;i<m;i++){
      cin>>a>>b;
      in[a].push_back(P(b,in[b].size()));
      in[b].push_back(P(a,in[a].size()-1));
      if(in[a].size()/3||in[b].size()/3) ans=0;
    }
    
    for(int i=1;i<=n;i++) check(i);
    cout <<(ans? "yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 32828
S = input()
a = 0
b = 0
c = 0
for i in S:
    if i == 'a':
        a += 1
    elif i == 'b':
        b += 1
    elif i == 'c':
        c +=1
smin = min(a,b,c)
smax = max(a,b,c)
if smax - smin > 1:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 39536
/*s1190073  Rina Sato
  File name: prog9a.c
  This is a heap program.
*/

#include <stdio.h>
#include <stdlib.h>

#define MAX 250

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

struct Node T[MAX];

int Parent(int i){
  return i/2;
}
int Left(int i){
  return 2*i;
}
int Right(int i){
  return 2*i+1;
}

int main(void){
  int heap_size,i,key[MAX],left[MAX],right[MAX];

  scanf("%d",&heap_size);

  for(i = 1 ; i <= heap_size ; i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }

  for(i = 1 ; i <= heap_size ; i++){
    scanf("%d",&key[i]);
  }
  
  for(i = 1 ; i <= heap_size ; i++){
    if(i > 1){
      T[i].p = key[Parent(i)];
    } 
    
    left[i] = Left(i);
    if(left[i] <= heap_size){
      T[i].l = key[left[i]]; 
    }
    
    right[i] = Right(i);
    if(right[i] <= heap_size){
      T[i].r = key[right[i]];
    } 
  }
  
  for(i = 1 ; i <= heap_size ; i++){
    printf("node %d: key = %d, ",i,key[i]);
    
    if(i > 1){
      printf("parent key = %d, ",T[i].p);
    }
    if(left[i] <= heap_size){
      printf("left key = %d, ",T[i].l); 
    }
    if(right[i] <= heap_size){
      printf("right key = %d, ",T[i].r);
    } 
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
arr = []
p = 1
c = 0
l = 0
a = list(map(int,input().strip().split()))[:n] 

for i in range(n):
    if a[i]==0:
        c = 1
    if p > 1000000000000000000:  
        l = 1
    else:    
        p *= a[i]
if c == 1:
    print(0)
elif l == 1 or p > 1000000000000000000 :
    print(-1)
else:
    print(p)


Measured memory_bytes: 21620
#include<stdio.h>

int a[100001],b[50001];

int main(void){

  int n,q,cnt=0,i,j;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&b[i]);

  for(i=0;i<q;i++){
    int l=0,r=n;
    while(r-l>1){
      int m=(l+r)/2;
      if(a[m] > b[i])r=m;
      else l=m;
    }
    cnt+=(a[l]==b[i] || a[r]==b[i]);
  }

  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
	int h, w;
	cin >> h >> w;
	for(int i=0;i<h;i++){
		string input;
		cin >> input;
		cout << input << endl;
		cout << input << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    int b = a + a*a + a*a*a;
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    int x = 0, y = 0;
    rep(i,s.size()){
        if(s[i] == '0') x++;
        if(s[i] == '1') y++;
    }
    cout << 2*(x>y?y:x) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define Values ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modvalue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modvalue);ll total = ((ans % modvalue) * (ans % modvalue)) % modvalue;  if(pow % 2 == 0) return total; else{ return (total * (base % modvalue) ) % modvalue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(long ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{	
	ld d,t,s;
	cin>>d>>t>>s;
	ld tt=d/s;
	if(tt <= t)cout<<"Yes";
	else cout<<"No";
}


int main()
{

#ifndef ONLINE_JUDGE
	freopen("C:/Users/91731/Documents/input.txt", "r", stdin);
	freopen("C:/Users/91731/Documents/output.txt", "w", stdout);
	freopen("C:/Users/91731/Documents/error.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	solve();
}


Measured memory_bytes: 3716