akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
x = 0

for i in a:
  if i%2==1:
    continue
  elif i%3==0:
    continue
  elif i%5==0:
    continue
  else:
    print("DENIED")
    x = 1
    break
    
if x == 0:
  print("APPROVED")

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
using namespace std;
int dp[11][1<<17];
int n,d,x,M=1e5;
int p[11][11];
main()
{
	cin>>n>>d>>x;
	for(int i=0;i<d;i++)for(int j=0;j<n;j++)cin>>p[i][j];
	for(int i=0;i<=M;i++)dp[d-1][i]=i;
	for(int i=d-1;i--;)
	{
		for(int j=0;j<=M;j++)
		{
			dp[i][j]=j;
			for(int k=0;k<n;k++)
				if(p[i][k]<=j)
					dp[i][j]=max(dp[i][j],
							dp[i][j-p[i][k]]+p[i+1][k]);
		}
	}
	for(int i=0;i<d-1;i++)
	{
		x=dp[i][x];
	}
	cout<<x<<endl;
}



Measured memory_bytes: 7012
#include<queue>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> P;
struct edge{
    ll to;
    ll cost;
    ll en;
    edge(ll t, ll w,ll e) : to(t), cost(w) ,en(e){ }
};
int main(){
  vector<vector<edge> > g(60);
  ll i,j,n,m,s,u,V,a,b,c[60],d[60];
  ll ds[60][3010],ns[60][3010];
  const ll INF=1000000000000000;
  priority_queue<P,vector<P>,greater<P> > que;
  scanf("%lld %lld %lld\n",&n,&m,&s);
  for(i=0;i<m;i++){
    scanf("%lld %lld %lld %lld\n",&u,&V,&a,&b);
    u--,V--;
    g[u].push_back(edge(V,b,a));
    g[V].push_back(edge(u,b,a));
  }
  for(i=0;i<n;i++){
    scanf("%lld %lld\n",&c[i],&d[i]);
    if(c[i]>2800){
      c[i]=2800;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<3000;j++){
      ds[i][j]=INF,ns[i][j]=0;
    }
  }
  if(s>2800){
    s=2800;
  }
  ds[0][s]=0,ns[0][s]=1;
  que.push(make_pair(0,pll(0,s)));
  while(!que.empty()){
    P p=que.top();
    ll v=p.second.first,w=p.second.second;
    que.pop();
    for(i=0;i<g[v].size();i++){
      edge us=g[v][i];
      if(ds[us.to][w-us.en]>ds[v][w]+us.cost && ns[us.to][w-us.en]==0 && w-us.en>=0){
        ds[us.to][w-us.en]=ds[v][w]+us.cost;
        que.push(make_pair(ds[us.to][w-us.en],pll(us.to,w-us.en)));
      }
      if(w+c[v]<=2800 && ds[v][w+c[v]]>ds[v][w]+d[v] && ns[v][w+c[v]]==0){
        ds[v][w+c[v]]=ds[v][w]+d[v];
        que.push(make_pair(ds[v][w+c[v]],pll(v,w+c[v])));
      }
      if(w+c[v]>2800 && ds[v][2800]>ds[v][w]+d[v] && ns[v][2800]==0){
        ds[v][2800]=ds[v][w]+d[v];
        que.push(make_pair(ds[v][2800],pll(v,2800)));
      }
    }
    ns[v][w]=1;
  }
  for(i=1;i<n;i++){
    ll min=INF;
    for(j=0;j<3000;j++){
      if(min>ds[i][j]){
        min=ds[i][j];
      }
    }
    printf("%lld\n",min);
  }
  return 0;
}

Measured memory_bytes: 8808
#include<stdio.h>
 
int main(){
  int N, K, X, Y, accommodation;
  
  scanf("%d %d %d %d", &N, &K, &X, &Y);
  
  if(N <= K){
    accommodation = N*X;
  } else {
    accommodation = K*X + (N - K)*Y; 
  }
  
  printf("%d\n", accommodation);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 1000000007
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}
 
 

ll dp[3003][3003];
ll p[3003][3003];

int main(){
      sync;
      ll n;
      cin>>n;
      string s;
      cin>>s;
      
      dp[1][1]=1;
      p[1][1]=1;
      for(int i=2;i<=n;i++){
           for(int j=1;j<=i;j++){
               if(s[i-2]=='<'){
                    dp[i][j]=mod(dp[i][j]+p[i-1][j-1]);
               }
               else{
                    dp[i][j]=mod(MOD+dp[i][j]+(p[i-1][i-1]- p[i-1][j-1]));
               }
           }

           for(int j=1;j<=i;j++){
                p[i][j]=mod(p[i][j-1]+dp[i][j]);
           }
           
      }
         cout<<p[n][n]<<endl;
}

