akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mxn 200005
#define xx first
#define yy second
using namespace std;
typedef pair<int, int>pi;
pi ara[mxn];
int main()
{
    int n, x, mc= 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    scanf("%d %d", &ara[i].xx, &ara[i].yy), mc= max(mc, ara[i].yy);
    sort(ara, ara+n);
    int res= 0, mx= 0;
    for(int i=n-1; i>=0; i--)
    mx= max(mx, (ara[i].xx+ara[i].yy)),
    res= max(res, mx-(ara[i].xx+ara[i].yy));
    for(int i=0; i<n; i++)ara[i].yy= mc-ara[i].yy;
    sort(ara, ara+n);
    mx= 0;
    for(int i=n-1; i>=0; i--)
    mx= max(mx, (ara[i].xx+ara[i].yy)),
    res= max(res, mx-(ara[i].xx+ara[i].yy));
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 5376
import collections
n = int(input())
ls = []
for i in range(2, n + 1):
    t = i
    for j in range(2, i + 1):
        while True:
            if t % j == 0:
                t //= j
                ls.append(j)
            else:
                break
ls = collections.Counter(ls)
cnt = 1
for i in ls.values():
    cnt *= ((i + 1) % (10 ** 9 + 7))
print(cnt % (10 ** 9 + 7))


Measured memory_bytes: 3316
#include <stdio.h>
main(){
  int a,b,w[30],n,m,c;
  for(n=0;n<30;n++){
    w[n]=n+1;
  }
  scanf("%d %d",&a,&b);
  for(;b>0;b--){
    scanf("%d,%d",&n,&m);
    c=w[n-1];
    w[n-1]=w[m-1];
    w[m-1]=c;
  }
  for(n=0;n<a;n++){
    printf("%d\n",w[n]);
  }
  return(0);
}   

Measured memory_bytes: 596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	string s;
	cin>>s;
	int x[30]={0};
	for(int i=0;i<s.length();i++)
	{
		x[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
	{
		if(x[i]==0)
		{
			printf("%c\n",'a'+i);
			return 0;
		}
	}
	puts("None");
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int a,b,c,d;
    int val1,val2,val3,val4;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    val1=a+c;
    val2=a+d;
    val3=b+c;
    val4=b+d;
    
    if(val1<=val2 && val1<=val3 && val1<=val4){
        printf("%d\n",val1);
    }
    
    else if(val2<=val1 && val2<=val3 && val2<=val4){
        printf("%d\n",val2);
    }
    
    else if(val3<=val1 && val3<=val2 && val3<=val4){
        printf("%d\n",val3);
    }
    
    else if(val4<=val1 && val4<=val2 && val4<=val3){
        printf("%d\n",val4);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const int mod = 1e9 + 7;

int n;
bool a[22][22];
int d[21][1 << 21];
vector<int> k[22];

inline void add(int &x, int y){
    x = (x + y) % mod;
}

int main(){
    fio;
    cin >> n;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
    for(int b = 0; b < (1<<n); b++) k[ __builtin_popcount(b) ].push_back(b);
    for(int i = 0; i < n; i++){
        if(!i){
            for(int j = 0; j < n; j++){
                if(a[i][j]) d[i][1 << j] = 1;
            }
            continue;
        }
        for(int j = 0; j < n; j++){
            if(!a[i][j]) continue;
            for(int u : k[i]){
                if(u >> j & 1) continue;
                add(d[i][u | 1 << j], d[i-1][u]);
            }
        }
    }
    cout << d[n-1][(1<<n)-1] << '\n';
}

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

using namespace std;
using ll = long long;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<int> A(200);

    for(int i = a; i < b; i++)A[i]++;
    for(int i = c; i < d; i++)A[i]++;
    cout << count(A.begin(), A.end(), 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define LINF 1000000000LL * 1000000
#define MAXN 45002
using namespace std;
 
int n;
int a[200000];
int b[200000];
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b , b + n);
	for(int i = 0;i < n; i++)
		if(a[i] <= b[n / 2 - 1])
		{
			cout << b[n / 2] << endl;
		}
		else
			cout << b[n / 2 - 1] << endl;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
#define ull unsigned long long
#define ll long long
const int mod=1e9+7;
using namespace std;
//priority_queue
inline int in()
{
    int res=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return res;
}

 int gcd(int a,int b)
 {
     return b==0?a:gcd(b,a%b);
 }
int main()
{  ios::sync_with_stdio(false);
 string s;
 cin>>s; int a;
 a=s.size();
    int sum=0;
 for(int i=0;i<a;i++)
  if(s[i]=='o')sum++;
 if(sum+15-a>=8)cout<<"YES\n";
 else cout<<"NO\n";
}


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

int z(int x)
{
  if(x>=0)
    return x;
  else
    return x*-1;
}

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(z(a-c)<=d)
    cout<<"Yes"<<endl;
  else if((z(a-b)<=d)&&(z(b-c)<=d))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3600
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000

ll cnt(ll x) {

    ll val = 1;
    while(x!=1) {
        x /= 2;
        val++;
    }
    return val;
}

ll power(ll x, ll n) {

    if(n==0)
        return 1;

    return n%2==0 ? power(x*x, n/2) : x*power(x*x, n/2);
}

int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,ans=0,x;
    unordered_multiset<ll> ms;
    cin>>n;
    vector<ll> v;
    for(ll i=0; i<n; i++) {
        cin>>x;
        v.push_back(x);
        ms.insert(x);
    }
    sort(v.begin(), v.end());

    for(ll i=n-1; i>=0; i--) {
        x = v[i];
        if(!(ms.find(x)!=ms.end()))
            continue;
        ll val = power(2, cnt(x));
        if(ms.find(val - x)!=ms.end()) {
            ans++;
            ms.erase(ms.find(val-x));
            if(!(ms.find(x)!=ms.end())) {
                ans--;
                ms.insert(val - x);
                continue;
            }
            ms.erase(ms.find(x));
        }
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 10044
#include "stdio.h"
#include <iostream>
#include <vector>
#include <unordered_map>
#include<algorithm>

int read_int()
{
    int n;std::cin >> n;return n;
}

template<typename T>
std::vector<T> read_vector(int count)
{
    std::vector<T> v(count);
    for (int i=0; i<count; i++)
    {
        T tmp;std::cin >> tmp;v[i] = tmp;
    }
    return v;
}

template<typename T>
std::vector<std::vector<T>> read_vector(int row, int col)
{
    std::vector<std::vector<T>> vv(row);
    for (int i=0; i < row; i++)
    {
        auto v = read_vector<T>(col);vv[i] = v;
    }
    return vv;
}

int main()
{
    int h = read_int();
    int w = read_int();
    int m = read_int();

    std::vector<int> hi(h);
    std::vector<int> wi(w);
    //std::vector<int> total(m);
    std::unordered_map<int, int> total; 
    for (int i = 0; i < m; i++)
    {
        auto jj = read_int() - 1;
        auto ii = read_int() - 1;
        hi[jj] += 1;
        wi[ii] += 1;
        total[jj*w + ii] = 1;
    }

    std::vector<int>::iterator maxh_iter = std::max_element(hi.begin(), hi.end());
    //size_t hindex = std::distance(x.begin(), maxh_iter);
    int max_h = *maxh_iter;

    std::vector<int>::iterator maxw_iter = std::max_element(wi.begin(), wi.end());
    //size_t windex = std::distance(x.begin(), maxw_iter);
    int max_w = *maxw_iter;

    int max_b = max_h + max_w;
    if (max_b == h+w)
    {
        std::cout << h+w-1;
        return 0;
    }

    bool has_0 = false;

    std::vector<int> max_w_i;
    for (int j = 0; j < w; j++)
    {
        if (wi[j] != max_w)
            continue;
        max_w_i.push_back(j);
    }

    for (int i = 0; i < h; i++)
    {
        if (hi[i] != max_h)
            continue;

        // for (int j = 0; j < w; j++)
        // {
        //     if (wi[j] != max_w)
        //         continue;
        for (std::vector<int>::iterator itr=max_w_i.begin(); itr != max_w_i.end(); itr++)
        {
            int j = *itr;
            if (total.find(i * w + j) == total.end())
            {
                has_0 = true;
                break;
            }
        }
        if (has_0)
            break;
    }
    if (!has_0)
        max_b -= 1;

    std::cout << max_b;
    return 0;
}


Measured memory_bytes: 22252
#include<cstdio>
#include<vector>

using namespace std;

int main(void)
{
	int n;

	while(scanf("%d\n", &n)==1)
	{
		char s[n+2];
		vector<int> c(n+2);
		int w;

		scanf("%s", s);
		for(int i=0;i<n;i++)
		{
			c[i+1]=c[i];
			if(s[i]=='W') c[i+1]++;
		}
		w=c[n];
/*
	for(int i=0;i<n;i++) printf("%d ", c[i]);
	printf("\n");
	for(int i=0;i<n;i++) printf("%d ", (w-c[i+1]));
	printf("\n");
*/
		int ans=n;
		for(int i=0;i<n;i++)
		{
			int l=c[i];
			int r=n-1-i-(w-c[i+1]);
			int x=l+r;
			if(ans>x) ans=x;
//			printf("%d %d\n", l, r);
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(ll i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    map<int, int> mp;
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    for (int i=1;i<=n;i++) {
        mp[i] = 0;
    }
    rep(i,m){
        mp[a[i]]++;
        mp[b[i]]++;
    }
    for(auto x:mp){
        cout << x.second << endl;
    }

}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


  int main(){
    int M;
    cin >> M;
    print(48 - M);
  }

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

# #大きな値
INF = 10**10
#
# # DPtable
dp = [INF]*N

# dp = [10**10 for _ in range(N)]


#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))


print(dp[N-1])



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

//#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

int n, k;

void update(vector<int> &v){
    vector<int> next(n+1,0);
    rep(i,n){
        next[max(0,i-v[i])]   += 1;
        next[min(n,i+v[i]+1)] -= 1;
    }
    
    rep(i,n){
        next[i+1] += next[i];
    }
    
    next.resize(n);
    v = next;
}

signed main(){
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    while(k--){
        update(a);
        if(a[0] == n) break;
    }

    rep(i,n){
        printf("%d%c",a[i],(i == n-1 ? '\n' : ' '));
    }
    return 0;
}

Measured memory_bytes: 4988
import sys

INVERSE_ROTATIONS = {
    'N': [
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ],
    'S': [
        [1, 0, 0],
        [0, 0, 1],
        [0, -1, 0]
    ],
    'E': [
        [0, 0, -1],
        [0, 1, 0],
        [1, 0, 0]
    ],
    'W': [
        [0, 0, 1],
        [0, 1, 0],
        [-1, 0, 0]
    ]
}


def mul(mat1, mat2):
    return [
        [
            sum(mat1[i][k] * mat2[k][j] for k in range(3))
            for j in range(3)
        ]
        for i in range(3)
    ]


faces = [int(n) for n in sys.stdin.readline().strip().split()]
commands = sys.stdin.readline().strip()

rotation = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for c in commands:
    rotation = mul(rotation, INVERSE_ROTATIONS[c])
location = [rotation[i][2] for i in range(3)]

number = {
    (1, 0, 0): 3,
    (-1, 0, 0): 4,
    (0, 1, 0): 5,
    (0, -1, 0): 2,
    (0, 0, 1): 1,
    (0, 0, -1): 6
}[tuple(location)]

print(faces[number - 1])



Measured memory_bytes: 5624
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int n;
		cin>>n;
		if(n == 0) break;
		vector<vector<pair<int, int> > > g(n);
		ll sum = 0;
		REP(i, n - 1) {
			int a, b, t;
			cin>>a>>b>>t;
			--a;
			--b;
			g[a].pb({b, t});
			g[b].pb({a, t});
			sum += t;
		}
		queue<int> q;
		vector<ll> d(n, INF);
		q.push(0);
		d[0] = 0;
		while(!q.empty()) {
			int p = q.front();
			q.pop();
			REP(i, g[p].size()) {
				if(d[g[p][i].first] == INF) {
					d[g[p][i].first] = d[p] + g[p][i].second;
					q.push(g[p][i].first);
				}
			}
		}
		vector<int> pai;
		REP(i, n) {
			if(g[i].size() == 1 && i != 0) {
				sum -= g[i][0].second;
				pai.pb(g[i][0].first);
			}
		}
		sum = sum * 2;
		ll hoge = 0;
		REP(i, pai.size()) {
			hoge = max(hoge, d[pai[i]]);
		}
		sum -= hoge;
		cout<<sum<<endl;
	}
}

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

int main(){
    ll N; cin>>N;
    vector<ll> p(N);
    for (ll i = 0; i < N; i++){
        cin>>p[i];
    }
    ll m=p[0],ans=1;
    for (ll i = 1; i < N; i++){
        if(m>p[i]){
            m=p[i];
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4816
#include <stdio.h>
# include <string.h>

int main() {
    char c1[12], c2[12];
    int n1, n2;
    char u[12];
    
    scanf("%s %s", c1, c2);
    scanf("%d %d", &n1, &n2);
    scanf("%s", u);
    
    if (strcmp(c1, u) == 0)
        n1 -= 1;
    else
        n2 -= 1;
    printf("%d %d\n", n1, n2);

    return 0;
}


Measured memory_bytes: 128
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod        1000000007 
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod;}
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    if(a.first==b.first)
    return (a.second < b.second);
    return (a.first < b.first); 
} 
ll ans=0;
vector<ll>root;
void calldfs(ll v,int visit[])
{
 visit[v]=1;
 for(int i=0;i<m1[v].size();i++)
 {
  if(visit[m1[v][i]]==0)
  {
   calldfs(m1[v][i],visit);
  }
 }
}
void dfs(ll n)
{
 ll i;
 int visit[1000000]={0};
 fli(i,1,n+1)
 {
  visit[i]=0;
 }
 fli(i,1,n+1)
 {
  if(visit[i]==0)
  {
   calldfs(i,visit);
   ans++;
  } 
 }
}
void comp()
{
 ll n,i,k,temp;
 vector<ll>v1;
 v1.pb(1);
 fl(i,50)
 {
  v1.pb(v1[v1.size()-1]*2);
 }
 cin>>n>>k;
 double ans=0.0;
 ll low,high,mid;
 fli(i,1,n+1)
 {
  temp=k/i;
  if(k%i)
  temp++;
  low=0;
  high=50;
  double curr;
  while(low<=high)
  {
   mid=(low+high)/2;
   if(v1[mid]>=temp)
   {
    curr=v1[mid];
    high=mid-1;
   }
   else
   {
    low=mid+1;
   }
  }
  //cout<<curr<<" ";
  double temp1=1/(curr*(double)n);
  ans=ans+temp1;
 }
 cout<<setprecision(12)<<fixed<<ans;
} 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define mod 1000000007
#define cbrt cbrtl
using namespace __gnu_pbds;
using namespace std;

int main()
{
  IOS

  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll i,ans=0;
  for(i=0;i<n;)
  {
  	 char x=s[i];
  	 while(i<n && s[i]==x)
  	 	i++;
  	 ans++;
  }
  cout<<ans;
  return 0; 
  		
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++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(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,v.size())i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(v.size())o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pii a,pii b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n;cin>>n;
  ll c,k; cin>>c>>k;
  vl t(n);
  cin>>t;
  sort(rng(t));
  ll wait = 0;
  ll lim = t[0]+k;
  int ans=0;
  rep(i,n){
    while(t[i]>lim ){
      ll go = min(wait,c);
      wait -= go;
      lim = t[i-wait]+k;
      ans++;
    }
    wait++;

  }
  ans+=dup(wait,c);
  cout<<ans<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

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

typedef long long ll;

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

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 (b<a) { a=b; return 1; } return 0; }

int dx[] = {1, -1, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0};

int main() {
    int N, K;
    cin >> N >> K;
    
    ll ans = 1;
    rep(i, N) ans += (ans < K ? ans : K);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
 	
int dpf(int i, int t, int k)
{

}
#define N 100010
int n, q;
string s;
int seg[4 * N];
vector<int> a;
void build(int node, int l, int r)
{
	if(l == r)
		seg[node] = a[l];
	else
	{
		int mid = l + r >> 1;
		build(2 * node + 1, l, mid);
		build(2 * node + 2, mid + 1, r);
		seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
	}
}

int Q(int node, int l, int r, int x, int y)
{
	if(x <= l && r <= y)
		return seg[node];
	else
	{
		int ans = 0;
		int mid = l + r >> 1;
		if(x <= mid)
			ans += Q(2 * node  + 1, l, mid, x, y);
		if(y > mid)
			ans += Q(2 * node + 2, mid + 1, r, x, y);
		return ans;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> q >> s;
	int l, r;
	for (int i = 0; i < n - 1; ++i)
	{
		if(s[i] == 'A' && s[i + 1] == 'C')
			a.pb(1);
		else
			a.pb(0);
	}
	build(0, 0, n - 1);
	for (int i = 0; i < q; ++i)
	{
		cin >> l >> r;
		cout << Q(0, 0, n - 1, l - 1, r - 2) << "\n";
	}

	return 0;
}

Measured memory_bytes: 2504
n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=[]
for lhs in range(k+1):
    for rhs in range(k-lhs+1):
        if lhs+rhs<=n:
            array=v[:lhs]+v[n-rhs:]
        else:
            array=v[:]
        # print(v[:lhs],v[n-rhs:])
        for i in range(k+1-lhs-rhs):
            array.sort()
            ans.append(sum(array[i:]))
# print(ans)
print(max(ans))

Measured memory_bytes: 8600
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    string S;
    cin >> S;

    int zero = 0;
    int one = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '0')
        {
            zero++;
        }
        else
        {
            one++;
        }
    }
    int ans = min(one, zero) * 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll a; cin >> a;
    ll b1, b2; char c;
    cin >> b1 >> c >> b2;
    co(a*(b1*100 + b2)/100);

    return 0;
}


Measured memory_bytes: 3644
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B
// DFS algorithm
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool dfs(vector<vector<int>> &A, vector<int> &U, vector<int> &R, int c)
{
        if (U[c] == 2)
                return true;
        if (U[c] == 1)
                return false;
        U[c] = 1;
        for (auto a: A[c])
                if (!dfs(A, U, R, a))
                        return false;
        U[c] = 2;
        R.push_back(c);
        return true;
}

int main(int argc, char **argv)
{
        int V, E;
        cin >> V >> E;
        vector<vector<int>> A(V);
        for (int i = 0; i < E; i++) {
                int s, t;
                cin >> s >> t;
                A[s].push_back(t);
        }
        vector<int> U(V), R;
        bool ok = true;
        for (int i = 0; i < V && ok; i++)
                if (!U[i])
                       ok = dfs(A, U, R, i);
        if (!ok) {
                cout << "Found cyclic path" << endl;
                return 0;
        }
        reverse(R.begin(), R.end());
        for (auto r: R)
                cout << r << endl;
        return 0;
}

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

int main() {
  int N, d;
  cin >> N;
  d = 0;
  vector<int> vec(N);
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i=0; i<N; i++) {
    if (i%2 == 0) {
      d += vec.at(i);
    } else {
      d -= vec.at(i);
    }
  }
  cout << d << endl;
}


Measured memory_bytes: 256
n1=int(input())
a=list(map(int,input().split()))
n2=int(input())
b=list(map(int,input().split()))
c=[]
d=0
for i in b:
		left=0
		right=n1
		while left<right:
			mid=int((left+right)/2)
			if i==int(a[mid]):
				d+=1
				break
			elif i<a[mid]:
				right=mid
			else:
				left=mid+1
print(d)


Measured memory_bytes: 16712
#include<bits/stdc++.h>
using namespace std;
int n, m, a[333][333], tong[333];
bool mark[333];
int main(){
    cin>>n>>m;
    for(int i = 1;i <= n; i++){
        for(int j = 1;j <= m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    int ans = n, ma = 0, pos;
    for(int i = 1;i <= n; i++){
        tong[a[i][1]]++;
        if(tong[a[i][1]] > ma){
            ma = tong[a[i][1]];
            pos = a[i][1];
        }
    }
    ans = ma;
    for(int i = 1;i < m; i++){
        mark[pos] = 1; ma = 0;
        memset(tong, 0, sizeof(tong));
        for(int j = 1;j <= n; j++){
            for(int k = 1;k <= m; k++){
                if(!mark[a[j][k]]){
                    tong[a[j][k]]++;
                    if(tong[a[j][k]] > ma){
                        ma = tong[a[j][k]];
                        pos = a[j][k];
                    }
                    break;
                }
            }
        }
        ans = min(ans, ma);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

void failure () {
  cout << -1 << endl;
  exit(0);
}

const int MAX_N = 105;

int arr [MAX_N];
int del [MAX_N];
int inv [MAX_N];
int ans [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    inv[i] = i - arr[i];
    if (inv[arr[i]] < 0) {
      failure();
    }
  }

  for (int i = n; i >= 1; i--) {
    int rz = -1;
    for (int j = 1; j <= n; j++) {
      if (!del[j] && inv[j] == 0) {
	rz = j;
      }
    }

    if (rz == -1) failure();
    ans[i] = arr[rz];
    del[rz] = 1;
    for (int j = rz + 1; j <= n; j++) {
      inv[j]--;
    }
  }

  for (int i = 1; i <= n; i++) {
    if (ans[i] > i) failure();
  }

  for (int i = 1; i <= n; i++) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;


int main()
{
	int X,Y;
	cin>>X>>Y;
	int ans =0;
	if(X == 1){
		ans += 300000;
	}else if(X == 2){
		ans += 200000;
	}else if(X == 3){
		ans += 100000;
	}

	if(Y == 1){
		ans += 300000;
	}else if(Y == 2){
		ans += 200000;
	}else if(Y == 3){
		ans += 100000;
	}

	if(X == 1 && Y == 1){
		ans += 400000;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
public class Main {


		public static void main(String[] args) {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		double i, r, s;
		i = scan.nextDouble();

		if(0<i && i < Math.pow(10, 4)){
			
			r = i*i*Math.PI;
			System.out.print(String.format("%.6f",r));
			System.out.print(" ");
			s = i*2*Math.PI;
			System.out.println(String.format("%.6f",s));

		}


		}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N){
  	cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = 1;
  if(N == 1){
  	cout << 1 << endl;
  }else{
  	rep(i, N - 1){
      if(vec.at(i) != vec.at(i + 1)){
      	ans++;
      }
    }
  cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
 
int main(){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    printf("%.8lf\n",hypot(x2-x1,y2-y1));
}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
int a = 0;
int b = 0;
int cnt = 0;


int main() {
  int N,M = 0;
  cin >> N >> M;
  if(N == M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
ll n, a[314514], itrplace[314514];
set<ll> s;
int main() {
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    itrplace[a[i]] = i + 1;
  }
  s.insert(0);
  s.insert(n + 1);
  ll cc = 0;
  REP(i, n) {
    ll center = itrplace[i + 1];
    auto itr = s.upper_bound(center);
    auto itr2 = itr;
    itr2--;
    ll cnt = ((*itr) - center) * (center - (*(itr2)));
    cc += cnt * (i + 1);
    //  cout << cnt << endl;
    s.insert(center);
  }
  cout << cc << endl;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}



int check(int n) {

	int temp = n + 9;

	temp = temp / 10;
	return temp * 10;



}

bool comp(pair<string,pair<int,int>> a , pair<string,pair<int,int>> b) {


	// return a % 10 > b % 10;
	if(a.F!=b.F)
		return a.F<b.F;
	return a.S.F>b.S.F;

}

int main() {
	int i, n, m, k, c = 0;
	c_p_c();
	cin>>n;
	int a[n];
	fo(i,n) cin>>a[i];
	// sort(a,a+n);
	for (int i = 1; i < n; ++i)
	{
		/* code */
		a[i]=a[i]+a[i-1];
	}
	// parray(a,n);


	int mini  = INF;
	for (int i = 1; i < n; ++i)
	{

		int sum1= a[i-1];
		int sum2=a[n-1]-a[i-1];
		// watch3(sum1,sum2,abs(sum1-sum2));
		mini=min(mini,abs(sum1-sum2));
	}

	cout<<mini<<endl;
	return 0;
}



Measured memory_bytes: 3592
#include<stdio.h>
int main(){
  int N,i,j,com,minj,num=0;
  scanf("%d",&N);
    int A[N];
    for(i=0;i<N;i++){
      scanf("%d",&A[i]);
    }
    /*selection sort*/
    for(i=0;i<=N-1;i++){
      minj = i;
   	 for(j=i;j<=N-1;j++){
	   if(A[j]<A[minj]){
	     minj = j;
	   }
   	 }
   	 com = A[i];
   	 A[i] = A[minj];
   	 A[minj] = com;
   	 if(i != minj){
	   num++;
   	 }
    }
    for(i=0;i<N;i++){
      printf("%d",A[i]);
      if(i<N-1){
	printf(" ");
      }
    }
    printf("\n");
    printf("%d\n",num);
    return 0;
}



Measured memory_bytes: 2140
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cassert>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int m;
	cin >> m;
	
	long long cnt = 0;
	long long sum = 0;
	
	for (int i = 0; i != m; ++i)
	{
		long long d, c;
		cin >> d >> c;
		
		cnt += c;
		sum += d * c;
	}
	
	cout << cnt + (sum - 1) / 9 - 1 << '\n';
	
	return 0;
}


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

using namespace std;

bool is_completed(vector<int> &blocks) {

    for(int i = 0; i < blocks.size(); ++i) {
        if(blocks[i] != i + 1) {
            return false;
        }
    }

    return true;
}

int main() {

    int n;

    while(cin >> n, n) {

        vector<int> b(n);
        int cnt = 0;

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

        bool complete = false;
        while(!(complete = is_completed(b)) && cnt < 10000) {

            vector<int> nb;

            for(int i = 0; i < b.size(); ++i) {
                --b[i];
            }

            for(int i = 0; i < b.size(); ++i) {
                if(b[i]) {
                    nb.push_back(b[i]);
                }
            }

            nb.push_back(b.size());

            b = nb;

            ++cnt;

        }

        if(complete) {
            cout << cnt << endl;
        } else {
            cout << -1 << endl;
        }

    }

}

Measured memory_bytes: 3172
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
ant=[a,b,c,d,e]
def antenna(ant,k):
  for i in range(4):
    for ii in range(1,5):
      if ant[ii]-ant[i]>k:
        return ":("
  else:
    return "Yay!"
print(antenna(ant,k))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::max;
using std::endl;

template <typename T>
class Vector {
  private:
  unsigned int end;
  unsigned int alloc;
  public:
  T* A;
  Vector(): end(0), alloc(1), A((T *)malloc(sizeof(T))){}
  // Vector(){
  //   end = 0;
  //   alloc = 1;
  //   A = (T *)malloc(sizeof(T));
  // }
  Vector(const unsigned int initial_size){
    end = initial_size;
    alloc = max((unsigned int)1, initial_size);
    A = (T *)malloc(sizeof(T) * initial_size);
  }
  Vector(const Vector &other){
    end = other.end;
    alloc = other.alloc;
    A = (T *)malloc(sizeof(T) * alloc);
    memcpy(A, other.A, sizeof(T) * alloc);
  }
  Vector &operator=(const Vector &other){
    if(this != &other){
      end = other.end;
      alloc = other.alloc;
      A = (T *)malloc(sizeof(T) * alloc);
      memcpy(A, other.A, sizeof(T) * alloc);
    }
    return *this;
  }
  unsigned int size()const{
    return end;
  }
  void push_back(T v){
    if(end < alloc){
    }else{
      if(alloc == 0 || A == NULL){
        A = (T *)malloc(sizeof(T));
        alloc++;
      }else{
      unsigned int nalloc = alloc * 2;
      T* nA = (T *)malloc(sizeof(T) * nalloc);
      memcpy(nA, A, sizeof(T) * end);
      free(A);
      A = nA;
      alloc = nalloc;
      }
    }
    A[end] = v;
    end++;
  }
  void pop_back(){
    if(end == 0) return;
    end--;
  }
  T &operator[](const unsigned int idx)const{
    return A[idx];
  }
  ~Vector(){
    free(A);
  }
};

class WUnionFind {
  public:
  Vector<int> par;
  Vector<int> rank;
  Vector<int> dw;

  WUnionFind(int size): par(size), rank(size), dw(size){
    for(int i = 0; i < size; i++){
      par[i] = i;
      rank[i] = 0;
      dw[i] = 0;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    int tmp = root(par[x]);
    dw[x] += dw[par[x]];
    return par[x] = tmp;
  }

  int weight(int x){
    root(x);
    return dw[x];
  }

  void unite(int x, int y, int w){
    int xroot = root(x);
    int yroot = root(y);
    w += weight(x); w -= weight(y);
    if(rank[xroot] < rank[yroot]){
      par[xroot] = yroot;
      dw[xroot] = -w;
    }else{
      par[yroot] = xroot;
      dw[yroot] = w;
      if(rank[xroot] == rank[yroot]){
        rank[yroot]++;
      }
    }
  }
};


int main(void){
  int n, q; cin >> n >> q;
  WUnionFind wuf(n);
  
  for(int i = 0; i < q; i++){
    int op, x, y, z;
    cin >> op;
    if(op == 0){
      cin >> x >> y >> z;
      wuf.unite(x, y, z);
    }else{
      cin >> x >> y;
      if(wuf.root(x) != wuf.root(y)){
        cout << "?" << endl;
      }else{
        cout << wuf.dw[y] - wuf.dw[x] << endl;
      }
    }
  }
}



Measured memory_bytes: 3852
import java.util.*;

public class Main {
    static long MOD = 1000000007;

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        char[][] chs = new char[2][n];
        chs[0] = sc.next().toCharArray();
        chs[1] = sc.next().toCharArray();

        List<Boolean> isOneBlocks = new ArrayList<>();

        for(int i = 0; i < n;) {
            if(chs[0][i] == chs[1][i]) {
                isOneBlocks.add(true);
                i += 1;
            } else {
                isOneBlocks.add(false);
                i += 2;
            }
        }

        long ans = 1;
        if(isOneBlocks.get(0)) {
            ans *= 3;
        } else {
            ans *= 6;
        }

        for (int i = 1; i < isOneBlocks.size(); i++) {
            if(isOneBlocks.get(i - 1)) {
                ans *= 2;
                ans %= MOD;
            } else {
                if(!isOneBlocks.get(i)) {
                    ans *= 3;
                    ans %= MOD;
                }
            }
        }

        System.out.println(ans);
    }
}

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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; }

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int n,m;
int solve(){
    int ans=0;
    vvi d(n+1,vi(n+1,inf));
    vector<vector<bool>> br(n+1,vector<bool>(n+1,false));
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
        br[a][b] = true;
        br[b][a] = true;
    }
    rrep(i,n){
        d[i][i]=0;
    }
    rrep(k,n){
        rrep(i,n){
            rrep(j,n){
                if(chmin(d[i][j] , d[i][k] + d[k][j])){
                    br[i][j] = false;
                }
            }
        }
    }
    rrep(i,n-1){
        srep(j,i+1,n+1){
            if(br[i][j]) ans++;
        }
    }
    return m-ans;
}

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

    while(cin >> n >> m){
        int ans = 0;
        cout << solve() << endl;
        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	bool num[101];
	int n,m,hanako[100],taro[100];
	while(cin>>n>>m,n,m){
		int sum_hanako=0,sum_taro=0;
		for(int i=0;i<n;i++){
			cin>>taro[i];
			sum_taro+=taro[i];
		}
		for(int i=0;i<m;i++){
			cin>>hanako[i];
			sum_hanako+=hanako[i];
		}
		bool f=false;
		vector<int> ans;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(sum_hanako-hanako[j]+taro[i]==sum_taro-taro[i]+hanako[j]){
					f=true;
					ans.push_back(hanako[j]+taro[i]);
				}
			}
			if(f)break;
		}
		if(f){
			sort(ans.begin(),ans.end());
			int h=(ans[0]-(sum_hanako-sum_taro)/2)/2;
			cout<<h<<" "<<ans[0]-h<<endl;
		}else cout<<-1<<endl;		
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int len=s.length();
	rep(i,len/2){
		if(s.at(i)==s.at(len-i-1)){
			continue;
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	rep(i,(len/2)/2){
		if(s.at(i)==s.at((len/2)-i-1)){
			continue;
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        string s = ReadLine();
        int a = 0, b = 0, c = 0;

        for (int i = 0; i < 3; i++)
        {
            switch (s[i])
            {
                case 'a':
                    a++;
                    break;
                case 'b':
                    b++;
                    break;
                case 'c':
                    c++;
                    break;
            }
        }

        bool good = a == 1 && b == 1 && c == 1 ;
        WriteLine(good?"Yes":"No");
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int a = Integer.parseInt(tokens[0]);
		int b = Integer.parseInt(tokens[1]);
		if (a % 2 == 1 && b % 2 == 1) {
			System.out.println("Odd");
		} else {
			System.out.println("Even");
		}
		in.close();
	}

}

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


int main(int argc, char **argv)
{
  double x,d,n;
  int xi;
  scanf("%lf %lf",&d,&n);
  x = pow(100.0,d) * n;
  xi = (int)x;
  if(n == 100.0){
    if(d == 0.0)
      xi = 101;
    if(d == 1.0)
      xi = 10100;
    if(d == 2.0)
      xi = 1010000;
  }
  printf("%d\n",xi);

  return 0;
}


Measured memory_bytes: 128