akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
string S;

void solve(){
	int ans = 0;
	rep(i, S.size()){
		if(i % 2 == 0 and S[i] == 'p')
			ans--;
		else if(i % 2 == 1 and S[i] == 'g')
			ans++;
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> S;
		solve();
	return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ll n = 100, year = 0;
    ll m; cin >> m;
    while(n < m)
    {
        year++;
        n += n/100;
    }
    cout << year << endl;
    return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    char s[13];
    int n = 0, bs = 0;
    cin >> s;
    while (s[n] != '\0') n++;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'B') bs++;
        else {
            if (bs > 0) {
                s[i] = 'N';
                bs--;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (s[i] != 'B' && s[i] != 'N') cout << s[i];
    }
    return 0;
}



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

int main(void) {

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


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n;
  cin >> n;

  vector<int> v(n), c(n);
  for (auto &x : v) cin >> x;
  for (auto &x : c) cin >> x;

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] > c[i]) {
      ans += v[i] - c[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(i=0, c=T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p){
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
    int i,j,d,v,c,l,r;
    cin >> n;
    for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;

    for(i=0;i<n;i++){
        cin >> v >> d;
        for(j=0;j<d;j++){
            cin >> c;
            if(j==0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i=0;i<n;i++){
        if(T[i].p == NIL) r = i;
    }
    rec(r,0);
    for(i=0;i<n;i++) print(i);

    return 0;
}


Measured memory_bytes: 7800
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	int H = 0;
    	int W = 0;

    	Scanner sc= new Scanner(System.in);

    	while( true ) {
    		H = sc.nextInt();
    		W = sc.nextInt();

    		if( ( H == 0 ) && ( W == 0 ) ) {
    			break;
    		}

    		for( int i = 0 ; i < H ; i++ ) {
    			for ( int j = 0 ; j < W ; j++ ) {
    				if( ( i == 0 ) || ( i == H-1) || ( j == 0 ) || ( j == W-1) ) {
            			System.out.print( '#' );
    				}else {
    					System.out.print( '.' );
    				}
    			}
    			System.out.print( "\n" );
    		}
    		System.out.print( "\n" );
    	}
    	sc.close();
    }
}


Measured memory_bytes: 36684
#include<stdio.h>
#define N 100
#define MAX 2000
#define INFTY (1<<21)


int A[N][N],n;

int prim();

int main(){
  int i,j,s;
  scanf("%d",&n);
  for(i=0; i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&s);
      A[i][j] = (s == -1) ? INFTY : s;
    }
  }
  printf("%d\n",prim());
  return 0;
}


int prim(){
  int i,u,v,minv;
  int sum=0;
  int d[N],p[N],flg[N];

  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    flg[i] = 0;
  }
  d[0] = 0;

  while(1){
    minv = INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && flg[i] != 2){
	u = i;
	minv= d[i];
      }
    }

    if(u==-1)break;
    flg[u] = 2;
    for(v=0;v<n;v++){
      if(flg[v] != 2 && A[u][v] != INFTY){
	if(d[v] > A[u][v]){
	  d[v] = A[u][v];
	  p[v] = u;
	  flg[v] = 1;
	}
      }
    }
  }
  for (i = 0;i<n ;i++){
    if(p[i] != -1)sum += A[i] [p[i]];
  }
  return sum;
}




Measured memory_bytes: 2056
n=int(input());a=[0]*n;l=[list(map(int,input().split()))for i in a];d=1;k=n*~-n
while sum(a)<k and d<1e4:
 L=[1]*n;y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]*L[x]*L[i]==i+1:a[i]+=1;a[x]+=1;L[i]=L[x]=0;y=1
