akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,v,w,t;
  cin >> a>>v>>b>>w>>t;
  ll V, D;
  D = max(a-b, b-a);
  if((v-w)*t >= D) cout << "YES\n";
  else cout << "NO\n";


  return 0;
}


Measured memory_bytes: 3104
x = int(input())

if 400 <= x < 600:
  ans = 8
elif 600 <= x < 800:
  ans = 7  
elif 800 <= x < 1000:
  ans = 6  
elif 1000 <= x < 1200:
  ans = 5  
elif 1200 <= x < 1400:
  ans = 4  
elif 1400 <= x < 1600:
  ans = 3  
elif 1600 <= x < 1800:
  ans = 2  
elif 1800 <= x < 2000:
  ans = 1  

print(ans)

Measured memory_bytes: 9208
#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 3e3 + 10;

int n, a[N];
long f[N][N];

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

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

    for (int r = 1; r <= n; ++r)
        for (int l = r; l > 0; --l)
            f[l][r] = max(a[l] - f[l + 1][r], a[r] - f[l][r - 1]);

    cout << f[1][n];

    return 0;
}


Measured memory_bytes: 70144
// {{{ Template for Competitive Programming
// -std=c++14 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

using vint = vector<int>;
using pint = pair<int, int>;

#define int long long
#define FOR(i, a, b)  for (int(i) = (a); (i) < (b); ++(i))
#define CFOR(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
#define rep(i, n) FOR((i), 0, (n))
#define crep(i, n) CFOR((i), 0, (n))
#define rrep(i, n) RFOR((i), (n), 0)
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(ALL(x), 0)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline void debug(T a) { cout << "[ "; for (const auto e : a) { cout << e << ", "; } cout << "]" << endl; }

int ceil(int a, int b) { return (a + (b - 1)) / b; }

const int INF = 1'010'000'000'000'000'017LL;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// }}}

signed main() {
	int a, b;
	cin >> a >> b;
	if (b * 2 > a) cout << 0 << endl;
	else cout << a - b * 2 << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}







int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    int mxa(0);
    for(int i(0); i < N; ++i){
        std::cin >> A[i];
        chmax(mxa, A[i]);
    }
    std::sort(std::begin(A), std::end(A));
    std::vector<bool> okay(mxa + 1, true), has(mxa + 1, false);
    for(int i(0); i < N; ++i){
        if(has[A[i]]) okay[A[i]] = false;
        if(okay[A[i]]){
            for(int j(2*A[i]); j <= mxa; j += A[i]){
                okay[j] = false;
            }
            has[A[i]] = true;
        }
    }
    int ans(0);
    for(int i(0); i < N; ++i) if(okay[A[i]]) ++ans;
    std::cout << ans << std::endl;
    return 0;
}


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

int main() 
{
	int i,n;
	scanf("%d",&n);
	int a[n];
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		
	}
	for(i=1;i<=n;i++){
	printf("node %d: key = %d, ",i,a[i]);
	if(i/2>0) printf("parent key = %d, ",a[i/2]);
	if(i*2<=n) printf("left key = %d, ",a[i*2]);
	if(i*2+1<=n) printf("right key = %d, ",a[i*2+1]);
	printf("\n");
    }
	return 0;
}



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

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

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

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

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

int n, choco;
int inp[N];

int main(){
    fastScan(n); fastScan(choco);
    for(int i = 1; i <= n; i++){
        fastScan(inp[i]);
    }
    sort(inp + 1, inp + n + 1);
    int ans = 0, st = 1;
    while(st <= n && (choco - inp[st]) >= 0){
        st++; choco -= inp[st - 1];
        ans++;
    }
    if(choco > 0 && st > n) ans--;
    printf("%d\n", max(ans, 0));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l,f,m,sum,t1;
     cin>>n;
      f=n/100;
      t1=n%100;
      l=t1%10;
      m=t1/10;
      if(l==7||m==7||f==7){
            cout<<"Yes"<<endl;}

     else cout<<"No"<<endl;}




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

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, p;
    
    scanf("%d%d", &a, &p);
    
    printf("%d", (3*a+p)/2);
    
    return 0;
}



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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e6) + 17;

int n;
int a[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, 3 * n)
        cin >> a[i];

    return true;
}

