akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    using namespace std;
         
    long long ans1, ans2, s1[1<<20], s2[1<<20];
int n;
     
    int main() {
        cin >> n >> s1[0];
        s2[0] = s1[0];
        if (s1[0] <= 0) ans1 = -s1[0] + 1, s1[0] = 1;
        if (s2[0] >= 0) ans2 = s2[0] + 1, s2[0] = -1;
        for (int i = 1; i < n; i++) {
            cin >> s1[i];
            s2[i] = s1[i] + s2[i-1];
            s1[i] += s1[i-1];
            if (i%2 && s1[i] >= 0) {
                ans1 += s1[i] + 1;
                s1[i] = -1;
            } else if (i%2==0 && s1[i] <= 0) {
                ans1 += -s1[i] + 1;
                s1[i] = 1;
            }
            if (i%2 && s2[i] <= 0) {
                ans2 += -s2[i] + 1;
                s2[i] = 1;
            } else if (i%2==0 && s2[i] >= 0) {
                ans2 += s2[i] + 1;
                s2[i] = -1;
            }
        }
    	cout << min(ans1,ans2);
    }

Measured memory_bytes: 3072
#include <stdio.h>

int N=2;

int main() {
  int a[N];
  for (int i=0;i<N;i++){
    scanf("%d", &a[i]);
  }

  int dif = a[1]-a[0];
  int sum=0;
  for (int i=dif;i>0;i--){
    sum+=i;
  }

  printf("%d\n", sum-a[1]);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

const int Q = 200005;

int n, q, s, t, x, ans[Q];
multiset<int> se;

struct TEvent
{
    int tim, typ, ind;

    TEvent(int _tim = 0, int _typ = 0, int _ind = 0)
    {
        tim = _tim; typ = _typ; ind = _ind;
    }

    bool operator<(const TEvent &oth) const
    {
        return tim < oth.tim || (tim == oth.tim && typ < oth.typ);
    }
};
vector<TEvent> ve;

int main()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> s >> t >> x;
        ve.push_back(TEvent(s - x, 1, x));
        ve.push_back(TEvent(t - x, 2, x));
    }
    for (int i = 1; i <= q; i++)
    {
        cin >> x;
        ve.push_back(TEvent(x, 3, i));
    }
    sort(ve.begin(), ve.end());
    for (TEvent &v : ve)
        if (v.typ == 1)
            se.insert(v.ind);
        else if (v.typ == 2)
            se.erase(se.find(v.ind));
        else
            if (se.empty())
                ans[v.ind] = -1;
            else
                ans[v.ind] = *se.begin();
    for (int i = 1; i <= q; i++)
        cout << ans[i] << '\n';
}


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

int main(){
  int e;
  while(cin>>e && e){
  int m=1000000;
  for(int z=0;z*z*z<=e;z++){
    for(int y=0;y*y<=e-z*z*z;y++){
      int x=e-z*z*z-y*y;
      int n=x+y+z;
      if(n<=m){
        m=n;
      }
    }
  }
  cout<<m<<endl;
}
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod;
constexpr int MAX = 200010;

int n, q;
string s;
char t[MAX], d[MAX];

int check(int mid){
        rep(i, q){
                if(s[mid]==t[i]) d[i]=='L' ? --mid : ++mid;
                if(mid<0) return 1;
                else if(mid==n) return 2;
        }
        return 0;
}

int main(){
        scanf("%d%d", &n, &q);
        cin>>s;
        rep(i, q) scanf(" %c %c", &t[i], &d[i]);
        int ans=n;
        int low=0, high=n;
        if(check(low)==1){
                while(high-low>1){
                        int mid=(high+low)/2;
                        (check(mid)==1 ? low : high)=mid;
                }
                ans-=low+1;
        }
        low=-1, high=n-1;
        if(check(high)==2){
                while(high-low>1){
                        int mid=(high+low)/2;
                        (check(mid)==2 ? high : low)=mid;
                }
                ans-=n-high;
        }
        printf("%d\n", ans);
}

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

#define task "A"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,a[100004],res[100004];
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i,1,n)
	{
	    cin >> a[i];
	    res[a[i]]=i;
	}
	rep(i,1,n) cout << res[i] << ' ';
}


Measured memory_bytes: 1664
#include <iostream>
#include <math.h>

using namespace std;

#define N 8

