akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

#include <vector>
#include<memory>
using namespace std;
struct po {
	int index;
	vector<int> coors;
	po(int _d):coors(_d) {
		index = -1;
	}
	po() {}
};
template<class T>
class axisSorter {
	int k;
public:
	axisSorter(int _k) : k(_k) {}
	bool operator()(const T &a, const T &b) {
		return a.coors[k] < b.coors[k];
	}
};
long long int getdis(const po&l, const po&r) {
	long long int dis = 0;
	for (int i = 0; i < l.coors.size(); ++i) {
		dis += (l.coors[i] - r.coors[i])*(l.coors[i] - r.coors[i]);
	}
	return dis;
}
template<class T, int Dim = 2>
struct kdtree {
public:
	T val;
  shared_ptr<kdtree<T>> ltree, rtree;
	int depth;
	int axis;
	kdtree(const T &p_) :val(p_), ltree(nullptr), rtree(nullptr) {

	}

	kdtree(vector<T>&ps_, const int& l, const int& r, const int depth_ = 0) : ltree(nullptr), rtree(nullptr), depth(depth_), axis(depth%Dim) {
		init(ps_, l, r);
	}
~kdtree() {
}

//????????????????±??????????
void get_closest(const T& apo,int r, long long int &ans) {
	if (getdis(apo, val) <= r*r)ans++;
	axisSorter<T> as(axis);
	if (as(apo, val) || val.coors[axis] == apo.coors[axis]) {
		if (ltree)ltree->get_closest(apo, r,ans);
		long long int dis = apo.coors[axis] - val.coors[axis];
		if (dis*dis > r*r)return;
		else {
			if (rtree)rtree->get_closest(apo, r,ans);
		}
	}
	else {
		if (rtree)rtree->get_closest(apo,r, ans);
		long long int dis = val.coors[axis] - apo.coors[axis];
		if (dis*dis > r*r)return;
		else {
			if (ltree)ltree->get_closest(apo,r, ans);
		}
	}
}
private:
	void init(vector<T>&ps, const int& l, const int& r) {
		if (l >= r) {
			return;
		}
		const int mid = (l + r) / 2;
		nth_element(ps.begin() + l, ps.begin() + mid, ps.begin() + r, axisSorter<T>(axis));
		val = ps[mid];
		ltree = make_kdtree(ps, l, mid, depth + 1);
		rtree = make_kdtree(ps, mid + 1, r, depth + 1);
	}

};
//[l..r)
template<class T>
unique_ptr<kdtree<T>>make_kdtree(vector<T>&ps_, const int& l, const int& r, const int& depth = 0) {
	if (l >= r)return nullptr;
	else {
		return make_unique<kdtree<T>>(ps_, l, r, depth);
	}
}

int main() {
	while (1) {
		int AN, BN, R; cin >> AN >> BN >> R;
		if (!AN&&!BN)break;
		R *= 4;
		long long int ans = 0;
		vector<po>pos;
		for (int i = 0; i < AN; ++i) {
			int x, y; cin >> x >> y;
			pos.push_back(po{ 2 });
			pos[i].coors[0] = x;
			pos[i].coors[1] = y;
		}
		auto tree(make_kdtree(pos, 0, AN));
		for (int i = 0; i < BN; ++i) {
			int x, y; cin >> x >> y;
			po apo = po{ 2 };
			apo.coors[0] = x; 
			apo.coors[1] = y;
			tree->get_closest(apo, R, ans);
		}
		cout << ans << endl;
	}
	

	return 0;
}

Measured memory_bytes: 26232
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String S=scan.next();
		String s="Sunny";
		String c="Cloudy";
		String r="Rainy";
		if(S.equals(s)){
			System.out.print("Cloudy");
		}
		else if(S.equals(c)){
			System.out.print("Rainy");
			
		}
		else if(S.equals(r)){
			System.out.print("Sunny");
		}

	}

}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, K; cin >> N >> K;
	string S; cin >> S;
	string ans = S;

	string T(S.rbegin(), S.rend());
	string U = S + T;
	char a = *min_element(S.begin(), S.end());

	if (K == 1) {
		for (int i = 0; i <= N; i++) {
			ans = min(ans, string(U.begin() + i, U.begin() + i + N));
		}
		cout << ans << '\n';
		return 0;
	} else {
		for (int i = 0; i <= N; i++) {
			string cur = string(U.begin() + i, U.begin() + i + N);
			int cnt = 0;
			while (!cur.empty() && cur.back() == a) {
				cur.pop_back();
				cnt++;
			}
			if (cnt == 0) continue;
			for (int z = 0; cnt < N && z < K-1; z++) {
				cnt = min(cnt * 2, N);
			}
			string cnd(cnt, a);
			cnd += string(cur.rbegin(), cur.rend());
			ans = min(ans, string(cnd.begin(), cnd.begin() + N));
		}
		cout << ans << '\n';
	}

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int H,W;
	int i,j;
	while(1){
	scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			break;
		}
	for(i=0;i<H;i++){
		for(j=1;j<W;j++){
			printf("#");
				}
		printf("#\n");
			}
		printf("\n");
		}
	return 0;
}

