akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long

using namespace std;

vector<int> e;

inline int solve(vector<int> &arr) {
	int ans = 0;
	int n = (int)arr.size();
	for(int i = 0; i < n; i++) {
		if(e[n - 1] == e[n - i - 1] + e[i]) {
			ans = (ans + arr[i]) % 2;
		}
	}
	return ans;
}

int main() {
#ifdef HOME
    ifstream cin("B.in");
    ofstream cout("B.out");
#endif
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string str; cin >> n >> str;
    vector<int> arr(n);
    for(i = 0; i < n; i++) {
    	arr[i] = str[i] - '1';
    }
    e.resize(n);
    for(i = 1; i < n; i++) {
    	e[i] = e[i - 1];
    	int cur = i, cnt = 0;
    	while(cur % 2 == 0) {
    		cur /= 2;
    		cnt++;
    	}
    	e[i] += cnt;
    }

    if(solve(arr) == 1) {
    	cout << 1;
    	return 0;
    }
    for(i = 0; i < n; i++) {
    	if(arr[i] == 1) {
    		cout << 0;
    		return 0;
    	}
    }
    for(i = 0; i < n; i++) {
    	arr[i] /= 2;
    }
    cout << 2 * solve(arr);

    return 0;
}


Measured memory_bytes: 9116
n = int(input())

t = []
t = list(map(int, input().split()))

count = 0
min = t[0]

for i in t:
    if i <= min:
        count = count + 1
        min = i
#        print("c:{}".format(i))
#    else:
#        print("NG:{}".format(i))
        
print(count)

Measured memory_bytes: 24744
#include<stdio.h>

int main(void)
{
   int  n, d[50], i, f, s=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
      scanf("%d",&d[i]);

   for(i=0;i<n-1;i++)
      for(f=i+1;f<n;f++)
         s+=d[i]*d[f];

   printf("%d\n",s);
   return 0;
}

Measured memory_bytes: 128
/*Filename: aoj0014.cpp
 *Author: Mushiyo
 */

#include <iostream>

using namespace std;

int main(){
	int d = 0;

    while(cin >> d){
    	int s = 0;

        for(int i = d; i < 600; i += d){
        	s += d * (i * i);
        }
        
        cout << s << endl;
    }

	return 0;
}

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

using namespace std;