//yakusu
int main(void){
    // Your code here!
    int n;int i;int cnt=0;
    int numcnt=0;
    int j;
    
    scanf("%d",&n);//scanf("%d",n);
    
    //printf("%d\n",n%0); -> 0
    
    
    for(j=1;j<=n;j+=2){ //for(j=1;j<=n;j+=2){ //not j++
    
    cnt=0;
    for(i=1;i<=j;i++){
        if( j%i==0 ){ //if( n%i==0 ){
           // printf("%d\n",i);
            cnt++;
            if( cnt > N ) break;
        }

    }
    //puts("");
    
    //printf("%d\n",cnt);

    if( cnt == N ) numcnt++; //printf("1");else printf("0");
    //printf("%d\n",numcnt);
    //cnt=0;
    
    }
    
    
    printf("%d\n",numcnt); //output  105 -> 1  106 -> 0
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    map<string,ll> m;

    rep(i,N){
        string S;
        cin >>S;
        m[S] = 1;
    }
    ll ans=0;
    for (const auto& [key, value] : m){
        ans++;
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 19236
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    string s;
    cin >> s;
    int k = s.size();
    int cnt = 0;
    for (int i=0; i<k; i++)if (s[i] == 'o')cnt++;
    
    if (15-k + cnt>= 8)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, x;
  cin >> n >> x;

  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());

  int ans = 0;
  rep(i, 0, n) {
    x -= a[i];
    if (x < 0)
      break;
    if (i == n - 1 && x != 0)
      break;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll n = s.size();
    vll a(3);
    REP(i, n) a[s[i] - 'a']++;
    ll v = 0;
    REP(i, 3){
        if(a[i]) v++;
    }
    if(v < 3){
        if(n == 1 || n == 2 && v == 2) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
    }
    VSORT(a);
    if(a[2] - a[0] <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int MOD = 1e9 + 7;

inline int mod_add(int a, int b, int m = MOD) {
    int sum = a + b;
    return sum >= m ? sum - m : sum;
}

int N;
vector<vector<int>> A;

int main() {
    scanf("%d", &N);
    A.assign(N, vector<int>(N));

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            scanf("%d", &A[i][j]);

    vector<int> dp(1 << N, 0);
    dp[0] = 1;

    for (int mask = 0; mask < (1 << N) - 1; mask++) {
        int men = __builtin_popcount(mask);

        for (int i = 0; i < N; i++)
            if ((mask >> i & 1) == 0 && A[men][i])
                dp[mask | 1 << i] = mod_add(dp[mask | 1 << i], dp[mask]);
    }

    printf("%d\n", dp[(1 << N) - 1]);
}


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


int main()
{
	int n;
	cin >> n;
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(i>=1&&i<=9)cnt++;
		if(i>=100&&i<=999)cnt++;
		if(i>=10000&&i<=99999)cnt++;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll a_base2(ll n, ll a, ll i){return i==1?n%a:a_base2(n/a,a,i-1);}

int main(void){
    // char ;
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll fa,fb;
    if(a==0){
        fa=0;
    }else{
        if((a-1)%2){
            fa= (a-1)%4==1 ? 1 : 0;
        }else{
            fa = ( (a-2)%4==1 ? 1 : 0 ) ^ (a-1);
        }
    }
    if(b%2){
        fb= b%4==1 ? 1 : 0;
    }else{
        fb = ( (b-1)%4==1 ? 1 : 0 ) ^ b;
    }
    // PN;
    // printf("%lld %lld ",fa,fb);
    
    printf("%lld\n",fa^fb);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int main() {
    LL n;

    cin >> n;
    LL min = 1e15 + 1;
    for (int i=0; i < 5; i++) {
        LL t;
        cin >> t;
        if (t < min) {
            min = t;
        }
    }

    cout << 5 + ((LL)ceil((double)n / min) - 1) << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
   string s;
   cin >> s;
   int a[4];
   rep(i,4)a[i] = s[i] - '0';
   char op[3];

   for(int bit=0;bit < (1<<3);bit++){
      int ans = a[0];
      for(int i=0;i<3;i++){
         if(bit & (1<<i))ans += a[i+1],op[i] = '+';
         else ans -= a[i+1],op[i] = '-';
      }
      if(ans == 7){
         cout << a[0];
         rep(i,3)cout << op[i] << a[i+1];
         cout << "=7" << endl;
         return 0;
      }
   }
   return 0;
}


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

H_arg = H*30 + 0.5*M
M_arg = 6*M

if H_arg - M_arg>=180:
    H_M_arg = (360-H_arg) + M_arg
else:
    H_M_arg = abs(H_arg - M_arg)

# print(H_M_arg)

X = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(H_M_arg)))
print(X)


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

    const int N = 1e6 + 100;

    int main() {
        // freopen("in.txt", "r", stdin);
        ios::sync_with_stdio(0);
        cin.tie(0);

        vector<int> F(200);
        int X, n;
        cin >> X >> n;
        for(int i = 0; i < n; i++) {
            int a;
            cin >> a;
            F[a] = true;
        }
        int dist = 1e9, ans = -1;
        for(int i = 0; i < 200; i++) {
            if(F[i]) continue;
            if(abs(X-i) < dist) {
                dist = abs(X-i);
                ans = i;
            }
        }
        cout << ans << endl;

        return 0;
    }



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

int main(){

  int n;
  double v,t,y;

  while(cin >> v){

    t = v/9.8;
    y = 4.9 * t * t;

    int i = 0;

    while(5*i-5 < y) i++;

    cout << i << endl;
  }
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for(auto nv : G[v]) {
        if(seen[nv]) continue;
        dfs(G, nv);
    }
}

int main() {
    int N, M; cin >> N >> M;
    
    vector<int> a(M), b(M);
    for(int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    
    int ans = 0;
    for(int i = 0; i < M; ++i) {
        Graph G(N);
        for(int j = 0; j < M; ++j) {
            if(i == j) continue;
            G[a[j]].push_back(b[j]);
            G[b[j]].push_back(a[j]);
        }
        
        int count = 0;
        seen.assign(N, false);
        for(int v = 0; v < N; ++v) {
            if(seen[v]) continue;
            dfs(G, v);
            ++count;
        }
        if(count > 1) ++ans;
    }
    
    cout << ans << endl;
}

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

int main(void){
    char letras[10000];
    int n;

    scanf("%d", &n);
    scanf("%s", letras);

    int tam_let;
    tam_let = strlen(letras);
    for (int i = 0; i < tam_let; i++) {
        letras[i] += n;
        if (letras[i] > 90) {
            letras[i] -= 26;
        }
    }

    printf("%s", letras);


    return 0;
}


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


int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++)
  {
      if(i%k==0)
      {
          cout<<"OK";
          return 0;
      }
  }
  cout<<"NG";
  return 0;
}


Measured memory_bytes: 3624
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define MAXN 200005
#define mod 998244353

ll fac[MAXN + 1] = {0};
void init(ll n)
{
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % mod;
}

ll power(ll x, ll y)
{
    ll res = 1;

    x = x % mod;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;

        y = y >> 1;
        x = (x * x) % mod;
    }
    return res % mod;
}

ll modInverse(ll n)
{
    return power(n, mod - 2);
}

ll nCrModPFermat(ll n, ll r)
{
    if (r == 0)
        return 1;
    return (fac[n] * modInverse(fac[r]) % mod *
            modInverse(fac[n - r]) % mod) % mod;
}

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
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, k, m;
    cin >> n >> m >> k;
    init(n);
    ll out = 0;
    while (k >= 0)
    {
        out = out + (((nCrModPFermat(n - 1, k) * power(m - 1, n - 1 - k)) % mod) * m) % mod;
        out %= mod;
        k--;
    }
    cout << out << "\n";
    return 0;
}

