akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 1e5 + 20;
const ll inf = 1e17 + 7;

int n, m;
int dp[3010][3010];
ii pr[3010][3010];
int main() {
    string s, h;
    cin >> s >> h;
    pr[0][0] = {-1, -1};
    for (int i = 0; i < sz(s); i++)
    	for (int j = 0; j < sz(h); j++) {
    		if (dp[i][j + 1] > dp[i + 1][j])
    			dp[i + 1][j + 1] = dp[i][j + 1], pr[i + 1][j + 1] = {i, j + 1};
    		else dp[i + 1][j + 1] = dp[i + 1][j], pr[i + 1][j + 1] = {i + 1, j};
    		if (s[i] == h[j] && dp[i][j] + 1 > dp[i + 1][j + 1]) 
    			dp[i + 1][j + 1] = dp[i][j] + 1, pr[i + 1][j + 1] = {i, j};
    	}
    string ans = "";
    ii cur = {sz(s), sz(h)};
    while (pr[cur.fi][cur.se].fi != -1) {
		int x = pr[cur.fi][cur.se].fi;
		int y = pr[cur.fi][cur.se].se;
		if (x == cur.fi - 1 && y == cur.se - 1) ans += s[x];
		cur = {x, y};    	
    }
    reverse(all(ans));
    cout << ans;
	return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, r[200000], Max = -999999999, Min;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  Min = r[0];
  for (int i = 1; i < n; i++) {
    Max = max(r[i] - Min, Max);
    Min = min(r[i], Min);
  }
  cout << Max << '\n';
  return 0;
}



Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int w1 = 0, w2 = w, h1 = 0, h2 = h;
    rep(i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1) w1 = max(w1, x);
        if(a == 2) w2 = min(w2, x);
        if(a == 3) h1 = max(h1, y);
        if(a == 4) h2 = min(h2, y);
        }

        cout << max(w2 - w1, 0) * max(h2 - h1, 0) << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>

#include <vector>
using namespace std;

template <class T = long long>
class Union_Find {
  using size_type = std::size_t;
  using _Tp = T;
public:

  vector<_Tp> par;

  const _Tp & operator[] (size_type child) {
    return -par[root(child)];
  }

  Union_Find(size_type n) : par(n, -1) {}
  void init(int n) {
    par.assign(n, -1);
  }

  _Tp root(size_type x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool issame(size_type x, size_type y) {
    return root(x) == root(y);
  }

  bool merge(size_type x, size_type y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  _Tp size(int x) {
    return -par[root(x)];
  }
};

// verify ABC120_D Decayid Bridge
 
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  Union_Find<long long> uf(n);
 
  vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    a[i] -= 1; b[i] -= 1;
  }
  long long con = (n * (n-1)) / 2;
  vector<long long> comf;
 
  for (int i = m - 1; i >= 0; --i) {
    comf.push_back(con);
    if (uf.issame(a[i], b[i])) {
      continue;
    }
    long long ta = uf.size(a[i]), tb = uf.size(b[i]);
    con -= ta * tb;
    uf.merge(a[i], b[i]);
  }
 
  for (int i = m - 1; i >= 0; --i) {
    cout << comf[i] << endl;
  }
}


Measured memory_bytes: 3828
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ship_list1 = []
ship_list2 = []
count = 0
loop = False

for i in range(m):
    if ab[i][0] == 1:
        ship_list1.append(ab[i][1])
    if ab[i][1] == n:
        ship_list2.append(ab[i][0])

if len(set(ship_list1) & set(ship_list2)) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 61152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;

    if(s == u)
        cout << a - 1 << " " << b << endl;
    else
        cout << a << " " << b - 1 << endl;
  
    return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}
ll k;
ll cnt;
vector<string> ANS;

bool cust(string& a,string& b){
    if(a.size() != b.size())
        return a.size() < b.size();
    return a.compare(b) <= 0;
}

void go(ll prev,string& a){
    if(a.size() > 11)
        return;
    if(prev != -1){
        ANS.pb(a);
    }
    if(cnt >= 1e8)
        return;
    if(prev == -1){
        for(ll i=1;i<10;i++){
            char ch = '0' + i;
            cnt++;
            string tmp = a + ch;
            go(i,tmp);
        }
    }
    else{
        char ch = '0' + prev;
        if(prev != 0){
            ch--;
            cnt++;
            string tmp = a + ch;
            go(prev-1,tmp);
        }
        ch = '0' + prev;
        cnt++;
        string tmp = a + ch;
        go(prev,tmp); 
        if(prev != 9){
            ch++;
            cnt++;
            string tmp = a + ch;
            go(prev+1,tmp);
        }
    }
}

