akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val s = readLine()!!

    fun check(ss: String): String? {
        var builder = StringBuilder(ss)
        for (i in 1 until n){
            if(s[i] == 'o' && builder[i] == 'S' || builder[i] == 'W' && s[i] == 'x'){
                builder.append(builder[i-1])
            }else{
                builder.append(if(builder[i-1] == 'S') 'W' else 'S')
            }
        }
        if(builder.first() != builder.last()){
            return null
        }else{
            builder.deleteCharAt(builder.length-1)
        }
        if((s[0] == 'o' && builder[0] == 'S' || s[0] == 'x' && builder[0] == 'W') && builder.last() == builder[1]){
            return builder.toString()
        }
        if((s[0] == 'x' && builder[0] == 'S' || s[0] == 'o' && builder[0] == 'W') && builder.last() != builder[1]){
            return builder.toString()
        }
        return null
    }

    println(check("SS") ?: check("SW") ?: check("WS") ?: check("WW") ?: -1)
}

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

typedef long long ll;

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

    int n,k;
    cin >> n >> k;
    int dislike[10] = {0};
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        dislike[d]++;
    }
    string s;
    while(n){
        bool ok = true;
        s = to_string(n);
        for(int i=0;i<s.size();i++){
            if(dislike[s[i]-'0']==1){
                ok = false;
                break;
            }
        }
        if(ok) break;
        n++;
    }
    cout << stoi(s) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	// 入力
	char S[10];
	// 文字列の入力
	scanf("%s", S);
	
	printf((S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) ? "Bad\n" : "Good\n");
	
	return 0;
}

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

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

using namespace std;