/* Iterative Function to calculate (x^y)%p
in O(log y) */


// Returns n^(-1) mod p


// Returns nCr % p using Fermat's little
// theorem.



Measured memory_bytes: 5216
from collections import Counter as ct


def prime_factorization(N):
    res = []
    x = N
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res


n, p = map(int, input().split())
ans = 1
q = ct(prime_factorization(p))
for i, v in q.items():
    ans *= i ** (v // n)
print(ans)

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

vector<vector<int>> mp;

int dx[] = {1,1,0,-1,-1,-1,0,1};
int dy[] = {0,1,1,1,0,-1,-1,-1};

void dfs(int x, int y, int hight, int width){
   mp[x][y] = 0;
  
  for(int k = 0; k < 8; k++){
    int a = x+dx[k]; int b = y+dy[k];
    if( a < 0 || a >= hight || b < 0 || b >= width){ continue;}
    if( mp[a][b] == 0){ continue;}
    else if(mp[a][b] == 1){
   dfs(a,b ,hight,width);}}
  return  ;
}
  
  
int main(){

 int w,h;
  while( cin >> w >> h){
    if( w == 0 && h == 0){ break;}
    
    mp = vector<vector<int>> (h,vector<int>(w));
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){ cin >> mp[i][j];}}
    
    //reserching the number of rikuchi by using dfs method
    int ans = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(mp[i][j]==0){ continue;}
        dfs(i,j,h,w); 
        ans++;
      }
    }
    
    
    cout << ans << endl;
  }
  
  return 0;}
    
    