Measured memory_bytes: 588
import java.util.BitSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
//	public static int[][][] cost;
	public static int[][] dx = {
		{1, 1, 2, 1, 2, 3, 1, 2, 1},
		{-1, -1, -2, -1, -2, -3, -1, -2, -1},
	};
	public static int[][] dy = {
		{-2, -1, -1, 0, 0, 0, 1, 1, 2},
		{-2, -1, -1, 0, 0, 0, 1, 1, 2}
	};
	
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		final int INF = (int)1e8;
		while(true){
			int w = in.nextInt();
			int h = in.nextInt();
			if(w == 0) break;
			char[][] map = new char[h][w];
			Queue<Pos> slist = new LinkedList<Pos>();
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					map[i][j] = in.next().charAt(0);
					if(map[i][j] == 'S'){
						slist.add(new Pos(i*w+j, j, i, 0, 0));
						slist.add(new Pos(i*w+j, j, i, 1, 0));
						// state: 0:left 1:right
					}
				}
			}
//			cost = new int[2][h][w];
			BitSet[] used = new BitSet[2];
			used[0] = new BitSet(h*w);
			used[1] = new BitSet(h*w);
			int res = INF;
			while(!slist.isEmpty()){
				Pos start = slist.poll();
				Queue<Pos> qu = new PriorityQueue<Pos>();
				qu.add(start);
				used[0].clear();
				used[1].clear();
				while(!qu.isEmpty()){
					Pos p = qu.poll();
					if(used[p.state].get(p.id)) continue;
					used[p.state].set(p.id);
					for(int i=0; i<9; i++){
						int nx = p.x + dx[p.state][i];
						int ny = p.y + dy[p.state][i];
						if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
						if(map[ny][nx] == 'S' || map[ny][nx] == 'X') continue;
						if(map[ny][nx] == 'T'){
							res = Math.min(res, p.dist);
							continue;
						}
						int d = map[ny][nx] - '0';
						qu.add(new Pos(ny*w+nx, nx, ny, p.state==0?1:0, p.dist+d));
					}
				}
			}
			System.out.println(res==INF?-1:res);
		}
		in.close();
	}
}

class Pos implements Comparable<Pos>{
	int id, x, y, state, dist;
	public Pos(int id, int x, int y, int state, int dist){
		this.x = x;
		this.y = y;
		this.id = id;
		this.dist = dist;
		this.state = state;
	}
	
	@Override
	public int compareTo(Pos o) {
		return dist - o.dist;
//		return Main.cost[state][y][x] - Main.cost[o.state][o.y][o.x];
	}
}

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

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	for (int k = 0; k < K; k++) {
		int M = max(C, max(A, B));
		if (M == A) A = 2 * A;
		else if (M == B) B = 2 * B;
		else if (M == C) C = 2 * C;
	}

	cout << A + B + C << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n,m=MI()
if n>m:
    n,m=m,n
#print(n)
if n==1:
    if m==1:
        ans=1
    else:
        ans=m-2
else:
    ans=n*m-2*(n+m-2)
print(ans)

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

using namespace std;

