akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int s, w;
  cin >> s >> w;
  if (w >= s) puts("unsafe");
  else puts("safe");
  return 0;
}

Measured memory_bytes: 3636
def insertionSort(A, n, g):
    cnt = 0
    for i in xrange(g, n):
        v = A[i]
        j = i - g
        while (j >= 0) and (A[j] > v):
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt

def shellSort(A, n):
    # variables
    cnt, m, t = 0, 1, n
    # getting m
    while (t-1)/3 > 0:
        t, m = (t-1)/3, m+1
    print m
    # creating and printing G
    G = [1]
    for i in xrange(1,m):
        G.append(1+G[i-1]*3)
    G = list(reversed(G))
    print " ".join( map(str, G) )
    # sorting
    for i in xrange(0, m):
        cnt += insertionSort(A, n, G[i])
    return cnt

# MAIN
n = input()
A = [input() for i in xrange(n)]
cnt = shellSort(A, n)
print cnt
for i in xrange(n):
    print A[i]

Measured memory_bytes: 38076
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int num = 0;
  while (true) {
    if (num++) cout << endl;
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    vector<string> v(h, string(w, '.'));
    v[0] = v[h - 1] = string(w, '#');
    rep(i, h) v[i][0] = v[i][w - 1] = '#';
    for (auto &x : v) cout << x << endl;
  }
}



Measured memory_bytes: 3148
#include <stdio.h>

long long A[101][101];
long long B[101][101];
long long C[101][101];

int main(void)
{
    int n, m, l;
    int i, j, k;

    scanf("%d%d%d", &n, &m, &l);
    for (i = 1; i <= n; i++){
        for (j = 1; j <= m; j++){
            scanf("%d", &A[i][j]);
        }
    }
    
    for (i = 1; i <= m; i++){
        for (j = 1; j <= l; j++){
            scanf("%d", &B[i][j]);
        }
    }

    for (i = 1; i <= n; i++){
        for (j = 1; j <= l; j++){
            for (k = 1; k <= m; k++){
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }

    for (i = 1; i <= n; i++){
        for (j = 1; j <= l; j++){
            if (j > 1){
                printf(" ");
            }
            printf("%ld", C[i][j]);
        }
        printf("\n");
    }

    return (0);
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;

int main() {

    char c[3][3];
    rep(i,3)std::cin >> c[i][0] >> c[i][1] >> c[i][2];
    std::cout << c[0][0] << c[1][1] << c[2][2];

    return 0;

}

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

int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}
void qsort(
  void *base, size_t num, size_t size,
  int (*compare)(const void *a, const void *b)
);

int main(void)
{
long N, A[200000], index;
  scanf("%ld", &N);
  for (index = 0; index < N; ++index) {
    scanf("%ld", &A[index]);
  }
  qsort(&A, N, sizeof(long), asc);
  for (index = 0; index < N; ++index) {
    if (index > 0) {
      if (A[index - 1] == A[index]) {
        break;
      }
    }
  }
  if (index == N) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n);
  map<int, LL> m;
  REP(i, 0, n) {
    cin >> a[i];
    m[a[i]]++;
  }
  VEC<LL> l(2,0);
  for (auto c : m) {
    if (c.second >= 4) {
      l.push_back(c.first);
      l.push_back(c.first);
    } else if (c.second >= 2) {
      l.push_back(c.first);
    }
  }
  sort(ALL(l), greater<int>());
  DUMP(l);
  cout << l[0] * l[1] << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (auto&& a : A) {
        cin >> a;
    }
    
    vector<ll> B(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        B[A[i]] = i;
    }
    
    ll ans = 0;
    set<ll> s;
    s.insert(-1);
    s.insert(N);
    for (ll a = 1; a <= N; a++) {
        auto p = s.lower_bound(B[a]);
        
        ll r = *p - B[a];
        p--;
        ll l = B[a] - *p;
        ans += a * l * r;
        
        s.insert(B[a]);
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using ll = long long;
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[4] == s[5] && s[2] == s[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
string s;
int ans;
int main()
{
	cin>>s;
	if(s.size()==1) {cout<<"0"; return 0;}
	for(int i=0;i<s.size();i++)
	if(s[i]>='A'&&s[i]<='Z') s[i]='a'+s[i]-'A';
	for(int i=0;i<=s.size()/2-1;i++)
	ans+=(s[i]!=s[s.size()-i-1]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
D = [0] + list(map(int, input().split()))
Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)]

candidates = []
for i in range(N+1):
  for j in range(i+1, N+1):
    di, dj = D[i], D[j]
    diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj)
    candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]])
    Diffs[i][j] = [diff1, diff2]

