akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 int n,m;
  cin >> n;
  string tmp;
  vector<int> sum(n);
  for(int i=0;i<n;i++){
    sum.at(i)=1;
  }
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> tmp;
    for(int j=0;j<n;j++){
      if(tmp==s.at(j)){
        sum.at(j)++;
      }
    }
    s.at(i)=tmp;
  }
  cin >> m;
  
  for(int i=0;i<m;i++){
    cin >> tmp;
    for(int j=0;j<n;j++){
      if(s.at(j)==tmp){
        sum.at(j)--;
      }
    }
  }
  sort(sum.begin(), sum.end());
  if(sum.at(n-1)>0){
    cout << sum.at(n-1) << endl;
  }
  else{
    cout << "0" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll cd = 1000000007;
const double pi = 3.14159265358979;

int main() {
  	constexpr ll MOD=1e9+7;
    ll N, K;
    cin >> N >> K;
    ll count = 0;
    vel sum(N + 2);
    sum[0] = 0;
    rep(i, N+1) {
        sum[i+1] = sum[i] + i;
    }
    REP(i, K, N+2) {
        ll max, min;
        max = sum[N+1] - sum[N+1-i];
        min = sum[i] - sum[0];
        count += (max - min + 1)%MOD;
      	count%=MOD;
    }
    cout << count << endl;
}

Measured memory_bytes: 4700
n = int(input())
done = [False for _ in range(n)]
A = [int(input()) - 1 for _ in range(n)]
tmp = 0
for i in range(n + 1):
    if A[tmp] == 1:
        print(i + 1)

        break
    if done[tmp]:
        print(-1)
        break
    else:
        done[tmp] = True
    tmp = A[tmp]
else:
    print(-1)


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

int main(){
  int n,x,y,b,p,i;
  double ans=0.8,hoge,str,foo;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> x >> y >> b >> p;
    if(b>=5&&p>=2){
      foo=x*b+y*p;
      foo=foo*ans;
      cout << foo << endl;
    }else{
      hoge=x*b+y*p;
      if(b>=5&&p<2){
	str=x*b+y*2;
	str=str*ans;
      }else if(b<5&&p>=2){
	str=x*5+y*p;
	str=str*ans;
      }else{
	str=x*5+y*2;
	str=str*ans;
      }
      if(hoge<=str){
	cout << hoge << endl;
      }else if(str<=hoge){
	cout << str << endl;
      }
    }
  }
  return 0;
}



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

int main(){
    int a,b,c,d,e,f,ob,oc,oe;
    cin>>a>>b>>c>>d>>e>>f;
    
    if(a>b){
        ob=b;
        b=a;
        a=ob;
    }
    if(b>c){
        oc=c;
        c=b;
        b=oc;
    }
    if(c>d){
        oc=c;
        c=d;
        d=oc;
    }
    if(a>b){
        ob=b;
        b=a;
        a=ob;
    }
    if(b>c){
        oc=c;
        c=b;
        b=oc;
    }
    if(c>d){
        oc=c;
        b=a;
        a=ob;
    }
    if(e>f){
        oe=e;
        e=f;
        f=oe;
    }
    if(a>b){
        ob=b;
        b=a;
        a=ob;
    }
    if(b>c){
        oc=c;
        c=b;
        b=oc;
    }
    if(c>d){
        oc=c;
        c=d;
        d=oc;
    }
    if(a>b){
        ob=b;
        b=a;
        a=ob;
    }
    if(b>c){
        oc=c;
        c=b;
        b=oc;
    }
    if(c>d){
        oc=c;
        b=a;
        a=ob;
    }
    if(e>f){
        oe=e;
        e=f;
        f=oe;
    }


    cout<<b+c+d+f<<endl;

}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

vector<vector<int>> to(100005);
int n;
vector<int> dist;
void dfs(int v, int d=0, int p=-1) {
	dist[v] = d;
	for (int u : to[v]) {
		if (u == p) continue;
		dfs(u, d+1, v);
	}
}
vector<int> calcDist(int s) {
	dist = vector<int>(n);
	dfs(s);
	return dist;
}