int main(){
	while(1){
		int n[3]={};
		rep(i,6){
			int a; scanf("%d",&a);
			n[i%3]+=a;
		}
		if(n[0]==0 && n[1]==0 && n[2]==0) break;

		int ans=0;
		rep(i,3){
			int sum=0,ok=1;
			rep(j,3) if(n[j]>=i) sum+=(n[j]-i)/3; else ok=0;
			if(ok) ans=max(ans,i+sum);
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 768
N,K = map(int,input().split(" "))
ans = N
snuke = [False] * (N + 1)
for i in range(K):
    d = int(input())
    A = list(map(int,input().rstrip().split(" ")))
    for i2 in range(d):
        if snuke[A[i2]] == False:
            snuke[A[i2]] = True
            ans -= 1
print(ans)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
int n, ans = (-1) * 1000000000;
vector<vector<int> > f, p;

void rec(vector<int> v){
  if ( v.size() == 10){
    bool flag = true;
    for ( int i = 0; i < 10; i++){
      if ( v[i] == 1){
        flag = false;
        break;
      }
    }
    if ( flag ) {return;}

    int profit = 0;
    for ( int i = 0; i < n; i++ ){
      int cnt = 0;
      for ( int j = 0; j < 10; j++){
        if ( v[j] ==1 && f[i][j] == 1){
          cnt ++;
        }
      }
      profit += p[i][cnt];
    }
    ans = max(ans, profit);
  } else {
    v.push_back(0);
    rec(v);
    v[v.size()-1] = 1;
    rec(v);
  }
}

int main(){
  cin >> n;
  int val;
  for ( int i = 0; i < n; i++){
    vector<int> tmp;
    for ( int j = 0; j < 10; j++){
      cin >> val;
      tmp.push_back(val);
    }
    f.push_back(tmp);
  }

  for ( int i = 0; i < n; i++){
    vector<int> tmp;
    for ( int j = 0; j <= 10; j++){
      cin >> val;
      tmp.push_back(val);
    }
    p.push_back(tmp);
  }

  vector<int> v;
  rec(v);

  cout << ans << endl;

}

Measured memory_bytes: 256
import itertools
n = int(input())
li1 = []
for i in range(n):
    li1.append(i+1)
li2 = list(itertools.permutations(li1,n))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
print(abs(li2.index(p)-li2.index(q)))

Measured memory_bytes: 8052
R,G,B,N = map(int,input().split())
count = 0
 
for i in range(0,N+1,R):
    for j in range(0,N+1,G):
        sum = i + j
        if N - sum < 0:
            break
        elif (N - sum) % B == 0:
            count += 1
 
print(count)

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

int main(){

int A,B,C;
  cin >> A >> B >> C;
  if((A==5 && B==5 && C==7)||(A==5 && B==7 && C==5)||(A==7 && B==5 && C==5)){
  	cout << "YES" << endl;
  }
  else{
  	cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace  std;

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
int main() {
	long long int A, B;
	cin >> A >> B;
	if (A > B) {
		cout << A * B / gcd(A, B) << endl;
	}
	else {
		cout << A * B / gcd(B, A) << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    ll n, k;
    cin >> n >> k;
    ll count =0;
    while(true){
        n /= k;
        count ++;
        if(n==0) break;
    }

    cout << count << endl;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	string s[h];
	int ans[h][w];
	for(int i=0;i<h;i++)
		cin>>s[i];
	set<int> st;
	for(int i=0;i<h;i++)
	{
		bool f=0;
		for(int j=0;j<w;j++)
			if(s[i][j]=='#')
				f=1;
		if(f)
			st.insert(i);
	}
	int cur = 0;
	int ct = 0;
	for(auto it = st.begin();it!=st.end();it++)
	{
		int lst = *it;
		int row = *it;
		if(it == --(st.end()))
			lst = h-1;
		set<int> strb;
		for(int j=0;j<w;j++)
		{
			if(s[row][j] == '#')
				strb.insert(j);
		}
		int cols = 0;
		for(auto it1 = strb.begin();it1!=strb.end();it1++)
		{
			int cole = *it1;
			if(it1 == --(strb.end()))
				cole = w-1;
			ct++;
			for(int p=cur;p<=lst;p++)
			{
				for(int q=cols;q<=cole;q++)
					ans[p][q] = ct;
			}
			cols = cole+1;
		}
		cur = lst+1;
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cout<<ans[i][j]<<" ";
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4080
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

signed main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int a, b, c;
	a = (A - B) + (A - C);
	b = (B - A) + (B - C);
	c = (C - A) + (C - B);

	int cnt = 0;

	while (true)
	{
		if (a == 0 && b == 0 && c == 0)
		{
			cout << -1 << endl;
			break;
		}
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
		{
			cout << cnt << endl;
			break;
		}
		a /= 2;
		b /= 2;
		c /= 2;
		cnt++;
	}
}

Measured memory_bytes: 256
N,M,C = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
c = 0
for _ in range(N):
    A = [int(i) for i in input().split()]
    if sum([A[i]*B[i] for i in range(M)] + [C]) > 0:
        c += 1
print(c)

Measured memory_bytes: 9120
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

ll dp[5001][5001];

int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    int array[n+1];
    array[0] = 0;
    rep(i,n)
      cin>>array[i+1];

    rep(i,n+1)
      rep(j,n+1)
        dp[i][j] = 1e18;

    dp[0][0] = 0;
    rep(i,n)
      rep(j,n+1)
      {
        if(array[i+1] > array[j])
          dp[i+1][i+1] = min(dp[i+1][i+1], dp[i][j]);
        dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (array[i+1] > array[j]? a : b));
      }
    ll ans = 1e18;
    rep(i,n+1)
      ans = min(ans, dp[n][i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 195712
N, M = map(int,input().split())

X = list(map(int,input().split()))
X.sort(reverse=True)

Y = [ X[i-1]-X[i] for i in range(1,M)]
Y.sort()

if N ==1:
    ans = sum(Y)
else:
    ans = sum(Y[:-N+1])

print(ans)

Measured memory_bytes: 13968
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a[10],b=0,c=1000,i;
	for(i=0;i<6;i++){
		scanf("%d",&a[i]);
		if(i<6){
			b=max(b,a[i]);
			c=min(c,a[i]);
		}
	}
	if(b-c<=a[5]){
		printf("Yay!");
	}else{
		printf(":(");
	}
	return 0;
}


Measured memory_bytes: 128
x, n = (int(x) for x in input().split())
p_list = list(map(int, input().split()))
 
ans = 0
 
max_ = 0
min_ = 0

for i in range(x, 102, 1) :
 
    if i not in p_list:
        max_ = i
        break
for j in reversed(range(x + 1)) :

 
    if j not in p_list:
        min_ = j
        break
 
if abs (min_ - x) <= abs(max_ - x) :
    ans = min_
else : 
    ans = max_
 
print(ans)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int c2 = 0;
  int c4 = 0;
  for (auto &x : a) {
    if (x % 4 == 0) c4++;
    else if (x % 2 == 0) c2++;
  }
  string ans = (c4 >= n / 2 || c4 * 2 + c2 >= n) ? "Yes" : "No";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int r,g,b;
  cin >> r >> g >> b;
  cout << ((g*10+b)%4==0?"YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
#define N 131072
int dat[N*2+10];
int inf=1000000000;
//[a,b)の最小値
//外からは(a,b,0,0,n)として呼ぶ
int query(int a,int b,int k=0,int l=0,int r=N){
	if(r<=a || b<=l) return inf;
	if(a<=l && r<=b) return dat[k];
	int vl=query(a,b,k*2+1,l,(l+r)/2);
	int vr=query(a,b,k*2+2,(l+r)/2,r);
	return min(vl,vr);
}
void update(int k,int a){
	k+=N-1;
	dat[k]=a;
	while(k>0){
		k=(k-1)/2;
		dat[k]=min(dat[k*2+1],dat[k*2+2]);
	}
	return;
}
int main()
{
	int n,m;string s;
	cin>>n>>m;cin>>s;
	rep(i,N*2+5) dat[i]=inf;update(n,0);
	for(int i=n-1;i>=0;i--){
		if(s[i]=='1') continue;
		int q=query(i+1,min(i+m+1,n+5));
		update(i,q+1);
	}
	int out=query(0,1),now=0;
	if(out>=inf){
		cout<<-1<<endl;return 0;
	}
	//cout<<out<<endl;
	rep(i,out){
		int lo=now+1,hi=now+m;
		while(hi>lo){
			int mi=(hi+lo)/2;
			if(query(now+1,mi+1)<=out-i-1) hi=mi;else lo=mi+1;
		}
		cout<<lo-now;now=lo;
		if(i<out-1) cout<<' ';else cout<<endl;
	}
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    int n, c;
    cin >> n >> c;
    int D[32][32];
    vector<map<int, int>> C(3);
    rep(i, c)rep(j, c) cin >> D[i][j];
    rep(i, n)rep(j, n){
        int tmp;
        cin >> tmp;
        tmp--;
        C[(i+j)%3][tmp]++;
    }
    vector<vector<int>> abc(3);
    rep(i, 3){
        rep(j, c){
            int tmp=0;
            for(auto itr = C[i].begin(); itr!=C[i].end(); itr++){
                int a = itr->first, count = itr->second;
                tmp += (D[a][j] * count);
            }
            abc[i].push_back(tmp);
        }
    }
    ll ans = INF;
    rep(i, c)rep(j, c)rep(k, c){
        if(i!=j and i!=k and j!=k){
            ll aa = abc[0][i], bb = abc[1][j], cc = abc[2][k];
            chmin(ans, aa+bb+cc);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
   
   int N, i, a = 0, b = 0,s = 0;
   cin >> N;

   for(i = 0; i <N; i++){
     cin >> a >> b;
    s +=  b - a + 1;
    


   }
    cout << s << endl;
     return 0;
    
    }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

struct Tree
{
    ll id;
    ll toward;
    ll from;
    ll res;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<Tree> trees(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];A[i]--;
        Tree t = {(ll)i, A[i], -1, -1};
        trees[i] = t;
    }
    ll from_i = 0;
    ll i = trees[0].toward;
    ll loop_cost = 1;
    ll loop_start_point = -1;
    while(loop_start_point != i)
    {
        if(trees[i].from != -1 && loop_start_point == -1)
        {
            loop_start_point = i;
            trees[loop_start_point].res = 0;
            K--;
            //cerr << "start:" << loop_start_point << endl;
        }
        else if (loop_start_point == -1) K--;

        if(loop_start_point != i && loop_start_point != -1)
        {
            //cerr << i << ":" <<  loop_cost << endl;
            trees[i].res = loop_cost;
            loop_cost++;
        }
        if(K == 0) {cout << i+1 << endl; return 0;}
        //cerr << "from:" << from_i << ":i:" << i << ":toward:" << trees[i].toward << ":K:" << K << endl;
        trees[i].from = from_i;
        from_i = i;
        i = trees[i].toward;
    }
    //cerr << K << ":" <<loop_cost << endl;
    K = K % loop_cost;
    //cerr << loop_start_point << ":" << loop_cost << ":" <<  K << endl;
    for(size_t i=0;i<N; i++)
    {
        //cerr << i << ":" << trees[i].res << endl;
        if(K == trees[i].res)
        {
            cout << i+1 << endl;
            break;
        }
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 11092
program polygon
  implicit none
  integer :: n, l(10) = 0
  read(*,*) n
  read(*,*) l(1:n)
  if (2*maxval(l) < sum(l)) then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
end program polygon

Measured memory_bytes: 256
m,d = list(map(int,input().split()))
num_list = []
s_list = [1 for i in range(10,d+1)]
count = 0

for i in range(10,d+1):
    num_list.append(str(i))
    for j in num_list[i-10]:
        if int(j) >= 2:
            s_list[i-10] *= int(j)
        else:
            s_list[i-10] *= 0

for i in s_list:
    if i <= m and i > 0:
        count+=1
       
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
typedef long long ll;

int main() {
    int M = 1000005;
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>cnt(M);
    rep(i, 0, N){
        cin >> A[i];
    }
    for (int x : A) {
        if(cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        for(int i = x; i < M; i+=x) cnt[i]++;
    }
    int ans = 0;
    for (int x : A) {
        if(cnt[x] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

  
bool judge_kaibun(string A){
    string B,C;
     B = A.substr(0,(A.size() - 1)/2);
     C = A.substr((A.size() + 1)/2,A.size());
    bool is_not = true;
    for(int i = 0; i < B.size() ; i++){
        if(B[i] != C[i]){
            is_not = false;
        }
    }
    return is_not;
    }

int main(){
    string N;
    cin >> N;
    if(judge_kaibun(N)==true){
        cout << "Yes" << endl;
    }else{
        cout << "No"<< endl;
    }
}

Measured memory_bytes: 256
/* Aditya0412 */
    #include <bits/stdc++.h>
    using namespace std; 
    #define int long long 
    #define pb push_back 
    #define vii vector < int > 
    #define pii pair < int , int >
    #define fi first
    #define all(a)      (a).begin(),(a).end()
    #define si(x)       (int)((x).size())
    #define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
    #define se second 
    #define endl        '\n'
    #define f(i,a,b)    for(int i=a;i<b;i++)
    #define mem(a,x)          memset(a,x,sizeof(a))
    #define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    // const int  mod=998244353;
    const int  mod = 1000000000+7;
    const int  N=1000000+6;
    #define M_PI           3.14159265358979323846

    // int x2[]={+1,-1,+0,+0};
    // int y2[]={+0,+0,+1,-1};
    // int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
    // int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
    // int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
    // int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

    // === Debug macro starts here ===

    int recur_depth = 0;
    #ifdef DEBUG
    #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
    #else
    #define dbg(x)
    #endif
    template<typename Ostream, typename Cont>
    typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
        os<<"[";
        for(auto& x:v){os<<x<<", ";}
        return os<<"]";
    }
    template<typename Ostream, typename ...Ts>
    Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
        return os<<"{"<<p.first<<", "<<p.second<<"}";
    }

    // === Debug macro ends here ===

    main() 
    {
        fastIO;
        int n;cin>>n;
        vector< pair< int,int> > v(n);
        f(i,0,n)
        {
            int x,y;cin>>x>>y;
            v[i]={x,y};
        }
        bool bo=false;
        f(i,0,n)
        {
            if(v[i].fi==v[i].se and i+1<n and v[i+1].fi==v[i+1].se and i+2<n and v[i+2].fi==v[i+2].se)
            bo=true;
        }
        if(bo)
        cout<<"Yes";
        else
        {
            cout<<"No";
        }
        
        
    } 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	vector<int> a(n), freq(n + 5);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		freq[a[i]]++;
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i++)
		ans += 1ll * freq[i] * (freq[i] - 1) / 2ll;
	
	for(int i = 0; i < n; i++){
		ans -= 1ll * freq[a[i]] * (freq[a[i]] - 1) / 2ll;
		freq[a[i]]--;
		ans += 1ll * freq[a[i]] * (freq[a[i]] - 1) / 2ll;
		cout << ans << endl;
		ans -= 1ll * freq[a[i]] * (freq[a[i]] - 1) / 2ll;
		freq[a[i]]++;
		ans += 1ll * freq[a[i]] * (freq[a[i]] - 1) / 2ll;
	}

	return 0;
}



Measured memory_bytes: 4224
#include<stdio.h>

static int N =100;
int min(int, int);

int main(){
    int n, p[N+1], m[N+1][N+1];
    scanf("%d",&n);

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

    for(int i=1; i<=n; i++) m[i][i]=0;

    for(int l=2; l <= n; l++){
        for(int i=1; i<=n-l+1; i++){
            int j=i+l-1;
            m[i][j]=1000000;
            for(int k=i; k<=j-1; k++){
                m[i][j]=min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    printf("%d\n",m[1][n]);
    return 0;
}

int min(int a, int b)
{
    if(a>b) return b;
    else return a;

}



Measured memory_bytes: 2104
def insertionSort(A, n, g, cnt):
    i = g
    while n-1 >= i:
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            cnt += 1
        A[j+g] = v
        i += 1
    return cnt


def shellSort(A, n, cnt):
    G = []
    e = 1
    while len(A) >= e:
        G.append(e)
        e = 3 * e + 1
    G.reverse()
    m = len(G)

    print(m)
    i = 0
    for g in G:
        if i != m-1:
            print("{} ".format(g), end="")
        elif i == m-1:
            print(g)
        i += 1

    for g in G:
        cnt = insertionSort(A, n, g, cnt)

    print(cnt)
    for a in A:
        print(a)

    return cnt


n = int(input())
a = []
cnt = 0
for _ in range(n):
    a.append(int(input()))

cnt = shellSort(a, n, cnt)



Measured memory_bytes: 45520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end()
#define int long long
#define double long double
int gcd(int x, int y){
    if (y == 0)
        return x;
    x = x % y;
    gcd(y, x);
}
main()
{
	int a,b;
	cin>>a>>b;
	if(a<1||a>9||b<1||b>9) cout<<-1<<endl;
	else cout<<a*b<<endl;
}


Measured memory_bytes: 256
(defun puyopuyo ()
  (let ((n (read))
        (s (string (read)))
        (cnt 1))
    (dotimes (i (1- n))
      (unless (char-equal (elt s i) (elt s (1+ i))) (incf cnt)))
    (format t "~a" cnt)))

(puyopuyo)

Measured memory_bytes: 15204
import java.util.*;

public class Main{
	
	String [] data = {"100101",
			"10011010",
			"0101",
			"0001",
			"110",
			"01001",
			"10011011",
			"010000",
			"0111",
			"10011000",
			"0110",
			"00100",
			"10011001",
			"10011110",
			"00101",
			"111",
			"10011111",
			"1000",
			"00110",
			"00111",
			"10011100",
			"10011101",
			"000010",
			"10010010",
			"10010011",
			"10010000",
			"101",
			"000000",
			"000011",
			"10010001",
			"010001",
			"000001"};
	HashMap<String, String> map;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		init();
		while(sc.hasNextLine()){
			String s = sc.nextLine();
			StringBuilder sb = new StringBuilder();
			int len = s.length();
			for(int i = 0; i < len; i++){
				char c = s.charAt(i);
				switch(c){
				case ' ':
					sb.append("101");
					break;
				case '\'':
					sb.append("000000");
					break;
				case ',':
					sb.append("000011");
					break;
				case '-':
					sb.append("10010001");
					break;
				case '.':
					sb.append("010001");
					break;
				case '?':
					sb.append("000001");
					break;
				default:
					sb.append(data[(int)(c - 'A')]);
				}
			}
			int len2 = (5 - sb.length() % 5) % 5;
			for(int i = 0; i < len2; i++){
				sb.append("0");
			}
			StringBuilder ans = new StringBuilder();
			for(int i = 0; i < sb.length(); i += 5){
				String sub = sb.substring(i, i + 5);
				ans.append(map.get(sub));
			}
			System.out.println(ans.toString());
		}
	}
	
	private void init() {
		map = new HashMap<String, String>();
		map.put("00000","A");
		map.put("00001","B");
		map.put("00010","C");
		map.put("00011","D");
		map.put("00100","E");
		map.put("00101","F");
		map.put("00110","G");
		map.put("00111","H");
		map.put("01000","I");
		map.put("01001","J");
		map.put("01010","K");
		map.put("01011","L");
		map.put("01100","M");
		map.put("01101","N");
		map.put("01110","O");
		map.put("01111","P");
		map.put("10000","Q");
		map.put("10001","R");
		map.put("10010","S");
		map.put("10011","T");
		map.put("10100","U");
		map.put("10101","V");
		map.put("10110","W");
		map.put("10111","X");
		map.put("11000","Y");
		map.put("11001","Z");
		map.put("11010"," ");
		map.put("11011",".");
		map.put("11100",",");
		map.put("11101","-");
		map.put("11110","'");
		map.put("11111","?");
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

int a[MAXN], b[MAXN], c[MAXN];
int top;

void add_tr(int a0, int b0, int c0) {
	a[top] = a0;
	b[top] = b0;
	c[top] = c0;
	top++;
}

void solve_odd(int n) {
	int k0 = (n + 1) / 2;
	int m = k0 - 1;
	REPN(i, m + 1, 2 * m + 1) {
		int a0 = i, b0 = i + 3 * m + 1;
		add_tr(a0, b0, a0 + b0);
	}
	REPN(i, 2 * m + 2, 3 * m + 1) {
		int a0 = i, b0 = i + m;
		add_tr(a0, b0, a0 + b0);
	}
}

void solve(){
	int n, k;
	cin >> n >> k;
	int k0 = (n + 1) / 2;
	if (k > k0) {
		printf("-1\n");
		return;
	}
	int top = 0;
	if (n % 2 == 1) {
		solve_odd(n);
	} else {
		solve_odd(n - 1);
		REP(i, 0, n - 1) {
			a[i] += 1;
			b[i] += 2;
			c[i] += 3;
		}
		add_tr(k0, 3 * k0, 5 * k0);
	}
	REP(i, 0, n) {
		a[i] -= (k0 - k);
		b[i] -= (k0 - k);
		c[i] -= (k0 - k);
		printf("%d %d %d\n", a[i], b[i], c[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3456
N, M = map(int, input().split())
ans = [-1]*N
reg = [list(map(int, input().split())) for _ in range(M)]
answer = True
for s, c in reg:
  if ans[s-1]!=-1 and ans[s-1]!=c:
    answer = False
    break
  else:
    ans[s-1]=c
if not answer:
  print(-1)
elif N==1 and M==0:
  print(0)
elif ans[0]==0 and N!=1:
  print(-1)
else:
  for i in range(N):
    if i==0 and ans[0]==-1:
      ans[0]=1
    elif ans[i]==-1:
      ans[i]=0
  print(int(''.join([str(i) for i in ans])))

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

bool prime(int x){
    if(x==1){
        return false;
    }
    else if(x==2){
        return true;
    }
    else{
        bool flag = true;
        for(int i=2; i<=x-1; i++){
            if(x%i ==0){
                flag = false;
            }
        }
        return flag;
    }
}

int main() {
    int X;
    cin >>X;

    bool flag1 = false;
    while(!flag1){
        if(prime(X)){
            cout << X << endl;
            return 0;
        }
        X++;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll INF = 1LL<<60;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int w,h,n;
  cin >> w >> h >> n;
  int right = w, left = 0, bottom = 0, upper = h;
  rep(i,n) {
    int x,y,a;
    cin >> x >> y >> a;
    if (a == 1) chmax(left, x);
    else if (a == 2) chmin(right, x);
    else if (a == 3) chmax(bottom, y);
    else chmin(upper, y);
  }
  debug(right, left, upper, bottom);
  int ans = 0;
  if (right-left > 0 && upper-bottom > 0) ans = (right-left)*(upper-bottom);
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 256
import sys 

N = int(sys.stdin.readline().strip())
X = sys.stdin.readline().strip()

pc = X.count("1")
# print("pc", pc)

# popcountはpcの+-1にしかならないので計算可能
mod_sum = {pc-1:0, pc+1:0}
# real_v = 0
for i in range(N):
    for this_pc in (pc-1, pc+1):
        if this_pc == 0:
            mod_sum[this_pc] = 0
            break
        if X[i] == "1":
            mod_sum[this_pc] += pow(2, N-i-1, this_pc)
            mod_sum[this_pc] %= this_pc
            # real_v += pow(2, N-i-1)
# print("real_v", real_v, "bin to int", int(X, 2))

for i in range(N):
    tmp_pc = pc
    if X[i] == "0":
        tmp_pc += 1
    else:
        tmp_pc -= 1
    if tmp_pc == 0:
        print(0)
        continue

    if X[i] == "0":
        tmp_mod_sum = mod_sum[tmp_pc] + pow(2, N-i-1, tmp_pc)
        tmp_mod_sum %= tmp_pc
    else:
        tmp_mod_sum = mod_sum[tmp_pc] - pow(2, N-i-1, tmp_pc)
        tmp_mod_sum %= tmp_pc

    count = 1
    tmp_sum = tmp_mod_sum
    # print(bin(tmp_sum))
    # print("tmp_sum", tmp_sum, "tmp_pc", tmp_pc)
    while tmp_sum > 0:
        tmp_x = str(bin(tmp_sum))
        tmp_pc = tmp_x.count("1")
        count += 1
        if tmp_pc == 0:
            break
        tmp_sum = tmp_sum % tmp_pc
        # print("tmp_sum", tmp_sum)
    print(count)

Measured memory_bytes: 80376
from itertools import accumulate
import sys
import bisect

input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse = True)

li = [0] * (2*10**5+1)

for i in a:
    li[i] += 1

acm = list(accumulate(li))
acm_a = list(accumulate(a))

l = 0
r = 2 * 10 ** 5

while l <= r:
    mid = (l + r) // 2
    count = 0
    for i in a:
        if mid - i >= 0:
            count += n - acm[mid-i]
        else:
            count += n
    if count >= m:
        l = mid + 1
    else:
        r = mid - 1

sum_idx = 0
ans = 0
b = a[::-1]
for left in a:
    right_min = l - left
    idx = bisect.bisect_left(b,right_min)
    if n - idx > 0:
        sum_idx += n - idx
        ans += left * (n - idx) + acm_a[n - idx - 1]

ans -= l * (sum_idx - m)

print(ans)


Measured memory_bytes: 71072
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    *na, = map(int, read().split())
    n, a = na[0], na[1:]
    xyz = [0, 0, 0]
    p = 1
    for i in range(n):
        p *= sum([j==k for j, k in zip([a[i]]*3, xyz)])
        if xyz[0]==a[i]: xyz[0]+=1; continue
        if xyz[1]==a[i]: xyz[1]+=1; continue
        if xyz[2]==a[i]: xyz[2]+=1; continue

    print(p%(10**9+7))

if __name__ == "__main__":
    main()


Measured memory_bytes: 53652
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif

public class App
{
    public static void Main(string[] args)
    {
console.ReadLine();
        int m = 0;
        
        cout = console.ReadLine().Split().Select(s=>int.Parse(s)).Where(w=>{
        if(w>=m)
        {
            m=w;
            return true;
        }
        return false;
        }).Count().ToString();
    }
}
public static class Exter
{
    public static int Max(params int[] p)=>p.Max();
    public static short Max(params short[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static string cout
    {
        set
        {
            console.WriteLine(value);
        }
    }
    public static int[] readarr
    {
        get 
        {
            return console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

ll dp[1<<21][21];
int main(){
	int n,a[21][21];
	cin>>n;
	FOR(i,0,n) FOR(j,0,n){
		cin>>a[i][j];
	}
	FOR(i,0,n){
		if(a[0][i]) dp[1<<i][0]=1;
	}
	FOR(i,1,n){
		vint v;
		FOR(k,0,n-i) v.PB(0);
		FOR(k,0,i) v.PB(1);
		do{
			int k=0;
			FOR(i,0,n){
				k<<=1;
				k+=v[i];
			}
			FOR(j,0,n){
				if(!a[i][j]) continue;
				if(!((k>>j)&1)){
					(dp[k|(1<<j)][i]+=dp[k][i-1])%=MOD;
				}
			}
		}while(next_permutation(all(v)));
	
	}
	co(dp[(1<<n)-1][n-1]);
}


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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5 + 5;


void solve() {

  int r,c,k,ans=0;
  cin>>r>>c>>k;
  vvi a(r,vi(c));
  rep(i,0,r)
    rep(j,0,c){
      char ch;
      cin>>ch;
      a[i][j]=ch=='#';
    }
  rep(m1,0,1<<r){
    rep(m2,0,1<<c){
      int cnt = 0;
      rep(i,0,r)
        rep(j,0,c)
          cnt+=a[i][j]&&((m1>>i)&1)&&((m2>>j)&1);
      ans+=cnt==k;
    }
  }
  cout<<ans<<endl;
   
          
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


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


Measured memory_bytes: 3656
N,K=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(N)]

X=sorted([i[0] for i in xy])
Y=sorted([i[1] for i in xy])

ans=[]
for i in range(N-1):
  lx=X[i]
  for j in range(i+1,N):
    rx=X[j]
    for k in range(N-1):
      dy=Y[k]
      for l in range(k+1,N):
        uy=Y[l]
        cnt=0
        for x,y in xy:
          if lx<=x and x<=rx and dy<=y and y<=uy:
            cnt+=1
        if cnt>=K:
          ans.append((rx-lx)*(uy-dy))
          
          
print(min(ans))

Measured memory_bytes: 113372
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

bool hantei1(string s) {
	int judge = 0;
	if (s.size() == 1) {
		return true;
	} else {
	for (int i = 0; i <= (s.size()-2) / 2; i++) {
		if (s[i] != s[s.size()-1-i]) {
			judge = 1;
			break;
		}
	}

	if (judge == 0) {
		return true;
	} else {
		return false;
	}
	}
}

bool hantei2 (string s) {
	int judge = 0; 
	if (s.size() == 1) {
		return true;
	} else {
	for (int i = 0; i <= (s.size()-3) / 2; i++) {
		if (s[i] != s[s.size()-1-i]) {
			judge = 1;
			break;
		}
	}
	if (judge == 0) {
		return true;
	} else {
		return false;
	}
	}
}

int main() {
	string ss;
	stringstream sout;
	int n;
	int a;

	cin >> a;

	sout << a;

	sout >> ss;

	n = ss.size();

	if (n % 2 == 0) {
		if (hantei1(ss)) {
			cout << ss << endl;
		} else {
			for (int i = 1; true; i++) {
				sout.str("");
				sout.clear();
				sout << ss;
				sout >> a;
				if (i % 2 == 0) {
					a += i;
				} else {
					a -= i;
				}
				sout.str("");
				sout.clear();
				sout << a;
				sout >> ss;
				if (hantei1(ss)) {
					cout << ss << endl;
					break;
				}
			}
		}
	} else {
		if (hantei2(ss)) {
			cout << ss << endl;
		} else {
			for (int i = 1; true; i++) {
				sout.str("");
				sout.clear();
				sout << ss;
				sout >> a;
				if (i % 2 == 0) {
					a += i;
				} else {
					a -= i;
				}
				sout.str("");
				sout.clear();
				sout << a;
				sout >> ss;
				if (hantei2(ss)) {
					cout << ss << endl;
					break;
				}
			}
		}
	}

	return 0;
}

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

using namespace std;
const double PI (acos(-1));


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

  int num=0;
  if(N%2 == 0)
  {
    num = N/2;
  }else
  {
    num = N/2 + 1;
  }
  
cout << num;

}


Measured memory_bytes: 3632
n = int(input())  # nは入力回数
num_list = [list(map(int, input().split())) for _ in range(n)]
ans = "No"

for i in range(n-2):
    if num_list[i][0] == num_list[i][1] and num_list[i+1][0] == num_list[i+1][1] and num_list[i+2][0] == num_list[i+2][1]:
        ans = "Yes"

print(ans)

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

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }



int main(){
    int N, A, B, cnt = 0, bcnt = 0;
    string S;
    cin >> N >> A >> B;
    cin >> S;
    for(int i = 0; i < N; ++i){
        if(S[i] == 'a'){
            if(cnt < A+B) {cnt++; cout << "Yes" << endl;}
            else cout << "No" << endl;
        }
        else if (S[i] == 'b'){
            if(cnt < B+A && bcnt < B) {cnt++; bcnt++; cout << "Yes" << endl;}
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
using namespace std;


int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N;
	cin >> N;
	int C[N];
	C[0] = 1;
	vector<int> P, Q;

	C[N-1] = 1;
	for(int i=N-1, x=1; i>0; i--, x++) {
		C[i-1] = C[i]*x;
	}

	for(int i=0; i<N; i++) {
		P.push_back(i+1);
		Q.push_back(i+1);
	}
	
	int a = 1;
	for(int i=0; i<N; i++) {
		// for(vector<int>::iterator it=P.begin(); it!=P.end(); it++) {
    	//     cout << *it;
		// }
		// cout << endl;

		int n;
		cin >> n;

		vector<int>::iterator idx = find(P.begin(), P.end(), n);
		int diff = (idx - P.begin());
		a += diff*C[i];
		// cout << "diff: " << diff << endl;
		P.erase(P.begin()+diff);
    }
	a = max(1, a);
	// cout << a << endl;

	int b = 1;
	for(int i=0; i<N; i++) {
		// for(vector<int>::iterator it=P.begin(); it!=P.end(); it++) {
    	//     cout << *it;
		// }
		// cout << endl;

		int n;
		cin >> n;

		vector<int>::iterator idx = find(Q.begin(), Q.end(), n);
		int diff = (idx - Q.begin());
		b += diff*C[i];
		// cout << "diff: " << diff << endl;
		Q.erase(Q.begin()+diff);
    }
	b = max(1, b);
	cout << abs(a-b);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    int K=in();
    ll ans=0;
    for(int i=K;i<=N+1;i++){
        ans+=((ll)i*(N+1-i)+1)%MOD;
        ans=ans%MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(int argc, char const *argv[]) {
    bool rate[8];
    for(int i=0;i<8;i++) rate[i]=false;
    int N;
    cin >> N;
    int count=0;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a<3200){
            rate[a/400]=true;
        }else{
            count++;
        }
    }
    int calc=0;
    for(int i=0;i<8;i++){
        if(rate[i]) calc++;
    }
    cout << max(calc,1) << " " << calc+count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll bg = 1000000007;
#define ff(i,n) for(i=0;i<n;i++)
#define vv vector<vector<ll> >
vector<vector<ll> >master [31]; 
int main() 
{
	ll t;
	t=1;
	while(t--)
	{
		ll x=0,i,n,d;
		cin>>n;
		string s;
		cin>>s;
		for(i=0;i<n;i++)
		{
			if(s[i]=='R')
				x++;	
		}
		ll ss = 0;
		for(i=0;i<x;i++)
		{
			if(s[i]=='W')
				ss++;
		}
		cout<<ss<<endl;
	}
    return 0;
}

Measured memory_bytes: 3756
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
if len(set(V)) == 1:
  print(n//2)
else:
  odd = []
  even = []
  for i in range(len(V)):
    if i % 2 == 0:
      even.append(V[i])
    else:
      odd.append(V[i])
  max_even,max_e_count = Counter(even).most_common(1)[0]
  max_odd,max_o_count = Counter(odd).most_common(1)[0]
  if max_even == max_odd:
    sec_even,sec_e_count = Counter(even).most_common(2)[1]
    sec_odd,sec_o_count = Counter(odd).most_common(2)[1]
    even_rank2 = len(odd) - max_o_count + len(even) - sec_e_count
    odd_rank2 = len(odd) - sec_o_count + len(even) - max_e_count
    print(min(even_rank2,odd_rank2))
  else:
    print(len(odd) - max_o_count + len(even) - max_e_count)

Measured memory_bytes: 16228