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

const int MAXN = 2005;

char A[MAXN], B[MAXN];
int n;
int pre[MAXN], nxt[MAXN];

struct point {
	int p, n;
	friend bool operator < (const point &a, const point &b)
	{ return a.p < b.p; }
} pt[MAXN];

int main()
{
	scanf("%s", A);
	scanf("%s", B);
	n = strlen(A);
	int flag = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			if (B[j] == '1') pre[j] = 0, flag = 1;
			else pre[j] = pre[(j-1+n)%n]+1;
		}
		for (int j = n-1; j >= 0; j--) {
			if (B[j] == '1') nxt[j] = 0;
			else nxt[j] = nxt[(j+1)%n]+1;
		}
	}
	if (flag == 0) {
		for (int j = 0; j < n; j++)
			if (A[j] == '1') {
				cout << -1 << endl;
				return 0;
			}
		cout << 0 << endl;
		return 0;
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		int cur = i, top = 0;
		for (int j = 0; j < n; j++)
			if (A[j] != B[(i+j)%n]) {
				cur++;
				if (nxt[j] > i)
					pt[++top] = (point) {pre[j], nxt[j]-i};
			}
		sort(pt+1, pt+top+1);
		static int b[MAXN];
		b[top+1] = 0;
		for (int j = top; j >= 1; j--)
			b[j] = max(b[j+1], pt[j].n);
		int shi = 1e8;
		// cerr << top << "," << cur << endl;
		for (int j = 0; j <= top; j++) {
			// cerr << pt[j].p << " " << pt[j].n << endl;
			shi = min(shi, pt[j].p+b[j+1]);
		}
		cur += shi*2;
		ans = min(ans, cur);
	}
	for (int i = 0; i < n; i++) {
		int cur = i, top = 0;
		for (int j = 0; j < n; j++)
			if (A[j] != B[(j-i+n)%n]) {
				cur++;
				if (pre[j] > i)
					pt[++top] = (point) {pre[j]-i, nxt[j]};
			}
		sort(pt+1, pt+top+1);
		static int b[MAXN];
		b[top+1] = 0;
		for (int j = top; j >= 1; j--)
			b[j] = max(b[j+1], pt[j].n);
		int shi = 1e8;
		// cerr << top << "," << cur << endl;
		for (int j = 0; j <= top; j++) {
			// cerr << pt[j].p << " " << pt[j].n << endl;
			shi = min(shi, pt[j].p+b[j+1]);
		}
		cur += shi*2;
		ans = min(ans, cur);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin>>N;
  vll A(N+1),B(N);
  REP(i,N+1)cin>>A[i];
  REP(i,N)cin>>B[i];
  ll ans = 0;
  REP(i,N){
    if(B[i]>=A[i]){ 
      ans+=A[i];
      B[i]-=A[i];
      A[i]=0;
      if(B[i]>=A[i+1]){
        ans+=A[i+1];
        A[i+1]=0;
      }else{
        ans+=B[i];
        A[i+1]-=B[i];
      }
    }else{
      ans+=B[i];
      A[i]-=B[i];
    }
  }
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){

    int a=0,b=0,c=0;
    
    scanf("%d %d %d",&a,&b,&c);

    if (a<b&&b<c&&a<c)
        printf("Yes\n");
    else if(a>b||b>c||a>c)
        printf("No\n");
    else
        printf("No\n");
    
    return 0;
    
    }

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