print([k//2,d*y-1][d*y<1e4])

Measured memory_bytes: 53852
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

int main()
{
    map <int, int> rec;
    bool flag = 1;
    int n, num;
    cin >> n;
    rep(i, 1, n)
    {
        cin >> num;
        rec[num]++;
        if (rec[num] > 1)
            flag = 0;
    }
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

#define int long long

int32_t main(){

      int n;
      cin>>n;

      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];

      int dp[n];

      dp[n-1]=0;
      dp[n-2]=abs(a[n-2]-a[n-1]);
      
      for(int i=n-3;i>=0;i--){
         dp[i]=min((abs(a[i]-a[i+1])+dp[i+1]),abs(a[i]-a[i+2])+dp[i+2]);
      }

      cout<<dp[0];
   
}


Measured memory_bytes: 1792
def resolve():
    N = int(input())
    A = input().split()
    ans = 1
    if "0" in A:
        print(0)
    else:
        for i in A:
            ans = int(i) * ans
            if ans > 1e+18:
                print(-1)
                return
        else:
            print(ans)
        return
resolve()

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

int main(){
 	int n,m;
	cin >>n >> m;
	
	vector<int> p(m);
  	vector<pair<long, int> > pairs(m);
	vector<int> ccc(m);
	long t;
	for(int i = 0; i < m; i++) {
		cin >> p[i] >> t;
		pairs[i] = make_pair(t, i);
	}
	sort(pairs.begin(), pairs.end());
	
	vector<int> count(n);
	for(int i = 0; i < m; i++) {
		int t = pairs[i].second;
		count[p[t]-1]++;
		ccc[t] = count[p[t]-1];
	}

	for(int i = 0; i < m; i++) {
		for(int j=0; j < 6 - to_string(p[i]).size(); j++)
			cout << "0";
		cout << p[i];
		for(int j=0; j < 6 - to_string(ccc[i]).size(); j++)
			cout << "0";
		cout << ccc[i] << endl;
	}
}


Measured memory_bytes: 4224
n, m = map(int, input().split())
a = list(map(int, input().split()))

imos = [0] * (2 * m)
diff = [0] * (2 * m)
res = 0
for i in range(n - 1):
    l = a[i] - 1
    r = a[i + 1] - 1
    if l > r:
        r += m
    imos[l + 2] += 1
    imos[r + 1] -= 1
    diff[r + 1] += r - l - 1
    res += r - l

ans = [0] * (2 * m)
tmp = 0
for i in range(2 * m):
    tmp += imos[i]
    if i - 1 >= 0:
        ans[i] += ans[i - 1] + tmp
    else:
        ans[i] += tmp
    ans[i] -= diff[i]
    
max_ = 0
for i in range(m):
    max_ = max(max_, ans[i] + ans[i + m])
print(res - max_)

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;

    vector<int> a(n,0);
    int tmp;
    for (int i = 0; i < q; i++) {
        cin >> tmp;
        a.at(tmp-1)++;
    }

    for (int i = 0; i < n; i++) {
        if (k - q + a.at(i) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


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

int main() {
	char s[1000];
	char command[10];
	int a, b;
	char p[1000];
	int q;
	scanf("%s", s);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%s", &command);
		if (!strcmp(command, "replace")) {
			scanf("%d %d %s", &a, &b, p);
			for (int j = a; j <= b; j++) {
				s[j] = p[j - a];
			}
		}
		else if (!strcmp(command, "reverse")) {
			scanf("%d %d", &a, &b);
			for (int j = a; j <= b; j++) {
				p[j] = s[j];
			}
			for (int j = a; j <= b; j++) {
				s[j] = p[b + a - j];
			}
		}
		else if (!strcmp(command, "print")) {
			scanf("%d %d", &a, &b);
			for (int j = a; j <= b; j++) {
				printf("%c", s[j]);
			}
			printf("\n");
		}
	}
	return 0;
}


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

long long int data[111][111];
  
int main(){
  
  int n;
  cin >> n;
  
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
	cin >> data[i][j];
	data[i][j] += data[i-1][j] + data[i][j-1] - data[i-1][j-1];
      }
    }
  
  long long int ans = -1<<28;
  for(int i=1;i<n+1;i++)
    for(int j=1;j<n+1;j++)
      for(int p=1;p<i+1;p++)
	for(int q=1;q<j+1;q++)
	  ans = max(ans, data[i][j] - data[i-p][j] - data[i][j-q] + data[i-p][j-q]);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1252
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k,x,pos1,pos2,pos3;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> g,b,r;
    for(i=0;i<n;++i)
    {
        if(s[i]=='R') r.pb(i);
        if(s[i]=='B') b.pb(i);
        if(s[i]=='G') g.pb(i);
        
    }
    m=r.size();
    f=b.size();
    t=g.size();
    //cout << t << endl ;
    for(i=m-1;i>=0;--i)
    {
        for(j=f-1;j>=0;--j)
        {
            if(r[i]>b[j])
            {
                x=r[i]-b[j];
                pos1=r[i]+x;
                pos2=b[j]-x;
                pos3=-1;
                if((r[i]+b[j])%2==0)
                    pos3=(r[i]+b[j])/2;
                ans+=t;
                if(binary_search(g.begin(),g.end(),pos1)) ans--;
                if(binary_search(g.begin(),g.end(),pos2)) ans--;
                if(binary_search(g.begin(),g.end(),pos3)) ans--;
                
            }
            else if(r[i]<b[j])
            {
                x=b[j]-r[i];
                pos1=r[i]-x;
                pos2=b[j]+x;
                pos3=-1;
                if((r[i]+b[j])%2==0)
                    pos3=(r[i]+b[j])/2;
                ans+=t;
                if(binary_search(g.begin(),g.end(),pos1)) ans--;
                if(binary_search(g.begin(),g.end(),pos2)) ans--;
                if(binary_search(g.begin(),g.end(),pos3)) ans--;
            }
            //cout << ans << endl ; 
        }
        
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <set>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

#define forsn(i,s,n) for(int i=(s); i<(int)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second

int a[512][512];

int main() {
	int n, m; cin >> n >> m;
	forn(i,n) forn(j,m) {cin >> a[i][j]; a[i][j]--;}
	
	map<int, set<int>> rev;
	
	set<int> who[300];
	set<int> erased;
	
	int pointers[300] = {};
	forn(i,n) who[a[i][0]].insert(i);
	forn(i,m) rev[who[i].size()].insert(i);
	
	int best = 300;
	forn(i,m) {
		int bestSport = *rev.rbegin()->S.begin();
			best = min(best, (int)who[bestSport].size());
		if (i == m - 1) break;
		for (int chabon : who[bestSport]) {
			int	newSport = a[chabon][++pointers[chabon]];
			while (erased.find(newSport) != erased.end()) newSport = a[chabon][++pointers[chabon]];

			who[newSport].insert(chabon);
			
			rev[who[newSport].size() - 1].erase(newSport);
			if (rev[who[newSport].size() - 1].empty()) rev.erase(who[newSport].size() - 1);
			rev[who[newSport].size()].insert(newSport);
			
		}
		rev[who[bestSport].size()].erase(bestSport);
		erased.insert(bestSport);
		if (rev[who[bestSport].size()].empty()) rev.erase(who[bestSport].size());
	}
	cout << best << endl;
	
}


Measured memory_bytes: 5120
#include <stdio.h>
int main()
{   int t,d=1,x=0;

    scanf("%d", &t);
    int a[t*2];
    for (int i = 0; i < t*2; i++)
        {
            scanf("%d", &a[i]);
        }
      for (int i = 0; i < t*2; i+=2)
    {
        if(a[i]==a[i+1])
        {
           x++;
           if(x>=3)
           {
               break;
           }
           continue;

        }
        else
        {
            x=0;
        }
    }
    if(x>=3)
        printf("Yes");
    else
        printf("No");

    return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>

int main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    if (a * b * 1 % 2 ||
        a * b * 2 % 2 ||
        a * b * 3 % 2) {
        puts("Yes");
    }
    else {
        puts("No");
    }

    return 0;
}


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

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

    if(n % 2){
        cout << "No" << endl;
    }else{
        string t;
        for(int i = 0; i < n/2; i++){
            t += s[i];
        }
        t = t+t;
        if(s == t) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  int N, A, B, a, b;
  cin >> N >> A >> B;
  
  a = (N * A);
  b = B;
  if(a < b){
    cout << a << endl;
  }
  else if(a == b){
    cout << a << endl;
  }
  else {
    cout << b << endl;
  }
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
  if(tableF[a] != (ll)-1){
    return tableF[a];
  }
  if(a == 1){
    tableF[1] = 1;
    return (ll)1;
  }
  ll res = a * modfact(a-1,m) % m;
  tableF[a] = res;
  return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   ll res = 1;
   if(r == 0 || n == 0){
     return (ll)1;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
}


int main(){
    ll H,W,A,B;cin >> H >> W >> A >> B;
    ll ans = 0;
    fill(tableF,tableF+200010,-1);
    fill(tableI,tableI+200010,-1);
    tableF[0] = 1;
    tableI[0] = 1;
    for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,MOD);
      tableI[i] = modinv(tableF[i],MOD);
      //cout << tableF[i] << ' ' << tableI[i] << endl;
    }
    for(int i = B+1;i <= W;i++){
        //cout <<i-1+H-A-1 << ' ' << H-A-1 << ' ' << W-i+A << ' ' <<  A-1 << endl;;
        //cout << modCON(i-1+H-A-1,H-A-1,MOD) << ' ' << modCON(W-i+A-1,A-1,MOD) << endl;
        ans += modCON(i-1+H-A-1,H-A-1,MOD)*modCON(W-i+A-1,A-1,MOD);
        ans %= MOD;
    }
    //cout << modCON(3,3,MOD) << endl;
    cout << ans << endl;
}


Measured memory_bytes: 3456
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    int n, C;
    cin >> n >> C;
    vector<tuple<int, int, int> > stc(n);
    rep(i, n) {
        int s, t, c;
        cin >> s >> t >> c;
        stc[i] = make_tuple(s, t, c);
    }
    stc.push_back(make_tuple(0, 0, 0));
    sort(stc.begin(), stc.end());

    vector<pair<int, int> > dp(C, make_pair(0, 0));
    rep(i_, n) {
        int i = i_+1;
        rep(k, C) {
            dp[k].first -= get<0>(stc[i]) - get<0>(stc[i-1]);
        }
        rep(k, C) {
            if(dp[k].first > 0) {
                continue;
            } else if(!dp[k].first && get<2>(stc[i]) == dp[k].second) {
                dp[k].first = get<1>(stc[i]) - get<0>(stc[i]);
                break;
            } else if(dp[k].first < 0){
                dp[k].first = get<1>(stc[i]) - get<0>(stc[i]);
                dp[k].second = get<2>(stc[i]);
                break;
            }
        }
        
    }

    int ans = C;
    rep(i, C) {
        if(dp[i].first == -get<0>(stc[n])) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
#define v_inputrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z <<" "<<x<<" "<<y;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,W;
	cin>>n>>W;
	vector<pair<long long int,long long int> >arr;
	for(int i=0;i<n;i++)
	{
		long long int w,v;
		cin>>w>>v;
		arr.push_back(make_pair(w,v));
	}
	vector<vector<long long int> >dp(n,vector<long long int> (W+1,0));
	for(int i=0;i<n;i++)
	   dp[i][0]=0;
	for(int j=1;j<=W;j++){
		if(j>=arr[0].first)
	        dp[0][j]=arr[0].second;
	    }
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=W;j++){
		if(j<arr[i].first)
		  dp[i][j]=max(dp[i-1][j],dp[i][j]);
		else
		    dp[i][j]=max(dp[i-1][j],(dp[i-1][j-arr[i].first]+arr[i].second));
		}
	}
//	for(int i=0;i<n;i++)
//	{
//		for(int j=0;j<=W;j++)
//		  cout<<dp[i][j]<<" ";
//		cout<<"\n";
//	}
	
	cout<<(dp[n-1][W])<<"\n";
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n, cnt=0;
    cin >> s;
    n = s.length();
    for(int i=0;i<n/2;i++){
        if(s[i] != s[n-1-i])cnt++;
    }
    cout << cnt << '\n';
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    if(i+1 < s.size() && s[i] == s[i+1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    if(i+2 < s.size() && s[i] == s[i+2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
from collections import deque

n = int(input())
tree = [[] for _ in range(n)]
color = dict()
edge = [(0, 0)] * (n-1)
for i in range(n-1):
    a, b = map(lambda x : int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)
    edge[i] = (a, b)
color_n = max(map(len, tree))

q = deque()
q.append((0, -1))

visited = set()
while q:
    i, prev_c = q.popleft()
    visited.add(i)
    c = prev_c
    for x in tree[i]:
        if not x in visited:
            c = (c + 1) % color_n
            p = (i, x) if i < x else (x, i)
            color[p] = c
            q.append((x, c))
print(color_n)
for e in edge:
    print(color[e] + 1)

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s, t;
    cin >> s >> t;
    int n = s.size();
    int cnt = 0;
    for(int i=0; i<n; i++){
        cnt += (s[i] == t[i]);
    }
    cout << cnt;
    return 0;
}


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

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

  int X = 0;
  int I = 1;
  
  if (a < b) {
    for (int i =0;i < b;i++) {
      X += a * I;
      I *= 10;
    }
  }
  else {
    for (int i =0;i < a;i++) {
      X += b * I;
      I *= 10;
    }
  }

  cout << X << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        //Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        PrintWriter pw = new PrintWriter(System.out);
        int n = Integer.parseInt(st.nextToken());
        long k = Long.parseLong(st.nextToken());
        int q = Integer.parseInt(st.nextToken());
        int[] right = new int[n+1];
        for(int i = 1; i<=q; i++){
            st = new StringTokenizer(br.readLine());
            int ind = Integer.parseInt(st.nextToken());
            right[ind]++;
        }
        for(int i = 1; i<=n; i++){
            if(k - q + right[i] > 0){
                pw.println("Yes");
            }
            else{
                pw.println("No");
            }
        }
        pw.close();
    }
}

Measured memory_bytes: 34676
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N,K,Q,A[100001]={0};
  cin>>N>>K>>Q;

  rep(i,Q){
    int x;
    cin>>x;
    A[x]++;
  }

  rep(i,N){
    if(K-(Q-A[i+1])<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c;
    a=read(), b=read(), c=read();
    (a+b>=c)?puts("Yes"):puts("No");
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,j,k,t,l,r;
float a,b,c,d;
char A,B,C,X,Y,Z;
float ans,MAX,MIN=40,sum;
ll ax[8005];
char str[200050],bx[200050];

int main()
{
    ll i,s,x;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
		ll flag=0;
		scanf("%s",str);
		scanf("%s",bx);
		n=strlen(str);
		for(i=0;i<n;i++)
		{
			if(str[i]!=bx[i])
			{
				flag=1;
				break;
			}
		}
		if(flag) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3772
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

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

  ull y = 100;

  ull ans=0;
  while(true){
    if(x <= y) break;
    y += y / 100;
    //cout << y << endl;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007


int main()
{
  string S;
  cin >>S;
  if(S[6]-'0'>4||S[5]-'0'==1)
    cout << "TBD" << endl;
  else if(S[6]-'0'<4)
    cout << "Heisei" << endl;
  else if(S[8]-'0'==3&&S[9]-'0'==1)
    cout << "TBD" << endl;
  else 
    cout << "Heisei" << endl;
    
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

int main(){
  fastio;
  int n;
  cin>>n;
  string s;
  cin>>s;
  stack<char> st;
  int ans=1;char pre;
  for(int i=0;i<n;i++)
  {
     if(i!=0)
     {
      if(pre!=s[i])
        ans++;
     }
    pre=s[i];
   
  }
    cout<<ans<<endl;
  
}

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

int main() {
  vector<int> v = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin >> x  >> y;
  if(v[x]==v[y]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

// input
int N, K;
vector<int> L, R;

const ll MOD =  998244353;


void input() {
    cin >> N >> K;
    L = R = vector<int>(K);
    rep(i, K) cin >> L[i] >> R[i];
}


struct SegmentTree {
    int n;
    vector<int> left, right;
    vector<ll> dat;

    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        left = right = vector<int>(2 * n - 1);
        dat = vector<ll>(2 * n - 1, 0);
        set_range(0, 0, n);
    }

    void set_range(int i, int l, int r) {
        left[i] = l;
        right[i] = r;
        if (i < n - 1) {
            set_range(2 * i + 1, l, (l + r) / 2);
            set_range(2 * i + 2, (l + r) / 2, r);
        }
    }

    void add_recur(int i, int l, int r, ll x) {
        if (left[i] == l && right[i] == r) {
            dat[i] += x;
            dat[i] %= MOD;
            return;
        }
        int c = (left[i] + right[i]) / 2;
        if (l < c) add_recur(2 * i + 1, l, min(c, r), x);
        if (c < r) add_recur(2 * i + 2, max(c, l), r, x);
    }

    void add(int l, int r, ll x) {
        add_recur(0, l, r, x);
    }

    ll val(int i) {
        i += n - 1;
        ll ret = dat[i];
        while (i > 0) {
            i = (i - 1) / 2;
            ret += dat[i];
            ret %= MOD;
        }
        return ret;
    }
};


int main() {
    input();
    SegmentTree st = SegmentTree(N);
    st.add(0, 1, 1);
    rep(i, N - 1) {
        ll v = st.val(i);
        rep(j, K) {
            int l = i + L[j];
            if (l >= N) continue;
            int r = min(N, i + R[j] + 1);
            st.add(l, r, v);
        }
    }
    ll ans = st.val(N - 1);
    cout << ans << endl;
}


Measured memory_bytes: 11464
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin>>s;
  int aka=count(begin(s),end(s),'0');
  int ao=count(begin(s),end(s),'1');
  int kotae=aka+ao-abs(aka-ao);
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
  ll n, m, c, ans=0, value;
  cin >> n >> m;
  priority_queue<int> que;
  rep(i, n) {
    cin >> c;
    que.push(c);
  }
  rep(i, m) { 
    value = que.top() / 2;
    que.pop();
    que.push(value);
  }
  rep(i, n){
    ans += que.top();
    que.pop();
  }
  cout << ans;
}

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

int main() {
    string N;
    cin >> N;
    if ((N[0] == N[1] && N[1] == N[2]) ||
        (N[1] == N[2] && N[2] == N[3]) ||
        (N[0] == N[1] && N[1] == N[2] && N[2] == N[3] && N[3] == N[4])) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
typedef long long ll; // long long型をこのように定義することで時間短縮

int main() {
  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  ll ans = 1; //long long型にしておく
  for(int i=1; i<=n; i++){
    ans = ans*i%MOD; //掛け算一回ごとにあまりをとる
  }
  cout << ans << endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string S,T;
    cin >> S >> T;
    ll N = S.size();
    ll M = T.size();
    //vector<vector<ll>> dp(N+1,vector<ll>(M+1));
    /*rep(i,N){
        rep(j,M){
            if(S[i] == T[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            cmax(dp[i+1][j+1], dp[i+1][j]);
            cmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }*/
    ll ans = 1e18;
    rep(i,N){
        ll cnt = 0;
        rep(j,M){
            if(i+j >= N) goto gt;
            if(S[i+j] != T[j]){
                cnt++;
            }
        }
        cmin(ans,cnt);
        gt:
        continue;
    }
    //dp[N][M];
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

int path[10],flag[10];int x[10],y[10];
double ans=0;
int n;
int sear(int tmp){

    if (tmp==n){

        for (int ii=1;ii<n;++ii){
            int i=path[ii];int j=path[ii-1];
            ans+=sqrt( 1.0*(x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
        }
        return 0;
    }
    for (int i=0;i<n;++i)
    if (!flag[i]){
        path[tmp]=i;
        flag[i]=1;
        sear(tmp+1);
        flag[i]=0;
    }
}

int main(){
    scanf("%d",&n);
    for (int i=0;i<n;++i)
        scanf("%d%d",&x[i],&y[i]);
    sear(0);
    for (int i=2;i<=n;++i)
        ans/=(1.0*i);
    printf("%.10lf",ans);

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
    int four = 0, odd = 0;
    bool flag = false;
	for(int i = 0; i < n; i++)
	{
        ll x;
		cin >> x;
		if(x % 4 == 0) four++;
        else if(x % 2 == 0) flag = true;
        else if(x % 2 == 1) odd++;
	}
    if(flag) cout << (four >= odd ? "Yes" : "No") << endl;
    else cout << (four + 1 >= odd ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
m = 10**9
while m >0:
    for i in A:
        if i != 0 and i <= m:
            m = i
    A = [k%m for k in A]
    if max(A) == 0:
        break
    A += [m]
print(m)



Measured memory_bytes: 64536
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, w, weight[110], value[110];
ll dp[110][100100];

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> weight[i] >> value[i];

    for(int i = 0; i < 110; i++) for(int j = 0; j < 100100; j++) dp[i][j] = inf;

    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 100100; j++){
            if(j - value[i] >= 0) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - value[i]] + weight[i]);
            }
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    ll res = 0;
    for(int i = 0; i < 100100; i++){
        if(dp[n][i] <= w) res = i;
    }

    cout << res << endl;
}

Measured memory_bytes: 86400
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
if n==2:
    print(A[1])
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    t1 = a1 & a2
    t2 = a2 & a3
    t3 = a1 & a3
    cond = t1 | t2 |t3
    maxi = 0
    for con in cond:
        count = 0
        flag = True
        for a in A:
            if a%con != 0:
                count +=1
            if count >= 2:
                
                flag = False
                break
        if flag and maxi < con:
            maxi = con
    print(maxi)

Measured memory_bytes: 14400
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000001;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int w,a,b; cin>>w>>a>>b;
  if(a>b) swap(a,b);
  if(a+w>=b)
  cout<<0<<endl;
  else
  cout<<b-(a+w)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <cstdlib>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  string S;
  long long cnt=0;
  cin>>S;
  for(int i=0;i<S.size();i++){
    for(int j=i;j<S.size();j++){
      long long num=stoll(S.substr(i,j-i+1));
      long long K=1;
      if(i==0){
        K*=1;
      }else{
        K*=(1<<(i-1));
      }
      long long L=S.size()-j-1;
      if(L==0){
        K*=1;
      }else{
        K*=(1<<(L-1));
      }
      cnt+=num*K;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
$s = <>; chomp $s;
$k = <>; chomp $k;

$len = length $s;
for my $i (0..$len) {
    for my $j (1..$k) {
        $substr = substr $s, $i, $j;
        $substr_map{$substr} = 1;
    }
}

@a = sort keys %substr_map;
print $a[$k];


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, M, i;
  cin >> N >> M;
  vvi edges(N);
  REP(0, M, i) {
    i64 u, v;
    cin >> u >> v;
    u--; v--;
    edges[u].pb(v);
    edges[v].pb(u);
  }

  vi dist(N, -1);
  dist[0] = 0;
  vi from(N, -1);

  set<pi> q;
  q.insert({0, 0});
  while(!q.empty()) {
    pi top = *q.begin();
    q.erase(q.begin());

    i64 cur = top.second;
    i64 d = top.first;
    
    for(auto next: edges[cur]) {
      if(dist[next] == -1) {
	dist[next] = d + 1;
	from[next] = cur;
	q.insert({d+1, next});
      }
      else if(d + 1 < dist[next]) {
	q.erase(q.find({dist[next], next}));
	dist[next] = d + 1;
	from[next] = cur;
	q.insert({d+1, next});
      }
    }
  }

  cout << "Yes" << endl;
  REP(1, N, i) {
    cout << from[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 19272
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int rangeA = Math.abs(X - A);
		int rangeB = Math.abs(X - B);
		
		if (rangeA < rangeB) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j=0,sum=0;
    int x;
    cin>>n>>x;
    int a[100];
    for( i=0; i<n; i++) cin>>a[i];
    sort(a,a+n);

    for(j=0; j<n; j++)
    {
        sum+=a[j];
        if(sum>x) break;
    }
    if(sum<x)    j--;


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


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;
vl A;
vl B;

void input() {
  IN(K);
  IN(N);
  REP(i, N) {
    IN(t);
    A.pb(t);
  }
}

void solve() {
  REP(i, N-1) {
    B.pb(A[i+1] - A[i]);
  }
  B.pb(A[0] + K - A[N-1]);
  sort(ALL(B));
  REP(i, N-1) {
    ret += B[i];
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


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

typedef long double LD;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define mod             1000000007
#define INF             2147483647
#define Endl            "\n"
#define FasterIO        ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0) ;
#define precision(a)    cout << fixed << setprecision(a)
#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define reset(a,b)      memset(a,b,sizeof(a));
#define srt(a)      sort(a.begin(),a.end());

const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int sz=1e5+9;

int strtoint(string str){
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string intostr(int x){
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
void rem(string &s, const string &c) {
	auto pos = s.find(c);
	if (pos == string::npos) {
		cout << -1 << endl;
		exit(0);
	}
	s.erase(0, pos + 1);
}
void println (int n){
    cout<<n<<"\n";
}
void printvec(vector <int> &a){
    for (int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printgraph(vector <int> g[],int e){
    for (int i=0;i<e;i++){
        cout<<i<<" --> ";
        for (int j=0;j<g[i].size();j++){
            cout<<g[i][j]<<" ";
        }
        cout<<"\n";
    }
}

void printmap (map <int,int> &mymap){
    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {
        cout << '\t' << itr->first
             << '\t' << itr->second << '\n';
    }
    cout << "\n";
}

int n,x,arr[sz],dp[sz],k;


int rec (int i){
    if (i==n) return 0;
    if (dp[i]!=-1) return dp[i];

    int ret1=INF;
    for(int j=1;j<=k && i+j<=n;j++){
        ret1=min(ret1,abs(arr[i]-arr[i+j])+rec(i+j));
    }
    return dp[i]=ret1;
}


void solve(){

    cin>>n>>k;
    reset (dp,-1);
    for (int i=1;i<=n;i++)cin>>arr[i];


    cout << rec (1) << Endl;

    //printvec(v);
}


int main(){
    //FasterIO;

    solve();
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(void){
    int n, p[100], i, j, s=0, t;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    for(i=0;i<n;i++){
        if(s<p[i]){
            s=p[i];
            j=i;
        }
    }
    for(i=0;i<j;i++) t+=p[i];
    t+=s/2;
    for(i=j+1;i<n;i++) t+=p[i];
    printf("%d\n",t);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int INF=(int)2e9;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
const ll MOD=(ll)1e9+7;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define FOR(i,n) for(int i=0;i<n;i++)
#define MAX 100005
#define wa cout<<"wa"<<endl;

void base(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

int main(){
	string str;
	cin>>str;
	string str2 = str;
	reverse(str2.begin(),str2.end());
	if (str2==str) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



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

typedef struct xyz{
    double x;
    double y;
}XYZ;

int main(void){

    int times;
    cin >> times;

    XYZ a,b,c,d;
    double x1,y1,x2,y2;

    while(times > 0){
        cin >> a.x >> a.y;
        cin >> b.x >> b.y;
        cin >> c.x >> c.y;
        cin >> d.x >> d.y;

        x1 = a.x - b.x;
        y1 = a.y - b.y;
        x2 = c.x - d.x;
        y2 = c.y - d.y;

        

        if(fabs((y1 * x2) - (y2 * x1)) <= 1e-10){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }

        times--;
    }


    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll a,b,c,x;
    cin >> a >> b >> c >> x;
    ll ctr=0;
    rp(i,a+1){
        rp(j,b+1){
            rp(k,c+1){
                if(500*i+100*j+50*k==x) ctr++;
            }
        }
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3656
#!/usr/bin/env python3

def ans(X, Y):
    TT = Y - 2*X
    if TT < 0:
        return "No"
    if TT % 2 != 0:
        return "No"
    T = TT // 2
    C = X - T
    if C < 0:
        return "No"
    return "Yes"
    
X, Y = input().split(' ')
X = int(X)
Y = int(Y)

print(ans(X, Y))


Measured memory_bytes: 61680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X,Y;
  string S;
  vector<long long> rc={},gc={},bc={};
  cin >> N >> S;
  for (int i=0;i<N;i++) {
    if (S.at(i)=='R') {rc.push_back(i+1);}
	if (S.at(i)=='G') {gc.push_back(i+1);}
	if (S.at(i)=='B') {bc.push_back(i+1);}
  }
  A=0;
  if (rc.size()*gc.size()*bc.size()>0) {
    for (long long jr=0;jr<rc.size();jr++) {
	  for (long long jg=0;jg<gc.size();jg++) {
        X=max(gc.at(jg),rc.at(jr));
        Y=min(gc.at(jg),rc.at(jr));
        A+=bc.size();
        T=0;
	    if (X*2-Y<=N) {
		  if (S.at(X*2-Y-1)=='B') {T--;}
		}
        if (Y*2-X>0) {
          if (S.at(Y*2-X-1)=='B') {T--;}
        }
        if ((X-Y)%2==0) {
          if (S.at(Y+(X-Y)/2-1)=='B') {T--;}
        }
          
	    A+=T;
	  }
	}
	cout << A << endl;
  }
  else {cout << 0 << endl;}
  
}

Measured memory_bytes: 3668
'use strict';

const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("");
const ary = lines.map(str => Number(str));
const length = ary.length;

let sum = 0;
for (let i=0; i<length; i++) {
  sum += calculator(i);
}
console.log(sum);

function calculator(i) {
  let total = 0;
  if (i===length-1) {
    total += ary[length-1] * Math.pow(2,length-1);
  } else {
    for (let j=0; j<length-i-1; j++) {
      total += ary[i] * Math.pow(2,length-2-j) * Math.pow(10, j);
    }
    total += ary[i] * Math.pow(2, i) * Math.pow(10, length-i-1);
  }
  return total;
};


Measured memory_bytes: 21064