Measured memory_bytes: 139520
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
ll dp[201];
int main(){
  ll a;cin>>a;
  dp[0]=1;
  dp[1]=1;
  for(ll i=2;i<=a;i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  cout<<dp[a]<<endl;
}


Measured memory_bytes: 3092
import sys
from fractions import gcd

input = sys.stdin.buffer.readline

LARGE = 10 ** 9 + 7

def lcm(x, y):
    return (x * y) // gcd(x, y)

input()
A = list(map(int, input().split()))

l = 1
for a in A:
    l = lcm(l, a)

total = 0
for a in A:
    total += l // a

print(total % LARGE)


Measured memory_bytes: 5944
n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
c = gets.split(" ").map(&:to_i)
sum = b[a[0]-1]
n.times  do |i|
	if a[i+1] == a[i] + 1
		sum += (b[a[i+1]-1] + c[a[i]-1])
	else
		sum += b[a[i+1]-1]
	end
	i += 1
	if i == n-1
		break
	end
end
puts sum




Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n,Q; cin >> n >> Q;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    rep(i,Q){
        ll x; cin >> x;
        ll ans = 0;
        int right = 0;
        ll sum = 0;
        for(int left = 0; left < n; left++){
            while(right < n && sum + v[right] <= x){
                sum += v[right];
                right++;
            }
            ans += (right-left);

            if(right == left) right++;
            else sum -= v[left];
        }
        cout << ans << endl;
    }

    return 0;
}


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

int *check(char *str, int len, int *cnt) {
    int i, j = 0;
    int *list = (int*)malloc(len * sizeof(int));
    list[j] = 0; ++j;
    for(i = 1; i < len; ++i) {
        if(str[i-1] != str[i]) { list[j] = i; ++j; }
    }
    list[j] = i; ++j;
    *cnt = j;
    return list;
}