Measured memory_bytes: 3200
#偶数と奇数配列に分ける
#奇数番配列にLが存在するかで条件分岐
#偶数番配列にRが存在するかで条件分岐
S = input()
Odd = S[::2]
Even = S[1::2]
print('Yes' if Odd.count('L') == 0 and Even.count('R') == 0 else 'No')

Measured memory_bytes: 8892
import java.util.*;
public class Main {
	int p,q,a,n;
	int ans;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			p = sc.nextInt();
			q = sc.nextInt();
			a = sc.nextInt();
			n = sc.nextInt();
			if((p|q|a|n) == 0) break;
			ans = 0;
			dfs(0,0,1,1, 1);
			System.out.println(ans);
		}
	}
	
	private void dfs(int deep, int aa, int bb, int mul,int  prev) {
		
//		if(aa == p && bb == q){
//			ans++;
//			return ;
//		}
		if(ismatch(aa,bb)){
			ans++;
			return ;
		}
//		if(deep == n - 1){
//			int [] res = sub(aa,bb);
//			if(res[1] * mul <= a && res[1] >= prev){
//				ans++;
//			}
//			return ;
//		}
		if(deep == n) return;
		if(isbig(aa, bb))return;
		
		for(int i = prev; i * mul <= a; i++){
			int [] res = calc(aa,bb, 1, i);
			dfs(deep + 1, res[0], res[1], i * mul, i);
		}
	}

	private boolean ismatch(int aa, int bb) {
		int a = p * bb;
		int b = q * aa;
		if(a == b) return  true;
		return false;
	}

	private int[] sub(int aa, int bb) {
		int a = p * bb;
		int b = q * aa;
		int c = q * bb;
		int d = a - b;
		int g = gcd(d, c);
		int [] res = {d / g, c / g};
		return res;
	}

	private boolean isbig(int aa, int bb) {
		int a = p * bb;
		int b = q * aa;
		if(a < b) return true;
		return false;
	}

	private int[] calc(int aa, int bb, int cc, int dd) {
		int [] res = new int[2];
		int up = bb * cc + aa * dd;
		int down = bb * dd;
		res[0] = up;
		res[1] = down;
		return res;
	}

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

	public static void main(String [] args){
		new Main().doit();
	}
}

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

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

int main(void) {
  int N;
  cin >> N;
  
  int sum = find_sum_of_digits(N);

  if (N % sum== 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main() {
    // input
    int N;
    cin >> N;

    // solve
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; ++j) {
            ans++;
        }
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool cmp(LL i,LL j){
	return i>j;
}
int main(){
	vector<LL>v;
	LL suma=0,sumb=0,n,i,j;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>j;
		v.push_back(j);
	}
	sort(v.begin(),v.end(),cmp);
	for(i=0;i<n;i++){
		if(i%2==0)suma+=v[i];
		else sumb+=v[i];
	}
	cout<<suma-sumb<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.max(a*b, c*d));
    }
}