void solve(){
    cin>>k;
    string a;
    go(-1,a);
    sort(ANS.begin(),ANS.end(),cust);
    // int ind=-1;
    // for(ll i=0;i<ANS.size();i++)
    //     if(ANS[i] == "3234566667")
    //         ind  = i;
    // cout << ind << " "; 
    cout << ANS[k-1];
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 42472
#include<stdio.h>
int main(void)
{
  int a,b,c,i,d=0;
   scanf("%d%d%d", &a,&b,&c);
        for(i=0; i<c; i++){
         if (b >= a) b = b - a;
          else d++;}
        printf("%d",i-d);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

struct edge {
  i64 a, b, c, d;
};
i64 N, M;
vector<vector<edge>> G(10);
i64 res = 0;
void dfs(i64 i, i64 next, std::vector<i64>& A, i64 ans) {
  if(i == N) {
    res = std::max(res, ans);
    return;
  }
  rep(n, next, M) {
    i64 sum = ans;
    A[i] = n;
    for(auto e: G[i]) {
      if(A[e.b] - A[e.a] == e.c) sum += e.d;
    }
    dfs(i + 1, n, A, sum);
  }
}
int main() {
  i64 Q;
  cin >> N >> M >> Q;
  rep(i,0,Q) {
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    G[b].push_back({ a, b, c, d });
  }
  vector<i64> A(N);
  dfs(0, 0, A, 0);
  cout << res << endl;
}


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

int main() {
    uint64_t N, K;
    std::cin >> N >> K;

    uint64_t cnt[100000+1] = {0};
    uint64_t a, b;

    for (size_t i = 0; i < N; ++i) {
        std::cin >> a >> b;
        cnt[a] += b;
    }

    size_t cur = 0;
    for (size_t i = 1; i < 100001; ++i) {
        cur += cnt[i];
        if (K <= cur) {
            std::cout << i << std::endl;
            return 0;
        }
    }

    return 0;
}


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

int main(){
  char n ;
  cin>>n;
  if(n=='A')
    cout<<'T'<<endl;
    else if(n=='T')
    cout<<'A'<<endl;
    else if(n=='C')
    cout<<'G'<<endl;
    else if(n=='G')
    cout<<'C'<<endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    string s;
    cin >> s;
    int n = s.length();
    if (s[n-1] == 's') {
        s+="e";
    }
    s += "s";
    cout << s << endl;
    return 0;
}      

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDSk

using namespace std;



int main(){
       
     LL N,M;
     SL(N); SL(M);
     LL ans = (N*(N-1))/2;
     ans += (M*(M-1))/2;
     cout<<ans<<endl;

return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int n,m;

inline int lucas(int x,int y){
   if(y < 2){
      if(y == 0)return 1;
      else return x%2;
   }
   return 1LL*lucas(x/2,y/2)*lucas(x%2,y%2)%2;
}

int a[N],b[N];
int main(){
   scanf("%d\n",&n);
   fr(i,1,n){
      char ch; ch = getchar();
      a[i] = ch-'0';
   }
   fr(i,1,n-1)b[i] = a[i+1] >= a[i] ? a[i+1]-a[i] : a[i]-a[i+1];
   --n;

   int res1 = 0;
   fr(i,1,n){
      res1 ^= lucas(n-1,i-1)*(b[i]%2);
   }
   if(res1 == 1)puts("1");
   else {
      fr(i,1,n){
         if(b[i] == 1){
            puts("0"); return 0;
         }
      }
      int res2 = 0;
      fr(i,1,n){
         res2 ^= lucas(n-1,i-1)*((b[i]/2)%2);
      }
      if(res2){
         puts("2");
      } else puts("0");
   }
   return 0;
}


Measured memory_bytes: 8064
#include<iostream>

using namespace std;

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

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

int main() {
  string S2, T;
  cin >> S2 >> T;

  if (S2.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  int sub = S2.size() - T.size();
  vector<string> S;

  for (int i=0; i<=sub; i++) {
    bool unlock = true;
    rep(j,T.size()) {
      if (S2[i+j] != '?' && S2[i+j] != T[j]) {
        unlock = false;
        break;
      }
    }
    if (unlock) {
      string ans = S2;
      rep(j,T.size()) {
        ans[i+j] = T[j];
      }
      rep(k,ans.size()) {
        if (ans[k] == '?') ans[k] = 'a';
      }
      S.push_back(ans);
    }
  }

  if (S.empty()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  sort(S.begin(), S.end());
  cout << S[0] << endl;
  return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(random_device{}());

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> pos[3];
    forn(i,n){
        char ch;
        cin>>ch;
        if(ch=='R') pos[0].push_back(i);
        else if(ch=='G') pos[1].push_back(i);
        else pos[2].push_back(i);
    }
    vector<int> perm{0,1,2};
    ll ans=0;
    do{
        for(auto i:pos[perm[0]]){
            auto j=lower_bound(all(pos[perm[1]]),i);
            for(;j!=pos[perm[1]].end();++j){
                ans+=pos[perm[2]].end()-lower_bound(all(pos[perm[2]]),*j);
                if(binary_search(all(pos[perm[2]]),2*(*j)-i)) ans--;
            }
        }
    }while(next_permutation(all(perm)));
    cout<<ans;
    return 0;
}



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

int main(void){

    int N,L; cin>>N>>L;
    int aji, zenbu=0;
    int mininmum=500;
    for (int i = 1; i <= N; ++i) {
        aji=L+i-1;
        zenbu += aji;
        if(abs(mininmum) > abs(aji)) mininmum = aji;
    }

    cout<<zenbu-mininmum<<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 n = sc.nextInt();
        int[] a = new int[n];

        while (sc.hasNext()) {
            int s = sc.nextInt();
            a[s-1]++;
        }

        for (int i=0;i<n;i++) {
            System.out.println(a[i]);
        }
    }
}


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

const int INF = 1001001001;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n, INF));
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    if (c > l) continue;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k, n) rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
  vector<vector<int>> dist2(n, vector<int>(n, INF));
  rep(i, n) rep(j, n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(k, n) rep(i, n) rep(j, n) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);
  int q;
  cin >> q;
  rep(qi, q) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    int ans = dist2[s][t] - 1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin>>s;
    int l=s.length();
    int a=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            a++;
        }
    }
    if(a==0 || a==l)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }
    
    return 0;
}    

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

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