void solve(char *str, int len, int try) {
    int i, j, k, max = 1, tmp, cnt;
    int *list = check(str, len, &cnt);
    //for(i = 0; i < cnt; ++i) { printf("%d ", list[i]); }
    //printf("\n");
    for(i = 0; i < cnt-1; ++i) {
        j = list[i];
        if(str[j] == '0') {
            if( i + 2*try < cnt) {
                k = (list[i+2*try] < len) ? list[i+2*try] : len;
            }
            else { k = len; }
        } else {
            if( i + 2*try + 1 < cnt) {
                k = (list[i+2*try+1] < len) ? list[i+2*try+1] : len;
            }
            else { k = len; }
        }
        tmp = k - j;
        max = (max < tmp) ? tmp : max;
    }
    printf("%d\n", max);
    free(list);
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    char *str = (char*)malloc((n+4)*sizeof(char));
    scanf("%s", str);
    solve(str, n, k);
    free(str);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000001
#define epsilon 1e-6
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
class IO{
public:

    void read(vector<T> &a){ for(int i=0; i<a.size(); i++) cin >> a[i];}
    void read(vector<vector<T>> &a){
        for(int i=0; i<a.size(); i++)
            for(int j=0; j<a[i].size(); j++)
                cin >> a[i][j];
    }
    void print(vector<T> &a){ for(int i=0; i<a.size(); i++) cout << a[i] << ' '; }
    void print(vector<vector<T> > &a){
        for(int i=0; i<a.size(); i++){
            for(int j=0 ; j<a[i].size(); j++){
                cout << a[i][j] << ' ';
            }
        cout << '\n';
        }
    }
};

IO<int> io;

void solve(){
    int n, cnt = 0;
    cin >> n;
    vector<pair<int, int> > P(n);
    for(int i=0; i<n; i++){
        cin >> P[i].first >> P[i].second;
    }

    for(int i=0; i<n; i++){
        if(P[i].first == P[i].second){
            cnt++;
            if(cnt == 3){
                cout << "Yes";
                return;
            }
        }
        else cnt = 0;
    }
    cout << "No";
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
    #endif

    int t =1;

    while(t--){
        solve();
    }

    return 0;
}





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

int main(){
  int n,a=0;
  char c;
 cin >> n;
  r(i,n){
    cin >> c;
    if(c=='R')a++;
  }
  if(a>n-a)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void f(string& deck) {
  queue<char> q;
  rep(i, deck.size()) q.push(deck[i]);
  int m;
  cin >> m;
  rep(i, m) {
    int h;
    cin >> h;
    rep(j, h) {
      char c = q.front();
      q.pop();
      q.push(c);
    }
  }
  rep(i, deck.size()) {
    cout << q.front();
    q.pop();
  }
  cout << endl;
}

int main() {
  string deck;
  for (;;) {
    cin >> deck;
    if (deck == "-")
      return 0;
    f(deck);
  }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int p[100005];
int main()
{
  int n;
  cin >> n;
  n = n %10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    cout << "hon";
  else if(n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon";
  else if(n == 3)
    cout << "bon";

}


Measured memory_bytes: 3540
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    string s;
    cin >> s;
    ll n = s.size();

    vvl dp(n+1, vl(5));  // dp[i][j] : i文字目までで、"ABC"のj文字目までに丸をつける方法の数
    dp[0][0] = 1;
    rep(i, n) {
        exrep(j, 0, 3) {
            if(s[i] == '?') {
                dp[i+1][j] += 3*dp[i][j];
                dp[i+1][j+1] += dp[i][j];
            }
            else {
                dp[i+1][j] += dp[i][j];
                if(j < 3 && s[i] == "ABC"[j]) {
                    dp[i+1][j+1] += dp[i][j];
                }
            }
            dp[i+1][j] %= mod;
            dp[i+1][j+1] %= mod;
        }
    }

    out(dp[n][3]);
    re0;
}

Measured memory_bytes: 10364
// 改善版
#include <bits/stdc++.h>
using namespace std;

static const int MAX = 1001001;

// 閉路検出
vector<int> G[MAX], color(MAX, 0);
// main関数からこれらを削除すること

bool cycle(int u) {
  color[u] = 1; // GRAY
  bool ret;
  for(int i = 0; i < G[u].size(); i++){
    int v = G[u][i];
    if(color[v] == 1) return true;
    if(color[v] == 0) ret = cycle(v);
  }
  color[u] = 2; // BLACK
  return ret;
}

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> dist(MAX, 1e9);
// main関数からこれらを削除すること

int dfs(int u) {
  int keep = -1;
  for(int i = 0; i < G[u].size(); i++){
    int v = G[u][i];
    if(dist[v] != 1e9) keep = max(keep, dist[v]);
    else keep = max(keep, dfs(v));
  }
  if(keep == -1){
    dist[u] = 1;
    return 1;
  }
  else{
    dist[u] = keep + 1;
    return keep + 1;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<vector<int>> a(n, vector<int>(n - 1));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - 1; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  // vector<int> G[1001001]; // G:頂点数がnのグラフを表す隣接リスト
  
  for(int i = 0; i < n; i++){
    for(int j = 1; j < n - 1; j++){
      int w = i + 1, x = i + 1, y = a.at(i).at(j - 1), z = a.at(i).at(j);
      if(w > y) swap(w, y);
      if(x > z) swap(x, z);
      G[w * 1000 + y].emplace_back(x * 1000 + z);
    }
  }
  
  bool check;
  for(int i = 0; i < MAX; i++){
    if(color.at(i) == 0) check = cycle(i);
    if(check){
      cout << "-1\n";
      return 0;
    }
  }
  
  int ans = 0;
  for(int i = 0; i < MAX; i++){
    if(dist.at(i) == 1e9) ans = max(ans, dfs(i));
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 51200
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S; cin >> S;
    int N = SZ(S) + 1;

    vec a(N, 0);

    int c = 0;
    REP(i, N - 1){
        if(S[i] == '<') c++;
        else c = 0;
        Max(a[i + 1], c);
    }
    c = 0;
    IREP(i, N - 1){
        if(S[i] == '>') c++;
        else c = 0;
        Max(a[i], c);
    }
    int ans = 0;
    REP(i, N) ans += a[i];
    Out(ans);

    return 0;
}


Measured memory_bytes: 4764
n,k = map(int,input().split())
# lr = [list(map(int,input().split())) for i in range(k)]
# imos = [0]*(n+1)
lr = [list(map(int,input().split())) for i in range(k)]
# for i in lr:
#     l,r = map(int,input().split())
#     imos[l] += 1
#     imos[r+1] -= 1
# print(imos)
mod = 998244353
temp = 0
dp = [0]*(2*n)
dp[n] = 1
s = [0]*n + [1]*n
# print(dp)
for i in range(n+1,2*n):
    for j in lr:
        dp[i] += (s[i-j[0]]-s[i-j[1]-1]) % mod
    s[i] = (dp[i] + s[i-1]) % mod
#     print("dp",dp)
#     print("ss",s)
# print(s)
print(dp[n*2-1] % mod)


Measured memory_bytes: 78340
# ABC101 C - Minimization
# N <= K + (K-1)(g-1)を満たす最小のgが答え
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
g = 1
while True:
    if N <= K + (K-1)*(g-1):
        break
    else:
        g += 1
print(g)

Measured memory_bytes: 13812
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		char map[128];
		for(int i=0;i<128;i++)	map[i]=0;
		for(int i=0;i<n;i++){
			char a,b;	cin>>a>>b;
			map[a]=b;
		}
		int l;	cin>>l;
		for(int i=0;i<l;i++){
			char c;	cin>>c;
			cout<<(map[c]?map[c]:c);
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 856
#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 vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<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 range(i,a,n) for(int 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 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;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,s;
	ll ans=0;
	cin>>k>>s;
	rep(i,k+1){
		rep(j,k+1){
			if(0<=s-(i+j)&&s-(i+j)<=k)ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a, b, c, Sum = 0;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        for (int i= 0; i< b-a+1; i++){
                if(c%(a+i)==0){
                    Sum ++;
                }
        }
        System.out.println(Sum); 
    }
}


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

int main()
{
	string moji, kari, ushiro, mae; int a = -1;
	while (cin >> kari) {
		a++;
		char c = kari[0];
		if (isdigit(c)) {
			int number = stoi(kari);
			ushiro = moji.substr(number);
			mae = moji.substr(0, number);
			moji = ushiro + mae; //cout << moji << endl;
		}
		else {
			if (a) {
				cout << moji << endl;
			}
			if (kari == "-") {
				break;
			}
			else {

		int z; cin >> z;
			}
			moji = kari;
		}
	}
	return 0;
}

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

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    double mi = 1000000000;
    int idx = -1;

    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        double diff = abs(a - (t - h * 0.006));
        if (diff < mi) {
            mi = diff;
            idx = i + 1;
        }
    }
    cout << idx << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11

int main(int argc, char **argv)
{
    

    ll A, B, C, D;

    cin >> A >> B >> C >> D;

    bool tturn = true;
    while(A > 0 && C > 0) {
        if(tturn) {
            C-=B;
        }
        else {
            A-=D;
        }
        tturn = !tturn;
    }

    cout << (A > 0 ? "Yes" : "No") << endl;
}

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

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

class Item{
public:
	int n,c,s,g;
	Item(int n=0,int c=0,int s=0,int g=0):n(n),c(c),s(s),g(g){}
};

class State{
public:
	int x,y,cost,sum,visited;
	State(int x=0,int y=0,int c=0,int s=0,int v=0):x(x),y(y),cost(c),sum(s),visited(v){}
};

int main(){
	int h,w;
	while(cin >> w >> h && h && w){
		int a[20][20], n, ans = 0;
        bool G[20][20];
        int n_i[10]; //商品番号を配列の番号に変換
		bool f[20][20][(1<<8)];
		Item item[8];
		queue<State> Q;
		State u,v;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=0;k<(1<<8);k++) f[i][j][k] = false;

				char c;
				cin >> c;
				G[i][j] = true;
				a[i][j] = -1;
				if(c == '.') G[i][j] = false;
				else if(c == 'P'){
					u.y = i;
					u.x = j;
					f[i][j][0] = true;
					G[i][j] = false;
				} else a[i][j] = c - '0';
			}
		}

		cin >> n;
		for(int i=0;i<n;i++){
			cin >> item[i].n >> item[i].c >> item[i].s >> item[i].g;
            n_i[item[i].n] = i;
		}

		Q.push(u);
		while(!Q.empty()){
			u = Q.front();
			Q.pop();
            
			for(int i=0;i<4;i++){
				v = u;
				v.y += dy[i];
				v.x += dx[i];
				v.cost++;
				if(v.y >= 0 && v.y < h && v.x >= 0 && v.x < w && !f[v.y][v.x][v.visited]){
                    if(!G[v.y][v.x]){
                        f[v.y][v.x][v.visited] = true;
                        Q.push(v);
                    }
                    else if((v.visited & (1<<n_i[a[v.y][v.x]])) == 0){
                        if(u.cost >= item[n_i[a[v.y][v.x]]].s && u.cost < item[n_i[a[v.y][v.x]]].g){
                            State v2 = u;
                            //f[v2.y][v2.x][v2.visited] = true;
                            v2.visited = v2.visited | (1<<n_i[a[v.y][v.x]]);
                            f[v2.y][v2.x][v2.visited] = true;
                            v2.sum += item[n_i[a[v.y][v.x]]].c;
                            ans = max(ans,v2.sum);
                            if(v2.visited != ((1<<n)-1)) Q.push(v2);
                        } else if(u.cost < item[n_i[a[v.y][v.x]]].s){
                            //変更点
                            State v2 = u;
                            v2.cost += item[n_i[a[v.y][v.x]]].s - v2.cost;
                            Q.push(v2);
                            //ここまで
                        }
                    }
                }
            }
            
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main()
{
  finp;
  string s = "keyence";
  string t;
  cin>>t;
  int pref = 0;
  int suf = 0;
  int m = s.size();
  int n = t.size();
  afor(i,0,min(n,m)-1)
  {
    if(t[i] != s[i])break;
    pref++;
  }
  int pos = m-1;
  bfor(i,n-1,n-min(n,m))
  {
    if(t[i] != s[pos])break;
    pos--;
    suf++;
  }
  if(pref+suf >= m)cout<<"YES";
  else cout<<"NO";
return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

status = [0, 0, 0]
mod = 1000000007

ans = status.count(a[0])
status[0] += 1

for i in range(1, n):
    ans *= status.count(a[i])
    ans %= mod

    for j in range(len(status)):
        if status[j] == a[i]:
            status[j] += 1
            break

print(ans)



Measured memory_bytes: 20692
from collections import deque


def main(num_1, num_2, num_3):
    if (num_3 > num_1 and num_3 > num_2) or (num_3 < num_1 and num_3 < num_2):
        return 'No'
    else:
        return 'Yes'


if __name__ == "__main__":
    num_1, num_2, num_3 = list(map(int, input().split()))
    print(main(num_1, num_2, num_3))


Measured memory_bytes: 38256
/*
 * @Filename: 
 * @Author: shifaqiang
 * @Email: 14061115@buaa.edu.cn
 * @Github: https://github.com/luoboganer
 * @Date: 2020-07-12 00:38:24
 * @LastEditors: shifaqiang
 * @LastEditTime: 2020-07-12 23:30:58
 * @Software: Visual Studio Code
 * @Description: 
 */

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    int n, w, weight, value, ret = 0, total_values = 0;
    int max_values = 1e5; // 可能获得的最大价值
    int max_volumes = 1e9;
    cin >> n >> w;
    vector<long long> dp(max_values + 1, max_volumes); // dp[j]代表到i这个价值所需要的最小体积
    dp[0] = 0;                                         // initialization
    for (auto i = 0; i < n; i++)
    {
        cin >> weight >> value;
        total_values += value;
        for (auto j = max_values; j >= value; j--)
        {
            dp[j] = min(dp[j], dp[j - value] + weight);
            if (dp[j] <= w && j > ret && j <= total_values)
            {
                ret = j;
            }
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  if(a*12.5>=b*10){    
    if(b*10<=a*12.5 && a*12.5<(b+1)*10) dunk(ceil(a*12.5));
    else dunk(-1);
  }
  else{
    if(b*10>=a*12.5 && (a+1)*12.5>b*10) dunk(b*10);
    else dunk(-1);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long
 
using namespace std;
 
typedef pair<int, int> P;
 
int a, b;
int tmp;
char maze[84][53];
 
void black(int x, int y){
    if(tmp == 0) return;
 
    if(y == 41){
        y = 1;
        x += 2;
    }
 
    maze[y][x] = '#';
 
    --tmp;
    black(x, y+2);
}
 
void white(int x, int y){
    if(tmp == 0) return;
 
    if(y == 83){
        y = 43;
        x += 2;
    }
 
    maze[y][x] = '.';
 
    --tmp;
    white(x, y+2);
}
 
int main(){
    cin >> a >> b;
 
    for(int i=0;i<42;++i){
        for(int j=0;j<53;++j){
            maze[i][j] = '.';
        }
    }
    for(int i=42;i<84;++i){
        for(int j=0;j<53;++j){
            maze[i][j] = '#';
        }
    }
 
    if(b != 1){
        tmp = b - 1;
        black(1, 1);
    }
  	if(a != 1){
        tmp = a - 1;
        white(1, 43);
    }
 
    cout << 84 << " " << 53 << endl;
    REP(i, 84){
        REP(j, 53){
            cout << maze[i][j];
        }
        cout << endl;
    }
 
	return 0;
}

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

int main()
{
    int a[3];
    for (int i = 0; i < 3; i++)
    {
        cin >> a[i];
    }

    int result1 = abs(a[0] - a[1]) + abs(a[1] - a[2]);
    int result2 = abs(a[0] - a[2]) + abs(a[1] - a[2]);
    int result3 = abs(a[0] - a[1]) + abs(a[0] - a[2]);

    int r = result1;
    if (r > result2)
        r = result2;
    if (r > result3)
        r = result3;

    cout << r << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <numeric>
#include <time.h>
#include <stack>
#include <bitset>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)
 
using namespace std;
 
typedef long long ll;
typedef double dbl;
 
template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}
 
template<class T>   
void print(const T* s, int n){
    for (int i = 0; i < n; i++)
        cout << s[i] << ' ';
    cout << endl;
}

template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

ll gcd(ll a, ll b){
    return b > 0 ? gcd(b, a % b) : a;
}

int solve(){
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (abs(a - b) + w * t <= v * t)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed; 
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++){
        // cout << "Case #" << i + 1 << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3592
import copy

# input
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

# process
def f(l):
    if len(l) == 2:
        return [l, [l[1],l[0]]]

    result = []

    for i in l:
        l2 = copy.copy(l)
        l2.remove(i)
        for j in f(l2):
            result.append([i] + j)
    
    return result

l=[]
for i in range(1, N+1):
    l.append(i)

ll = f(l)

# output
print(abs(ll.index(P)-ll.index(Q)))


Measured memory_bytes: 10100
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

#define INF 1 << 29

typedef unsigned long long LL;

using namespace std;

LL calcSmallest(int w, int h) {
	LL answer1 = 1 << 29;
	if (h % 3 == 0) {
		return 0;
	}
	if (h > 3)
		answer1 = w;
	LL answer2 = 1000000000;
	bool flag = true;
	for (int i = 1; i < w; i++) {
		if (h % 2 == 0) {
			LL block1 = (LL)i*h;
			LL block2 = (LL)(w - i)*(h / 2);
			if (block1 > block2) {
				answer2 = min(answer2, (block1 - block2));
			}
			else {
				answer2 = min(answer2, (block2 - block1));
			}
		}
		else {
			LL block1 = i*h;
			LL block2 = (w - i)*(h / 2);
			LL block3 = (w - i)*((h / 2) + 1);
			LL smallest = min(block1, min(block2, block3));
			LL biggest = max(block1, max(block2, block3));
			answer2 = min(answer2, biggest - smallest);
		}
	}
	return min(answer1, answer2);
}

int main() {
	int H, W;
	cin >> H >> W;
	LL answer = min(calcSmallest(H, W), calcSmallest(W, H));
	cout << answer << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[N] = {};
    int B[N] = {};
    for (int i = 0;i < N;i++){
        cin >> A[i];
        B[A[i] - 1] = i + 1;
    }
    for (int i = 0;i < N - 1;i++){
        cout << B[i] << " ";
    }
    cout << B[N - 1] << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.1415926535

int main(){
	long a, b, C;
	cin >> a >> b >> C;
	double S, L, h;
	double radC;
	radC = PI / 180.0 * C;
	S = 0.5 * a * b * sin(radC);
	L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(radC));
	h = b * sin(radC);
	cout << fixed << S << endl << L << endl << h << endl;
	return 0;
}

Measured memory_bytes: 1240
import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
S = input()
Q = int(input())
k = list(map(int, input().split()))

DM_total = [(0,0,0)]
C_list = []

for i in range(N):
	if S[i] == "D":
		DM_total.append((DM_total[-1][0] + 1, DM_total[-1][1], DM_total[-1][2]))
	elif S[i] == "M":
		DM_total.append((DM_total[-1][0], DM_total[-1][1] + 1, DM_total[-1][2] + DM_total[-1][0]))
	else:
		DM_total.append(DM_total[-1])
	if S[i] == "C":
		C_list.append(i)

ans_list = [0]*Q
for q in range(Q):
	for c in C_list:
		if k[q] > c:
			ans_list[q] += DM_total[c + 1][2]
		else:
			ans_list[q] += DM_total[c + 1][2] - DM_total[c + 1 - k[q]][2]
			ans_list[q] -= DM_total[c + 1 - k[q]][0] * (DM_total[c + 1][1] - DM_total[c + 1 - k[q]][1])

for q in range(Q):
	print(ans_list[q])


Measured memory_bytes: 143060
/* ***************************************
Author        :Scau.ion
Created Time  :2017/10/22 19:58:09 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
	IOS;
	string s;
	cin>>s;
	if (s.find("AC") != string::npos) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,x[101],m,a[100],i,j,flg;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++)	scanf("%d",&x[i]);
	scanf("%d",&m);
	for(i=1;i<=m;i++)	scanf("%d",&a[i]);
	for(i=1;i<=m;i++){
		if(!(x[a[i]]+1==x[a[i]+1])){
			if(!(x[a[i]]+1>2019))	x[a[i]]++;
		}
	}
	for(i=1;i<=n;i++)	printf("%d\n",x[i]);
	return 0;
}



Measured memory_bytes: 2080
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;




int main() {
  int n;
  cin >> n;
  vi hon = {2, 4, 5, 7, 9};
  vi pon = {0, 1, 6, 8};
  vi bon = {3};

  n = n % 10;
  rep(i, hon.size()){
    if (hon[i] == n){
      cout << "hon" << endl;
      return 0;
    }
  }

  rep(i, pon.size()){
    if (pon[i] == n){
      cout << "pon" << endl;
      return 0;
    }
  }

  rep(i, bon.size()){
    if (bon[i] == n){
      cout << "bon" << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		System.out.println(n*(n-1)/2+m*(m-1)/2);
	}
}


Measured memory_bytes: 22868
import scala.collection.mutable._

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val n = sc.nextInt
	val a = Seq.fill(n)(sc.nextInt)
	
	pw.println(if (a.distinct.size == n) "YES" else "NO")
	pw.flush()
}

Measured memory_bytes: 75200
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, M = map(int, input().split())
    
    s = sum(list(map(int, input().split())))
    if s > N:
        print(-1)
    else:
        print(N - s)


if __name__ == '__main__':
    main()

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main()
{
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

    vvi path(10, vi(10, 0));
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        path[a][b] = path[b][a] = 1;
    }

    vi v(n-1);
    for(int i = 2; i <= n; ++i) {
        v[i-2] = i;
    }
    int ans = 0;
    do {
        bool comp = true;
        if(!path[1][v[0]]) continue;
        REP(i, n-2) {
            if(!path[v[i]][v[i+1]]) {
                comp = false;
                break;
            }
        }
        if(comp == true) {
            ++ans;
        }
    } while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
#include<math.h>
 int main()  {  	int a,b,c,d; 	 	scanf("%d%d%d%d",&a,&b,&c,&d);	if(b<c||d<a) 	printf("0"); 	else 		{ 	    if((a==0&&c!=0&&d>b)||(a<c&&b<d)) 		{ 				printf("%d",b-c); 				return 0; 				} 				if((c==0&&a!=0&&d<b)||(a>c&&b>d)) 		{ 			printf("%d",d-a); 			return 0; 			} 				if(a>c&&b<d) 	{ 				printf("%d",b-a); 			return 0; 		} 			if(c>a&&d<b) 			{ printf("%d",d-c); 			
	return 0; 				} 		if(a==0&&c==0) 			{ 			if(b<d) 		
	printf("%d",b); 				else 			printf("%d",d); 		return 0; 		} 			if(a==c&&b==d) 			{ 			printf("%d",b-a); 			return 0; 		} 		if(b==d) 		{ 			if(a<c) 			printf("%d",d-c); 			else 			printf("%d",b-a); 				return 0; 		} 									if(a==c) 		{ 	if(b>d) printf("%d",d-c); 					else 	printf("%d",b-a); 				return 0; 		} 			} 	return 0; }

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

int main()
{
    int a, b;
    cin>>a>>b;
    if(a==b)cout<<'a'<<" == "<<'b'<<endl;
    else if(a<b)cout<<'a'<<" < "<<'b'<<endl;
    else     cout<<'a'<<" > "<<'b'<<endl;
    return 0;
}


Measured memory_bytes: 3076
#include <algorithm>
#include <array>
#include <iostream>
#include <string>

const long mod = 1000000007;

int ctoi(char c) {
  return c - '0';
}

void update_counts(
    int n,
    const std::array<long, 13>& prev_counts,
    std::array<long, 13>& counts)
{
  for (int prev_rem = 0; prev_rem < 13; ++prev_rem) {
    const auto index = (prev_rem * 10 + n) % 13;
    counts[index] += prev_counts[prev_rem];
    counts[index] %= mod;
  }
}

long solve(const std::string& s)
{
  const auto len = static_cast<int>(s.size());
  std::array<std::array<long, 13>, 2> counts_array = {};

  if (s[0] == '?') {
    std::fill(counts_array[0].begin(), counts_array[0].begin() + 10, 1);
  } else {
    counts_array[0][ctoi(s[0])] = 1;
  }

  for (int i = 1; i < len; ++i) {
    const auto& prev_counts = counts_array[(i - 1) % 2];
    auto& counts = counts_array[i % 2];
    std::fill(counts.begin(), counts.end(), 0);
    if (s[i] == '?') {
      for (int j = 0; j <= 9; ++j) {
        update_counts(j, prev_counts, counts);
      }
    } else {
      update_counts(ctoi(s[i]), prev_counts, counts);
    }
  }

  return counts_array[(len - 1) % 2][5];
}

int main()
{
  std::string s;
  std::cin >> s;

  std::cout << solve(s) << std::endl;
}


Measured memory_bytes: 512
def collatz(n, count):
    if (n == 1) or (n == 2) or (n == 4):
        return count + 3
    elif n % 2:
        return collatz(3 * n + 1, count + 1)
    else:
        return collatz(n // 2, count + 1)

s = int(input())
print(collatz(s, 1))

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>

using namespace std;

int sum[600][600] = {};

int solve(){
  int h, w, n, m;

  memset(sum, 0, sizeof(sum));
  
  scanf("%d%d%d%d", &w, &h, &n, &m);

  if(!h)return false;
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      sum[i][j] = 1;

  int l = 0, u = 0;

  for(int i=0;i<n;i++){
    int d, c;

    scanf("%d%d", &d, &c);
    
    if(d == 1){
      c += l;
      for(int j=l;j<c;j++){
        for(int k=u;k<u+32;k++){
          sum[k][c+(c-j-1)] += sum[k][j];
          sum[k][j] = 0;
        }
      }
    }else{
      c += u;
      for(int j=u;j<c;j++){
        for(int k=l;k<l+32;k++){
          sum[c+(c-j-1)][k] += sum[j][k];
          sum[j][k] = 0;
        }
      }
    }

    int l2 = l, u2 = u;
    
    l = -1;
    for(int i=u2;i<u2+32;i++){
      for(int j=l2;j<l2+32;j++){
        if(sum[i][j]){
          l = j; u = i;
          break;
        }
      }
      if(l != -1) break;
    }
  }


  assert(l != -1);
  
  for(int i=0;i<m;i++){
    int x, y;

    scanf("%d%d", &x, &y);

    printf("%d\n", sum[y+u][x+l]);
  }

  return 1;
}

int main(){
  while(solve());
}



Measured memory_bytes: 4072
# https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_3_B
# この問題は前処理パートと、効率よく長方形の面積を求めるパートに分かれる。

from itertools import product, chain

# load data
H, W = list(map(int, input().split()))
C = []
for i in range(H):
    C.append(list(map(int, input().split())))


# まず、前処理を行う
# T (H,W) ... そのマスより上に何マスまで濡れるか
T = []
pre_tmp = [0] * W
for c in C:
    tmp = []
    for cc, pre in zip(c, pre_tmp):
        if cc == 1:
            tmp.append(0)
        else:
            tmp.append(pre + 1)
    T.append(tmp)
    pre_tmp = tmp.copy()


def get_largest_rectangle(hist: list):
    '''
    ヒストグラムが渡されたときに、その中の最大の長方形を返す
    '''
    hist = hist.copy()
    hist.append(0)
    ret = 0
    stack = []
    for i, v in enumerate(hist):
        # vが本で言うrectのこと
        if len(stack) == 0:
            stack.append((i, v))
        elif stack[-1][1] < v:
            stack.append((i, v))
        elif stack[-1][1] > v:
            while stack and stack[-1][1] > v:
                # スタックが空でなく、最後の要素がvより大きい限りは、
                # 面積の最大値を更新していく
                i_left, h = stack.pop()
                ret = max(ret, (i - i_left) * h)
            stack.append((i_left, v))
    return ret


# 各行について走査することで長方形の最大値を求める
ans = 0
for t in T:
    ans = max(ans, get_largest_rectangle(t))
print(ans)



Measured memory_bytes: 64068
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    pair<int,bool>NM[n+1];
    for(int i=1;i<=n;i++)
    {
        NM[i].first=0;
        NM[i].second=false;
    }
    for(int i=1;i<=m;i++)
    {
        int a;
        cin>>a;
        string x;
        cin>>x;
        if(x=="WA"&&NM[a].second==0){
            NM[a].first++;
        }else{
        NM[a].second=true;
        }
    }
    int AC=0,pen=0;
    for(int i=1;i<=n;i++)
    {
        if(NM[i].second){
            AC++;
            pen=pen+NM[i].first;
        }
    }
    cout<<AC<<" "<<pen;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  final int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 125644