void solve() {
    sort(a, a + 3 * n);
    ll ans = 0;

    forn (i, n)
        ans += a[3 * n - 2 * (i + 1)];

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

using namespace std;

int main()
{
    int a[3], k=0;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if (a[0]%2==a[1]%2 && a[1]%2==a[2]%2) k=(a[2]-a[0]+a[2]-a[1])/2;
    if (a[0]%2!=a[1]%2 && a[1]%2==a[2]%2)
    {
        a[1]++;
        a[2]++;
        k=1+(a[2]*2-a[0]-a[1])/2;
    }
    if (a[1]%2!=a[2]%2 && a[2]%2==a[0]%2)
    {
        a[0]++;
        a[2]++;
        k=1+(a[2]*2-a[0]-a[1])/2;
    }
    if (a[0]%2!=a[2]%2 && a[0]%2==a[1]%2)
    {
        a[0]++;
        a[1]++;
        k=1+(a[2]*2-a[0]-a[1])/2;
    }

    cout<<k<<endl;
    return 0;
}


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

int find_sumation_individual_digits(int n){
    int sum = 0;
    while(n > 0){
        sum = sum + (n % 10);
        n = n / 10;
    }
    return sum;
}

int main() {
    int N ;
    cin >> N ;
    int f_N = find_sumation_individual_digits(N) ;
    if( (N % f_N) == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
//43
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  int x=1;
  for(int i=1;i<=22222;i++){
    if(abs(n-x)>abs(n-i)){
      stringstream ss;
      ss<<i;
      string s;
      ss>>s;
      if(s==string(s.rbegin(),s.rend())){
	x=i;
      }
    }
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 1224
import unittest


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(8, [[3, 30], [4, 50], [5, 60]]),
            90
        )

    def test_2(self):
        self.assertEqual(
            think(1000000000, [[1000000000, 10]]),
            10
        )

    def test_3(self):
        self.assertEqual(
            think(15, [[6, 5], [5, 6], [6, 4], [6, 6], [3, 5], [7, 2]]),
            17
        )


def solve():
    w, list_of_w_and_v = read()
    result = think(w, list_of_w_and_v)
    write(result)


def read():
    n, w = read_int(2)
    list_of_w_and_v = []
    for _ in range(n):
        list_of_w_and_v.append(read_int(2))
    return w, list_of_w_and_v


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(w, list_of_w_and_v):
    w_max = 10 ** 9
    invalid = w_max + 1
    v_max = 10 ** 3
    n_max = 100

    # dp[value] = min weight at 'value'
    dp = [invalid for _ in range(v_max * n_max + 1)]
    dp[0] = 0

    for weight, value in list_of_w_and_v:
        for i in range(len(dp) - 1, -1, -1):
            if dp[i] == invalid:
                continue
            if i + value >= len(dp):
                continue
            dp[i + value] = min(
                    dp[i + value],
                    dp[i] + weight
            )

    for i in range(len(dp) - 1, -1, -1):
        if dp[i] == invalid:
            continue
        if dp[i] > w:
            continue
        return i


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 56556
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n;
long long ats, pr1, pr2;

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

    if (n == 0) {
        cout << 2 << endl;
    } else if (n == 1) {
        cout << 1 << endl;
    } else {
        pr1 = 2;
        pr2 = 1;
        for (int i = 1; i < n; i++) {
            ats = pr1 + pr2;
            pr1 = pr2;
            pr2 = ats;
        }
        cout << ats << endl;
    }
}


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

int main()
{
	int x, y;
	int t;

	for (;;) {
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0) break;
		if (x > y) t = x, x = y, y = t;
		printf("%d %d\n", x, y);
	}
	return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (f(x,y/2)*((x*f(x,y/2))%mod))%mod;
}
int64_t comb(int64_t x,int64_t y){
int64_t ans=1;
  for(int64_t i=y;1<=i;i--){
  ans=(f(i,mod-2)*((ans*(x-y+i))%mod))%mod;
  }return ans;

}
int main(){
int64_t N,M;
  cin>>N>>M;
  int64_t m=M;
  vector<int64_t>A={};
  for(int64_t i=2;i*i<=m;i++){
  if(M%i==0){
    int64_t a=0;
    while(M%i==0){
    M/=i; a++;
    }A.push_back(a);
  
  }
  }if(M!=1)
    A.push_back(1);
  int L=A.size();
  int64_t ans=1;
  for(int i=0;i<L;i++){
    int64_t a=A.at(i);
    ans=(ans*comb(N-1+a,a))%mod;
  }cout<<ans<<endl;        
     return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;

  cin >> N;

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

  puts("No");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define all(v) (v).begin(),(v).end()
//int xx[]={0,1,0,-1,-1,-1,1,1,-1};int yy[]={1,0,-1,0,1,1,-1,-1}; //E S W N NE SE SW NW
int main() {
_
ll n;cin>>n;
ll h=3*n;
vector<ll> v;ll t;
while(h--){
    cin>>t;
    v.pb(t);
}
sort(v.rbegin(),v.rend());
ll ans=0;
for(int i=0;i<n;i++){
    ans=ans+v[(2*i+1)];
}
cout<<ans<<'\n';
return 0;
}


Measured memory_bytes: 6000
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int cnt[51];
int fie[51][51];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		cnt[f]++;
		cnt[t]++;
	}
	for(int i=0;i<n;i++){
		printf("%d\n",cnt[i]);
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
#define MAXN 330000
priority_queue<long long int, vector<long long int>, greater<long long int> > q_1;
priority_queue<long long int> q_2;
int main()
{
    int n;
    scanf("%d",&n);
    long long int rem_1[MAXN],rem_2[MAXN],num[MAXN];
    memset(rem_1, 0, sizeof(rem_1));
    memset(rem_2, 0, sizeof(rem_2));
    for(int i = 1; i <= 3*n; i++)
        scanf("%lld",&num[i]);
    long long int sum1=0,sum2=0;
    for(int i = 1; i <= n; i++)
    {
        sum1 += num[i];
        q_1.push(num[i]);
        rem_1[i] = sum1;
        sum2 += num[3*n+1-i];
        q_2.push(num[3*n+1-i]);
        rem_2[3*n+1-i] = sum2;
    }
    for(int i = n+1; i <= 2*n; i++)
    {
        long long int tem = q_1.top(); q_1.pop();
        sum1 = sum1 - tem + max(tem, num[i]);
        rem_1[i] = sum1;
        q_1.push(max(tem, num[i]));
    }
    for(int i = 2*n; i > n; i--)
    {
        long long int tem = q_2.top(); q_2.pop();
        sum2 = sum2 - tem + min(tem, num[i]);
        rem_2[i] = sum2;
        q_2.push(min(tem, num[i]));
    }
    long long int ans = -100020000000000;
    for(int i = n; i <= 2*n; i++)
        ans = max(ans, rem_1[i] - rem_2[i+1]);
    printf("%lld",ans);
    return 0;
}

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

using LL = long long;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for(auto& i: P) cin >> i, --i;

  struct Data {LL p, i; vector<LL> l, r;};
  vector<Data> X(N);
  for(auto i = 0; i < N; ++i) X[P[i]].p = P[i] + 1, X[P[i]].i = i;

  set<int> R;
  for(auto p: P) {
    set<int> remove;
    for(auto x: R) {
      if(p < x) break;
      if(X[x].r.size() == 2) remove.emplace(x);
      else                   X[x].r.emplace_back(X[p].i);
    }
    for(auto x: remove) R.erase(x);
    R.emplace(p);
  }
  for(auto& x: X) while(x.r.size() != 2) x.r.emplace_back(N);

  set<int> L;
  reverse(begin(P), end(P));
  for(auto p: P) {
    set<int> remove;
    for(auto x: L) {
      if(p < x) break;
      if(X[x].l.size() == 2) remove.emplace(x);
      else                   X[x].l.emplace_back(X[p].i);
    }
    for(auto x: remove) L.erase(x);
    L.emplace(p);
  }
  for(auto& x: X) while(x.l.size() != 2) x.l.emplace_back(-1);

  LL ans = 0;
  for(auto& x: X) {
    auto l1 = x.i - x.l[0];
    auto l2 = x.l[0] - x.l[1];
    auto r1 = x.r[0] - x.i;
    auto r2 = x.r[1] - x.r[0];
    auto d =  l1 * r2 + l2 * r1;
    ans += x.p * d;
  }
  cout << ans << endl;
}


Measured memory_bytes: 17536
#include <stdio.h>

int fib(int n, int *f) {
  // printf(">> f[%d] = %d\n", n, f[n]);
  if (n == 0 || n == 1) {
    return f[n] = 1;
  }
  if (f[n] != -1) {
    return f[n];
  }
  
  return f[n] = (fib(n - 2, f) + fib(n - 1, f));
}

int main() {
  int n, f[45];
  int i;

  scanf("%d", &n);

  for (i = 0; i <= n; i++) {
    f[i] = -1;
  }

  printf("%d\n", fib(n, f));
}



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

int main() {
	int N;
  int countB=0;
  int countA=0;
  int countAB=0;
  int countAABB=0;//AmoBmoaruyatu
  int siz;
  cin >> N;
  for (int i = 0; i<N; i++){
    string S;
  cin >> S;
    siz = S.size();
    if(S.at(0)=='B' && S.at( siz - 1)=='A'){
      countAABB++;
    }
    else if (S.at(0)=='B'){
      countB++;
    }
    else if(S.at( siz - 1)=='A'){
      countA++;
    }
    for( int j=0; j< (siz - 1);j++){
     if(S.at(j)=='A' && S.at(j+1)=='B'){
       countAB++;
     }
    }
  
  }
int mi;
  int ans;
  mi= min(countA,countB);
  int ma;
  ma= max(countA,countB);
  if ( countAABB==0){
  ans = mi + countAB;
}
  else{
    if (ma==0){
    ans = (countAABB + countAB - 1);     
    }
    else {
      ans = (countAABB + mi + countAB);
    }
        
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int W, H, N, x, y, a, i;
	scanf("%d %d %d", &W, &H, &N);
	
	int upper = H, under = 0, right = W, left = 0;
	
	for(i = 0; i < N; i ++){
		scanf("%d %d %d", &x, &y, &a);
		switch( a ){
		case 1:
			if(left < x){
				left = x;
			}
			break;
		case 2:
			if(x < right){
				right = x;
			}
			break;
		case 3:
			if(under < y){
				under = y;
			}
			break;
		case 4:
			if(y < upper){
				upper = y;
			}
			break;
		}
		if(right <= left || upper <= under){
			printf("0\n");
			return 0;
		}
		
	}
	printf("%d\n", (upper - under) * (right - left));
	return 0;
}

Measured memory_bytes: 128
#define NDEBUG
//http://arc079.contest.atcoder.jp/tasks/arc079_b
//D - Decrease (Contestant ver.)
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <bitset>
#include <list>
#include <utility>
#include <cassert>

#ifndef NDEBUG
#define SHOW(x)  cout<<#x<<": "<<(x)<<endl
#define SPLIT(x) cout<<"=========== " << (x) << " =========="<<endl
#else
#define SHOW(x)  ((void)0)
#define SPLIT(x)  ((void)0)
#endif

using namespace std;

const int MAXN = 50;
int64_t a[MAXN+20];
const int64_t MAXAI = 100000000001000;

void test(int n)
{
    //static int64_t b[MAXN+2];
    int pos = 1;
    for (int i=2; i<=n; ++i)
        if(a[i] > a[pos])
            pos = i;
    for (int i=1; i<=n; ++i)
        ++a[i];
    a[pos] -= n + 1;
}

int main()
{
    int64_t k;
    int64_t n;
    cin >> k;
    //for (int64_t t=0; t<MAXAI*40; ++t){
        //cout << "=========" << t << endl;
        //k = t;
    n = k / ( MAXAI - 51 ) + 1;
    if (n <= 2)
        n = 2;
    n = 50;
    int64_t repeat = k / n;
    int64_t r = k % n;

    SHOW(repeat);
    SHOW(k);
    SHOW(n);

    for (int i=1; i<=r; ++i)
        a[i] = repeat + n + n - r;
    for (int i=r+1; i<=n; ++i)
        a[i] = repeat + n - r - 1;

    cout << n << endl;
    for (int i=1; i<n; ++i)
        cout << a[i] << ' ';
    cout << a[n] << endl;

#ifndef NDEBUG
    SPLIT("test");
    for (int i=0; i < k; ++i)
        test(n);
    for (int i=1; i<n; ++i)
        cout << a[i] << ' ';
    cout << a[n] << endl;
#endif

    //}


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int sum = 0;
    vec<int> mi(N),D(N);
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        int d = 0;
        for(auto& c:S){
            d += (c=='('? 1:-1);
            mi[i] = min(mi[i],d);
        }
        sum += d;
        D[i] = d;
    }
    if(sum){
        cout << "No\n";
        return 0;
    }
    vec<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int i,int j){
        if((ll) D[i]*D[j]<0) return D[i]>D[j];
        else if(D[i]>=0 && D[j]>=0) return mi[i]>mi[j];
        else return D[i]-mi[i]>D[j]-mi[j];
    });
    int now = 0;
    for(auto& i:idx){
        if(now+mi[i]<0){
            cout << "No\n";
            return 0;
        }
        now += D[i];
        if(now<0){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int w;
char out[] = "-0+";
bool dfs(int n, int mul) {
    if (n == w) {
        return true;
    }

    if (mul > 3 * w) {
        return false;
    }

    REP(sign, -1, 2) {
        bool res = dfs(n + sign * mul, 3 * mul);
        if (res) {
            cout << out[sign + 1];
            return true;
        }
    }
    return false;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> w;
    dfs(0, 1);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3220
s = input()
li = [[1, 1, 0, 0], [0, 0, 1, 1], [1, 1, 1, 1]]

direction = [0] * 4

for i in s:
    if i == 'N':
        direction[0] = 1
    elif i == 'S':
        direction[1] = 1
    elif i == 'W':
        direction[2] = 1
    else:
        direction[3] = 1

if direction in li:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9144
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n;
set<string> st;
set<string> cd[20];
string d[]={"aaaaaaaaaa","aaaaaaaaab","aaaaaaaabc","aaaaaaabcd","aaaaaabcde","aaaaabcdef","aaaabcdefg","aaabcdefgh","aabcdefghi","abcdfghij"};
void dfs(string s,int x,int mx){
	if(x==n){st.insert(s);return;}
	rep(i,x){
		if(cd[x].count(s+s[i]))continue;
		cd[x].insert(s+s[i]);
		dfs(s+s[i],x+1,mx);
	}
	cd[x].insert(s+char('a'+mx+1));
	dfs(s+char('a'+mx+1),x+1,mx+1);
}
void Put(const string& s){
	rep(i,sz(s)){
		putchar(s[i]);
	}
	putchar('\n');
}
int main(int argc,char** argv){
	
	cin>>n;
	dfs("a",1,0);
	foreach(it,st)Put(*it);
	return 0;
}

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

int main(){
    long int n;
  scanf("%ld",&n);
  
  long int sum=0;
 for(long int i=0;i<n+1;i++){
   if(i%3!=0&&i%5!=0){
     sum+=i;
   }
 }
  printf("%ld",sum);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int x,y;
    cin>>x>>y;
    int ans=0;
    if(x==1)ans+=300000;
    if(x==2)ans+=200000;
    if(x==3)ans+=100000;
    if(y==1)ans+=300000;
    if(y==2)ans+=200000;
    if(y==3)ans+=100000;
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
}

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

int main() {
  int n,cnt = 0;
  string s;
  cin >> n >> s;
  vector<bool>seen0(10,false);
  rep(i,0,s.size()-2){
    if(seen0[s[i]-'0']) continue;
    seen0[s[i]-'0'] = true;
    vector<bool>seen1(10,false);
    rep(j,i+1,s.size()-1){
      if(seen1[s[j]-'0']) continue;
      seen1[s[j]-'0'] = true;
      vector<bool>seen2(10,false);
      rep(k,j+1,s.size()){
        if(seen2[s[k]-'0']) continue;
        seen2[s[k]-'0'] = true;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
	string str;
	while(cin >> str && str != "0") {
		int len = str.length(), sum = 0;
		for(int i = 0; i < len; i++) sum += str[i] - '0';
		cout << sum << '\n';
	}
	return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
using namespace std;
int n, k, mn=2e9, h[100005];
int main() {
	int i;
	cin>>n>>k;
	for(i=0; i<n; i++) scanf("%d", &h[i]);
	sort(h, h+n);
	for(i=k-1; i<n; i++) mn = min(mn, h[i] - h[i-k+1]);
	cout<<mn;
	return 0;
}

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

int main() {
  int n,a=0,w=0,t=0,r=0;
  string s;
  cin >> n;
  
  
  for(int i=0;i<n;i++){
    cin >> s;
    if(s =="AC"){
      a++;
    }else if(s =="WA"){
	  w++;
    }else if(s =="TLE"){
	  t++;
    }else if(s =="RE"){
	  r++;
    }
  }
  
  cout << "AC x " << a << endl;
  cout << "WA x " << w << endl;
  cout << "TLE x " << t << endl;
  cout << "RE x " << r << endl;
      
  return 0;
}

Measured memory_bytes: 3628
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    M, N, m0, md, n0, nd = map(int, readline().split())

    S = [0]*(M+1)
    S[0] = mi = m0
    for i in range(1, M):
        S[i] = mi = (mi * 58 + md) % (N + 1)
    S.sort()
    for i in range(M):
        S[i+1] += S[i]

    T = [0]*(N+1)
    T[0] = ni = n0
    for i in range(1, N):
        T[i] = ni = (ni * 58 + nd) % (M + 1)
    T.sort()
    for i in range(N):
        T[i+1] += T[i]

    def gen():
        def calc(a, b):
            return (M - a)*(N - b) + S[a] + T[b]
        yield 10**18
        j = N
        for i in range(M+1):
            while j > 0 and calc(i, j) > calc(i, j-1):
                j -= 1
            yield calc(i, j)
    write("%d\n" % min(gen()))
solve()


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
vector<ll> a(55), p(55);

 
int main(){
  int n, m;
  cin >> n >> m;
  int b[m]={};
  for(int i=0; i<n; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int a;
      cin >> a;
      a--;
      b[a]++;
    }
  }
  int ans = 0;
  for(int i=0; i<m; i++){
    if(b[i]==n) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <climits>

using namespace std;

typedef pair<int, int> P;

int main() {
    int n, m; cin >> n >> m;
    vector<P> bridges;
    bridges.resize(m);
    for (int i = 0; i < m; ++i) {
        int l, r; cin >> l >> r;
        bridges[i] = P(l, r);
    }

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

    int ans = 0;
    int l = 0, r = 0;

    for (int i = 0; i < m; ++i) {
        if (bridges[i].first >= r) {
            ++ans;
            l = bridges[i].first;
            r = bridges[i].second;
            continue;
        }

        l = max(l, bridges[i].first);
        r = min(r, bridges[i].second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll cnt[66][2];

int main(void){
	int n,i,j;
	ll a,ans = 0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		for(j=0; j<60; ++j){
			add_mod(ans,(1ll<<j)%MOD*cnt[j][((a>>j)&1)^1]%MOD);
			++cnt[j][(a>>j)&1];
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	int ans = (a + b - 3) / (a - 1);
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.function.DoubleToLongFunction;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a == b && b == c) System.out.println(1);
		else if(a != b && a != c && b != c) System.out.println(3);
		else System.out.println(2);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
# 2019-11-16 14:51:41(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
import heapq

def main():
    # 10**5連勤とか超人すぎる
    n, m = [int(x) for x in sys.stdin.readline().split()]

    job_list = dict((i, list()) for i in range(1, m+1))
    for _ in range(n):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        if a <= m:
            job_list[a].append(b)
    
    schedule = [0 for _ in range(m+1)] # 当日は報酬0
    q = []
    for i in range(1, m+1):
        for reward in job_list[i]: # 期限i日前にできる仕事の報酬一覧をheqp queueに入れる
            heapq.heappush(q, -reward) 
            # あとで最大値を取り出すために-1かける(heappop()で取り出せるのは最小値)

        if q: # その日できる仕事が一つでもあれば
            # 報酬の最小値(マイナスなので元々の最大値)を取り出して-1をかけ、scheduleにいれる
            schedule[i] = -heapq.heappop(q) # 戻り値を返すと同時にq自体も変更している
        else: # できる仕事がなければ
            pass  # その日の報酬は0のまま

    print(sum(schedule))


if __name__ == "__main__":
    main()


Measured memory_bytes: 29924
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int h, w;
struct indata {
    int x, y;
};

int main() {
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w, '.'));
    vector<vector<int>> dp(h+1, vector<int>(w+1, -1));
    vector<int> dx; vector<int> dy;
    dx.push_back(1); dx.push_back(0);
    dy.push_back(0); dy.push_back(1);

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> s.at(i).at(j);
        }
    }

    if(s.at(0).at(0) == '#') dp.at(0).at(0) = 1;
    else dp.at(0).at(0) = 0;

    indata first; first.x = 0; first.y = 0;
    queue<indata> que;
    que.push(first);

    while(!que.empty()) {
        indata exe = que.front();
        que.pop();
        for(int i = 0; i < 2; ++i) {
            int nex = exe.x+dx.at(i);
            int ney = exe.y+dy.at(i);
            if(nex >= 0 && nex < w && ney >= 0 && ney < h) {
                if(s.at(exe.y).at(exe.x) == '#') {
                    if(dp[ney][nex] == -1 || dp[ney][nex] > dp[exe.y][exe.x]) {
                        if(dp[ney][nex] == -1) {
                            indata next;
                            next.x = nex; next.y = ney;
                            que.push(next);
                        }
                        dp[ney][nex] = dp[exe.y][exe.x];
                    }
                }else {
                    if(s.at(ney).at(nex) == '#') {
                        if(dp[ney][nex] == -1 || dp[ney][nex] > dp[exe.y][exe.x]+1) {
                            if(dp[ney][nex] == -1) {
                                indata next;
                                next.x = nex; next.y = ney;
                                que.push(next);
                            }
                            dp[ney][nex] = dp[exe.y][exe.x]+1;
                        }
                    }else {
                        if(dp[ney][nex] == -1 || dp[ney][nex] > dp[exe.y][exe.x]) {
                            if(dp[ney][nex] == -1) {
                                indata next;
                                next.x = nex; next.y = ney;
                                que.push(next);
                            }
                            dp[ney][nex] = dp[exe.y][exe.x];
                        }
                    }
                }
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    static ArrayList<Integer>[] rec;
    static int[] tar;
    static int A,B,C;
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(), B = sc.nextInt(), Q = sc.nextInt();
        TreeSet<Long> s = new TreeSet<>(), t = new TreeSet<>();
        for(int i=0;i<A;i++) s.add(sc.nextLong());
        for(int i=0;i<B;i++) t.add(sc.nextLong());
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            long x = sc.nextLong();
            long ans = Long.MAX_VALUE/10;
            // left-left
            Long sh = s.floor(x), te = t.floor(x);
            if(sh!=null&&te!=null) ans = Math.min(ans,x-Math.min(te,sh));
            //right-right
            sh = s.ceiling(x); te = t.ceiling(x);
            if(sh!=null&&te!=null) ans = Math.min(ans,Math.max(sh,te)-x);
            // left-right ceiling(x) >= x >= floor(x)
            sh = s.ceiling(x); te = t.floor(x);
            if(sh!=null&&te!=null) ans = Math.min(ans,Math.abs(te-sh)+Math.min(sh-x,x-te));
            sh = s.floor(x); te = t.ceiling(x);
            if(sh!=null&&te!=null) ans = Math.min(ans,Math.abs(te-sh)+Math.min(te-x,x-sh));
            out.println(ans);
        }
        out.flush();
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

int h, w, n;
char g[1000 + 5][1000 + 5];
int sx, sy;

bool check(int y, int x) {
    if (0 <= y && y < h && 0 <= x && x < w) {
        if (g[y][x] != 'X') return true;
    }
    return false;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> n;
    rep(i, h)rep(j, w) {
        cin >> g[i][j];
        if (g[i][j] == 'S') {
            sy = i;
            sx = j;
        }
    }
    int ans = 0;
    int dist[h][w] = {};
    bool visited[h][w] = {};
    int nowy = sy, nowx = sx;
    rep(i, n) {
        rep(i, h)rep(j, w) {
            dist[i][j] = INF;
            visited[i][j] = false;
        }
        queue<pair<int, int>> q;
        q.push({nowy, nowx});
        dist[nowy][nowx] = 0;
        visited[nowy][nowx] = true;
        while (q.size() != 0) {
            pair<int, int> now = q.front(); q.pop();
            rep(j, 4) {
                int ny = now.fi + dy4[j];
                int nx = now.se + dx4[j];
                if (!check(ny, nx) || visited[ny][nx]) continue;
                q.push({ny, nx});
                visited[ny][nx] = true;
                dist[ny][nx] = dist[now.fi][now.se] + 1;
                if (g[ny][nx] - '0' == i + 1) {
                    ans += dist[ny][nx];
                    nowy = ny;
                    nowx = nx;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main () {
  int A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K=0;
  cin >> K;
  cout << A[K-1];
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int i, j, k;
int m, n, coun, ans, jud = 1, s;
int town[11][11];
P start;
void dfs(int y, int x, int flag);

inline int bit(int n, int i) {
	return n | 1 << i;
}

inline bool bitj(int n, int i) {
	if (n & 1 << i )
		return false;
	else
		return true;
}
int main() {
	while (cin >> m >> n&& m && n) {
		ans = 0;
		coun = 1;
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= m; j++) {
				cin >> town[i][j];
				if (town[i][j] == 2) {
					start = make_pair(i, j);
					s = coun;
				}
				if (town[i][j]) {
					town[i][j] = coun;
					coun++;
				}
			}
		}
		jud = 1;
		for (i = 0; i < coun; i++) {
			jud *= 2;
		}
		dfs(start.first, start.second, 1 << s);
		cout << ans << endl;
	}
}
void dfs(int y, int x, int flag) {
	for (i = x + 1; i <= m; i++) {
		if (town[y][i] && bitj(flag, town[y][i])) {
			dfs(y, i, bit(flag, town[y][i]));
			break;
		}
		if (town[y][i] == s&&bit(flag, town[y][i]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = x - 1; i > 0; i--) {
		if (town[y][i] && bitj(flag, town[y][i])) {
			dfs(y, i, bit(flag, town[y][i]));
			break;
		}
		if (town[y][i] == s&&bit(flag, town[y][i]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = y + 1; i <= n; i++) {
		if (town[i][x] && bitj(flag, town[i][x])) {
			dfs(i, x, bit(flag, town[i][x]));
			break;
		}
		if (town[i][x] == s&&bit(flag, town[i][x]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = y - 1; i > 0; i--) {
		if (town[i][x] && bitj(flag, town[i][x])) {
			dfs(i, x, bit(flag, town[i][x]));
			break;
		}
		if (town[i][x] == s&&bit(flag, town[i][x]) == jud - 2) {
			ans++;
			break;
		}
	}
}

Measured memory_bytes: 1160
# tenka1-2017-beginnerC - 4/N
# exhaustive search
def main():
    N = int(input())
    for h in range(N // 4 + 1, 3501):
        for n in range(N * h // (4 * h - N) + 1, 3501):
            numerator = N * h * n
            denominator = 4 * h * n - N * n - N * h
            if denominator > 0 and numerator % denominator == 0:
                w = numerator // denominator
                print(h, n, w)
                return


if __name__ == "__main__":
    main()

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, A, B;
	
	cin >> N >> A >> B;
	
	if(A*N >= B)
		cout << B;
	else
		cout << A*N;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  int ans = 0;
  for(int i = 0;i < 4;i++){
    if(s.charAt(i) == '+')ans++;
    else ans--;
  }
  System.out.println(ans);
}}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m,r;
	cin>>n>>m>>r;
	int R[r];
	for(int i = 0; i<r; i++)
	{
		cin>>R[i];
		--R[i];
	}
	sort(R,R+r);
	ll sp[n][n];
	// memset(sp,0x3f,sizeof(sp));
	for(int i = 0; i<n; i++)
	{
		for(int j = 0; j<n; j++)
			sp[i][j] = (ll)1e12;
		sp[i][i] = 0;
	}
	for(int i= 0 ; i<m; i++)
	{
		ll j,k,l;
		cin>>j>>k>>l;
		--j,--k;
		sp[j][k] = min(sp[j][k],l);
		sp[k][j] = min(sp[k][j],l);
	}
	for(int k = 0; k<n; k++)
		for(int i = 0; i<n; i++)
			for(int j = 0; j<n; j++)
				sp[i][j] = min(sp[i][j],sp[i][k]+sp[k][j]);
	ll ans = 1e18, ans2 = 0;
	do
	{
		ans2 = 0;
		for(int j = 0; j<r-1; j++)
			ans2 += sp[R[j]][R[j+1]];
		ans = min(ans,ans2);
	}while(next_permutation(R,R+r));
  	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int N = 1e5+7;
vector< pair<int,int> > V[N];
int cmp( pair<int,int> p1, pair<int,int> p2 ) {
    return p1.first < p2.first;
}
string ans[N];
string generate_( int a, int b ) {
    b += 1;
    string tmp = "";
    while( a ) {
        tmp += a%10 + '0';
        a/=10;
    }
    reverse( tmp.begin(), tmp.end() );
    while( tmp.size() < 6 ) {
        tmp = '0' + tmp;
    }

    string tmp2 = "";
    while( b ) {
        tmp2 += b%10 + '0';
        b/=10;
    }
    reverse( tmp2.begin(), tmp2.end() );
    while( tmp2.size() < 6 ) {
        tmp2 = '0' + tmp2;
    }
    //cout<<tmp+tmp2<<endl;
    return tmp+tmp2;
}

int main() {
    int n, m;
    cin>>n>>m;
    for( int i = 0; i < m; ++i ) {
        int a, b;
        cin>>a>>b;
        V[a].push_back( make_pair(b,i) );
    }
    for( int i = 1; i <= n; ++i ) {
        sort( V[i].begin(), V[i].end(), cmp );
        for( int j = 0; j < V[i].size(); ++j ) {
            int id = V[i][j].second;
            ans[id] = generate_( i, j );
        }
    }
    for( int i = 0; i < m; ++i ) {
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 12416
N, K = map(int, input().split())

mod = 10**9+7
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

for i in range(1, K+1):
    v1 = comb(K-1, i-1)
    v2 = 0

    if i == 1:
        v2 = N-K+1
    else:
        for j in range(i-1, N-K+1):
            v2 += comb(j-1, i-2) * (N-K-j+1)
    print((v1*v2)%mod)

Measured memory_bytes: 3444