ans = 0
for idx1, idx2, diff, c in candidates:
  conditions = [-1] * (N+1)
  if c == 0:
    conditions[idx1] = conditions[idx2] = 0
  else:
    conditions[idx1] = 0; conditions[idx2] = 1
  res = True
  for i in range(N+1):
    for j in range(i+1, N+1):
      if idx1 == i and idx2 == j:
        continue
      diff1, diff2 = Diffs[i][j]
      if diff1 < diff and diff2 < diff:
        res = False
        break
      elif diff1 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = 0; conditions[j] = 1
        elif c1 < 0:
          conditions[i] = 1 - c2
        elif c2 < 0:
          conditions[j] = 1 - c1
        else:
          if c1 == c2:
            res = False
            break
      elif diff2 < diff:
        c1, c2 = conditions[i], conditions[j]
        if c1 < 0 and c2 < 0:
          conditions[i] = conditions[j] = 0
        elif c1 < 0:
          conditions[i] = c2
        elif c2 < 0:
          conditions[j] = c1
        else:
          if c1 != c2:
            res = False
            break
    else:
      continue
    break
  if res:
    ans = max(ans, diff)

print(ans)

Measured memory_bytes: 3572
S_a = str(input())
S_b = str(input())
S_c = str(input())

player = S_a[0]
S_a = S_a[1:]
winner = 'A'

while True:
    if player == 'a':
        if len(S_a) > 0:
            player = S_a[0]
            S_a = S_a[1:]
        elif len(S_a) == 0:
            winner = 'A'
            break
    elif player == 'b':
        if len(S_b) > 0:
            player = S_b[0]
            S_b = S_b[1:]
        elif len(S_b) == 0:
            winner = 'B'
            break
    elif player == 'c':
        if len(S_c) > 0:
            player = S_c[0]
            S_c = S_c[1:]
        elif len(S_c) == 0:
            winner = 'C'
            break

