akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

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

struct edge{ int to, cost; };
typedef pair<int , int> P;


int V;

int INF = 10000000;
vector<edge> G[22];
int d[22];
int m;
int a1,b1,c1,d1;

bool operator < (P a,P b){
	return a.first == b.first;
}
bool comp(P a,P b){
	return a.first < b.first;
}


void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+V, INF);
	d[s] = 0;
	que.push(P(0,s));
	
	while (!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		//cout<<" que top "<<v<<endl;
		if (d[v] < p.first) continue;
		for(int i=0;i<G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				//cout<<e.to<< " "<<d[e.to]<<endl;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	char t;
	int go,come;
	cin>>V>>m;
	rep(i,m){
		edge tmp;
		cin>>a1>>t>>b1>>t>>c1>>t>>d1;
		//cout<<a1<<endl;
		tmp.to = b1-1; tmp.cost = c1;
		G[a1-1].push_back(tmp);
		tmp.to = a1-1; tmp.cost = d1;
		G[b1-1].push_back(tmp);
	}
	/*
	rep(i,V+1){
		rep(j,G[i].size()){
			cout<<i<< " "<<G[i][j].to<< " "<<G[i][j].cost<<endl;
		}
	}
	*/
	cin>>a1>>t>>b1>>t>>c1>>t>>d1;
	dijkstra(a1-1);
	go = d[b1-1];
	
	//cout<<"go  d[i]\n";
	rep(i,V+1){
		//cout<<i<<" "<<d[i]<<endl;
	}
	
	//cout<<"go = "<< go<< endl;
	dijkstra(b1-1);
	come = d[a1-1];
	//cout << "come = " << come<< endl;
	cout<<c1-d1-go-come<<endl;
	return 0;
}

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

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

 if ((A > B && B != 1 )||(A < B && A == 1)){

  cout << "Alice" << endl;
}
  else if ( A > B && B == 1){
    cout << "Bob" << endl;
  }
  else if (A == B){ 
    cout << "Draw" << endl;
  }
  else if (A < B && A != 1 ){
    cout << "Bob" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		// Scanner scanner = new Scanner("3 5 4 2 0 0 8 8");
		Scanner scanner = new Scanner(System.in);
		int h;
		int w;
		while (true) {
			h = scanner.nextInt();
			w = scanner.nextInt();
			if (h == 0 && w == 0) {
				break;
			}
			if (0 == h % 2) {
				for (int i = 0; i < (h / 2); i++) {
					lineMaker01(w);
					lineMaker02(w);
				}
			} else {
				for (int j = 0; j < (h / 2); j++) {
					lineMaker01(w);
					lineMaker02(w);
				}
				lineMaker01(w);
			}
			System.out.println("");
		}
		// System.out.println("");
	}

	static void lineMaker01(int w) { // #.#. ??¶??°?????´???
		if (0 == w % 2) {
			for (int i = 0; i < w / 2; i++) {
				System.out.print("#");
				System.out.print(".");
			}
		} else {
			for (int i = 0; i < (w / 2); i++) {
				System.out.print("#");
				System.out.print(".");
			}
			System.out.print("#");
		}
		System.out.println("");
	}

	static void lineMaker02(int w) { // .#.# ?\???°?????´???
		if (0 == w % 2) {
			for (int i = 0; i < (w / 2); i++) {
				System.out.print(".");
				System.out.print("#");
			}
		} else {
			for (int i = 0; i < (w / 2); i++) {
				System.out.print(".");
				System.out.print("#");
			}
			System.out.print(".");
		}
		System.out.println("");

	}

}

Measured memory_bytes: 33564
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll dp[1010][10100];

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) { cin >> A[i] >> B[i]; }
    // dp[i][j]:=i個めまでみたときに、jダメージ与えるときの最小の魔力
    rep(i, N + 1) rep(j, H + 1) dp[i][j] = LINF;
    rep(i, N + 1) dp[i][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= H; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][min(H, j + A[i])] =
                min(dp[i + 1][min(H, j + A[i])], dp[i + 1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];

    vector<vector<int> > ans(h, vector<int> (w));
    rep(i, h) {
        int tmp = -1;
        rep(j, w) {
            if(field[i][j] == 'c') tmp = 0;
            ans[i][j] = tmp;
            if(tmp != -1) tmp++;
        }
    }
    rep(i, h) rep(j, w) cout << ans[i][j] << (j == w-1 ? '\n' : ' ');
    return 0;
}


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

