akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
    p[i]--;
  }

  vector<ll> a(n - 1), b(n - 1), c(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<int> cum(n, 0);
  for (int i = 0; i < m - 1; i++) {
    int l = min(p[i], p[i + 1]), r = max(p[i], p[i + 1]);
    cum[l]++;
    cum[r]--;
  }
  for (int i = 1; i < n; i++) {
    cum[i] += cum[i - 1];
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += min(a[i] * cum[i], b[i] * cum[i] + c[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n;
  cin>>n;
  string s;cin>>s;
  ll p=n,q=n,c=0;
  vector <ll> red,white;
  fo(i,n)
  {
      if(s[i]=='W')
      white.pb(i);
  }
  fo(i,n)
  {
      if(s[i]=='R')
      red.pb(i);
  }
  for(auto x:white)
  {
      auto it=upper_bound(all(red),x);
      if(it==red.end())
      break;
      else
      {
          c++;
          auto it1=red.end();
          --it1;
          red.erase(it1);;
      }
  }
  cout<<c;
  
  return 0;
}

Measured memory_bytes: 5856
S = input()
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        print(i + 1, i + 2)
        exit()

for i in range(len(S) - 2):
    if S[i] == S[i + 2]:
        print(i + 1, i + 3)
        exit()

print(-1, -1)


Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,a,f=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a%2==0)
		{
			if(a%3&&a%5)
			{f=0;break;}
		}
	}
	if(f)puts("APPROVED");
	else puts("DENIED");
	return 0;
}


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

l = []

for i in range(0,26):
    t = 4*i
    l.append(t)
    for j in range(0,15):
        t = t  + 7*j
        if t > 100:
            continue
        l.append(t)
    if t > 100:
        continue

if (n in l):
    print("Yes")
else:
    print("No")

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main(){

    string S;
    cin >> S;

    ll Q;
    cin >> Q;

    ll rev = 0;
    deque<char > deq;
    for(ll i = 0; i < S.length(); i++){
        deq.push_back(S[i]);
    }

    for(ll i = 0; i < Q; i++){
        ll t; cin >> t;
        if(t == 1){
            rev++;
        }else{
            ll f; cin >> f;
            char c; cin >> c;
            if(rev % 2 == 0){
                if(f == 1) deq.push_front(c);
                if(f == 2) deq.push_back(c);
            }else{
                if(f == 1) deq.push_back(c);
                if(f == 2) deq.push_front(c);                
            }
        }
    }

    while(!deq.empty()){
        if(rev % 2 == 0){
            cout << (char)(deq.front());
            deq.pop_front();
        }else{
            cout << (char)(deq.back());
            deq.pop_back();
        }
    }
    cout << endl;
    

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin>>N;
    map<string, int> mp;
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        mp[S]++;
    }
    int m = 0;
    for(auto p : mp){
        m = max(m, p.second);
    }
    for(auto p : mp){
        if(m == p.second){
            cout << p.first << endl;
        }
    }
    
}

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

int main() {
  int A,B;
  cin>>A>>B;
      int count=0;
  for(int i=A;i<B+1;i++){
    int five=0;
    int four=0;
    int three=0;
    int two=0;
    int one=0;
    int i_buff=i;
    if(i_buff>100000){
      five = i_buff/100000;
      i_buff %= 100000;
    }
    if(i_buff>10000){
      four= i_buff/10000;
      i_buff %= 10000;
    }
    if(i_buff>1000){
      three = i_buff/1000;
      i_buff %= 1000;
    }
    if(i_buff>100){
      two= i_buff/100;
      i_buff %= 100;
    }
    if(i_buff>10){
      one= i_buff/10;
      i_buff %= 10;
    }
    if(five!=0){
      if(five==i_buff&&four==one&&three==two){
        count++;
      }
    }else if(four!=0){
      if(four==i_buff&&three==one){
        count++;
      }
    }else if(three!=0){
      if(three==i_buff&&two==one){
        count++;
      }
    }else if(two!=0){
      if(two==i_buff){
        count++;
      }
    }else if(one!=0){
      if(one==i_buff){
      count++;
      }
    }
  } 
  cout<<count<<endl;
  // ここにプログラムを追記
  
}