int n;

std::vector<std::vector<int>> vec, dp;

int main() {
    std::cin >> n;
    vec.assign(n, std::vector<int>(3, 0));
    dp.assign(n+1, std::vector<int>(3, 0));
    
    for (int i = 0; i < n; i++) {
        for (int p = 0; p < 3; p++) {
            std::cin >> vec[i][p];
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int p = 0; p < 3; p++) {
            for (int j = 0; j < 3; j++) {
                if (p == j)
                    continue;
                chmax(dp[i+1][j], dp[i][p] + vec[i][j]);
            }
        }
    }
    int u = 0;
    for (int i = 0; i < 3; i++) {
        if (dp[n][i] > u) {
            u = dp[n][i];
        }
    }
    std::cout << u << std::endl;
}


Measured memory_bytes: 11136
n,k,q = map(int,input().split())
# N人がK点持っており、Q回クイズが行われた

A = [int(input()) for i in range(q)]
# Aは正解者のリスト

### 最終的に１点以上持っている人がＯＫ

# 正解している人に点数をプラス
score = [k-q]*n
for i in range(q):
    score[A[i]-1] += 1

### 出力は i さんが ＯＫ ならYes, Fail なら NO

for i in range(n):
    if(score[i] >= 1):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10472
import numpy as np

n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
min = np.inf

for i in range(1, x[-1]+1):
    total = 0
    for j in x:
        total += (j-i)**2
    if total < min:
        min = total

print(min)

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int actr = a/d;
	int cctr = c/b;
	if(a%d !=0) actr++;
	if(c%b !=0) cctr++;
	if (actr >= cctr) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int H,W,h,w,a[1111][1111],sum;
