akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x = x->left;
  return x;
}
/*
Node treeSearch(Node u, int k){
  while(u!=NIL && u!=u->key){
    if(k<u->key)
      u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



  }*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key<x->key)
      x = x->left;
    else x = x->right;
  }

  z->parent = y;
  
  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  Node T;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      //  T = treeSearch(root, x);
      if ( T != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }// else if ( com[0] == 'd' ){
    //scanf("%d", &x->key);
      //  treeDelete(treeSearch(root, x));
    // }
  }

  return 0;
}

Measured memory_bytes: 24040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>V(n);
  for(int i=0;i<n;i++){
    cin>>V.at(i);
  }
  vector<int>C(n);
  for(int i=0;i<n;i++){
    cin>>C.at(i);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(V.at(i)>C.at(i)){
      ans+=V.at(i)-C.at(i);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<map>
#include<cmath>
using namespace std;

pair<double,double> route_vet(pair<double,double>a,double deg)
{//kaiten
  double x,y;
  x=cos(deg/180.0*M_PI)*a.first+(-sin(deg/180.0*M_PI))*a.second;
  y=sin(deg/180.0*M_PI)*a.first+cos(deg/180.0*M_PI)*a.second;
  return make_pair(x,y);
}

pair<double,double> norm_vet(pair<double,double>a)
{//seikika
  double x,y;
  x=a.first/sqrt(a.first*a.first+a.second*a.second);
  y=a.second/sqrt(a.first*a.first+a.second*a.second);
  return make_pair(x,y);
}

int main()
{
  
  int n;
  for(;cin>>n,n!=-1;)
    {
      double x=1,y=1;   
      n-=2;
      for(;n--;)
	{
	  pair<double,double> tmp = norm_vet(route_vet(make_pair(x,y),90.0));
	  x+=tmp.first;
	  y+=tmp.second;
	}
      cout<<fixed<<setprecision(2)<<x<<endl<<y<<endl;
    }
}

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

int main()
{
    int n, d;

    cin >> n >> d;

    vector<vector<int>> points(n, vector<int>(d, 0));

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < d; ++j)
        {
            int input;
            cin >> input;
            points[i][j] = input;
        }
    }

    int ans = 0;

    for (int x = 0; x < n; ++x)
    {
        for (int y = 0; y < n; ++y)
        {
            if (x > y)
            {
                int distance = 0;
                for (int i = 0; i < d; ++i)
                {
                    distance += (points[x][i] - points[y][i]) * (points[x][i] - points[y][i]);
                }
                int i = 1;
                while (1)
                {
                    if (i * i > distance)
                    {
                        break;
                    }

                    if (i * i == distance)
                    {
                        ans++;
                        break;
                    }
                    ++i;
                }
            }
        }
    }

    cout << ans << endl;
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int a, b;
    cin >> a >> b;
    int count = max(a,b);
    if(a > b) {
        a--; 
    } else {
        b--;
    }
    count += max(a, b);

    cout << count << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
//  .:::.   .:::.
// :::::::.:::::::
// :::::::::::::::
// ':::::::::::::'
//   ':::::::::'
//     ':::::'
//       ':'
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
using namespace std;
ll a[100001][3], dp[100001][3];
int main()
{
    
    FIO;
    ll t, q, maxx, n, k, i, j, k1, k2, k3, x, flag, ans, sum, cnt, prev;
    cin>>n;
    rep(i,0,n)
    {
        rep(j,0,3)
        {
            cin>>a[i][j];
        }
    }
    FILL(dp,0, ll);
    
    rep(i,0,3)
    {
        dp[0][i] = a[0][i];
    }
    rep(i,1,n)
    {
        rep(j,0,3)
        {
            rep(k,0,3)
            {
                if( j != k)
                {
                    dp[i][j] = max(dp[i][j], dp[i-1][k]);
                }
            }
            dp[i][j]+=a[i][j];
        }
    }
    // rep(i,0,n)
    // {
    //     rep(j,0,3)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    ans = 0;
    rep(i,0,3)
    {
        ans = max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
    return 0;    
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdio>
using namespace std;

int main() {
	string s;
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(isalpha(s[i]))
			putchar(toupper(s[i]));
		else putchar(s[i]);
	}cout<<endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e+5+7;
int a[N];

long long solve(int n, int x) {
	long long res = 0;
	for(int i = 0; i < n-1; i++) {
		if( a[i] + a[i+1] > x) {
			long long diff =  a[i] + a[i+1] - x;
			a[i+1] = max(a[i+1] - diff,(long long) 0);
			res += diff;
		}
	}
	return res;
}

int main() {
	int n,x;
	cin >> n >> x;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << solve(n,x) << endl;
}



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

#define EPS (1e-10)
#define equals(a,b) (fabs( (a)-(b) ) < EPS)

class Point{

public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x+p.x,y+p.y); }
  Point operator - (Point p) { return Point(x-p.x,y-p.y); }
  Point operator * (double a) { return Point(a*x,a*y); }
  Point operator / (double a) { return Point(x/a,y/a); }

  double abs() { return sqrt(norm()); }
  double norm() { return x*x + y*y; }
  
  bool operator < (const Point &p) const{
    return x != p.x ? x<p.x : y<p.y;
  }
  
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
  
};
typedef Point Vector;

double dot(Vector a,Vector b){
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y - a.y*b.x;
}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}

int main(){
  int n;
  double x1,y1,x2,y2,x3,y3,x4,y4;
  Point p1,p2,p3,p4;
  
  scanf("%d",&n);

  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    
    p1 = Point(x1,y1);
    p2 = Point(x2,y2);
    p3 = Point(x3,y3);
    p4 = Point(x4,y4);
    
    if(isOrthogonal(p1,p2,p3,p4)){
      puts("1");
    } else if(isParallel(p1,p2,p3,p4)){
      puts("2");
    } else {
      puts("0");
    }
  }  

  return(0);
}



Measured memory_bytes: 3252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }



int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		double h, m;
		char k;
		
		cin >> h >> k >> m;
		
		/*
		h = (h * 30.0) + (m / 2.0);
		m *= 6.0;
		
		double d = (180.0 < abs(h - m) ? 360.0 - abs(h - m) : abs(h - m));
		
		cout << (d < 30.0 ? "aleart" : (d < 90.0 ? "warning" : "safe")) << endl;
		 */
		
		h = h * 60 + m;
		
		m *= 12.0;
		
		int d = (360 < abs(h - m) ? 720 - abs(h - m) : abs(h - m));
		
		cout << (d < 60 ? "alert" : (d < 180 ? "warning" : "safe")) << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> pos, neg;
    int ans = 0;
    int lf, rf;
    rep(i, 0, n){
        if(a[i] < 0){
            neg.push_back(a[i]);
        }else{
            pos.push_back(a[i]);
        }
    }
    reverse(neg.begin(), neg.end());
    if(neg.size() == 0){
        rf = pos[0];
        lf = pos[1];
        pos.erase(pos.begin());
        pos.erase(pos.begin());
    }else if(pos.size() == 0){
        lf = neg[0];
        rf = neg[1];
        neg.erase(neg.begin());
        neg.erase(neg.begin());
    }else{
        lf = pos[0];
        rf = neg[0];
        pos.erase(pos.begin());
        neg.erase(neg.begin());
    }
    ans -= rf;
    ans += lf;
    rep(i, 0, pos.size()) ans += pos[i];
    rep(i, 0, neg.size()) ans -= neg[i];
    cout << ans << endl;
    // right
    int rtmp = rf;
    rep(i, 0, pos.size()){
        cout << rtmp << ' ' << pos[i] << endl;
        rtmp = rtmp - pos[i];
    }
    // left
    int ltmp = lf;
    rep(i, 0, neg.size()){
        cout << ltmp << ' ' << neg[i] << endl;
        ltmp = ltmp - neg[i];
    }
    cout << ltmp << ' ' << rtmp << endl;
    int tmp = ltmp - rtmp;
    assert(tmp == ans);
}