Measured memory_bytes: 256
from collections import deque
def dfs(s):
    q.append(s)
    d = [INF] * n
    d[s] = 0
    while len(q):
        u = q.popleft()
        for v in range(n):
            if M[u][v] == 0:
                continue
            if d[v] != INF:
                continue
            d[v] = d[u] + 1
            q.append(v)
    for i in range(n):
        if d[i] == INF:
            d[i] = -1
        print('{} {}'.format(i+1, d[i]))
n = int(input())
data = [list(map(int, input().split()))for _ in range(n)]
#print(data)
color = []
INF = 1000000000000000000000000000000000000000
M = [[0 for _ in range(n)]for _ in range(n)]
q = deque([])
for i in data:
    for j in i[2:]:
        M[i[0]-1][j-1] = 1
dfs(0)



Measured memory_bytes: 6088
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int t, p, r;
    while(cin >> t >> p >> r, t+p+r){
        bool correct[t][p];
        int penalty[t][p];
        rep(i, t)rep(j, p){penalty[i][j] = 0; correct[i][j] = false;}
        rep(k, r){
            int team, problem, time;
            string message;

            cin >> team >> problem >> time >> message;
            team--; problem--;

            if(message == "CORRECT"){
                correct[team][problem] = true;
                penalty[team][problem] += time;
            }
            else {
                penalty[team][problem] += 1200;
            }
        }

        vector<pair<int, pair<int, int> > > v(t);
        rep(i, t){
            int ca = 0, pn = 0;
            rep(j, p){
                if(correct[i][j]){
                    ca++;
                    pn += penalty[i][j];
                }
            }
            v[i] = mp(ca, mp(inf-pn, 100-i));
        }
        sort(all(v));

        for(int i=t-1; 0 <= i; i--){
            cout << 100-v[i].second.second+1 << " " << v[i].first << " " << inf-v[i].second.first << endl;
        }
    }
}

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

int main(){

    int n,t;
    int minc=1000;
    bool can=false;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        int c,tt;
        cin>>c>>tt;
        if(tt<=t){
            minc=min(minc,c);
            can=true;
        }
    }

    if(can) cout<<minc<<endl;
    else cout<<"TLE"<<endl;


    return 0;
}

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

int main(){
    int n,r;
    cin >> n>>r;
    int ans=0;
    rep(i,100000000){
        int m = pow(r,i);
        if(m==n){
            ans = i+1;
            break;
        }
        if(m>=n){
            ans = i;
            break;
        }
    }

    cout <<ans<<endl;
}





Measured memory_bytes: 4064
#include<iostream>
#include<algorithm>
#include<iomanip>

using namespace std;
int N;
int t[100], s[100];
double dp[40001][202];

//2倍したtimeを入れて、その時の限界速度を返す
int getlimit(double time) {
	double sum = 0;
	time /= 2;
	for (int i = 0; i < N; i++) {
		sum += t[i];
		if (time <= sum) {
			if (time == sum) {
				if(i != N - 1)
					return min(s[i], s[i + 1]);
				return s[i];
			}
			return s[i];
		}
	}
	return s[N - 1];
}

int main() {
	int totalt = 0;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> t[i], totalt += t[i];
	for (int i = 0; i < N; i++)cin >> s[i];
	for (int i = 0; i < totalt * 2; i++)for (int j = 0; j <= 200; j++)dp[i][j] = -114514810;
	dp[0][0] = 0;
	//dp[i][j]:i / 2秒の時に速度がj / 2の時の距離の最大値
	for (int i = 0; i < totalt * 2; i++) {
		int limit = getlimit(i) * 2;
		for (int j = 0; j <= limit ; j++) {
			if (dp[i][j] < 0)continue;
			if (j + 1 <= getlimit(i + 1) * 2) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (2 * j + 1) * 0.25 / 2);
				// 全速力で加速
			}
			if (j - 1 >= 0 && j - 1 <= getlimit(i + 1) * 2) {
				dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + (2 * j - 1) * 0.25 / 2);
				//全速力で減速
			}

			if(j <= getlimit(i + 1) * 2)
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 0.5 * j / 2);
				//速度を維持
		}
	}
	cout << fixed << setprecision(10) << dp[totalt * 2][0] << endl;
	return 0;
}

Measured memory_bytes: 63360
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)
bef = -1
for x in a:
    if bef + 1 == x:
        ans += c[bef - 1]
    bef = x
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const string G = "GREATER";
const string L = "LESS";
const string E = "EQUAL";

