akhauriyash/Code-Regression huggingface dataset:
while True:
  try:
    n=input()
    cnt = 0
    for a in range(0,10):
      for b in range(0,10):
        for c in range(0,10):
          for d in range(0,10):
              if a + b + c + d == n:
                cnt+=1
    print cnt
  except:
    break

Measured memory_bytes: 6336
def dis(c1, c2):
    return abs(c1[0]-c2[0]) + abs(c1[1]-c2[1])

if __name__ == "__main__":
    nums = [int(num) for num in input().split()]
    N = nums[0]
    M = nums[1]
    students = []
    cps = []
    for i in range(N):
        coord = [int(num) for num in input().split()]
        students.append((coord[0], coord[1]))
    for i in range(M):
        coord = [int(num) for num in input().split()]
        cps.append((coord[0], coord[1]))

    cps2 = []
    for s in students:
        idx = -1
        d = 0
        for i, c in enumerate(cps):
            dd = dis(s, c)
            if idx == -1 or d > dd:
                idx = i
                d = dd
        cps2.append(idx+1)

    for c in cps2:
        print(c)

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

double dp[210][210], height[210][210];
signed main() {
    int N, M; cin >> N >> M;
    vector< vector< tuple<int, int> > > box(N);
    for(int i=0; i<N; i++) {
        int K; cin >> K;
        for(int k=0; k<K; k++) {
            int s, h; cin >> s >> h;
            box[i].emplace_back(s, h);
        }
    }

    fill(height[0], height[N+1], -1);
    for(int i=0; i<N; i++) {
        height[i][0] = 0;
        int X = box[i].size();
        int off_w = 0; double off_h = 0;
        for(int k=0; k<X; k++) {
            int s, h; tie(s, h) = box[i][k];
            for(int l=1; l<=s*h; l++) {
                off_w++;
                off_h += 1.0 / s;
                if(off_w > M) continue;
                height[i][off_w] = off_h;
            }
        }
    }

    for(int i=0; i<N; i++) {
        for(int j=0; j<=M; j++) {
            for(int k=0; j+k<=M; k++) {
                if(height[i][k] < 0) continue;
                chmax(dp[i+1][j+k], dp[i][j] + height[i][k]);
            }
        }
    }

    double ans = *max_element(dp[N], dp[N] + M + 1);
    printf("%.12f\n", ans);
    return 0;
}



