akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

ll M;

void dfs1(int s, int prev, vector<vector<int>>& graph, vector<ll>& dp) {
    for(auto next: graph[s]) {
        if(next != prev) {
            dfs1(next, s, graph, dp);
            dp[s] = (dp[s]*(dp[next] + 1)) % M;
        }
    }
}

void dfs2(int s, int prev, vector<vector<int>>& graph, vector<ll>& dp, vector<ll>& ans, ll prev_comb) {
    vector<ll> values;
    vector<int> edges;
    for(auto next: graph[s]) {
        if(next != prev) {
            values.push_back(dp[next]);
            edges.push_back(next);
        }
    }

    int size = values.size();
    if(size == 0) return;

    vector<ll> prod_forward(size+2, 1), prod_backward(size+2, 1);
    for(int i=1; i<=size; i++) {
        prod_forward[i] = (1+values[i-1]) % M ;
        prod_forward[i] = (prod_forward[i] * prod_forward[i-1]) % M;
        prod_backward[size-i+1] = (1+values[size-i]) % M;
        prod_backward[size-i+1] = (prod_backward[size-i+1] * prod_backward[size-i+2]) % M;
    }

    for(int i=1; i<=size; i++) {
        ll tmp = prev_comb;
        tmp = (tmp * prod_forward[i-1]) % M;
        tmp = ((tmp*prod_backward[i+1])%M + 1) % M;
        ans[edges[i-1]] = (tmp * values[i-1]) % M;
        dfs2(edges[i-1], s, graph, dp, ans, tmp);
    }
}

int main() {
    int N;
    cin >> N >> M;
    vector<vector<int>> graph(N, vector<int>());

    for(int i=0; i<N-1; i++) {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--; tmp2--;
        graph[tmp1].push_back(tmp2);
        graph[tmp2].push_back(tmp1);
    }

    vector<ll> dp(N, 1); // dp[i]: iをルートとする部分木の塗り方
    vector<ll> ans(N);

    dfs1(0, -1, graph, dp);
    // cerr << "dp: " << endl;
    // for(auto x: dp) cerr << x << endl;

    ans[0] = dp[0];
    dfs2(0, -1, graph, dp, ans, 1);
    // cerr << "ans" << endl;
    for(auto x: ans) cout << x << endl;
    return 0;
}

Measured memory_bytes: 29952
#include <stdio.h>


int solve(int a, int b) {
    if (a < 10 && b < 10) {
        return a * b;
    } else {
        return -1;
    }
}


int main () {
    int a, b;

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

}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Main{
  static int n, a, b;
  static long[] v;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    a = sc.nextInt();
    b = sc.nextInt();
    v = new long[n];
    for(int i = 0; i < n; i++){
      v[i] = sc.nextLong();
    }

    Arrays.sort(v);
    long[] rv = new long[n];
    for(int i = 0; i < n; i++){
      rv[i] = v[n - i - 1];
    }
    long sum = 0;
    for(int i = 0; i < a; i++){
      sum += rv[i];
    }
    double max = (double)sum / (double)a;

    long[][] dp = new long[n + 1][n + 1];
    for(int i = 1; i <= n; i++){
      for(int j = 0; j <= n; j++){
        if(j == 0 || i == j){
          dp[i][j] = 1;
        }
        else{
          dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
        }
      }
    }

    long count = 0;
    if(rv[0] != rv[a - 1]){
      int c = 0, d = 0;
      for(int i = 0; i < n; i++){
        if(rv[a - 1] == rv[i]){
          ++c;
        }
      }
      for(int i = 0; i < a; i++){
        if(rv[a - 1] == rv[i]){
          ++d;
        }
      }
      count += dp[c][d];
    }
    else{
      int c = 0;
      for(int i = 0; i < n; i++){
        if(rv[0] == rv[i]){
          ++c;
        }
      }
      for(int i = a; i <= b; i++){
        if(i <= c){
          count += dp[c][i];
        }
      }
    }

    System.out.println(max);
    System.out.println(count);
  }
}


Measured memory_bytes: 22996
#include<stdio.h>

int main(void)
{
	int a,b,d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	
	d=a/b;
	r=a%b;
	f=(double)a/b;
	
	printf("%d %d %.5f\n",d,r,f);
	
	return 0;
}



Measured memory_bytes: 2116
n,m = map(int, input().split())
lst = [[] for _ in range(n)]

for i in range(m):
    p,y = map(int, input().split())
    lst[p-1].append((y,i))

ans = [None]*m

for i,d in enumerate(lst):
    d.sort()
    for j, (Y,I) in enumerate(d):
        ans[I] = str(i+1).zfill(6) + str(j+1).zfill(6)