Measured memory_bytes: 21716
#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

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() {
    i64 K, T; cin >> K >> T;
    using P = pair<i64, i64>;
    priority_queue<P> pq;
    REP(i, T) {
        i64 n; cin >> n;
        pq.push({n, i});
    }

    i64 cnt = 0;
    while (pq.size() > 1) {
        P p1 = pq.top(); pq.pop();
        P p2 = pq.top(); pq.pop();
        p1.first--, p2.first--;
        if (p1.first > 0) pq.push(p1);
        if (p2.first > 0) pq.push(p2);
    }

    if (pq.size() == 1) {
        cnt += pq.top().first - 1;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
signed main(){
	int n, m;
	cin >> n >> m;
	
	vector<int> a(m), b(m);
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
	}
	
	vector<int> vec(n);
	for(int i = 0; i < n; i++) vec[i] = i + 1;
	int ans = 0;
	do{
		//for(int i = 0; i < n; i++) cout << vec[i];
		//cout << endl;
		
		if(vec[0] != 1) break;
		
		int count = 0;
		for(int i = 0; i < n - 1; i++){
			int tmp = vec[i];
			int tmp1 = vec[i + 1];
			for(int j = 0; j < m; j++){
				if((tmp == a[j] && tmp1 == b[j]) || (tmp == b[j] && tmp1 == a[j])){
					count++;
					break;
				}
			}
		}
		if(count == n - 1){
			ans++;
		}
	}while(next_permutation(vec.begin(), vec.end()));
	
	cout << ans << endl;
}

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

#define ll long long

using namespace std;

int main()
{
	ll n, l; cin>>n>>l;
	vector<pair<ll, ll> > itv(n);
	for(int i=0; i<n; i++){
		ll l, r; cin>>l>>r;
		itv[i] = make_pair(l, r);
	}
	sort(itv.begin(), itv.end());
	ll cur=0, x=0;
	for(int i=0; i<n; i++){
		ll maximum=0;
		while(itv[i].first<=cur){
			maximum = max(maximum, itv[i].second);
			i++;
			if (i==n) break;
		}
		cur = maximum;
		x++; i--;
		if (cur==l) break;
	}
	ll y;
	set<ll> S;
	map<ll, ll> M;
	for(int i=0; i<n; i++){
		S.insert(itv[i].first); S.insert(itv[i].second);
	}
	ll idx=0;
	for(auto it=S.begin(); it!=S.end(); it++){
		M[*it] = idx;
		idx++;
	}
	vector<ll> imos(S.size()+1);
	for(int i=0; i<n; i++){
		ll left = M[itv[i].first];
		ll right = M[itv[i].second];
		imos[left]++;
		imos[right+1]--;
	}
	ll minimum = imos[0];
	for(int i=1; i<imos.size()-1; i++){
		imos[i]+=imos[i-1];
		minimum = min(minimum, imos[i]);
	}
	y = n-(minimum-1);
	cout << x << " " << y << endl;
	return 0;
}


Measured memory_bytes: 51032
'use strict';
function Main(stdin){
  const input = stdin.trim().split(' ').map(str => Number(str));
  const A = input[0], B = input[1], C = input[2];
  let result = 'NO';
  for(let i = 1; i <= 100; i++){
    if((A*i)%B === C){
        result = 'YES';
        break;
    }
  }
  console.log(result);
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>

using namespace std;

const long long MOD = 1000000007;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int cnt=0,temp_a=a,temp_b=b,temp_c=c;
	while(1){
		if(a%2!=0 || b%2!=0 || c%2!=0){
			break;
		}
		if((a%2==0 && b%2==0 && c%2==0)&&(a==b && b==c)){
			cout << "-1" << endl;
			return 0;
		}
		temp_a=(b+c)/2;
		temp_b=(c+a)/2;
		temp_c=(a+b)/2;
		a=temp_a;
		b=temp_b;
		c=temp_c;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
# nA = C mod B
# 1 - B


l = [int(x) for x in input().split(" ")]
A = l[0]
B = l[1]
C = l[2]

for n in range(1,B+1,1):
	if (n * A) % B == C:
		print("YES")
		quit()

print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str ;
 int count = 0;
  for(int i=0; i < str.size(); i++) {
   
    if(str[i] == '1'){
    
      count++;
    }  
  }
    cout << count << endl;
  
}












Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <map>
#define llint long long

using namespace std;

llint n;
string s[100005];
map<string, llint> mp;

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s[i], sort(s[i].begin(), s[i].end());
	for(int i = 1; i<= n; i++) mp[s[i]]++;
	
	llint ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		ans += it->second*(it->second-1)/2;
	}
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    rep(i, s.size()) {
        putchar('x');
    }
    cout << endl;
    return 0;
}

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

int main(){
  ll n,m,k,mb,i,f;
  ll min=0;
  ll ab=0;
  ll bb=0;
  cin >> n >> m >> k;
  ll a[n],b[m];
  f=1;
  for(i=0;i<n;i++){
    cin >> a[i];
    if((min+a[i]<=k)&&(f==1)){
      ab+=1;
      min+=a[i];
    }
    else{
      f=0;
    }
  }
  f=1;
  for(i=0;i<m;i++){
    cin >> b[i];
    if((min+b[i]<=k)&&(f==1)){
      bb+=1;
      min+=b[i];
    }
    else{
      f=0;
    }
  }
  mb=ab+bb;
  for(i=ab;i>0;i--){
    min-=a[i-1];
    while((min+b[bb]<=k)&&(bb<m)){
      min+=b[bb];
      bb+=1;
    }
    mb=max(mb,bb+i-1);
  }
  cout << mb;
}