Measured memory_bytes: 3924
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
int a[100005],ans[100005];
int main(){
	int n,i;
	int tmp;
	scanf("%d",&n);
	for(i=0;i<n;i++){
        scanf("%d",&a[i]);
	}
	for(i=0,tmp=a[0];i<n;i++){
        tmp=a[i]-tmp;
	}
	tmp=tmp+a[0];
	tmp=tmp/2;
	for(i=0;i<n;i++){
	    printf("%d ",tmp*2);
        tmp=a[i]-tmp;

	}
    return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include<cstring>
using namespace std;

int main()
{

    long long  x,y,z,w;
    cin>>x>>y>>z>>w;
    int ans=0;
    for(int i=0;i<=x;i++)
        for(int j=0;j<=y;j++)
        {
            if((w-(500*i+j*100))%50==0&&w-(500*i+j*100)>=0)
                if(z-(w-(500*i+j*100))/50>=0)
                 {
                    ans++;
                   // cout<<i<<" "<<j<<" "<<endl;
                 }
        }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=1<<18,mod=1e9+7;
int h,n,p[N],tag[N],ans,stk[N],top;
inline void travel2(CI x,int prod,CI opt)
{
	if (x==1) return; prod=1LL*prod*x%mod;
	if (opt) (tag[x]+=prod)%=mod; else (ans+=1LL*(x>>1)*tag[x^1]%mod*prod%mod)%=mod;
	travel2(x>>1,prod,opt);
}
inline void travel1(CI x,int prod,CI opt)
{
	prod=1LL*prod*x%mod;
	if (x>=n) return stk[++top]=n+p[x-n]-1,travel2(n+p[x-n]-1,prod,opt);
	travel1(x<<1,prod,opt); travel1(x<<1|1,prod,opt);
}
int main()
{
	RI i; for (scanf("%d",&h),n=1<<h-1,i=0;i<n;++i)
	scanf("%d",&p[i]); for (i=1;i<n;++i)
	{
		travel1(i<<1,i,1); travel1(i<<1|1,1,0);
		while (top) for (int x=stk[top--];x;x>>=1) tag[x]=0;
	}
	return printf("%d",ans),0;
}

Measured memory_bytes: 3796
#include <stdio.h>

int main() {
    int N, A[100], flag, change, count = 0;
    int i, j;
    
    scanf("%d", &N);
    
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    flag = 1;
    
    while (flag) {
        flag = 0;
        
        for (j = N - 1; j >= 1; j--) {
            if (A[j] < A[j - 1]) {
                change = A[j - 1];
                A[j - 1] = A [j];
                A[j] = change;
                
                count++;
                
                flag = 1;
            }
        }
    }
    
    for (i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        
        printf("%d", A[i]);
    }
    
    putchar('\n');
    
    printf("%d\n", count);
    
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define FOR(i, c) for(decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;

    ll ans = 0;
    REP(i, n) {
        ans += (i + 1) * (n - i);
    }

    vec<P> es;
    REP(i, n - 1) {
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        ll l = min(u, v);
        ll r = max(u, v);
        ans -= (l + 1) * (n - r);
    }
    cout << ans << en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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

int64_t divceil(int64_t a, int64_t b) {
    return a / b + (a > 0 && a % b ? 1 : 0);
}

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, K, x = 0;
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
    }
    int ans = divceil(N - 1, K - 1);
    cout << ans << endl;
    return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int a; cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3612
import scala.io.StdIn._
 
object Main {
  def main(args: Array[String]): Unit = {
    println(
      confirm(
        isHaiku(Helper.readToListInts)
      )
    )
  }
 
  def isHaiku(list: List[Int]) : Boolean =
    list.count(n => n == 5) == 2 && list.count(n => n == 7) == 1
 
  def confirm(isHaiku: Boolean): String = if (isHaiku) "YES" else "NO"
}
 
 
 
object Helper {
  def readToListInts: List[Int] = readLine.split(" ").map(_.toInt).toList
  def readToVectorInts: Vector[Int] = readLine.split(" ").map(_.toInt).toVector
}

Measured memory_bytes: 25412
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

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

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

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

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

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

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

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 26628
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const int N = 1000005;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 1e9+7;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(12);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here


//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

void solve()
{
    
    int n,m;
    cin>>n>>m;
    vector<int>adj[n+1];
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    queue<int>q;
    vector<array<int,2>>vec(n+1,{INF,INF});


    vec[1][0]=0;
    vec[1][1]=0;
    bool vis[n+1]={0};

    q.push(1);
    while(!q.empty()){
        int src = q.front();
        vis[src]=1;
        q.pop();
        for(auto j:adj[src]){
            if(vis[j]==1)continue;
            if(vec[j][1]>vec[src][1]+1){
                vec[j][0] = src;
                vec[j][1] = vec[src][1]+1;
                q.push(j);
            }
        }
    }

    for(int i=2;i<=n;i++){
        if(vec[i][0]==INF){
            cout<<"No\n";
        }
    }

    cout<<"Yes\n";

    for(int i=2;i<=n;i++){
        cout<<vec[i][0]<<"\n";
    }

    return;
}

Measured memory_bytes: 13928
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[3];
  scanf("%s", s);
  puts((s[0] == s[1] && s[1] == s[2] && s[2] == s[0]) ? "No" : "Yes");
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
  int xc = min(c,k);
  cout << xa - xc << endl;
  
}



Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

int gcd(int a, int b){
    while(b != 0) {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(void){
    int K;
    unsigned long long int res=0;
    std::cin >> K;

    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                res+=gcd(gcd(i,j),k);
            }
        }
    }
    std::cout << res << std::endl;

    return 0;
}

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

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

int lcm(int a,int b)
{
	return a/gcd(a,b)*b;
}

int main()
{
	int a,b;
	while(cin>>a>>b) {
		cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
# dream = list(reversed('dream'))
# dreamer = list(reversed('dreamer'))
# erase = list(reversed('erase'))
# eraser = list(reversed('eraser'))

# def check(string):
#   l = len(string)

#   if l == 0:
#     return True
  
#   if l < 5:
#     return False

#   if string[0:5] == dream:
#     return check(string[5:])
#   if l >= 7 and string[0:7] == dreamer:
#     return check(string[7:])
#   if string[0:5] == erase:
#     return check(string[5:])
#   if l >= 6 and string[0:6] == eraser:
#     return check(string[6:])
      
#   return False

# S = input()
# S = list(reversed(S))
# if check(S):
#   print("YES")
# else:
#   print("NO")

s = input()
 
while len(s) > 4:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        break
 
print('NO' if len(s) > 0 else 'YES')

Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k=map(int,input().split())
print(n-k+1)

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

using namespace std;

int main(void) {
    int n, mina = 1001, maxa = -1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mina = min(mina, a);
        maxa = max(maxa, a);
    }
    cout << maxa - mina << endl;

    return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
bool second_greater(const pii& left, const pii& right) {
    return left.second > right.second;
}
#endif


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

    int N; cin >> N;
    vi v(N); REP(i, N) cin >> v[i];

    bool same = true;
    REP(i,N-1) {
        if (v[i] != v[i+1]){
            same = false;
            break;
        }
    }
    if (same) {
        cout << N / 2 << endl;
        return 0;
    }

    const int VMAX = 100000;
    vi ho(VMAX + 1, 0), he(VMAX + 1, 0);
    REP(i,N) {
        if (i % 2 == 0) {
            ho[v[i]]++;
        } else {
            he[v[i]]++;
        }
    }

    vector<pii> mdO;
    FOR(i,1,VMAX+1) {
        if (0 < ho[i]) {
            mdO.push_back(pii(i, ho[i]));
        }
    }
    sort(mdO.begin(), mdO.end(), second_greater);

    vector<pii> mdE;
    FOR(i,1,VMAX+1) {
        if (0 < he[i]) {
            mdE.push_back(pii(i, he[i]));
        }
    }
    sort(mdE.begin(), mdE.end(), second_greater);

    int mo=mdO[0].first, me=mdE[0].first;

    int ans;
    if (mo==me){
        int mo2=mdO[1].first, me2=mdE[1].first;
        ans = min(N - ho[mo] - he[me2], N - ho[mo2] - he[me]);
    } else {
        ans = N - ho[mo] - he[me];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2552
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

H, N = MAP()
AB = [()]
for i in range(N):
    a, b = MAP()
    AB.append((a, b))

dp = list2d(N+1, 20007, INF)
dp[0][0] = 0
for i in range(1, N+1):
    a, b = AB[i]
    for j in range(20007):
        dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j-a >= 0:
            dp[i][j] = min(dp[i][j], dp[i-1][j-a] + b)
            dp[i][j] = min(dp[i][j], dp[i][j-a] + b)
print(min(dp[N][H:]))


Measured memory_bytes: 192280
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC064D();

#if 1
int main()
{
	ABC064D();
	fflush(stdout);
	return 0;
}
#endif

class RunLengthEnc {
public:
	class RLEData {
	public:
		char c = 0;
		int cnt = 0;
	};

	typedef std::vector<RLEData> RLEvec;

	void Exec(RLEvec& vRle, const char* str) {
		int sLen = strlen(str);

		char bfr = 0;
		RLEData ccnt;
		for (int i = 0; i < sLen; i++) {
			if (str[i] != bfr) {
				if (ccnt.c != 0) {
					vRle.push_back(ccnt);
				}
				ccnt.c = str[i];
				ccnt.cnt = 1;
			}
			else {
				ccnt.cnt++;
			}
			bfr = str[i];
		}
		if (ccnt.c != 0) {
			vRle.push_back(ccnt);
		}
	}
};

static void ABC064D()
{
	int N;
	getint(N);
	std::string orgs;
	std::cin >> orgs;
	
	RunLengthEnc rle;
	RunLengthEnc::RLEvec data;

	rle.Exec(data, orgs.c_str());

	int leftCount = 0,  addLeft = 0, addRight = 0;
	for (auto it = data.begin(); it != data.end(); it++) {
		if (it->c == '(') {
			leftCount += it->cnt;
		}
		else {
			leftCount -= it->cnt;
			if (leftCount < 0) {
				addLeft += std::abs(leftCount);
				leftCount = 0;
			}
		}
	}
	addRight = leftCount;

	for (int i = 0; i < addLeft; i++) {
		orgs.insert(orgs.begin(), '(');
	}
	for (int i = 0; i < addRight; i++) {
		orgs += ')';
	}
	printf("%s\n", orgs.c_str());
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[15][15];
int p[15];
int ans;
int main()
{
    int n,m,k;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>k;
        for(int j=1; j<=k; j++)
        {
            cin>>s[i][j];
        }
    }
    for(int i=1; i<=m; i++)
    {
        cin>>p[i];
    }
    for(int s0=0; s0<(1<<n); s0++)
    {
        int a=0;
        for(int i=1; i<=m; i++)
        {
            int num=0;
            for(int j=1; j<=n; j++)
            {
                if(s0&(1<<(s[i][j]-1)))
                    num++;
            }
            if(num%2==p[i])
                a++;
            else
                break;
        }
        if(a==m)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# INPUT
n,m = list(map(int, input().split()))

ac = 0
wa = 0
finished = [0] * (n + 1) 
q_wa = [0] * (n + 1)

for i in range(m):
    
    if len(finished) == n:
        break

    s = input().split()

    if finished[int(s[0])] == 0:
        if s[1] != "AC":
                q_wa[int(s[0])] += 1
        else:
                finished[int(s[0])] = 1
                ac = ac + 1
                wa = wa + q_wa[int(s[0])]

print("{0} {1}".format(ac,wa))

Measured memory_bytes: 4596
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 13:45:43 2019
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	ans := 0
	for _, n := range []int{1, 2, 4, 8, 16, 32, 64} {
		if n <= N {
			ans = n
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
def f(n, h, t):
    if 10*h + t > n:
        return 0
    return 1 + sum(f(n, 10*h+x, t) for x in range(10))

def solve(n):
    ans = 0
    for h in range(1,10):
        for t in range(1,10):
            # 一桁の特殊ケース
            s = int((h == t) and (h <= n))
            ans += (f(n, h, t) + s) * (f(n, t, h) + s)
    return ans

n = int(input())
print(solve(n))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s, t;
	cin >> s >> t;
	
	int n = s.size();
	bool yes = false;
	for(int i = 0; i < n; ++i) {
		if( s == t ) { 
			yes = true;
			break;
		}
		
		char c;
		c = s.back();
		s.pop_back();
		s.insert(s.begin(), c);
	}
	
	if( yes ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n],i,count=0;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  for(i=0;i<n-2;i++){
    if((s[i]<s[i+1] && s[i+1]<s[i+2]) || (s[i]>s[i+1] && s[i+2]<s[i+1])){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s1,s2,s3 string
	fmt.Scan(&s1,&s2,&s3)

	s1s := strings.Split(s1,"")
	s2s := strings.Split(s2,"")
	s3s := strings.Split(s3,"")

	fmt.Println(strings.ToUpper(s1s[0])+strings.ToUpper(s2s[0])+strings.ToUpper(s3s[0]))
}


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

int main() {
    int vid, att;
    scanf("%d %d", &vid, &att);
    
    if (vid%att ==0)
        printf("%d\n", (vid/att));
    else
        printf("%d\n", (vid/att)+1);
    return 0;
}


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

int n,x,a;

void pertition(int *A,int p,int r){
  int i,j,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++; 
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
      tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    a=i+1;
}

int main(void){
  int i;
  int *A;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  pertition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i==a) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  free(A);
  return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;

    int a[n][m] = {{0}};
    int count[m] = {0};

    for(int i = 0; i < n; i++){
        int k = 0;
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> a[i][j];
            count[a[i][j]-1] += 1;
        }
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        if(count[i] == n){
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
vector<vector<int>> A(4);
bool ans  = false;
void dfs(int v,vector<int> count,int p){
    count[v] = 1;
    bool flag = false;
    rep(i,4){
        if(count[i]!=1){
            flag = true;break;
        }
    }
    if(flag){
        for(auto nv:A[v]){
            if(nv==p) continue;
            dfs(nv,count,v);
        }
    }else{
        ans = true;
        return;
    }
}
int main(){
   
    rep(i,3){
        int a,b;cin >> a >> b;
        a--,b--;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    for(int i=0;i<4;i++){
        vector<int> count(4);
        dfs(i,count,-1);
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, t; cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < s.size(); i++) ans += (s[i] != t[i]);
	cout << ans;

	return 0;
}

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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, begin, end) for(int (i) = (begin); (i) < (end); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    string s;
    rep(i, 0, H) {
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[n+5];
	for(int i=1;i<=n;i++)  scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	cout<<a[n]-a[1]<<endl;
	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9;j++) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

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

long long int ans;
long long int MOD = 1000000007;

long long int fact(int n) {
    long long int res = 1;
    for (int i = 1; i <= n; i++) {
        res *= i;
        res %= MOD;
    }
    return res;
}

int main(void) {
    int n;
    scanf("%d", &n);

    printf("%lld\n", fact(n));
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    vector<pair<int, int> > A, B;
    for(int n=0; n<N; ++n) {
        int a;
        scanf("%d", &a);
        A.emplace_back(a, n);
    }
    for(int n=0; n<N; ++n) {
        int b;
        scanf("%d", &b);
        B.emplace_back(b, n);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int n=0; n<N; ++n) {
        if(B[n].first<A[n].first) {
            printf("No\n");
            return 0;
        }
    }
    for(int n=1; n<N; ++n) {
        if(A[n].first<=B[n-1].first) {
            printf("Yes\n");
            return 0;
        }
    }
    vector<int> Ans(N), Now(N);
    for(int n=0; n<N; ++n) {
        Now[n] = n;
        Ans[B[n].second] = A[n].second;
    }
    for(int n=0; n<N-1; ++n) {
        if(Now[n]==Ans[n]) {
            printf("Yes\n");
            return 0;
        }
        int ans = Ans[n];
        for(int i=n+1; i<N; ++i) {
            if(ans==Now[i]) {
                Now[i] = Now[n];
                break;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2548
H , W = map  ( int , input().strip().split(" ") ) ; 
s1 = (  H //2 + H %2 ) * ( W //2  + W %2 ) ;
s2 = (  H //2  ) * ( W //2 ) ;

if H == 1 or W == 1 :
	print ( 1 ) ;
else :
	print ( s1 + s2 ) ;

Measured memory_bytes: 3064
li = []
for i in range(5):
  li.append(int(input()))
mi = 1e10
ans = 0
for i in range(5):
  ans+=(li[i]//10+(li[i]%10!=0))*(10)
  mi = min(mi,li[i]%10+(li[i]%10==0)*10)
print(ans - 10 + mi)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
void min(int &x,int &y) {
    if (x > y){
    int z;
    z = y;
    y = x;
    x = z;
    }
}
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    min (a,c);
    min (a,b);
    min (b,c);
    cout << a << ' ' << b << ' ' << c << endl;
}


Measured memory_bytes: 3076
def dfs(v):
    if sum(visited) == N:
        return 1
    res = 0
    for nv in g[v]:
        if visited[nv]:
            continue
        visited[nv] = 1
        res += dfs(nv)
        visited[nv] = 0
    return res


N, M, *ab = map(int, open(0).read().split())
g = [[] for _ in range(N)]
for a, b in zip(*[iter(ab)] * 2):
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

visited = [0] * N
visited[0] = 1
print(dfs(0))


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) b[i] = i + 1;
  int cnt = 0;
  for(int i = 0; i < n; i++)
    if(a[i] != b[i]) cnt++;
  cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int n,q;
vector<char> field(200020);
vector<char> t(200020),d(200020);
int ans1=0,ans2=0;

bool isOk1(int now){
    int tmp=now;
    //cout<<now<<endl;
    REP(i,q){
        char ns=field[tmp];
        //cout<<tmp<<":"<<ns<<":"<<t[i]<<endl;
        if(ns==t[i]){
            if(d[i]=='L'){
                if(tmp-1<0){
                    ans1 = max(ans1,now+1);
                    return true;
                }
                else tmp--;
            }
            else tmp++;
        }
    }
    return false;
}
bool isOk2(int now){
    int tmp=now;
    //cout<<now<<endl;
    REP(i,q){
        char ns=field[tmp];
        //cout<<ns<<":"<<t[i]<<endl;
        if(ns==t[i]){
            if(d[i]=='R'){
                if(tmp+1>=n){
                    //cout<<"R:"<<n<<":"<<now<<endl;
                    ans2 = max(ans2,n-now);
                    return true;
                }
                else tmp++;
            }
            else tmp--;
            //cout<<tmp<<endl;
        }
    }
    return false;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>q;

    REP(i,n) cin>>field[i];
    //map<char,int> mp;
    //bool Left=false,Right=false;
    
    REP(i,q){
        cin>>t[i]>>d[i];
    }

    int l = -1;
    int r = n;
    while(r-l>1){
        int m=l + (r-l) / 2;
        //cout<<m<<endl;
        if(isOk1(m)) l=m;
        else r=m;
    }

    l = -1;
    r = n;
    while(r-l>1){
        int m=l + (r-l) / 2;
        //cout<<m<<endl;
        if(isOk2(m)) r=m;
        else l=m;
    }
    //cout<<ans1<<":"<<ans2<<endl;
    cout<<n-(ans1+ans2)<<endl;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length =  (a + b) * 2;
        System.out.println(area + " " + length);
        sc.close();
        }
}


Measured memory_bytes: 26348
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 300002
using namespace std;
struct SegmentTree{
	int dat,add;
}t[N*4];
struct point{
	int x,y;
}p[N];
int w,h,n,i,ans;
void build(int p,int l,int r)
{
	t[p].dat=t[p].add=0;
	if(l==r) return;
	int mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
}
void update(int p)
{
	t[p].dat=max(t[p*2].dat,t[p*2+1].dat);
}
void spread(int p)
{
	if(t[p].add){
		int tmp=t[p].add;
		t[p].add=0;
		t[p*2].dat+=tmp;t[p*2].add+=tmp;
		t[p*2+1].dat+=tmp;t[p*2+1].add+=tmp;
	}
}
void change(int p,int l,int r,int ql,int qr,int x)
{
	if(ql<=l&&r<=qr){
		t[p].dat+=x;
		t[p].add+=x;
		return;
	}
	int mid=(l+r)/2;
	spread(p);
	if(ql<=mid) change(p*2,l,mid,ql,qr,x);
	if(qr>mid) change(p*2+1,mid+1,r,ql,qr,x);
	update(p);
}
int my_comp(const point &a,const point &b)
{
	return a.x<b.x;
}
void solve()
{
	sort(p+1,p+n+1,my_comp);
	int s1[N],s2[N],top1=0,top2=0;
	s1[0]=s2[0]=1;
	build(1,1,n);
	change(1,1,n,1,n,h*2);
	for(int i=2;i<=n;i++){
		change(1,1,n,1,i-1,(p[i].x-p[i-1].x)*2);
		ans=max(ans,t[1].dat);
		if(p[i].y>=h/2){
			change(1,1,n,s1[top1],i-1,-(h-p[i].y)*2);
			while(top1&&p[s1[top1]].y>=p[i].y){
				change(1,1,n,s1[top1-1],s1[top1]-1,-(p[s1[top1]].y-p[i].y)*2);
				top1--;
			}
			s1[++top1]=i;
		}
		else{
			change(1,1,n,s2[top2],i-1,-p[i].y*2);
			while(top2&&p[s2[top2]].y<=p[i].y){
				change(1,1,n,s2[top2-1],s2[top2]-1,-(p[i].y-p[s2[top2]].y)*2);
				top2--;
			}
			s2[++top2]=i;
		}
	}
}
int main()
{
	cin>>w>>h>>n;
	for(i=2;i<=n+1;i++) cin>>p[i].x>>p[i].y;
	n+=2;
	p[n].x=w;p[n].y=h;
	solve();
	swap(w,h);
	for(i=1;i<=n;i++) swap(p[i].x,p[i].y);
	solve();
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13056
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
dp = [false]*(k+1) #trueならk個スタートで先手勝ち

1.upto(k) do |i|
  j = 0
  ans = false
  while !ans && j < n
    ans = true if (i-a[j]) >= 0 && !dp[i-a[j]]
    j += 1
  end
  dp[i] = ans
end
puts dp[k] ? "First" : "Second"

Measured memory_bytes: 2556
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;

int field[55][55], H, W, block;
int dh[] = { -1, 0, 1, 0};
int dw[] = { 0, 1, 0, -1};


int bfs() {
    int res = -1, cnt = 0;
    
    queue<pair<int,int>> pre, nxt;
    pre.push({1,1});
    
    while( !pre.empty() ) {
        pair<int,int> p = pre.front(); pre.pop();
        
        if ( p.first==H && p.second==W ) {
            res = cnt;
            break;
        }
        
        for ( int i=0; i<4; i++) {
            if ( field[p.first+dh[i]][p.second+dw[i]] == 1 ) {
                nxt.push({ p.first+dh[i], p.second+dw[i]});
                field[p.first+dh[i]][p.second+dw[i]] = 0;
            }
        }
        
        if ( !pre.empty()) continue;
        else {
            cnt++;
            swap( pre, nxt);
        }
    }
    return res;
}

int main() {
    cin >> H >> W;
    mem( field, 0);
    
    char c; block = 0;
    rep1( i, H)rep1( j, W) {
        cin >> c;
        if ( c=='.') field[i][j] = 1;
        else block++;
    }
    
    int cost = bfs();
    
    if ( cost == -1 ) {
        cout1(cost);
    } else {
        cout1( H*W - block - cost - 1);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;


int main(){
    ll N;
    string S;
    cin >> N >> S;
    ll x = 0;
    ll ans = 0;
    for (auto s:S){
        if (s=='I'){
            x++;
        }
        else
            x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
}


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

vector<ll> cnt;
vector<ll> pat;

ll rec(ll N,ll X){
  if(X==0) return 0;
  if(N==0&&X==1) return 1;
  X--;
  if (X <= cnt[N - 1]) return rec(N - 1, X);
  X-=cnt[N-1];
  if (X == 1) return pat[N-1]+1LL;
  X--;
  if (X <= cnt[N - 1]) return pat[N-1] + rec(N - 1, X) + 1;
  return pat[N];
}

int main() {
    ll N,X;
    cin >> N >> X;
    cnt.resize(N+1); cnt[0] = 1;
    pat.resize(N+1); pat[0] = 1;
    rep(i,N){
        cnt[i + 1] = 3LL + 2 * cnt[i];
        pat[i + 1] = 1LL + 2 * pat[i];
    }
    cout << (ll)rec(N,X) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(n, k) = sc.nextLine.split(" ").map(_.toInt)
    if (n == 1) println(k)
    else println((2 to n).foldLeft(k) {
      (acc, _) => acc * (k - 1)
    })
  }
}


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

int main(){
	double d,t,s;
	cin >> d >> t >> s;
	if(d/s > t) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 3720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		sc.close();
		
		int ans = 0;
		for(int i = 0;i <= K;++i) {
			for(int j = 0;j <= K;++j) {
				int res = S - i - j;
				if(0 <= res && res <= K)
					++ans;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	int N; cin >> N;
	if (N % 2 == 0) {
		int M = N * (N - 2) / 2;
		cout << M << endl;
		rep2(i, 1, N) {
			int gi = min(i, N + 1 - i);
			rep2(j, i + 1, N + 1) {
				int gj = min(j, N + 1 - j);
				db(gi); db(gj); dbl(int(gi != gj));
				if (gi != gj) {
					cout << i << " " << j << endl;
				}
			}
		}
	} else {
		int M = (N - 1) * (N - 1) / 2;
		cout << M << endl;
		rep2(i, 1, N) {
			int gi = min(i, N - i);
			rep2(j, i + 1, N + 1) {
				int gj = (j == N ? N : min(j, N - j));
				db(gi); db(gj); dbl(int(gi != gj));
			 if (gi != gj) {
				 cout << i << " " << j << endl;
			 }
		 }
	 }
 }
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256