int main(){
    int x; cin >> x;
    int ans,cnt = 1000;
    for(int b=1;b<32;b++){
        int q = b*b;
        for(int p=2;p<10;p++){
            if(x-q < cnt && x-q >= 0){
                cnt = x-q;
                ans = q;
            }
            q = q*b;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int i,n,x,y,z,ans,a[100000]={0};
//    for(i=1;i<=10;i++){
//        cout<< a[i] <<endl;
//    }
    cin>> n;

    for(x=1;x<=102;x++){
        for(y=1;y<=102;y++){
            for(z=1;z<=102;z++){
                ans = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                if(ans<=n)a[ans]++;
            }
        }
    }

    for(i=1;i<=n;i++){
        cout<< a[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define INF 100000
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,ans=0,l,r;
	cin >> N;
	rep(i,N){
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

const lint INF = 1ll << 60;
const int mod = 1000000007;
const int inf = INT_MAX;
void speed() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	return;
}



int main(void) {
	speed();
	int n; cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		s.insert(a);
	}
	cout << s.size() - (n - (int)s.size()) % 2 << endl;

	return 0;
}

Measured memory_bytes: 8180
#include <cmath>
#include <cstdio>
#include <cstring>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define For(i, l, r) for (int i = (l); i <= (r); ++i)

typedef long long LL;
typedef pair<int, int> Pii;

const int maxn = 2 * sqrt(1000000000) + 5;
const int mod = 1000000007;

int n, k, m;
int f[2][maxn];

int main() {
  scanf("%d%d", &n, &k);
  m = sqrt(n + 0.5);
  int o = 0;
  For(j, 1, 2 * m) f[o][j] = 1;
  For(i, 1, k) {
    o ^= 1;
    int pre = 0;
    For(j, 1, m) {
      pre = (pre + f[o ^ 1][2 * m - j + 1]) % mod;
      f[o][j] = pre;
    }
    int last = m;
    for (int j = m; j >= 1; --j) {
      pre = (pre + (LL)f[o ^ 1][j] * (n / j - last)) % mod;
      f[o][2 * m - j + 1] = pre;
      last = n / j;
    }
  }
  printf("%d\n", f[o][2 * m]);

  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		char x=scan.next().charAt(0);
		char y=scan.next().charAt(0);
		if(x<y) {
			System.out.println("<");
		}
		else if(x>y) {
			System.out.println(">");
		}
		else {
			System.out.println("=");
		}

	}

}


Measured memory_bytes: 35540
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
#define pb push_back
using std::cin; using std::cout;
const int maxn = 100200;
typedef std::pair<int, int> pr;
int n, m, q;
int a[maxn], b[maxn], c[maxn];
int tg[maxn];
std::vector<int> v, vc0[maxn];
std::multiset<int> vc1[maxn];
inline int find(int x){ return std::lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }
int pre[maxn], tag[maxn], add[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) cin >> a[i] >> b[i];
	rep(i, 1, n + 1) cin >> c[i], v.pb(c[i]);
	std::sort(v.begin(), v.end()), v.erase(std::unique(v.begin(), v.end()), v.end()), m = v.size();
	rep(i, 1, n) {
		a[i] = find(a[i]), b[i] = find(b[i]);
		++ tag[m], -- tag[a[i] - 1];
		if(b[i] < a[i]) {
			vc0[a[i] - 1].pb(b[i]);
			vc1[b[i]].insert(a[i] - 1);
		}
	}
	rep(i, 1, n + 1) ++ tag[find(c[i]) - 1], --tag[m];
	std::priority_queue<pr, std::vector<pr>, std::greater<pr>> hp0;
	std::priority_queue<int> hp1;
	int ans = n;
	for(int i = m;i >= 1;--i) {
		for(int x : vc0[i]) hp0.push(pr(x, i));
		for(;tag[i] + tag[i + 1] < -1 && hp0.size();hp0.pop()) {
			int x = hp0.top().first;
			++ tag[i], -- tag[x - 1], -- ans;
			++ add[i + 1], -- add[hp0.top().second + 1];
			vc1[x].erase(vc1[x].find(hp0.top().second));
		}
		if((tag[i] += tag[i + 1]) < -1)
			ans = -1e9;
	}
	*pre = ans;
	for(int i = 1;i <= m;++i) {
		add[i] += add[i - 1];
		for(int x : vc1[i]) hp1.push(x);
		for(;tag[i] + add[i] < 0 && hp1.size();hp1.pop()) ++ add[i], --add[hp1.top() + 1], -- ans;
		if(tag[i] + add[i] < 0) ans = -1e9;
		pre[i] = ans;
	}
	cin >> q;
	rep(i, 1, q) {
		int x, y, ans;
		cin >> x >> y;
		ans = std::max(pre[find(x) - 1] + 1, pre[find(y) - 1]);
		cout << (ans < 0 ? -1 : ans) << '\n';
	}
}


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

using namespace std;

int main() {
    int t;
    cin>>t;
    
    vector<string>S;
    S.push_back("AC");
     S.push_back("WA");
      S.push_back("TLE");
       S.push_back("RE");
    
    string R;
    map<string,int>P;
    while(t--)
    {
        cin>>R;
        P[R]++;
    }
    
    for(auto x:S)
    {
        cout<<x<<" x "<<P[x]<<endl;
    }
    
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    int n, l;
    cin >> n >> l;
    string s[n];
    rep(i,n) cin >> s[i];
    sort(s,s+n);
    rep(i,n) cout << s[i];
    cout << endl;
}
/*



*/

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 1001001;
  rep(i, sz(s)-sz(t)) {
      int num = 0;
      rep(j,sz(t)) {
        if (i + j >= sz(s)) break;
        if (s[i + j] != t[j]) num++;
      }
      mins(ans, num);
  }
  int a = 0;
  rep(i,sz(t)){
    a += (s[sz(s)-1-i]==t[sz(t)-1-i]);
  }
  mins (ans,sz(t)-a);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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(){
  ll n;
  cin >> n;
  vi p(n);
  vi q(n);
  rep(i, n){
    cin >> p[i];
    q[i] = p[i];
  }
  sort(all(q));
  ll count = 0;
  rep(i,n){
    if(p[i]!=q[i]){
      count++;
    }
  }
  if(count==0||count==2){
    print("YES");
  }
  else{
    print("NO");
  }
}

Measured memory_bytes: 256
import sys
import collections

def solve():
    N = int(sys.stdin.readline().rstrip())
    A = list(map(int,sys.stdin.readline().rstrip().split()))
    A = sorted(A, reverse=True)
    maxA = A[0]
    cntA = collections.Counter(A)

    ans = 0
    for a in A:
        if cntA[a] == 0:
            continue
        cntA[a] -= 1
        #print('a =',a)
        b = (1 << a.bit_length()) - a
        if cntA[b] > 0:
            cntA[b] -= 1
            ans += 1
    return ans

print(solve())

#  1  1  7   9
#     3  5   11
#        13
#     15
#  2  6  10
#     14
#  4  4  12
#
#  8


Measured memory_bytes: 104272
#include <cstdio>
#include <utility>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (int R0, W0, C, R; R0 = in, W0 = in, C = in, R = in;)
		outl(max(0, (C * W0  - R0 + R - 1) / R));
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    ll N,K;
    cin >> N >> K;

    ll ma=0,mi=0,ans=0;

    for(int i=0;i<K-1;i++){
        mi+=i;
        ma+=N-i;
    }

    for(int i=K;i<=N+1;i++){
            mi += i-1;
            ma += N-i+1;

        ans += ma - mi + 1;
        ans = ans%1000000007; 
    }

    cout << ans << endl;

 
    return 0;

}

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

int main(void)
{
  char s[10];
  int c=0,i,j;
  scanf("%s",s);
  if(s[0]=='A')
  {
//    printf("%lu",strlen(s));
    for(i=2;i<strlen(s)-1;i++)
    {
      if(s[i]=='C')
      {
        c++;
        j=i;
      }

    }
    if(c==1)
    {
  //    printf("B");
      c=0;
      for(i=1;i<strlen(s);i++)
      {
        if(s[i]<97||s[i]>122) c++;
      }
  //    printf("%d",c);
      if(c==1) printf("AC");
      else printf("WA");
    }
    else printf("WA");
  }
  else printf("WA");
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> a(n, true);
  rep(i, k) {
    int d;
    cin >> d;
    rep(i, d) {
      int x;
      cin >> x;
      x--;
      a[x] = false;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (a[i] == true) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
n, m = gets.split.map(&:to_i)
xyz = n.times.map {gets.split.map(&:to_i)}

w=->a{a.zero? ? 1 : -1}

ans = 0
8.times do |i|
    xyz.sort_by!{|(x,y,z)| w[i[0]]*x + w[i[1]]*y + w[i[2]]*z}
    
    v = [0,0,0]
    xyz[0,m].each do |(x,y,z)|
        v[0] += x
        v[1] += y
        v[2] += z
    end

    ans = [ans, v[0].abs + v[1].abs + v[2].abs].max
end

p ans

Measured memory_bytes: 2040
#include <cmath>
#include <iostream>
#include <limits>

template <class T>
T calc_number_of_digits(T x) {
    T ret = 0;
    do {
        ++ret;
        x /= 10;
    } while (x);
    
    return ret;
}

template <class T>
T f(T a, T b) {
    return std::max<T>(calc_number_of_digits<T>(a), calc_number_of_digits<T>(b));
}

int main() {
    long long N;
    std::cin >> N;

    auto ret = std::numeric_limits<long long>::max();
    for (long long a = 1; a * a <= N; ++a) {
        if (N % a != 0) {
            continue;
        }

        const auto b = N / a;
        ret = std::min(ret, f(a, b));
    }

    std::cout << ret << std::endl;
}


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

int main() {
	int i,n,w,a1,a2,temp;
	char ch;
	
	cin >>w >>n;

	vector<int> amida;
	
	for(i=0;i<w;i++)
		amida.push_back(i+1);
	
	for(i=0;i<n;i++){
		cin >> a1;
		cin >> ch;
		cin >> a2;
		
		temp = amida[a1-1];
		amida[a1-1] = amida[a2-1];
		amida[a2-1] = temp;
		
	}
	
	for(i=0;i<w;i++){
		cout << amida[i] <<endl;
	}	
			
	return 0;
  
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int answer=0;
    if(a<k){
        answer=a;
        k-=a;
        if(b<k){
            k-=b;
            answer-=k;
        }
    }
    else answer=k;
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 998244353;
//


        signed main() {
        int a,b,m;
        cin>>a>>b>>m;
        int p[a],mip=MAX,q[b],miq=MAX;
        for(int i=0;i<a;i++){
          cin>>p[i];mip=min(mip,p[i]);
        }
       for(int i=0;i<b;i++){
         cin>>q[i];miq=min(miq,q[i]);
       }
       int ans=miq+mip;
       int x,y,c;
       for(int i=0;i<m;i++){
         cin>>x>>y>>c;x--;y--;
         ans=min(ans,p[x]+q[y]-c);
       }
       cout<<ans;

        


      }


        


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

using namespace std;

int main()
{

    int n,q;
    long long S[1000000], T;
    cin >> n;
    for(int i = 0; i<n;i++)
        cin >> S[i];
    cin >> q;

    int count =0;

        for(int j = 0;j<q;j++)
           {
               cin >> T;
               int left = 0;
               int right = n;
               int mid= (left +right)/2;
               while(left <right)
                   {
                       mid= (left +right)/2;
                    if (T== S[mid])
                        {
                            count++;
                            break;
                        }
                   if(T > S[mid])
                        {
                            left = mid +1;
                        }
                    else if(T<S[mid])
                        {
                            right = mid;
                        }
                   }
           }
    cout << count <<endl;
    return 0;
}



Measured memory_bytes: 3776
import time

t0 = time.clock()

N = int(input())
mat = []
for i in range(N):
    mat.append(list(map(lambda x:int(x)-1, input().split())))

ind = [0 for i in range(N)]
days = 0
while True:
    if time.clock() - t0 > 1:
        print(N * (N - 1) // 2)
        quit()
        
    madeMatch = False
    
    played = [False for i in range(N)]
    for i in range(N):
        if ind[i] == N-1 or played[i]: continue
        playAgainst = mat[i][ind[i]]
        if mat[playAgainst][ind[playAgainst]] == i and not played[playAgainst]:
            madeMatch = True
            played[i] = True
            played[playAgainst] = True

            ind[playAgainst] += 1
            ind[i] += 1
    if not madeMatch: break
    days += 1
    
if all(x == N-1 for x in ind):
    print(days)
else:
    print(-1)


Measured memory_bytes: 56536
// B - 105
// https://abc106.contest.atcoder.jp/tasks/abc106_b

import scala.io.StdIn.readLine

object Main extends App {

  val n = readLine.toInt

  def countDivisors(num: Int): Int = {
    (1 to num).filter(num % _ == 0).length
  }

  val count = (1 to n).filter(_ % 2 == 1).filter(countDivisors(_) == 8).length

  println(count)

}

Measured memory_bytes: 25424
#include<stdio.h>
int main(){
int max=0,n,k,i,j,a[100010],dp[3][100010],z[100010];
while(1){
scanf("%d %d\n",&n,&k);
if(n==0 && k==0){
break;
}
for(i=0;i<k;i++){
scanf("%d\n",&a[i]);
}
for(i=0;i<=n;i++){
z[i]=0;
}
for(i=0;i<k;i++){
z[a[i]]=1;
}
for(i=0;i<3;i++){
for(j=0;j<=n;j++){
dp[i][j]=0;
}
}
dp[0][0]=0,dp[1][0]=0;
for(i=1;i<=n;i++){
if(z[i]==0){
dp[0][i]=0;
}
else{
dp[0][i]=dp[0][i-1]+1;
}
}
if(z[0]==1){
for(i=1;i<=n;i++){
if(dp[0][i]==0){
dp[1][i]=dp[0][i-1]+1;
}
else{
dp[1][i]=dp[1][i-1]+1;
}
}
}
for(i=0;i<=1;i++){
for(j=0;j<=n;j++){
if(dp[i][j]>max){
max=dp[i][j];
}
}
}
printf("%d\n",max);
max=0;
}
return 0;
}


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			String text = sc.nextLine();
			char[] a = new char[text.length()];
			int[] b = new int[text.length()];
			for (int i = 0; i < text.length(); i++) {
				a[i] = text.charAt(i);
				b[i] = (int) a[i];
				if (b[i] >= 97 && b[i] < 123) {
					b[i] = b[i] - 32;
				} else if (b[i] <= 90 && b[i] > 64) {
					b[i] = b[i] + 32;
				}
				a[i] = (char) b[i];
			}
			System.out.println(a);
		
	}
}


Measured memory_bytes: 26020
import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] a = new int[N]; 
        
        for(int i=0; i<N; i++){
            
            a[i] = 1;
            
        }
        
        for(int i=0; i<K; i++){
            
            int d = scanner.nextInt();
            
            for(int j=0; j<d; j++){
                
                int A = scanner.nextInt();
                int X = A-1;
                
                a[X] = 0; 
                
            }
            
        }
        
        int Sum = 0;
        
        for(int i=0; i<N; i++){
            
            Sum += a[i];
            
        }
        
        System.out.println(Sum);
        
    }
}


Measured memory_bytes: 46156
#include <cstring>
#include <iostream>
#include <utility>

using namespace std;

int n, ncities;
int cities[10][10];

pair<int, int> solve()
{
    for (int k = 0; k <= ncities; ++k)
    {
        for (int i = 0; i <= ncities; ++i)
        {
            for (int j = 0; j <= ncities; ++j)
            {
                cities[i][j] = min(cities[i][j], cities[i][k] + cities[k][j]);
            }
        }
    }
    pair<int, int> result;
    result.second = 1000000000;
    for (int i = 0; i <= ncities; ++i)
    {
        int total = 0;
        for (int j = 0; j <= ncities; ++j)
        {
            total += cities[i][j];
        }
        if (total < result.second)
        {
            result.first = i;
            result.second = total;
        }
    }
    return result;
}

int main()
{
    while (cin >> n, n > 0)
    {
        ncities = -1;
        memset(cities, 0x3f, sizeof cities);
        int a, b, c;
        for (int i = 0; i < n; ++i)
        {
            cin >> a >> b >> c;
            cities[a][b] = cities[b][a] = c;
            ncities = max(ncities, max(a, b));
        }
        for (int i = 0; i <= ncities; ++i)
        {
            cities[i][i] = 0;
        }
        pair<int, int> result = solve();
        cout << result.first << " " << result.second << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
s = input()
for i in range(len(s)):
  if i & 1 == 0:
    if s[i] != 'h':
      break
  else:
    if s[i] != 'i':
      break
else:
  if len(s) & 1 == 0:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    string s; cin >> s;
    ll k; cin >> k;
    ll cnt = 0;
    if(s[0] != '1') cout << s[0] << endl;
    else{
        bool flag = true;
        REP(i, s.size()){
            if(s[i] == '1' && flag == true) cnt++;
            else flag = false;
        }
        //cout << cnt << endl;
        if(k <= cnt) cout << 1 << endl;
        else cout << s[cnt] << endl;
    }
}

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

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>str;
    rep(i,str.length()){
        char c=str[i];
        sum+=(ll)c-48;
    }
    //cout<<sum<<endl;
    if(sum%9==0) Yes;
    else No;


    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
void YesNo(bool x) {
    if (x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    int N, X, T; cin >> N >> X >> T;
    if (N%X) cout << (N/X+1)*T << endl;
    else cout << N/X*T << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
	char S[200100];
	scanf ("%s", S);
	int s = 0;
	for (int i = 0; S[i]; i++) s += S[i] - '0';
	puts(s % 9 == 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int l[50];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n) cin>>l[i];
    sort(l,l+n,greater<int>());
    int sum=0;
    rep(i,k) sum+=l[i];
    cout<<sum<<endl;
    return 0;
}

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

int main()
{
    int num;
    scanf("%d",&num);
    int box[100010];
    for(int i=1;i<=num;i++){
        scanf("%d",&box[i]);
    }
    int count = 0, current = 1;
    for(int i=1;i<=num;i++){
        current = box[current];
        count ++;
        if(current == 2){
            printf("%d\n",count);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

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

using namespace std;

#define FOR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){

    string s;
    cin >> s; 

    int ss = s.length();
    int a = 0, b = 0;
    FOR(i, 0, ss){
        if(s[i] == '0')
            a++;
        else 
            b++;
    }

    cout << 2*min(a,b);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  long count = 1;
  char a, b;
  cin >> a;
  for(int i = 1; i < N; i++){
    cin >> b;
    if(a != b){
      count++;
      a = b;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 163 -B
//#define MAX 11
#define MAX 101
static int f[MAX+1];
int main(void) {
	int i, x, n, p[MAX];

	scanf("%d %d", &x, &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		f[p[i]] = 1;
	}

	int min = 1000,ans,t;

	for (i = 0; i <= MAX; i++) {
		if (f[i])continue;
		t=abs(x - i);
		if (t < min) {
			min = t; ans = i;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  cout<<(100*N+1800*M)*pow(2, M)<<endl;
}



Measured memory_bytes: 4108
# use faster method than input()
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def manhattan(pos1, pos2):
    return abs(pos1[0]-pos2[0]) + abs(pos2[1]-pos1[1])


H, W, D = map(int, input().split())
A = [(0, 0)]*(H*W)
for r in range(H):
    l = list(map(int, input().split()))
    for c in range(W):
        A[l[c]-1] = (r, c)

dist = [0]*(H*W)
for i in range(D, H*W):
    dist[i] = dist[i-D]+manhattan(A[i], A[i-D])


Q = int(input())
L = []

ans_list = [0]*Q
for i in range(Q):
    ans = 0
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ans = dist[b]-dist[a]
    ans_list[i] = ans

for ans in ans_list:
    print(ans)


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

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

int main()
{
	int K,ans=0;
	cin >> K;
	for(int i=1;i <= K;i++)
		for(int j=1;j <= K;j++)
			for(int k=1;k <= K;k++)
				ans += gcd(gcd(i,j),k);
	cout << ans << endl;
	return 0;	
} 

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

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

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll sum=0,n;
    cin>>n;
    vec<ll> a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ave=sum/n,ans=0;
    if(sum%n==0){
        rep(i,n) ans+=(ave-a[i])*(ave-a[i]);
    }else{
        ll mini=INF;
        for(ll i=-1;i<=1;i++){
            ll num=0;
            rep(j,n) num+=(ave+i-a[j])*(ave+i-a[j]);
            mini=min(mini,num);
        }
        ans=mini;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double x1 = double.Parse(input[0]);
            double y1 = double.Parse(input[1]);
            double x2 = double.Parse(input[2]);
            double y2 = double.Parse(input[3]);
            double ans = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9492
#include <bits/stdc++.h>
using namespace std;
int main(){
	int R,G,B,N,S,T,U,answer;
  
  double Z,X;
  answer =0;
  	cin >> R >> G >> B >> N;
    S = N/R;
  //cout << S << endl;
  	for(int i=0;i<S+1;i++){
      T = N-R*i;
      U = T/G;
     // cout << T << U << endl;
      for(int k=0;k<U+1;k++){
        X =T-G*k;
        Z=X/B;
        if(ceil(Z)== floor(Z)){
          if(Z>=0){
          answer++;
          }
        }
        else{continue;}
    }
    }
  cout << answer << endl;
}

Measured memory_bytes: 256
using System;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            for(; ; ) {
                var array = Console.ReadLine().Split(' ');
                if (array[1] == "?") break;
                Console.WriteLine(Calc(array));
            }
        }

        static int Calc(string[] array)
        {
            int a = int.Parse(array[0]); int b = int.Parse(array[2]);
            string op = array[1];
            int result = 0;
            switch (op)
            {
                case "+":
                    result = a + b;
                    break;
                case "-":
                    result = a - b;
                    break;
                case "*":
                    result = a * b;
                    break;
                case "/":
                    result = a / b;
                    break;
            }
            return result;
        }
    }
}



Measured memory_bytes: 9164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        string[] s=new string[N];
        int ans=0;
        int Aend=0;
        int Bstart=0;
        int BA=0;
        for(int i=0;i<N;i++)
        {
          s[i]=cin.next();
          int n=s[i].Length;
          if(s[i][0]=='B'&&s[i][n-1]=='A')BA++;
          else if(s[i][0]=='B')Bstart++;
          else if(s[i][n-1]=='A')Aend++;
          for(int j=0;j<n-1;j++)
          {
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
          }
        }
        if(Aend+Bstart==0&&BA>0)ans+=(BA-1);
        else ans+=BA+Math.Min(Aend,Bstart);

        Console.WriteLine(ans);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


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

template<typename T>
ostream& operator << (ostream &out, vector<T> &v) {
	for (auto ele : v) out << ele << " ";
	out << '\n';
	return out;
}

bool search(int l, int r, int j, vector<int> &z) {
	while (l <= r) {
		int m = (l + r)/2;
		if (z[m] == j) {
			return true;
			break;
		} else if (z[m] < j) l = m + 1;
		else r = m - 1;
	}
	return false;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> z(n);
	for (int i = 0; i < n; i++) cin >> z[i];
	
	sort(z.begin(), z.end());
	int ans{};
	for (int i = 0; i < n; i++) {
		bool ok = (i != n ? z[i + 1] != z[i] : 1);
		for (int j = 1; j*j <= z[i]; j++) {
			if (!ok) break;
			if (z[i]%j == 0) {
//				cout << z[i] << " " << j << endl;
				if (search(0, i - 1, j, z) || search(0, i - 1, z[i]/j, z)) ok = 0;
			}
		}
		if (ok) {
			ans++;
//			cout << "OK\n";
		}
//		cout << endl;
	}
	cout << ans;
}

Measured memory_bytes: 3992
import sys
input = sys.stdin.readline
S = input()
odd_list = []
even_list = []
for i in range(len(S)-1):
    if i%2!=0:
        even_list.append(S[i])
    else:
        odd_list.append(S[i])
# print(odd_list)
# print(even_list)
if "L" in odd_list:
    print("No")
elif "R" in even_list:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
S = input()

if S == ('Sunny'):
    print('Cloudy')
elif S == ('Cloudy'):
    print('Rainy')
elif S == ('Rainy'):
    print('Sunny')
else:
    print('入力に誤りがあります。Sunny,Cloudy,Rainyのいずれかを入力してください。')


Measured memory_bytes: 9036
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int Min(int a, int b) {
	if (a < b)return a;
	else return b;
}
int main(void)
{
	int n, b[99], ans = 0;

	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", &b[i]);
	}
	ans += b[0] + b[n - 2];
	for (int i = 0; i < n - 2; i++) {
		ans += Min(b[i], b[i + 1]);
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int P[N];
    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }
    int current_min = INT_MAX;
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (P[i] <= current_min)
            count++;
        current_min = min(current_min, P[i]);
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a+b+1)/2 << endl;
}

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

using namespace std;
#define ll long long 

int main() 
{
    ll k ;
    cin>>k;
    ll a,b;
    cin>>a>>b;
    bool ans=false;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            ans=true;
            break;
        }
    }
    if(ans)
    cout<<"OK"<<endl;
    else
    cout<<"NG"<<endl;
    


}

Measured memory_bytes: 3636
a=int(input())
array2019=[]
array_num=[]
array2019+=map(int,input().split(" ",a-1))
b=int(input())
array_num+=map(int,input().split(" ",b-1))

for n in array_num:
    if array2019[n-1]+1 in array2019 or array2019[n-1]==2019:
        pass
    else:array2019[n-1]+=1

for m in array2019:
    print(m)


Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int x, a;
    cin >> x >> a;
    if (x < a){
        cout << 0;
    }
    else{
        cout << 10;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int  main(){
int N;
  cin>>N;
ll count=0;
int max=0;
int max2=0;
vector<int>data(N);
for(int i=0; i<N; i++){
    cin>>data.at(i);
    if(max<data.at(i)){
        max=data.at(i);
    }
    else if(max2<data.at(i)){
        max2=data.at(i);
    }
}
for(int i=0; i<N; i++){
if(data.at(i)==max){
    cout<<max2<<endl;
}
else
{
cout<<max<<endl;
}

}
}


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

vector<int> rt[11];

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,m) {
      int k;
      cin >> k;
      rep(j,k) {
        int s;
        cin >> s;
        rt[i].push_back(s);
      }
    }
    vector<int> t(m);
    rep(i,m) cin >> t[i];
    int ans = 0;
    rep(is, 1<<n) {
      bool flag = true;
      rep(i,m) {
        int l = 0;
        for (int x : rt[i]) {
          x--;
          l ^= is>>x&1;
        }
        if (l != t[i]) flag = false;
      }
      if (flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

string S;

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

  cin >> S;

  ll ans = 0, numW = 0;
  for (int i = 0; i < S.length(); ++i) {
    if (S[i] == 'W') ++numW;
  }

  for (int i = 0; i < S.length(); ++i) {
    if (S[i] == 'W') {
      --numW;
    } else {
      ans += numW;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1336
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    string s,ans;
    cin >> s;
    int cnt = 0;
    rep(i,s.size()){
        if(i == 0){
            if(s[i] != 'A'){
                cout << "WA";
                exit(0);
                }
            }
        else if(isupper(s[i])){
            if(i == 1 || i == s.size()-1 || s[i] != 'C'){
                cout << "WA";
                exit(0);
            }
            cnt++;
        }
    }
    if(cnt != 1){cout << "WA";exit(0);}
    cout << "AC";
}

Measured memory_bytes: 256