print(winner)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<string> words;
            for (int i=0;i<n;i++) {
                cin>>s;
                words.emplace_back(s);
            }
            for (int j=0;j<words.size();j++) {
                std::deque<int> num{5,7,5,7,7};
                int itr=0;
                int now=j;
                while (itr<5) {
                    if (words[now].size()<=num[itr]) {
                        num[itr]-=words[now].size();
                        if (num[itr]==0) {
                            itr++;
                            now++;
                        } else if (num[itr]>0) {
                            now++;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (itr==5) {
                    cout<<j+1<<endl;
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 3005;

int dp[MX][MX];

int main() {
  string s, t;
  cin>>s>>t;
  s += '$';
  t += '#';
  rep(i,sz(s))rep(j,sz(t)) {
    maxs(dp[i+1][j], dp[i][j]);
    maxs(dp[i][j+1], dp[i][j]);
    if (s[i] == t[j]) maxs(dp[i+1][j+1], dp[i][j]+1);
  }
  string ans;
  int i = sz(s)-1, j = sz(t)-1;
  while (i+j) {
    int x = dp[i][j];
    if (i && dp[i-1][j] == x) {
      i--;
    } else if (j && dp[i][j-1] == x) {
      j--;
    } else {
      i--; j--;
      ans += s[i];
    }
  }
  reverse(rng(ans));
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 35456
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int k, n; cin >> k >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  A.push_back(A[0]+k);
  n++;
  int max_ = 0;
  loop(i,0,n-1) max_ = max(max_, A[i+1]-A[i]);
  cout << k - max_ << endl;
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 3001;
const ll inf = 1e18;

int n,m,k;
ll dp[maxn][maxn][4];
ll g[maxn][maxn];


ll solve(int i, int j, int took) {
    if (took > 3) return -inf;
    if (i>=n || j>=m) return 0;
    if (~dp[i][j][took]) return dp[i][j][took];
    ll &res = dp[i][j][took] = 0;
    if (took<3) {
	res = max(res, g[i][j]+solve(i+1,j,0));
	res = max(res, g[i][j]+solve(i,j+1,took+1));
    }
    res = max(res, solve(i+1,j,0));
    res = max(res, solve(i,j+1,took));

    //cout<<i<<","<<j<<" "<<took<<": "<<res<<endl;
    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m>>k;

    while (k--) {
	int i,j,v;
	cin>>i>>j>>v;
	--i; --j;
	g[i][j]=v;
    }

    memset(dp,-1,sizeof(dp));

    cout<<solve(0,0,0)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 355852
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int n1 = S.size(), n2 = T.size();
    bool updated = false;
    RREP(i, n1 - n2) {
        bool same = true;
        REP(j, n2) {
            char s = S[i + j], t = T[j];
            same &= (s == t || s == '?');
        }
        if (!same) {
            continue;
        }
        REP(j, n2) {
            S[i + j] = T[j];
        }
        updated = true;
        break;
    }
    if (updated) {
        REP(i, n1) {
            if (S[i] == '?') {
                S[i] = 'a';
            }
        }
        cout << S << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num_of_list = sc.nextInt();
        int[] number_list = new int[num_of_list];
        for(int i = 0;i < num_of_list;i++){
            number_list[i] = sc.nextInt();
        }
        int smallest = Integer.MAX_VALUE;
        for(int i = 0;i < 100;i++){
            int total = 0;
            for(int j = 0;j < num_of_list;j++){
                total += (number_list[j]-(i+1))*(number_list[j]-(i+1));
            }
            if(total<smallest){
                smallest = total;
            }
        }
        System.out.println(smallest);
    }
}

Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <bitset>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    int n,m,p;
    cin>>n>>m>>p;
    if(n+m<p){
        cout<<"NA"<<endl;
        return 0;
    }
    cout<<max(0,p-n)<<endl;
    return 0;
}




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

#define ll long long
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;


int main() {
    ll L,R;
    cin >> L >> R;
    
    if((R-L)>2019) cout << 0 <<endl;
    else {
        int min =2020;
        for(ll i=L;i<=R-1;i++){
            for(ll j=i+1;j<=R;j++){
                if(min>(i*j)%2019) min = (i*j)%2019;
            }
        }
        cout << min <<endl;
    }
}

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

int main(){
  int64_t N;
  cin >> N;
  if(N==1){
    cout << "Yes" << endl;
    return 0;
  }
  priority_queue <int64_t> pq;
  vector <int64_t> H(N);
  cin >> H.at(0);
  pq.push(H.at(0));
  for(int64_t i=1;i<N;i++){
    cin >> H.at(i);
    pq.push(H.at(i));
    if(pq.top()-H.at(i)>=2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, k; cin >> n >> k;
  int x = (n - k)%(k - 1) == 0 ? 0 : 1;
  cout << (n - k > 0 ? ((n - k)/(k - 1)) + 1 + x : 1 )<< '\n';
}

Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            String N = in.next();

            boolean goodLeft = true;
            for (int i = 0; i < 3; i++) {
                goodLeft &= N.charAt(i) == N.charAt(0);
            }

            boolean goodRight = true;
            for (int i = 1; i < 4; i++) {
                goodRight &= N.charAt(i) == N.charAt(1);
            }

            out.println(goodLeft || goodRight ? "Yes" : "No");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#define loop(s) for(int i = 0; s > i; i++)
using namespace std;
int main(){
  int nedan = 700;
  loop(3){
    char tmp;
    cin >> tmp;
    if(tmp == 'o') nedan += 100;
  }
  cout << nedan << endl;
  return 0;
}

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

using namespace std;
int main(){
    int n;
    bool test = false;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1; j<=9; j++){
            if(i*j==n){
               i=10;
               j=10;
               test = true;
            }
        }
    }
   
    if(test) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int p[100001], e[100001];

int main(){
  int n,m,a,b,c;
  scanf("%d%d",&n,&m);

  for(int i=0;i<m;i++)scanf("%d",&p[i]);
  for(int i=1;i<m;i++){
    if(p[i]<p[i-1])e[p[i]]++, e[p[i-1]]--;
    else e[p[i]]--, e[p[i-1]]++;
  }

  ll ans = 0, num = 0;
  for(int i=1;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    num += e[i];
    ans += min(num*a, num*b+c);
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 1952
H, W=gets.chomp.split.map(&:to_i)
field = []
H.times { field << gets.chomp.split('')}

dn = [0,1,0,-1]
dm = [1,0,-1,0]
init = field.flatten.select {|a| a == '.'}.length
d = Array.new(H).map{Array.new(W, 0)}
d[0][0] = 1
queue = []
queue << [0,0]

while queue != [] do
  n, m = *queue.shift

  4.times do |i|
    nn = n + dn[i]
    nm = m + dm[i]
    if nn >= 0 && nm >= 0 && nn < H && nm < W && field[nn][nm] == '.' && d[nn][nm] == 0 then
      d[nn][nm] = d[n][m] + 1
      queue << [nn, nm]
    end
  end
end

puts d[H-1][W-1] == 0 ? -1 : init - d[H-1][W-1]


Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
typedef double f2;
int n;f2 d,x;
int main() {
	scanf("%d%lf%lf",&n,&d,&x);
	int i; f2 ans=0;
	for(i=n;i;i--) {
		f2 nd=d+(2*d+5*x)/(2*i);
		f2 nx=d+x+(2*d+9*x)/(2*i)-nd;
		ans+=d+x*(2*i-1)/2;
		d=nd, x=nx;
	}
	printf("%.12f\n",ans);
}


Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
MAX=0
MIN=0
count=1
for i in range(N-1):
	X=A[i+1]-A[i]
	if X>0:
		if MIN==0 and MAX==0:
			MAX=1
		elif MIN==1:
			count+=1
			MAX=0
			MIN=0
	elif X<0:
		if MIN==0 and MAX==0:
			MIN=1		
		elif MAX==1:
			count+=1
			MAX=0
			MIN=0
print(count)

Measured memory_bytes: 16044
func sumDigits(_ num: Int) -> Int {
    var sum = 0
    var num = num
    while num > 0 {
        sum += num%10
        num /= 10
    }
    return sum
}

func checkHash(_ num: Int) -> Void {
    if num % sumDigits(num) == 0 {
        print("Yes")
    } else {
        print("No")
    }
}
let a = Int(readLine()!)!
checkHash(a)

Measured memory_bytes: 7584
#include <stdio.h>

int main(void)
{
	int W, H;
	int map[21][21];
	char in[21];
	int x, y;
	int flag;
	int count;
	
	while (1){
		scanf("%d%d", &W, &H);
		if (W == 0 && H == 0){
			break;
		}
		
		for (y = 1; y <= H; y++){
			scanf("%s", in);
			for (x = 1; x <= W; x++){
				switch (in[x - 1]){
				  case '.':
				    map[y][x] = 0;
					break;
				  
				  case '#':
				    map[y][x] = -1;
					break;

				  case '@':
				    map[y][x] = 1;
					break;
				}
			}
		}
		count = 1;
		do {
			flag = 0;
			for (y = 1; y <= H; y++){
				for (x = 1; x <= W; x++){
					if (map[y][x] == 1){
						if (y - 1 >= 1 && map[y - 1][x] == 0){
							map[y - 1][x] = 1;
							count++;
							flag = 1;
						}
						if (y + 1 <= H && map[y + 1][x] == 0){
							map[y + 1][x] = 1;
							count++;
							flag = 1;
						}
						if (x - 1 >= 1 && map[y][x - 1] == 0){
							map[y][x - 1] = 1;
							count++;
							flag = 1;
						}
						if (x + 1 <= W && map[y][x + 1] == 0){
							map[y][x + 1] = 1;
							count++;
							flag = 1;
						}
					}
				}
			}
		} while (flag == 1);
		
		printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 604
#include "vector"
#include "set"
#include "map"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 1000000007

typedef vector<int> vi;
typedef pair<int, int> pii;


template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

ll pw(ll x, int n) {
    if (n == 1) {
        return x;
    }
    if (n%2 == 0) {
        return pw((x*x) % MOD, n/2);
    }
    return (pw(x, n-1) * x) % MOD;
}

ll dv(ll a, ll b) {
    return (a * pw(b, MOD - 2)) % MOD;
}

vector<ll> f;
void set_f(int n) {
    f.resize(n+1);
    f[0] = 1;
    for (int i=1; i<= n; i++) {
        f[i] = (f[i-1] * i) % MOD;
    }
}

ll c_n_k(int n, int k) {
    return dv(dv(f[n], f[k]), f[n-k]);
}

vector<vi> g;
vector<ll> ans1;
vector<ll> ans2;
vector<int> cnt;

void dfs1(int x, int p) {
    int sum = 0;
    for (int y : g[x]) {
        if (y != p) {
            dfs1(y, x);
            sum += cnt[y];
        }
    }

    cnt[x] = sum+1;
    ans1[x] = 1;
    if (sum==0) {
        return;
    }

    for (int y : g[x]) {
        if (y != p) {
            ans1[x] = (ans1[x] * ans1[y]) % MOD;
            ans1[x] = (ans1[x] * c_n_k(sum, cnt[y])) % MOD;
            sum -= cnt[y];
        }
    }
}

void dfs2(int x, int p) {
    ans2[x] = ans1[x];

    for (int y : g[x]) {
        if (y != p) {
            int cnt_x = cnt[x];
            int cnt_y = cnt[y];
            ll ans_x = ans1[x];
            ll ans_y = ans1[y];

            ans1[x] = dv(ans1[x], ans1[y]);
            ans1[x] = dv(ans1[x], c_n_k(cnt[x]-1, cnt[y]));
            cnt[x] -= cnt[y];
            cnt[y] += cnt[x];
            ans1[y] = (ans1[y] * ans1[x]) % MOD;
            ans1[y] = (ans1[y] * c_n_k(cnt[y]-1, cnt[x])) % MOD;

            dfs2(y, x);

            cnt[x] = cnt_x;
            cnt[y] = cnt_y;
            ans1[x] = ans_x;
            ans1[y] = ans_y;
        }
    }
}

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

    set_f(n);
    g.resize(n);
    ans1.resize(n);
    ans2.resize(n);
    cnt.resize(n);

    for (int i=0; i<n-1; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs1(0, -1);
    dfs2(0, -1);

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

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

    if (0) {
        int tests;
        cin >> tests;
        while (tests--) {
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 19444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N){
        int P; cin >> P; P--;
        A[P] = i;
    }
    int ans = 0;
    for(int i = 0; i < N;){
        int j = 1;
        while(i+j < N && A[i+j] > A[i+j-1]) j++;
        chmax(ans, j);
        i += j;
    }
    cout << N-ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

l, r = 0, 0
SUM, XOR = 0, 0
ans = 0

for l in range(N):
    # 区間を伸ばせるなら、伸ばす
    while r < N and SUM+A[r] == XOR^A[r]:
        SUM += A[r]
        XOR ^= A[r]
        r += 1

    # 伸ばせなくなったら区間の大きさを計算
    ans += r-l

    # 左端を一つ詰める（左が右を追い越すことはない）
    SUM -= A[l]
    XOR ^= A[l]
    
print(ans)

Measured memory_bytes: 24840
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a,b,c;
  	cin>>a>>b>>c;
  	if(a<=c && c<=b) cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}	

Measured memory_bytes: 3560
def gcd(a, b): return a if b == 0 else gcd(b, a % b)
def lcm(a, b): return a * b // gcd(a, b)

n, m = map(int, input().split())
s = input().strip()
t = input().strip()

l = lcm(n, m)
x, y = l // n, l // m

if all(s[i*y] == t[i*x] for i in range(gcd(n, m))):
    print (l)
else:
    print (-1)




Measured memory_bytes: 3316
def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
a,b=map(int, input().split())
cnt=0
if a==2:
    cnt=1
elif a>1:
    cnt=(factorial(a)/((factorial(a-2))*2))
if b==2:
    cnt=cnt+1
elif b>1:
    cnt=(factorial(b)/((factorial(b-2))*2))+cnt
print(int(cnt))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n, a[100005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

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

    vector<int> dp(n + 1, INF);
    dp[1] = 0;
    for (int i = 1; i <= n; i++) {
        if (i - 1 > 0) dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
        if (i - 2 > 0) dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n] << '\n';
}


Measured memory_bytes: 1024
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut x: usize = sc.read();
    let mut y: usize = sc.read();

    let table = vec![300000, 200000, 100000, 0];

    if x >= 4 {
        x = 4;
    }
    if y >= 4 {
        y = 4;
    }

    let mut ans = table[x - 1] + table[y - 1];
    if x == 1 && y == 1 {
        ans += 400000
    }
    println!("{}", ans);
}

Measured memory_bytes: 2164
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>

#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(ll (i)=(m);(i)<(n); i++)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(ll i=1;(i)<=(ll)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
	ll H,N;cin>>H>>N;
	vi a(H+1),m(H+1);
	REP(i,N)cin>>a[i]>>m[i];
	ll dp[H+1];dp[0]=0;
	ll tmpmp;
	REPS(h,H){
		if(a[0]>=h)tmpmp=m[0];
		else tmpmp=dp[h-a[0]]+m[0];
		FOR(n,1,N){
			if(a[n]>=h){
				if(tmpmp>m[n])tmpmp=m[n];
			}
			else{
				if(tmpmp>dp[h-a[n]]+m[n])
					tmpmp=dp[h-a[n]]+m[n];
			}
		}
		dp[h]=tmpmp;
	}
	cout<<dp[H]<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>

using namespace std;

void print(char str[],int a,int b){
	for(int i = a; i <= b; i++)	printf("%c",str[i]);
	printf("\n");
}

void replace(char str[],char p[],int a,int b){
	int p_length = b-a+1;
	for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}

void reverse(char str[],int a,int b){
	int left = a,right = b;
	while(left < right){
		swap(str[left++],str[right--]);
	}
}

int main(){
	char str[1001],p[1001],order[8];
	int q,a,b;
	scanf("%s",str);
	scanf("%d",&q);
	for(int i = 0; i < q; i++){
		scanf("%s %d %d",order,&a,&b);
		switch(order[2]){
		case 'i':
			print(str,a,b);
			break;
		case 'v':
			reverse(str,a,b);
			break;
		case 'p':
			scanf("%s",p);
			replace(str,p,a,b);
			break;
		}
	}
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int x,y,n,m;
  cin >> n >> m >> x >> y;
  vector<int> vecx(n+1), vecy(m+1);
  vecx.at(0)=x;
  vecy.at(0)=y;
  for(int i=0;i<n;i++){
    cin >> vecx.at(i+1);
  }
  for(int i=0;i<m;i++){
    cin >> vecy.at(i+1);
  }
  sort(vecx.begin(),vecx.end());
  sort(vecy.begin(),vecy.end());
  if(vecx.at(n)+1<=vecy.at(0)){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}
  

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

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  string S, T;
  cin >> S >> T;
  int s_bucket[26] = {0};
  int t_bucket[26] = {0};

  for (int i = 0; i < S.size(); i++) {
    s_bucket[S.at(i) - 'a']++;
    t_bucket[T.at(i) - 'a']++;
  }

  sort(s_bucket, s_bucket + SIZE_OF_ARRAY(s_bucket));
  sort(t_bucket, t_bucket + SIZE_OF_ARRAY(t_bucket));

  bool can_replace = true;
  for (int i = 0; i < 26; i++) {
    if (s_bucket[i] != t_bucket[i]) {
      can_replace = false;
      break;
    }
  }

  if (can_replace) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

const int N = 1e5 + 10;

struct UnionFind{
	vector<int> par;

	UnionFind(int n){
		par = vector<int>(n);
		rep(i, n) par[i] = i;
	}

	int find(int x){
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y){
		par[find(x)] = find(y);
	}
};

int p[N], qv[N];
char qc[N];

int main(){
	int n, q;
	while (cin >> n >> q, n){
		FOR(i, 1, n) cin >> p[i], --p[i];
		set<int> ok;
		rep(i, q){
			cin >> qc[i] >> qv[i], --qv[i];
			if (qc[i] == 'M'){
				if (ok.count(qv[i])) qv[i] = -1;
				else ok.insert(qv[i]);
			}
		}
		set<int> s;
		rep(i, q){
			if (qc[i] == 'M') s.insert(qv[i]);
		}

		UnionFind uf(n);

		rep(i, n) if (!s.count(i)) uf.unite(i, p[i]);

		ll ans = 0;
		for (int i = q - 1; i >= 0; --i){
			if (qv[i] < 0) continue;
			if (qc[i] == 'M'){
				uf.unite(qv[i], p[qv[i]]);
			}
			else{
				ans += uf.find(qv[i]) + 1;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int x=0;
  int Max = 0;
  
  for (int i=0; i<N; i++){
    if (S.at(i)=='I')
      x++;
    else
      x--;
    Max = max(Max, x);
  }
  cout << Max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
   vector <int> h(n), dp(n+1);
   for(int i=0; i < n; i++)
   {
      cin >> h[i];
   }
   dp[0] = 0;
   dp[1] = abs(h[1]-h[0]);
   for(int i=2; i<n;i++)
   {
	   dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
   }
   cout << dp[n-1] <<"\n";
   return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    unordered_map<string, int> mp;
    ll ans = 0;
    for(int i=0;i<n;i++) {
        cin >> s[i];    
    }
    for(int i=0;i<n;i++){
        sort(s[i].begin(),s[i].end());
        ans += mp[s[i]];
        mp[s[i]]++;
    }
    
    cout << ans << endl;
    return 0;
       
}

Measured memory_bytes: 17700
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
  
using namespace std;
  
struct Edge {
  int to, cost;
  Edge(int t, int c)
    : to(t), cost(c) {}
};

struct State {
  int cost, m, pos;
  State(int c, int m, int p) : cost(c), m(m), pos(p) {}
  bool operator<(const State& s) const { return cost>s.cost; }
};

#define INF ((int)1e9)
  
int N, LIM, EST, ROAD, src, dst;
bool estb[100];
vector<Edge> G[100];
int cost[100][101]; // cost[N][LIM]
 
int dijkstra(int src, int dst) {
   
  fill(cost[0], cost[0]+10100, INF);
   
  priority_queue<State> pq;
  pq.push(State(0, LIM, src)); // cost, m, now
   
  while(!pq.empty()) {
    State st = pq.top(); pq.pop();
     
    if(st.pos == dst) { return st.cost; }
     
    if(cost[st.pos][st.m] < st.cost) { continue; }
     
    if(estb[st.pos] == 1 && st.m + 1 <= LIM) {
      // 冷凍中
      if( cost[st.pos][st.m+1] > st.cost+1 ) {
	cost[st.pos][st.m+1]   = st.cost+1;
	pq.push( State(st.cost+1, st.m+1, st.pos ) );
      }
    }
       
    for(int i=0; i<G[st.pos].size(); i++) {
       
      const int next = G[st.pos][i].to;
      const int add_cost = G[st.pos][i].cost;
      const int moved_m = st.m - add_cost;
       
      if(moved_m < 0) { continue; } // 到達不可
       
      if( cost[next][moved_m] > st.cost + add_cost ) {
	cost[next][moved_m] = st.cost + add_cost;
	pq.push( State( st.cost + add_cost, moved_m, next ) );
      }
    }
  }
  
  return -1;
}
 
int main() {
   
  while(cin >> N >> LIM >> EST >> ROAD >> src >> dst && N) {
     
    for(int i=0; i<N; i++) {
      G[i].clear();
      estb[i] = 0;
    }
    for(int i=0; i<EST; i++) {
      int a; cin >> a; estb[a] = 1;
    }
     
    for(int i=0; i<ROAD; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      G[a].push_back(Edge(b, c));
      G[b].push_back(Edge(a, c));
    }
     
    int ret = dijkstra(src, dst);
    if(ret == -1) {
      cout << "Help!" << endl;
    }
    else {
      cout << ret << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1472
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k, P = 1000000007;std::cin >> n >> k;
  vvv dp = vvvl(n+1, n+1, n*n+1, 0);
  dp[0][0][0] = 1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=i;j++){
      for(int k=0;k<=n*n;k++){
        if(k<2*j) continue;
        dp[i][j][k] = (dp[i][j][k] + ((2*j+1)*dp[i-1][j][k-2*j])%P)%P;
        if(j!=0) dp[i][j][k] = (dp[i][j][k] + dp[i-1][j-1][k-2*j])%P;
        if(j!=i) dp[i][j][k] = (dp[i][j][k] + ((((j+1)*(j+1))%P)*dp[i-1][j+1][k-2*j])%P)%P;
      }
    }
  }
  ll ans = dp[n][0][k];
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 52352
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
div_length = max(nums)+1
divisible_list = {}
#initialize
for i in range(0, div_length):
  divisible_list[i] = 0

#count divisible numbers
for fNum in nums:
  for j in range(fNum, div_length, fNum):
   	divisible_list[j] += 1

#check for numbers
answer = 0
for num in nums:
  if (divisible_list[num] == 1):
    answer += 1
print(answer)


Measured memory_bytes: 217576
from array import array
from itertools import accumulate, repeat, starmap
from operator import add, itemgetter


def main():
    city_count, express_count, query_count = map(int, input().split())

    city_list = [array('L', repeat(0, city_count + 1))
                 for _ in range(city_count + 1)]

    for _ in range(express_count):
        l, r = map(int, input().split())
        city_list[l][r] += 1

    for city_index in range(1, city_count + 1):
        city_list[city_index] = array('L', accumulate(city_list[city_index]))

    for city_index in range(2, city_count + 1):
        city_list[city_index] = array('L', starmap(
            add, zip(*(city_list[city_index + i] for i in (-1, 0)))))

    for _ in range(query_count):
        p, q = map(int, input().split())
        print(city_list[q][q] - city_list[p - 1][q])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5876
#include "bits/stdc++.h"
#define allr(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define sp " "
#define double long double
#define pb push_back
#define ff first
#define int long long
#define ss second
#define vi vector<int>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define bruh freopen("bruh.txt", "r", stdin)
#define fo freopen("output.txt", "w", stdout)
#define pii pair<int, int>

long long inf = 2e18;
long long minf = -inf;

using namespace std;

signed main() {

#ifndef ONLINE_JUDGE
	//freopen("bruh.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	while(n--){
		int a;
		cin >> a;
		if(a%2==0 and  a%3!=0 and a%5!=0){
			cout<<"DENIED"<<endl;
			exit(0);

		}

	}
	cout<<"APPROVED"<<endl;



}




Measured memory_bytes: 256
from math import gcd
N = int(input())


S = 0

# all same
for i in range(1, N+1):
    S += i

# two is same
for i in range(1, N+1):
    for j in range(i+1, N+1):
        S += 6 * gcd(i, j)

# all not same
for i in range(1, N+1):
    for j in range(i+1, N+1):
        for k in range(j+1, N+1):
            S += 6 * gcd(gcd(i, j), k)

print(S)


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

int main(){
	char s;
  	cin >> s;
  
  	if(s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o'){
      cout << "vowel" << endl;
    } else {
      cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256