Measured memory_bytes: 6688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  double x, y;
  cin >> n >> x >> y;
  map<double, int> mp;
  double middle = x+(y-x)/2.0;
  for(double i=1; i<=n-1; i++){
    for(double j=i+1; j<=n; j++){
      if(i<middle && middle<j){
        mp[min(j-i, abs(i-x)+abs(j-y)+1)]++;
      }else{
       	mp[j-i]++; 
      }
    }
  }
  for(int i=1; i<n; i++) cout << mp[i] << endl;
  return 0;
}
    

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

int main(){
  char b;
  cin >> b;
  switch (b){
    case 'A':
      cout << "T" << endl;
      break;
    case 'T':
      cout << "A" << endl;
      break;
    case 'C':
      cout << "G" << endl;
      break;
    case 'G':
      cout << "C" << endl;
      break;
  }
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * n

    # 根を返す
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    # 合併する
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return

        if self.parents[x] > self.parents[y]:
            x,y=y,x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 同じグループに属するかを判定する
    def same(self,x,y):
        return self.find(x)==self.find(y)

    # 属するグループの要素数を判定する
    def size(self,x):
        return self.parents[self.find(x)]*(-1)

    # 属するグループの要素を返す
    def members(self,x):
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]

    # すべての根の要素を返す
    def root(self):
        return [i for i,x in enumerate(self.parents) if x<0]

    # グループの数を返す
    def group_count(self):
        return len(self.root())

    # ｛根：その要素｝の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.root()}

    # ｛根：その要素｝で表示する
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=map(int,input().split())
UF=UnionFind(N)

for i in range(M):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    UF.union(x,y)

ans=UF.group_count()-1
print(ans)


Measured memory_bytes: 75088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int l = 1, r = N;
  for (int i = 0; i < M; i++){
    int L, R;
    cin >> L >> R;
    l = max(l, L);
    r = min(r, R);
  }
  cout << max(r - l + 1, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
#define INF 1e9
#define FOR(i,s,e) for(int i=s; i<=e; i++)
int cost[MAXN], memo[MAXN];
int n;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int f(int i) {
    if(i > n) return INF;
    if(i == n) return 0;
    if(memo[i] != -1) return memo[i];
    return memo[i] = min(f(i+1) + abs(cost[i] - cost[i+1]), f(i+2) + abs(cost[i] - cost[i+2]));
}
void solve() {
    cin >> n;
    FOR(i,1,n) {
        cin >> cost[i];
    }
    memset(memo, -1, sizeof(memo));
    cout << f(1) << endl;
}
int main() {
  __fastio;
  solve();
  return 0;
}


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

A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)