int main(){
	cin>>H>>W>>h>>w;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			a[i][j]=1000;
		}
	}
	for(int i=h;i<=H;i+=h){
		for(int j=w;j<=W;j+=w){
			a[i][j]=-((h*w-1)*1000+1);
		}
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			sum+=a[i][j];
		}
	}
	if(sum<=0){
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(j!=1)cout<<" ";
			cout<<a[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 5632
n, k = gets.split.map &:to_i
snukes = n.times.map {true}
count = n
k.times do
  d = gets.to_i
  a = gets.split.map &:to_i
  a.each do |s|
    if snukes[s-1]
      count -= 1
      snukes[s-1] = false
    end
  end
end

p count

Measured memory_bytes: 14284
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
lol w[111],v[111];
lol mem[111][111111];
lol dp(int n,int m){
    if(n==a) return 0;
    if(mem[n][m]!=-1) return mem[n][m];
    if(m+w[n]>b) return mem[n][m]=dp(n+1,m);
    return mem[n][m]=max(dp(n+1,m+w[n])+v[n],dp(n+1,m));
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  string s;
  cin >>a>>b;
  for(int n=0;n<a;n++){
      cin >>w[n]>>v[n];
  }
  memset(mem,-1,sizeof(mem));
  cout <<dp(0,0)<<'\n';
  return (0);
}


Measured memory_bytes: 96640
fun main(args:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val input = readLine()!!.trim()

    val toRight = (1..itemCount).map { 0 }.toMutableList()
    val toLeft = (1..itemCount).map { 0 }.toMutableList()

    for(i in input.indices) {
        var n = if(i>0) toRight[i-1] else 0
        if(input[i] == 'E') {
            n++
        }
        toRight[i] = n
    }

    for(i in input.indices.reversed()) {
        var n = if(i == input.lastIndex) 0 else toLeft[i+1]
        if(input[i] == 'W') {
            n++
        }
        toLeft[i] = n
    }

    var ans = 0
    for(i in input.indices) {
        var tmp = 1
        if(i > 0) {
            tmp += toRight[i-1]
        }
        if(i < input.lastIndex) {
            tmp += toLeft[i+1]
        }
        ans = Math.max(ans, tmp)
    }
    ans = itemCount - ans
    println(ans)
}




Measured memory_bytes: 53136
#include <iostream>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>

#include <boost/range/algorithm.hpp>

using namespace std;

void getMaxMin(vector<int>& v,int& max,int& min)
{
  boost::sort(v);
  max = (v.back());
  min = (v.front());
}

long long int getSum(vector<int>& v)
{
  long long int sum = 0;
  for(int value: v)
  {
    sum += value;
  }
  return sum;
}

int main(int argc,char* argv[])
{
  int num,input,max,min;
  long long int sum;
  vector<int> inputs;
  cin >> num;
  for(int i=0;i<num;i++)
  {
    cin >> input;
    inputs.push_back(input);
  }
  getMaxMin(inputs,max,min);
  sum = getSum(inputs);
  cout << min << " " << max << ' ' << sum << endl;
}

Measured memory_bytes: 3248
import math

N = int(input())
P = [True for x in range(N + 3)]

P[0] = False
P[1] = False

for i in range(2, int(math.sqrt(N + 3)) + 1):
    if P[i]:
        for j in range(i * 2, N + 3, i):
            P[j] = False

count = 0

for q in range(3, N + 1):
    if P[q] and P[2 + q]:
        count += 2

print(count)



Measured memory_bytes: 84480
#!/usr/bin/python3
import math

(a, b) = map(int, input().split())

ll = max(math.ceil(100 * a / 8), 10 * b)
up = min(math.ceil(100 * (a + 1) / 8), 10 * (b + 1))

if ll < up:
    print(ll)
else:
    print(-1)


Measured memory_bytes: 3060
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int INF=1000000007;
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=Integer.parseInt(sc.next());
		int l[]=new int[N];
		for(int i=0;i<N;i++) {
			l[i]=Integer.parseInt(sc.next());
		}
		Arrays.sort(l);
		int ans=0;
		for(int a=0;a<N;a++) {
			for(int b=a+1;b<N;b++) {
				for(int c=b+1;c<N;c++) {
					if(l[a]<l[b]+l[c])if(l[b]<l[a]+l[c])if(l[c]<l[a]+l[b])ans++;
					else break;
				}
			}
		}
		p(ans);
	
	}
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


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

int main()
{
    string s;
    cin>>s;
    if(s=="SUN") cout<<7;
    else if(s=="MON") cout<<6;
    else if(s=="TUE") cout<<5;
    else if(s=="WED") cout<<4;
    else if(s=="THU") cout<<3;
    else if(s=="FRI") cout<<2;
    else cout<<1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	char[] c1 = sc.next().toCharArray();
    	char[] c2 = sc.next().toCharArray();
    	sc.close();
    	boolean ans = false;
    	if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) ans = true;
    	System.out.println(ans ? "YES" : "NO");
    }
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, D;

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

    std::cin >> N >> D;

    int g = 0;

    for(int i=0;i<N;++i){
        int A;
        std::cin >> A;

        g ^= (A - 1) % (D + 1);
    }

    if(g != 0){
        std::cout << "First" << std::endl;
    }else{
        std::cout << "Second" << std::endl;
    }
}



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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  if(k<=a){
    cout<<a-k<<" "<<b<<endl;
    return 0;
  }else{
    cout << 0 << " " << max(b - (k-a), (ll)0) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
 
money = 1000
stock = 0
 
for i in range(n-1):
  if a[i+1] > a[i]:
    stock = money // a[i]
    money = money - stock*a[i] + stock*a[i+1]
 
print(money)

Measured memory_bytes: 9184
N = int(input())
a = list(map(int,input().split()))
c_4 = 0
c_2 = 0
c_O = 0
for e in a:
    if e % 4 == 0:
        c_4 += 1
    elif e % 2 == 0:
        c_2 += 1
    else:
        c_O += 1
if c_2 > 0:
    c_O += 1
if c_O <= c_4 + 1:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   Vi         = vector<int>;
using   Pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

constexpr int MAX_VAL = 80*160 + 10;

int elems[81][81];
bitset<MAX_VAL*2> dp[81][81];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(18);

	int h, w; cin >> h >> w;

	rep(i, 0, h) rep(j, 0, w) cin >> elems[i][j];

	rep(i, 0, h) rep(j, 0, w) {
		int k; cin >> k;
		elems[i][j] = abs(elems[i][j]-k);
	}

	dp[0][0].set(MAX_VAL+elems[0][0]);
	dp[0][0].set(MAX_VAL-elems[0][0]);

	rep(i, 0, h) rep(j, 0, w) {
		if (i == 0 && j == 0) continue;
		bitset<MAX_VAL*2> tmp;

		if (i > 0) tmp = dp[i-1][j];
		if (j > 0) tmp |= dp[i][j-1];

		int e = elems[i][j];
		dp[i][j] = (tmp << e) | (tmp >> e);
	}

	int ans = INT_MAX;

	rep(i, 0, MAX_VAL*2) {
		if (dp[h-1][w-1][i]) {
			ans = min(ans, abs(i-MAX_VAL));
		}
	}

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


Measured memory_bytes: 20736
n=gets.to_i
p=gets.split.map(&:to_f)

p p.inject([1]){|dp,pi|
  rpi = 1-pi
  dp.each_with_object([0]*(dp.size+1)).with_index{|(ai,newdp),j|
    newdp[j] += ai * rpi
    newdp[j+1] += ai * pi
  }
}[-n/2..-1].inject(:+)

Measured memory_bytes: 3484
S=list(input())

Rbuff = []
Lbuff = []

#print(S)
B = [0]*len(S)

RLposi = None
for c in range(len(S)):
    if c == 0:
        Rbuff.append(c)
    else:
        if c != len(S)-1 and S[c] + S[c+1] == 'RL':
                B[c] += 1
        elif S[c-1] + S[c] == 'RL':
            RLposi = c
            B[c] += 1
            if Rbuff != []:
                for r in Rbuff:
                    if abs(c - r)%2 == 0:
                        B[c] += 1
                    else:
                        B[c-1] += 1
                Rbuff = []
        elif S[c] == 'R':
            Rbuff.append(c)
        elif S[c] == 'L':
            if RLposi is not None:
                if (c - RLposi)%2 == 0:
                    B[RLposi] += 1
                else:
                    B[RLposi-1] += 1
print(' '.join(map(str,B)))

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

const int maxn = 110, P = 1000000007;
int n, a[maxn];

int qp(int x, int y) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    function<pair<int, int>(int, int, int)> solve = [&](int l, int r, int lst) {
        int x = *min_element(a + l, a + r + 1);
        int coef = 1, sum = 1, num = r - l + 1;
        for (int i = l, j; i <= r; i++) if (a[i] ^ x) {
            for (j = i; a[j] ^ x && j <= r; j++) num--;
            auto p = solve(i, j - 1, x); i = j;
            coef = 1LL * coef * p.first % P;
            sum = 1LL * sum * (p.first + p.second) % P;
        }
        return pair<int, int>(1LL * coef * qp(2, x - lst) % P,
            (1LL * sum * qp(2, num) + 1LL * coef * (qp(2, x - lst) - 2) % P) % P);
    };
    auto p = solve(1, n, 0);
    printf("%d\n", (p.second + P) % P);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N + 1)]