Measured memory_bytes: 3572
#include <iostream>
#include <sstream>
#include <vector>
#include <utility>
#include <map>
#include<set>
#include <algorithm>
#include <string>
#include <string.h>
#include <iomanip>
#include <cmath>
#define ll long long
#define PI 3.14159265358979323846
#define lp(i, n) for (long long i = 0; i < n; i++)
#define rep(i, v) for (int i = 0; i < int(v.size()); i++)
using namespace std;
int main(){
	ll n,hp,ans=0,sum=0;
	multiset<ll,greater<ll>> ms_a,ms_b;
	cin>>n>>hp;
	lp(i,n)
	{
		int a,b;
		cin>>a>>b;
		ms_a.insert(a);
		ms_b.insert(b);
	}
	auto it_a=ms_a.begin(),it_b=ms_b.begin();
	while(hp>0)
	{
	
		if(*it_b>*it_a&&it_b!=ms_b.end())
			{
				hp-=*it_b;
				it_b++;
				ans++;
			}
			else
			{
				ans+=ceil((long double)hp/(*it_a));
				hp=0;
			}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 9600
n=int(input())
lis=list(map(int,input().split()))
listuse=sorted(lis)
maximum=max(listuse)
if maximum%2==0:
    index=0
    for i in range(n-1):
        if abs(listuse[i]-maximum/2)>abs(listuse[i+1]-maximum/2):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    print(*anslist)
if maximum%2!=0:
    
    index=0
    for i in range(n-1):
        if min(abs(listuse[i]-((maximum+1)/2)),abs(listuse[i]-(maximum-1)/2))>min(abs(listuse[i+1]-((maximum+1)/2)),abs(listuse[i+1]-(maximum-1)/2)):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    
    print(*anslist)
  

Measured memory_bytes: 14052
vacation_day = gets.to_i
day_point = []

vacation_day.times do |i|
    day_point.push(gets.split(' ').map(&:to_i))
end

dP = Array.new(vacation_day + 1).map{Array.new(3,0)}
dP[1][0] = day_point[0][0]
dP[1][1] = day_point[0][1]
dP[1][2] = day_point[0][2]

range = 2..vacation_day 
range.each do |day|
    
    dP[day][0] = dP[day - 1][1] >= dP[day - 1][2] ? dP[day - 1][1] + day_point[day - 1][0] : dP[day - 1][2] + day_point[day - 1][0]
    dP[day][1] = dP[day - 1][0] >= dP[day - 1][2] ? dP[day - 1][0] + day_point[day - 1][1] : dP[day - 1][2] + day_point[day - 1][1]
    dP[day][2] = dP[day - 1][0] >= dP[day - 1][1] ? dP[day - 1][0] + day_point[day - 1][2] : dP[day - 1][1] + day_point[day - 1][2]

end

p dP.last.max

Measured memory_bytes: 12668
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
#include<utility>
using namespace std;
int main(){
	int n; cin >> n;
	int data[2000];
	for (int i = 0; i < n; ++i) cin >> data[i];
	sort(data, data + n);
	int cnt = 0;
	for (int i = n - 1; i >= 2; --i) {
		for (int j = 1; i - j >= 1; ++j) {
			int x = data[i] - data[i - j];
			for (int k = 0; k < i - j; ++k) {
				if (x < data[k]) {
					cnt += (i - j - k);
					break;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
import math
from statistics import mean

N = int(input())
towns = []
for i in range(N):
    xi,yi=map(int,input().split())
    towns.append([xi,yi])
order=[int(x) for x in range(N)]
root_time=[]
for one_order in itertools.permutations(order):
    root_t=0
    for i in range(len(one_order)-1):
        root_t += math.sqrt((towns[one_order[i]][0]-towns[one_order[i+1]][0])**2+(towns[one_order[i]][1]-towns[one_order[i+1]][1])**2)
    root_time.append(root_t)

print(mean(root_time))

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

const ll INF = 1LL << 60;

P f(int x) {
    string tmp = to_string(x);

    return P(tmp[0], tmp[tmp.size() - 1]);
}

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

    map<P, int> mp;

    for (int i = 1; i <= N; i++) {
        P p = f(i);
        mp[P(p.first, p.second)]++;
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        P p = f(i);

        ans += mp[P(p.second, p.first)];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a[2]={},k,s,ans=0;
cin>>k>>s;
for(int i=k;i>=0;i--)
for(int j=k;j>=0;j--)
if((s-i-j)<=k&&(s-i-j)>=0)
ans++;
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 504
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    long a = scan.nextLong();
    long b = scan.nextLong();
    long c = a+b;
    long d = n%c;
    if ((a == 0)||(c == 0)){
      System.out.println("0");
      return;
    }

    long g = (long) (n-d)/c;
    if (g == 0){
      if (n<=a){
        System.out.println(n);
      }
      else{
        System.out.println(a);
      }
    }
    else{
      long other = 0;
      if (d<=a){
        other = d;
      }
      else{
        other = a;
      }
      System.out.println(g*a+other);
    }
  }
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b;
    while (cin >> a >> b)
    {

        int v[100] = {};
        a--, b--;
        v[a]++, v[b]++;

        while (cin >> a >> b, a)
        {
            a--, b--;
            v[a]++, v[b]++;
        }

        bool flag = 0;
        for (int i = 2; i < 100; i++)
        {
            if (v[i] % 2 == 1)
                flag = 1;
        }

        if (v[0] % 2 == 1 && v[1] % 2 == 1 && !flag)
            OP("OK");
        else
            OP("NG");
    }
    return 0;
}


Measured memory_bytes: 3068
[N,M] = list(map(int,input().split()))
K = []
S = []
for i in range(M):
  x = list(map(int,input().split()))
  K.append(x[0])
  S.append(x[1:])
P = list(map(int,input().split()))
ans = 0
for ms in range(1 << N):
  cnt = 0
  for i in range(M):
    sum = 0
    for v in S[i]:
      if (ms >> (v-1)) & 1:
        sum += 1
    if sum % 2 == P[i]:
      cnt += 1
  if cnt == M:
    ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[5],y[5]={0,0,1,1,1};
string a[100000],s="MARCH";
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		cin>>a[i];
		f(j,5){
			if(a[i][0]==s[j])x[j]++;
		}
	}
	do{
		int z=1;
		f(i,5){
			if(y[i])z*=x[i];
		}
		ans+=z;
	}while(next_permutation(y,y+5));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6144
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
    }
    let a: Vec<i64> = (0 .. n).map(|i| a[i] - b[i]).collect();
    if a.iter().sum::<i64>() < 0 {
        puts!("-1\n");
        return;
    }
    let negcount = a.iter().filter(|&&x| x < 0).count();
    let mut neg: i64 = a.iter().filter(|&&x| x < 0).sum();
    let mut pos: Vec<i64> = a.into_iter().filter(|&x| x > 0).collect();
    pos.sort();
    pos.reverse();
    let mut cnt = 0;
    for i in 0 .. pos.len() {
        if neg >= 0 { break; }
        neg += pos[i];
        cnt += 1;
    }
    puts!("{}\n", cnt + negcount);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10492
N = int(input())
A = [int(x) for x in input().split()]
dic = {}

for i in range(N):
    dic.setdefault(i+1,A[i])

new_dic = sorted(dic.items(), key=lambda x:x[1])


for item in new_dic:
    print(item[0],end=" ")
print()

Measured memory_bytes: 26296
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint
import numpy as np


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = np.array(LI(), dtype=np.int64)
bit_cnt = [((A >> k) & 1).sum() for k in range(40)]
ans = 0
for i in range(40):
    if k >> i & 1 == 0:
        continue
    ret = 0
    ret += bit_cnt[i] * (1 << i)
    for j in range(i + 1, 40):
        if k >> j & 1:
            ret += (n -  bit_cnt[j]) * (1 << j)
        else:
            ret += bit_cnt[j] * (1 << j)
    for l in range(i):
        ret += max(n - bit_cnt[l], bit_cnt[l]) * (1 << l)
    ans = max(ans, ret)


ret = 0
for a in A:
    ret += k ^ a

print(max(ret, ans))








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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
	return 0;
}

//Total solved problems:-3


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
    static long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s1 = sc.next();
        String s2 = sc.next();
        String ans = "";
        for (int i = 0; i < n; i++) {
            if (s1.charAt(i) == s2.charAt(i)) {
                ans += "x";
            } else {
                ans += "y";
                i++;
            }
        }
        long res = 1;
        if (ans.charAt(0) == 'x') {
            res *= 3;
        } else {
            res *= 6;
        }
        for (int i = 1; i < ans.length(); i++) {
            if (ans.charAt(i - 1) == 'x' && ans.charAt(i) == 'x') {
                res *= 2;
            } else if (ans.charAt(i - 1) == 'x' && ans.charAt(i) == 'y') {
                res *= 2;
            } else if (ans.charAt(i - 1) == 'y' && ans.charAt(i) == 'x') {
                res *= 1;
            } else if (ans.charAt(i - 1) == 'y' && ans.charAt(i) == 'y') {
                res *= 3;
            }
            res %= MOD;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>

int vector_finder(std::vector<int> vec, int number) {
    int i;
    for (i = 0; i < vec.size(); i++) {
        if (number == vec[i]) {
            break;
        }
    }
    if (i != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main() {
    int N, M, X, i, tmp, cost_up = 0, cost_down = 0;
    std::vector<int> A;
    std::cin >> N >> M >> X;
    for (i = 0; i < M; i++) {
        std::cin >> tmp;
        A.push_back(tmp);
    }
    for (i = N; i > X; i--) {
        cost_down += vector_finder(A, i);
    }
    for (i=0; i < X; i++) {
        cost_up += vector_finder(A, i);
    }
    if (cost_up < cost_down) {
        std::cout << cost_up << std::endl;
    } else {
        std::cout << cost_down << std::endl;
    }
    return 0;
}

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

int main() {
  int N = 3;
  for(int i = 0; i < N; i++ ){
  string s;
  cin >> s;
    if (i == 1){
    char x = s.at(0);
    cout << 'A' << x <<  'C' << endl;
    }
  }

}


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

using namespace std;

int main() {
int n,a;
cin>>n>>a;
int sum=0;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
    if(x>a/2)
    sum+=(a-x)*2;
    else
    sum+=x*2;
   
}
cout<<sum;
cout<<endl;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
		
		
		//H,Wが両方とも0になるまで繰り返す
		while(true) {
			
			
			//縦、横の高さ
			int H  = src.nextInt();
			int W  = src.nextInt();
			
  			//HW両方が0になった場合終了
		    if((W == 0) && (H == 0)) {
	   	    break;
	   	     } 

			
			
			//縦の列の繰り返し
	        for (int i = 1; i <= H; i++) {
	        	

	   	     
             //2行目からの出力
             if((1 < i) && (i < H)) {
             	System.out.print("#");			//初めのフレーム
             	
             	//ドットの出力
             	for (int k = 2; k < W; k++) {		
             		System.out.print(".");
             	}
             	
             	System.out.print("#");		//最後のフレーム
             }else {
            	 
 	        	//横の列の繰り返し
 	            for (int j = 1; j <= W; j++) {


 	                	//１行目と最後の行の出力
 		            	System.out.print("#");

 	            }
 	            
             }
	        	

	            //縦に１列進む
	            System.out.println("");

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


Measured memory_bytes: 32160
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String S = scanner.next();
        if (S.length() % 2 == 1) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < S.length() / 2; i++) {
            if (S.charAt(i) != S.charAt((S.length() / 2) + i)) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 20816
#include<stdio.h>

int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    char s[n+1];
    scanf("%s", s);
    long long int a[n];
    a[0] = 0;
    for(int i=1; i<n; i++){
        a[i] = a[i-1];
        if(s[i-1] == 'A' && s[i] == 'C'){
            a[i]++;
        }
    }
    long long int ans[q];
    for(int i=0; i<q; i++){
        int l, r;
        scanf("%d %d", &l, &r);
        ans[i] = a[r-1] - a[l-1];
    }
    for(int i=0; i<q; i++){
        printf("%lld\n", ans[i]);
    }
    /*for(int i=0; i<n; i++){
        printf("%lld ", a[i]);
    }*/

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll key = (ll)1 << 32, key_old;
    int mini;
    while (true)
    {
        key_old = key;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > 0 && a[i] < key)
            {
                key = a[i];
                mini = i;
            }
        }
        if (key == key_old)
            break;
        for (int i = 0; i < n; i++)
        {
            if (i != mini)
                a[i] = a[i] % key;
        }
    }
    cout << key << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

struct wrd{
  string s;
  vector<int> pp;
  void prnt(void){
    cout << s << endl;
    sort(all(pp));
    printf("%d", pp[0]);
    for(int i = 1;i < pp.size();++i)printf(" %d", pp[i]);
    kara;
    return;
  }
};

bool cmp(wrd a, wrd b){
  for(int i = 0;i < min(a.s.size(), b.s.size());++i)if(a.s[i] != b.s[i])
    return a.s[i] < b.s[i];
  return a.s.size() < b.s.size();
}

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    vector<wrd> lis;
    string tmp;
    for(;getline(cin, tmp);){
      for(i = 0;i < tmp.size();++i)if(tmp[i] == ' ')break;
      string t = tmp.substr(0, i);

      i++;
      int res = 0;
      for(;i < tmp.size();++i)res = res * 10 + (int)(tmp[i] - '0');

      rep(i, lis.size())if(lis[i].s == t)break;
      if(i != lis.size())lis[i].pp.pb(res);
      else{
        vector<int> qwe;
        qwe.pb(res);
        lis.pb((wrd){t, qwe});
      }
    }

    sort(all(lis), cmp);
    rep(i, lis.size())lis[i].prnt();

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1244
L = input()
mod_num = 10**9 + 7

L_split = [0]*len(L)
for i in range(len(L)):
    L_split[i] = int(L[len(L)-1-i])
    
ans = 0
if len(L_split) == 1 and L_split[0] == 0:
    print(1)
else:
    count_1 = 0 
    for i in range(len(L_split)-1,-1,-1):
        if L_split[i] == 1:
            ans += pow(2,count_1,mod_num) * pow(3,i,mod_num)
            ans %= mod_num
            
            count_1 += 1
            
ans += pow(2,count_1,mod_num)
ans %= mod_num
print(ans)


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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if (0 <= x - r&&x + r <= W && 0 <= y - r&&y + r <= H) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 3076
from collections import deque
H, W = map(int, input().split())
maze = [[0 for i in range(W)]for j in range(H)]
ans = -1
for i in range(H):
    S = input()
    for j in range(W):
        maze[i][j] = S[j]
        if maze[i][j] == '.':
            ans += 1

q = deque()
q.append([0, 0])
maze[0][0] = 0
while len(q) != 0:
    x, y = q.popleft()
    for i in range(4):
        nx, ny = x + [0, 1, 0, -1][i], y + [1, 0, -1, 0][i]
        if nx < 0 or ny < 0 or nx >= W or ny >= H:
            continue
        elif maze[ny][nx] == '#':
            continue
        elif maze[ny][nx] == '.':
            maze[ny][nx] = maze[y][x] + 1
            q.append([nx, ny])
if maze[H-1][W-1] == '.':
    print(-1)
else:
    print(ans - maze[H-1][W-1])



Measured memory_bytes: 3316
h, n = map(int, input().split())
inf = 10**12
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
dp = [[inf for i in range(h+1 + 10**4)] for j in range(n+1)]
for i in range(n):
    dp[i][0] = 0
for i in range(n):
    a, b = data[i]
    for j in range(h+1+10**4):
        if j - a >= 0:
            dp[i+1][j] = min(dp[i+1][j-a] + b, dp[i][j])
        else:
            dp[i+1][j] = min(b, dp[i][j])
print(dp[-1][h])

Measured memory_bytes: 270088
// syakyo http://d.hatena.ne.jp/simezi_tan/20120906/1346880190

#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int n;
double x[100], y[100], v[100];

inline double d(int i, double a, double b){
    return sqrt((x[i] - a)*(x[i] - a) + (y[i] - b)*(y[i] - b));
}

inline double g(double a, double b){
    double res = 0;
    rep(i, n){
        res = max(res, d(i, a, b)/v[i]);
    }
    return res;
}

inline double f(double x){
    double l = 0, r = 100, a, b;
    double ans;
    rep(i, 100){
        a = (l * 2 + r) / 3;
        b = (l + r * 2) / 3;
        if ((ans = g(x, a)) > g(x, b)) l = a;
        else r = b;
    }
    return ans;
}

int main(){
    while (cin >> n, n){
        rep(i, n){
            cin >> x[i] >> y[i] >> v[i];
        }
        double l = 0, r = 100, a, b;
        double ans;
        rep(i, 100){
            a = (l * 2 + r) / 3;
            b = (l + r * 2) / 3;
            if ((ans = f(a)) > f(b)) l = a;
            else r = b;
        }
        cout << fixed << setprecision(20);
        cout << f(l) << endl;
    }
}

Measured memory_bytes: 1292
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w,q,d[2010][2010],x[2010][2010],y[2010][2010];
bool m[2010][2010];
int main(){
	cin>>h>>w>>q;
	rep(i,h)rep(j,w){
		char z;cin>>z;m[i][j]=(z=='0')?0:1;
		d[i][j]=0,x[i][j]=0,y[i][j]=0;
	}
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
		d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]+m[i-1][j-1];
		x[i][j]=x[i-1][j]+x[i][j-1]-x[i-1][j-1];
		if(j<w)x[i][j]+=(m[i-1][j-1]&m[i-1][j]);
		y[i][j]=y[i-1][j]+y[i][j-1]-y[i-1][j-1];
		if(i<h)y[i][j]+=(m[i-1][j-1]&m[i][j-1]);
	}
	while(q--){
		int a,b,f,g;cin>>a>>b>>f>>g;a--,b--;
		int k=d[f][g]+d[a][b]-d[f][b]-d[a][g];
		k-=x[f][g-1]+x[a][b]-x[f][b]-x[a][g-1];
		k-=y[f-1][g]+y[a][b]-y[f-1][b]-y[a][g];
		cout<<k<<endl;
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> data(N, vector<int>(N - 1));
	for (int n = 0; n < N; ++n) {
		for (int m = 0; m < N - 1; ++m) {
			int num;
			cin >> num;
			num--;
			data[n][m] = num;
		}
		reverse(data[n].begin(), data[n].end());
	}
	vector<pair<int,int>>q;
	auto check = [&](int i) {
		if (0 == data[i].size()) {
			return;
		}	
		int j = data[i].back();
		if (0 == data[j].size()) {
			return;
		}
		if (i == data[j].back()) {
			q.push_back(make_pair(min(i,j),max(j,i)));
		}
	};
	for (int i = 0; i < N; ++i){
		check(i);
	}
	int day = 0;
	while (q.size() > 0) {
		day++;
		sort(q.begin(), q.end());
		q.erase(unique(q.begin(), q.end()), q.end());
		vector<P> prevQ;
		swap(prevQ, q);
		for (P p : prevQ) {
			int i = p.first, j = p.second;
			data[i].pop_back();
			data[j].pop_back();
		}
		for (P p : prevQ) {
			int i = p.first, j = p.second;
			check(i);
			check(j);
		}
	}
	rep(i, N) {
		if (data[i].size() != 0) {
			puts("-1");
			return 0;
		}
	}
	cout << day << endl;
	return 0;
}

Measured memory_bytes: 7544
#include <stdio.h>

main(){
  int m, n, i, count;
  char s[1000005];
  int t[1000005];

  while(1){
    scanf("%d", &n);
    if(n==0) break;
    getchar();

    scanf("%d", &m);
    getchar();

    scanf("%s", s);

    t[0]=t[1]=0;

    for(i=2;i<m;i++){
      if(s[i]=='I'){
        if(s[i-1]=='O' && s[i-2]=='I') t[i]=t[i-2]+1;
        else t[i]=0;
      }
      else t[i]=0;
    }
    
    count=0;
    
    for(i=0;i<m;i++){
      if(t[i]>=n) count++;
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[3],b[3];
int main()
{
	int i,j;
	for(i=1;i<=3;i++){
		cin>>a[i];
	}
	for(int j=1;j<=3;j++){
		cin>>b[j];
	}
	if(a[1]==b[3]&&a[3]==b[1]&&a[2]==b[2]) cout<<"YES";
	else cout<<"NO";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}


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

typedef long long ll;

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = N;
    rep(i, N-1) if (S[i] == S[i+1]) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int h,w;
  cin >> h >> w;
  vvi a(h,vi(w));
  rep(i,h){
    rep(j,w){
      cin >> a.at(i).at(j);
    }
  }
  
  //queue<pair<int,int>> que;
  vector<pair<int,int>> path;
  pair<int,int> p;
  
  rep(i,h){
    if(i % 2 == 0){
      rep(j,w){
        p = make_pair(i,j);
        path.push_back(p);
      }
    }else{
      for(int j=w-1;j>=0;j--){
        p = make_pair(i,j);
        path.push_back(p);
      }
    }
  }
  
  queue<int> xx;
  queue<int> yy;
  int count = 0;
  rep(i,h*w-1){
    int x,y,nx,ny;
    tie(x,y) = path.at(i);
    tie(nx,ny) = path.at(i+1);
    
    if(a.at(x).at(y) % 2 == 1){
      //cout << x << " " << y << " " << nx << " " << ny;
      xx.push(x);
      xx.push(nx);
      yy.push(y);
      yy.push(ny);
      a.at(x).at(y)--;
      a.at(nx).at(ny)++;
      count++;
    }
    /*if(!trans){
      if(a.at(x).at(y) % 2 == 1){
        cout << x << " " << y << " " << nx << " " << ny;
        trans = true;
      }
    }else if(trans){
      
    }*/
  }
  cout << count << endl;
  while(!xx.empty()){
    int x,y,nx,ny;
    x = xx.front();
    xx.pop();
    nx = xx.front();
    xx.pop();
    y = yy.front();
    yy.pop();
    ny = yy.front();
    yy.pop();
    cout << x+1 << " " << y+1 << " " << nx+1 << " " << ny+1 << endl;
  }
}

Measured memory_bytes: 7152
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(vector<int>& A) {
        sort(A.begin(), A.end());
        int n = A.size();
        vector<int> res(n, 0);
        vector<int> B;
        for (int i = 0; i < n; ++i) {
            int cnt = 1;
            while (i + 1 < n && A[i + 1] == A[i]) {
                ++i;
                ++cnt;
            }
            B.push_back(cnt);
        } 
        sort(B.begin(), B.end());

        int m = B.size();
        vector<int> acc(m + 1, 0);
        for (int i = 0; i < m; ++i) {
            acc[i + 1] = acc[i] + B[i];
        }

        auto count = [&](const vector<int>& B, int K) {
            int n = B.size();
            
            int lo = 0, hi = acc[n];

            while (lo < hi) {
                auto mi = (lo + hi + 1) / 2;
                
                auto it = lower_bound(B.begin(), B.end(), mi);
                int idx = it - B.begin();
                int sum = acc[idx] + (n - idx) * mi;
                int cnt = sum / K;
                // cout << mi << " " << cnt << " " << sum << " " << hi  <<  endl;
                if (cnt >= mi) {
                    lo = mi;
                } else {
                    hi = mi - 1;
                }

            }
            return lo;
        };


        for (int i = 0; i < m; ++i) {
            res[i] = count(B, i + 1);
        }

        return res;
    }
};

int main(int argc, char** argv) {
    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];
    }
    Solution sol;
    auto res = sol.solve(A);
    for (auto r : res) {
        cout << r << "\n";
    }

    return 0;
}

Measured memory_bytes: 4976
import math

N, M = map(int, input().split())
if N == M:
    ans = (math.factorial(N) ** 2) * 2
elif abs(N - M) == 1:
    x = max(N, M)
    ans = (math.factorial(x) ** 2) // x
else:
    ans = 0
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 10624
import numpy as np

N,K = map(int, input().split())

ls = input().split()
ls_arr = np.zeros(N)
for i in range(N):
  ls_arr[i] = int(ls[i])

ls_arr = np.sort(ls_arr)[::-1]

ans = int(ls_arr[:K].sum())

print(ans)


Measured memory_bytes: 18484
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
# Written by NoKnowledgeGG @YlePhan
 
#import math
#mod = 10**9+7
 
 
 
def main():
  n = int(input())
  a = list(map(int,input().split()))
  cnt = 0
  while True:
    for i in range(n):
      if a[i] % 2 == 0:
        a[i] //= 2
      else:
        print(cnt)
        exit()
    cnt += 1
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 10000000
#define ll long long
using namespace std;

int main(){
    ll n;
    cin>>n;
    map<ll,ll> data;
    for(ll i=0; i<n; i++){
        ll p;
        cin>>p;
        data[p]++;
    }
    
    ll ans=0;
    for(auto i=data.begin(); i!=data.end(); i++){
        for(auto j=i; j!=data.end(); j++){
            if(i==j) continue;
            for(auto k=j; k!=data.end(); k++){
                if(i==k) continue;
                if(j==k) continue;
                bool p=true;
                if(i->first==j->first) p=false;
                if(i->first==k->first) p=false;
                if(k->first==j->first) p=false;
                if(i->first>=j->first+k->first) p=false;
                if(j->first>=i->first+k->first) p=false;
                if(k->first>=i->first+j->first) p=false;
                if(p) ans+=i->second*j->second*k->second;
            }
        }
    }
    
    cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, maxa = -101, mina = 101, ans = INF, tot;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] > maxa) maxa = a[i];
    if (a[i] < mina) mina = a[i];
  }

  if (maxa == mina) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = mina; i <= maxa; ++i) {
    tot = 0;
    for (int j = 0; j < n; ++j) {
      tot += (i - a[j]) * (i - a[j]);
    }
    ans = min(ans, tot);
  }

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


Measured memory_bytes: 256