akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) throws IOException{
		
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		
		int n = Integer.parseInt(bufferedReader.readLine());
		
		String slimesInput = bufferedReader.readLine();
		String[] colorsString = slimesInput.split("[\\s]+");
		
		int[] colors = new int[n];
		for(int i = 0; i < n; i++) {
			colors[i] = Integer.parseInt(colorsString[i]);
		}
		
		int answer = 0;
		
		int continuous = 1;
		
		int previous = colors[0];
		int present = 0;
		
		for(int i = 1; i < n; i++) {
			
			present = colors[i];
			
			if (previous == present) {
				continuous++;
			}else {
				answer += continuous / 2;
				continuous = 1;
			}
			
			previous = present;
			present = 0;
		}
		
		answer += continuous / 2;
		
		print(String.valueOf(answer));
		
	}
	
	public static void print(String text) {
		System.out.println(text);
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin >> h >> w;
    vector<string> grid(h);
    rep(i,h) cin >> grid[i];
    vector<vector<ll>> cnt(h-1,vector<ll>(w-1,0));
    rep(i,h-1){
        rep(j,w-1){
            ll c = 0;
            if (grid[i][j] == '.') c++;
            if (grid[i+1][j] == '.') c++;
            if (grid[i][j+1] == '.') c++;
            if (grid[i+1][j+1] == '.') c++;
            if (c%2 == 0) cnt[i][j] = 1;
        }
    }
    rep(i,h-2){
        rep(j,w-1){
            if (cnt[i+1][j] != 0){
                cnt[i+1][j] += cnt[i][j];
            }
        }
    }
    ll ans = 0;
    rep(i,h-1){
        vector<ll> l(w-1),r(w-1);
        stack<ll> s;
        rep(j,w-1){
            while(!s.empty() && cnt[i][s.top()] >= cnt[i][j]){
                s.pop();
            }
            if (s.empty()){
                l[j] = 0;
            }
            else{
                l[j] = s.top()+1;
            }
            s.push(j);
        }
        stack<ll> t;
        for (ll j = w-2;j >= 0;j--){
            while(!t.empty() && cnt[i][t.top()] >= cnt[i][j]){
                t.pop();
            }
            if (t.empty()){
                r[j] = w;
            }
            else{
                r[j] = t.top()+1;
            }
            t.push(j);
        }
        //array_output(all(l));
        //array_output(all(r));
        rep(j,w-1){
            chmax(ans,(cnt[i][j]+1)*(r[j]-l[j]));
        }
    }
    chmax(ans,max(h,w));
    PRINT(ans);
}


Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 24;
bool used[N];
int a[N];
int ans = 0;
int n;
void gen(int i) {
    if (i == n) {
        int mn = 24;
        int r = -1;
        for (int i = 0; i < 24; ++i) {
            if (used[i]) {
                if (i)
                    mn = min(mn, i - r);
                r = i;
            }
        }
        mn = min(mn, 24 - r);
        ans = max(ans, mn);
        return;        
    }   
    if (!used[a[i]]) {
        used[a[i]] = 1;
        gen(i + 1);
        used[a[i]] = 0;
    }   
    if (a[i] && !used[24 - a[i]]) {
        used[24 - a[i]] = 1;
        gen(i + 1);
        used[24 - a[i]] = 0;
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    if (n > 24) {
        cout << 0 << endl;
        exit(0);
    }   
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    used[0] = 1;
    gen(0);
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int n,a,b;
    int res=0;
    n=read(), a=read(), b=read();
    for(ri int i=1;i<=n;i++)
    {
        int x=i;
        int qwq=0;
        while(x) qwq+=x%10, x/=10;
        if(qwq>=a&&qwq<=b) res+=i;
    }
    printf("%lld\n",res);
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    int n, m; cin >> n >> m;
    V<string> a(n);
    V<string> b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    bool ans = false;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i + m - 1 >= n || j + m - 1 >= n) continue;
            bool flag = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(a[i + k][j + l] != b[k][l]) flag = false;
                }
            }
            if(flag) ans = true;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll factorial(ll a, ll b) {
    ll ret = 1;
    rep(i, b) {
        ret = ret * a % mod;
        --a;
    }
    return ret;
} 