int main(int argc, char const *argv[]) {
    int H,W;
    cin >> H >> W;
    char pixel[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> pixel[i][j];
        }
    }
    for(int i=0;i<W+2;i++){
        cout << '#';
    }
    cout << endl;
    for(int i=0;i<H;i++){
        cout << '#';
        for(int j=0;j<W;j++){
            cout << pixel[i][j];
        }
        cout << '#' << endl;
    }
    for(int i=0;i<W+2;i++){
        cout << '#';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

int main(){
	int a;scanf("%d",&a);
	printf("%d\n",(a-2)*180);
}


Measured memory_bytes: 128
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

if len(D) < len(T):
    print("NO")
    exit()
D.sort()
T.sort()
dl = Counter(D)
tl = Counter(T)
for t in tl.keys():
    if not t in dl:
        print("NO")
        exit()
    if tl[t] > dl[t]:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 169412
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
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++)

bool mycompare(const tuple<string, int, int> &lhs, const tuple<string, int, int> &rhs)
{
    if (get<0>(lhs) == get<0>(rhs))
    {
        return get<1>(lhs) > get<1>(rhs);
    }
    else
    {
        return get<0>(lhs) < get<0>(rhs);
    }
}

int main()
{
    int N;
    cin >> N;
    vector<tuple<string, int, int>> S(N + 1);
    string temps;
    int temp;
    for (int i = 1; i <= N; i++)
    {
        cin >> temps >> temp;
        S[i] = make_tuple(temps, temp, i);
    }
    sort(ALL(S), mycompare);
    for (int i = 1; i <= N; i++)
    {
        cout << get<2>(S[i]) << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int d, mans=-imax, ans;
	vector<int> c, t, ld, at, us;
	vector< vector<int> >s;

	cin>> d;

	c.resize(26);
	rep(i, 26) cin>> c[i];
	s.resize(d);
	rep(i, d){
		s[i].resize(26);
		rep(j, 26) cin>> s[i][j];
	}
	t.resize(d);
	at.resize(d);
	ld.resize(26);
	rep(i, d){
		int tmp=1, su, ma=-imax;
		rep(j, 26){
			su=s[i][j];
			rep(k, 26){
				if(j==k) continue;
				ans-=(i-ld[k]+1)*c[k];
			}

			if(ma<=su){
				tmp=j;
				ma=su;
			}
		}
		ld[tmp]=i+1;
		at[i]=tmp+1;
		//cout<< ma <<endl;
	}

	rep(i, d){
		cout<< at[i] <<endl;
	}
return 0;
	us.resize(26);
	
  	std::random_device seed_gen;
  	std::mt19937 engine(seed_gen());

	int ti = clock();
    while (clock() - ti < 185 * CLOCKS_PER_SEC / 100){
	
		rep(i, 26) us[i]=0;

    	rep(i, d){
			int rs=engine();
			rs=abs(rs)%26;
			while(us[rs]>(i+0)/26) rs=(rs+1)%26;
			us[rs]++;
			t[i]=rs;
			//PV(us);
		}
		ans=0;
		rep(i, 26) ld[i]=0;

		rep(i, d){
			ans+=s[i][t[i]];
			ld[t[i]]=i+1;
			rep(j, 26) ans-=(i-ld[j]+1)*c[j];
		}

		if(mans<ans){
			rep(i, d) at[i]=t[i]+1;
			mans=ans;
			//cout<< mans <<endl;
		}
	}

	rep(i, d) cout<< at[i] <<endl;
 
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<60);

void rotate(vl &x, vl &y, vl &p){
    ll N = x.size();
    REP(i, N) swap(x[i], y[i]);
    REP(i, N) x[i] *= -1;
    REP(i, N) p[i] = (p[i]+1)%4;
    return;
}

ll tate(vl &X, vl &Y, vl &P){
    ll res = INF;
    ll N = X.size();
    map<ll, map<ll, set<int>>> mp1;
    REP(i, N){
        mp1[X[i]][P[i]].insert(Y[i]);
    }
    for(auto &m: mp1){
        auto &r = m.second;
        for(auto s: r[1]){
            auto itr = r[3].lower_bound(s);
            if(itr != r[3].end()){
                chmin(res, (*itr-s)*5ll);
            }
        }
    }
    //dump(res)
    return res;
}

ll yoko(vl &X, vl &Y, vl &P){
    ll res = INF;
    ll N = X.size();
    map<ll, map<ll, set<int>>> mp2;
    REP(i, N){
        mp2[X[i]+Y[i]][P[i]].insert(Y[i]);
    }
    for(auto &m: mp2){
        auto &r = m.second;
        for(auto s: r[1]){
            auto itr = r[0].lower_bound(s);
            if(itr != r[0].end()){
                chmin(res, (*itr-s)*10ll);
            }
        }
    }
    //dump(res)
    return res;
}

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

    map<char, ll> mp;
    mp['R'] = 0;
    mp['U'] = 1;
    mp['L'] = 2;
    mp['D'] = 3;

    ll N;
    cin >> N;
    vl X(N), Y(N), P(N);
    REP(i, N){
        cin >> X[i] >> Y[i];
        char tmp;
        cin >> tmp;
        P[i] = mp[tmp];
    }

    ll res = INF;
    REP(t, 4){
        ll tt = tate(X, Y, P);
        ll yy = yoko(X, Y, P);
        chmin(res, tt);
        chmin(res, yy);
        rotate(X, Y, P);
    }

    if(res == INF) cout << "SAFE\n";
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 72792
#include <stdio.h>
int linearSearch(int);

int S[10000];
int n;

int main(){
  int T[500];
  int q;
  int count=0;
  int i;
  int A[500];
  

  scanf("%d",&n);
  
  for(i = 0; i < n; i++){ scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);

  for(i = 0;i< q; i++){
    scanf("%d",&T[i]);
  }

 
  
  for(i = 0; i < q; i++){
    if(linearSearch(T[i])) {
      count++;}
  }
  printf("%d\n",count);
  return 0;
}


int linearSearch(int suuzi){
  int i;
  
  for(i = 0; i < n; i++){
    
    if(S[i] == suuzi) {return 1;}
  }
  return 0;
}




Measured memory_bytes: 2108
#coding: utf-8

n = int(raw_input())

def conv1(s):
    a = 0
    st = ['i', 'x' , 'c', 'm']
    for i in range(4):
        if s.find(st[i]) != -1:
            index = s.find(st[i])
            try:
                a = a + 10 ** i * int(s[index - 1])
            except:
                a = a + 10 ** i
    return a

def conv2(num):
    re = ''
    st = ['i', 'x' , 'c', 'm']
    for i in range(4):
        a = num % 10
        num = num / 10
        if a == 0:
            continue
        elif a == 1:
            re = st[i] + re
        else:
            re = str(a) + st[i] + re
    return re

for i in range(n):
    l = raw_input().split()
    print conv2(conv1(l[0]) + conv1(l[1]))

Measured memory_bytes: 6352
#include<stdio.h>
int main()
{
	long long x,a;
	while(~scanf("%lld%lld",&x,&a)&&x>=0&&x<=9&&a>=0&&a<=9)
	{
		if(x<a)
		printf("%d\n",0);
		else
		printf("%d\n",10);
	}
}

Measured memory_bytes: 128
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
	string s[5];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < 3; i++) {
		cout << s[i][i];
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n, k = map(int, input().split())
s = input()

ans = []
for i in range(n):
    if i == k - 1:
        ans.append(s[i].lower())
    else:
        ans.append(s[i])

print(''.join(ans))



Measured memory_bytes: 2940
#include<stdio.h>

int main(){
    for( ; ; ){
        int a, b;
        char op;
        scanf("%d %c %d",&a, &op, &b);
        if(op=='?') break;
    
        switch(op){
            case '+' : printf("%d\n",a+b);break;
            case '-' : printf("%d\n",a-b);break;
            case '*' : printf("%d\n",a*b);break;
            case '/' : printf("%d\n",a/b);break;

        }
    }
    return 0;
}

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

int main() {
 int N;
  cin >> N;
  pair<pair<string,int>,int> p[110];
  for (int i; i<N; i++){
   string S;int P;
   cin >> S >> P;
   P=P*(-1);
   p[i]=make_pair(make_pair(S,P),i);
  }
  sort (p,p+N);
  for(int i=0;i<N;i++){
   cout << p[i].second+1 << endl; 
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static final 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();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			if (s1.charAt(i) == s2.charAt(i)) {
				list.add(0);
			} else {
				list.add(1);
				i++;
			}
		}
		long val = 1;
		for (int i = 0; i < list.size(); i++) {
			if (i == 0) {
				if (list.get(i) == 0) {
					val *= 3;
				} else {
					val *= 6;
				}
			} else {
				if (list.get(i - 1) == 0 && list.get(i) == 0) {
					val *= 2;
				} else if (list.get(i - 1) == 0 && list.get(i) == 1) {
					val *= 2;
				} else if (list.get(i - 1) == 1 && list.get(i) == 0) {
					val *= 1;
				} else if (list.get(i - 1) == 1 && list.get(i) == 1) {
					val *= 3;
				}
			}
			val %= MOD;
		}
		System.out.println(val);
	}
}