int main(void){
  vector<int> num(3);

  int i;
  for(i=0; i<3; i++)
    cin >> num[i];

  sort(num.begin(), num.end());

  cout << 10*num[2] + num[1] + num[0] << endl;  

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final char[] s = sc.next().toCharArray();
        for (int i = 0; i < s.length; i++) {
            if (s[i] == (i%2==0? 'L': 'R')) {
                System.out.println("No");
                return;
            }
        } System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
const ll mod = 1e9+7;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll ans[2019];
int main() {
    string S;
    
    cin >> S;
    reverse(ALL(S));
    int r = 0, s = 1;
    ans[0]++;
    rep(i, S.length()){
        r += s * (S[i] - '0');
        r %= 2019;
        //cout << i << " " << r << endl;
        ans[r]++;
        s *= 10;
        s %= 2019;
    }
    ll a = 0;
    rep(r, 2019){
        if (ans[r] >= 2){
            //cout << r << " " << ans[r] << endl;
            a += ans[r] * (ans[r] - 1)/2;
        }
    }
    cout << a;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	int a[n];
	For(i,n) {
		cin >> a[i];
	}

	bool lose[k+1];
	For(i,k+1) {
		lose[i] = true;
		For(j,n) {
			if (i-a[j] >= 0) {
				lose[i] &= !lose[i-a[j]];
			}
		}
	}
	cout << (lose[k] ? "Second" : "First") << nl;

	return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <class T>
T gcd(T a, T b){
	if(a < b)swap(a, b);
	while(b){
		a = a % b;
		swap(a, b);
	}
	return a;
}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		int x;
		for(int i=0; i < n; i++){
			if(i == 0)cin >> x;
			else{
				int y;
				cin >> y;
				x = gcd(x,y);
			}
		}
		cout << x << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc121/tasks/abc121_c

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    ll sum = 0;
    cin >> n >> m;
    vector<PLL> v;
    v.resize(n);

    for (int i = 0; i < n; i++) {
        // 金額、本数
        cin >> v[i].first >> v[i].second;
    }
    //昇順ソート
    sort(ALL(v));

    for (const auto& e : v) {
        ll price = e.first;
        ll count = e.second;
        if (m <= count) {
            sum += (price * m);
            break;
        } else {
            sum += price * count;
            m -= count;
        }
    }

    cout << sum << endl;

    return 0;
}


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

// ------ Class ------ //
class Graph2 {
public:
	// ------ Variables ------ //
	static const long long INF = 1000000000000000000;
	int V, E; vector<vector<pair<int, long long> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, long long> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, long long> > >(v)) {}
	Graph2(vector<vector<pair<int, long long> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, long long w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, long long w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, long long> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	vector<long long> dist(int s) {
		priority_queue<pair<long long, int> > que; que.push(make_pair(0, s));
		vector<long long> d(V, INF); d[s] = 0;
		while (!que.empty()) {
			pair<long long, int> t = que.top(); que.pop();
			int u = t.second;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first; long long e = G[u][i].second;
				if (d[v] > d[u] + e) {
					d[v] = d[u] + e;
					que.push(make_pair(-d[v], v));
				}
			}
		}
		return d;
	}
};