int main() {
	cin >> n;
	int s, t;
	cin >> s >> t;
	--s; --t;
	rep(i,n-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	vector<int> distS = calcDist(s);
	vector<int> distT = calcDist(t);

    int mx = 0;
	rep(i,n) {
		if (distS[i] < distT[i]) {
			mx = max(mx, distT[i]);
		}
	}
	int ans = mx-1;
	cout << ans << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

int n,m,k;
int main(){
  cin>>n>>m>>k;
  LL s=0;
  REP(i,n-1)s=(s+((((LL)(i+1)*(LL)(n-1-i))%MOD)*m%MOD)*m%MOD)%MOD;
  REP(i,m-1)s=(s+((((LL)(i+1)*(LL)(m-1-i))%MOD)*n%MOD)*n%MOD)%MOD;
  Combinatrics comb;
  //cerr<<s<<endl;
  cout<<(comb.nck(n*m-2,k-2)*s)%MOD<<endl;
  return 0;
}


Measured memory_bytes: 8064
# include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  cin >> n;
  int temp, fin[n];
  for (int i = 0; i < n; i++){
  cin >> temp;
    fin[temp-1] = i+1;
  }
  for (int i = 0; i < n; i++)
    cout << fin[i]<<' ';
  cout <<'\n';
	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str1=sc.next();
		String str2=sc.next();
		int ans=0;
		for(int i=0;i<str1.length();i++){
		    if(str1.charAt(i)!=str2.charAt(i))
		    ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 41180
//Rudrakshi

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define mod1 1000000007
#define mod2 998244353
#define MAX ll(1e3)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//shuffle

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int minimum(int arr[],int n){
   int dp[n+1];
  dp[1] = 0;
  int op1,op2;
  for(int i=2;i<=n;i++){
     op1 = abs(arr[i]-arr[i-1]) + dp[i-1];
    if(i!=2){
       op2 = abs(arr[i]-arr[i-2]) + dp[i-2];
    }
    if(i==2){
       op2 = INT_MAX;
      
    }
    dp[i] = min(op1,op2);
   // cout<<dp[i]<<"\n";
  }
  return dp[n];
}

void solve()
{
    int n;
    cin >> n;
    int arr[n+1];
    for(int i=1;i<=n;i++){
      cin >> arr[i];
    }
    cout<<minimum(arr,n);
        
}
int32_t main()
{
	//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
    //#endif
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    	solve();
    	
    return 0;
}

Measured memory_bytes: 4356
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int dp[105][4][2];
int main() {
  ios::sync_with_stdio(false);
  string S;
  int K;
  cin >> S >> K;
  dp[0][K-1][1] = 1;
  dp[0][K-1][0] = S[0] - '0' - 1;
  dp[0][K][0] = 1;
  //for (int i=0; i<=K; i++) cout << dp[0][i][0] << ' ' << dp[0][i][1] << ' ';
  //cout << endl;
  int N = S.size();
  for (int i=1; i<N; i++) {
    int d = S[i] - '0';
    for (int j=0; j<=K; j++) {
      dp[i][j][0] = dp[i-1][j][0];
      if (j < K) dp[i][j][0] += dp[i-1][j+1][0] * 9;
      if (d > 0 && j < K) dp[i][j][0] += dp[i-1][j+1][1] * (d-1);
      if (d > 0) dp[i][j][0] += dp[i-1][j][1];

      if (d > 0 && j < K) dp[i][j][1] = dp[i-1][j+1][1];
      else dp[i][j][1] = dp[i-1][j][1];

    }
    //for (int j=0; j<=K; j++) cout << dp[i][j][0] << ' ' << dp[i][j][1] << ' ';
    //cout << endl;
  }
  cout << dp[N-1][0][0] + dp[N-1][0][1] << endl;
}

Measured memory_bytes: 256
import bisect
n = int(input())
v = sorted(list(map(int, input().split())))

for i in range(n - 1):
    v_ = (v[0] + v[1]) / 2
    v.pop(0)
    v.pop(0)
    bisect.insort_left(v, v_)

print(v[0])

Measured memory_bytes: 3188
import bisect
A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    SL, SR, TL, TR = 10**20, 10**20, 10**20, 10**20
    i = bisect.bisect_left(S, x)
    if i != 0:
        SL = x-S[i-1]
    if i != A:
        SR = S[i]-x

    j = bisect.bisect_left(T, x)
    if j != 0:
        TL = x-T[j-1]
    if j != B:
        TR = T[j]-x

    ans = min(max(SL, TL), min(2*SL+TR, SL+2*TR),
              min(2*TL+SR, TL+2*SR), max(SR, TR))
    print(ans)


Measured memory_bytes: 16144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
char s[100][100];
int H, W, stx, sty;
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= W || y >= H)
    return;
  if (s[y][x] == '.') {
    s[y][x] = 'x';
  } else
    return;
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
}
int main() {
  while (cin >> W >> H) {
    int ans = 0;
    if (H == 0 && W == 0)
      break;
    rep(i, H) rep(j, W) {
      cin >> s[i][j];
      if (s[i][j] == '@') {
        stx = j;
        sty = i;
      }
    }
    s[sty][stx] = '.';
    dfs(stx, sty);
    rep(i, H) rep(j, W) {
      if (s[i][j] == 'x')
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <regex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

template <class... T>
void output__(T ...a) {
  for(auto v: {a...}) {
    cout << v << " ";
  }
  cout << endl;
}

int main(){
  char in(a, b) out(a > b ? ">" : (a < b ? "<" : "="))
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	intt N; std::cin >> N;
	std::vector<intt> a(N);
	for (auto& r : a) std::cin >> r;
	intt count = 1;
	for (auto& r : a) {
		intt t = 0;
		if ((r - 1) % 2 == 1)
			++t;
		if (r % 2 == 1)
			++t;
		if ((r + 1) % 2 == 1)
			++t;
		count *= t;
	}
	std::cout << std::pow(3, N) - count << std::endl;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
ll S[100100];
ll S2[100100];


int main(){
    int N;
    ll M;
    cin >> N >> M;
    REP(i, N){
        ll a;
        cin >> a;
        A[i] = a;
        S[i] = a;
        if(i != 0) S[i] += S[i-1];
        S[i] %= M;
    }
    sort(S, S+N);

    //REP(i, N) printf("%d ", S[i]);
    //printf("\n");
    ll ans = 0;
    ll num;
    //num = upper_bound(S, S+N, 0) - lower_bound(S, S+N, 0);
    //ans += num*(num-1)/2;
    ll last = -1;
    REP(i,N){
        ll a = S[i];
        if(last == a) continue;
        num = upper_bound(S, S+N, a) - lower_bound(S, S+N, a);
        if(a == 0) num++;
        ans += num*(num-1)/2;
        //cout << ans << endl;
        last = a;
    }

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


Measured memory_bytes: 1792
while true
    str = gets.chomp
    break if str == "."
    arr, result = [], "yes"
    str.each_char{|c|
        case c
        when ')'
            if arr.pop != '('
                result = "no"
                break
            end
        when ']'
            if arr.pop != '['
                result = "no"
                break
            end
        when '(', '['
            arr << c
        end
    }
    result = "no" if arr != []
    puts result
end



Measured memory_bytes: 6860
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
const ll INF =1LL << 62;
using namespace std;
int dy[4] = { 0, -1, 0, 1 };
int dx[4] = { 1, 0, -1, 0 };
bool inside(int y, int x, int H, int W) {
    return 0 <= y && y < H && 0 <= x && x < W;
}
int h,w;
vector< vector<int> > field;
int ans;
void dfs(int x,int y, int depth){
	if(depth+1>=ans){ return ;}
	for(int i=0;i<4;i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(inside(ny,nx,h,w)){
			if(field[ny][nx]!=1){
			while(inside(ny,nx,h,w)){
				if(field[ny][nx]==3){
					ans=min(ans,depth+1);
					return ;
				}

				if(field[ny][nx]==1){
					field[ny][nx]=0;
					dfs(nx-dx[i],ny-dy[i],depth+1);
					field[ny][nx]=1;
					break;
				}

				nx+=dx[i];
				ny+=dy[i];
			}
		    }
		}
	}
	return ;
}
int main(){
	while(1){
		cin >>w>>h;
		if(h==0&&w==0) break;
		int sx,sy;
		field.assign(h,vector<int>(w));
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				cin >>field[y][x];
				if(field[y][x]==2){
					sx=x;
					sy=y;
					field[y][x]=0;
				}
			}
		}
		ans=11;
		dfs(sx,sy,0);
		cout << (ans<=10?ans:-1) << endl;
	}
	return 0;
}


Measured memory_bytes: 3152
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=3000;

int n,MOD;

int C[MAXN+1][MAXN+1];


int p2[MAXN+1];
int p2p[MAXN+1];
int S[MAXN+1][MAXN+1]; // stirling number of second kind


int pw(int x,int n) { int ret=1; while(true) { if(n&1) ret=(ll)ret*x%MOD; if((n>>=1)==0) return ret; x=(ll)x*x%MOD; } }


void run() {
	scanf("%d%d",&n,&MOD);
	
	REPE(i,n) { C[i][0]=C[i][i]=1; FOR(j,1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD; }
	p2[0]=1; FORE(i,1,n) p2[i]=(ll)p2[i-1]*2%MOD;
	p2p[0]=1; FORE(i,1,n) p2p[i]=(ll)p2p[i-1]*2%(MOD-1);
	memset(S,0,sizeof(S)); S[0][0]=1; FORE(i,1,n) FORE(j,1,n) S[i][j]=((ll)j*S[i-1][j]+S[i-1][j-1])%MOD;
	//REPE(i,n) { printf("S%d:",i); REPE(j,n) printf(" %d",S[i][j]); puts(""); }

	int ret=0;
	REPE(nerr,n) {
		int nok=n-nerr,cur=0,mlt=1;
		REPE(nextra,nerr) {
			// no zero
			cur=(cur+(ll)S[nerr][nextra]*mlt)%MOD;
			// at least one zero
			cur=(cur+(ll)S[nerr][nextra+1]*mlt%MOD*(nextra+1))%MOD;
			mlt=(ll)mlt*p2[nok]%MOD;
		}
		cur=(ll)cur*C[n][nerr]%MOD*pw(2,p2p[nok])%MOD;
		//printf("nerr=%d: %d\n",nerr,cur);
		if(nerr%2==0) ret=(ret+cur)%MOD; else ret=(ret+MOD-cur)%MOD;
	}
	printf("%d\n",ret);
}

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


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

typedef long long ll;
int main() {
    vector<ll>x(2), y(2);
    ll ans = 1e10;
    cin >>x[0]>>y[0];
    x[1] = -x[0];
    y[1] = -y[0];
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++) {
            if(x[i] < y[i])
                ans = min(ans, abs(y[i]-x[j])+i+j);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A;
    int B;
    cin >> A >> B;
    int ans;
    if(A > 9) {ans = -1;}
    else if(B > 9) {ans = -1;}
    else {ans = A * B;}
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int N;
    cin >> N;
    vector<ll> v(N);
    FOR(i, N){
        cin >> v[i];
    }

    ll sol = 0;
    FOR(i, N){
        for(int j=i+1; j<N; j++){
            sol += v[i]*v[j];
        }
    }
    cout << sol <<endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
k = []
for i in range(n):
    K = list(map(int,input().split()))
    k.append(K)
ans = 0
for q in range(1,m+5):
    Z = 0
    for i in range(n):
        a = []
        b = []
        a.append(k[i])
        b = a[0]
        for l in range(1, b[0]+1):
            if b[l] == q:
                Z += 1
    if Z == n:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
     
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
     
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>
     
int main(){
  lli N,A,B,countA=0,countB=0;
  string str;

  cin>>N>>A>>B;
  cin>>str;

  for(int i=0;i<str.length();i++){
    if(str[i]=='c'){
      cout<<"No"<<endl;
    }else if(str[i]=='b'){
      if(countB<B and countA+countB<A+B){
	cout<<"Yes"<<endl;
	countB++;
      }else{
	cout<<"No"<<endl;
      }
    }else{
      if(countA+countB<A+B){
	cout<<"Yes"<<endl;
	countA++;
      }else{
	cout<<"No"<<endl;
      }
    }
  }
      
  return 0;
}


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

const long long MOD = 1e9 + 7;

int N, M;
// DPテーブル、0-N段までのDP値を管理する
// 数え上げのため、初期値は0
long long dp[100100] = {0LL};
// 何段目が壊れているかを管理する配列
bool is_broken[100100] = {false};

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int a = 0;
    scanf("%d", &a);
    is_broken[a] = true;
  }
  // 足場0は初期値1, 初期値1とみなすことで、
  // フィボナッチ数列のN番目の項を求める問題と同じように解くことができる
  // {1, 1, 2, 3, 5, ... , N}
  // ただし、dp値を更新する際に、足場が壊れているかを確認する
  dp[0] = 1LL; 
  for (int i = 0; i < N; i++) {
    if (is_broken[i]) continue;
    if (!is_broken[i + 1]) dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    if (!is_broken[i + 2]) dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
  }

  cout <<dp[N] << endl;
}


Measured memory_bytes: 1152
s = input()[::-1]

dataset = [0]*2019
dataset[0] = 1

n = 0
d = 1

for i in s:
    n += int(i) * d
    a = n % 2019
    dataset[a] += 1
    d *= 10
    d %= 2019

count = 0
for i in dataset:
    count += i * (i-1) // 2

print(count)

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

typedef long long ll;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
 const ll MOD=1000000007ll;
//const ll MOD=998244353ll;
const int MAX=700000;

ll fact[MAX], fact_inv[MAX];

// 繰り返し二乗法
ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int main(){
 ios::sync_with_stdio(false);
	cin.tie(0);
  long long int x,y,n,K,i,j;
  cin>>x>>y;
  n=(x+y)/3;
  K=y-n;
  if((x+y)%3==0&&x>=n&&y>=n){
    fact[0]=1;
        // 階乗の計算
	REP(i, n) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[n]=power(fact[n], MOD-2);
        // 逆元の計算
	FORR(i, 0, n) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
        // nCrの計算
        cout<<comb(n, K);
        return 0;
  }else{
    cout<<0;
  }
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    
    vector<int> a(n), b(n);
    
    for(int&i:a)cin>>i;
    for(int&i:b)cin>>i;
    
    bool ae=true;
    for(int i=0; i<n && ae; i++){
        ae=ae&&(a[i]==b[i]);
    }
    if(ae){
        cout<<0;
        return 0;
    }
    
    vector<bool> needed(51,1);
    for(int i=50; i>=0; i--){
        vector<vector<int>> graph(51, vector<int>(51,0));
        
        vector<vector<int>> dists(51, vector<int>(51,2000));
        for(int j=1; j<=50; j++){
            for(int k=1; k<=j; k++){
                if(needed[k]){
                    graph[j][j%k]=1;
                    dists[j][j%k]=1;
                }
            }
        }
        
        
        for(int j=0; j<=50; j++){
            dists[j][j]=0;
        }
        
        
        for(int j=0; j<=50; j++){
            for(int k=0; k<=50; k++){
                for(int t=0; t<=50; t++){
                    dists[k][t]=min(dists[k][t], dists[k][j]+dists[j][t]);
                }
            }
        }
        bool works=true;
        for(int j=0; j<n && works; j++){
            if(dists[a[j]][b[j]]>=2000){
                //cout<<a[j]<<" "<<b[j]<<endl;
                works=false;
            }
        }
        if(!works){
            if(i==50){
                cout<<-1;
                return 0;
            }
            else{
                //cout<<i<<" ";
                needed[i+1]=1;
            }
            
        }
        
        //cout<<i<<" "<<works<<endl;
        needed[i]=0;
        
    }
    long long ans=0;
    
    for(int i=0; i<=50; i++){
        if(needed[i]){
            //cout<<i<<" ";
            ans+=(1ll<<i);
        }
    }
    cout<<ans;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++){
        cout << S[i];
        cout << T[i];
    }
}

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

using namespace std;

int main()
{
	vector<int> v;
	int res=0,i,n,x,k;
	
	for(i=0;i<3;i++)
	{
		scanf("%d",&x);
		v.push_back(x);
	}
	scanf("%d",&k);
	sort(v.begin(),v.end());
	//printf("%d\n",v.size());

	//printf("%d\n",v[i-1]);
	res=(v[i-1]<<k)+v[i-2]+v[0];
	printf("%d\n",res);


	return 0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int h, w;
    cin >> h >> w;
    vector<string> vs(h);
    fo(i, h) cin >> vs[i];

    fo(i, w + 2) cout << "#";
    cout << endl;

    fo(i, h) {
        fo(j, w + 2) {
            if ( j == 0 or j == w + 1 ) cout << "#";
            else cout << vs[i][j - 1];
        }
        cout << endl;
    }
    
    fo(i, w + 2) cout << "#";
    cout << endl;

    return 0;
}

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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = w * h / 2;
    
    int i;
    if (w / 2 == x && h / 2 == y) i = 1;
    else i = 0;

    printf("%.10f %d\n", ans, i);
}

Measured memory_bytes: 256
n = int(input())
ans = [[0]*3 for xxx in range(n)]
for i in range(n):
    a,b,c = list(map(int, input().split()))
    if i==0:
        ans[0][0] = a
        ans[0][1] = b
        ans[0][2] = c 
        continue
    ans[i][0] += max(ans[i-1][1], ans[i-1][2]) + a
    ans[i][1] += max(ans[i-1][2], ans[i-1][0]) + b
    ans[i][2] += max(ans[i-1][0], ans[i-1][1]) + c
ans = ans[-1]
print(max(ans))

Measured memory_bytes: 28584
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()

    tmp_d = sorted(d)

    front = tmp_d[n//2-1]
    rear = tmp_d[n//2]

    for num in d:

        if front>=num:
            print(rear)
        else:
            print(front)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85844
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int a = sc.nextInt();
		
		out.print(a*a);
		out.close();
	}
	
	
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

bool dd[200002];
int n, val;

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int res = 0;
    for (int i = 0; i < n; i++){
        cin >> val;
        if (val == 1) dd[1] = true;
        else if (dd[val - 1]) dd[val] = true;
        if (dd[val]) res = max(res, val);
    }
    if (res == 0) cout << -1; else cout << n - res;
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
    int n;
    char s1[20],s2[20],s3[20];
    scanf("%s%s",s1,s2);
    int a,b;
    scanf("%d%d",&a,&b);
    getchar();
    scanf("%s",s3);
    if(strcmp(s1,s3)==0)
        printf("%d %d\n",--a,b);
    if(strcmp(s2,s3)==0)
        printf("%d %d\n",a,--b);
}


Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split(' ')))