for n in range(N):
	for j in range(3):
		for k in range(3):
			if j == k:
				continue
			dp[n + 1][j] = max([dp[n + 1][j], dp[n][k] + ABC[n][j]])
	#print(dp)
print(max(dp[N]))


Measured memory_bytes: 47320
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    if (s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  n,m = readint()
  H = readint()
  G = ones(int,n)
  for i in 1:m
    a,b = readint()
    h1 = H[a]
    h2 = H[b]
    if h1 > h2
      G[b] = 0
      elseif h2 > h1
        G[a] = 0
      else
        G[a] = 0
        G[b] = 0
      end
  end
  println(sum(G))

end

main()

Measured memory_bytes: 242736
MOD = 1000000007
n = int(raw_input())
d = {}
for i, ai in enumerate(int(_) for _ in raw_input().split()):
    if ai in d:
        stt = d[ai]
        end = i
        break
    d[ai] = i
del d, i, ai

fac = {0: 1}
facinv = {}
for i in xrange(1, n + 2):
    fac[i] = fac[i - 1] * i % MOD
facinv[n + 1] = pow(fac[n + 1], MOD - 2, MOD)
for j in xrange(n, -1, -1):
    facinv[j] = facinv[j + 1] * (j + 1) % MOD


def ncr(n, r):
    return (fac[n] * facinv[n - r] * facinv[r]) % MOD


l = stt
r = n - end

for k in xrange(1, n + 2):
    a = ncr(n + 1, k) % MOD
    if l + r >= k - 1:
        a -= ncr(l + r, k - 1) % MOD
    print a % MOD


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

int main(){
    string s;
    int win=0;

    cin >>s;
    for (int i = 0; i < s.length(); i++){
        if(s[i]=='o')win++;
    }
    

    if (win + (15-s.length()) >= 8)
    {
        cout << "YES" <<endl;
    }
    else
    {
        cout << "NO" <<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
// CODE BY: kort0n

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
typedef pair<ll, l_l> lll;
ll dp[50][10001];
ll C[105], D[105];
const ll MaxS = 10000;
ll N, M, S;
vector<lll> paths[50];

void Dijkstra() {
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= MaxS; j++) {
            dp[i][j] = 1e18;
        }
    }
    dp[0][S] = 0;
    priority_queue<lll, vector<lll>, greater<lll>> que;
    que.push({0, {0, S}});
    while(!que.empty()) {
        auto tmp = que.top();
        que.pop();
        ll nowpos = tmp.second.first;
        ll nows = tmp.second.second;
        ll nowcost = tmp.first;
        //cerr << nowpos << " " << nows << " " << nowcost << endl;
        for(auto tmp : paths[nowpos]) {
            ll to = tmp.first;
            ll newcost = tmp.second.second + nowcost;
            ll news = nows - tmp.second.first;
            if(news >= 0) {
                if(chmin(dp[to][news], newcost)) {
                    que.push({newcost, {to, news}});
                }
            }
        }
        ll newcost = nowcost + D[nowpos];
        ll news = nows + C[nowpos];
        chmin(news, MaxS);
        if(chmin(dp[nowpos][news], newcost)) {
            que.push({newcost, {nowpos, news}});
        }
    }
}

int main() {
    cin >> N >> M >> S;
    chmin(S, MaxS);
    for(int i = 0; i < M; i++) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        paths[u].push_back({v, {a, b}});
        swap(u, v);
        paths[u].push_back({v, {a, b}});
    }
    for(int i = 0; i < N; i++) cin >> C[i] >> D[i];
    Dijkstra();
    for(int i = 1; i < N; i++) {
        ll ans = 1e18;
        for(int j = 0; j <= MaxS; j++) {
            chmin(ans, dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 19356
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int a[105],b[105];
int main(){
    ll n,ans=0;cin>>n;
    for(ll i=1;i<=n;i++){
        ans+=(n-1)/i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
S = input()
K = int(input())

ls = len(S)

moreWriteNeeded = False

if S[0] == S[ls-1]:

    i = 1
    while i < ls and S[i] == S[0]:
        i += 1

    if i == ls:
        print((ls * K) // 2)
        exit()

    if i % 2 == 1:
        i = 1
        while S[ls - i - 1] == S[0]:
            i += 1

        if i % 2 == 1:
            moreWriteNeeded = True

write = 0

last = "Z"
for c in S:
    if last == c:
        last = "Z"
        write += 1
    else:
        last = c

ans = K * write if not moreWriteNeeded else K * write + K - 1

print(ans)

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

int main(){
 set<int> s;
  int n,a,b,c;
  cin >> n;
  while(n--){
    cin >> a>>b;
    if(!a){
      s.insert(b);
      cout << s.size() <<endl;
    }
    else if(a==1)cout << s.count(b) << endl;
    else if(a==2)s.erase(b);
    else{
      cin >> c;
      auto it=s.lower_bound(b),end=s.upper_bound(c);
      for(;it!=end;it++){
        cout << *it<<endl;
      }
    }
}
}


Measured memory_bytes: 12408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  int ans=100000000;
  for(int i=a[0];i<=a[n-1];i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=(i-a[j])*(i-a[j]);
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoderSolve
{
    class Solve
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Math.Max(p[0] - p[1], 0));

            Console.Out.Flush();
        }
    }
}


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

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

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x;
  cin >> x;
  
  if(x % 11 == 0)
    cout << x / 11 * 2 << endl;
  else if(x % 11 <= 6)
    cout << x / 11 * 2 + 1 << endl;
  else
    cout << x / 11 * 2 + 2 << endl;

  
  
}


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
        String[] alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q",
                                        "r","s","t","u","v","w","x","y","z"};
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        ArrayList<Integer> list = new ArrayList<>();
        while(n>26){
            if(n%26==0){
                list.add(25);
                n=n/26-1;
            } else {
                list.add((int)(n%26-1));
                n/=26;
            }
        }
        System.out.print(alphabet[(int)n-1]);
        for(int i = list.size()-1;i>=0;i--){
            System.out.print(alphabet[list.get(i)]);
        }
    }
}


Measured memory_bytes: 35820
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nm = sc.nextLine().split(" ");
        int n = Integer.parseInt(nm[0]);// スイッチの種類
        int m = Integer.parseInt(nm[1]);// 電球の数

        List<List<Integer>> k = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            List<Integer> ele = new ArrayList<>();
            String[] a = sc.nextLine().split(" ");
            for (int j = 1; j < a.length; j++) {
                ele.add(Integer.valueOf(a[j]) - 1);
            }
            k.add(ele);
        }
        List<Integer> p = new ArrayList<>();
        for (String s : sc.nextLine().split(" ")) {
            p.add(Integer.valueOf(s));
        }

        int ans = 0;
        for (int i = 0; i < (Math.pow(2, n)); ++i) {
            boolean ok = true;
            for (int j = 0; j < m; ++j) {
                int c = 0;
                for (int id : k.get(j)) {
                    if ((1 & i >> id) == 1) {
                        ++c;
                    }
                }
                c %= 2;
                if (c != p.get(j)) {
                    ok = false;
                }
            }
            if (ok) {
                ++ans;
            }
        }
        System.out.println(ans);
    }
}

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