int main(){
  string a, b;
  cin >> a >> b;
  if(a.size() > b.size()) cout << G << endl;
  else if(a.size() < b.size()) cout << L << endl;
  else{
    if(a > b) cout << G << endl;
    else if(a < b) cout << L << endl;
    else cout << E << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
N = int(input())

X = list(map(int,input().split()))

maxlst = []
minlst = []
R = 10**10
L = 0
for i in range(N):
	L = max(X[i],L) 
	maxlst.append(L)
	R = min(X[-i-1],R)
	minlst.append(R)

minlst.reverse()
for i in range(N-1):
	if maxlst[i]-minlst[i+1] > 1:
		print("No")
		exit()
print("Yes")

Measured memory_bytes: 14704
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

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

const ll mod = 1e6;
const int N = 1e3 + 5, M = 35;
const ll INF = 1e15;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

int t;

int main()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define ull              unsigned long long
#define f                first
#define s                second
#define sqr(x)           (x)*(x)
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define intlim           2147483648
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define mk(x1,y1) make_pair(x1, y1)
#define maxl 1000010
#define psz 20
using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdin);
//ios_base::sync_with_stdio(false);
 //cin.tie(NULL);
//Code starts from here......
int n;
int a[200100];

ll ans = 1e18;

ll cal(ll mid){

    ll minu = mid, sum = 0;

    for(int i=0; i<n; i++, minu++) sum += abs(a[i]-minu);
        
   // cout<<"M  "<<mid<<"  "<<sum<<endl;

    return sum;
}

ll Turn(ll left , ll right){

    while(left <= right){

        ll mid1 = left+( (right-left)/3 );
        ll mid2 = mid1+( (right-left)/3 );

        ll tot1 = cal(mid1);
        ll tot2 = cal(mid2);

        if(tot1 < tot2){

            right = mid2-1;
            ans = min(ans,tot1);
        }
        else if(tot1>=tot2){

            left = mid1+1;
            ans = min(ans,tot2);
        }
        //cout<<"  "<<mid1<<" "<< tot1<<"  "<<mid2<<"  "<<tot2<<endl;

        //cout<<">>>>>>>>>>>>>>>>>>>>>"<<"  "<<left<<"  "<<right<<endl;

    }

}
int main(){

    scanf("%d",&n);

    for(int i=0; i<n; i++){

        scanf("%d",&a[i]);

    }

    Turn(-1e9,1e9);
    ll ans1 = ans;
    cout<<ans1<<endl;

    return 0; 
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)

vector<vector<int>> d;
vector<int> color;


bool dfs(int v = 0, int c = 1) {
	color[v] = c;
	rep(nv, 0, d[v].size()) {
		if (d[v][nv] == 1) {
			if (color[nv] == c) return false;
			if (color[nv] == 0 && !dfs(nv, -c)) return false;
		}
	}
	return true;
}


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

	int n; cin >> n;
	int ans = 0;
	char c;
	d.resize(n, vector<int>(n, 1 << 29));
	color.resize(n, 0);
	rep(i, 0, n) {
		rep(j, 0, n) {
			cin >> c;
			if (c == '1') d[i][j] = 1;
		}
		d[i][i] = 0;
	}
	if (!dfs()) {
		cout << -1;
		return 0;
	}
	
	rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	rep(i, 0, n) rep(j, 0, n) {
		ans = max(ans, d[i][j]);
	}
	cout << ans + 1;

	return 0;
}

Measured memory_bytes: 3804
N = int(input())
G = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    ls = list(map(int,input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u][v-1] = 1

for row in G:
    print(' '.join(map(str,row)))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  REP(i,n+1)REP(j,m+1){
    int a = i*(m-j) + j*(n-i);
    if(a==k){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  char x, y;
  cin >> x >> y;
  if (x == y) cout << "=" << endl;
  else cout << (x < y ? "<" : ">") << endl;
}


Measured memory_bytes: 256
#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 <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x/GCD(x,y)*y;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{

vector<double> A(5),B(5);

rep(i,5) cin>>A[i];
rep(i,5) B[i]=ceil(A[i]/10)*10;

double M=B[0]-A[0];

rep(i,4) M=max(M,B[i+1]-A[i+1]);

int S=0;

rep(i,5) S+=B[i];

cout << S-M << endl;

}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl(1);
const ll mod = 1000000007;
//const ll mod = 998244353;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
  ll n;cin>>n;
  vector<ll>A(n);
  rep(i,n)cin>>A[i];

  vector<ll>v;
  rep(i,n)v.push_back(A[i]-i-1);
  sort(all(v));

  ll s=v.size();
  s/=2;
  ll b=v[s];
  
  ll ans=0;
  rep(i,n){
    ans+=abs(A[i]-(i+1)-b);
  }
  cout<<ans<<endl;

}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);cout<<fixed;
  cout<<setprecision(30);
  solve();
}


Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>