def cal(l, x):
    ret = 0
    for i in l:
        ret += (i - x) * (i - x)
    return ret

aver = int(sum(a) / len(a))

ans = 1e9
for i in range(aver - 3, aver + 3):
    f = cal(a, i)
    if f < ans:
        ans = f

print(ans)


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

int main() {
    int N;  cin >> N;
    vector<int> cnt(N);
    for (int i = 0; i < N - 1; ++i) {
        int a;  cin >> a;
        ++cnt[a - 1];
    }
    for (int i = 0; i < N; ++i) cout << cnt[i] << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],f[100005];
int main(){
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    f[0]=0;
    f[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;++i){
        f[i]=min(f[i-1]+abs(a[i-1]-a[i]),f[i-2]+abs(a[i-2]-a[i]));
    }
    cout << f[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll ans = 0;
    char s;
    rep(i, 3){
        cin >> s;
        if(s == '1'){
            ans++;
        }
    }

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

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

int main(){
    int r;cin>>r;
    cout<<2*M_PI*r;
    return 0;
}

Measured memory_bytes: 3784
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vpulli vector <pair <ulli,ulli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=1e6+1;
const ld PI=acos(-1);
 
int main(){
    rapgame
    read2ll(n,m);
    lli sum=0;
    fr(i,m){
        readll(x);
        sum+=x;
    }
    cout << (sum<=n ? (n-sum) : (-1));
    return 0;
}

Measured memory_bytes: 3580
n,k = map(int,input().split())
ans = 0
for b in range(k+1,n+1):
    case = (n//b)*(b-k)
    if n%b >=k:
        if k==0:
            case += n%b
        else:
            case += n%b-k+1

    ans += case
print(ans)

Measured memory_bytes: 3060
/********** Raaghav Raaj (cf: raaghavraaj, cc: mothercoder27) *************/
#include<bits/stdc++.h>
using namespace std;
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
#pragma optimize("-O3")

// #ifndef LOCAL
// #include "trace.h"
// #else
// #define trace(args...)
// #endif

#define int long long
#define vi vector<int>
#define vc vector<char>
#define pi pair<int, int>
#define pii pair<pi,int>
#define rep(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define sp " "
#define endl '\n'
#define all(v) v.begin(), v.end()
#define debug(data) for(auto it: data) cout<<it<<sp;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int sz = 1e9 + 7;
int gcd(int n, int m) {
	while (n) swap(n, m), n %= m;
	return m;
}

int power(int a, int b) {
	a %= sz;
	int res = 1;
	while (b) {
		if (b & 1) res = (res * a) % sz;
		a = (a * a) % sz;
		b >>= 1;
	}
	return res;
}

int modInverse(int a) { //sz must be prime
	return power(a, sz - 2);
}
int cnt[10001];
void solve() {
	rep(i, 1, 101) {
		rep(j, 1, 101) {
			rep(k, 1, 101) {
				int val = i * i + j * j + k * k + i * j + j * k + k * i;
				if ( val <= 10000) {
					cnt[val]++;
				}
			}
		}
	}
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cout << cnt[i] << endl;
	}
}

int32_t main() {

	fast;
	int T = 1;
	// cin >> T;
	rep(i, 1, T + 1) {
		// cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3688
#include <cstdio>

	struct
	{
		int menjo;
		int next, before;
	}data[200001];
int main()
{

	int N, M, Q;

	scanf("%d %d %d",&N,&M,&Q);

	for (int i = 0; i < N; ++i)
	{
		data[i].menjo = 1;
		data[i].before = (i - 1 + N) % N;
		data[i].next = (i + 1) % N;
	}

	int batton=0;
	for (int i = 0; i < M; ++i)
	{
		int a;
		scanf("%d", &a);

		if (a % 2 == 0)
		{
			for (int k = 0; k < a; ++k)
			{
				batton = data[batton].next;
			}
		}
		else
		{
			for (int k = 0; k < a; ++k)
			{
				batton = data[batton].before;
			}
		}

		data[batton].menjo = 0;
		data[data[batton].next].before = data[batton].before;
		data[data[batton].before].next = data[batton].next;

		batton = data[batton].next;
	}
	for (int i = 0; i < Q; i++)
	{
		int a;
		scanf("%d",&a);
		printf("%d\n",data[a].menjo);
	}

	return 0;
}

Measured memory_bytes: 3372
A,B,C = map(int, raw_input().split())
ans = 0
for i in range(1000):
    if A%2!=0 or B%2!=0 or C%2!=0:
        break
    A,B,C = B/2+C/2,C/2+A/2,A/2+B/2
    ans += 1
print ans if ans < 1000 else -1


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

int main(void) {
    int n, m;
    scanf("%d%d", &n, &m);
    int p[m];
    char s[m][5];
    for (int i = 0; i < m; i++) scanf("%d%s", &p[i], s[i]);

    int ac = 0, wa = 0, prob[n][2];
    for (int i = 0; i < n; i++) {
        prob[i][0] = 0;
        prob[i][1] = 0;
    }
    for (int i = 0; i < m; i++) {
        if (strcmp(s[i], "AC") == 0) {
            prob[p[i]-1][0] = 1;
        } else {
            if (prob[p[i]-1][0] == 0) {
                prob[p[i]-1][1]++;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        ac += prob[i][0];
        if (prob[i][0] == 1) wa += prob[i][1];
    }

    printf("%d %d\n", ac, wa);

    return 0;
}


Measured memory_bytes: 1792
h,w=map(int,input().split())
li=[input() for i in range(h)]
ans=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if li[i][j]=='#':
      ans[i][j]='#'
      for k in range(-1,2):
        for l in range(-1,2):
          if 0<=i+k<h and 0<=j+l<w:
            if ans[i+k][j+l]!='#':
              ans[i+k][j+l]+=1
anss=[map(str,ans[i]) for i in range(h)]
for i in range(h):
  print(''.join(anss[i]))

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class UnionFindTree
{
private:
    int n;
    int groupNum;       // グループの数
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    int find(int i){
        if(parent[i] == i)
            return i;
        else
            return parent[i] = find(parent[i]);
    }
public:
    UnionFindTree(int n){ // コンストラクタ
        this->n = n;
        groupNum = n;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int a, int b){ // aとbのグループを併合
        if((a = find(a)) != (b = find(b))){
            if(rank[a] < rank[b]){
                parent[a] = b;
                num[b] += num[a];
            }
            else{
                parent[b] = a;
                if(rank[a] == rank[b])
                    ++ rank[a];
                num[a] += num[b];
            }
            -- groupNum;
        }
    }
    bool same(int a, int b){ // aとbのグループが同じかを調べる
        return find(a) == find(b);
    }
    int getNum(){ // グループの数を返す
        return groupNum;
    }
    int getNum(int a){ // aのグループの要素数を返す
        return num[find(a)];
    }
};

int main()
{
    int n, q;
    cin >> n >> q;

    UnionFindTree uft(n);
    for(int i=0; i<q; ++i){
        int t, u, v;
        cin >> t >> u >> v;

        if(t == 0)
            uft.unite(u, v);
        else
            cout << (uft.same(u, v) ? 1 : 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <atcoder/dsu>

int main(){
    using namespace std;
    int N, M;
    cin >> N >> M;

    atcoder::dsu city(N);
    for(int i = 0;i < M;i++){
        int u1, u2;
        cin >> u1 >> u2;
        u1--;
        u2--;
        city.merge(u1, u2);
    }

    vector<vector<int>> gs = city.groups();
    cout << gs.size() - 1 << endl;
}

Measured memory_bytes: 8968
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    double ad, bd;
    scanf("%d %d", &a, &b);
    ad=static_cast<double>(a);
    bd=static_cast<double>(b);
    printf("%d %d %.5f\n", a/b, a%b, ad/bd);
    
    return 0;
}



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

int n, t, a;
int min_idx;
double min_sa;

double ave_temp(int h)
{
    return t - h * 0.006;
}
int main()
{
    cin >> n;
    cin >> t >> a;
    for (int i = 0; i < n; ++i)
    {
        int h;
        cin >> h;
        if (i == 0)
        {
            min_idx = 0;
            min_sa = abs(ave_temp(h) - a) + 1;
        }
        if (abs(ave_temp(h) - a) < min_sa)
        {
            min_idx = i;
            min_sa = abs(ave_temp(h) - a);
        }
    }
    cout << min_idx + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
#define INF 100000000.0
using namespace std;
struct state { int n, v, l; double t; };

int N, M, S, G;
int vd[3] = { -1, 0, 1 };

class Compare {
public:
  bool operator() (struct state a, struct state b) {
    return a.t > b.t;
  }
};

int main(void) {
  while(cin >> N >> M, N) {
    cin >> S >> G;

    vector<int> T[101], D[101], C[101];
    REP(i, 1, M) {
      int x, y, d, c; cin >> x >> y >> d >> c;
      T[x].push_back(y); D[x].push_back(d); C[x].push_back(c);
      T[y].push_back(x); D[y].push_back(d); C[y].push_back(c);
    }

    double dp[101][101][101];
    REP(i, 0, 100) REP(j, 0, 100) REP(k, 0, 100) dp[i][j][k] = INF;

    priority_queue<struct state, vector<struct state>, Compare> q;
    struct state first = { S, 0, -1, 0.0 };
    q.push(first);

    while(!q.empty()) {
      struct state c = q.top();
      q.pop();

      // cout << c.n << " " << c.v << " " << c.t << endl;

      if(dp[c.n][c.l][c.v] <= c.t) continue;
      dp[c.n][c.l][c.v] = min(dp[c.n][c.l][c.v], c.t);

      for(int i = 0; i < T[c.n].size(); i++) {
        if(T[c.n][i] == c.l) continue;
        for(int j = 0; j < 3; j++) {
          int v = c.v + vd[j];
          if(v <= 0 || C[c.n][i] < v) continue;
          double t = c.t + ((double) D[c.n][i] / v);
          struct state n = { T[c.n][i], v, c.n, t };
          // if(n.t < dp[n.n][n.v]) q.push(n);
          q.push(n);
        }
      }
    }

    double ret = INF;
    REP(i, 1, N) ret = min(ret, dp[G][i][1]);
    if(ret < INF) printf("%.6f\n", ret);
    else cout << "unreachable" << endl;
  }

  return 0;
}

Measured memory_bytes: 29800
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
typedef long long ll;
using namespace std;

int n,i,a[200010],sum[200010],mx=0;
ll ans=0,out;
int main(){
    scanf("%d",&n);
    for(i=0;i<n;i++) {
            scanf("%d",&a[i]);
            sum[a[i]]++;
            mx=max(mx,a[i]);}
    for(i=0;i<=mx;i++){
        if(sum[i]>=2) ans+=(ll)sum[i]*(sum[i]-1)/2;
    }
    for(i=0;i<n;i++){
        if(sum[a[i]]>=2){
            out=ans-sum[a[i]]*(sum[a[i]]-1)/2;
            out+=(sum[a[i]]-1)*(sum[a[i]]-2)/2;
        }
        else out=ans;
        printf("%lld\n",out);
    }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=k;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
const int inf=1001001001;
const int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    ll n,k,ans=0;cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n-1){
        if(v[i]<=k){
            ans+=max(0ll,v[i+1]-(k-v[i]));
            v[i+1]-=max(0ll,v[i+1]-(k-v[i]));
        }
        else{
            ans+=v[i+1]+v[i]-k;
            v[i+1]=0;
        }
    }
    out(ans);
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->



int main()
{

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

   
   string s;
   cin>>s;

   ll ans = 0;

   for(int i=1; i<s.length();i++)
   {
    if(s[i] != s[i-1])
    {
      ans++;
    }
   }

  
  cout<<ans<<endl;

  
  
}
 

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

class Sieve_of_Eratosthenes {
public:
	vector<bool> PN;
	
	Sieve_of_Eratosthenes(int x){
		init(x);
	}
	
	void huga(int t, int x){
		if(PN[t]) return;
		for(int i = t*t; i <= x; i+=t)
			PN[i] = true;
	}
	
	void init(int x){
		PN.resize(x+5);
		PN[0]=PN[1]=PN[4]=true;
		for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
		for(int i = 6; i <= x; i+=6)
			PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
	}
};

int main(){
	const int MAX = 1000000;
	int n;
	
	Sieve_of_Eratosthenes S(MAX);
	vector<int> sum(MAX);
	
	for(int i = 1; i < MAX; i++){
		sum[i] += sum[i-1] + !S.PN[i];
	}
	
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	return 0;
}



Measured memory_bytes: 6564
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,area,mawari;
	scanf("%d %d",&a,&b);
	area = a*b;
	mawari = a*2 + b*2;
	printf("%d %d\n",area,mawari);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <set>

int G[301][301];

using namespace std;

int main() {
  int N;
  cin >> N;
  uint64_t ret = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> G[i][j];
      ret += G[i][j];
    }
  }

  set<pair<int, int>> s;
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (i == j || i == k || j == k) continue;
        if (G[i][j] > G[i][k] + G[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        if (G[i][j] == G[i][k] + G[k][j]) {
          if(s.count({i, j}) == 0) {
            s.insert({i, j});
            ret -= G[i][j];

          }
        }
      }
    }
  }

  cout << ret / 2 << endl;

  return 0;
}

Measured memory_bytes: 8164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    bool *dp=new bool[k+1]();
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-arr[j]<0)
                break;
            if(dp[i-arr[j]]==false)
                dp[i]=true;
        }
    }
    if(dp[k]==true)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 384
Program ABC121A

integer n,m,c,i,j,x,w
integer,allocatable::a(:,:),b(:)

read(*,*) n,m,c
allocate(a(n,m))
allocate(b(m))
read(*,*) b
read(*,*) ((a(i,j),j=1,m),i=1,n)
x=0

do i=1,n
 w=c
 do j=1,m
  w=w+a(i,j)*b(j)
 end do
 if (w>0) then
  x=x+1
 end if
end do

write(*,*) x


stop
end

Measured memory_bytes: 256
/*
ID: arthurc4
TASK: test
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)
#define ff \
first
#define ss \
second
#define pb \
push_back
int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	int a, b, c;
	cin >> a >> b >> c;

	cout << b + min(c, a+b+1) << endl;

	return 0;
}

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

void solve() {
    int ans = 0;

    std::vector<int> xs(4), ys(2);

    for (auto& x : xs) std::cin >> x;
    std::sort(xs.rbegin(), xs.rend());
    ans += std::accumulate(xs.begin(), --xs.end(), 0);

    for (auto& y : ys) std::cin >> y;
    std::sort(ys.rbegin(), ys.rend());
    ans += std::accumulate(ys.begin(), --ys.end(), 0);

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3184