int main(){
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> grid(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> grid.at(i).at(j);
    }
  }
  
  vector<vector<int>> best(H, vector<int>(W));
  
  if(W == 1){
    if(H == 1){
      if(grid.at(0).at(0) == '#'){
        cout << 1 << endl;
        return 0;
      }else{
        cout << 0 << endl;
        return 0;
      }
    }
    else{
      int count = 0;
      for(int i = 0; i < H - 1; i++){
        if(grid.at(i).at(0) != grid.at(i+1).at(0)){
          count++;
        }
      }
      if(grid.at(0).at(0) == '#'){
        count++;
      }
      cout << count << endl;
      return 0;
    }
  }
  
  for(int i = W - 2; i >= 0; i--){
    if(grid.at(H-1).at(i) != grid.at(H-1).at(i+1) && grid.at(H-1).at(i) == '.'){
      best.at(H-1).at(i) = best.at(H-1).at(i+1) + 1;
    }else{
      best.at(H-1).at(i) = best.at(H-1).at(i+1);
    }
  }
  int i = H - 2;
  while(i >= 0){
    for(int j = W - 1; j >= 0; j--){
      int count = 0;
      
      if(grid.at(i).at(j) != grid.at(i+1).at(j) && grid.at(i).at(j) == '.'){
        best.at(i).at(j) = best.at(i+1).at(j) + 1;
      }else{
        best.at(i).at(j) = best.at(i+1).at(j);
      }
      if(j != W - 1){
        if(grid.at(i).at(j) != grid.at(i).at(j+1) && grid.at(i).at(j) == '.'){
          count = best.at(i).at(j+1) + 1;
        }else{
          count = best.at(i).at(j+1);
        }
        best.at(i).at(j) = min(best.at(i).at(j), count);
      }
    }
    
    i--;
  }
  
  if(grid.at(0).at(0) == '#'){
    best.at(0).at(0) ++;
  }
  
  cout << best.at(0).at(0) << endl;
}

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