// ------ Main ------ //
int n, m, a, b, c;
int main() {
	cin >> n >> m;
	Graph2 G(n);
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		G.add1(a, b, -c);
	}
	cout << -G.dist(0)[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3084
N,M,P = map(int,input().split())
edge = []
cost = [-float('inf')]*N
cost[0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    edge.append([a-1,b-1,c-P])

for i in range(N-1):
    for a,b,c in edge:
        cost[b] = max(cost[b],cost[a]+c)


for a,b,c in edge:
    if cost[b] < cost[a]+c:
        cost[b] = float('inf')


for i in range(N-1):
    for a,b,c in edge:
        cost[b] = max(cost[b],cost[a]+c)

if cost[-1] == float('inf'):
    print(-1)
else:
    print(max(cost[-1],0))

Measured memory_bytes: 57688
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int MaxN = 1e5;

long long a[MaxN + 5],biu[MaxN + 5],piu[MaxN + 5];

int main()
{
	long long n,x,ans;
	while(~scanf("%lld",&n))
	{
		a[0] = 0;
		a[n+1] = 0;
		ans = 0;
		for(long long i = 1;i <= n;i++)
		{
			scanf("%lld",&a[i]);
			piu[i] = abs(a[i]-a[i-1]);
			ans += piu[i];
		}
		piu[n+1] = abs(a[n]);
		ans += piu[n+1];
		for(long long i = 1;i <= n;i++)
		{
			biu[i] = abs(a[i+1]-a[i-1]);
			printf("%lld\n",ans-piu[i]-piu[i+1]+biu[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3456
from itertools import product
S = input().strip()
N = len(S)
cnt = 0
for x in product((0,1),repeat=N-1):
    y = S[0]
    for i in range(N-1):
        if x[i]==1:
            y += "+"
        y += S[i+1]
    cnt += eval(y)
print(cnt)

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

using namespace std;

const int N = 400 + 77 , L = 30;
int n , m , P[N * N] , X[N * N] , Y[N * N];
int dx[4] = {0 , 0 , - 1 , 1} , dy[4] = {1 , - 1 , 0 , 0};
long long A;
char S[N][N];
int Find(int x){
   return P[x] == 0 ? x : (P[x] = Find(P[x]));
}
inline void Merge(int x , int y){
   x = Find(x);
   y = Find(y);
   if(x == y)
      return ;
   X[x] += X[y] , X[y] = 0;
   Y[x] += Y[y] , Y[y] = 0;
   P[y] = x;
}
int main(){
   //ios::sync_with_stdio(0);cin.tie(0);
   scanf("%d %d" , & n , & m);
   for(int i = 1;i <= n;++ i)
      scanf("%s" , S[i] + 1);
   for(int i = 1;i <= n;++ i)
      for(int j = 1;j <= m;++ j){
         if(S[i][j] == '#')
            X[i * N + j] = 1;
         else
            Y[i * N + j] = 1;
      }
   for(int i = 1;i <= n;++ i)
      for(int j = 1;j <= m;++ j){
         for(int k = 0;k < 4;++ k){
            int ni = i + dx[k] , nj = j + dy[k];
            if(ni == 0 || nj == 0 || ni == n + 1 || nj == m + 1)
               continue ;
            if(S[i][j] != S[ni][nj])
               Merge(i * N + j , ni * N + nj);
         }
      }
   for(int i = 0;i < N * N;++ i)
      if(P[i] == 0)
         A += X[i] * 1ll * Y[i];
   cout << A;
   return 0;
}



Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)
#define ff first
#define ss second
#define sz(a) (lli)(a.size())
lli inf = (1e18 + 2);

int main()
{
	lli x,k,d;
	cin>>x>>k>>d;
	lli val = x;

	if(val < 0)
		val = -val;

	if((k) <= (val/d))
	{
		cout<<(val - (k*d))<<endl;
		return 0;
	}

	k -= (val/d);
	val %= d;

	if(k % 2 == 0)
		cout<<val<<endl;
	else
		cout<<(d-val)<<endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int a[4];

bool calc(int bit)
{
    int num = a[0];
    rep(i, 3)
    {
        if (bit & (1 << i))
            num += a[i + 1];
        else
            num -= a[i + 1];
    }
    if (num == 7)
    {
        cout << a[0];
        rep(i, 3)
        {
            if (bit & (1 << i))
                cout << "+";
            else
                cout << "-";
            cout << a[i + 1];
        }
        cout << "=7" << endl;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;
    rep(i, 4) a[i] = s[i] - '0';
    for (int i = 0; i < (1 << 3); i++)
        if (calc(i))
            return 0;
}


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

using namespace std;

typedef pair<int, int> pii;
int vis[123456];
pii v[123456];
bool cmp(const pii& a, const pii& b){
    if(a.first != b.first)return a.first < b.first;
    return a.second < b.second;
}
int main(){
    int n, m, x, y;
    cin >> n >> m;
    memset(vis, 0, sizeof(vis));
    memset(v, 0, sizeof(v));
    int t = 0;
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        cin >> v[i].second >> v[i].first;
    }
    sort(v, v+m, cmp);
    int l = -1;
    for (int i = 0; i < m; ++i) {
        int r = v[i].first;
        if(l >= v[i].second + 1)continue;
        l = v[i].second + 1;
        bool flag = false;
        while (l < r){
            l++;
            if(vis[l]){
                flag = true;
                break;
            }
        }
        if(!flag)vis[l] = 1;
//        cerr << l << " " << r << endl;
    }
    for (int i = 1; i <= n; ++i) {
//        cerr << i << " " << vis[i] << endl;
        if(vis[i])sum ++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1664
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  la = list(map(int, input().split()))
  lb = list(map(int, input().split()))
  lc = list(map(int, input().split()))
  la.sort(), lb.sort(), lc.sort()
  
  i = 0
  ab = []
  for b in lb:
    while i < n and la[i] < b:
      i += 1
    ab.append(i)
      
  i = 0
  bc = []
  for c in lc:
    while i < n and lb[i] < c:
      i += 1
    bc.append(i)
    
  ans = 0
  cs = [0]
  for x in ab:
    cs.append(cs[-1] + x)
  for y in bc:
    ans += cs[y]
  print(ans)
  

if __name__=='__main__':
  main()



Measured memory_bytes: 27444
import math
n = int(input())
a=[]
for i in range(n):
  a.append(int(input()))
def isprime(x):
  if x == 2:
    return True
  if x < 2 or (x%2) == 0:
    return False
  i = 3
  while i <= math.sqrt(x):
    if (x%i) == 0:
      return False
    i += 2
  return True
b=0
for ai in a:
  if isprime(ai) == True:
    b += 1
print(b)


Measured memory_bytes: 6036
use std::collections::HashSet;

macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn neighbors(set: &HashSet<usize>, list: &Vec<HashSet<usize>>) -> HashSet<usize> {
    let mut ret: HashSet<usize> = HashSet::new();

    for x in set.iter() {
        ret.insert(*x);
        for y in list[*x].iter() {
            ret.insert(*y);
        }
    }

    ret
}

fn main() {
    loop {
        let n = get!(usize);
        let m = get!(usize);
        if n == 0 && m == 0 { break }

        let list = get!(usize, usize; m);

        let mut graph: Vec<HashSet<usize>> = Vec::with_capacity(n);
        for _i in 0..n {
            graph.push(HashSet::new());
        }

        for x in &list {
            let (mut a, mut b) = x.clone();
            a -= 1;
            b -= 1;
            let mut s = graph[a].clone();
            s.insert(b);
            graph[a] = s;
            let mut s = graph[b].clone();
            s.insert(a);
            graph[b] = s;
        }

        let mut me: HashSet<usize> = HashSet::new();
        me.insert(0);

        let friend = neighbors(&me, &graph);
        let friend = neighbors(&friend, &graph);

        let ans: usize = friend.difference(&me).collect::<HashSet<_>>().len();

        println!("{}", ans);
    }
}



Measured memory_bytes: 5056
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <utility>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long  
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

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

int a[100000];
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		cin >> a[i];
	}
	sort(a,a+n,greater<int>());
	bool flg = false;
	pair<int,int> pi = make_pair(0,0);
	for(int i = 1;i<n;++i){
		if(a[i] == a[i-1] && flg){
			pi.second = a[i];
			break;
		}
		else if(a[i] == a[i-1]){
			pi.first = a[i];
			++i;
			flg = true;
		}
	}
	cout << pi.first * pi.second << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <string.h>

#define HMAX 1001
#define WMAX 1001

using namespace std;

string a[HMAX];
long long int dp[HMAX][WMAX];
long long int finish[HMAX][WMAX];

long long int dp_func(int i, int j){
  if(finish[i][j]>0){
    return dp[i][j];
  }else if(a[i][j-1]=='#'){
    finish[i][j]=1;
    return 0;
  }else if(i*j==0){
    return 0;
  }else{
    finish[i][j]=1;
    dp[i][j]=(dp_func(i-1,j)+dp_func(i, j-1))%1000000007;
    return dp[i][j];
  }
}

int main(void){
  int H, W;
  cin >> H >> W;
  for(int i=1;i<=H;i++){
    cin >> a[i];
  }
  dp[1][1]=1;
  finish[1][1]=1;
  cout << dp_func(H, W);
  return 0;
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
int fac[N],inv[N];
inline int qpow(int x,int y){int A=1;for(;y;y>>=1,x=(ll)x*x%mod)if(y&1)A=(ll)A*x%mod;return A;}
inline int C(int x,int y){return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;}
int main()
{	ll k,a,b; int n,ans=0; cin>>n>>a>>b>>k;
	fac[0]=inv[0]=1; for(rint i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%mod,inv[i]=qpow(fac[i],mod-2);
	for(rint i=0;i<=n;i++)
	if((k-a*i)%b==0&&0<=(k-a*i)/b&&(k-a*i)/b<=n) (ans+=(ll)C(n,i)*C(n,(k-a*i)/b)%mod)%=mod;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5504
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        final String X = "x";
        final String EQUAL = "=";
        final String RETURN_MARK = "\r\n";
        StringBuilder sb = new StringBuilder();

        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                sb.append(i).append(X).append(j).append(EQUAL).append(i * j)
                        .append(RETURN_MARK);
            }
        }

        System.out.print(sb);
    }
}

Measured memory_bytes: 16996
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

#define DEBUG_ENABLED 0

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

    int N;
    cin >> N;

    // a[0] tells always true or false.
    // a0, a1, a2, ...
    // 1 1 0,   <- bit search it.

    vector<vector<pair<int, int>>> all_sayings;

    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        vector<pair<int, int>> tmp;
        for (int j = 0; j < a; j++)
        {
            int x, y;
            cin >> x >> y;
            pair<int, int> t = make_pair(x, y);
            tmp.push_back(t);
        }
        all_sayings.push_back(tmp);
    }

    // int max = numeric_limits<int>::min();
    int max = 0;

    for (int bit = 0; bit < (1 << N); ++bit)
    {
        long long mask = 0;

        if (DEBUG_ENABLED)
            cout << "---" << bit << endl;
        int is_truth_teller[N];
        for (int i = 0; i < N; ++i)
        {
            if (bit & (1 << i))
            {
                mask |= (1 << i);
            }

            is_truth_teller[i] = __builtin_popcount(bit & (1 << i));
            if (DEBUG_ENABLED)
                cout << "i: " << i << " is_truth_teller:" << is_truth_teller[i] << endl;
        }
        std::bitset<64> y(mask);
        if (DEBUG_ENABLED)
            cout << y << endl;

        // check
        bool is_acceptable = true;
        for (int i = 0; i < N && is_acceptable; ++i)
        {
            auto sayings = all_sayings.at(i);
            for (auto &p : sayings)
            {
                int who = p.first - 1;
                int s = p.second;
                // cout << "is_truth_teller[i]:" << is_truth_teller[i] << " who:" << who << " s:" << s << " is_truth_teller[who]:" << is_truth_teller[who] << endl;

                if (is_truth_teller[i])
                {
                    if (is_truth_teller[who] != s)
                    {
                        is_acceptable = false;
                        break;
                    }
                }
            }
        }
        if (is_acceptable)
        {
            int truth_tellers = __builtin_popcount(mask);
            if (max < truth_tellers)
            {
                max = truth_tellers;
            }
        }
    }

    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
//
// Created by 佐竹俊哉 on 2019/11/12.
//

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

const int INF = TEN(9);
int dp[1010][1<<12];

int main() {
    rep(i, 1010) rep(j, 1 << 12) dp[i][j] = INF;
    dp[0][0] = 0;
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        int mask = 0;
        rep(j, b) {
            int x; cin >> x;
            --x;
            mask |= (1 << x);
        }
        rep(j, 1<<N) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j|mask], dp[i][j] + a);
        }
    }
    int ans = dp[M][(1<<N)-1];
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

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

const int maxn = 2005;

string s[maxn];

long long get(vector<int> &v){
	stack<int> st;
	int n = v.size(); 
	int ans = 0, i = 0;
	while(i < n){
		if(st.empty() || v[st.top()] <= v[i]){
			st.push(i++);
		}else {
			int x = st.top();
			st.pop();
			ans = max(ans, (v[x] + 1) * (st.empty() ? i + 1 : i - st.top()));
		}
	}
	while(!st.empty()){
		int x = st.top();
		st.pop();
		ans = max(ans, (v[x] + 1) * (st.empty() ? i + 1 : i - st.top()));
	}
	return ans;
}

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> s[i];
	}
	vector<vector<int>> v;
	for(int i = 0; i < n - 1; ++i){
		vector<int> vv;
		for(int j = 0; j < m - 1; ++j){
			int cnt = 0;
			if(s[i][j] == '#')++cnt;
			if(s[i + 1][j] == '#')++cnt;
			if(s[i][j + 1] == '#')++cnt;
			if(s[i + 1][j + 1] == '#')++cnt;
			vv.push_back((cnt % 2 == 0));
		}
		v.push_back(vv);
	}
	vector<int> pass(m - 1);
	long long ans = max(n, m);
	for(int i = 0; i < n - 1; ++i){
		for(int j = 0; j < m - 1; ++j){
			if(v[i][j] == 1){
				pass[j]++;
			}else {
				pass[j] = 0;
			}
		}
		ans = max(ans, get(pass));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 20096
N = int(input())

c1, c2, c4 = 0, 0, 0
a = list(map(int, input().split()))

for i in a:
    if i % 4 == 0:
        c4 += 1
    elif i % 2 == 0:
        c2 += 1
    else:
        c1 += 1

if c2:
    print("Yes" if c4 >= c1 else "No")
else:
    print("Yes" if c4 and c4 + 1 >= c1 else "No")

Measured memory_bytes: 14480
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF=(int)1e9;

int main(){
    //入力パート
    int n; cin>>n;
    vector<pair<int,int>> tonari[110]; //隣接リスト 一つ目が行先の頂点で二つ目が辺のコスト
    vector<int> dist(n,INF); //各頂点の（暫定）最短距離を格納
    vector<bool> det(n,false); //各頂点の最短距離が確定しているか格納
    for(int i=0;i<n;++i){
        int u,k,c,v;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>c>>v;
            tonari[u].push_back(make_pair(c,v));
        }
    }
    //探索パート
    dist[0]=0; //出発地点の最短距離は0
    for(int i=0;i<n;++i){
        int mini=INF,mini_node=-1; //未確定点の最短距離とその頂点番号を格納
        for(int j=0;j<n;++j){ //最短距離が最小の点を探索
            if(det[j]) continue; //確定している点は対象外
            if(dist[j]<mini){
              mini=dist[j];
              mini_node=j;
            }
        }
        det[mini_node]=true; //最短距離を確定させる
        for(pair<int,int> tsugi:tonari[mini_node]){
            dist[tsugi.first]=min(dist[tsugi.first],dist[mini_node]+tsugi.second); //隣接ノードの値の更新
        }
    }
    
    //出力パート
    for(int i=0;i<n;++i){
        cout<<i<<" "<<dist[i]<<endl;
    }
    return 0; 
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
                            for(int j=0;j<n;j++){   \
                                cout<<a[i][j]<<" "; \
                            }                       \
                            cout<<endl;             \
                        }
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
int main() {
    fast_io()

    ll n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0&&(n/i)>=1&&(n/i)<=9){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		if ((i+1) % 2) {
			cout << s[i];
		}
	}
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 512
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    for a in A:
        if a % 2 == 1:
            print("first")
            return
    print("second")


if __name__ == '__main__':
    main()


Measured memory_bytes: 7072
def main() :
  n,t = (int(i) for i in input().split())
  ni = [int(i) for i in input().split()]

  total = 0

  for i in range(1,len(ni)) :
    delta = ni[i] - ni[i-1]
    if delta < t :
      total += delta
    else :
      total += t

    
  print(total+t)

main()

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

int main()
{
  long long int X = 0;
  cin >> X;
  long long int ans = 0, now = 0, i = 1;
  while (now < X)
  {
    now += i;
    i++;
  }
  ans = i - 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll dp[100005][2];
vector<int>edge[100005];
void dfs(int v,int u){
	dp[v][0] = 1;
	dp[v][1] = 1;
	for(int i=0;i<edge[v].size();i++){
		int to = edge[v][i];
		if(u == to) continue;
		dfs(to,v);
		dp[v][0] = dp[v][0] *(dp[to][0]+dp[to][1])%mod;
		dp[v][1] = dp[v][1]*dp[to][0]%mod;
	}
}
int main(){
	cin>>n;
	rep(i,n-1){
		int a,b; cin>>a>>b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	dfs(1,-1);
	ll ans = dp[1][0]+dp[1][1];
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 14208
var
  n,a,t,c,i,x:longint;
  h:array[1..1000]of real;
  min:real;
begin
  readln(n,t,a);
  for i:=1 to n do 
  begin 
    read(c);
	h[i]:=abs(a-(t-0.006*c));
  end;
  min:=h[1];x:=1;
  for i:=2 to n do
	if h[i]<min then begin min:=h[i];x:=i;end;
  write(x);
end.

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

using namespace std;
typedef long long ll;
//typedef pair<int,int> P;

ll N,M,V,P;
ll A[100005];
ll sum[100005];
ll B[100005];

bool check(int idx){
    for (int i = 0;i < N;i++){
        B[i] = A[i];
    }
    ll val = B[idx]+M;
    B[idx] = LLONG_MAX;
    sort(B,B+N);
    for (int i = 1;i < P;i++){
        B[N-1-i]+=M;
    }
    //if(B[N-1-P] > val) return false;
    ll rem = M*(V-P);
    
    for (int i = 0;i < N-P;i++){
        //cout << rem << " ";
        if(B[i] <= val) rem -= min(val-B[i],M);
        else return false;
    }
    //cout << endl;
    return rem <= 0;
    /*sum[0] = B[0];
    for (int i = 1;i < N-1;i++){
        sum[i] = sum[i-1]+B[i];
    }
    return ((N-P)*val-sum[N-P-1]) >= M*(V-P);*/
}

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

    cin >> N >> M >> V >> P;

    for (int i = 0;i < N;i++){
        cin >> A[i];
    }

    sort(A,A+N);

    sum[0] = A[0];
    for (int i = 1;i < N;i++){
        sum[i] = sum[i-1]+A[i];
    }

    ll high = N, low = 0; //[low,high]

    while(high!=low){
        ll mid = (high+low)/2;
        if(check(mid)) high = mid;
        else low = mid+1;
    }

    cout << N-high << endl;

    return 0;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;

 if ( a+b > c+d ){
 cout << "Left" << endl;
 }
 else if ( a+b < c+d ) {
 cout << " Right " << endl;
 }
 else{ 
 cout << " Balanced " << endl;
 }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 1;
    int index = 1;
    while (index < n) {
        if (s[index] == s[index-1]) {
            index++;
        } else {
            index++;
            cnt++;
        }
    }
    cout << cnt << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

bool bo[20][1010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, K;
    cin >> H >> W >> K;
    REP(i, 0, H) {
        string s;
        cin >> s;
        REP(j, 0, W) {
            if (s[j] == '1') {
                bo[i][j] = true;
            }
        }
    }
    ll num[H];
    ll ans = inf;
    REP(bit, 0, ((ll)1 << (H - 1))) {
        ll tmpans = 0;
        bool ok = true;
        REP(i, 0, H) {
            if (bit & (1 << i)) {
                tmpans++;
            }
        }
        fill(num, num + H, 0);
        REP(i, 0, W) {
            ll base = 0;
            REP(j, 0, H) {
                if (bo[j][i]) {
                    num[base]++;
                }
                if (bit & (1 << j)) {
                    base = j + 1;
                }
            }
            bool tmpok = true;
            REP(j, 0, H) {
                if (num[j] > K) {
                    tmpok = false;
                }
            }
            if (!tmpok) {
                tmpans++;
                fill(num, num + H, 0);
                base = 0;
                REP(j, 0, H) {
                    if (bo[j][i]) {
                        num[base]++;
                    }
                    if (bit & (1 << j)) {
                        base = j + 1;
                    }
                }
                REP(j, 0, H) {
                    if (num[j] > K) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) {
            ans = min(ans, tmpans);
        }
    }
    cout << ans << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    int n, k;
    cin >> n >> k;

    if (n % k == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b;
  char op;

  while(1) {
    scanf("%d %c %d",&a,&op,&b);
    if(op == '?') break;
    if(op == '+') printf("%d\n",a+b);
    else if(op == '-') printf("%d\n",a-b);
    else if(op == '*') printf("%d\n",a*b);
    else if(op == '/') printf("%d\n",a/b);
  }

  return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<vector<ll> > p(n+1, vector<ll>(2));
	for (ll i = 0; i < n; ++i) {
		ll v, w; scanf("%lld%lld", &v, &w);
		p[i+1][0] = v; p[i+1][1] = w;
	}
	int k = 1;
	while (n > ((1<<k)-1)) k++;
	k = min(k, 10);
	int K = 1<<k;
	vector<vector<ll> > dp(K, vector<ll>(100001, 0));
	for (int i = p[1][1]; i < 100001; ++i) dp[1][i] = p[1][0];
	for (int i = 2; i < min(n+1, K); ++i) {
		for (int j = 0; j < 100001; ++j) {
			if (j >= p[i][1]) dp[i][j] = max(dp[i/2][j], dp[i/2][j-p[i][1]] + p[i][0]);
			else dp[i][j] = dp[i/2][j];
		}
	}
	int Q; cin >> Q;
	for (int q = 0; q < Q; ++q) {
		int x, l; scanf("%d%d", &x, &l);
		if (x < K) {
			printf("%lld\n", dp[x][l]);
			continue;
		}
		int par = x; int cnt = 0;
		vector<int> pars(10);
		while (par >= K) {
			pars[cnt] = par;
			par /= 2;
			cnt ++;
		}
		ll ans = dp[par][l];
		vector<vector<ll> > dp2(1<<cnt, vector<ll>(2, 0));
		for (int i = 1; i < (1<<cnt); ++i) {
			int lsb = i & (-i); int lsb_ind = 0;
			while ((1 << lsb_ind) < lsb) lsb_ind++;
			dp2[i][0] = dp2[i-lsb][0] + p[pars[lsb_ind]][0];
			dp2[i][1] = dp2[i-lsb][1] + p[pars[lsb_ind]][1];
			if (dp2[i][1] <= l) {
				ans = max(ans, dp2[i][0] + dp[par][l - dp2[i][1]]);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 821192
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int weight[10] = {1,2,4,8,16,32,64,128,256,512};
	int count[10];
	int n;


	while(cin >> n){
		bool one = 0;
		memset(count,0,sizeof(count));

		while(n != 0){
			int u = 9;
			while(n < weight[u])u--;
			n -= weight[u];
			count[u]++;
		}

		for(int i=0;i<10;i++){
			if(count[i] != 0){
				if(one)printf(" ");
				printf("%d",weight[i]);
				one = 1;
			}
		}
		printf("\n");
	}

}

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

using namespace std;

long long a,b,c;

bool process()
{
    c-=(a+b);
    if (c<=0) return false;
    long long k=a*b*4;
    c*=c;
    return (k<c);
}

int main()
{
    cin>>a>>b>>c;
    if (process()) cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

int main(){
	int k,t;
	cin >> k >> t;
	int a[t];
	int max = 0;
	for(int i = 0;i < t;i++){
		cin >> a[i];
		if(max < a[i]) max = a[i];
	}
	if(max * 2 < k + 2){
		cout << 0 << endl;
	}else{
		cout << max * 2 - k - 1 << endl;
	}
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    }
    println!("{}",a+b/2)
}

Measured memory_bytes: 2076
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

int n;
ll a[4005], x, mn[4005][4005];
ll res = INF;

int main() {
	
	cin >> n >> x;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = n + 1; i <= 2 * n; i++) {
		a[i] = a[i - n];
	}
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = i; j <= 2 * n; j++) {
			mn[i][j] = INF;
			if (i == j) mn[i][j] = a[i];
		}	
	}
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = i + 1; j <= 2 * n; j++) {
			mn[i][j] = min(mn[i][j - 1], a[j]);
		}
	}
	for (int i = 0; i <= n; i++) {
		ll val = i * x;
		for (int j = 1; j <= n; j++) {
			val += mn[j][j + i];
		}
		res = min(val, res);
	}
	cout << res;
    return 0;
}


Measured memory_bytes: 125184