ll pow(ll a, ll n) {
    ll ret = 1;
    while(1) {
        if (n == 0) break;
        if (n % 2 == 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

ll inv(ll a) {
    return pow(a, mod-2);
}

ll combination(ll n, ll k, vector<ll> &fact, vector<ll> &ifact) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    vector<ll> fact(n+1), ifact(n+1);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1] * (ll)i % mod;
    ifact[n] = inv(fact[n]);
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * (ll)i % mod;
    ll ans = 0;
    rep(i, n) {
        ans = (ans +a[i] * combination((ll)i, (ll)k - 1LL, fact, ifact)) % mod;
        ans = (ans - a[i] * combination((ll)(n - 1 - i), (ll)k-1LL, fact, ifact) % mod);
        if (ans < 0) ans += mod;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 200010;

int p[N];

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

vector < pair <int, int> > g[N];
int x[N];
int y[N];
int v[N];
int deg[N];
int pos[N];
int q[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
    p[i] = i;
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", x + i, y + i, v + i);
    --x[i]; --y[i];
    if (v[i] == 0) {
      p[find(x[i])] = find(y[i]);
    }
  }
  memset(deg, 0, sizeof deg);
  map < pair <int, int>, int > edges;
  for (int i = 0; i < m; ++i) {
    int px = find(x[i]);
    int py = find(y[i]);
    if (px == py) {
      continue;
    }
    if (edges.count({py, px}) != 0) {
      puts("No");
      return 0;
    }
    if (edges.count({px, py}) != 0) {
      if (edges[{px, py}] != v[i]) {
        puts("No");
        return 0;
      }
    } else {
      edges[{px, py}] = v[i];
      g[px].emplace_back(py, v[i]);
      ++deg[py];
    }
  }
  int qt = 0;
  for (int i = 0; i < n; ++i) {
    if (deg[i] == 0) {
      q[qt++] = i;
    }
  }
  memset(pos, 0, sizeof pos);
  for (int qh = 0; qh < qt; ++qh) {
    int xx = q[qh];
    for (auto e : g[xx]) {
      int yy = e.first;
      pos[yy] = pos[xx] + e.second;
      --deg[yy];
      if (deg[yy] == 0) {
        q[qt++] = yy;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (deg[i] != 0) {
      puts("No");
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    int px = find(x[i]);
    int py = find(y[i]);
    if (pos[py] - pos[px] != v[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int h, w, k;
    cin >> h >> w >> k;
    bool ng[h][w] = {};
    queue<pair<int, int>> que;
    vector<vector<int>> dis(h, vector<int>(w, -1));
    rep(i, h) rep(j, w) {
        char c;
        cin >> c;
        if(c == 'S') {
            que.emplace(i, j);
            dis[i][j] = 0;
        }
        if(c == '#') ng[i][j] = true;
    }
    int ans = 1e9;
    const int dx[] = {0, 1, 0, -1};
    const int dy[] = {1, 0, -1, 0};
    while(!que.empty()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        chmin(ans, x);
        chmin(ans, h - 1 - x);
        chmin(ans, y);
        chmin(ans, w - 1 - y);
        if(dis[x][y] >= k) continue;
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w || ng[nx][ny]) continue;
            if(dis[nx][ny] != -1) continue;
            dis[nx][ny] = dis[x][y] + 1;
            que.emplace(nx, ny);
        }
    }
    cout << (ans + k - 1) / k + 1 << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;} 


int main(){
  ll H,W;
  cin >> H >> W;
  if(H==1 || W==1){
    cout << 1 << endl;
    return 0;
  }
  ll x = (H+1)/2;
  ll y = H/2;
  ll ans = x * ((W+1)/2);
  ans += y*(W/2);
  cout << ans << endl;
}



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


int main() {
    string S;
    cin >> S;
    int n = (int)S.length() - 1;
    long long allsum = 0;
    for (long long bit = 0; bit < (1<<n); ++bit) {
        long long sum = 0;
        int start_index = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                sum += stoll(S.substr(start_index, i + 1 - start_index));
                start_index = i + 1;
            }
        }
        sum += stoll(S.substr(start_index, n + 1 - start_index));
        allsum += sum;
    }
    cout << allsum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#define N 1234
#define NN 5678
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar(); bool flag = false;
  while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
  if (flag) x = -x;
}
using namespace std;
const int inf = 7654321;
inline void MIN(int &a, int b) {
  if (b < a)  a = b;
}
int n;
struct edge{
  int nxt, to;
}e[N << 1];
int head[N], ecnt;
inline void addedge(int from, int to) {
  e[++ecnt] = (edge){head[from], to};
  head[from] = ecnt;
}
int fa[N];
int val[N];
int f[N][2], g[NN], og[NN];
inline void calc(int cur, int t) {
  memset(g, 0x3f, sizeof(g)); g[0] = 0;
  for (signed int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to; memcpy(og, g, sizeof(g)); memset(g, 0x3f, sizeof(g));
    for (signed int j = val[cur]; ~j; --j) {
      if (j >= val[to] && og[j - val[to]] <= inf) MIN(g[j], og[j - val[to]] + f[to][t]);
      if (j >= f[to][t ^ 1] && og[j - f[to][t ^ 1]] <= inf) MIN(g[j], og[j - f[to][t ^ 1]] + val[to]);
    }
  }
  for (signed int j = 0; j <= val[cur]; ++j)  MIN(f[cur][t], g[j]);
}
void dfs(int cur) {
  for (signed int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to; dfs(to);
  }
  calc(cur, 0); calc(cur, 1);
  if (f[cur][0] > inf && f[cur][1] > inf) {
    puts("IMPOSSIBLE");
    exit(0);
  }
}

int main() {
  memset(f, 0x3f, sizeof(f));
  read(n);
  for (signed int i = 2; i <= n; ++i) read(fa[i]), addedge(fa[i], i);
  for (signed int i = 1; i <= n; ++i) read(val[i]);
  dfs(1);
  puts("POSSIBLE");
  return 0;
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  string ans;
  ans.pb(s[0]);
  ans.pb(s[1]);
  ans.pb(s[2]);


  prt(ans);
}


Measured memory_bytes: 3596
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[300005][2]={0};
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0];
        dp[i][1]=dp[i-1][1];
        if(s[i-1]=='E')
            dp[i][0]++;
        else dp[i][1]++;
    }
//    for(int i=0;i<=n;i++){
//        cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
//    }
    int ans=999999999;
    for(int i=1;i<=n;i++){
        if(i==0){
            ans=min(ans,dp[n][0]-dp[1][0]);
        }
        else if(i==n){
            ans=min(ans,dp[n-1][1]);
        }
        else{
            ans=min(ans,dp[i-1][1]-dp[0][1]+dp[n][0]-dp[i][0]);
        }
       // cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
return 0;}


Measured memory_bytes: 3076
#include <stdio.h>

int main(void){
	int a,b,c;
	int buf;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a > b){
		buf= a;
		a = b;
		b = buf;
	}
	if(b > c){
		buf= b;
		b = c;
		c = buf;
	}
	if(a >b){
		buf= a;
		a = b;
		b = buf;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 1024
import math
N, M = map(int, input().split())

INF = 10**9
array_len = int(math.pow(2, N))

min_array = [INF] * array_len

min_array[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c_array = map(int, input().split())
    key_sum = 0
    for c in c_array:
        key_sum += int(math.pow(2, c - 1))
    for i in range(array_len):
        if min_array[i] == INF:
            continue
        else:
            min_array[i | key_sum] = min(min_array[i | key_sum],
                                         min_array[i] + a)

if min_array[-1] == INF:
    print(-1)
else:
    print(min_array[-1])


Measured memory_bytes: 47448
#include<iostream>
#include<stack>
#include<vector>
#include <map>
#include <queue>
#include<string.h>
using namespace std;
typedef pair<int,int> P;
int node[200][200];

int que(int s,int d,int v)
{
  queue<P> qu;
  int c[200];
  memset(c,-1,sizeof(c));
  for(int i=0;i<200;i++)
    {
      if(v-1>0)
	if(node[s][i]==1)
	  qu.push(P(i,v-1));
    }
  while(!qu.empty())
    {
      P a = qu.front();
      qu.pop();
      //      cout<<a.first<<" "<<a.second<<endl;
      if(a.first==d)
	return v-a.second+1;
      for(int i=0;i<200;i++)
	{
	  if(node[a.first][i]==1)
	    {
	      if(a.second-1>0)
		{
		  if(c[i]==-1)
		    {
		      c[i]=a.second-1;
		      qu.push(P(i,a.second-1));	    
		    }
		}
	    }
	} 
    }
      return -1;
}
int main()
{
  int n;
  cin>>n;
  memset(node,-1,sizeof(node));
  for(;n--;)
    {
      int k,t;
      cin>>k>>t;
      for(int i=0;i<t;i++)
	{
	  int tmp;
	  cin>>tmp;
	  node[k][tmp]=1;
	}
    }
  int p;
  cin>>p;
  for(;p--;)
    {
      int s,d,v;
      cin>>s>>d>>v;
      int ans=que(s,d,v);
      if(ans==-1)
	cout<<"NA"<<endl;
      else
	cout<<ans<<endl;
      
    }
  
}

Measured memory_bytes: 1364
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;




ll n;
void solve(){
    cin>>n;
    ll x=26LL;
    int i=1;
    for(;i<16;i++) {
        if(x>=n)break;
        x*=26LL;
    }
    string ans="";

    x=n;
    while(x) {
        --x;
        ll t=x%26LL;
        ans+=(char)('a'+t);
        x=x/26LL;
    }
    reverse(all(ans));
    cout<<ans<<"\n";
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll n,m,val,index,sum;
	cin>>n;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	cin>>m;
	while(m--)
	{
		sum=0;
		cin>>index>>val;
		for(int i=1;i<=n;i++)
		{
			if(index==i)
				sum+=val;
			else
				sum+=arr[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t
#define fs first
#define sc second
inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

void solve()
{
	lli n,k,ctr=0,m=0,x,y,ans=0;
	cin>>n;
	map<lli,lli> mp;
	rep(i,1,10)
	rep(j,1,10)
		mp[i*j]=2;
	if(mp[n])
		cout<<"Yes";
	else
		cout<<"No";
}

int main()
{
	fast();
	lli t;
	//cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
	
	
	return 0;
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
setL=set(L)
dicL=dict()
ans=0
for i in L:
    if i in dicL:
        dicL[i]+=1
    else:
        dicL[i]=1
L=list(setL)
length=len(L)
for i in range(length):
    for j in range(i+1,length):
        for k in range(j+1,length):
            if L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i]:
                ans+=dicL[L[i]]*dicL[L[j]]*dicL[L[k]]
print(ans)


Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

void input(vector<int> x, auto n){
   rep(i,n)cin >> x[i];
}

int main(){
    int a,b;
    cin >> a >> b;

    printf("%d %d %lf\n", a/b, a%b, (double)a/b);

}


Measured memory_bytes: 3184
/*
AizuOnline A1085
Title spellcasters
*/
#include <stdio.h>
// Select Below
#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section

int n,S,r[20000];
//
int comp(void * x,void * y)
{
  int a,b;
  a = *(int *)x;b= *(int *)y;
  return(a-b);
}


main()
{
  int i,j,cnt;

  while(EOF != scanf("%d %d",&n,&S) && (n || S))
    {
      for(i=0;i<n;i++)
	scanf("%d",&(r[i]));

      cnt=0;
      //printf("N:%d\n",n);
      qsort(r,n,sizeof(int),(__compar_fn_t)comp);
      /*
      for(i=0;i<n;i++)
	printf("%d:",r[i]);
      printf("\n");
      */
      for(i=0;i<n-1;i++)
	for(j=i+1;j<n;j++)
	  if(r[i]+r[j] > S)
	    {  cnt += (n-j); 
	      break;
	    }

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

    }

return(0);
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = 1000000000;
ll inf = 1000000000000;
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 h, n;
	cin >> h >> n;
	int i;
	int a[1100], b[1100];
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	int dp[11000]; // 小さくしてvisual studioでも動くように
	for (i = 0; i <= h; i++) {
		dp[i] = Inf;
	}
	dp[0] = 0;
	for (i = 0; i < n; i++) {
		for (int j = 0; j <= h; j++) {
			int M = min(h, j + a[i]);
			dp[M] = min(dp[M], dp[j] + b[i]);
		}
	}
	cout << dp[h];
	return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int N;
vector<pair<int,int> >G[1<<17];
long s[1<<17];
long ans[1<<17];
int cc[1<<17];
void dfs(int u,int p)
{
	cc[u]=1;
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(v==p)continue;
		dfs(v,u);
		if(2*cc[v]!=N)ans[e.second]=(s[u]-s[v])/(2*cc[v]-N);
		cc[u]+=cc[v];
	}
}
pair<long,int>check(int u,int p)
{
	pair<long,int>ret=make_pair(0L,0);
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(v==p)continue;
		pair<long,int>now=check(v,u);
		ret.first+=now.first;
		ret.second+=now.second;
		if(ans[e.second]!=0)
		{
			ret.first+=ans[e.second]*cc[v];
		}
		else
		{
			ret.second+=cc[v];
		}
	}
	return ret;
}
main()
{
	cin>>N;
	for(int i=0;i<N-1;i++)
	{
		int a,b;cin>>a>>b;a--,b--;
		G[a].push_back(make_pair(b,i));
		G[b].push_back(make_pair(a,i));
	}
	for(int i=0;i<N;i++)cin>>s[i];
	dfs(0,-1);
	pair<long,int>A=check(0,-1);
	long X;
	if(A.second!=0)X=(s[0]-A.first)/A.second;
	for(int i=0;i<N-1;i++)cout<<(ans[i]?ans[i]:X)<<endl;
}


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

typedef long long ll;
typedef struct {
    ll a, b;
} BUG;

BUG foo[300000];
int n;

int seg[1 << 19][2];
int seg_size;

ll _max(ll a, ll b)
{
    return (a > b ? a : b);
}

void init(int n)
{
    seg_size = 1;
    
    while (n > seg_size){
        seg_size *= 2;
    }
    memset(seg, -1, sizeof(seg));
}

void update(int k, int x)
{
    k += seg_size;
    
    seg[k][0] = x;
    seg[k][1] = k - seg_size;
    
    while (k != 0){
        k = (k - 1) / 2;
        if (seg[k * 2 + 1][0] > seg[k * 2 + 2][0]){
            seg[k][0] = seg[k * 2 + 1][0];
            seg[k][1] = seg[k * 2 + 1][1];
        }
        else {
            seg[k][0] = seg[k * 2 + 2][0];
            seg[k][1] = seg[k * 2 + 2][1];
        }
    }
}

int comp(const void *a, const void *b)
{
    BUG x, y;
    x = *(BUG *)a;
    y = *(BUG *)b;
    
    if (x.b != y.b){
        return (y.b - x.b);
    }
    else {
        return (x.a - y.a);
    }
}

int canPut(int piv)
{
    int i;
    int pos;
    ll lim;
    
    init(piv);
    
    lim = 0;
    for (i = 0; i < piv - 1; i++){
        lim += foo[i].a;
        update(i, foo[i].a);
    }
    
    while (i < n){
        if (i == piv - 1){
            lim += foo[i].a;
            update(i, foo[i].a);
        }
        else {
            pos = seg[0][1];
            lim -= seg[0][0];
            lim += foo[i].a;
            update(pos, foo[i].a);
        }
        
        if (lim <= foo[i].b * piv){
            return (1);
        }
        i++;
    }
    
    return (0);
}

int main(void)
{
    int i;
    int left, right, center;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%lld %lld", &foo[i].a, &foo[i].b);
    }
    
    left = 0;
    right = n;
    
    qsort(foo, n, sizeof(BUG), comp);
    
    while (left != right){
        center = (left + right + 1) / 2;
        
        if (canPut(center)){
            left = center;
        }
        else {
            right = center - 1;
        }
    }
    
    printf("%d\n", left);
    
    return (0);
}

Measured memory_bytes: 9784
n = gets.chomp.to_i
hsh = {}
class Node
  attr_reader :id
  attr_accessor :children,:parent, :depth, :type
  def initialize(id)
    @id = id
    @parent = -1
    @depth = 0
    @type = nil
    @children = []
  end

  def leaf?
    @children.empty?
  end
end

def identify(node, depth, node_list)
  node.depth = depth
  if node.parent == -1
    node.type = 'root'
  elsif node.leaf?
      node.type = 'leaf'
  else
    node.type = 'internal node'
  end
  node.children.each do |i|
    identify(node_list[i], depth + 1, node_list)
  end
end

n.times do |index|
  hsh[index] = Node.new(index)
end
 
n.times do
  arr = gets.chomp.split.map(&:to_i)
  id = arr.shift
  num = arr.shift
  hsh[id].children = arr if num > 0
  arr.each do |item|
    hsh[item].parent = id
  end
end

root = hsh.select{|key, val| val.parent == -1}
identify(root.values[0], 0, hsh)
 
hsh.each do |key, node|
  puts "node #{node.id}: parent = #{node.parent}, depth = #{node.depth}, #{node.type}, #{node.children}"
end

Measured memory_bytes: 46628
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  vector<string>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  for(int i=0;i<n;i++){
  if(vec.at(i)=="AC"){
    a++;
  }
    else if(vec.at(i)=="WA"){
      b++;}
    else if(vec.at(i)=="TLE"){
      c++;
    }
else {d++;}
  }
  cout<<"AC"<<" x "<<a<<endl;
  cout<<"WA"<<" x "<<b<<endl;
  cout<<"TLE"<<" x "<<c<<endl;
  cout<<"RE"<<" x "<<d<<endl;
}
    


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

using namespace std;
long long x, k, d;


int main(){
    cin>>x>>k>>d;
    if (abs(x)/d>k) cout<<abs(x)-k*d;
    else {
        long long m=k-abs(x)/d;
        if (m%2==0) cout<<abs(x)%d;
        else cout<<abs(abs(x)%d-d);
    }
}


Measured memory_bytes: 3640
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
class ProgramE
	{
		static void Main(string[] args)
		{

			//入力
			string[] input = Console.ReadLine().Split(' ');
			long n = long.Parse(input[0]);
			long k = long.Parse(input[1]);

			long MOD = 1000000000 + 7;
			long sum = 0;

			//下準備
			nCk com = new nCk();
			com.fac = new long[n + 1];
			com.inv = new long[n + 1];
			com.finv = new long[n + 1];
			com.mod = MOD;
            com.max = n + 1;

			//メモ作成
			com.com_init();
            
            //最大の部屋の数を考える
            long m = n;
          　if(n > k)
                m = k + 1;

			//nCm×n-mHm = nCm×n-1Cn-m-1の和を出す
			for(long i = 0;i < m;i++)
			{
				sum += com.com(n, i) * com.com(n - 1, n - i - 1) % MOD;
				sum %= MOD;
			}

			//出力
			Console.WriteLine(sum);

		}

	}

	class nCk
	{
		public long mod;
		public long max;
		public long[] fac;
		public long[] inv;
		public long[] finv;
		

		//メモ作成
		public void com_init()
		{
			fac[0] = 1;
			fac[1] = 1;
			finv[0] = 1;
			finv[1] = 1;
			inv[1] = 1;
			for(long i = 2;i < max;i++)
			{
				fac[i] = i * fac[i - 1] % mod;
				inv[i] = mod - inv[mod % i] * (mod / i) % mod;
				finv[i] = finv[i - 1] * inv[i] % mod;
			}
		}

		//二項計算
		public long com(long n,long k)
		{
			if (n < 0 || k < 0)
				return 0;
			if (n < k)
				return 0;
			return fac[n] * (finv[n - k] * finv[k] % mod) % mod;
		}

	}

Measured memory_bytes: 15584
#include<bits/stdc++.h>
#define lli long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
lli powm(lli a,lli b ,lli mod){if(b==0) return 1;if(b%2==0){ lli tmp = powm(a,b/2,mod); return (tmp*tmp)%mod;}else return (a%mod * powm(a,b-1,mod))%mod;}
lli invm(lli a, lli mod) {return powm(a,mod-2,mod); } //fermats's method // mod has to be a prime


inline void solve(){
	int n;
	cin>>n;
	cout<<(1000*(n/500) + 5*((n%500)/5))<<endl;
}

int main(){
	fastio;lli  t=1;
	//cin>>t;
	while(t--){solve();}return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;

int a[N];
int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

   int a, n;
   cin>>n;
   int ans = 0;
   for(int i=1; i<=n; i++){
    cin>>a;
    if(i%2 && a%2)ans++;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
    using namespace std;
    #define ll  long long
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define pb push_back
    #define in insert
    #define test   ll t;cin>>t;while(t--)
    #define bs  binary_search
    #define rep1(x,n) for(ll x=n-1;x>=0;x--) 
    
    #define SORT(x) sort(x.begin(),x.end())
    #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
    #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
    #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
    #define All(x) (x).begin(),(x).end()
    #define rAll(x) (x).rbegin(),(x).rend()
    #define db  double
    #define sc scanf
    #define pf printf
    const ll MAX=1e8;
    //ll d[MAX],h[MAX];
    const double pi=3.14159265358979323846;
    const ll M=2e18 +7;
    ll gcd(ll x,ll y){
    	if(x==0)return y;
    	else return gcd(y%x,x);
    }
    ll lcm(ll x,ll y){
    	return (x*y)/gcd(x,y);
    }
   
      bool isPrime(ll n) 
{  
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6){ 
        if (n % i == 0 || n % (i + 2) == 0){ 
            return false; 
        }
    }
    return true; 
} 
bool pdrome(string s){
    ll n = s.length();
    for(ll i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]){
            return false;
        }
    }
    return true;
}
ll mindig(ll x){
    ll ans = 9;
    ll t = x;
    while(x){
        ans = min(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll maxdig(ll x){
    ll ans = 0;
    ll t = x;
    while(x){
        ans = max(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll modpow(ll x,ll n,ll M){
	if(n==0)return 1%M;
	ll u=modpow(x,n/2,M);
	u=(u*u)%M;
	if(n%2==1)u=(u*x)%M;
	return u;

}
ll sum(ll a) {
    ll result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}
ll digits(long long n) 
{ 
    return floor(log10(n) + 1); 
}                                  

    int main() {
    	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    	int n;
    	cin>>n;
    	vector<int>a(10050);
    	
    	for(int x=1;x<=105;x++){
    		for(int y=1;y<=105;y++){
    			for(int z=1;z<=105;z++){
    				int l=(x*x+y*y+z*z+x*y+y*z+z*x);
    				if(l<10050)a[l]++;
    				
    			}
    		}
    		
    	}
    	//int ans=0;
    	
    	//cout<<ans;
    	for(int x=1;x<=n;x++)cout<<a[x]<<"\n";
    return 0;
}
    


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL N, vector<LL> A){
	LL l = A[0], r = A[1], p = A[2], q = A[N - 1];   // sum of each segment
	int l_sep = 1, p_sep;

	// initialize p and q
	int left = 3, right = N - 2;
	while (left < right) {
		if (p <= q) {
			p += A[left];
			left++;
		} else {
			q += A[right];
			right--;
		}
	}
	if (left == right) {
		if (p <= q) {
			p += A[left];
			p_sep = left + 1;
		} else {
			q += A[right];
			p_sep = left;
		}
	}

	//printf("l=%lld, r=%lld (l_sep=%d), p=%lld, q=%lld (p_sep=%d)", l, r, l_sep, p, q, p_sep);

	LL min_diff = abs(max({l, r, p, q}) - min({l, r, p, q}));

	//printf(" diff=%d\n", min_diff);

	// sweep the middle separation
	for (int i = 2; i < N - 2; i++) {
		r += A[i];
		while (1) {   // move l_sep to right until optimum (= min(l - r))
			LL l_new = l + A[l_sep];
			LL r_new = r - A[l_sep];
			if (abs(l_new - r_new) < abs(l - r)) {
				l = l_new;
				r = r_new;
				l_sep++;
			} else {
				break;
			}
		}
		p -= A[i];
		if (i + 1 == p_sep) {   // p consisted of only a single element, so we have to shift p_sep right by 1
			p += A[i + 1];
			q -= A[i + 1];
			p_sep++;
		}
		while (1) {   // move p_sep to right until optimum
			LL p_new = p + A[p_sep];
			LL q_new = q - A[p_sep];
			if (abs(p_new - q_new) < abs(p - q)) {
				p = p_new;
				q = q_new;
				p_sep++;
			} else {
				break;
			}
		}
		LL diff = abs(max({l, r, p, q}) - min({l, r, p, q}));
		if (diff < min_diff) {
			min_diff = diff;
		}

		//printf("l=%lld, r=%lld (l_sep=%d), p=%lld, q=%lld (p_sep=%d) diff=%d\n", l, r, l_sep, p, q, p_sep, diff);
	}
	cout << min_diff << endl;
}


int main(){	
	LL N;
	scanf("%lld",&N);
	vector<LL> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
const int N = 1e5 + 5;
ll n, dp[N], height[N];
ll solve(int idx){
    if(idx >= n)
        return 2e9;
    else if(idx == n - 1)
        return 0;
    if(dp[idx] != -1)
        return dp[idx];
    ll mn = 2e9;
    if(idx + 1 < n)
        mn = min(mn, solve(idx + 1) + abs(height[idx] - height[idx + 1]));
    if(idx + 2 < n)
        mn = min(mn, solve(idx + 2) + abs(height[idx] - height[idx + 2]));
    dp[idx] = mn;
    return mn;
}
int main()
{
    Hello
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> height[i];
    cout << solve(0);
    return 0;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> res;
  for (int i=0; i<=(int)S.size()-(int)T.size(); i++) {
    string sub = S.substr(i, (int)T.size());
    int diff = 0;
    for (int j=0; j<(int)T.size(); j++) {
      if (sub[j]!=T[j]) diff++;
    }
    res.push_back(diff);
  }
  sort(res.begin(), res.end());
  cout << res[0] << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main(){

  int n;
  cin  >> n;
  char s[n+1];
  int i;  
  for(i=0;i<n;++i){
    cin >> s[i];
  }
  bool P = false,W = false,G = false,Y = false;
  for(i=0;i<n;++i){
    if(s[i]=='P')P=true;
    else if(s[i]=='W')W=true;
    else if(s[i]=='G')G=true;
    else Y=true;

  }

  if(P&&W&&G&&Y)cout << "Four" << endl;
  else cout << "Three" << endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int K;
  cin >> K;
  int ans = 0;
  for (int i = 1; i <= K; i++){
    for (int j = 1; j <= K; j++){
      for (int k = 1; k <= K; k++){
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
const int maxn=1e2+10,maxsize=3e7,mod=998244353;
ll pow2[maxn];
char s[maxn];
map<string,int> dp;
int cnt,ch[maxsize][2],val[maxsize]={1};

inline void insert(string s,int v){
	int pos=0;
	for(int i=0;i<s.length();++i){
		if(!ch[pos][s[i]-'0'])
			ch[pos][s[i]-'0']=++cnt,val[cnt]=-1;
		pos=ch[pos][s[i]-'0'];
	}
	val[pos]=v;
}
inline bool find(string s,int&res){
	int pos=0;
	for(int i=0;i<s.length();++i){
		if(!ch[pos][s[i]-'0'])
			return false;
		pos=ch[pos][s[i]-'0'];
	}
	if(val[pos]==-1)
		return false;
	res=val[pos];
	return true;
}
int dfs(string s){
	int res=0;
	if(find(s,res))
		return res;
	int cnt1=0,dp[maxn]={};
	dp[s.length()]=1;
	for(int i=s.length()-1;~i;--i){
		for(int len=1;i+2*len<=s.length();++len){
			string nxt=string(s,i,len);
			for(int cnt=2;i+cnt*len<=s.length();++cnt){
				for(int j=0;j<len;++j)
					if(nxt[j]=='1'&&s[i+(cnt-1)*len+j]=='0')
						nxt[j]='0';
				dp[i]=(dp[i]+(ll)dfs(nxt)*dp[i+cnt*len])%mod;
			}
		}
		if(s[i]=='1')
			dp[i]=(dp[i]+2ll*dp[i+1])%mod;
		else
			dp[i]=(dp[i]+dp[i+1])%mod;
	}
	insert(s,dp[0]);
	return dp[0];
}

int main(){
	pow2[0]=1;for(int i=1;i<maxn;++i)pow2[i]=pow2[i-1]*2%mod;
	cin>>s;
	printf("%lld\n",dfs(s));
	return 0;
}

Measured memory_bytes: 768
if __name__ == '__main__':
    n = int(input())
    d = {"AC": 0, "WA":0, "TLE": 0, "RE": 0}
    for i in range(n):
        n = input()
        d[n] += 1
    for key, value in d.items():
        print(f'{key} x {value}')


Measured memory_bytes: 9172
s = input()
t = ["+", "-"]

for i in t:
    for j in t:
        for k in t:
            if eval(s[0]+i+s[1]+j+s[2]+k+s[3]) == 7:
                print(s[0]+i+s[1]+j+s[2]+k+s[3]+"=7")
                exit()

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

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n, d; cin >> n >> d;
    vector<vector<int>> vec(n, vector<int>(d));
    rep(i, n)rep(j, d){
        cin >> vec.at(i).at(j);
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int sum = 0;
            for(int k = 0; k < d; k++){
                sum = sum + (vec.at(i).at(k) - vec.at(j).at(k)) * (vec.at(i).at(k) - vec.at(j).at(k));
            }
            double sque = sqrt(sum);
            for(int c = 0; c <= sque; c++){
                if(c == sque) count++;
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll a,b,c;cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define ll long long

int main(){

    int a,b; cin >> a >> b;
    cout << (a-1)*(b-1) << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

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

int N;

int main(){
  cin >> N;
  if(N==1){
    int x;
    cin >> x;
    if(x==0){
      cout << 1 << endl;
    }
    else{
      cout << 0 << endl;
    }
    return 0;
  }
  bool isOdd = N % 2;
  vector<int> A(N);
  vector<int> sum(N/2, 0);
  REP(i, N){
    cin >> A[i];
    if(isOdd && A[i] % 2){
      cout << 0 << endl;
      return 0;
    }
    else if(!isOdd && !(A[i] % 2)){
      cout << 0 << endl;
      return 0;
    }
    if(isOdd){
      if((N-1) < A[i]){
        cout << 0 << endl;
        return 0;
      }
      sum[A[i]/2]++;
      
    }
    else if(!isOdd){
      if(N-1 < A[i]){
        cout << 0 << endl;
        return 0;
      }
      sum[(A[i]-1)/2]++;
    }
  }
  REP(i, N/2){
    if(isOdd){
      if(i == 0){
        if(sum[i]!= 1){
          cout << 0 << endl;
          return 0;
        }
      }
      else{
        if(sum[i]!=2){
          cout << 0 << endl;
          return 0;
        }
      }
    }
    else{
      if(sum[i]!=2){
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ans = 1;
  REP(i, N/2){
    ans *= 2;
    ans = ans % (ll)(1e9+7);
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896