def calc(x): #全てx以下にするために何回変える必要があるか
    tmp = 0
    for a, f in zip(A, F):
        tmp += max(0, a - (x // f))
        if tmp > K:
            return tmp
    return tmp

ng = -1
ok = 10 ** 18
while ok - ng > 1:
    mid = (ok + ng) // 2
    if calc(mid) <= K:
        ok = mid
    else:
        ng = mid

print (ok)

Measured memory_bytes: 114028
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力

		// 文字列の入力
		String s = sc.next();
      char threend = s.charAt(2);
      char fourth = s.charAt(3);
      char fiveth = s.charAt(4);
      char sixth = s.charAt(5);
      
      if ((threend == fourth) && (fiveth == sixth))
		// 出力
      {
		System.out.println("Yes");
      }
      else
      {
      System.out.println("No");
      }
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#pragma optimizer(O2)
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
//#define MXN 300000
#define N 100005
int main(){
    int n;
    scanf("%d",&n);
    int a[205];
    for(int i = 0;i<2*n;i++)
        scanf("%d",&a[i]);
    sort(a,a+2*n);
    int ans=0;
    for(int i = 0;i<2*n;i+=2){
        ans+=a[i];
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
// B - Sum of Three Integers
#include <bits/stdc++.h>
using namespace std;

int main(){
	int k,s; cin>>k>>s;
	int ans = 0;
	for(int x=0; x<=k; ++x)
		for(int y=0; y<=k; ++y){
			int z = s-x-y;
			if(0<=z && z<=k)ans++;
		}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    if N == 2:
        if A[0] == A[1]:
            print(0)
        elif A[0] < A[1]:
            print(-1)
        else:
            if (A[0] - A[1]) %2 == 0:
                print((A[0] -  A[1])//2)
            else:
                print(-1)
        exit()

    g1 = A[0]
    g2 = A[1]
    g3 = 0
    for i in range(2, N):
        g3 ^= A[i]
    n1 = g1.bit_length()
    n2 = g2.bit_length()
    n3 = g3.bit_length()
    NN = max(n1, n2, n3)
    ans = 0
    cnt = 0
    while True:
        cnt += 1
        if cnt == 10000:
            print(-1)
            exit()
        for i in range(NN):
            if (g1 >> i & 1) ^ (g2 >> i & 1) != (g3 >> i & 1):
                r1 = g1 % (1 << i) + 1
                r2 = (1<<i) - g2 % (1 << i)
                if r1 < r2:
                    g1 -= r1
                    g2 += r1
                    ans += r1
                    break
                elif r1 > r2:
                    g1 -= r2
                    g2 += r2
                    ans += r2
                    break
                else:
                    print(-1)
                    exit()
            if g1 ^ g2 == g3:
                if ans != A[0]:
                    print(ans)
                else:
                    print(-1)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 68324
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;


long double pow(long double A, int P){
	int a = A, p = P;
	if(p == 0) return 1;
	if(p == 1) return a;
	int adash = a * a;
	if(p % 2) return pow(adash, p / 2) * a;
	else return pow(adash, p / 2);
}
int main(){
	int N, K;
	cin >> N >> K;
	long double n = N * 1.0;
	long double k = K * 1.0;
	long double ans = 0;
	for(int i=1;i<=N;i++){
		long double now = i * 1.0;
		long double ans1 = 1.0 / n;
		while(now < k){
			now *= 2;
			ans1 /= 2.0;
		}
		ans+= ans1;
	}
	printf("%1.10Lf", ans);
}

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 vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<vector<P>> a(n);
    rep(i,n){
        int b;
        cin >> b;
        rep(j,b){
            int x,y;
            cin >> x >> y;
            x--;
            a[i].push_back(make_pair(x,y));
        }
    }
    int ans = 0;
    for(int i=0;i<(1<<n);i++){
        bitset<15> bit(i);
        bool ok = true;
        rep(j,n) if(bit.test(j)){
            rep(k,a[j].size()){
                int x = a[j][k].first;
                bool honto = a[j][k].second;
                if(bit.test(x)!=honto){
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok){
            ans = max(ans,(int)bit.count());
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  private[this] var cnt = 0
  private[this] val l = new Array[Int](260000)
  private[this] val r = new Array[Int](260000)

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

 def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w = w/2
    }

    def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] = {
      if(h==0) l
      else
        scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(a,e._1,mid,e._2)
      }
    }
    merge(a,0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

Measured memory_bytes: 321000
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  vector<string> vec;
  cin >> n >> m;
  rep(i,0,n){
    cin >> s;
    vec.pb(s);
  }
  rep(i,0,m+2)cout << "#";
  puts("");
  rep(i,0,n){
    cout << "#" << vec[i] << "#" << endl;
  }
  rep(i,0,m+2)cout << "#";
  puts("");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+100;
const int inf=0x3f3f3f;

vector<string> vc;
map<string,int>mp;
int goal[N];
int main(){
    int n,x,y,z;
    cin>>x>>y>>z;
    bool flag=0;
    if(x==y&&x==z)
        flag=0;
    else if(x==y||y==z||x==z)
        flag=1;
    if(flag)
        puts("Yes");
    else
        puts("No");
    return 0;
}
/*
87
13
4
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int a[n];
  ll sum=0,sum1=0,sum2=0,sum3=0;
  rep(i,0,n){
    cin>>a[i];
    a[i]=(a[i]-i-1);
  }
  sort(a,a+n);
  if(n%2) sum=a[n/2];
  else sum= (a[n/2]+a[n/2-1])/2;
  rep(i,0,n) sum1+= abs(a[i]-sum);
  sum-=1;
  rep(i,0,n) sum2+= abs(a[i]-sum);
  sum+=2;
  rep(i,0,n) sum3+= abs(a[i]-sum);
  cout<<min(sum3,min(sum1,sum2))<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 4424
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
vector<vi> adj ;
vector<bool> visited ;
vll a ;
void dfs(int u){
	visited[u] = true ;
	for(int x:adj[u]){
		if(!visited[x]){
			a[x] += a[u] ;
			dfs(x) ;
		}
	}
}
//check modulo
int main(){
	IOS;
	cout.precision(30) ;
	int n , q ; cin >> n >> q ;
	int u , v ;
	adj.resize(n) ;
	a.resize(n , 0) ;
	visited.resize(n , false) ;
	for(int i = 0 ; i < n - 1 ; i++){
		cin >> u >> v;
		u--;v-- ;
		adj[u].pb(v);
		adj[v].pb(u) ;
	}
	int p ; ll x ;
	for(int i = 0 ; i < q ; i++){
		cin >> p >> x;
		p--;
		a[p] += x;
	}
	dfs(0) ;
	for(int i = 0 ; i < n ; i++) cout << a[i] << " " ;
	cout << endl; 
	return 0;
}


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

int main() {
  int N;
  cin >> N;

  if (N / 100 == 7 || (N % 100) / 10 == 7 || N % 10 == 7)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3604
n = int(input())
txy = []
for i in range(n):
    txy.append(list(map(int,input().split())))
ok = True
for i in range(n):
    if i == 0 : 
        if txy[0][0] < txy[0][1] + txy[0][2] or (txy[0][0] - txy[0][1] + txy[0][2])%2 != 0 :
            ok = False
    else:
        time = txy[i][0] - txy[i-1][0]
        dis = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])
        if time < dis or (time-dis)%2 != 0:
            ok = False

print('Yes' if ok else 'No')

Measured memory_bytes: 27300
def main():
    INF = 10**12
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))
    H = [0] + H
    # dp[n][k][l]: n列目までで合計k列Hの値を変えている＆直近l列を変えている場合の塗りの回数の最小値
    # 答えは min_{k,l}(dp[N][k][l])
    dp = [[[INF for _ in range(K + 1)] for _ in range(K + 1)] for _ in range(N + 1)]
    dp[0][0][0] = 0
    for n in range(1, N + 1):
        for k in range(min(n, K) + 1):
            v = INF
            for l in range(k + 1):
                if l > 0:
                    dp[n][k][l] = dp[n - 1][k - 1][l - 1]
                v = min(v, dp[n - 1][k][l] + max(0, H[n] - H[n - l - 1]))
            dp[n][k][0] = v
    ans = INF
    for k in range(K + 1):
        for l in range(k + 1):
            ans = min(ans, dp[N][k][l])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 300864
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> N >> M;
	map<int, int>xp;
	map<int, int>yp;
	vector<int>x(N);
	vector<int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		xp[x[i]] = 0;
		yp[y[i]] = 0;
	}
	int cnt = 0;
	xp[MOD] = yp[MOD] = xp[-MOD] = yp[-MOD] = 0;
	for (auto &i : xp) {
		i.second = cnt++;
	}
	cnt = 0;
	for (auto &i : yp) {
		i.second = cnt++;
	}
	H = yp.size(), W = xp.size();
	vector<vector<int>>sum(H, vector<int>(W));
	for (int i = 0; i < N; i++) {
		sum[yp[y[i]]][xp[x[i]]]++;
	}
	for (int i = 0; i < H; i++) {
		for (int j = 1; j < W; j++) {
			sum[i][j] += sum[i][j - 1];
		}
	}
	for (int i = 1; i < H; i++) {
		for (int j = 0; j < W; j++) {
			sum[i][j] += sum[i - 1][j];
		}
	}
	//cout << H << " " << W << endl;
	while (M--) {
		cin >> L >> R;
		int sx = xp.lower_bound(L)->second;
		int sy = yp.lower_bound(R)->second;
		cin >> L >> R;
		int gx = xp.upper_bound(L)->second - 1;
		int gy = yp.upper_bound(R)->second - 1;
	//	cout << sy << " " << sx << " " << gy << " " << gx << endl;
		sy--, sx--;
		cout << sum[gy][gx] - sum[gy][sx] - sum[sy][gx] + sum[sy][sx] << endl;
	}
}


Measured memory_bytes: 101372
#include <iostream>
#include <vector>
#define REP(i,n) for(int i = 0; i < (n); i++)

using namespace std;

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

int main()
{
  int N, K; cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int g = A[0];
  bool is_ge = false;
  REP(i, N) {
    g = gcd(g, A[i]);
    if (A[i] >= K) is_ge = true;
  }
  if (is_ge && K % g == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 640