using namespace std;

int s(int num){
    int sum = 0;
    while(num){
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

int main(){

    int n;

    cin >> n;

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Node{
  int key;
  Node *pr;
  Node *rt;
  Node *lt;
};

Node *root,*nil;
  
void insert(int k){
  Node *x=root, *y=nil, *z;

  z = new Node;
  z->key=k;
  z->rt=z->lt=nil;

  while(x!=nil){
    y=x;
    if(z->key < x->key) x=x->lt;
    else x=x->rt;
  }
  z->pr = y;

  if(y==nil) root=z;
  else if(z->key < y->key) y->lt=z;
  else y->rt=z;
}

void preo(Node *r){
  if(r==nil) return;
  cout << " " << r->key;
  preo(r->lt);
  preo(r->rt);  
}

void ino(Node *r){
  if(r==nil) return;
  ino(r->lt);
  cout << " " << r->key;
  ino(r->rt);
}

int main(){
  int m,k;
  string str;

  cin >> m;
  for(int i=0;i<m;i++){
    cin >> str;
    if(str=="insert"){
      cin >> k;
      insert(k);
    }
    else if(str=="print"){
      ino(root);
      cout << endl;
      preo(root);
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 26496
import itertools
n = int(input())
s = input()
rui_rl = [0] + list(itertools.accumulate([1 if x == 'R' else 0 for x in s]))
rui_gl = [0] + list(itertools.accumulate([1 if x == 'G' else 0 for x in s]))
rui_bl = [0] + list(itertools.accumulate([1 if x == 'B' else 0 for x in s]))
rui = {'R': rui_rl, 'G': rui_gl, 'B': rui_bl}
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            continue

        if 'R' not in [s[i], s[j]]:
            target = 'R'
        elif 'G' not in [s[i], s[j]]:
            target = 'G'
        else:
            target = 'B'

        dif_ji = j-i

        ans += rui[target][-1] - rui[target][j+1]
        if j+dif_ji <= n-1:
            if s[j+dif_ji] == target:
                ans -= 1
print(ans)


Measured memory_bytes: 68944
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    budget = 1000
    stock = 0
    temp = 0

    for i in range(n-1):
        if A[i] < A[i+1] and A[i] <= temp+budget:
            budget += temp
            temp = 0
            stock = budget//A[i]
            budget %= A[i]
        elif A[i+1] < A[i]:
            budget += A[i]*stock
            stock = 0

    return str(A[-1]*stock+budget)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
void dispdp(int* dp){
	for (int i = 0; i < 10; ++i)
	{
		printf("%2d ",dp[i]);
	}
	printf("\n");
}
int main(){
	// freopen("in.txt","r",stdin);
	int N;
	int A[100100];//客が来る時間
	int dp[100100]={0};
	long long SUM = 0;
	cin >> N ;
	for (int i = 0; i < N; ++i)
	{
		scanf("%d",&A[i]);
	}
	sort(A,A+N);
	for (int i = 0; i < N; ++i)
	{
		SUM += A[i];
		
		if(A[i+1] <= SUM*2) dp[i+1]=dp[i]+1;
		// dispdp(dp);
	}
	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 1024
A,B,C = map(int,input().split())
ans = 0

if not (A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
  print(0)
  exit()

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)


Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    if(n!=m){
      System.out.println("No");
    }
    else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 23380
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c,k,t=0;
	std::cin >> a >> b >> c;
	std::cin >> k;
	while(!(a<b)){
		b *= 2;
		++t;
	}
	while(!(b<c)){
		c *= 2;
		++t;
	}
	std::cout << ((t>k)?"No":"Yes") << std::endl;
	return 0;
}


Measured memory_bytes: 3632
// 22
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 5
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, len(v)) o << setw(7) << left << v[i];
  return o << endc << endl << coutc;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
template <class T, class... Ts>
void debug(const T &e, const Ts &... r) {
#ifdef DEBUG
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
#endif
}
// 3
void _main(int tc) {
  int n;
  cin >> n;
  set<string> s;
  rep(n) {
    string x;
    cin >> x;
    s.insert(x);
  }
  cout << len(s) << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 19196
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    long long N;
    long long x;
    cin >> N;
    map<long long, long long> A;
    for(int i=0; i<N; i++){
        A[i] = 0;
    }
    for(int i=0; i<N-1; i++){
        cin >> x;
        A[x-1]++;
    }
    for(int i=0; i<N; i++){
        cout << A[i] << endl;
    }
}


Measured memory_bytes: 16128
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<ll> A(N),acc(N+1,0LL); // acc[i] [0,i)の和
    ll len = 0,ansMin=2020202020LL * 200000LL + 10LL;
    rep(i,N) cin >> A[i],len+=A[i];
    rep(i,N) acc[i+1] = acc[i] + A[i];
    rep(i,N+1){
        ansMin = min(ansMin,abs(len-acc[i]-acc[i]));
    }
    cout << ansMin << nn;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (int)1e6 + 77;
ll f[N], rf[N];

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	int n, m;
	scanf("%d%d", &n, &m);
	ll ans = 0;
	for (int k = 1; k <= min(n, m); k++)
		ans = add(ans, mult(getC(2 * k, k), getC(n + m - 2 * k, n - k)));
	ans = mult(ans, rev(mult(2, getC(n + m, m))));
	ans = add(ans, max(n, m));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 19436
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42

#define endl '\n'

#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < long long, long long >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)

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

#define mp(a,b) make_pair(a,b)
#define first first
#define ss second

void check()
{
    if(false)
    cout<<"check"<<endl;
}



int main() {


	long long t, i, x, j, y, m,	z = 0, k, n;
	cin >> n >> m;
	string s[n];
    check();
	long long cx, cy, dx, dy;
	 check();
	cin >> cx >> cy >> dx >> dy;
	cx--;
	cy--; 
	dx--; 
	dy--;
	 check();
	 cx++;
	cy++; 
	dx++; 
	dy++;
   
	
	long long dynamicprogramming[n][m];
 cx--;
	cy--; 
	dx--; 
	dy--;
	for(long long i=0;i<n;i++) {
		cin >> s[i];
		rep(j, 0, m, 1)	dynamicprogramming[i][j] =  1000000007;
	}


	priority_queue<pair<long long, pll>> q;
	q.push(mp(0, mp(cx, cy)));

	if (s[cx][cy] != '.')	return cout << -1, 0;

	dynamicprogramming[cx][cy] = 0;

	long long x_mo[] = {1, 0, -1, 0};
	long long y_mo[] = {0, 1, 0, -1};

	while (q.size()) {
		pair<long long, pll> temp = q.top();
		q.pop();
		x = temp.ss.first, y = temp.ss.ss;
		if (temp.first != -dynamicprogramming[x][y])
		{
		continue;
        }
		for (i = 0; i < 4; i++) {
			long long xxx = x + x_mo[i];
			long long newY = y + y_mo[i];

			if (xxx<n and xxx >= 0 and newY >= 0 and newY < m) {
				if (s[xxx][newY] == '.' and dynamicprogramming[x][y] < dynamicprogramming[xxx][newY] ) {
					dynamicprogramming[xxx][newY] = min(dynamicprogramming[x][y], dynamicprogramming[xxx][newY]);
					
					q.push(mp(-dynamicprogramming[xxx][newY], mp(xxx, newY)));

				}
			}
		}

		for (i = -2; i <= 2; i++) {
			for (j = -2; j <= 2; j++) {
				long long xxx = x + i;
				long long newY = y + j;

				if (xxx<n and xxx >= 0 and newY >= 0 and newY < m) {
					if (s[xxx][newY] == '.' and dynamicprogramming[x][y] + 1 < dynamicprogramming[xxx][newY] ) {
						dynamicprogramming[xxx][newY] = min(dynamicprogramming[x][y] + 1, dynamicprogramming[xxx][newY]);
						q.push(mp(-dynamicprogramming[xxx][newY], mp(xxx, newY)));
					}
				}
			}
		}
	}

	z = dynamicprogramming[dx][dy];

	if (!(!(z ==  1000000007)))
	{z = -1;
	};
	cout<<z<<"\n";
	debug(z);
}

Measured memory_bytes: 13612
#include "bits/stdc++.h"
 
using namespace std;
 
class UnionFind
{
    std::vector<int> data;
 
  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};
 
struct Edge
{
    int from, to, cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};
 
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using P = std::pair<int, int>;
constexpr int INF = 1e9;
 
// 逆順にしているので注意
bool operator<(const Edge &e, const Edge &f)
{
    return e.cost > f.cost;
}
 
// プリム法による最小全域木
// 到達可能な頂点への辺の内, コストが最小のものを選んでいく
// O(ElogV)
int prim(const Graph &g)
{
    int sz = g.size();
    int ret = 0;
    std::vector<bool> used(sz, false);
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(P(0, 0));
    while (!que.empty())
    {
        P p = que.top();
        if (used[p.second])
            continue;
        used[p.second] = true;
        ret += p.first;
        for (const auto &e : g[p.second])
        {
            que.push(P(e.cost, e.to));
        }
    }
    return ret;
}
 
// クラスカル法による最小全域木
// 辺を重みが小さい順に閉路を作らないように追加していく
// O(ElogV), V := 頂点数
int kruskal(Edges &es, int V)
{
    UnionFind uf(V);
    int ret = 0;
    sort(es.rbegin(), es.rend());
    for (const auto &e : es)
    {
        if (!uf.find(e.from, e.to))
        {
            ret += e.cost;
            uf.unite(e.from, e.to);
        }
    }
    return ret;
}
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int V, E;
    cin >> V >> E;
    Edges es;
    Graph g(V);
    for (int i = 0; i < E; i++)
    {
        int s, t, w;
        cin >> s >> t >> w;
        es.push_back(Edge{s, t, w});
        g[s].push_back(Edge{s, t, w});
        g[t].push_back(Edge{t, s, w});
    }
    cout << kruskal(es, V) << endl;
}


Measured memory_bytes: 8384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int h[] = new int[a];
		for(int k = 0; k < a; k++){
			h[k] = sc.nextInt();
		}
		boolean flg1 = true;
		boolean flg2 = false;

		for(int i = 1; i < a; i++){
			if(h[i] - h[i-1] == -1 && flg2 == false){
				flg2 = true;
			}
			else if(h[i] - h[i-1] == -1 && flg2 == true){
				flg1 = false;
				break;
			}
			else if(h[i] - h[i-1] > 0){
				flg2 = false;
			}
			else if(h[i] - h[i-1] < -1){
				flg1 = false;
				break;
			}
		}

		if(flg1){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 52372
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

namespace IntegerMath
{
  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }    

  int64_t log10(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log10l( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t number_of_digits(int64_t x) {
    return static_cast<int64_t>(
      ::ceill( ::log10l( 
        static_cast<long double>(x + 1)
      ) )
    );
  }

  uint64_t gcd(uint64_t a, uint64_t b)
  {
    uint64_t n = std::min(a, b), m = std::max(a, b);
    return (n == 0) ? m : gcd(m % n, n);
  }

  uint64_t lcm(uint64_t a, uint64_t b)
  {
    uint64_t d = gcd(a, b);
    return (a % d == 0) ? (a / d) * b : a * (b / d);
  }
};

int main(int argc, char **argv)
{
  uint64_t N, M;
  std::cin >> N >> M;
  
  std::string S, T;
  std::cin >> S >> T;
  
  uint64_t L = IntegerMath::lcm(N, M);
  std::map<uint64_t, char> map;
  
  N_TIMES(n, N) {
    map.emplace(n * (L / N), S[n]);
  }
  
  N_TIMES(m, M) {
    map.emplace(m * (L / M), T[m]);
  }
  
  bool flag = true;
  
  N_TIMES(n, N) {
    auto itr = map.find(n * (L / N));
    if ((itr != map.end()) && (itr->second != S[n])) {
      flag = false;
      break;
    }
  }
  
  if (!flag) { goto RESULT_OUTPUT; }
  
  N_TIMES(m, M) {
    auto itr = map.find(m * (L / M));
    if ((itr != map.end()) && (itr->second != T[m])) {
      flag = false;
      break;
    }
  }
  
RESULT_OUTPUT:
  std::cout << static_cast<int64_t>(flag ? L : -1) << std::endl;
  
  return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
double dp[303][303][303];
int n,cnt[4];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int k=0;k<=300;k++)
		for(int j=0;j<=300;j++)
			for(int i=0;i<=300;i++){
				if(i||j||k){
					if(i+j+k>n)break;
					if(i)dp[i][j][k]+=dp[i-1][j][k]*i;
					if(j)dp[i][j][k]+=dp[i+1][j-1][k]*j;
					if(k)dp[i][j][k]+=dp[i][j+1][k-1]*k;
					dp[i][j][k]=(dp[i][j][k]+n)/(i+j+k);
				}
			}
	printf("%.12lf\n",dp[cnt[1]][cnt[2]][cnt[3]]);
	return 0;
}
/*
10
1 3 2 3 3 2 3 2 1 3
*/

Measured memory_bytes: 217344
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
count = 0

for i in range(2**n):
  SUMLIST = []
  SUM = 0
  check = 0
  l = [0]*n
  for j in range(n):
    if ((i >> j)&1):
      l[n-j-1] = 1
  
  for switch in ks:
    for each in switch[1:]:
      SUM += (l[each-1])
    SUMLIST.append(SUM)
    SUM = 0
  
  for i in range(m):
    if SUMLIST[i]%2 == p[i]:
      check += 1
 
  if check == m:
    count += 1

print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <sstream>
#include <cmath>

using namespace std;

typedef long long LL;


vector<vector<LL>> creat_matrix(LL h, LL w) {
	LL _temp;
	vector<vector<LL>> mat;
	for (LL i = 0; i < h; ++i) {
		vector<LL> vec;
		for (LL j = 0; j < w; ++j) {
			cin >> _temp;
			vec.emplace_back(_temp);
		}
		mat.emplace_back(vec);
	}
	return mat;
}


vector<vector<LL>> inner_product(vector<vector<LL>> X, vector<vector<LL>> Y) {
	size_t n = X.size();
	size_t m = X[0].size();
	size_t l = Y[0].size();

	vector<vector<LL>> mat(n, vector<LL>(l, 0));
	for (LL i = 0; i < n; ++i) {
		for (LL j = 0; j < m; ++j) {
			for (LL k = 0; k < l; ++k) {
				mat[i][k] += X[i][j] * Y[j][k];
			}
		}
	}
	return mat;
}


void show_matrix(vector<vector<LL>> mat) {
	size_t len = mat[0].size();
	for (auto&& t : mat) {
		for (LL i = 0; i < len; ++i) {
			printf("%d", t[i]);
			if (i != (len - 1)) printf(" ");
		}
		printf("\n");
	}
}


int main() {
	string str;
	getline(cin, str);

	for (auto&& _str : str) {
		if (isupper(_str)) printf("%c", tolower(_str));
		else if (islower(_str)) printf("%c", toupper(_str));
		else printf("%c", _str);
	}
	printf("\n");
	return 0;
}



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





int main() {
    int  n;
    cin >> n;
    if (n / 100 == 1) {
        n += 800;
   }
    else n -= 800;
    if (n % 100/10 == 1) {
        n += 80;
    }
    else n -= 80;
    if (n % 10 == 1) {
        n += 8;
    }
    else n -= 8;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    ll M = 0, ans = 0;
    rep(i, N) {
        chmax(M, A[i]);
        ans += M - A[i];
    }

    cout << ans << endl;
}   

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

int main() {
  int X,Y,ans=0;
  cin >> X >> Y;
  if(X==1) ans += 300000;
  if(X==2) ans += 200000;
  if(X==3) ans += 100000;
  if(Y==1) ans += 300000;
  if(Y==2) ans += 200000;
  if(Y==3) ans += 100000;
  if(X==1 && Y==1) ans += 400000;
  
  cout << ans << endl;
  return 0;
}


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



int32_t main()
{

   string str;
   cin>>str;

   if(str[str.size()-1]=='s'){
    cout<<str<<"es"<<endl;
   }
   else cout<<str<<"s"<<endl;

    return 0;
}


Measured memory_bytes: 3596