int main() {
    int H, W, N, ele;
    cin >> H >> W >> N;
    int a[H][W];
    int k = 0;
    for(int i = 1; i < N+1; i++){
        cin >> ele;
        for(int j = k; j < k+ele; j++){
            a[j/W][abs((j/W % 2)*(W-1)-(j % W))] = i;
        }
        k +=ele;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(ll i=0;i<N;++i)
const ll INF = 1LL<<60;

int F[105][10];
int P[105][11];

int main(){
    ll N; cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            cin >> F[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<11;j++){
            cin >> P[i][j];
        }
    }
    ll ans = -INF;
    for(int bit=1;bit < (1<<10);bit++){
        ll sum = 0;
        for(int i=0;i<N;i++){
            ll cnt = 0;
            for(int j=0;j<10;j++){
                if((bit>>j & 1) && F[i][j]) cnt ++;
            }
            sum += P[i][cnt];
        }
        ans = max(ans,sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
abc = []
ia, ib, ic = map(int, input().split())
for _ in range(n-1):
    a, b, c = map(int, input().split())
    abc.append((a, b, c))

dp = [ia, ib, ic]

for a, b, c in abc:
    newdp = [None]*3
    newdp[0] = max(dp[1], dp[2]) + a
    newdp[1] = max(dp[2], dp[0]) + b
    newdp[2] = max(dp[0], dp[1]) + c
    dp = newdp

print(max(dp))

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = (c + (b - 1)) / b;
  int y = (a + (d - 1)) / d;
  cout << (y>=x?"Yes":"No") << endl;
  return 0;
}

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

int cnt_circle_cross(int n, string s) {
    bool is_testing = true;
    int result = 0;
    for (int i = 1; i < n; i++)
        if (is_testing) {
            if (s[i - 1] != s[i]) {
                result++;
                is_testing = false;
            }
        } else
            is_testing = true;
    return result;
}

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

    const int val = cnt_circle_cross(n, s);

    cout << val << endl;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
#define fr(i, n) for (ll i = 0; i < n; ++i)
#define frab(i, a, b) for (ll i = a; i < b; ++i)
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e9 + 7;
const int M = 105;
const ld PI = acos(-1);
const int POW = 42;
const ll MOD = 1000 * 1000 * 1000 + 7;

const int N = 1e6 + 5;

bool check(string &s) {
    bool fnd = false;
    fr(i, s.size()) {
        if (s[i] != s[0]) fnd = true;
    }
    return !fnd;
}

int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;

    if (check(s)) {
        cout << 0;
        return 0;
    }

    int ans = INF;
    frab(ch, 'a', 'z' + 1) {
        bool fnd = false;
        fr(i, s.size())
            if (s[i] == ch)
                fnd = true;
        if (!fnd) continue;
        string s1 = s;
        while (true) {
            string t;
            fr(i, (int)s1.size() - 1)
                if (s1[i] == ch || s1[i + 1] == ch)
                    t += ch;
                else
                    t += s1[i];
            if (check(t)) {
                ans = min(ans, (int)s.size() - (int)t.size());
                break;
            }
            s1 = t;
        }
    }

    cout << ans;



}


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

int main()
{
	char inputS[11], inputT[11], inputU[11];
	int redBallsNum, blueBallsNum;

	scanf("%s %s", inputS, inputT);
	scanf("%d %d", &redBallsNum, &blueBallsNum);
	scanf("%s", inputU);

	// Compare inputed strings and if both have value 'red' then reduce number of red balls
	if (strcmp(inputU, inputS) == 0)
	{
		redBallsNum--;
	}
	// Compare inputed strings and if both have value 'blue' then reduce number of blue balls
	else if (strcmp(inputU, inputT) == 0)
	{
		blueBallsNum--;
	}

	printf("%d %d \n", redBallsNum, blueBallsNum);

	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<ll> getPositions(const string& s, ll k, ll c) {
  ll n = s.size();
  ll i = 0;
  vector<ll> ans;
  while (i < n && ans.size() < k) {
    if (s[i] == 'o') {
      ans.push_back(i);
      i += c+1;
    } else {
      ++i;
    }
  }
  return ans;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<ll> l = getPositions(s, k, c);
  reverse(all(s));
  vector<ll> r = getPositions(s, k, c);
  reverse(all(s)); // revert state
  rep(i, k) { r[i] = n-1-r[i]; } // update index of r. r is decreasing order.

  // Here, l and r are calculated.
  vector<ll> lastL(n+1, -1); // lastL[i] .. last position before i.
  rep(i, k) { lastL[l[i]+1] = i; }
  rep(i, n) {
    if (lastL[i+1] == -1) { lastL[i+1] = lastL[i]; }
  }
  vector<ll> lastR(n+1, -1); // lastR[i+1] .. last position after i.
  rep(i, k) { lastR[r[i]] = i; }
  for (int i = n-1; i >= 0; --i) {
    if (lastR[i] == -1) { lastR[i] = lastR[i+1]; }
  }

  vector<ll> ans;
  rep(i, n) {
    if (s[i] == 'x') { continue; }
    ll li = lastL[i]; // last position before i.
    ll ri = lastR[i+1]; // last position after i.
    ll cnt = 0; // maximum count without i.
    if (li != -1) { cnt += li + 1; }
    if (ri != -1) { cnt += ri + 1; }
    if (li != -1 && ri != -1 && (r[ri]-l[li] <= c)) {
      --cnt;
    }
    if (cnt >= k) { continue; } // we can make k without i
    ans.push_back(i);
  }

  for (int idx : ans) {
    cout << idx + 1 << endl;
  }
}


Measured memory_bytes: 9736
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64

signed main() {
  string s; cin>>s;
  vector<int> cnt(26,0);
  for(auto &&si: s){
    ++cnt[si-'a'];
  }

  for(int i=0;i<26;++i){
    if(cnt[i]>0) continue;
    // 文字コードで'a'からiだけずれている英小文字を出力
    printf("%c\n", 'a'+i);
    return 0;
  }
  cout<<"None"<<endl;
  return 0;
}


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

vector<int> dat;
int n;

int main(){
    int ans=0;
    cin>>n;
    dat=vector<int>(n);
    rep(i,n) cin>>dat[i];
    while(dat.size()){
        ans++;
        rep(i,dat.size()){
            if(dat[i]!=0){
                dat[i]--;
            }
            else if(i==0){
                dat.erase(dat.begin());
                i--;
                ans--;
                break;
            }
            else{
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int min(int a, int b){
    if(a<b){
        return a;
    }else{
        return b;
    }
}

int max(int a, int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

int p(int a){
    if(a<0){
        a=-a;
    }
    return a;
}

int main()
{
    int n,mn=-100,mx=100,ans=1000000000,sum;
    int a[100];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mn=min(mn,a[i]);
        mx=max(mx,a[i]);
    }
    if(mn==mx){
        cout << 0 << endl;
    }else{
        for(int i=mn;i<=mx;i++){
            sum=0;
            for(int j=0;j<n;j++){
                sum+=(i-a[j])*(i-a[j]);
            }
            ans=min(ans,sum);
        }
        cout << ans << 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++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's') {
    s += "es";
  } else {
    s += 's';
  }
  cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll modpow(ll m, ll p) {
    if (p == 0) return 1;
    ll tmp = modpow(m, p / 2);
    if (p & 1) return (tmp * tmp % MOD) * m % MOD;
    else return tmp * tmp % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y; cin >> x >> y;
    if ((x + y) % 3 != 0) cout << 0 << '\n';
    else {
        ll a = (2 * y - x) / 3, b = (2 * x - y) / 3;
        if (a < 0 || b < 0) {
            cout << 0 << '\n';
            return 0;
        }
        ll ab = a + b, ans = 1;
        for (ll i = ab; i > ab - min(a, b); i--) (ans *= i) %= MOD;
        for (ll i = 2; i <= min(a, b); i++) (ans *= modpow(i, MOD - 2)) %= MOD;
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int W=sc.nextInt();
		long[][] dp=new long[n+1][1000*n+1];
		Arrays.fill(dp[0],100000000001L);
		dp[0][0]=0;
		for(int i=1; i<=n; i++){
			int w=sc.nextInt();
			int v=sc.nextInt();
			for(int j=1000*n; j>=0; j--){
				if(j>=v){
					dp[i][j]=Math.min(dp[i-1][j],dp[i-1][j-v]+w);
				}else{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
		for(int i=1000*n; i>=0; i--){
			if(dp[n][i]<=W){
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 126292
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    ll n;
    cin >> n;
    int rt = sqrt(n);

    for (int i = rt; i > 0; i--) {
        if (n % i == 0) {
            cout << n / i + i - 2 << "\n";
            return 0;
         }
    }
    return 0;
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = c * d / gcd(c, d);

    ll ans = b - a + 1;
    ans -= b / c - (a - 1) / c;
    ans -= b / d - (a - 1) / d;
    ans += b / g - (a - 1) / g;
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N,i,count=0;
	scanf("%d",&N);
	int p[N];
	for(i=1;i<=N;i++){
		scanf("%d",&p[i]);
	}
	for(i=1;i<=N;i++){
		if(i!=p[i]){
			count++;
		}
	}
	if(count==0 || count==2){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void)
{
    int a,i,min=753;
    char c[20];
    gets(c);
    for(i=0;i<strlen(c);i++)c[i]=c[i]-48;
    for(i=0;i<strlen(c)-2;i++)
    {
        a=c[i]*100+c[i+1]*10+c[i+2];
        if(a>753)a=a-753;
        else a=753-a;
        if(min>a)min=a;
    }
    printf("%i",min);
    return 0;
}


Measured memory_bytes: 128
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  vector<vector<int> > g(100010);
  int n,i,a[100010],b[100010];
  cin >> n;
  for(i=0;i<n-1;i++){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  map<P,int> mp;
  vector<int> seen(100010,0);
  queue<int> que;
  que.push(0);
  vector<int> c(100010,-1);
  int ans=0;
  while(!que.empty()){
    int v=que.front();
    que.pop();
    if(seen[v]==1){
      continue;
    }
    seen[v]=1;
    int color=0;
    for(i=0;i<g[v].size();i++){
      if(seen[g[v][i]]==1){
        continue;
      }
      if(c[v]==color){
        color++;
      }
      c[g[v][i]]=color;
      mp[P(v,g[v][i])]=color;
      mp[P(g[v][i],v)]=color;
      color++;
      que.push(g[v][i]);
      if(ans<color){
        ans=color;
      }
    }
  }
  cout << ans << endl;
  for(i=0;i<n-1;i++){
    cout << mp[P(a[i],b[i])]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 22584
S=input()
key='keyence'
ans='NO'
for i in range(len(key)):
    key1=key[:i]
    key2=key[i:]
    A=key1+'0'*(len(S)-len(key))+key2
    if all([S[l]==A[l] or A[l]=='0' for l in range(len(S))]):
        ans='YES'
print(ans)

Measured memory_bytes: 3060
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define tree 			ped
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)		for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n;
vint tree;

void update(int index, int data){
	while(index<=n){
		tree[index] = max(tree[index], data);
		index+=(index&(-index));
	}
}

int get(int index){
	int ans=0;
	while(index>0){
		ans = max(ans, tree[index]);
		index-=(index&(-index));
	}
	return ans;
}

int32_t main() {

    om_shree_ganeshaya_namah();

    cin>>n;
    vint arr(n), beauty(n), dp(n+1);
    f(n) cin>>arr[i];
    f(n) cin>>beauty[i];

    tree = vint(n+1);

    f(n){
    	int maxi = get(arr[i]);
    	dp[arr[i]] = maxi+beauty[i];
    	update(arr[i], dp[arr[i]]);
    }

    cout<<get(n);
}

Measured memory_bytes: 9500
import qualified Data.ByteString.Char8 as BS
import Data.List

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

calc :: [[Char]] -> [(Char, Int)]
calc [] = []
calc (xs : xss) = (head xs, length xs) : calc xss

main = do
  [s] <- getString
  let s' = s ++ "abc"
  let g = calc (group (sort s'))
  let sn = map snd g
  let m = minimum sn
  let sn' = map (\x -> x - m) sn
  if length (filter (\x -> x > 1) sn') > 0
    then putStrLn "NO"
    else putStrLn "YES"


Measured memory_bytes: 14952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }
  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};


int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<ll,int>> a(n);
  rep(i,n){
    cin >> a[i].F;
    a[i].S = i;
  }
  UnionFind uf(n+1);
  rep(i,m){
    int x,y; cin >> x >> y; 
    uf.unite(x,y);
  }

  ll ans = 0;
  sort(a.begin(),a.end());
  set<int> rtcnt; //root cnt
  rep(i,n){
    rtcnt.insert(uf.root(a[i].S));
  }
  int cnt = rtcnt.size();
  if(cnt==1){ cout << 0 << endl; return 0; }
  int adc = (cnt-1)*2-cnt;
  set<int> st;
  for(int i=0; i<n && !(st.size()==cnt && adc==0); i++){
    if(st.find(uf.root(a[i].S))==st.end()){
      ans += a[i].F;
      st.insert(uf.root(a[i].S));
      uf.unite(n,a[i].S);
    } else {
      if(adc>0){
        ans += a[i].F;
        adc--;
        uf.unite(n,a[i].S);
      }
    }
  }

  if(uf.size(n)!=n+1 || adc>0){
    cout << "Impossible" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int n; cin>>n;
    queue<ll> q;
    for(ll i=1;i<=9;i++){
        q.push(i);
    }
    for(int i=0;i<n-1;i++){
        ll k=q.front();
        //cout<<k<<endl;
        q.pop();
        if(k%10==0){
            q.push(10*k+(k%10));
            q.push(10*k+(k%10)+1);
        }else if(k%10==9){
            q.push(10*k+(k%10)-1);
            q.push(10*k+(k%10));
        }else{
            q.push(10*k+(k%10)-1);
            q.push(10*k+(k%10));
            q.push(10*k+(k%10)+1);
        }
    }
    cout<<q.front()<<endl;
    
}


Measured memory_bytes: 1792
#
import sys
import math
import numpy as np
import itertools

# ひとつ入力
n = int(input())

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())


for i in range(len(s)):
    a = ord(s[i]) - ord('A')
    a += n
    a = a % 26
    print(chr(a+65), end="")



Measured memory_bytes: 13788
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  int n, i;
  cin >> n;
  for (i = n; ; ++i) {
    if (is_prime(i)) break;
  }
  cout << i << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
    int none = 0, two = 0, four = 0;
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        if (x % 4 == 0)
            ++four;
        else if (x % 2 == 0)
            ++two;
        else
            ++none;
    }

    if (none >= four) {
        if (none == four || (four != 0 && two == 0 && none - four == 1))
            std::cout << "Yes\n";
        else
            std::cout << "No\n";
    } else {
        std::cout << "Yes\n";
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int []a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
		}
		int sum = 0;
		for (int val:a) {
			sum += val;
		}
		if (n-sum < 0) {
			System.out.println("-1");
		} else {
			System.out.println(n-sum);
		}
		sc.close();

	}

}

Measured memory_bytes: 39060
s = str(input())
t = str(input())
import sys
s_ = s
if s_ == t:
    print('Yes')
    sys.exit()

for i in range(len(s)):
    s_ = s[-i-1]+s_[:-1]
    if s_==t:
        print('Yes')
        sys.exit()

print('No')


Measured memory_bytes: 3060
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K=int(input())
print(sum(gcd(a,b,c)for a in range(1,K+1)for b in range(1,K+1) for c in range(1,K+1)))

Measured memory_bytes: 75536
import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.List

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . bool "No" "Yes"

sol (n:as) = q*2+1>=n || e==n || q*2+e>=n
  where
  (o,q,e) = f (0,0,0) as
  f (o,q,e) []    = (o,q,e)
  f (o,q,e) (a:as)
    | odd a       = f (succ o,q,e) as
    | a`mod`4==0  = f (o,succ q,e) as
    | even a      = f (o,q,succ e) as

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

int main(){
  #define int long
  using namespace std;
  int N;cin>>N;
  vector<string>S(N);for(int i=0;i<N;i++)cin>>S[i];
  vector<char>initials={'M','A','R','C','H'};
  vector<int>times(5,0);
  for(int i=0;i<N;i++){
    for(int j=0;j<5;j++){
      if(S[i][0]==initials[j])times[j]++;
    }
  }
  int ans=0;
  for(int a=0;a<5;a++){
    for(int b=a+1;b<5;b++){
      for(int c=b+1;c<5;c++){
        ans+=times[a]*times[b]*times[c];
      }
    }
  }

  cout<<ans;
}





Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x; i <= y; ++ i)
#define repd(i,x,y) for(register int i = x; i >= y; -- i)
typedef long long ll;
using namespace std;
template<typename T>inline bool chkmax(T&x,T y) { return x < y ? x = y,1 : 0; }
template<typename T>inline bool chkmin(T&x,T y) { return x > y ? x = y,1 : 0; }
template<typename T>inline void read(T&x)
{
	char c;int sign = 1;x = 0;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}
const int N = 1e5 + 50;
ll n,mx,ans;

int main()
{
	
	read(n);
	rep(i,1,n)
	{
		int x;
		read(x);
		if(x&1)return puts("first"),0;
	}
	
	puts("second");
	
	return 0;
}

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

int MAX_N=262144;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return -1;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return max(X,Y);
  }
}

void chmax(int64_t a,int b){
  int D=MAX_N-1+b;
  seg[D]=a;
  while(D>0){
    D--;
    D/=2;
    seg[D]=max(seg[2*D+1],seg[2*D+2]);
  }
}

int main() {
  int N,Q;
  cin>>N>>Q;
  for(int i=1;i<=N;i++){
    int64_t a;
    cin>>a;
    chmax(a,i);
  }
  for(int i=0;i<Q;i++){
    int64_t a,b,c;
    cin>>a>>b>>c;
    if(a==1){
      chmax(c,b);
    }
    else if(a==2){
      cout<<qu(b,c+1,0,0,MAX_N)<<endl;
    }
    else{
      if(qu(b,N+1,0,0,MAX_N)<c){
        cout<<N+1<<endl;
      }
      else{
        int l=b,r=N+1;
        while(r-l>1){
          int D=(l+r)/2;
          if(qu(b,D,0,0,MAX_N)>=c){
            r=D;
          }
          else{
            l=D;
          }
        }
        cout<<l<<endl;
      }
    }
  }
}

Measured memory_bytes: 7268
N=int(input())
S=input()

alphabet='abcdefghijklmnopqrstuvwxyz'
nums=[1]*26
for i in range(N):
  ind=alphabet.index(S[i])
  nums[ind]+=1
out=1
for i in nums:
  out*=i
print((out-1)%(10**9+7))

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> va(a), vb(b), vm(m);
  for (auto &i : va) cin >> i;
  for (auto &i : vb) cin >> i;
  for (auto &i : vm) {
    int j, k, l;
    cin >> j >> k >> l;
    i = va[j - 1] + vb[k - 1] - l;
  }
  sort(all(va));
  sort(all(vb));
  sort(all(vm));
  cout << min(va[0] + vb[0], vm[0]) << '\n';
}


Measured memory_bytes: 5560
D,G = map(int, input().split())
ps,cs = [],[]
for i in range(D):
    p,c = map(int, input().split())
    ps.append(p)
    cs.append(c)
    
limit=1<<D
ans = sum(ps)
for a in range(0,limit):
    s,p,i = 0,0,D-1
    b = 1<<(D-1)
    upperIndex = 0
    while (s<G and b>0):
        if (a&b!=0):
            s += ps[i]*100*(i+1)+cs[i]
            p += ps[i]
        else:
            upperIndex=max(upperIndex,i)
        b>>=1
        i-=1

    for j in range(ps[upperIndex]):
        if (s>=G):
            ans = min(ans,p)
            break
        s += 100*(upperIndex+1)
        p += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    
    int H, W;
    cin >> H >> W;
    
    vector<string> ans;

    int v[H][W];
    rep(h, H){
        rep(w, W){
            cin >> v[h][w] ;
        }
    }

    int cnt = 0;
    rep(y, H){
        rep(x, W-1){
            if( (v[y][x] % 2) == 1){
                string s = to_string(y + 1) + ' ' + to_string(x + 1) + ' ' + to_string(y + 1) + ' ' + to_string(x+2);
                ans.push_back(s);
                v[y][x+1] ++;
                cnt++;
            }
        }
    }

    rep(y, H-1){
        if(v[y][W-1] % 2 ){
            string s = to_string(y+1) + ' ' + to_string(W) + ' ' + to_string(y+2) + ' ' + to_string(W);
            ans.push_back(s);
            v[y+1][W-1] ++;
            cnt++;
        }
    }

    cout << cnt << endl;
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }


}

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

int m[6] = {500, 5};

int main(void)
{
    long int X=0, glad=0;

    scanf("%ld", &X);

    while(X >= 5) {
        if(X/500 >= 1) {
            X -= 500;
            glad += 1000; 
        } else {
            X -= 5;
            glad += 5;
        }
    }   
    
    printf("%ld\n", glad);

    return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int w[N];
int h[N],e[N],ne[N],idx;
int in[N];
void add(int a,int b){
	e[idx] = b,ne[idx] = h[a],h[a] = idx++;
}

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&w[i]);
	memset(h,-1,sizeof h);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b),add(b,a);
		in[a]++,in[b]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(in[i]==0) ans++;
		else {
			int flag=1;
			for(int k=h[i];~k;k=ne[k]){
				int j = e[k];
				if(w[j] >= w[i]) flag=0; 
			}
			if(flag) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6788
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

ll n, a[102], ans;

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

Measured memory_bytes: 3632
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))

const int32_t group1[] = {1, 3, 5, 7, 8, 10, 12};
const int32_t group2[] = {4, 6, 9, 11};
const int32_t group3[] = {2};

int32_t in_group(int32_t x)
{
  for (int32_t i = 0; i < ARRAY_SIZE(group1); i++) {
    if (group1[i] == x) return 1;
  }
  for (int32_t i = 0; i < ARRAY_SIZE(group2); i++) {
    if (group2[i] == x) return 2;
  }
  for (int32_t i = 0; i < ARRAY_SIZE(group3); i++) {
    if (group3[i] == x) return 3;
  }
}

int32_t main(void)
{
  int32_t x, y;
  (void)scanf("%d %d", &x, &y);

  if (in_group(x) == in_group(y)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
N = int(input())
H = list(int(i) for i in input().split())

# 再帰的にカウントしていく
def count(h):
    if len(h) != 0:
        output = 0
        min_elem = min(h)
        output += min_elem
        for index in range(0, len(h)):
            h[index] -= min_elem
        tmp_h = []
        for index in range(0, len(h)):
            if (h[index] > 0):
                tmp_h.append(h[index])
            else:
                output += count(tmp_h)
                tmp_h = []
        output += count(tmp_h)
        return output
    else:
        return 0

h = H
print(count(h))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	string s;
	cin >> s;
	int n = s.size();
	
	int alp[3] = {};

	rep(i,0,n) alp[ s[i] - 'a' ]++;

	if( abs( alp[0] - alp[1] ) > 1 || abs(alp[1] - alp[2]) > 1 || abs( alp[2] - alp[0] ) > 1 ) NO;
	else YES;

	ret 0;
}

Measured memory_bytes: 512
n, q = [int(e) for e in input().strip().split()]
s = input().strip()
lrs = []
for i in range(q):
    l, r = [int(e) for e in input().strip().split()]
    lrs.append((l, r))

cnt = 0
cumcnt = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if s[i-1:i+1] == 'AC':
        cnt += 1

    cumcnt[i] = cnt



for inx in lrs:
    l, r = inx
    tmp = cumcnt[r-1] - cumcnt[l-1]
    print(tmp)

Measured memory_bytes: 19764
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int a , b , x; 
	cin >> a >> b >> x ;
	cout << (b>=x-a and a<=x? "YES":"NO") << endl;
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a); i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    ull n,m,pos = 1,cells[1010] = {0},dice[1010] = {0};
    
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0) return 0;
        
        pos = 1;
        
        rep(i,0,1010){
            cells[i] = 0;
            dice[i] = 0;
        }
        
        rep(i,0,n) cin >> cells[i];
        rep(i,0,m) cin >> dice[i];
        
        rep(i,0,m){
            pos += dice[i];
            if(pos >= n){
                cout << i+1 << endl;
                break;
            }
            else{
                if(pos < 1) pos = 1;
                pos += cells[pos-1];
            }
            
            if(pos >= n){
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;   
}


Measured memory_bytes: 3012
#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// flagを用いたバブルソート
int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}


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

int main(){
  int X;
  cin >> X;
  
  int max = 100000;
  
  int ans;
  for(int j=X; j<max+5;j++){
    int count=0;
    
  	for(int i=2;i<X;i++){
      if(j%i==0){
        break;
      }
      count++;
    }
    
    if(count==X-2){
      ans=j;
      break;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;




int main(){	
	ll n,m;cin>>n>>m;	
	if(m==1&&n==1){
		cout<<"1"<<endl;
		return 0;
	}
	if(m==1||n==1){
		cout<<n+m-3<<endl;
		return 0;
	}
	cout<<(n-2)*(m-2)<<endl;

	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring> 
using namespace std;
int main()
{
	char a[100001];
	scanf("%s",a);
	int len = strlen(a);
	int ans = 0;
	for(int i = 1;i < len - 1;i++)
	{
		ans++;
	}
	printf("%c%d%c",a[0],ans,a[len - 1]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int main() {
	int L, R, d; cin >> L >> R >> d;
	int cnt = 0;
	for (int p = L; p <= R; p++) {
		if (p % d == 0) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3596
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 1000000007;
int n, ans, cnt[10][10];

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n;
	for(int i=1; i<=n; i++){
		int cur=i, last=i%10, first=0;
		while(cur){
			first=cur;
			cur/=10;
		}
		cnt[first][last]++;
	}
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			ans+=cnt[i][j]*cnt[j][i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
program string_formation
  implicit none
  character(100000) :: s
  character(500000) :: ans = ""
  character(5) :: t
  integer :: q, l, r, i, f
  logical :: reversed = .false.
  read(*,*) s
  l = 200001
  r = 200000+len_trim(s)
  ans(l:r) = s(1:len_trim(s))
  read(*,*) q
  do i = 1, q
    read(*,'(a)') t
    if (t(1:1) == "1") then
      reversed = .not.reversed
      cycle
    end if
    f = ichar(t(3:3))-48
    if (f == 1 .eqv. reversed) then
      r = r+1
      ans(r:r) = t(5:5)
    else
      l = l-1
      ans(l:l) = t(5:5)
    end if
  end do
  if (reversed) then
    do i = l, r
      f = l+r-i
      if (i >= f) exit
      t(1:1) = ans(i:i)
      ans(i:i) = ans(f:f)
      ans(f:f) = t(1:1)
    end do
  end if
  write(*,'(a)') ans(l:r)
end program string_formation

Measured memory_bytes: 1444
#include <stdio.h>
#define MAX 101
#define INF 10000000

int p[MAX], M[MAX][MAX];

int min(int x, int y){
  if(x < y)return x;
  return y;
};
void MatrixChain(int n){
  int i, j, l, k;

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

  for(l=2; l<=n; l++){   
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      M[i][j] = INF;
      
      for(k=i; k<=j-1; k++){
	M[i][j] = min(M[i][j], M[i][k] + M[k+1][j] + p[i-1]*p[k]*p[j]);
      }      
    }
  }  
};

int main(){
  int i;
  int n;
   
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d%d", &p[i-1], &p[i]);
  }
  
  MatrixChain(n);
  
  printf("%d\n", M[1][n]);
 
  return 0;
}

Measured memory_bytes: 636
#include <cstdio>
int N,mn=101,mx=-101, ans=1e9;
int arr[101];
int main()
{
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", arr + i);
    mn = mn > arr[i] ? arr[i] : mn;
    mx = mx < arr[i] ? arr[i] : mx;
  }
  for (int now = mn; now <= mx; ++now) {
    int tmp = 0;
    for (int i = 0; i < N; ++i) {
      tmp += (now - arr[i]) * (now - arr[i]);
    }
    if (tmp < ans) {
      ans = tmp;
    }
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
// use std::cmp;
use std::collections::BTreeMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;


// const INF: i64 = 1_000_000_000;


fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

type Vu = Vec<u8>;

fn getpairs(s: Vu) -> BTreeMap<Vu, i64> {
    let mut ret: BTreeMap<Vu, i64> = BTreeMap::new();
    let n = s.len();
    for flags in 0..(1<<n) {
        let mut s0: Vu = Vec::new();
        let mut s1: Vu = Vec::new();
        for i in 0..n {
            if (flags >> i) & 1 == 0 {
                s0.push(s[i]);
            }else{
                s1.push(s[i]);
            }
        }
        let mut k = s0;
        k.push(0);
        k.append(&mut s1);
        *ret.entry(k).or_insert(0) += 1;
    }
    ret
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n = sc.read();
    let s = sc.read::<String>().into_bytes();
    let mut s0 = Vec::new();
    let mut s1 = Vec::new();
    for i in 0..n {
        s0.push(s[i]);
        s1.push(s[2*n-1-i]);
    }
    let map0 = getpairs(s0);
    let map1 = getpairs(s1);
    // println!("{:?}", s);
    // println!("{:?}", map0);

    let mut ans = 0;
    for (k, v) in map0.iter() {
        ans += v * map1.get(k).unwrap_or(&0);
    }
    println!("{}", ans);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

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

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 49404
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,ans=0;
  cin>>n;
  vector<int> a(n),b(n),c(n-1);
  for(i=0;i<n;i++) cin>>a.at(i);
  for(i=0;i<n;i++) cin>>b.at(i);
  for(i=0;i<n-1;i++) cin>>c.at(i);
  for(i=0;i<n;i++) {
    ans+=b.at(i);
    if(i>0 && a.at(i-1)+1==a.at(i)) ans+=c.at(a.at(i-1)-1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256