akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[1000005],x,n,t,s,p,q,u,v,l[1000005],r[1000005],f[1000005][26]; char S[1000005],T[1000005];
int main(){
	//freopen("game.in","r",stdin);
	//freopen("game.out","w",stdout);
	scanf("%d",&n);
	scanf("%s%s",S+1,T+1);
	if (strcmp(S+1,T+1)==0) return puts("0"),0;
	for (int i=1;i<=n;++i){
		for (int j=0;j<26;++j) f[i][j]=f[i-1][j];
		f[i][S[i]-'a']=i;
	}
	x=n;
	for (int i=n,j;i;i=j){
		for (j=i;T[j]==T[i];--j); x=min(x,j+1);
		r[++t]=i; l[t]=f[x][T[i]-'a']; x=l[t]-1;
		if (!l[t]) {puts("-1"); return 0;}
	}
	x=p=q=u=v=0;
	for (int i=t;i;--i){
		if (q<l[i]){
			u=1; for (v=0,p=l[i];p<=r[i];++p) a[++v]=1;
			p=l[i]; q=r[i]; x=0;
		}else{
			for (;p<l[i];++p) a[u++]=0; a[u-1]=a[u]; --u;
			p=l[i]; for (++q;q<r[i];++q) a[++v]=-x; ++x;			
		}
		s=max(a[u]+x,s);
	}
	
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 114944
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	string s;
	scans(s);
	cout << "ABC" + s << endl;

	Please AC;
}


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

#define MAX 100001
typedef long long ll;