int main() {
    int a[5], k;
    rep(i, 5) cin >> a[i];
    cin >> k;

    bool ok = true;

    rep(i, 5) {
        for (int j = i+1; j < 5; j++) {
            if (abs(a[i]-a[j]) > k) ok = false;
        }
    }

    if (ok) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;

int countDigit(long long n) 
{ 
    return floor(log10(n) + 1); 
} 

int main() {
	ll n;
	cin>>n;
	ll arr[n],brr[n],flag=0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		brr[i]=arr[i];
	}	
	sort(arr,arr+n);
	for(ll i=0;i<n;i++)
	{
		if(brr[i]-1>arr[i])
		{
			cout<<"No";
			flag=1;
			break;
		}
	}
	if(flag==0)
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,x,i,y,ans=0;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main()
{
	scanf("%d%d",&n,&x);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&y);
		ans=gcd(ans,abs(x-y));
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  bool can = true;
  int length = S.size();
  int cnt_C = 0;
  if (S[0] != 'A') can = false;
  if ((int)S[1] - 97 < 0) can = false;
  if ((int)S[length-1] - 97 < 0) can = false;
  if (can) {
    for (int i = 2; i < length-1; i++) {
      if (S[i] == 'C') cnt_C++;
      else {
        if ((int)S[i] - 97 < 0) {
          can = false;
          break;
        }
      }
    }  
  }
  if (cnt_C != 1) can = false;
  
  if (can) cout << "AC";
  else cout << "WA";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e5+5;
int fa[maxn];
struct Node{
  ll x, y, id;
}st[maxn];
 
struct Edge{
  ll cost, p1, p2;
}edge[maxn*2];
 
int cmp1(Node a,Node b){ 
	return a.x<b.x; 
}
int cmp2(Node a,Node b){ 
	return a.y<b.y; 
}
int cmp3(Edge a,Edge b){ 
	return a.cost<b.cost; 
}
 
int find(int u){
  	if(fa[u]==u) 
  		return fa[u];
  	return fa[u]=find(fa[u]);
}
 
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
		scanf("%lld%lld", &st[i].x, &st[i].y); 
		st[i].id=i; 
		fa[i]=i;
	}
    sort(st+1,st+1+n,cmp1);
    int cnt=0;
    for(int i=2;i<=n;i++){
        edge[++cnt].p1=st[i-1].id;
        edge[cnt].p2=st[i].id;
        edge[cnt].cost=st[i].x-st[i-1].x;
    }
    sort(st+1,st+1+n,cmp2);
    for(int i=2;i<=n;i++){
        edge[++cnt].p1=st[i-1].id;
        edge[cnt].p2=st[i].id;
        edge[cnt].cost=st[i].y-st[i-1].y;
    }
    sort(edge+1,edge+1+cnt,cmp3);
    ll ans=0;int num=0;
    for(int i=1;i<=cnt;i++){
        int fa_p1=find(edge[i].p1);
        int fa_p2=find(edge[i].p2);
        if(fa_p1==fa_p2) 
			continue;
        else{
            fa[fa_p1]=fa_p2;
            num++;
            ans+=(edge[i].cost);
        }
        if(num==n-1) break;
    }
    printf("%lld\n",ans);
    return 0;
}


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

Measured memory_bytes: 4768