akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(LL i=0;i<(LL)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<LL,LL>
#define pll pair<LL,LL>

using namespace std;

bool used[100001];
bool color[100001];
vector<LL> edge[100001];


LL dfs(LL v,bool cl){
    used[v]=true;
    color[v]=cl;
    LL res=(edge[v].size()>0 ? 1:-1);
    for(LL u:edge[v]){
        if(!used[u])res=max(res,dfs(u,!cl));
        else if(color[u]==cl)res=2;
    }
    return res;
}

int main(){

    LL N,M;cin>>N>>M;

    REP(i,M){
        LL u,v;cin>>u>>v;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
    }
    fill_n(used,N,false);
    LL ans=0;
    LL p=0,q=0,r=0;
    REP(i,N)if(!used[i]){
            switch(dfs(i,true)){
                case -1:
                    r++;
                    break;
                case 1:
                    q++;
                    break;
                case 2:
                    p++;
                    break;
            }
        }
    ans = 2*N*r-r*r +p*p+2*p*q+2*q*q;
    cout<<ans<<endl;



    return 0;
}

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

using ll = long long;

int main(){
    ll n, k;
    cin >> n >> k;
    ll opr = n / k;
    ll ans = min(abs(n - opr*k), abs(n - (opr + 1)*k));

    cout << ans << endl;
}

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

int is_black(vector<string> &S, int i, int j) {
  if (S.at(i).at(j) == '#') {
    return 1;
  }
  return 0;
}

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

  int64_t H, W;

  cin >> H >> W;

  vector<string> S(H);
  vector<vector<int>> dp(H, vector<int>(W));

  for (int64_t i = 0; i < H; i++) {
    cin >> S.at(i);
  }
  for (int64_t i = 0; i < H; i++) {
    for (int64_t j = 0; j < W; j++) {
      if (i == 0) {
        if (j == 0) {
          dp.at(i).at(j) = is_black(S, i, j);
        } else {
          if (S.at(i).at(j - 1) == S.at(i).at(j)) {
            dp.at(i).at(j) = dp.at(i).at(j - 1);
          } else {
            dp.at(i).at(j) = dp.at(i).at(j - 1) + is_black(S, i, j);
          }
        }
      } else {
        if (j == 0) {
          if (S.at(i - 1).at(j) == S.at(i).at(j)) {
            dp.at(i).at(j) = dp.at(i - 1).at(j);
          } else {
            dp.at(i).at(j) = dp.at(i - 1).at(j) + is_black(S, i, j);
          }
        } else {
          auto tmp_from_left = dp.at(i - 1).at(j);
          if (S.at(i - 1).at(j) == S.at(i).at(j)) {
          } else {
            tmp_from_left += is_black(S, i, j); 
          }
          auto tmp_from_up = dp.at(i).at(j - 1);
          if (S.at(i).at(j - 1) == S.at(i).at(j)) {
          } else {
            tmp_from_up += is_black(S, i, j); 
          }
          if (tmp_from_left > tmp_from_up) {
            dp.at(i).at(j) = tmp_from_up;
          } else {
            dp.at(i).at(j) = tmp_from_left;
          }
        }
      }
    }
  }

  cout << dp.at(H - 1).at(W - 1);

  return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    
    if(n%m>0)
    {
        cout<<n/m + 1<<endl;
    }
    
    else
    {
        cout<<n/m<<endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<cctype>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

bool isprime(int x) {
	if (x == 2) return true;

	if (x < 2 Or x % 2 == 0) return false;

	int i = 3;
	while (i <= sqrt(x)) {
		if (x%i == 0) return false;
		i += 2;
	}
	return true;

}

int main(void) {
	int n; cin >> n;
	int x;
	int sum = 0;
	rep(i, 0, n) {
		cin >> x;
		if (isprime(x)) sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n;
  vector<int> D(n);
  for(auto&& x:D)cin >> x;
  cin >> m;
  vector<int> T(m);
  for(auto&& x:T)cin >> x;
  sort(D.begin(), D.end());
  sort(T.begin(), T.end());
  string ans = "";
  for(int i=0, j=0;;){
    if(i == n && j != m){
      ans = "NO";
      break;
    }
    else if(j == m){
      ans = "YES";
      break;
    }else if(D[i] < T[j]){
      i++; 
    }else if(D[i] == T[j]){
      i++;j++; 
    }else if(D[i] > T[j]){
      ans = "NO";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
	int D, E;
	while (1) {
		cin >> D >> E;
		if (!D && !E) {
			return 0;
		}
		double diff = INF;
		for (int e = 0; e <= D; e++) {
			int n = D - e;
			double dist = sqrt((e * e) + (n * n));
			//cout << dist << endl;
			//cout << "abs: " << abs(dist - (double)E) << endl;
			diff = min(diff, abs(dist - (double)E));
		}
		cout << diff << endl;
	}
}

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

using namespace std;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;

const int N = 20;

int n;
int s[N];
ll dp[N][2];

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

	cin >> n;
	ll res = 1;
	ll imp = 1;
	for( int i = 1; i <= n; i++ ){
		cin >> s[i];
		res *= 3;
		ll curr = 0;
		for( int j = s[i] - 1; j <= s[i] + 1; j++ ){
			if(j % 2 == 1){
				curr += imp;
			}
		}

		imp = curr;
	}
	cout << res - imp << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

int m;
string s;

vi f(string s) {
	int n = s.size(), l = -1, r = -1;
	vi p(n);
	p[0] = n;
	for(int i=1; i<n; ++i) {
		if(i <= r) 
			p[i] = min(r-i, p[i-l]);
		while (i+p[i]<n && s[i+p[i]] == s[p[i]]) p[i]++;
		if (r < i+p[i]) r = i+p[i], l = i;
	}
	return p;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	vector<string> weather;
	weather.pb("Sunny");
	weather.pb("Cloudy");
	weather.pb("Rainy");
	string s;
	cin >> s;
	rep(i,0,3) {
		if(weather[i] == s) {
			cout << weather[(i+1)%3] << endl;
		}
	}
	return 0;
}


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

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

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    while(1){
        c-=b;

        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3648
import itertools as itr
n = int(input())
first = list(range(1, n + 1))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
posp, posq = 0, 0
num = 0
for i in itr.permutations(first):
  num += 1
  i = list(i)
  if i == p:
    posp = num
  if i == q:
    posq = num
print(abs(posp - posq))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 2e5;
const int INF = 1e9 + 7;
/*
void init(int x, int l, int r) {
    if (l == r) {
        tree[x] = INF;
    } else {
        int mid = (l + r) / 2;
        init(x + x, l, mid);
        init(x+x+1, mid + 1, r);
        tree[x] = min(tree[x + x], tree[x + x + 1]);
    }
}
int get(int x, int l, int r, int tl, int tr) {
    if (r < tl || tr < l) {
        return INF;
    }
    if (tl <= l && r <= tr) {
        return tree[x];
    }
    int mid = (l + r) / 2;
    return min(get(x + x, l, mid, tl, tr), get(x+x+1, mid + 1, r, tl, tr));
}
void upd(int x, int l, int r, int pos, int val) {
    if (l == r) {
        tree[x] = min(tree[x], val);
    } else {
        int mid = (l + r) / 2;
        if (pos <= mid) {
            upd(x + x, l, mid, pos, val);
        } else {
            upd(x+x+1, mid + 1, r, pos, val);
        }
        tree[x ] =min(tree[x + x], tree[x + x +1]);
    }
}

*/
int main() {
    int r, g, b;
    cin >> r >> g >> b;
    r *= 10;
    r += g;
    r *= 10;
    r += b;
    if (r % 4 == 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int red = 0;
	int blur = 0;
	for (int ii = 0; ii < N; ++ii){
		if (s[ii] == 'R'){
			red++;
		} else {
			blur++;
		}
	}


	if (red > blur){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";		
	}

	return 0;
}


Measured memory_bytes: 256
// D - Gathering Children
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void out(int s, int l, int e, int o){
	rp(i, s, l-1) cout<<"0 ";
	cout<< (l%2? e:o) <<" "<< (l%2? o:e) <<" ";
}

int main(){
	string S; cin>>S;
	int s = 0, l = -1, r = -1, e, o, n = S.size();
	rp(i, 0, n){
		if(r<0 && S[i]=='R'){
			if(l>=0) out(s,l,e,o);
			s = l + 1;
			r = i; l = -1;
			e = o = 0;
		}
		else if(l<0 && S[i]=='L'){
			l = i; r = -1;
		}
		if(i%2) o++; else e++;
	}
	out(s,l,e,o);
	rp(i, l+1, n) cout<<"0 ";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

#define MAX_V 100005
int V, E;
vector<int> G[MAX_V];
int depth[MAX_V];
int cnt[MAX_V];
int visited[MAX_V];
vector<P> ans;

void dfs(int pos, int prev){
    visited[pos] = true;
    for(int i = 0; i < (int)G[pos].size(); i++){
        int to = G[pos][i];
        if(to==prev)continue;
        if(!visited[to]){
            depth[to] = depth[pos] + 1;
            dfs(to, pos);
            cnt[pos]+=cnt[to];
            if(cnt[to] == 0) ans.push_back(P(min(pos,to) , max(pos,to)));
        }else if(depth[to] < depth[pos]){
            cnt[pos]++;
            cnt[to]--;
        }
    }
}
 
int main(){
    scanf("%d %d", &V, &E);
    for(int i = 0; i < E; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0,-1);
    sort(ans.begin(), ans.end());
    for(int i = 0; i < (int)ans.size(); i++) printf("%d %d\n",ans[i].first, ans[i].second);
    return 0;
}



Measured memory_bytes: 7404
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Online Judge: Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<utility>
using namespace std;
typedef long long LL;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF LL(1e18);
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define EMPP emplace_back
#define vii vector<int>
#define vll vector<LL>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sf1(v) scanf("%I64d",&v);
#define sf2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sf3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL GCD(LL a, LL b) {
	return !b ? a : GCD(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / GCD(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2) {
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool Is_Square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL Power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = Power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool Is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, x;
	cin >> n >> x;
	vii a(n);
	int ans = 0, sum = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i],sum+=a[i];
	sort(a.begin(), a.end());
	if (sum <= x)
		ans = n,x-=sum;
	while (x > 0)
	{
		if (x >= a[0])
		{
			ans++;
			x -= a[0];
		}
		else break;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i=0; i<N; i++) cin >> p[i];
    
    int cnt = 0;
    
    for (int i=0; i<N; i++) {
        if (p[i] != i+1) cnt++;
    }
    
    if (cnt == 2 || cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
//const ll p = 1e9 + 7;
//const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

struct rerooting {
	ll n;
	vector<vector<vll>> nx;
	unordered_map<ll, unordered_map<ll, ll>> dp;
	unordered_map<ll, unordered_map<ll, bool>> is_calculated;

	rerooting(ll m, vector<vector<vll>> &v) {
		n = m;
		nx = v;
	}

	ll calc_sub(ll a, ll b) {
		if (is_calculated[a][b]) return dp[a][b];
		else if (nx[b].size() == 1) {
			is_calculated[a][b] = true;
			return dp[a][b] = 0;
		}
		else {
			ll ret = 0;
			for (ll i = 0; i < nx[b].size(); i++) {
				if (nx[b][i][1] == a) continue;
				ret = max(ret, calc_sub(b, nx[b][i][1]) + nx[b][i][0]);
			}
			is_calculated[a][b] = true;
			return dp[a][b] = ret;
		}
	}

	ll calc(ll a) {
		ll ret = 0;
		for (ll i = 0; i < nx[a].size(); i++) {
			ret = max(ret, calc_sub(a, nx[a][i][1]) + nx[a][i][0]);
		}
		return ret;
	}
};

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

	ll n;
	cin >> n;
	vector<vector<vll>> nx(n, vector<vll>(0));
	for (ll i = 0; i < n - 1; i++) {
		ll s, t, w;
		cin >> s >> t >> w;
		nx[s].push_back({w, t});
		nx[t].push_back({w, s});
	}

	rerooting rr(n, nx);
	ll ans = 0;
	for (ll i = 0; i < n; i++) ans = max(ans, rr.calc(i));
	cout << ans << endl;
}


Measured memory_bytes: 76876
#include<bits/stdc++.h>
using namespace std;
#define int 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 endl "\n"
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
void shikhar7s(int cas)
{
    int n,i,j,c=0,f=1,ff=1;
    cin>>n;
    int p,q;
    string a[2],s;
    fr(i,n)
    {
        cin>>p;
        a[0].pb(p+'0');
    }
    fr(i,n)
    {
        cin>>q;
        a[1].pb(q+'0');
    }
    fr(i,n)
    {
        s.pb(i+'1');
    }
    sort(a,a+2);
    f=1;
    fr(i,n)
    {
        if(s[i]!=a[0][i])
        {
            f=0;
            break;
        }
    }
    if(f)
    {
        ff=1;
        fr(i,n)
        {
            if(s[i]!=a[1][i])
            {
                ff=0;
                break;
            }
        }
        if(ff)
        {
            cout<<c;
            return;
        }
        else
            c++;
    }
    while(next_permutation(all(s)))
    {
        if(!f)
        {
            f=1;
            fr(i,n)
            {
                if(s[i]!=a[0][i])
                {
                    f=0;
                    break;
                }
            }
        }
        if(f)
        {
            ff=1;
            fr(i,n)
            {
                if(s[i]!=a[1][i])
                {
                    ff=0;
                    break;
                }
            }
            if(ff)
            {
                cout<<c;
                return;
            }
            else
                c++;
        }
    }
    cout<<c;
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

string s;

void solve() {
  // int x;
  // cout << endl;
}

map<pair<string, string>, int> dict;

signed main() {
  int n;
  cin >> n >> s;
  string first = s.substr(0, s.size() / 2);
  string second = s.substr(s.size() / 2, s.size() / 2);

  int upper = (0x1 << s.size() / 2) - 1;

  for (int i = 0; i <= upper; i++) {
    string red;
    string blue;
    int p = i;
    int j = 0;
    while (p != 0) {
      if (p & 0x1) {
        red.push_back(first.at(j));
      } else {
        blue.push_back(first.at(j));
      }
      p = p >> 1;
      j++;
    }

    while (j < first.size()) {
      blue.push_back(first.at(j));
      j++;
    }

    dict[make_pair(red, blue)]++;
  }

  int ans = 0;

  reverse(second.begin(), second.end());
  for (int i = 0; i <= upper; i++) {
    string red;
    string blue;
    int p = i;
    int j = 0;
    while (p != 0) {
      if (p & 0x1) {
        red.push_back(second.at(j));
      } else {
        blue.push_back(second.at(j));
      }
      p = p >> 1;
      j++;
    }

    while (j < first.size()) {
      blue.push_back(second.at(j));
      j++;
    }

    ans += dict[make_pair(red, blue)];
  }

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


Measured memory_bytes: 91904
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  string a="";
  string b="";
  ll count=0;
  ll n=s.size();
  rep(i,n){
    char c=s[i];
    b+=c;
    if(a!=b){
      a=b;
      b="";
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    double n, m;
    cin >> n >> m;
    vector<double> a(n);
    rep(i, n)cin >> a[i];
    sort(rall(a));
    bool ok = true;
    double sum = accumulate(all(a), 0.0), now;
    rep(i, m){
        now = a[i] / sum;
        if(now < 1.0/(4.0*m))ok = false;
    }
    if(ok)cout << "Yes";
    else cout << "No";
}   

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

using namespace std;

typedef long long ll;

const ll MOD = 998244353;

int N, S;
int A[3000 + 10];

ll dp[3000 + 10][3000 + 10];//0->まだ取り始めていない　1->Lが決まっていて、Rが未定 2->LもRも決まってる

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

	ll ans = 0;
	for (int i = 0; i <= N; i++)dp[i][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < S; j++) {
			(dp[i + 1][j] += dp[i][j]) %= MOD;
			if (j + A[i] < S) {
				(dp[i + 1][j + A[i]] += dp[i][j]) % MOD;
			}
			if (j + A[i] == S) {
				(ans += dp[i][j] * (N - i)) %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70912
def cmb(n,r,mod):
	a=1
	b=1
	r = min(r,n-r)
	for i in range(r):
		a = a*(n-i)%mod
		b = b*(i+1)%mod
	return a*pow(b,mod-2,mod)%mod
mod = 10**9+7
n,a,b = list(map(int,input().split()))
ans = pow(2,n,mod)+mod - cmb(n,a,mod) - cmb(n,b,mod)
ans = (ans -1)%mod
print(ans)

Measured memory_bytes: 38760
import sys

def makePuzzle():
    count_Scc = 0
    tmp = sys.stdin.readlines()
    num_s, num_c = tmp[0].split(" ")
    num_s = int(num_s)
    num_c = int(num_c)

    if num_c-num_s*2>=0:
        count_Scc = num_s
        num_c = num_c - num_s*2
        count_Scc = count_Scc + num_c//4
    else:
        count_Scc = num_c//2

    return count_Scc

if __name__=="__main__":
    print(makePuzzle())

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 1e5+5;

ll f(ll a, ll b)
{
    if(a%b)
    {
        return a%b;
    }

    return f(a/b, b);
}

void solve()
{
    ll n;
    cin >> n;


    ll cnt = 0;

    for(ll i=2; i*i < n; i++)
    {
        if((n-1) % i == 0)
        {
            cnt++;

            if(i != (n-1)/i)
            {
                cnt++;
            }
        }
    }   

    for(ll i=2; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            if(f(n/i, i) == 1)
            {
                cnt++;
            }

            if(i != (n/i))
            {
                if(f(i, n/i) == 1)
                {
                    cnt++;
                }
            }
        }
    }

    if(n == 2)
    {
        cnt--;
    }

    cout << cnt + 2 << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 384
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){


	long long r;
	long long g;
	long long d;

	cin>>r;
	cin>>g;

	d=g*2-r;

	cout<<d<<endl;

}


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

int main()
{
  string s;
  cin >> s;
  int max=0;

  for (int i = 0; i < s.size(); i++)
  {
    for (int j = i; j < s.size(); j++)
    {
      bool flag=true;
      for (int k = i; k <= j; k++)
      {
        if (s[k] != 'A' && s[k] != 'C' && s[k] != 'G' && s[k] != 'T')
        {
          flag=false;
          break;
        }
      }
      if (flag)
      {
        if (max<j-i+1)
        {
          max=j-i+1;
        }
      } 
    } 
  }
  cout << max << "\n";
    
  return 0;
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner s = new Scanner(in);
		
		String input = s.nextLine();
		
		int res = input.lastIndexOf("Z") - input.indexOf("A") + 1;
		
		out.println(res);
	}
}

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

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<string> s(N);
  unordered_map<string, int> map;
  ll ret = 0;

  for (int i = 0; i < N; ++i) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    if (map.count(s[i]) == 0)
      map[s[i]] = 1;
    else {
      ret += map[s[i]];
      map[s[i]]++;
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 17700
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int K=sc.nextInt();
        int S=sc.nextInt();
        int X=0;
        int Y=0;
        int sum=0;
        for(int i=0;i<=K;i++){
            for(int j=0;j<=K;j++){
                
                    X=i;
                    Y=j;
                    int Z=S-(X+Y);
                    if((Z>=0)&&(Z<=K)){
                        sum=sum+1;
                    

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

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var s = Read();
            var st = s.Split(',');
            Println($"{st[0]} {st[1]} {st[2]}");
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e5+5;

int n,a[N],b[N],c[N];
ll dp[N][3];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];

    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];

    for(int i=2;i<=n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }

    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));

    return 0;
}


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

int main() {
  string a,b;
  cin>>a>>b;
  int ab=stoi(a+b);
  bool f=true;
  for (int i=1; i<=317; i++) {
    f=(i*i==ab?true:false);
    if (f) {
      break;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}



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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=0;i<n;++i)m[i] = 0;
    for(int i=0;i<n-1;++i){
        int ai;cin>>ai;
        m[ai-1]++;
    }
    for(int i=0;i<n;++i){
        cout << m[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12992
given = [i[::-1] for i in ["dreamer", "eraser", "dream", "erase"]]
S = input()[::-1]
while S != "":
    tmp = S
    for i in given:
        if S.startswith(i):
            S = S.replace(i, "", 1)
            if len(S) == 0:
                print("YES")
                break
    if tmp == S:
        print("NO")
        break

Measured memory_bytes: 3336
n = int(input())
s = input()

r = g = b = 0
for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1

all = r * g * b
sub = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k < n and s[i] != s[j] and s[j] != s[k]and s[k] != s[i]:
            sub += 1
print(all - sub)


Measured memory_bytes: 9204
N = int(input())
Vlis = list(map(int, input().split()))
Clis = list(map(int, input().split()))

res = 0

for i in range(N):
  if Vlis[i] - Clis[i] > 0:
    res += Vlis[i] - Clis[i]
    
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
long long arr[100005];
int main(){
	long long n,maxn=-1,wrong=0,ans=1;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		long long x;
		scanf("%lld",&x);
		if(i==1&&x!=0)wrong=1;
		arr[x]++;
		maxn=max(maxn,x);
	}
	//for(int i=0;i<=maxn;i++)cout<<arr[i]<<" ";
	for(int i=1;i<=maxn;i++){
		if(arr[i]==0){
			wrong=1;
			break;
		}
	}
	if(arr[0]!=1)wrong=1;
	if(wrong)printf("0\n");
	else{
		for(int i=2;i<=maxn;i++){
			for(int j=1;j<=arr[i];j++){
				ans=(ans*arr[i-1])%mod;
			}
		}
		printf("%lld\n",ans);	
	}
	return 0;
}

Measured memory_bytes: 1024
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	cin >> N;
	
	string co;
	cin >> co;

	int cnt = 0;
	rep(i, N)
	{
		if (co[i] == 'R')
		{
			cnt++;
		}
	}

	if (2 * cnt > N)
	{
		cout << "Yes" << endl;
	} 
	else
	{
		cout << "No" << endl;
	}
	
	
	return 0;
}


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

int main()
{
    int n, y;
    cin >> n >> y;
    int sum = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            int l = n - i - j;
            sum = 10000 * i + 5000 * j + 1000 * l;
            if (sum == y && l >= 0)
            {
                cout << i << " " << j << " " << l << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> heights(N, 0);
	for(int i=0;i<N;i++){
		cin >> heights[i];
	}
	unordered_map<int, vector<int>> m;
	vector<int> good(N, 0);
	for(int i=0;i<M;i++){
		int k, l;
		cin >> k >> l;
		m[k-1].push_back(l-1);
	}

	for(auto &p:m){
		int k = p.first;
		auto v = p.second;
		for(int i=0;i<v.size();i++){
			if(heights[k] <= heights[v[i]]){
				good[k] = 1;
			}
			if(heights[v[i]] <= heights[k])
				good[v[i]] = 1;
		}
	}
	int i=0;
	int count = 0;
	for(auto &k:good){
		if(k == 0)
			count++;
		i++;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 10452
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=55;
int n,a[maxn]; 
int main()
{
	cin>>n;
	F(i,1,n) read(a[i]);
	ll sum=0;
	for(int i=1;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
			sum+=a[i]*a[j];
	}
	cout<<sum<<endl;
	return 0;
}

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

int main() {
  int N,ans,cash = 0;
  cin >> N;
  vector<int> d(N);
  for(int i = 0;i < N;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  for(int i = 0;i < N;i++){
    if(cash != d.at(i)){
      ans++;
      cash = d.at(i);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   using namespace std;
   using pii = pair<int, int>;
   using ll = long long;
   #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
   const ll MOD = 1000000007;
   const ll INFL = (1LL << 60);
   const int INFI = (1 << 30);

   int main() {
     ll N, K; cin >> N >> K;
     vector<ll> A(N + 1);
     rep(i, 1, N + 1) cin >> A.at(i); //1-index

     vector<ll> path; //i回目にいる場所
     map<ll, ll> done;

     path.push_back(1); //0回目は1にいる
     done[1]++;

     ll start_v, period;
     bool periodic = false;

     while (1) { //まず周期の最初の数字を求める
       int next = A.at(path.back());
       path.push_back(next);
       done[next]++;
       if (done[next] == 2) {
         start_v = next; //周期の最初の場所start_vはnext
         break;
       }
     }

     ll start_i; //start_vに最初にたどり着くのはstart_i回目
     for (ll i = 0;;i++) { //
       if (path.at(i) == start_v) {
         start_i = i;
         period = path.size() - start_i - 1;
         break;
       }
     }

     vector<ll> cycle(period);
     for (ll i = 0; i < period; i++) {
       cycle.at(i) = path.at(start_i + i);
     }

     if (K < start_i) cout << path.at(K) << endl;
     else {
       ll k = (K - start_i) % period;
       cout << cycle.at(k) << endl;
     }
   }


Measured memory_bytes: 19000
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int dp[110][100100];


int main(){
  int n, w;
  cin >> n >> w;
  vector<int> value(n);
  vector<int> weight(n);
  int v_sum = 0;
  for(int i = 0; i < n; ++i){
    cin >> value[i] >> weight[i];
    v_sum += value[i];
  }
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= v_sum; ++j){
      dp[i][j] = INF;
    }
    dp[i][0] = 0; 
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j <= v_sum; ++j){
      if(j >= value[i])dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
      else dp[i + 1][j] = dp[i][j];
    }
  }

  int ans = 0;
  for(int i = 0; i <= v_sum; ++i){
    if(dp[n][i] <= w){
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 42588
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

int main(void) {
	int N;
	cin >> N;
	vector<ll> A(N + 1);
	vector<ll> B(N);
	for (int i = 0; i < N + 1; ++i) cin >> A[i];
	for (int i = 0; i < N; ++i) cin >> B[i];
	ll count = 0;
	for (int i = 0; i < N; ++i) {
		ll beat = min(A[i], B[i]);
		A[i] -= beat;
		B[i] -= beat;
		count += beat;
		ll beat_next = min(A[i + 1], B[i]);
		A[i + 1] -= beat_next;
		B[i] -= beat_next;
		count += beat_next;
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 1792
s_str = input()
s_list = list(s_str)
g_count = 0
p_count = 0
score = 0
for s in s_list:
  if p_count >= g_count:
    if s == "p":
      score -= 1
    g_count += 1
  else:
    if s == "g":
      score += 1
    p_count += 1
print(score)

Measured memory_bytes: 3956
s = input()
a = "ATCG"
m = [0]
for i in range(len(s)):
    if s[i] in a:
        j = i + 1
        niz = 1
        while j < len(s) and s[j] in a:
            niz += 1
            j += 1
        m.append(niz)
print(max(m))

# 02:49


Measured memory_bytes: 2940
N = int(input())
l = []
i = 0
while i < N:
    l.append(int(input()))
    i += 1

size = 0
tmp = -1
while len(l) > 0:
    if tmp != max(l):
       size += 1
    tmp = max(l)
    l.remove(max(l))
print(size)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vi v(n);
	int ans=1000000;
	int total=0;
	rep(i,0,n){
		cin>>v[i];
		total+=v[i];
	}
	int sum=0;
	rep(i,0,n){
		sum+=v[i];
		total-=v[i];
		chmin(ans,abs(sum-total));
	}
	cout<<ans<<endl;
	
	
	
	return 0;
}

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

#define ll long long

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    string s;
    cin>>s;
    int tmp=0,ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R') tmp++;
        else {ans = max(ans,tmp); tmp=0;}
    }
    ans = max(ans,tmp);
    cout<<ans<<"\n";
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 200005;

int n;
int a[N];

int main() {

	FAST;

	cin >> n;
	for (int i = 2; i <= n; i ++) {
		int x;
		cin >> x;
		a[x] ++;
	}
	for (int i = 1; i <= n; i ++) {
		cout << a[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 4328
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
def solve():
    N = int(readline())
    P = [list(map(int, readline().split())) for i in range(N)]
    ok = 0
    x0, y0 = P[0]; x1, y1 = P[1]
    for i in range(2, N):
        x2, y2 = P[i]
        if (x1 - x0) * (y2 - y0) != (x2 - x0) * (y1 - y0):
            ok = 1
            break
    if not ok:
        write("No\n")
        return
    A = defaultdict(int)
    B = defaultdict(int)
    for i in range(N):
        xi, yi = P[i]
        for j in range(i):
            xj, yj = P[j]
            dx = xi - xj; dy = yi - yj
            g = gcd(abs(dx), abs(dy))
            dx //= g; dy //= g
            if dy < 0:
                dx = -dx; dy = -dy
            if dx == 0:
                p = xi * dy - yi * dx; q = dy
                g = gcd(abs(p), abs(q))
                p //= g; q //= g
                if q < 0:
                    q = -q; p = -p
                key = (p, 0, q, dx, dy)
            else:
                p = yi * dx - xi * dy; q = dx
                g = gcd(abs(p), abs(q))
                p //= g; q //= g
                if q < 0:
                    q = -q; p = -p
                key = (0, p, q, dx, dy)
            A[key] += 1

            gx = -dy; gy = dx
            if gy < 0:
                gx = -gx; gy = -gy
            if dy == 0:
                p = dy * (yi + yj) + dx * (xi + xj)
                q = 2 * dx
                g = gcd(abs(p), abs(q))
                p //= g; q //= g
                if q < 0:
                    q = -q; p = -p
                key = (p, 0, q, gx, gy)
            else:
                p = dx * (xi + xj) + dy * (yi + yj)
                q = 2 * dy
                g = gcd(abs(p), abs(q))
                p //= g; q //= g
                if q < 0:
                    q = -q; p = -p
                key = (0, p, q, gx, gy)
            B[key] += 1
    ok = 0
    if N % 2 == 0:
        for k, v in B.items():
            if 2*v == N:
                ok = 1
                break
            if 2*v == N-2:
                if A[k] == 1:
                    ok = 1
                    break
    else:
        R = []
        for k, v in B.items():
            if 2*v+1 == N:
                R.append(k)
        ok = 0
        for x0, y0, z0, dx, dy in R:
            cnt = 0
            for x, y in P:
                if dy*(x*z0 - x0) == dx*(y*z0 - y0):
                    cnt += 1
            if cnt == 1:
                ok = 1
                break
    if ok:
        write("Yes\n")
    else:
        write("No\n")
solve()


Measured memory_bytes: 246136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	const int n = 3;
	vector<vector<int>> c(n, vector<int>(n));
	rep(i, n) rep(j, n){
		cin >> c[i][j];
	}
	bool is_takahashi_liar = false;
	
	rep(i, n){
		int mn = 1001;
		rep(j, n){
			if(mn > c[i][j]) mn = c[i][j];
		}
		rep(j, n){
			c[i][j] -= mn;
		}
	}
	
	rep(j, n){
		int tmp = c[0][j];
		rep(i, n){
			if(c[i][j] != tmp){
				is_takahashi_liar = true;
				break;
			}
		}
		if(is_takahashi_liar) break;
	}
	
	if(is_takahashi_liar) puts("No");
	else puts("Yes");
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
  int a;
  char s[15];

  scanf("%d", &a);
  scanf("%s", s);

  if(a >= 3200) printf("%s\n", s);

  else printf("red\n");
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val K = sc.nextInt()

fun main(args: Array<String>) {
    (1..N).map {
        val x = sc.nextInt()
        Math.min(x, K - x) * 2
    }.sum().let { println(it) }
}


Measured memory_bytes: 31388
#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;
	string s,t;
	cin>>s>>t;
	lli i,count=0;
	fr(i,s.length())
	{
		if(s[i]!=t[i])
			count++;
	}
	cout<<count;
	
	return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

bool dfs(int x,int y,int color);
int w,h;
int xs,ys;
int xg,yg;
int board[111][111];
int cheak[111][111];
int xd[]={0,-1,0,1};
int yd[]={-1,0,1,0};
int main(){
  int n;
  int c,d,x,y;
  int a[]={1,0,1,0,1,0,1};
  int b[]={0,1,1,2,2,3,3};
  while(1){
    cin >> w >> h;
    if(w==0 && h==0) break;
    memset(board,0,sizeof(board));
    memset(cheak,0,sizeof(cheak));
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    xs--,ys--,xg--,yg--;
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;
      x--,y--;
      board[y][x]=c;
      for(int j=0;j<7;j++){
	if(d==0) board[y+a[j]][x+b[j]]=c;
	else board[y+b[j]][x+a[j]]=c;
      }
    }
    if(board[ys][xs]!=0){
      if(dfs(xs,ys,board[ys][xs])==true) cout << "OK" << endl;
      else cout << "NG" << endl;
    }
    else cout << "NG" << endl;
  }
}

bool dfs(int x,int y,int color){
  board[y][x]=0;
  if(x==xg && y==yg) return true;
  for(int i=0;i<4;i++){
    int xn=x+xd[i];
    int yn=y+yd[i];
    if(xn>=0 && xn<w && yn>=0 && yn<h && board[yn][xn]==color && board[yn][xn]!=0){
      if(dfs(xn,yn,board[yn][xn])==true) return true;
    }
  }
  return false;
}

Measured memory_bytes: 1260
import math
import sys
import collections
import bisect


def main():
    n = int(input())
    a, b = map(int, input().split())
    p = list(map(int, input().split()))
    q = [0, 0, 0]
    for i in range(n):
        if p[i] <= a:
            q[0] += 1
            continue
        if p[i] <= b:
            q[1] += 1
            continue
        q[2] += 1
    print(min(q))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9484