for i in ans:
    print(i)


Measured memory_bytes: 35944
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
        int a,b,c;cin>>a>>b>>c;
        cout<<a+b+c-max({a,b,c});
    }
    


Measured memory_bytes: 256
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define s(x) x.size()

using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;
int pref[200];

void solve(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++){
		int x; cin >> x;
		pref[i] = pref[i-1]+x;
	}
	int mins = 1e6;
	for(int i = 1; i < n; i++){
		int lefts = pref[i];
		int rights = pref[n]-pref[i];
		if(abs(lefts-rights) < mins)
		mins = abs(lefts-rights);
	}
	cout << mins << endl;
}	

int main(){ 
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}


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

int main(){
    long long n;
    cin>>n;
    long long a[n+1],b[n+1],c=0;
    for(int i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]) c++;
    }
    if(c>2)
    cout<<"NO";
    else
    cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,maxi=0,f=0,mini=INF;
    double sum=0;
    string str,sub;
    cin>>a>>b>>str;
  	str[b-1]=str[b-1]+'a'-'A';
      cout<<str<<endl;
    return 0;
}

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

using namespace std;
typedef tuple<int, int, int> int3;

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

  int r[110][110] = {};
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--;
    if (c > d) r[a][b] = 1, r[b][a] = -1;
    else if (c < d) r[a][b] = -1, r[b][a] = 1;
  }

  vector<int> p(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      if (r[i][j] > 0) p[i] += 3;
      else if (r[i][j] == 0) p[i] += 1;
    }
  }

  vector<int> p2 = p;
  sort(p2.begin(), p2.end(), greater<int>());
  
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    mp[p2[i]] = lower_bound(p2.begin(), p2.end(), p2[i], greater<int>()) - p2.begin() + 1;
  }

  for (int i = 0; i < n; i++) {
    cout << mp[p[i]] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
    int a=inputValue();
    int b=inputValue();
    int min = 0;
    if(a<b){
        for(int i=0;i<b;i++){
            cout << a;
        }
    }else{
        for(int i=0;i<a;i++){
            cout << b;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  a, b = map(int, input().split())
  if b <= 1:
    print(0)
  elif a >= b:
    print(1)
  else:
    print(math.ceil((b-a)/(a-1))+1)
  return 0
 
if __name__ == "__main__":
  solve()

Measured memory_bytes: 15372
a=input().split()
A=int(a[0])
B=int(a[1])
S=input()
S=list(S)

t=1

for i in range(A):
 if(S[i]=="-"):
  t=0

if(S[A] != "-"):
  t=0

for i in range(A+B):
 if(i>A):
  if(S[i]=="-"):
   t=0

if(t==1):
 print("Yes")
else:
 print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  int X,Y;
	      	  cin >> X >> Y;
	      	  if(X%Y==0) cout << -1 << endl;
	      	  else cout << X << endl;

	          return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1145141919;
const long long INFL = 1LL<<60;
 
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
 
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
 
int dp[3*1100][3*1100] = {};
int main()
{
	string s,t;
	cin >> s >> t;
	s = "@" + s;
	t = "@" + t;
	for (int i = 1; i < s.size(); ++i)
	{
		for (int j = 1; j < t.size(); ++j)
		{
			if(s[i] == t[j])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	int len = dp[s.size() - 1][t.size() - 1];
	int i = s.size() - 1;
	int j = t.size() - 1;
	string ans;
	while(len > 0)
	{
		if(s[i] == t[j])
		{
			ans += s[i];
			--i;
			--j;
			--len;
		}
		else if(dp[i][j] == dp[i-1][j])
		{
			--i;
		}
		else
		{
			--j;
		}
	}
	for (int i = 0; i < ans.size(); ++i)
	{
		cout << ans[ans.size() - 1 - i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 39168
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(){
    int n,m,h,k;
    for(;;){
        scanf("%d%d%d%d",&n,&m,&h,&k);
        if(n==0&&m==0&&h==0&&k==0)break;
        vector<int> scs(n);
        for(int i=0;i<n;i++)scanf("%d",&scs[i]);
        vector<vector<bool> > right(n-1,vector<bool>(h,false));
        for(int i=0;i<m;i++){
            int a,b;
            scanf("%d%d",&a,&b);
            right[a-1][b]=true;
        }
        vector<P> toris;
        vector<int> nown,prev(n);
        for(int i=0;i<n;i++)prev[i]=i;
        for(int i=1;i<h;i++){
            nown=vector<int>(n,-1);
            for(int j=0;j<n-1;j++){
                if(right[j][i]){
                    nown[j]=prev[j+1];
                    nown[j+1]=prev[j];
                    toris.push_back(P(nown[j],nown[j+1]));
                }
            }
            for(int j=0;j<n;j++)if(nown[j]==-1)nown[j]=prev[j];
            prev=nown;
        }
        int nor=0;
        vector<int> ftol(n);
        for(int i=0;i<n;i++){
            if(nown[i]<k)nor+=scs[i];
            ftol[nown[i]]=i;
        }
        int mi=nor;
        for(int i=0;i<toris.size();i++){
            int a=toris[i].first,b=toris[i].second;
            if(a<k&&b>=k)mi=min(mi,nor-(scs[ftol[a]]-scs[ftol[b]]));
            if(a>=k&&b<k)mi=min(mi,nor-(scs[ftol[b]]-scs[ftol[a]]));
        }
        printf("%d\n",mi);
    }
}

Measured memory_bytes: 972
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		String s = sc.next();
        String t = "No";
        if(s.charAt(0)==s.charAt(1))
        {if(s.charAt(2)==s.charAt(3) && s.charAt(0)!=s.charAt(2)){t = "Yes";}}
		 if(s.charAt(0)==s.charAt(2))
        {if(s.charAt(1)==s.charAt(3) && s.charAt(0)!=s.charAt(1)){t = "Yes";}}
         if(s.charAt(0)==s.charAt(3))
        {if(s.charAt(1)==s.charAt(2) && s.charAt(0)!=s.charAt(1)){t = "Yes";}}  
            System.out.println(t);
	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const ll INF = 1ll << 60;
const double EPS = 1e-8;
const int MOD = 1000000007;

int T, n, m;
ll W;
vector<vi> g;

int dfs(vi &log, int u, int p = -1) {
    log.push_back(u);
    for(int v : g[u]) {
        if(v != p) {
            return dfs(log, v, u);
        }
    }
    return u;
}

vi construct(const vi &log) {
    vi ans;
    int cur = 0;
    REP(i, log.size()) {
        int u = log[i];
        int p = cur ++;
        for (int v: g[u]) {
            if(i && v == log[i-1]) continue;
            if(i + 1 < log.size() && v == log[i+1]) continue;
            ans.push_back(cur ++);
        }
        ans.push_back(p);
    }
    return ans;
}

int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    REP(i, n-1) {
        int u, v;
        cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    REP(i, n) {
        sort(RALL(g[i]), [&](int u, int v) {
            return g[u].size() < g[v].size();
        });
    }
    vi log;
    int u = dfs(log, 0);
    log.clear();
    dfs(log, u);
    auto ans = construct(log);
    reverse(ALL(log));
    ans = min(ans, construct(log));
    if (ans.size() != n) cout << -1 << endl;
    else {
        REP(i, n) cout << ans[i] + 1 << " \n"[i+1 == n];
    }
    return 0;
}

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

int main(){
    while(1){
        int M,T,P,R;
        cin>>M>>T>>P>>R;

        if(M==0&&T==0&&P==0&&R==0){
            break;
        }

        int CP[50],TT[50],PT[50][10];
        for(int i=0;i<T;i++){
            CP[i]=TT[i]=0;
            for(int j=0;j<P;j++){
                PT[i][j] = 0;
            }
        }

        for(int i=0;i<R;i++){
            int m,t,p,j;
            cin>>m>>t>>p>>j;

            if(j==0){
                CP[t-1]++;
                TT[t-1]+=(m+PT[t-1][p-1]);
            }
            else{
                PT[t-1][p-1]+=20;
            }
        }

        int tnow,tpre=-1;
        bool flg[50];
        for(int i=0;i<T;i++)
            flg[i]=0;

        for(int i=0;i<T;i++){
            tnow=-1;
            for(int j=0;j<T;j++){
                if(flg[j]){
                    continue;
                }

                if(tnow==-1){
                    tnow=j;
                }
                else{
                    if(CP[j]>CP[tnow]||(CP[j]==CP[tnow]&&TT[j]<=TT[tnow])){
                        tnow=j;
                    }
                }
            }

            if(tpre!=-1){
                if(CP[tnow]==CP[tpre]&&TT[tnow]==TT[tpre]){
                    cout << '=';
                }
                else{
                    cout << ',';
                }
            }
            cout<<tnow+1;

            flg[tnow]=1;
            tpre=tnow;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3108
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    S=input()
    n=len(S)

    def check(k):
        if(n-k>=k): return True
        else: return len(set(S[n-k:k]))==1

    print(bisection(1,n,check))
resolve()

Measured memory_bytes: 73500
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
using namespace std;
int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int y = abs(a - x);
    int z = abs(b - x);
    if (y < z)
        cout << "A";
    else
        cout << "B";


    return 0;
}


Measured memory_bytes: 3644
n = gets.to_i

arr = [[0,0,0]]
n.times do
  t, x, y = gets.split.map(&:to_i)
  arr << [t,x,y]
end
puts arr.each_cons(2).all? { |((t1, x1, y1), (t2, x2, y2))|
  dt = t2 - t1
  dx = (x2 - x1).abs
  dy = (y2 - y1).abs
  dx + dy <= dt && (dx + dy) % 2 == dt % 2
} ? 'Yes' : 'No'


Measured memory_bytes: 9468
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
using namespace std;

vector<pair<int, int> > rem;
int win[9];
int lose[9];
int half;

int solve(int n){
	if(n == 0) return 1;
	int x = rem[n].first;
	int y = rem[n].second;
	int ret = 0;
	for(int d=0; d<2; d++){
		if(win[x] < half && lose[y] < half){
			win[x]++;
			lose[y]++;
			ret += solve(n-1);
			win[x]--;
			lose[y]--;
		}
		swap(x, y);
	}
	return ret;
} 

int main(){
	while(1){
		int n,m;
		cin >> n;
		if(n == 0) break;
		cin >> m;
		int used[9][9] = {};
		fill(win, win+n, 0);
		fill(lose, lose+n, 0);
		half = (n-1)/2;

		for(int i=0; i<m; i++){
			int x,y;
			cin >> x >> y;
			x--; y--;
			win[x]++;
			lose[y]++;
			used[x][y] = used[y][x] = 1;
		}
		bool ng = false;
		for(int i=0; i<n; i++){
			if(win[i] > half || lose[i] > half){
				ng = true;
				break;
			}
		}
		if(ng){
			cout << 0 << endl;
			continue;
		}
		
		rem = vector<pair<int, int> >();
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				if(used[i][j] == 0) rem.emplace_back(i, j);
			}
		}
		cout << solve(rem.size()-1) << endl;
	}
    return 0;
}


Measured memory_bytes: 3076
from copy import copy
n = int(input())
p = list(map(int, input().split()))
q = sorted(p)
ret = 'NO'
for i in range(n-1):
    for j in range(i, n):
        r = copy(p)
        r[i] = p[j]
        r[j] = p[i]
        if q == r:
            ret = 'YES'
            break
print(ret)

Measured memory_bytes: 71676
s=list(str(input()))
tmp=0
for i in range(0,len(s)):
            if i%2==0 and s[i]=='L':
                        tmp+=1
            if i%2!=0 and s[i]=='R':
                        tmp+=1
if tmp>=1:
            print('No')
if tmp==0:
            print('Yes')
                     
                        
                        

          

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());
	cout << v[0] << " " << v[1] << " " << v[2] << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
   
int main() {
          int A;
          int B;
          scanf("%d %d", &A, &B);
          
          
  if(A % 3 ==0 || B % 3 == 0 || (A + B) % 3 ==0){
  printf("Possible ");
  } else {
  printf("Impossible ");
  } 
  return 0;  


}

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

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t=sc.next();
		int count=0;
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)!=t.charAt(i)){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 41288
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        String l1Input = s.nextLine();
        String l2Input = s.nextLine();
        String[] l1 = l1Input.split(" ");
        String[] l2 = l2Input.split(" ");

        if (i(l2[0]) == i(l1[0])) {
            System.out.println(0);
        } else {
            if (i(l2[1]) == 1) {
                System.out.println(1);
            } else {
                System.out.println(0);
            }
        }
    }

    private static Integer i(String s) {
        return Integer.valueOf(s);
    }
}


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

using LL = long long;
using LD = long double;
 
LL mod = 998244353;

int main()
{
	LL l;
	cin >> l;
	LD lll = l/(LD)(3.0);

	cout << fixed << setprecision(10) << lll*lll*lll << "\n";


}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  string S;
  cin>>S;

  int ans=0;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C') ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
a,b = map(int, input().split())
ls = [b*10+i for i in [0,1,2,3,4,5,6,7,8,9]]
t = 0
for x in ls:
    if a == math.floor(x*8/100):
        print(x)
        break
    else:
        t += 1
        
if t == 10:
    print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll unsigned long long
#define int long long
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define a first
#define b second

int n;
vi dp(11000, -1);
vii arr(1100);

int f(int health){
    if(health <= 0){
        return 0;
    }

    if(~dp[health]) return dp[health];

    int ans = INT_MAX;
    forn(i, n){
        ans = min(ans, arr[i].b + f(health - arr[i].a));
    }
    return dp[health] = ans;
}
 
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int h;
    cin >> h >> n;
    forn(i, n){
        cin >> arr[i].a >> arr[i].b;
    }
    cout << f(h) << endl;    

    return 0;
}

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

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

  int64_t ans = 0;

  for(int i=0;i<=9;i++){//1000通りの暗証番号を試す
    for(int j=0;j<=9;j++){
      for(int k=0;k<=9;k++){
        bool a=false,b=false,c=false;//1桁目、2桁目、3桁目があったかどうか
        for(int x=0;x<S.size();x++){
          if(S[x]==(char)('0'+i)&&!a){a=true; continue;}//一桁目の数字を初めて見つけたとき。continueがないとi==jの時とかにおかしくなる
          if(S[x]==(char)('0'+j)&&a&&!b){b=true; continue;}//二桁目の数字を初めて見つけたとき。同上
          if(S[x]==(char)('0'+k)&&b&&!c) c=true;
        }
        if(c) ans++;//cがtrueなら、a~cはすべてtrue
      }
    }
  }

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

Measured memory_bytes: 256
import itertools
import math

def combinations_count(n, r):
    return 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = list(map(int, input().strip().split()))
# NC2 + MC2
print(combinations_count(N, 2) + combinations_count(M, 2))

Measured memory_bytes: 3060
N = int(input())
As = [int(input()) for _ in range(N)]

Bs = sorted(As)
maxA2, maxA = Bs[-2:]

anss = []
for A in As:
    if A == maxA:
        anss.append(maxA2)
    else:
        anss.append(maxA)

print('\n'.join(map(str, anss)))


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

signed main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;

    vector<int> cnt(S.size());
    for (int i = 1; i < S.size(); i++) {
        cnt[i] += cnt[i - 1];
        cnt[i] += (S[i - 1] == 'A' && S[i] == 'C');
    }

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        cout << cnt[r] - cnt[l] << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
string s;
int x,a;
int main()
{
    cin>>s;
    for (int i=1;i<s.size();i++)
    {
        if (s[i]=='9')
            a++;
    }
    if (a==s.size()-1)
    {
        for (int i=0;i<s.size();i++)
            x+=int (s[i])-48;
        cout<<x;
        return 0;
    }
    x+=9*(s.size()-1);
    x+=int (s[0])-49;
    cout<<x;
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int N;
int ans=0;
cin >> N;
if(N<=104)ans=0;
else if(N<=134)ans=1;
else if(N<=164)ans=2;
else if(N<=188)ans=3;
else if(N<=194)ans=4;
else ans=5;
cout << ans;
}

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

using ll = long long;

int main() {
    ll m, n, ans = 1, MOD = 1e9 + 7;
    cin >> m >> n;
    while (n > 0) {
        if (n & 1) ans = (ans * m) % MOD;
        n /= 2;
        m = (m * m) % MOD;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;



int main() {
	int a, b;
	cin >> a >> b;
	if (a < 9 && b < 9) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

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

using namespace std;

char c[101][101];

int main(){
    int a, b;
    cin >> a >> b;
    a--, b--;
    for (int i = 1; i <= 50; i++)
        for (int j = 1; j <= 100; j++) c[i][j] = '#';
    for (int i = 51; i <= 100; i++)
        for (int j = 1; j <= 100; j++) c[i][j] = '.';
    for (int i = 1; i <= 50 && a; i += 2)
        for (int j = 1; j <= 100 && a; j += 2) 
            c[i][j] = '.', a--;
    for (int i = 100; i > 50 && b; i -= 2)
        for (int j = 1; j <= 100 && b; j += 2) 
            c[i][j] = '#', b--;
    cout << "100 100" << endl;
    for (int i = 1; i <= 100; i++, cout << endl)
        for (int j = 1; j <= 100; j++) cout << c[i][j];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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; }

int h, w;

int main() {
    while(1) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        int len = w*w + h*h;
        int ans = 1e9;
        int ah = 200, aw = 200;
        int cah = 200, caw = 200;
        for(int i = 1; i <= 150; ++i) {
            for(int j = i+1; j <= 150; ++j) {
                int ch = i*i + j*j;
                if(len == ch) {
                    if(h < i && i < cah) {
                        ans = ch;
                        cah = i, caw = j;
                    }
                }else if(len < ch) {
                    if(ans == ch) {
                        if(ah > i) {
                            ans = ch;
                            ah = i, aw = j;
                        }
                    }else if(ans > ch) {
                        ans = ch;
                        ah = i, aw = j;
                    }
                }
            }
        }
        if(cah == 200 && caw == 200) cout << ah << " " << aw << endl;
        else cout << cah << " " << caw << endl;
    }
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout<<((a+b)%3==0||a%3==0|b%3==0?"Possible":"Impossible")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1e5 + 51;

int dp[N], xorv[N];
int dfs(int S) {
	if (dp[S]) return dp[S];
	int ret = __builtin_popcount(S) - 1;
	for (int T = (S - 1) & S; T; T = (T - 1) & S)
		if (!xorv[T]) ret = std::min(ret, dfs(T) + dfs(S ^ T));
	return dp[S] = ret;
}

int n, x, y, z, v[N], c[22], ans, msk;
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &x, &y, &z), x++, y++;
		x[v] ^= z, y[v] ^= z;
	}
	for (int i = 1; i <= n; i++) i[v][c]++;
	for (int i = 1; i <= 15; i++) {
		ans += i[c] / 2;
		msk |= (i[c] & 1) << (i - 1);
	}
	for (int S = 0; S < 32768; S++)
		for (int j = 1; j <= 15; j++)
			if ((S >> (j - 1)) & 1) xorv[S] ^= j;
	printf("%d", ans + (msk ? dfs(msk) : 0));
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
int main() {
	int w[4];
	for (int l1 = 0; l1 < 4; l1++)
		std::cin >> w[l1];
	if (w[0] + w[1] < w[2] + w[3])
		std::cout << "Right" << std::endl;
	else if (w[0] + w[1] > w[2] + w[3])
		std::cout << "Left" << std::endl;
	else
		std::cout << "Balanced" << std::endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var S = ReadLine();
            if (S.Length == 1)
            {
                WriteLine("YES");
                return;
            }
            if (S.Length == 2)
            {
                if (S[0] == S[1])
                    WriteLine("NO");
                else
                    WriteLine("YES");
                return;
            }
            var aNum = S.Count(s => s == 'a');
            var bNum = S.Count(s => s == 'b');
            var cNum = S.Count(s => s == 'c');
            var max = Max(Max(aNum, bNum), cNum);
            var min = Min(Min(aNum, bNum), cNum);
            if (max - min <= 1)
                WriteLine("YES");
            else
                WriteLine("NO");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut sum: i32 = 0;
    let mut line = String::new();
    stdin.read_line(&mut line).expect("");
    let n: u32 = line.trim().parse().unwrap();
    for _ in 0..n {
        line = String::new();
        stdin.read_line(&mut line).expect("");
        let n: Vec<&str> = line.split(' ').collect();
        let a = "1";
        let nums: Vec<i32> = line.split_whitespace().map(|s| s.parse::<i32>().unwrap()).collect();
        sum += 1 + nums[1] - nums[0];
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
(declaim (optimize (speed 3) (debug 0) (safety 0)))

(let ((a (read))
      (b (read))
      (k (read)))

  (defun small (p q &optional (acc nil))
    (if (= q 0)
      acc
      (small (1+ p) (1- q) (cons p acc))))


  (defun big (p q &optional (acc nil))
    (if (= q 0)
      acc
      (big (1- p) (1- q) (cons p acc))))


  (defun delete-small (p lst)
    (mapcar #'(lambda (x)
                (if (< x p)
                  p
                  x))
            lst))


  (defun delete-big (p lst)
    (mapcar #'(lambda (x)
                (if (> x p)
                  p
                  x))
            lst))


  (format t "~{~A~%~}"
          (sort (remove-duplicates (append (delete-big b (small a k))
                                           (delete-small a (big b k))))
                #'<)))


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

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int a[3];
        rep(i, 3){
            cin >> a[i];
        }
        sort(a, a+3);

        if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    // printf("%d\n", N);
    return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int cntAC=0;
	int cntRE=0;	
	int cntWA=0;
	int cntTLE=0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		if(s=="AC")
		{
			cntAC++;
		}
		if(s=="TLE")
		{
			cntTLE++;
		}
		if(s=="WA")
		{
			cntWA++;
		}
		if(s=="RE")
		{
			cntRE++;
		}
	}
	cout<<"AC x "<<cntAC<<endl;

	cout<<"WA x "<<cntWA<<endl;
	
	cout<<"TLE x "<<cntTLE<<endl;

	cout<<"RE x "<<cntRE<<endl;
}

Measured memory_bytes: 3644
class ST
	def initialize a
		@l = (1<<(a.size-1).bit_length)-1
		@h = [nil]*@l + a
		@h << a[-1] if a.size&1==1
		(@l-1).downto(0){|i|
			j = 2*i+1
			next unless @h[j]
			@h[i] = @h[j]|(@h[j+1]||0)
		}
	end

	def [] l,r=l
		x,l,r = 0,l+@l,r+@l
		x,l,r = x|@h[l]|@h[r],l/2,r/2-1 while l<=r
		return x
	end

	def []= i,x
		i += @l
		@h[i] = x
		while 0<i
			i = (i-1)/2
			j = 2*i+1
			@h[i] = @h[j]|(@h[j+1]||0)
		end
	end
end

gets
bs = ST.new [0]+gets.chomp.bytes.map{|c| 1<<(c-?a.ord) }
gets.to_i.times{
	c,d,e = gets.split
	case c
	when ?1
		bs[d.to_i] = 1<<e.ord-?a.ord

	when ?2
		p 26.times.inject([0,bs[d.to_i,e.to_i]]){|(n,b),| next n+(b&1),b>>1 }[0]
	end
}


Measured memory_bytes: 38948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A+B) {
		cout << min(A, K) << endl;
	} else {
		cout << A-(K-(A+B)) << endl;
	}
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
  long long int a,b,x;
  cin>>a>>b>>x;
 
  long long int A;
  if(a!=0){
   A=(a-1)/x;
  }
  else{
     A=-1;
  }
 
  long long int B=b/x;
 
  long long int ans=B-A;
  cout<<ans<<endl;
 
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;

class Main{
	public static void main(String[]$){

		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		Pattern ym = Pattern.compile("^([0-9]{2}(0[1-9]|1[0-2]))$");
		Pattern my = Pattern.compile("^((0[1-9]|1[0-2])[0-9]{2})$");
		String ans = "";

		if(ym.matcher(S).find() && my.matcher(S).find())
			ans = "AMBIGUOUS";
		else if(ym.matcher(S).find())
			ans = "YYMM";
		else if(my.matcher(S).find())
			ans = "MMYY";
		else
			ans = "NA";

		System.out.println(ans);
	}
}


Measured memory_bytes: 21076
N=int(input())
E=list(map(int, input().split()))
k=max(E)
D={}
for i in range(k+1):
    D[i]=0
for i in range(N):
    D[E[i]]+=1
    

ans=1
for i in range(1,k+1):
    ans*=D[i-1]**D[i]
if D[0]==1 and E[0]==0:
    print(ans%998244353)
else:
    print(0)

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

int main() {
    string w;
    cin >> w;
    int alpha[26]={};
    bool flag=1;
    for(int i=0; i<w.length(); i++) alpha[w[i]-'a']++;
    for(int i=0; i<26; i++) if(alpha[i]%2) flag=0;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*
 
fun main(args: Array<String>) {
  var num = readLine()!!

  when(num.length) {
    1 -> {
      println(num.toInt())
    }
    2 -> {
      println(9)
    }
    3 -> {
      println(9 + num.toInt() - 99)
    }
    4 -> {
      println(9 + 900)
    }
    5 -> {
      println(9 + 900 + num.toInt() - 9999)
    }
    6 -> {
      println(9 + 900 + 90000)
    }
  }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long int 
#define mp make_pair
#define pb push_back

int32_t main()
{
    string str;
    cin>>str;
    
    for(int i=0;i<str.size();i++)
    {
         if(str[i]=='1')
         str[i]='9';
         else if(str[i]=='9')
         str[i]='1';
    }
    
    cout<<str;
    
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
b = [0]*N
c = []
m = 0

for i in range(N-1,N//2,-1):
  if a[i] == 1:
    b[i] = 1
    c.append(i+1)
    m += 1
for i in range(N//2,-1,-1):
  sum_b = 0
  j = (i+1)*2
  while j <= N:
    sum_b += b[j-1]
    j += i+1
  if sum_b%2 != a[i]:
    c.append(i+1)
    b[i] = 1
    m += 1

print(m)
print(" ".join(map(str,c)))

Measured memory_bytes: 20572
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

void print_vec(vector<string> A) {
    for(auto c : A) cout << c << endl;
}

int main() {
    int N; cin >> N;
    int cnt_A = 0,cnt_B = 0,cnt_AB = 0;
    int ans = 0;
    REP(i,N) {
        string S; cin >> S;
        int n = S.size();
        if(S[0] == 'B' && S[n-1] == 'A') cnt_AB++;
        else if(S[n-1] == 'A') cnt_A++;
        else if(S[0] == 'B') cnt_B++;
        REP(i,n-1) if(S[i] == 'A' && S[i+1] == 'B') ans++;
    }  
    if(cnt_AB == 0) ans += min(cnt_A,cnt_B);
    else {
        if(cnt_A == 0 && cnt_B == 0) {
            ans += cnt_AB-1;
        } else {
            ans += min(cnt_A,cnt_B) + cnt_AB;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	cout << N / 3 << endl;
}

Measured memory_bytes: 256
#coding-utf-8

N, K, Q = map(int, input().split())
A = []
for q in range(Q):
    A.append(int(input()))

I = [0]*N

for a in A:
    I[a-1] += 1

for i in I:
    if i > Q-K:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8632
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        []{lint n; cin>>n; return n;}()

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

    int ans = 0;
    char prev = S[0];
    for( int i=1; i<S.size(); i++ ) {
        if( S[i] == prev ) continue;
        prev = S[i];
        ans ++;
    }

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


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Policy;

class Program
{
	static void Main()
	{
		var nk = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var n = nk[0];
		var k = nk[1];
		var a = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));

		var nums = new Dictionary<int, int>();
		foreach(var num in a) {
			if (nums.ContainsKey(num)) {
				nums[num]++;
			} else {
				nums.Add(num, 1);
			}
		}

		if (nums.Count > k) {
			var pairs = nums.ToArray().OrderBy(num => num.Value);
			var changing = pairs.Take(nums.Count - k);

			var sum = 0;
			foreach (var target in changing) {
				sum += target.Value;
			}

			Console.WriteLine(sum);
		} else {
			Console.WriteLine(0);
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 47904
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	int A,B,ANS=0;
	cin >> A >> B;

	fore(i,A,B+1){
		ostringstream oss;
		oss<<i;
		if(oss.str()[0]==oss.str()[4]&&oss.str()[1]==oss.str()[3])ANS++;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
n, t = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

D = [[0] * (t+1) for i in range(2)]

for i in range(n):
    for j in range(t, -1, -1):
        D[1][j] = max(D[1][j], D[0][j] + A[i][1])
        if j-A[i][0] >= 0:
            
            D[0][j] = max(D[0][j], D[0][j-A[i][0]] + A[i][1])
            D[1][j] = max(D[1][j], D[1][j-A[i][0]] + A[i][1])
        # else:
        #     # print(D)
        #     break

# print(D)
print(D[1][-2])

Measured memory_bytes: 49128
#include<iostream>

using namespace std;

int main(void)
{
	int h,w;
	cin >> h >> w;
	char c[105][105];
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin >> c[i-1][j-1];
	
	for(int i=1;i<=2*h;i++)
	{
		for(int j=1;j<=w;j++)
			cout << c[(i+1)/2-1][j-1];
		cout << endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<iostream>
#include<string>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int a[200000];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    REP(i,n)cin>>a[i];
    int b=0;REP(i,n)b^=a[i];
    REP(i,n){cout<<(a[i]^b)<<"\n";}
    return 0;
}

Measured memory_bytes: 4304
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
vector<int> in_(100010,0);
vector<int> out_(100010,0);
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    rep(i,n) {
        int x,y;
        cin >> x >> y;
        in_[x]++;
        out_[y]++;
    }
    int ans = 0;
    int now = 0;
    rep(i,100010){
        now += in_[i];
        if(now + 1 >= i) chmax(ans,i-1);
        now -= out_[i];
    }
    cout << max(ans, 0)<< endl;
    return 0;
}


Measured memory_bytes: 3460
#include <iostream>
#define MAX 100000


using namespace std;

int A[MAX],n;


int partition(int p,int r){
    int x,i,j,t;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            t=A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }

    int q=partition(0,n-1);

    for(int i=0;i<n;i++){
        if(i)
            cout<<" ";
        if(i==q) cout<<"[";
        cout<<A[i];
        if(i==q) cout<<"]";
    }

    cout<<endl;
    return 0;

}


Measured memory_bytes: 3372
#include "bits/stdc++.h"
using namespace std;

#define BLACK '0'
#define WHITE '1'

int main(int argc, char **argv) {
  string S;
  size_t N;

  cin >> S;
  N = S.size();

  size_t cnt = 0;

  for (size_t i = 1; i < N; i++) {
    if (S[i] == S[i - 1]) {
      cnt++;
      if (S[i] == BLACK)
        S[i] = WHITE;
      else if (S[i] == WHITE)
        S[i] = BLACK;
    }
  }

  cout << cnt << endl;

  return 0;
}


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

typedef long long ll;

#define MOD 1000000007
#define INF LLONG_MAX
#define decimDigits(n) fixed << setprecision(n)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(it, arr) for(auto it = begin(arr); it != end(arr); it++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll K, S, ans = 0, z;

    cin >> K >> S;

    rep(x, K + 1){
        rep(y, K + 1){
            z = S - y - x;
            if(0 <= z && z <= K)
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256