Measured memory_bytes: 23764
n = int(input())
a_list = list(map(int, input().split()))
 
import collections
count_dic = collections.Counter(a_list)
 
count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2
fund_values = sum(list(count_dic_new.values()))
 
for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (((n-1) * (n-2)) // 2) - (((n) * (n-1)) // 2) 
 
    print(a_value)

Measured memory_bytes: 100556
n = int(input())
a = input().split(' ')
p = 1
broken = 0
id = 1
if str(1) in a:
  for i in range(n):
    a[i] = int(a[i])
    if id == a[i]:
      id += 1
    else:
      broken += 1
else:
  broken = -1
print(broken)

Measured memory_bytes: 17976
// AOJ 2665: Hopping Hearts
// 2018.1.3 bal4u@uu


#include <stdio.h>
#include <string.h>

#define M  1000000007

int x[5002], a[5002];
int dp[2][5002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

 
int main()
{
    int n, L, i, j, k1, k2;

	n = in(), L = in();
    for (i = 0; i < n; i++) x[i] = in();
    for (i = 0; i < n; i++) a[i] = in();
  
	for (i = 0; i < L; i++) dp[0][i] = 1;
    for (k1 = 0, k2 = 1, i = 0; i < n; i++, k1 = k2, k2 = !k2) {
		memset(dp[k2], 0, sizeof(dp[0]));

		if (!a[i]) {
			if (!(j = x[i])) dp[k2][j] = dp[k1][j];
			else {
				dp[k2][j] += dp[k1][j-1];
				if (dp[k2][j] >= M) dp[k2][j] -= M;
			}
		} else for (j = x[i]; j < L; j += a[i]) {
			if (!j) dp[k2][j] = dp[k1][j];
			else {
				dp[k2][j] += dp[k1][j-1];
				if (dp[k2][j] >= M) dp[k2][j] -= M;
			}
		}
          
		for (j = x[i]; j < L; j++) {
			dp[k2][j+1] += dp[k2][j];
			if (dp[k2][j+1] >= M) dp[k2][j+1] -= M;
		}
    }
    printf("%d\n", dp[k1][L-1]);
    return 0;
}


Measured memory_bytes: 1892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    pair<pair<ll,ll>,ll> cake[n];
    for(int i=0;i<n;i++){
        ll x,y,z;
        cin>>x>>y>>z;
        cake[i]={{x,y},z};
    }
    ll ans=-1;
    for(int a=0;a<2;a++){
        for(int b=0;b<2;b++){
            for(int c=0;c<2;c++){
                ll p[n];
                for(int i=0;i<n;i++){
                    ll score=0,x,y,z;
                    x=cake[i].first.first;
                    y=cake[i].first.second;
                    z=cake[i].second;
                    if(a)score+=x;
                    else score-=x;
                    if(b)score+=y;
                    else score-=y;
                    if(c)score+=z;
                    else score-=z;
                    p[i]=score;
                }
                sort(p,p+n);
                ll sum=0;
                for(int i=0;i<m;i++){
                    sum+=p[n-1-i];
                }
                ans=max(ans,sum);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
    while (b) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return a;
}

ll po(ll a, ll b) {
    ll c = 1;
    while (b) {
        if (b % 2) c = c * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return c;
}

ll f[2000006], g[2000006];

void comb() {
    f[0] = 1;
    for (int i = 1; i <= 2000000; i++) f[i] = f[i - 1] * i % mod;
    g[2000000] = 407182070;
    for (int i = 1999999; i >= 0; i--) g[i] = g[i + 1] * (i + 1) % mod;
}

int p[200005];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, a[270000] = {}, b[270000] = {1};
    cin >> n;
    for (int i = 0; i < (1 << n); i++) cin >> a[i];
    sort(a, a + (1 << n)); reverse(a, a + (1 << n));
    for (int i = 0; i < n; i++) {
        vector<int> c;
        int d = 0;
        for (int j = 0; j < (1 << n); j++) if (b[j]) c.push_back(j);
        for (int j = 0; j < (1 << n); j++) if (!b[j]) {
            if (d < c.size() && a[j] < a[c[d]]) d++, b[j] = 1;
        }
        if (d != c.size()) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 6192
def main():
    a, op, b = (i for i in input().split())
    while op != '?':
        a, b = int(a),int(b)
        if op == '+':
            print(a+b)
        elif op == '-':
            print(a-b)
        elif op == '*':
            print(a*b)
        elif op == '/':
            print(a//b)
        a, op, b = (i for i in input().split())

if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  int a, b;
  a = n % 10;
  b = (n / 100);
  if(a == b)  cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

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

int main(){
  int n,counter=0;
  cin >> n;
  for(int i=1;i<=n;i++){
   if(i%2==1)counter++;
  }
  cout<<(double)counter/n<<endl;
}



Measured memory_bytes: 256
#include <iostream>

/* CUT CUT CUT */

#include <vector>
#include <queue>
using namespace std;

const long long INF = 10000000000000000; // 10e16

struct edge { long long to, cost;};
typedef pair<long long, long long> P_dij;

void dijkstra(const long long s, const long long n,
  vector< vector<edge> > const &G, vector<long long> & d){
  d.resize(n);
  for(int i=0; i<n; i++) d[i] = INF; 
  priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;
  d[s] = 0;
  que.push(P_dij(0, s));
  while (!que.empty()) {
    P_dij p = que.top();
    que.pop();
    long long v = p.second;
    if(d[v] < p.first)continue;
    for(int i=0;i<G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P_dij(d[e.to], e.to));
      }
    }
  }
}

/* END END END */

// verifiy shpc2018D Saving Snuuk


long long i, j, k;
 
int main(){
    long long n, m, s, t;
    cin >> n >> m >> s >> t;
    vector< vector<edge> > edge_yen(200001);
    vector< vector<edge> > edge_snu(200001);
    vector< long long > d1, d2;
    for(i=0; i<m; i++){
        long long u, v, a, b;
        cin >> u >> v >> a >> b;
        edge e1;
        e1.to = v, e1.cost = a;
        edge_yen[u].push_back(e1);
        edge e2;
        e2.to = u, e2.cost = a;
        edge_yen[v].push_back(e2);
        edge e3;
        e3.to = v, e3.cost = b;
        edge_snu[u].push_back(e3);
        edge e4;
        e4.to = u, e4.cost = b;
        edge_snu[v].push_back(e4);
    }
 
    dijkstra(s, n+1, edge_yen, d1);
    dijkstra(t, n+1, edge_snu, d2);
 
    long long ans[200001];
    long long Max = 0;
    long long FIRST = 1e15;
    for(i=n; i>=1; i--){
        long long val = FIRST - (d1[i] + d2[i]);
        Max = max(val, Max);
        ans[i] = Max;
    }
    for(i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 23804
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n,k;
	cin>>n>>k;
	lli a[n],i;
	fr(i,n)
	{
		cin>>a[i];
	}
	for(i=k;i<n;i++)
	{
		if(a[i]>a[i-k])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	
	return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <string>

using namespace std;

int main()
{
  int n, k, c; string s; cin >> n >> k >> c >> s;
  
  int a[200000]; int b[200000];
  for (int i = 0, idx = 0; i < n; ++i) if (s[i] == 'o') {a[idx++] = i; i += c;}
  for (int i = n-1, idx = k-1; i >= 0; --i) if (s[i] == 'o') {b[idx--] = i; i -= c;}
  
  for (int i = 0; i < k; ++i) if (a[i] == b[i]) cout << a[i]+1 << endl;
  return 0;
}


Measured memory_bytes: 3332
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include<stack>
#include<string>

int main() {
	usize n;
	std::cin >> n;
	std::vector<usize> p(n), a(n);
	for (auto &e : p) {
		std::cin >> e;
		--e;
	}
	for (const auto i : rep<>(0, n)) {
		a[p[i]] = i;
	}
	std::string ans;
	std::stack<usize> st;
	st.push(n);
	usize itr = 0;
	for(const auto i : rep<>(0,n)) {
		while (itr!=n&&st.top() != i) {
			st.push(a[itr++]);
			ans.push_back('(');
		}
		if (st.top() != i) {
			std::cout << ":(" << std::endl;
			return 0;
		}
		st.pop();
		ans.push_back(')');
	}
	
	std::cout << ans << std::endl;


	return 0;
}



Measured memory_bytes: 5340
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << max(0,min(B,D)-max(A,C)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll F[2100010];

ll Mul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
ll square(ll x) {
	return (x * x) % mod;
}

ll power(ll x, ll y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

ll Div(ll a, ll b) {
	return Mul(a, power(b, mod - 2));
}
ll P(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

ll C(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	ll ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}

int main()
{
	fact();
	ll N, K;
	cin >> N >> K;
	ll ans = 0;
	for (ll i = 1; i <= K; i++) {
		cout << Mul(C(N - K + 1, i), C(K - 1, i - 1)) << endl;
	}
}


Measured memory_bytes: 16640
// AGC5-A
    #include <bits/stdc++.h>
    #define endl "\n"
    #define rep(i,n) for(int i=0;i<int(n);i++)
    #define e_b emplace_back
    #define sz(x) ((int)(x).size())
    #define all(x) (x).begin(),(x).end()
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> ipair;
    typedef pair<ll,ll> lpair;
    template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
    {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
    void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
    void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る
    
    
    int main() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    
        string s;
        cin>>s;
        int t_num=0,s_num=0,ans=0;
        rep(i,s.size()){
            if(s[i]=='S'){
                ans+=t_num;
                t_num=0;
                s_num++;
            }else{
                if(s_num==0) t_num++;
                else{
                    s_num--;
                }
            }
        }
        ans+=t_num;
        ans+=s_num;
        cout<<ans<<endl;
        return 0;
    }

Measured memory_bytes: 3760
#include <stdio.h>
#include <math.h>

struct point {
    float x, y;
};

struct line {
    /* ax + by = c */
    float a, b, c;
};

float distance(struct point p, struct point q)
{
    return sqrt(pow(p.x - q.x, 2) + pow(p.y - q.y, 2));
}

struct line bisector(struct point p, struct point q)
{
    struct line l;

    l.a = (p.x - q.x);
    l.b = (p.y - q.y);
    l.c = ((p.x * p.x - q.x * q.x) + (p.y * p.y - q.y * q.y)) / 2;

    return l;
}

struct point intersection(struct line l1, struct line l2)
{
    float det = l1.a * l2.b - l1.b * l2.a;
    struct point p;

    p.x = (l1.c * l2.b - l1.b * l2.c) / det;
    p.y = (l1.a * l2.c - l1.c * l2.a) / det;

    return p;
}

struct point center(struct point a, struct point b, struct point c)
{
    struct line l1, l2;
    struct point p;
    
    l1 = bisector(a, b);
    l2 = bisector(b, c);
    p = intersection(l1, l2);

    return p;
}

int main(void)
{
    int i, n;
    float d;
    struct point a, b, c;
    struct point p;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%f %f %f %f %f %f",
                &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);
        p = center(a, b, c);
        d = distance(p, a);
        printf("%.3f %.3f %.3f\n", p.x, p.y, d);
    }

    return 0;
}

Measured memory_bytes: 652
import bisect
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
for bi in range(N):
  ai=bisect.bisect_left(alist,blist[bi])  
  ci=bisect.bisect(clist,blist[bi])  
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)

Measured memory_bytes: 23232
S = str(input())
F = int(S[0:2])
T = int(S[2:4])

def Greaterthan12(x):
    if x > 12:
        return 0
    else:
        if x == 0:
            return 0
        else:
            return 1
        
Fjudge = Greaterthan12(F)
Tjudge = Greaterthan12(T)
if Fjudge == 0:
    if Tjudge == 0:
        print("NA")
    else:
        print("YYMM")
else:
    if Tjudge == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    con_input(vec);
    int h=0,ans=0;
    rep(i,n-1){
        if(vec[i]>=vec[i+1]){
            h++;
        }else{
            ans=max(ans,h);
            h=0;
        }
    }
    ans=max(ans,h);
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,k,i,sum=0;
    cin >> n >> k;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    for(i=0;i<k;i++) sum+=a[i]; 
    cout << sum;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n;
	map<string,ll>mp;
	string s;
	cin>>s;
	char c=s.back();
	mp[s]++;
	n--;
	while(n--){
		cin>>s;
		mp[s]++;
		if(mp[s]==2 || c!=s.front()) return cout<<"No",0;
		c=s.back();
	}

	cout<<"Yes";

}

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

int main() {
  int n;
  cin >> n;
  VI a(n);
  VI b(n);
  VI c(n-1);
  int ans=0;
  for(int i=0;i<n;i++) {cin >> a.at(i);}
  
  for(int i=0;i<n;i++) {cin >> b.at(i);}
  
  for(int i=0;i<n-1;i++) {cin >> c.at(i);}
  for(int i=0;i<a.size();i++){
    
    ans+=b.at(a.at(i)-1);
  }
  for(int i=0; i<n-1;i++){
    if(a.at(i+1)-a.at(i)==1){
     
      ans+=c.at(a.at(i)-1);
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll a,b,c,d,x1,x2,x3,x4;
  cin>>a>>b>>c>>d;
   x1=a*c,x2=b*c;  x1=max(x1,x2);
   x3=a*d,x4=b*d;  x3=max(x3,x4);
   x1=max(x1,x3);
   cout<<x1;
return 0;
}



Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <iomanip>
using namespace std;

int main(){
    int n ; cin >> n;
    int cnt = 0;
    for ( int i = n ; i >= 1 ; i-- ){
        if ( to_string(i).size() % 2 == 1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
vector<int> go(int n, int a, int b) {
	if (n == 1) {
		assert((a ^ 1) == b);
		return {a, b};
	}
	int bit = (1 << (n - 1));
	bool bita = a & bit;
	bool bitb = b & bit;
	vector<int> z;
	if (bita != bitb) {
		int mid = a ^ 1;
		auto x = go(n - 1, a, mid);
		auto y = go(n - 1, mid ^ bit, b);
		z = x;
		z.insert(z.end(), y.begin(), y.end());
	} else {
		auto x = go(n - 1, a, b);
		for (int i = 0; i < x.size(); i += 2) {
			z.push_back(x[i]);
			z.push_back(x[i] ^ bit);
			z.push_back(x[i + 1] ^ bit);
			z.push_back(x[i + 1]);
		}
	}
	return z;
}
int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	int ca = __builtin_popcount(a) & 1;
	int cb = __builtin_popcount(b) & 1;
	if (ca == cb) printf("NO\n");
	else {
		printf("YES\n");
		auto sol = go(n, a, b);
		for (int x : sol) printf("%d ", x);
	}
}


Measured memory_bytes: 1656
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <fstream>

using namespace std;


#define LL long long
#define N 901000
#define M 3000011
#define MP make_pair
#define Pi acos(-1.0)
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define ls (root << 1)
#define rs (ls | 1)
#define md ((ll+rr)/2)
#define lson ll, md, ls
#define rson md+1, rr, rs
#define mod 1000000007
#define inf 0x3f3f3f3f
#define sqr(x) ((x)*(x))
#define eps 1e-6
#define MP make_pair
#define uLL unsigned long long
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#define F(x) ((x)/3+((x)%3 == 1 ? 0 : tb))
#define G(x) ((x)<tb ? (x)*3+1 : ((x) - tb)*3+2)
#define lowbit(x) ((x)&(-x))
#define fi first
#define se second
#define pii pair<int,int>

int gcd(int a,int b){
    while(b){
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a & 1 && b & 1 && c & 1){
        LL x = 1LL*a*b,y = 1LL*b*c,z = 1LL*a*c;
        cout<<min(min(x,y),z)<<endl;
    }else puts("0");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string s;
int n,ans=0;
bool flag=true;

void solve(){
    cin >> s;
    n=s.length();
    rep(i,n){
        if (flag) {
            ans+=1;
            flag=false;
            //cout << s[i] << endl;
            continue;
        }
        if (!flag && s[i-1]==s[i]){
            ans+=1;
            flag=true;
            //cout << s.substr(i,2) << endl;;
            i+=1;
            if (i>=n) ans-=1;
            continue;
        }
        if (!flag && s[i-1]!=s[i]){
            ans+=1;
            //cout << s[i] << endl;
            continue;
        }
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 720
using System;
using System.Collections.Generic;

class OneStroke
{
	
	static int N, M;
	static bool[] visited;
	static int count;
	static int answer;
	static List<int>[] dest;

	static public void Main(string[] args)
	{
		string[] vals = Console.ReadLine().Split(' ');
		N = int.Parse(vals[0]);
		M = int.Parse(vals[1]);
		dest = new List<int>[N+1];
		for(int i=1; i<=N; i++)
			dest[i] = new List<int>();
		int a, b;
		for(int i=0; i<M; i++)
		{
			vals = Console.ReadLine().Split(' ');
			a = int.Parse(vals[0]);
			b = int.Parse(vals[1]);
			dest[a].Add(b);
			dest[b].Add(a);
		}
		visited = new bool[N+1];
		count = answer = 0;
		search(1);
		Console.WriteLine(answer);
	}

	static void search(int n)
	{
		visited[n] = true;
		if(++count == N)
		{
			answer++;
			return;
		}

		for(int i=0; i<dest[n].Count; i++)
		{
			if(visited[dest[n][i]] == false)
			{
				search(dest[n][i]);
				visited[dest[n][i]] = false;
				count--;
			}
		}
	}

}


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

int main() {
    int l,r;
    cin >> l >> r;
    if(r - l > 2018) {
        cout << 0 << endl;
    }else {
        int mini = 2018;
        for(int i = min(l % 2019,r % 2019);i < max(l % 2019,r % 2019);i++) {
            for(int j = i + 1;j <= max(l % 2019,r % 2019);j++) {
                if((i * j) % 2019 < mini) {
                    mini = (i * j) % 2019;
                    if(mini == 0) {
                        cout << 0 << endl;
                        return 0;
                    }
                }
            }
        }
        cout << mini << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;


const ll mod = 1e9+7;
const double eps = 1e-9;


vector<int>cost,value;
int h , n;
int dp[10001][1002]; 

int recur(int ind,int w) {
    if(ind==0&&w>0)return 1e9;
    else if(ind>=0&&w<=0)return 0;

    if(dp[w][ind]!=-1)return dp[w][ind];

    int first=recur(ind,w-cost[ind-1])+value[ind-1];
    int second=recur(ind-1,w);
    return dp[w][ind]=min(first,second);
}

void show(int a,int b){
    for(int i=0;i<=a;i++) {
        for(int j=0;j<=b;++j) {
            cout<<dp[i][j]<<"  ";
        }
        cout<<endl;
    }
}

void solve(){
    cin>>h>>n;
    cost.resize(n+1);
    value.resize(n+1);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++) {
        cin>>cost[i]>>value[i];
    }
    cout<<recur(n,h)<<endl;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 39936
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)

for a in A:
    d[a] += 1

ans = 0
for k, v in d.items():
    ans += (v * (v - 1)) // 2

for i in range(n):
    ai = A[i]
    cnt = d[ai]
    diff = (cnt * (cnt - 1)) // 2 - ((cnt - 1) * (cnt - 2)) // 2
    print(ans - diff)

Measured memory_bytes: 26780
MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
ifact = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
    ifact.append(pow(f[-1], MOD-2, MOD))
def nCr(n, r):
    return f[n] * ifact[r] * ifact[n-r] % MOD

def nPr(n, r):
    return f[n] * ifact[n-r] % MOD

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    # tmp = pow(nPr(m-k, n-k), 2, MOD) * nPr(m, k) * nCr(n,k) % MOD
    tmp = nPr(m-k, n-k) * nPr(m, n) * nCr(n,k) % MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans = (ans + MOD) % MOD
print(ans)


Measured memory_bytes: 157972
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
string i2s(int num){
  stringstream ss;
  string str;
  ss << num;
  ss >> str;
  return str;
}
int main(){
  int n;
  cin >> n;
  for(int k = 1 ; k <= n ; k++ ){
    int num;
    cin >> num;
    cout << "Case " << k << ":" << endl;
    for(int i = 0 ; i < 10 ; i++ ){
      string tmp = i2s(pow(num,2));
      string str="";
      for(int i = 0 ; i < 8 - tmp.size() ; i++){
	str+='0';
      }
      str+=tmp;
      str = str.substr(2,4);

      cout << atoi(str.c_str()) << endl;

      num = atoi(str.c_str()); 
    }
  }
  return 0;
}

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

int main() {
  int N,H;
  cin>>N>>H;
  int a[100001],b[100001];
  for(int i=0;i<100001;i++){
    cin>>a[i]>>b[i];
  }
  sort(a,a+N);
  reverse(a,a+N);
  sort(b,b+N);
  reverse(b,b+N);
  int cont;
  cont=0;
  for(int i=0;i<N;i++){
    if(b[i]>=a[0] && H>0){
      cont+=1;
      H-=b[i];
    }
  }
  if(H>0){
    cont+=(H-1)/a[0]+1;}
  cout<<cont<<endl;
}


Measured memory_bytes: 1024
import queue
H , W = list(map(int, input().split()))
S = [input() for _ in range(H)]
Sum = 0
for i in range(H):
  for j in range(W):
    Sum += (S[i][j] == '#')
start = [1, 1, 1]
visited = [[0] * W for _ in range(H)]
visited[0][0] = 1
Q = queue.Queue()
Q.put(start)
now = start
while(now[:2] != [H, W] and not Q.empty()):
  now = Q.get()
  for i in range(2):
    for j in range(2):
      h = now[0] + ((-1) ** i + (-1) ** j) // 2
      w = now[1] + ((-1) ** i - (-1) ** j) // 2
      if(1 <= h and h <= H and 1 <= w and w <= W and visited[h - 1][w - 1] == 0 and S[h - 1][w - 1] == '.'):
        visited[h - 1][w - 1] = 1
        Q.put([h, w, now[2] + 1])
if(now[:2] == [H, W]):
  print(H * W - Sum - now[2])
else:
  print(-1)

Measured memory_bytes: 76528
#include <stdio.h>
#include <math.h>

int main(){
	int ans, a;
	char x[1];
	scanf("%d", &ans);
	while(scanf("%s", &x) != '='){
		if(x[0] == '=') break;
		scanf("%d", &a);
		if(x[0] == '+') ans += a;
		if(x[0] == '-') ans -= a;
		if(x[0] == '*') ans *= a;
		if(x[0] == '/') ans /= a;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main()
{
  unsigned int n;
  int count = 0;
  unsigned int bit = 1;
  
  scanf("%d", &n);

  for (; n / 2; n /=2) {
    if (!(n % 2)) bit = 0;
    count++;
  }

  printf("%d\n", count + bit);

  return 0;
}
  



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

int main()
{
    int N = 0, X = 0;
    std::cin >> N >> X;
    std::vector<int> m(N);
    for (int i = 0; i < N; i++) { std::cin >> m.at(i); }

    /* 最小の値を求める  */
    int minVal = 1000000;
    int result = 0;
    for (int i = 0; i < N; i++) {
        if (minVal > m[i]) {
            minVal = m[i];
        }
        /* 
         * 各一つずつドーナツ作るのでmの合計をXから引く
         * N回引くのでN個はできる
         */
        X -= m[i];
    }

    result = N;
    
    /*
     * あとは一番小さい値(お菓子の素)で作れるドーナツを作る。
     * X / minVal で求めた回数を結果に足す
     */

    result += X / minVal;
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
next = 1
List = [-1]*N
 
for i in range(K):
    if List[next-1] == -1:
        List[next-1] = i
        next = A[next-1]
 
    else:
        loop = i - List[next-1]
        afterloop = (K-(i-loop))%loop
        print(List.index((i-loop) + afterloop)+1)
        exit()
 
print(next)

Measured memory_bytes: 32088
#include <stdio.h>
#include <stdlib.h>
#define INT_MAX __INT_MAX__
int main(){
    int n,i, min;
    int l_b=0, r_w=0;
    char *s;

    scanf("%d", &n);
    s = malloc(sizeof(char)*(n+1));
    scanf("%s", s);


    for(i=0;i<n;i++){
        if(s[i] == '.') r_w++;
    }

    min = r_w;
    for(i=0;i<n;i++){
        if(s[i] == '#') l_b++;
        if(s[i] == '.') r_w--;
        if(l_b + r_w < min) min = l_b + r_w;
    }
    printf("%d\n", min);

    return 0;
}

Measured memory_bytes: 384