akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    string s;
    cin >> s;
    char c = s[0];
    int ans = 0;
    FOR(i,1,s.size()) {
        if (c!=s[i]) {
            ans++;
            c = s[i];
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

#include <complex>
typedef complex<double> P;

double dot(P a, P b) {
	return (a.real()*b.real() + a.imag()*b.imag());
}

double cross(P a, P b) {
	return (a.real()*b.imag() - a.imag()*b.real());
}

int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > 0) return +1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

namespace std {
	bool operator<(const P &a, const P &b) {
		return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
	}
}

vector<P> convex_hull(vector<P> ps) {
	int n = ps.size(), k = 0;
	sort(ALL(ps));
	vector<P> ch(2*n);
	for(int i = 0; i < n; ch[k++] = ps[i++])
		while(k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
	for(int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
		while(k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
	ch.resize(k-1);
	return ch;

}

int main() {
	double xa, ya, xb, yb, xc, yc, xd, yd;
	char c;
	while(cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >> c >> xd >> c >> yd) {
		P a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd);
		vector<P> points;
		points.push_back(a);
		points.push_back(b);
		points.push_back(c);
		points.push_back(d);

		if(convex_hull(points).size() != 4) {
			cout << "NO" << endl;
		} else {
			cout << "YES" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int diff(string s,string t) {
    int ans=0;
    for(int i=0;i<s.size();i++) {
        ans+=s[i]!=t[i];
    }
    return ans;
}
int main() {
    string s,t;
    cin>>s>>t;
    int ans=1e9;
    for(int i=0;i<s.size()-t.size()+1;i++) {
        string tmp=s.substr(i,t.size());
        ans=min(ans,diff(tmp,t));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2e5 + 100;
int A[MAXN];

int main() {
  int K, N;
  scanf("%d%d", &K, &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  int sh = A[0] + K - A[N - 1];
  for (int i = 1; i < N; i++)
    sh = max(sh, A[i] - A[i - 1]);
  cout << K - sh << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c,d;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num1[100005];
ll num2[100005];
ll n,k,x,y;
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;

		b>>=1;
	}
	return res;
}

string s;
int main()
{
    //IOS
    while(cin>>n>>k)
    {
        num1[1]=n-k+1;
        for(int i=2;i<=n-k+1;i++)
        {
            num1[i]=num1[i-1]*(n-k+1-i+1)%mod*mypow(i,mod-2)%mod;
            num1[i]%=mod;
        }
        num2[0]=1;
        num2[1]=k-1;
        for(int i=2;i<=k-1;i++)
        {
            num2[i]=num2[i-1]*(k-1-i+1)%mod*mypow(i,mod-2)%mod;
            //num2[i]%=mod;
        }


        ll tmp1=n-k+1,tmp2=1;
        for(int i=1;i<=k;i++)
        {
            //cout<<num1[i]<<" "<<num2[k-i]<<"\n";
            cout<<(num1[i]*num2[k-i])%mod<<"\n";
            //tmp1=tmp1*(n-k+1-i)/(i+1)%mod;
            //tmp2=tmp2*(k-1-i)/(i)%mod;
        }
    }


}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
B_array = list(map(int, input().split()))
A_array = [0] * N
A_array[0] = B_array[0]
for i in range(N-1):
    A_array[i+1] = B_array[i]
    if B_array[i] <= A_array[i]:
        A_array[i] = B_array[i]
print(sum(A_array))


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

using namespace std;

int main(){
    long long N,ans=0;
    string S;
    cin>>N;

    vector<long long> v(N);
    vector<long long> sum(N);

    for (long  i = 0; i < N; i++)
    {
        cin>>v[i];
        if(i!=0){
            sum[i]=sum[i-1]+v[i];
        }else{
            sum[i]=v[i];
        }
    }

    long sa=1e9;

    for (long i = 0; i < N-1; i++)
    {
        if(abs(sum[i]-(sum[N-1]-sum[i]))<sa){
            sa=abs(sum[i]-(sum[N-1]-sum[i]));
        }
    }
    
cout<<sa<<endl;
        

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    for(int a = 1;a < n;a++) {
        ans += n/a;
        if(n%a==0) ans--;
    }
    cout << ans << endl;
}

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

#define M 1000000007

int grid(vector<vector<char>> v,int r, int c){
    long long dp[r][c];
    bool flag=0;
    for(int i=0; i<r; i++){
        if(v[i][0]=='#') flag=1;
        if(flag==0) dp[i][0]=1;
        else dp[i][0]=0;
    }
    flag=0;
    for(int i=0; i<c; i++){
        if(v[0][i]=='#') flag=1;
        if(flag==0) dp[0][i]=1;
        else dp[0][i]=0;
    }
    for(int i=1; i<r; i++){
        for(int j=1; j<c; j++){
            if(v[i][j]=='#') dp[i][j]=0;
            else dp[i][j]= (dp[i-1][j]%M+dp[i][j-1]%M)%M;
        }
    }
    return dp[r-1][c-1]%M;
}

int main(){
    int r,c;
    cin>>r>>c;
    vector<vector<char>> v(r, vector<char>(c));
    for(int i=0; i<r; i++)
        for(int j=0; j<c; j++) cin>>v[i][j];
    cout<<grid(v, r, c);
    return 0;
}


Measured memory_bytes: 13420
package main

import "fmt"

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func main() {
	// n, m, c
	nums := scanNums(3)
	bArray := scanNums(nums[1])
	var n int = nums[0]
	var m int = nums[1]

	counter := 0
	for i := 0; i < n; i++ {
		res := 0
		aArray := scanNums(m)
		for j := 0; j < m; j++ {
			res += aArray[j] * bArray[j]
		}
		res += nums[2]
		if res > 0 {
			counter += 1
		}
	}
	fmt.Println(counter)
}


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

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

    map<int, int> m;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (m.find(a) == m.end())
        {
            m[a] = 1;
        }
        else{
            m[a]++;
        }
    }

    vector<int> vi;
    for (auto iter: m) 
    {
        if (iter.second >= 2)
        {
            vi.push_back(iter.first);
            if (iter.second >= 4)
            {
                vi.push_back(iter.first);
            }
        }
    }

    sort(vi.begin(), vi.end());
    int len = vi.size();
    if (len < 2) 
    {
        cout << 0 << endl;
    }
    else 
    {
        long long area = (long long)vi[len-2] * (long long)vi[len-1];
        cout << area << endl;
    }

    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<queue>
#include<complex>
typedef long long ll;

using namespace std;
#define N 100010
ll n;
ll a[N],b[N],l[N],r[N];
ll sp,tp;
priority_queue<ll> S,s;
priority_queue<ll,vector<ll>,greater<ll> >T,t;
ll Sf(){
  return S.top()+sp;
}
ll Tf(){
  return T.top()+tp;
}
void Sp(ll x){
  S.push(x-sp);
}
void Tp(ll x){
  T.push(x-tp);
}
int main(){
    cin>>n;
    if(n>N)return 0;
    for(int i=0;i<n;i++)cin>>l[i]>>r[i];
    for(int i=1;i<n;i++){
      a[i]=l[i]-r[i-1];
      b[i]=r[i]-l[i-1];
    }
    ll ans=0; sp=tp=0;
    Sp(0); Tp(0);
    Sp(-1e17); Tp(1e17);
    for(int i=1;i<n;i++){
      sp-=b[i],tp-=a[i];
      ll s0=Sf();
      ll t0=Tf();
      if(s0<=0&&0<=t0){
	Sp(0); Tp(0);
      }
      if(0<s0){
	Sp(0); Sp(0);
	Tp(Sf());
	ans+=abs(Sf());
	S.pop();
      }
      if(t0<0){
	Tp(0); Tp(0);
	Sp(Tf());
	ans+=abs(Tf());
	T.pop();
      }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N, L;
  string S[110];
  string tmp;

  cin >> N >> L;
  rep(i, N) cin >> S[i];

  sort(S, S+N);

  tmp = S[0];

  for(int i=1; i < N; i++) {
    tmp += S[i];
  }

  cout << tmp << endl;

  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == S[i + 1] && i + 1 <= S.size()) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string in; cin >> in;
    rep(i, in.size()){
        if(in.substr(i, 2) == "AC"){
            cout << "Yes" << endl;
            return 0;
        }
    }
            cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    str1, str2 = input().rstrip().split(' ')
    str1_quantity, str2_quantity = (int(i) for i in input().rstrip().split(' '))
    chosen_ball_str = input().rstrip()

    if str1 == chosen_ball_str:
        str1_quantity -= 1
    else:
        str2_quantity -= 1
    print('{} {}'.format(str1_quantity, str2_quantity))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

int main() {
  int N; scanf("%d", &N);
  static int A[100000], B[100000];
  static pair<int, int> ABtbl[100000];
  static pair<int, int> BAtbl[100000];
  for(int i = 0; i < N; ++i) {
    scanf("%d%d", &A[i], &B[i]);
    ABtbl[i] = make_pair(A[i], B[i]);
    BAtbl[i] = make_pair(B[i], A[i]);
  }
  if(A[0] != 0 || B[1] != 0 || A[1] == 0 || A[1] != B[0]) {
    printf("%d\n", -1);
    return 0;
  }
  sort(ABtbl, ABtbl+N);
  sort(BAtbl, BAtbl+N);
  for(int i = 0; i < N; ++i) {
    if(i != 0 &&
        lower_bound(ABtbl, ABtbl+N, make_pair(A[i]-1, B[i]-1))
        == upper_bound(ABtbl, ABtbl+N, make_pair(A[i]-1, B[i]+1))) {
      printf("%d\n", -1);
      return 0;
    }
    if(i != 1 &&
        lower_bound(BAtbl, BAtbl+N, make_pair(B[i]-1, A[i]-1))
        == upper_bound(BAtbl, BAtbl+N, make_pair(B[i]-1, A[i]+1))) {
      printf("%d\n", -1);
      return 0;
    }
  }
  int count = 2 * (N-1);
  for(int ii = 0; ii < N; ++ii) {
    if(ii > 0 && ABtbl[ii-1] == ABtbl[ii]) continue;
    int a = ABtbl[ii].first;
    int b = ABtbl[ii].second;
    if(lower_bound(ABtbl, ABtbl+N, make_pair(a-1, b+1))
        < upper_bound(ABtbl, ABtbl+N, make_pair(a-1, b+1))) {
      continue;
    }
    int have =
      upper_bound(ABtbl, ABtbl+N, make_pair(a, b))
        - lower_bound(ABtbl, ABtbl+N, make_pair(a, b));
    int rem = have;
    while(true) {
      int capa = have;
      if(lower_bound(ABtbl, ABtbl+N, make_pair(a-1, b-1))
          < upper_bound(ABtbl, ABtbl+N, make_pair(a-1, b-1))) {
        // fprintf(stderr, "(%d, %d) -- %d recyclable edges to (%d, %d)\n",
        //     a, b, rem, a-1, b-1);
        count -= rem;
        capa -= rem;
      }
      ++a;
      --b;
      have =
        upper_bound(ABtbl, ABtbl+N, make_pair(a, b))
          - lower_bound(ABtbl, ABtbl+N, make_pair(a, b));
      if(have == 0) break;
      // fprintf(stderr, "(%d, %d) -- %d recyclable edges to (%d, %d)\n",
      //     a-1, b+1, min(capa, have), a, b);
      count -= min(capa, have);
      rem = have - min(capa, have);
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(10**7)
strlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(n, before):
    lensetbefore = len(set(before))
    if n == 1:
        print(before)
    if n > 1:
        for s in strlist[:lensetbefore+1]:
            dfs(n-1, before+s)

def main():
    N = int(input())
    dfs(N, 'a')


if __name__ == "__main__":
    main()


Measured memory_bytes: 4340
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = []
b = []
for _ in range(M):
    X, Y = map(int, input().split())
    if X == 1:
        a.append(Y)
    if Y == 1:
        a.append(X)
    if X == N:
        b.append(Y)
    if Y == N:
        b.append(X)
if len(set(a) & set(b)) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 21836
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, A[100050];

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

    int ans = 0;
    int even = 0;
    for(int i = 1;i < 100005;++i)
    {
        if(A[i] and !(A[i] & 1))
            ++even;

        else if(A[i])
            ++ans;
    }

    if(even & 1)
        --even;

    printf("%d\n", ans + even);
    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

long long discrete_binary_search(long long ok, long long ng, const std::function<bool(long long)> &check) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

int K, A, B;
signed main() {
    cin >> K >> A >> B;
    if (B <= A + 2 || K < A - 1) { cout << K + 1 << endl; }
    else {
        int n = K - (A - 1);
        cout << A + n / 2 * (B - A) + n % 2 << endl;
    }
}


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

int main(){
	int a,b,c,k;

	cin >> a >> b >> c >> k;
	if(k <= a){
		cout << k << endl;
	}else if(k <= a+b){
		cout << a << endl;
	}else{
		int kari = k - a - b;
		cout << a - kari << endl;
	}
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll mp[500][500];
ll tmp[500][500];

int main(){

    ll H, W;
    cin >> H >> W;

    for(ll y = 0; y < H; y++){
        for(ll x = 0; x < W; x++){
            cin >> mp[y][x];
            tmp[y][x] = mp[y][x];
        }
    }
    ll cnt = 0;
    for(ll y = 0; y < H; y++){
        for(ll x = 0; x < W; x++){
            if(tmp[y][x] % 2 == 0)continue;
            if(x + 1 == W && y + 1 == H)continue;
            cnt++;
            tmp[y][x]--;
            if(x + 1 == W)tmp[y+1][x]++;
            else tmp[y][x+1]++;
        }
    }
    cout << cnt << endl;
    for(ll y = 0; y < H; y++){
        for(ll x = 0; x < W; x++){
            if(mp[y][x] % 2 == 0)continue;
            if(x + 1 == W && y + 1 == H)continue;
            cnt++;
            mp[y][x]--;
            if(x + 1 == W){
                mp[y+1][x]++;
                printf("%d %d %d %d\n", y + 1, x + 1, y + 2, x + 1);
            }
            else{
                mp[y][x+1]++;
                printf("%d %d %d %d\n", y + 1, x + 1, y + 1, x + 2);
            }
        }
    }
    

    return 0;
}


Measured memory_bytes: 6016
N,x = map(int,input().split())
if x == 1:
  print('No')
elif x == 2*N-1:
  print('No')
else:
  print('Yes')
  if N == 2:
    for i in range(1,4):
      print(i)
  else:
    if x != 2*N-2:
      L = []
      M = [x+2,x-1,x,x+1]
      for i in range(1,2*N):
        if not i in M:
          L.append(i)
      for j in range(N-2):
        print(L[j])
      for k in range(4):
        print(M[k])
      for l in range(N-3):
        print(L[l+N-2])
    else:
      L = []
      M = [x-2,x,x+1,x-1]
      for i in range(1,2*N):
        if not i in M:
          L.append(i)
      for j in range(N-2):
        print(L[j])
      for k in range(4):
        print(M[k])
      for l in range(N-3):
        print(L[l+N-2])

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int a[maxn] ;
vector <int> ans ;

void Print()
{
    for(int i=0 ; i<ans.size() ; i++) printf("%d ",ans[i]) ;
    printf("\n") ;
    exit(0) ;
}

int main()
{
    int n ;

    scanf("%d",&n) ;

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

    if(n==2)
    {
        printf("-1\n") ;
        return 0 ;
    }

    set<int> st ;

    for(int i=2;  i<=n ; i++)
    {
        st.insert(i) ;
    }

    ans.pb(1) ;

    for(int i=2 ; i<=n ; i++)
    {
        auto it = st.begin() ;
        if( *it == a[ ans.back() ] )
        {
            if(i==n) break ;
            int val = *it ;
            st.erase( it ) ;
            it = st.begin() ;
            ans.pb( *it ) ;
            st.erase( it ) ;
            st.insert(val) ;
        }
        else{
            ans.pb(*it) ;
            st.erase(it) ;
        }
    }

    if( (int)ans.size() == n ) Print() ;

    if( a[ ans[n-3] ] != (*st.begin()) )
    {
        int val = *st.begin() ;

        st.erase( st.begin() ) ;

        if( a[val] != ans[n-2] )
        {
            ans.pb(val) ;
            swap( ans[n-2] , ans[n-1] ) ;
            Print() ;
        }
        else{

            int u = val , v = ans[n-2] ;
            val = ans[n-3] ;
            ans.pop_back() ;
            ans.pop_back() ;
            if( u>v ) swap(u,v) ;
            if( n>=4 && a[ ans.back() ] == u ) swap(u,v) ;
            ans.pb(u) ;


            u = val ;
            if( u>v ) swap(u,v) ;
            if( a[ ans.back() ] == u ) swap(u,v) ;
            ans.pb(u) ;
            ans.pb(v) ;

            Print() ;
        }
    }

    else{
        vector <int> extra ;
        int val = (*st.begin()) ;
        for(int i=n-2 ; i>=0 ; i--)
        {
            if( a[ ans[i] ] == val )
            {
                extra.pb( ans[i] ) ;
                ans.pop_back() ;
            }
            else break ;
        }
        assert( (int)extra.size() >= 2 ) ;
        ans.pb(val) ;
        sort( extra.begin() , extra.end() ) ;
        reverse( extra.begin() , extra.end() ) ;
        if( ans.size() > 0 && a[ ans.back() ] == extra.back() )
        {
            int val = extra.back() ;
            extra.pop_back() ;
            ans.pb( extra.back() ) ;
            extra.pop_back() ;
            extra.pb(val) ;
        }
        for(int i = (int)(extra.size()) - 1 ; i>=0 ; i-- ) ans.pb( extra[i] ) ;
        Print() ;
    }

    return 0 ;
}


Measured memory_bytes: 5888
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc098e {
public:
    void solve(istream& in, ostream& out) {
        int N, K, Q;
        in >> N >> K >> Q;
        vector<int> A(N);
        for (int i = 0; i < N; ++i) {
            in >> A[i];
        }
        int ans = 1'000'000'000;
        for (int i = 0; i < N; ++i) {
            vector<int> cur, res;
            for (int j = 0; j < N; ++j) {
                if (A[j] < A[i]) {
                    sort(begin(cur), end(cur));
                    for (int k = 0; k + K <= (int)cur.size(); ++k) {
                        res.push_back(cur[k]);
                    }
                    cur.clear();
                } else {
                    cur.push_back(A[j]);
                }
            }
            sort(begin(cur), end(cur));
            for (int k = 0; k + K <= (int)cur.size(); ++k) {
                res.push_back(cur[k]);
            }
            sort(begin(res), end(res));
            if ((int)res.size() >= Q) {
                ans = min(ans, res[Q - 1] - res[0]);
            }
        }
        out << ans << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc098e solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int solve(int n,int a[],int wt[],int w,vector<vector<int>>&dp)
{
    if(n<0 ||w==0)
     return 0;
    if(dp[n][w]!=-1)
     return dp[n][w];
    if(wt[n]<=w)
     return dp[n][w]=max(a[n]+solve(n-1,a,wt,w-wt[n],dp),solve(n-1,a,wt,w,dp));
    return dp[n][w]=solve(n-1,a,wt,w,dp);
}
int32_t main(){
    int n,w;
    cin>>n>>w;
    int a[n],wt[n];
    vector<vector<int>>dp(n+1,vector<int>(w+1,-1));
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>a[i];
        
    }
    //memset(dp,-1,sizeof(dp));
    cout<<solve(n-1,a,wt,w,dp)<<endl;


}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n][3];
	for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) a[i][j] = ri();
	std::vector<std::vector<int> > dp(n, std::vector<int> (3, 0));
	for (int i = 0; i < 3; i++) dp[0][i] = a[0][i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) dp[i][k] = std::max(dp[i][k], dp[i - 1][j] + a[i][k]);
			}
		}
	}
	std::cout << *std::max_element(dp[n - 1].begin(), dp[n - 1].end()) << std::endl;
	return 0;
}


Measured memory_bytes: 6912
#include<stdio.h>
int main()
{
	int a,b,c;
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		if(a==b&&b==c)
		{
			printf("Yes\n");
		} 
		else
		{
			printf("No\n");
		}
	}
} 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

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


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];

vector<int> v;
int L[200009], R[200009];
int C[510][510], X[510][510];
int main(void) {
    
    ll N, M, Q; cin >> N >> M >> Q;
    REP(i, M){
        cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
    }
    for(int i=1; i<=N; ++i){
        for(int j=1; j<=N; ++j) C[i][j] = C[i][j-1]+X[i][j];
    }
    for(int i=0; i<Q; ++i){
        int p, q; cin >> p >> q;
        int ans=0;
        for(int j=p; j<=q; ++j) ans += C[j][q]-C[j][p-1];
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9600
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a,T2 b){if (b>a) a=b;}
template <class T1, class T2>inline void gmin(T1 &a,T2 b){if (b<a) a=b;}
void up(int&x,int y){x+=y;if(x>=P)x-=P;}
ll x,y;
int main(){
    read(x),read(y);
    if (x<y) cout<<x<<endl;
    else{
        if (x%y==0) cout<<-1<<endl;
        else cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import collections
n = int(input())
#a, b, x = list(map(int, input().split()))
#b = list(map(int, input().split()))
s_dic = {}
ans = 0
for i in range(n):
    s = input()
    s = ''.join(sorted(list(s)))
    if s in s_dic:
        # 辞書のキーで管理
        ans += s_dic[s]
        s_dic[s] += 1
    else:
        s_dic[s] = 1

print(ans)


Measured memory_bytes: 18140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  ll K;
  cin>>K;
  ll cnt=1;
  ll ans=0;
  rep(i,S.size()){
    if(i){
      if(S[i]==S[i-1]) cnt++;
      else{
        ans+=(cnt/2);
        cnt=1;
      }
    }
  }
  ans+=(cnt/2);
  string SS=S+S;
  ll cnt2=1;
  ll ans2=0;
  rep(i,SS.size()){
    if(i){
      if(SS[i]==SS[i-1]) cnt2++;
      else{
        ans2+=(cnt2/2);
        cnt2=1;
      }
    }
  }
  ans2+=(cnt2/2);
  string SSS=SS+S;
  ll cnt3=1;
  ll ans3=0;
  rep(i,SSS.size()){
    if(i){
      if(SSS[i]==SSS[i-1]) cnt3++;
      else{
        ans3+=(cnt3/2);
        cnt3=1;
      }
    }
  }
  ans3+=(cnt3/2);
  if(ans3-ans2==ans2-ans) cout<<ans+(ans2-ans)*(K-1)<<endl;
  else if(ans*2==ans2) cout<<ans*K<<endl;
  else cout<<(K/2)*ans2+(K%2)*ans<<endl;
}



Measured memory_bytes: 256
////sfef
#include<stdio.h>
int main(){

int k,x,i,p,q,r;
scanf("%d %d",&k,&x);
p=(x-(k-1));
q=(x+(k-2));
r=(x+(k-1));
if(k==1)
{
    printf("%d",x);
}
else{
    for(i=p;i<=q;i++)    
    {
        printf("%d ",i);
    }
    printf("%d",r);
}

return 0;
}


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

int main()
{
  string S;
  string res;
  cin >> S;

  if (S=="Sunny") res = "Cloudy";
  if (S=="Cloudy") res = "Rainy";
  if (S=="Rainy") res = "Sunny";
  
  cout << res << endl;
}

    


Measured memory_bytes: 256
N=int(input())
A=[]
B=[[] for i in range(N+1)]
B[0].append("")
for i in range(N):
    A.append(chr(97+i))
    for j in B[i]:
        for k in A:
            B[i+1].append(j+k)
for i in B[N]:
    count=ord("a")
    yes=1
    for j in range(N):
        if ord(i[j])<=count+1:
            count=max(count,ord(i[j]))
        else:
            yes=0
            continue;
    if yes==1:
        print(i)

Measured memory_bytes: 397420
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    int W;
    cin >> N >> W;

    int v[100];
    int w[100];
    for(int i=0;i<N;i++){
        cin >> v[i] >> w[i];
    }

    int dp[1100][11000];
    for(int i=0;i<=N;i++){
        dp[0][i] = 0;
    }
    
    for(int i=1;i<=N;i++){
        for(int j=1;j<=W;j++){
            if(j<w[i-1]){
                dp[i][j] = dp[i-1][j];
            }else{ 
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 7392
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
int i, j, k, l, m, n;
int N, M, Q;

////////////

int main()
{
	cin >> N >> M;
	vector<int> L;
	vector<int> R;
	for (i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		L.push_back(l);
		R.push_back(r);
	}
	sort(L.begin(), L.end());
	reverse(L.begin(), L.end());
	sort(R.begin(), R.end());
	cout << max(0,R[0] - L[0] + 1);
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	string A, B;
	for (int i = 0; i<b; i++) A += '0'+a;
	for (int i = 0; i<a; i++) B += '0'+b;
	if (A.length() >= B.length())
		cout << A << "\n";
	else
		cout << B << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int arr[20010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);
    int l[10];
    int v1, v2;
    char c;
    while (cin >> l[0] >> c >> l[1] >> c >> l[2] >> c >> l[3] >> c >> l[4] >> c >> l[5] >> c >> l[6] >> c >> l[7] >> c >> l[8] >> c >> l[9])
    {
        cin >> c >> v1 >> c >> v2;

        int sum = 0;
        double c = (double)v1 / (v1 + v2);

        for (int i = 0; i < 10; ++i)
        {
            sum += l[i];
        }

        int partsum = 0;

        for (int i = 0; i < 10; ++i)
        {
            partsum += l[i];
            if ((double)partsum / sum >= c)
            {
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3060
N = int(input())
march_count = [0 for i in range(5)]
march_dict = {'M': 0, 'A': 1, 'R': 2, 'C': 3, 'H': 4}


for i in range(N):
    c = input()[0]
    if c in march_dict:
        march_count[march_dict[c]] += 1

count = 0


def calc(a, b, c):
    return march_count[a] * march_count[b] * march_count[c]

# 10通りの組み合わせをすべて計算
count = calc(0, 1, 2) + calc(0, 1, 3) + calc(0, 1, 4) \
    + calc(0, 2, 3) + calc(0, 2, 4) + calc(0, 3, 4) \
    + calc(1, 2, 3) + calc(1, 2, 4) + calc(1, 3, 4) \
    + calc(2, 3, 4)

print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){

  int room[4][3][10],x,y,z,add,count,count1,count2,i,m;

  cin>>m;

  for(count=0; count<4; count++)for(count1=0; count1<3; count1++)for(count2=0; count2<10; count2++)room[count][count1][count2]=0;

  for(i=0; i<m; i++){
    cin>>x>>y>>z>>add;
    room[x-1][y-1][z-1]+=add;
  }

  for(count=0; count<4; count++){

    for(count1=0; count1<3; count1++){

      for(count2=0; count2<10; count2++){
	cout<<" "<<room[count][count1][count2];
    }

      cout<<"\n";

    }

    if(count==3)return 0;

      cout<<"####################\n";

  }

}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;




int main(){
  ll n,m;
  cin >> n >> m;
  vector <ll> a;
  vector <ll> b;
  ll p[n+1] = {0};
  REP(i,m){
    ll x,y;
    cin >> x >> y;
    if(x == 1 && y != n){
      p[y]++;
    }
    else if(x != 1 && y == n){
      p[x]++;
    }
  }
  //cout << "gfgjksd";
  int f = 0;
  
  REP(i,n){
    if(p[i] >= 2){
      f = 1;
      break;
    }
  }
  //cout << "dsgdsfg";
  if(f == 1){
    cout << "POSSIBLE" << endl;
  }
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;


int n;
vector<int> in(100000);

int dfs(int s){
    int re=n,c=in[s];
    int l=s,r=s,f,p=1;
    
    while(1){
        f=0;
        
        if(0<l && in[l-1]==c){
            l--;
            f++;
            p++;
        }
        if(r<n-1 && in[r+1]==c){
            r++;
            f++;
            p++;
        }
        
        if(f){
            f=0;
        }else{
            if(p>=4){
                re-=p;
            }else{
                return re;
            }
            if(0<l && r<n-1 && in[l-1]==in[r+1]){
                l--;
                r++;
                p=2;
                c=in[l];
            }else{
                return re;
            }
        }
    }
}

void calc(){
    int memo=0,ans=100001;
    
    for(int i=0;i<n;i++){
        scanf("%d",&in[i]);
    }
    
    for(int i=0;i<n;i++){
        memo=in[i];
        for(int j=1;j<=3;j++){
            if(memo!=j){
                in[i]=j;
                ans=min(ans,dfs(i));
            }
        }
        in[i]=memo;
    }
    
    printf("%d\n",ans);
    
    return;
}

int main(){
    while(1){
    
        scanf("%d",&n);
        
        if(n==0)
            break;
        
        calc();
    }
}

Measured memory_bytes: 1532
#include<cstdio>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>

#define ll long long
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int H,W;
    cin>>H>>W;
    FOR(i,H){
        FOR(j,W){
            string s;
            cin>>s;
            if(s=="snuke"){
                string ret="";
                char col='A'+j;
                ret+=col;
                ret+=to_string(i+1);
                cout<<ret<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()


#define x(p) real(p)
#define y(p) imag(p)

const double eps=1e-8;
const double inf=1e12;
typedef complex<double> P;

namespace std{
  bool operator<(const P& a,const P& b){
    return x(a)==x(b)?y(a)<y(b):x(a)<x(b);
  }
}
double cross(const P& a,const P& b){
  return y(conj(a)*b);
}
double dot(const P& a,const P& b){
  return x(conj(a)*b);
}
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

P projection(const L& l,const P& p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*x(c/b);
}
P reflection(const L& l,const P& p){
  return p+2.0*(projection(l,p)-p);
}
P rotation(const P& a,double r){
  return P(x(a)*cos(r)-y(a)*sin(r),x(a)*sin(r)+y(a)*cos(r));
}

//// counter-clockwise
int ccw(P a,P b,P c) {
  b=b-a;c=c-a;
  if(cross(b,c)>0) return +1;       // counter clockwise
  if(cross(b,c)<0) return -1;       // clockwise
  if(dot(b,c)<0)   return +2;       // c--a--b on line
  if(norm(b)<norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L& l,const L& m){
  return abs(cross(l[1]-l[0],m[1]-m[0]))>eps;
}
bool intersectSS(const L& s,const L& t){
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1])<=0&&ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1])<=0;
}
bool intersectSP(const L& s,const P& p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<eps;
}
double distanceSP(const L& s,const P& p) {
  const P r=projection(s,p);
  return intersectSP(s,r)?abs(r-p):min(abs(s[0]-p),abs(s[1]-p));
}
double distanceSS(const L& s,const L& t) {
  return intersectSS(s,t)?0:min(min(distanceSP(s,t[0]),distanceSP(s,t[1])),
                                min(distanceSP(t,s[0]),distanceSP(t,s[1])));
}

P ps[111][5];
double dist[111][111];
const double PI=acos(-1);

int main(){
	cin.sync_with_stdio(false);
  while(1){
    int n,m,l;
    cin>>n>>m>>l;
    l--;m--;
    if(n==0)break;
    rep(i,n){
      double x,y,a,r;
      cin>>x>>y>>a>>r;
      P cent(x,y),p0(0,r);
      rep(j,5){
        ps[i][j]=rotation(p0,(((a+(double)j*72.0)/180.0)*PI))+cent;
      }
    }
    rep(i,n)rep(j,n)dist[i][j]=i==j?0:inf;
    rep(i,n)rep(j,n)rep(id,5)rep(jd,5){
      if(i==j)continue;
      minch(dist[i][j],distanceSS(L(ps[i][id],ps[i][(id+2)%5]),L(ps[j][jd],ps[j][(jd+2)%5])));
    }
    rep(k,n)rep(i,n)rep(j,n)minch(dist[i][j],dist[i][k]+dist[k][j]);
    printf("%.20f\n", dist[l][m]);
  }
	return 0;
}

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

int main() {
    int k, n;
    std::cin >> n >> k;
    std::vector<int> x(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += 2*std::min(std::abs(k - x[i]), x[i]);
    }

    std::cout << ans << "\n";
}

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

using namespace std;

long long test, n, d, dem, ma[10], res;

void pt(long long x){
    dem = 0;
    long long tmp[10];
    for(long long i = 1; i <= 7; i++) tmp[i] = 0;
    while(x > 0){
        dem ++;
        tmp[dem] = x % 2;
        x = x / 2;
    }
    for(long long i = 1; i <= 7; i++) ma[i] = tmp[8 - i];
}

int main()
{
    cin >> test;
    while(test--){
        cin >> n >> d;
        pt(d);
        res = 0;
        for(long long i = 1; i <= 7; i++){
            if(n % 2 == 0){
                if(ma[i] == 0) res = res + n * pow(2, 7 - i);
                else res = res + (n - 1) * pow(2, 7 - i);
            }
            else{
                if(ma[i] == 0) res = res + (n - 1) * pow(2, 7 - i);
                else res = res + n * pow(2, 7 - i);
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int k, a, b; scanf("%d%d%d", &k, &a, &b);

	if((a + k - 1) / k * k <= b) printf("OK\n");
	else printf("NG\n");
	return 0;
}


Measured memory_bytes: 3764
s = input()
len_s = len(s)
cnt = [0, 0]
for i in range(1, len(s)):
    memo_0 = s[i - 1]
    memo_1 = s[len_s - i]
    if s[i] != memo_0:
        cnt[0] += 1
    if s[len_s - i - 1] != memo_1:
        cnt[1] += 1
print(min(cnt))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int n, k, ans;
    cin >> n >> k;
    int p[n];
    ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }

    sort(p, p+n);

    for(int i = 0; i < k; i++) {
        ans += p[i];
    }

    cout << ans << endl;
            
}

Measured memory_bytes: 3592