ll dp[MAX];
ll height[MAX];

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

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

    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    auto dp = make_vec<int>((1 << n) + 10, n + 10);
    rep(i, (1 << n) + 10) rep(j, n + 10) dp[i][j] = INF;
    rep(i, n) dp[1 << i][i] = i;

    rep(bit, 1 << n) {
        rep(i, n) {  // i番目のカードがbitで表される集合の末尾
            if (!(bit & (1 << i))) continue;

            int pos = __builtin_popcount(bit) - 1;
            int last = ((pos - i) % 2 == 0 ? a[i] : b[i]);
            rep(j, n) {  // j番目のカードを追加
                if (bit & (1 << j)) continue;

                int now = ((pos + 1 - j) % 2 == 0 ? a[j] : b[j]);
                if (now < last) continue;

                int cnt = 0;
                for (int k = 0; k < j; k++) {
                    if (!(bit & (1 << k))) cnt++;
                }
                chmin(dp[bit | (1 << j)][j], dp[bit][i] + cnt);
            }
        }
    }

    int ans = INF;
    rep(i, n) {
        chmin(ans, dp[(1 << n) - 1][i]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}

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

int main() {
  int a;
  cin>>a;
  vector<int> b(4);
  string c;
  for(int i=0;i<a;i++){
  cin>>c;
    if(c=="AC")b.at(0)++;
    else if(c=="WA")b.at(1)++;
    else if(c=="TLE")b.at(2)++;
    else if(c=="RE")b.at(3)++;
  }
  cout<<"AC x "<<b.at(0)<<endl<<"WA x "<<b.at(1)<<endl<<"TLE x "<<b.at(2)<<endl<<"RE x "<<b.at(3)<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;
#define pp pair<ll,ll>
bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int u=1;
  while(u--)
  {
    int k,t;
    cin>>k>>t;
    int a[t];
    REP(i,t)cin>>a[i];
    if(t==1)
    {
        cout<<a[0]-1;
        return 0;
    }
    sort(a,a+t);
    int pref[t];
    pref[0]=a[0];
    for(int i=1;i<t;i++)
    pref[i]=pref[i-1]+a[i];
    if(a[t-1] <= pref[t-2] + 1)
    cout<<0;
    else
    {
        cout<<(a[t-1] - pref[t-2]) - 1;
    }
    
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    cnt = 0
    right = 0
    acc = a[0]
    xor = a[0]
    for left in range(n):
        while right < n:
            if right + 1 >= n or acc + a[right+1] != xor ^ a[right+1]:
                break
            right += 1
            acc += a[right]
            xor ^= a[right]
        if acc == xor:
            cnt += (right - left + 1)
        acc -= a[left]
        xor ^= a[left]
    print(cnt)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 32048
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<29;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> x(n+1),y(n+1);
    x[0]=0;y[0]=0;
    rep(i,n){
        x[i+1] = gcd(x[i],a[i]);
    }
    vector<int> b = a;
    reverse(b.begin(),b.end());
    rep(i,n){
        y[i+1] = gcd(y[i],b[i]);
    }
    ll ma = 0;
    rep(i,n){
        ma = max(ma,gcd(x[i],y[n-i-1]));
    }
    cout << ma << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

map<ll,ll> mp;

void f(ll x){
  if(x <= 1)return;
  for(ll i = 2; i*i <= x; ++i){
    if(x%i==0){
      f(i);
      f(x/i);
      return;
    }
  }
  mp[x]++;
}

int main(){
  ll n,p; cin >> n >> p;
  f(p);
  ll ans = 1;
  for(auto e:mp){
    ans *= pow(e.first,(e.second / n));
  }
  cout << ans << endl;
}


Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */
void solve(vector<int> v[], int n)
{
  vector<int> d(n+1, INT_MAX);
  vector<int> res(n+1,0);
  d[1] = 0;
  queue<int> q;
  q.push(1);
  bool vis[n+1];
  memset(vis,false,sizeof(vis));
  int i;
  bool flag = false;
  int cnt = 0;
  while(!q.empty())
  {
    int t = q.front();
    cnt++;
    //cout << t << " ";
    q.pop();
    vis[t] = true;
    for(auto it = v[t].begin(); it != v[t].end(); it++)
    {
      if(!vis[*it])
      { 
        if(d[*it] > d[t] + 1)
        {
          d[*it] = d[t] + 1;
          res[*it] = t;
        }
        q.push(*it);
        vis[*it] = true;
      }
    }
  }
  //cout << endl;
  /*f(i,2,n+1)
  {
    if(d[i] == INT_MAX)
    {
      flag = true;
      break;
    }
  }
  */
  if(cnt != n)
    cout << "No"<<endl;
  else
  {
    cout << "Yes"<<endl;
    f(i,2,n+1)
      cout << res[i] << endl;
  }
}
int main()
{
    fio;
    int t,n,i,m,x,y;
    cin >> n >> m;
    vector<int> v[n+1];
    f(i,0,m)
    {
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }
    solve(v, n);
}


Measured memory_bytes: 10820
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
s = input()
n = len(s)
#条件1
for i in range(n):
    if s[i] == s[n-1-i]:
        continue
    else:
        print("No")
        sys.exit()
ans1 = []
#条件2
for i in range(n//2):
    ans1.append(s[i])
for i in range(len(ans1)):
    if ans1[i] == ans1[len(ans1)-1-i]:
        continue
    else:
        print("No")
        sys.exit()
#条件3
ans2 = []
for i in range((n+3)//2-1,n):
    ans2.append(s[i])
for i in range(len(ans2)):
    if ans2[i] == ans2[len(ans2)-1-i]:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")


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

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

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

#define PI              acos(-1.0)

//inline int setBit(int n,int pos) { return n = n | (1 << pos); }
//inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
//inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }
//inline int countBit(int n) { return __builtin_popcount(n); }


//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

/******************************************************************************************/

//const int MAX = 300010;
//const int INF = 0x3f3f3f3f;
//const double inf = 1.0/0.0;
//const int MOD = 1000000007;


int main() {
//    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);


    ll n,m,d;
    slll(n,m,d);

    long double ans;

    ans = (n-d)*(m-1)*2.0;
    ans /= (n*n);

    if(d==0) {
        ans /= 2.0;
    }

    if(ans<0) ans = 0;

    cout << setprecision(9) << fixed << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll a, b, c;
  cin >> a >> b >> c;
  if(b-a == c-b) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
//*/

#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
#include <complex>

#define N 15005

using namespace std;

typedef long long int lld;

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	switch (n % 10)
	{
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		printf("hon\n");
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		printf("pon\n");
		break;
	default:
		printf("bon\n");
		break;
	}
	return 0;
}

//*/ 

Measured memory_bytes: 1660
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

bool dfs(vll& b, vll& ans, vb& f) {
    if(ans.size() == f.size()) {
        reverse(ans.begin(), ans.end());
        for(ll& i : ans) cout << i << endl;
        return true;
    }
    ll num = 1, idx = -1;
    for(ll i = 0; i < (ll)b.size(); i++) {
        if(f[i]) continue;
        if(b[i] == num) idx = i;
        ++num;
    }
    if(idx != -1) {
        f[idx] = true;
        ans.push_back(b[idx]);
        if(dfs(b, ans, f)) return true;
    }
    return false;
}

void solve() {
    ll n;
    cin >> n;
    vll b(n);
    rep(i, n) cin >> b[i];
    vll ans;
    vb used(n, false);
    if(!dfs(b, ans, used)) cout << -1 << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3640
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e15;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(void) {
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    if (x / d >= k && x >= 0) {
        cout << abs(x - k * d) << endl;
        return 0;
    }ll big = x - x / d * d, sm = big - d;
     if ((k - x / d) % 2 == 0) cout << abs(big) << endl;
     else cout << abs(sm) << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] s1=new char[s.length()+1];
		for(int i=0; i<s.length(); i++){
			s1[i]=s.charAt(i);
		}
		for(int i = 0; i<Math.pow(2,s.length()-1); i++){
			long ans = Long.parseLong(String.valueOf(s1[0]));
			StringBuilder sb=new StringBuilder();
			sb.append(s);
			int t=i;
			int count=1;
			String a=String.valueOf(s1[1]);
			while(count<s.length()){
				if((t & 1)==1){
					ans+=Long.parseLong(a);
					
						sb.insert(count*2-1,"+");
					
				}else{
					ans-=Long.parseLong(a);
					
						sb.insert(count*2-1,"-");
					
				}
				count++;
				a=String.valueOf(s1[count]);
				t>>=1;
			}
			if(ans==7){
				sb.append("=7");
				System.out.println(sb);
				return;
			}
		}
	}
}

Measured memory_bytes: 22996
N = int(input())
adj_list = [[] for i in range(N+1)]
for i in range(N-1):
    a,b,c, = map(int,input().split())
    adj_list[a].append([b,c])
    adj_list[b].append([a,c])

Q,s = map(int,input().split())
from heapq import heapify,heappush,heappop
D_INF = 10**15
d = [D_INF]*(N+1)#最速到達距離。でかい数で初期化
d[s] = 0#スタート
que = []
heapify(que)
heappush(que,(d[s],s))

while(len(que)):
    time,place = heappop(que)
    if time > d[place]:
        continue
    for i in range(0,len(adj_list[place]),1):
        if d[adj_list[place][i][0]] > time + adj_list[place][i][1]:#とりあえず円で
            d[adj_list[place][i][0]] = time + adj_list[place][i][1]
            heappush(que,(d[adj_list[place][i][0]],adj_list[place][i][0]))


ans = []
for i in range(Q):
    x,y = map(int,input().split())
    ans.append(d[x]+d[y])

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 120268
N = int(input().strip())

moves = []
for i in range(N):
    moves.append(map(int, input().split()))

pos = [0, 0, 0]
out = 'Yes'

for t_to, x_to, y_to in moves:
    move_to = abs(x_to - pos[1]) + abs(y_to - pos[2])
    time_to = t_to - pos[0]
    
    if move_to == time_to or (((time_to - move_to) > 0) and (time_to - move_to) % 2 == 0):
        pos = [t_to, x_to, y_to]
    else:
        out = 'No'
        break

print(out)


Measured memory_bytes: 48784
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    char last = S[0];
    int cnt = 0;
    for (auto c : S) {
        if (last != c) {
            cnt++;
            last = c;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,j;
    j=0;
    // Your code here
    cin>>a>>b>>c;
        for(int i=a;i<=b;i++){
            if(c%i==0)j++;
        }
        cout<<j<<"\n";

   }
   



Measured memory_bytes: 3080
#include <stdio.h>
#include <queue>
using namespace std;

int n,m; char map[22][22]; int d[22][22];
int bfs(int sx, int sy)
{
for (int i=0;i<n;i++) for (int j=0;j<m;j++) d[i][j] = -1;
queue<pair<int, int> > q; q.push({sx,sy}); d[sx][sy] = 0;
  int r = 0;
  while (!q.empty()){
int x = q.front().first, y = q.front().second; r = d[x][y]; q.pop();
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};
    for(int k=0;k<4;k++){
int px = x + dx[k], py = y + dy[k];
      if (px < 0 || px >= n || py < 0 || py >= m || map[px][py] == '#') continue;
      if (d[px][py] == -1){
q.push({px,py}); d[px][py] = d[x][y] + 1;
      }
    }
  }
  return r;
}

int main()
{
scanf ("%d %d",&n,&m);
  for (int i=0;i<n;i++) scanf ("%s",map[i]);
  int ans = 0;
  for (int i=0;i<n;i++) for (int j=0;j<m;j++) if (map[i][j] == '.'){
int a = bfs(i,j);
    if (ans < a) ans = a;
  }
  printf ("%d\n",ans);
  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1001

int32_t main()
{                
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int n,k;
    cin>>n>>k;
    vi v(n);
    int ind=-1;
    for(int i=0;i<n;i++)
    {
    	cin>>v[i];
    	if(ind==-1 && v[i]>=0)
    	{
    		ind=i;
    	}
    }
    if(ind==-1 || ind==0)
    {
    	if(ind==-1)
    	{
    		cout<<abs(v[n-k]);
    	}
    	else
    		cout<<v[k-1];
    }
    else
    {
    	int cnt=0;
    	int ans=1e14;
    	for(int i=ind;i<n;i++)
    	{
    		cnt++;
    		if(cnt+ind>=k)
    		{
    			ans=min(ans,2*v[i]+abs(v[ind-(k-cnt)]));
    		}
    		if(cnt==k)
    			{ans=min(ans,v[i]);break;}
    		//trace2(ans,i);
    	}
    	cnt=0;
    	for(int i=ind-1;i>=0;i--)
    	{
    		cnt++;
    		if(cnt+n-ind>=k)
    		{
    			//trace3(i,2*abs(v[i]),v[ind+(k-cnt)-1]);
    			ans=min(ans,2*abs(v[i])+v[ind+(k-cnt)-1]);
    		}
    		if(cnt==k)
    			{ans=min(ans,abs(v[i]));break;}
    	}
    	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    int n, m;
    cin >> n >> m;
    vi a(m);
    vi b(m);
    
    vi h(n+1);
    vi f(n+1);
    
    int r = 0;
    
    for (int i = 1; i <= n; ++i) cin >> h[i];
    
    for (int i = 0; i < m; ++i) cin >> a[i] >> b[i];
    
    rep (i, m) {
        if (h[a[i]] > h[b[i]]) {
            f[b[i]] = 1;
        }
        if (h[a[i]] == h[b[i]]) {
            f[a[i]] = 1;
            f[b[i]] = 1;
        }
        if (h[a[i]] < h[b[i]]) {
            f[a[i]] = 1;
        }
    }
    
    for (int i = 1; i <= n; i++) {
        if (f[i] == 0) r++;
    }
    
    
    
    cout << r;
    
    
    
   
    
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<vector<int>> books(10);
    for(int i = 0; i < N; ++i) {
        int c, g;
        cin >> c >> g;
        books[g - 1].push_back(c);
    }
    for(int i = 0; i < 10; ++i) {
        sort(rbegin(books[i]), rend(books[i]));
    }
    vector<vector<int>> dp(11, vector<int>(K + 1));
    for(int i = 0; i < 10; ++i) {
        int total = 0;
        for(int m = 0; m <= books[i].size(); ++m) {
            for(int k = 0; k + m <= K; ++k) {
                dp[i + 1][k + m] = max(dp[i + 1][k + m], dp[i][k] + total);
            }
            if(m != books[i].size()) {
                total += books[i][m] + 2 * m;
            }
        }
    }
    cout << dp[10][K] << endl;
}


Measured memory_bytes: 3280
#include <stdio.h>

int main(void)
{
	int a, b, i, sum;
	int count = 0;
	while(scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		for(i = 1; sum != 0; i++){
			sum = sum / 10;
		}
		printf("%d\n", i-1);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int ans[maxn],d[maxn*2],fa[maxn*2],h[maxn*2],now[maxn*2],go[maxn*6],nxt[maxn*6],sta[maxn*6];
bool bz[maxn*6],czy;
int i,j,k,l,r,s,t,n,m,tot,top,rot1,rot2;
/*int read(){
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') f=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){

    }
}*/
void add(int x,int y){
    go[++tot]=y;
    nxt[tot]=h[x];
    h[x]=tot;
}
void dfs(int x,int y){
    int t=h[x];
    while (t){
        if (go[t]!=y){
            dfs(go[t],x);
            d[x]^=1;
        }
        t=nxt[t];
    }
    d[x]^=1;
}
void travel(int x){
	int &t=h[x];
    while (t){
        if (!bz[(t+1)/2]){
            bz[(t+1)/2]=1;
            //now[x]=nxt[t];
            travel(go[t]);
        }else t = nxt[t];
    }
    sta[++top]=x;
}
int main(){
    scanf("%d",&n);
    fo(i,1,n){
        scanf("%d",&fa[i]);
        if (fa[i]==-1){
            fa[i]=0;
            rot1=i;
        }
        else{
            add(fa[i],i);
            add(i,fa[i]);
        }
    }
    fo(i,n+1,2*n){
        scanf("%d",&fa[i]);
        if (fa[i]==-1){
            fa[i]=0;
            rot2=i;
        }
        else{
            add(fa[i]+n,i);
            add(i,fa[i]+n);
        }
    }
    dfs(rot1,0);
    dfs(rot2,0);
    czy=1;
    fo(i,1,n)
        if (d[i]^d[i+n]){
            czy=0;
            break;
        }
    if (!czy){
        printf("IMPOSSIBLE\n");
        return 0;
    }
    printf("POSSIBLE\n");
    s=0;
    add(s,rot1);
    add(rot1,s);
    add(s,rot2);
    add(rot2,s);
    fo(i,1,n)
        if (d[i]){
            add(i,i+n);
            add(i+n,i);
        }
    travel(s);
    fo(i,1,n)
        if (d[i]) ans[i]=-1;
    fo(i,1,top-1)
        if (sta[i]>0&&sta[i]<=n&&sta[i+1]==sta[i]+n) ans[sta[i]]=1;
    fo(i,1,n) printf("%d ",ans[i]);
}

Measured memory_bytes: 20352
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
    string[] S=Console.ReadLine().Split(' ');
     int[] arr=S.Select(int.Parse).ToArray();
      for(int i=1;i<N;i++){
       Console.Write(Array.IndexOf(arr,i)+1+(" "));
   
        
      }
      Console.Write((Array.IndexOf(arr,N)+1)+"\n");
    
    }
    
  }

}


Measured memory_bytes: 42576
#include <iostream>

using namespace std;

int main()
{
   int H,W;
   for(;;){
     cin >> H >> W;
   if(H!=0||W!=0){
     for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            cout << "#" ;
        }
        cout << "#" << endl;
     }
     cout << endl;
   }
   else break;
   }
   return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
int main(){
  int n,k;
  std::cin >> n >> k;
  char c[51];
  
  for (int i = 0; i < n;++i){
  std::cin >> c[i];
  }
  
  c[k-1] += 32;
  
  for (int i = 0; i < n;++i){
  std::cout << c[i];
  }
  
  std::cout << "" << std::endl;
  
}

Measured memory_bytes: 256
def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()


def fst(t):
    return t[0]


def snd(t):
    return t[1]


def thd(t):
    return t[2]


if __name__ == '__main__':
    n, m = map(int, input().split())
    l = []
    ans = []
    for i in range(m):
        p, y = map(int, input().split())
        l.append((p, y, i))

    l = sorted(l)
    end = 0
    for i in range(n):
        begin = end
        while end < len(l) and fst(l[end]) == i + 1:
            end += 1
        town = l[begin:end]
        sorted(town, key=lambda x: snd(x))
        tmp = 1
        for e in town:
            ans.append((fst(e), tmp, thd(e)))
            tmp += 1

    ans = sorted(ans, key=lambda x : thd(x))
    for e in ans :
        birth = str(fst(e))
        rate = str(snd(e))
        print(birth.zfill(6) + rate.zfill(6))

Measured memory_bytes: 35932
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		System.out.println(ans(n));
	}

	public static int ans(int n) {
		if (n < 112) {
			return 111;
		} else if (n < 223) {
			return 222;
		} else if (n < 334) {
			return 333;
		} else if (n < 445) {
			return 444;
		} else if (n < 556) {
			return 555;
		} else if (n < 667) {
			return 666;
		} else if (n < 778) {
			return 777;
		} else if (n < 889) {
			return 888;
		} else {
			return 999;
		}
	}
}

Measured memory_bytes: 22740
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll a, b;
    scanf("%lld %lld", &a, &b);
    printf((a*b%2==0)?"Even\n":"Odd\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Kannondou
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int[] dp = new int[34];
		dp[0] = 1;

		for (int i = 0; i <= 30; i++) {
			dp[i + 1] += dp[i];
			dp[i + 2] += dp[i];
			dp[i + 3] += dp[i];
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			System.out.println((dp[n] / 3650) + (dp[n] % 3650 > 0 ? 1 : 0));

		}
	}
}

Measured memory_bytes: 24464
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 200000;

int main(void){
    ll N, M;
    ll a[MAX_N];
    ll answer[MAX_N];

    cin >> N;
    M = 0;
    rep(i, N) cin >> a[i];
    For(i, N / 2, N) {answer[i] = a[i]; M += answer[i];}
    
    for (int i = N / 2 - 1; i >= 0; i--){
        ll k = 2;
        while ( k * (i + 1) - 1 < N ){
            answer[i] += answer[k * (i + 1) - 1];
            k ++;
        }
        answer[i] = (answer[i] + a[i]) % 2;
        M += answer[i];
    }
    
    cout << M << endl;
    rep(i, N) if (answer[i]) cout << i + 1 << " ";
    cout << "" << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
 
using namespace std;
 
const int maxn=500005;
typedef long long ll;
 
int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}
 
ll x,y;
ll a,b;

int main()
{
	cin>>x;
	for(a=-200;a<=200;a++)
	{
		for(b=-200;b<=200;b++)
		{
			if(a*a*a*a*a-b*b*b*b*b==x)
			{
				cout<<a<<' '<<b<<endl;
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
  int N, ans = 0;
  cin >> N;
  while (N > 0) {
    int check = 0, Nc = N;
    while (Nc > 0) {
      check++;
      Nc /= 10;
    }
    if (check % 2 == 1) {
      ans++;
    }
    N--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	char sen[100000 + 1];
	scanf("%s", sen);
	int count = 0;
	int preCo;
	if (sen[0] == 'W')preCo = 1;
	else preCo = 0;
	int i = 0;
	while (sen[i] != '\0') {
		if (sen[i] == 'W') {
			if (preCo == 0) {
				preCo = 1;
				count++;
			}
		}
		else {
			if (preCo == 1) {
				preCo = 0;
				count++;
			}
			}
		i++;
	}
	printf("%d", count);
	return 0;
}


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

int main()
{
	int a, b, c, min;
	cin >> a >> b >> c;
	min = a + b;
	if (min > a + c) {
		min = a + c;
	}
	if (min > b + c) {
		min = b + c;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
S = input().rstrip()
cnt = 0
for s in S[2:-1]:
    if s == "C":
        cnt += 1
    else:
        if not s.islower():
            print("WA")
            exit()
if cnt == 1 and S[0] == "A" and S[1].islower() and S[-1].islower():
    print("AC")
else:
    print("WA")

Measured memory_bytes: 61940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vp in(n);
		rep(i,n)cin>>in[i].first>>in[i].second;
		sort(all(in));
		int sum1=0,sum2=0;
		rep(i,n)sum1+=in[i].first,sum2+=in[i].second;
		if(sum1>=2*in[n-1].first)cout<<sum1+sum2<<endl;
		else{
			int m=2*in[n-1].first-sum1;
			vi dp(m+1);
			dp[0]=true;
			rep(i,n-1)for(int j=m-in[i].second;j>=0;j--)if(dp[j])dp[j+in[i].second]=true;
			int ma=0;
			rep(i,m+1)if(dp[i])ma=i;
			cout<<in[n-1].first*2+sum2-ma<<endl;
		}
	}
}

Measured memory_bytes: 3068
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
char a[1000];
char b[1000];
char c[1000];
int main(){
    ss(a)
    ss(b)
    ss(c)
    int lena = len(a);
    int lenb = len(b);
    int lenc = len(c);
    int aa = 0,bb = 0,cc = 0;
    int count0 = 1;
    while(1){
        if(count0 == 1){
            if(aa == lena+1){
                pc('A') pn;
                return 0;
            }
            if(a[aa] == 'a'){
                count0 = 1;
            }else if(a[aa] == 'b'){
                count0 = 2;
            }else if(a[aa] == 'c'){
                count0 = 3;
            }
            a[aa] = 0;
            aa ++;
        }else if(count0 == 2){
            if(bb == lenb+1){
                pc('B') pn;
                return 0;
            }
            if(b[bb] == 'a'){
                count0 = 1;
            }else if(b[bb] == 'b'){
                count0 = 2;
            }else if(b[bb] == 'c'){
                count0 = 3;
            }
            b[bb] = 0;
            bb ++;
        }else if(count0 == 3){
            if(cc == lenc+1){
                pc('C') pn;
                return 0;
            }
            if(c[cc] == 'a'){
                count0 = 1;
            }else if(c[cc] == 'b'){
                count0 = 2;
            }else if(c[cc] == 'c'){
                count0 = 3;
            }
            c[cc] = 0;
            cc ++;
        }
    }














    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int N, K;

signed main() {
  cin >> N >> K;
  vector<ll> a(N), s1(N + 1), s2(N + 1);
  rep(i, N) {
    cin >> a[i];
    s1[i + 1] = s1[i] + a[i];  // s1[i] := a[0]~a[i-1]までの合計
    s2[i + 1] =
        s2[i] +
        max(0ll, a[i]);  // s2[i] := a[0]~a[i-1]のうち0以上の部分だけを加える
  }
  ll res = -INF;
  // 最後に長さKの区間を選び, それを白か黒にする
  // それ以外は自由に決められる
  for (int i = 0; i + K <= N; i++) {
    int left = i,
        right = i + K;  // 長さKの区間の左端と右端+1(累積和から求めるから)
    ll tmp = (s2[left] - s2[0]) +              // 区間外は自由に選べるので非負の累積和
             max(0ll, s1[right] - s1[left]) +  // 今選んでいる長さKの区間のマスを全て黒にするか白にするか
             (s2[N] - s2[right]); // 区間外は自由に選べるので非負の累積和
    res = max(res, tmp);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];

    ll res = 0;
    rep(i, n - 1) {
        if (a * (x[i + 1] - x[i]) < b) {
            res += a * (x[i + 1] - x[i]);
        }
        else {
            res += b;
        }
    }

    cout << res << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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

const ll SIZE = 1e5+10;

string s,t;

int main(){
    cin >> s >> t;
    cout << t+s << endl;
}

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

using namespace std;

int main()
{
    string st;
    int n;
    set<char>s;
    cin>>st;
    cin>>n;

    for(int i=0; i<st.size(); i++)
        s.insert(st[i]);

    int t = n;
    set<char>::iterator it = s.begin();
    set<string>s22;

    for(int cnt = 1; cnt<=6; cnt++)
    {
        for(int i=0; i<st.size(); i++)
        {
            if(*it != st[i])
                continue;
            for(int j=1; j<=5&&j+i<=st.size(); j++)
            {
                string st2 = st.substr(i,j);
                s22.insert(st2);
            }
        }
        if(it != s.end())
        it++;
    }

    set<string>::iterator it2 = s22.begin();

    n--;
    while(n-- && it2 != s22.end())
        it2++;
    cout<<*it2<<endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string p;
	bool flag=false;
	getline(cin,p);
	for(int i=0;i<=p.size();i++)
	{
		if(p[i]=='C') flag=true;
		if(p[i]=='F'&&flag)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
def main():
    from math import sqrt
    import sys
    input = sys.stdin.buffer.readline
    N, D = (int(i) for i in input().split())
    Xs = [[int(i) for i in input().split()] for j in range(N)]

    def check(A, B):
        v = sum((a-b)**2 for a, b in zip(A, B))
        if sqrt(v).is_integer():
            return True
        else:
            return False

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if check(Xs[i], Xs[j]):
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512