akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;
	char a[h][w];
	rep(i, h) cin >> a[i];
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#')
				cout << '#';
			else {
				int p = 0;
				rep(k, 8) {
					int nx = i + dx[k], ny = j + dy[k];
					if (nx < 0 or ny < 0 or nx >= h or ny >= w) continue;
					if (a[nx][ny] == '#') p++;
				}
				cout << p;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dep(m);
    for(int i = 0, k; i < m; ++i) {
        cin >> k;
        dep[i].resize(k);
        for(auto& x : dep[i])
            cin >> x;
    }
    vector<int> p(m);
    for(int i = 0; i < m; ++i)
        cin >> p[i];
    int ans = 0;
    for(int r = 0; r < (1 << n); ++r) {
        bool ok = true;
        for(int i = 0; i < m; ++i) {
            int g = 0;
            for(int j : dep[i]) {
                g += ((1 << (j - 1)) & r) > 0;
            }
            ok &= g % 2 == p[i];
        }
        ans += ok;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	char a,b,c,d;
	while(cin>>a>>b>>c>>d)
	{
		if((a==b&&b==c)||(b==c&&c==d))
		{
			printf("Yes\n");
		}
		else
			printf("No\n");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}
int main()
{
	int R,G,B,N;
	cin >> R >> G >> B >> N;
	int i,j;
	int n = 0;
	int ans = 0;
	for(i=0; i<=N; i+=R)
	{
		n = N - i;
		for(j=0; i+j<=N;j+=G)
		{
			if(n%B==0)
				ans++;
			n -= G;
		}
	} cout << ans << endl;
	return 0;
}









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

using namespace std;

int N;
long int dp[100001]={};

int main() {
    cin >> N;
    
    int h[N];
    for(int i=0; i<N; i++) {
        cin >> h[i];
    }
    
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    
    for(int i=2; i<N; i++) {
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        dp[i] = min(dp[i], (dp[i-2] + abs(h[i]-h[i-2])));
    }
    
    cout << dp[N-1] << endl;

    return 0;
    
}

Measured memory_bytes: 1408
#Kagami Mochi
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a

num = int(input())
mochi = []*num
for i in range(num):
    any = input()
    mochi.append(any)
    
bSort(mochi)

out = mochi[0]
cnt = 1
for i in range(1,num):
    if(out == mochi[i]):
        continue
    else:
        cnt += 1
        out = mochi[i]

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long H, long long W){
	ll res = 0;
	if (W == 1 || H == 1) res = 1;
	else if (W%2 == 1 && H%2 == 1) res = W*H/2+1;
	else res = W*H/2;
	cout << res << endl;
}

int main(){	
	long long W;
	long long H;
	scanf("%lld",&H);
	scanf("%lld",&W);
	solve(H, W);
	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


#define MOD 1000000007



int popcount32(unsigned int x) {
	x = x - ((x >> 1) & 0x55555555);
	x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
	x = (x + (x >> 4)) & 0x0F0F0F0F;
	x = x + (x >> 8);
	x = x + (x >> 16);
	return x & 0x0000003F;
}

int n;
int a[21][21];

int dp[1 << 21];


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

	cin >> n;
	rep(i, n)rep(j, n)cin >> a[i][j];

	dp[0] = 1;
	rep(j, 1 << n) {
		int man = popcount32(j);
		rep(k,n) if((j>>k&1)==0 && a[man][k]==1) {
			(dp[j | 1 << k] += dp[j]) %= MOD;
		}
	}
	cout << dp[(1 << n) - 1] << endl;

	return 0;
}


Measured memory_bytes: 8448
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int K, S;
int main() {
	cin >> K >> S;
	int ret = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (0 <= S - i - j && S - i - j <= K) ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int ans=0;
for (int i=1;i<=a;i++){
	int temp = i;
	int total = 0;
	while (temp>0){
		total += temp %10;
		temp /=10;
	}
	if (total >=b&& total <=c){
		ans +=i;
	}
}

printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int h,w,k;
  cin>>h>>w>>k;
  k--;
  int dp[110][10]={};
  dp[0][0]=1;

  rep(i,h){
    rep(j,(1<<w-1)){
      bool flag=false;
      rep(l,w-2){
        flag|=((j>>l)%4==3);
      }
      if(flag) continue;

      int x[10];
      rep(l,w) x[l]=l;

      rep(l,w-1){
        if((1<<l)&j) swap(x[l],x[l+1]);
      }

      rep(l,w){
        dp[i+1][x[l]]+=dp[i][l];
        dp[i+1][x[l]]%=M;
      }
    }
  }

  cout<<dp[h][k]<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long MOD = 1000000007;
constexpr long long INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long X,Y,Z,K;cin >> X >> Y >> Z >> K;
    vector<long long> A(X),B(Y),C(Z);
    for(auto &e:A) cin >> e;for(auto &e:B) cin >> e;for(auto &e:C) cin >> e;
    sort ALL(A);sort ALL(B);sort ALL(C);
    vector<long long> V;
    REP(i,Y){
        REP(j,Z){
            V.pb(B[i]+C[j]);
        }
    }
    sort ALL(V);
    reverse ALL(V);
    vector<long long> W;
    REP(i,X){
        REP(j,min((long long)V.size(),3000LL)){
            W.pb(A[i]+V[j]);
        }
    }
    sort ALL(W);
    reverse ALL(W);
    REP(i,K){
        cout << W[i] << endl;
    }
}

Measured memory_bytes: 43112
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int a, b;
    cin >> a >> b;
    cout << 6 - a- b << endl;
}

Measured memory_bytes: 256
import math

n,k = list(map(int,input().split()))
ans=0
if n<=k:
    for i in range(1,n+1):
        ans+=1/2**(math.ceil(math.log(k/i,2)))
else:
    ans+=n-k+1
    for i in range(1,k):
        ans+=1/2**(math.ceil(math.log(k/i,2)))

ans/=n

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; int A[100010] = {}; 
	cin >> N; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	A[0] --; 
	for(int i = 1; i < N; i++){
		if(A[i] > A[i-1]) A[i] --; 
	}
	bool ok = true; 
	for(int i = 1; i < N; i++){
		if(A[i] < A[i-1]) ok = false; 
	}	
	cout << (ok ? "Yes" : "No") << endl; 
}

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

int main(){
	int n;
	cin>>n;
	map<string,int> np;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		np[s]++;
	}
	
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		string s;
		cin>>s;
		np[s]--;
	}
	
	int ans=0;
	
	for(auto x:np){
		ans=max(ans,x.second);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s[6];
void u(){
  char p;p=s[0][2];s[0][2]=s[1][2];s[1][2]=s[1][3];s[1][3]=s[0][3];s[0][3]=p;
  char c[2];
  c[0]=s[2][0],c[1]=s[2][1];
  s[2][0]=s[2][2],s[2][1]=s[2][3];
  s[2][2]=s[2][4],s[2][3]=s[2][5];
  s[2][4]=s[2][6],s[2][5]=s[2][7];
  s[2][6]=c[0],s[2][7]=c[1];
}
void f(){
  char p;p=s[2][2];s[2][2]=s[3][2];s[3][2]=s[3][3];s[3][3]=s[2][3];s[2][3]=p;
  char c[2];
  c[0]=s[1][2],c[1]=s[1][3];
  s[1][2]=s[3][1],s[1][3]=s[2][1];
  s[2][1]=s[4][2],s[3][1]=s[4][3];
  s[4][2]=s[3][4],s[4][3]=s[2][4];
  s[3][4]=c[1],s[2][4]=c[0];
}
void r(){
  char p;p=s[2][4];s[2][4]=s[3][4];s[3][4]=s[3][5];s[3][5]=s[2][5];s[2][5]=p;
  char c[2];
  c[0]=s[3][6],c[1]=s[2][6];
  s[2][6]=s[1][3],s[3][6]=s[0][3];
  s[0][3]=s[2][3],s[1][3]=s[3][3];
  s[3][3]=s[5][3],s[2][3]=s[4][3];
  s[4][3]=c[0],s[5][3]=c[1];
}
void d(){
  char p;p=s[4][2];s[4][2]=s[5][2];s[5][2]=s[5][3];s[5][3]=s[4][3];s[4][3]=p;
  char c[2];
  c[0]=s[3][0],c[1]=s[3][1];
  s[3][0]=s[3][6],s[3][1]=s[3][7];
  s[3][6]=s[3][4],s[3][7]=s[3][5];
  s[3][4]=s[3][2],s[3][5]=s[3][3];
  s[3][2]=c[0],s[3][3]=c[1];
}
void b(){
  char p;p=s[2][6];s[2][6]=s[3][6];s[3][6]=s[3][7];s[3][7]=s[2][7];s[2][7]=p;
  char c[2];
  c[0]=s[0][2],c[1]=s[0][3];
  s[0][2]=s[2][5],s[0][3]=s[3][5];
  s[2][5]=s[5][3],s[3][5]=s[5][2];
  s[5][3]=s[3][0],s[5][2]=s[2][0];
  s[3][0]=c[0],s[2][0]=c[1];
}
void l(){
  char p;p=s[2][0];s[2][0]=s[3][0];s[3][0]=s[3][1];s[3][1]=s[2][1];s[2][1]=p;
  char c[2];
  c[0]=s[0][2],c[1]=s[1][2];
  s[0][2]=s[3][7],s[1][2]=s[2][7];
  s[3][7]=s[4][2],s[2][7]=s[5][2];
  s[4][2]=s[2][2],s[5][2]=s[3][2];
  s[2][2]=c[0],s[3][2]=c[1];
}

int main(){
  s[0]="..rr....";
  s[1]="..rr....";
  s[2]="ggyybbww";
  s[3]="ggyybbww";
  s[4]="..oo....";
  s[5]="..oo....";
  string t;
  cin>>t;
  for(int i=0;i<t.size();i++){
    if(t[i]=='U')u();
    if(t[i]=='F')f();
    if(t[i]=='R')r();
    if(t[i]=='D')d();
    if(t[i]=='B')b();
    if(t[i]=='L')l();
  }
  for(int i=0;i<6;i++)
    cout<<s[i]<<endl;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	return gcd(b,a%b);
}
void solve()
{
	int n;cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{	
				int x=gcd(j,k);
				sum+=gcd(i,x);
				
			}
		}
	}
	cout<<sum;
}
int main()
{
//	int t;cin>>t;
//	while(t--)
	solve();
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int>L(M),R(M);
    rep(i,0,M)cin >> L[i] >> R[i];
    vector<int> vec(100001);
    rep(i,0,M){
        vec[L[i]]++;
        vec[R[i]+1]--;
    }
    rep(i,1,100001){
        vec[i] += vec[i-1];
    }
    int cnt = 0;
    rep(i,0,100001){
        if(vec[i] == M)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes";
  }  
  else {
    cout << "No";
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;
int main() {
	int n;
	cin >> n;



	int dp[n][n];

	for( int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = 0;
		}
	}

	int p[n + 1];

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


	// |--**+-|

	// |+*---| l = 2, i = 0, j=0 : p(0) * P(1) * P (2)
	// |-+*--| l = 2, i = 1, j = 1 : p(1) * p(2) * p (3); p (i) * p(j+1) * p(i+l+1)
	// |---+*| l = 2, i = 1, j = 2
	// |-++*-| l = 3, i = 1, j = 3 : p(1) * p(3) * p(4)
	// |-****| 

	// 1 2 3   1 * 2 * 3

	for (int l = 2; l <= n; l++) {
		for (int i = 0; i < n - l + 1; i++) {
			int min = INT_MAX;
			for (int j = i; j < i + l - 1;j++ ) {
				int t = dp[i][j] + p[i] * p[j + 1] * p[i + l] + dp[j+1][i + l - 1];
				if (t < min) {
					min = t;
				}
			}
			dp[i][i + l - 1] = min;
			//cout << "i:" << i << " j:" << i + l - 1 << " max:" << min << endl;
		}
	}

	cout << dp[0][n -1] << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  vector<bool> IsPrime(60000, true);
  IsPrime.at(0) = false;
  IsPrime.at(1) = false;
  for( int i = 2; i <= 55555; i++ ){
    if( IsPrime.at(i) == true ){
      for( int j = 2; i*j <= 55555; j++ ) IsPrime.at(i*j) = false;
    }
  }
  
  vector<int> P;
  for( int i = 2; i <= 55555; i++ ){
    if( IsPrime.at(i) == true ) P.push_back(i);
  }
  
  int cnt = 0;
  for( int i = 0; i < P.size(); i++ ){
    if( P.at(i)%5 == 1 ){
      cout << P.at(i) << " ";
      cnt++;
    }
    if( cnt == N ){
      cout << endl;
      return 0;
    }
  }
  
  
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N,M; cin >> N >> M;
    vector<ll> A(N); REP(i,N) cin >> A[i];
    vector<ll> S(N+1); S[0] = 0;
    REP(i,N) S[i+1] = (S[i]+A[i]) % M;
    SORT(S);

    vector<pair<ll,ll>> p;
    p.emplace_back(0,1);

    REP(i,N){
        if(p.back().first == S[i+1]) p.back().second++;
        else p.emplace_back(S[i+1], 1);
    }
    ll ans = 0;
    REP(i,p.size()){
        ans += p[i].second * (p[i].second-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 2e5 + 10;
int a[N], n, now;
ll ans;
int main()
{
	n = read();
	rep(i, 1, n) a[i] = read();
	now = n;
	rrep(i, n, 1)
	{
        int x;
        if (i >= now) x = i - now;
        else x = 0;
        if (x > a[i])
        {
            puts("-1");
            return 0;
        }
        if (x == a[i]) continue;
        now = i - a[i];
        if (now > 0) ans += a[i];
        else
        {
            puts("-1");
            return 0;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
typedef pair<int, pii > ppi;
const int mod = 1000000007;
const int INF = 1000000009;

int N;
string s = "second";

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a % 2 == 1){
            s = "first";
        }
    }
    cout << s << endl;


    return 0;
}


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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int n;
int p, q;
VI ps, qs;

signed main()
{
    cin >> n;
    REP(i, n) {
        int a;
        cin >> a;
        p += a*pow(10, n - i - 1);
    }
    REP(i, n) {
        int a;
        cin >> a;
        q += a*pow(10, n - i - 1);

    }
    VI pi;
    VI qi;
    REP(i, n){ pi.push_back(i+1); }
    REP(i, n){ qi.push_back(i+1); }

    
    do {
        int a = 0;
        int b = 0;
        REP(i, n) {
            a += pow(10, i) * pi[i]; 
            b += pow(10, i) * qi[i]; 
        }
        ps.push_back(a);
        qs.push_back(b);
    } while (next_permutation(pi.begin(), pi.end()) && next_permutation(qi.begin(), qi.end()));

    sort(ALL(ps));
    sort(ALL(qs));

    auto x = lower_bound(ALL(ps), p) - ps.begin();
    auto y = lower_bound(ALL(qs), q) - qs.begin();

    cout << abs(x - y) << endl;
    return 0;
}

Measured memory_bytes: 1276
import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();

    // f[i]はi! mod MODを表す
    long[] f = new long[2 * (int)Math.pow(10, 5) + 1];
    // g[i]はmod MODにおけるf[i]の積に関する逆元を表す
    long[] g = new long[2 * (int)Math.pow(10, 5) + 1];
    f[0] = 1;
    g[0] = 1;
    for(int i = 1; i < f.length; i++) {
      f[i] = (f[i - 1] * i) % MOD;
      g[i] = func(f[i], MOD - 2);
    }
    long ans = (((f[H + W - 2] * g[H - 1]) % MOD) * g[W - 1]) % MOD;
    for(int r = 0; r < B; r++) {
      long a = (((f[H - A - 1 + r] * g[r]) % MOD) * g[H - A - 1]) % MOD;
      long b = (((f[W - r - 1 + A - 1] * g[W - r - 1]) % MOD) * g[A - 1]) % MOD;
      ans -= (a * b) % MOD;
      if(ans < 0) ans += MOD;
    }
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if(x % 2 == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      long t = func(a, x / 2);
      long s = (a * t) % MOD;
      s = (s * t) % MOD;
      return s;
    }
  }

}

Measured memory_bytes: 28116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                ans += i;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string s=cin.next();
        string s1=cin.next();
        string s2=cin.next();
        Console.WriteLine(s[0]+""+s1[1]+s2[2]);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 11092
H = ''
W = ''
i = j = 0

while True:
  line = input()
  line = line.split()
  H = int(line[0])
  W = int(line[1])

  if H == 0 and W == 0:
    break

  while i < H:
    if i == 0 or i == H-1:
      print('#'*W)
    else:
      print('#',end='')
      print('.'*(W-2),end='')
      print('#')
    i += 1
  i = 0
  print()

Measured memory_bytes: 7680
N, M = map(int, input().split())

for i in range(M):
  L, R = map(int, input().split())
  
  if i == 0:
    top = R
    bottom = L
  
  top = min(top, R)
  bottom = max(bottom, L)

if top >= bottom:
  print(top-bottom+1)
else:
  print(0)

Measured memory_bytes: 9196
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  int N;
  vector<int> L;
  int a;
  cin >> N;
  for (int i=0; i < N; i++) {cin >> a; L.push_back(a);}
  sort(L.begin(), L.end());
  int cnt=0;
  for (int i=0; i < N-2; i++) {
    for (int j=i+1; j < N-1; j++) {
      if (L[i] == L[j]) continue;
      int k = j+1;
      while(L[k] < L[i] + L[j] && k < N) {
        if (L[i]!=L[k] && L[j]!=L[k])cnt++; 
        k++;}
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(final String [] args) {
        final Scanner scanner = new Scanner(System.in);
        final String input = scanner.next();
        if (input.charAt(0) != '1' || input.charAt(input.length() - 1) != '0') {
            System.out.println(-1);
            return;
        }
        for (int i = 0, j = input.length() - 2; i < j; ++i, --j) {
            if (input.charAt(i) != input.charAt(j)) {
                System.out.println(-1);
                return;
            }
        }
        int currentEnd = 1;
        for (int i = 1; i < input.length(); ++i) {
            if (input.charAt(i - 1) == '1') {
                System.out.println(currentEnd + " " + (i + 1));
                currentEnd = (i + 1);
            } else {
                System.out.println(currentEnd + " " + (i + 1));
            }
        }
    }
}


Measured memory_bytes: 42648
N,A,B,C,D=map(int,input().split())
A,B,C,D=A-1,B-1,C-1,D-1
S=input()

ans=True
if "##" in S[A:C+1]:
  ans=False
if "##" in S[B:D+1]:
  ans=False

if (A-B)*(C-D)<0:
  commonL=max(A,B)
  if commonL>0:
    commonL-=1
  commonR=min(C,D)
  if commonL<len(S)-1:
    commonR+=1
  if commonR<commonL:
    ans=False
  elif "..." not in S[commonL:commonR+1]:
    ans=False

print(("No","Yes")[ans])


Measured memory_bytes: 3572
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll MOD=998244353;
int main(){
    int N;
    cin>>N;
    vector<int> X(N);
    {
        string s; cin>>s;
        for(int i=0;i<N;i++) X[i]=s[i]-'0';
    }
    vector<int> ys;
    for(int i=2;i<N;i++){
        if(2*N%i==0 && N%i!=0) ys.push_back(i);
    }

    
    ll cnt=0;
    ll res=0;
    vector<ll> Z(ys.size());
    for(int i=0;i<ys.size();i++){
        ll y=ys[i];
        int s=N%y;

        bool maxOK=true;
        for(int j=s;j<N;j++){
            if(j%y<s){
                if(X[j]==X[j%y]) continue;
                else if(X[j]<X[j%y]) maxOK=false;
                else break;
            }
            else{
                if(X[j]!=X[j%y-s]) continue;
                else if(X[j]<(!X[j%y-s])) maxOK=false;
                else break;
            }
        }

        ll pat=0;
        

        for(int j=0;j<s;j++){
            pat*=2;
            pat+=X[j];
            pat%=MOD;
        }
        if(maxOK) pat++;
        pat+=Z[i];
        for(int j=0;j<ys.size();j++){
            if(ys[j]%y==0) Z[j]-=pat;
            Z[j]%=MOD;
        }
        cnt+=pat,res+=y*pat;
        

        res%=MOD;
        cnt%=MOD;
    }
    
    ll alcnt=0;
    for(int i=0;i<N;i++){
        alcnt*=2;
        alcnt+=X[i];
        alcnt%=MOD;
    }
    alcnt++;

    res+=(alcnt-cnt)*2*N;
    res=(res%MOD+MOD)%MOD;
    cout<<res<<endl;
    
    return 0;
}


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

int main(){
	std::vector<int> vec(10);
	for(int i=0;i<10;i++){
		std::cin>>vec[i];
	}
	while(1){
		int a=0;
		for(int i=0;i<9;i++){
			if(vec[i]>vec[i+1]){
				int b=0;
				b=vec[i];
				vec[i]=vec[i+1];
				vec[i+1]=b;
				a++;
			}
		}
		if(a==0)break;
	}
	std::cout<<vec[9]<<std::endl<<vec[8]<<std::endl<<vec[7]<<std::endl;
	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>

//#define NOT_FOUND -1;
int binarySearch(int *,int,int);

int main(){
  int i,j,k,s,numA,numB,num=0,key;
  scanf("%d",&numA);

  int retuA[numA];

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

  scanf("%d",&numB);

  for(i = 0; i < numB; i++){
    scanf("%d",&key);
    //   printf("%d",binarySearch(retuA,retuB[i]));
    if(binarySearch(retuA,key,numA) == 1) num++;
  }

  printf("%d\n",num);

return 0;
}

int binarySearch(int* A,int B,int C){
  int left = 0;
  int right = C;
  int mid;
  //  int flag=0;

  while(left < right){
    mid = (left + right) / 2;
    
    if(A[mid] == B)return 1;
    else if(B < A[mid]) right = mid;
    else left = mid + 1;
  }

  return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long n,s,a[10000],ans;
int main(){
cin>>n>>s;
for(int k=1;k<=n;k++){
    cin>>a[k];
}
for(int k=1;k<=n;k++){
        long long h=0;
    for(int i=k+1;i<=n;i++){
        if(a[k]>a[i])
        h++;
    }
    long long t=0;
for(int i=1;i<=n;i++){
    if(a[k]>a[i])
        t++;
}
long long p=((s*(s-1))/2)%mod;
ans+=(h*s)%mod;
ans+=(p*t)%mod;
ans%=mod;

}
cout<<ans;
return 0;
}


Measured memory_bytes: 256
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f

using namespace std;

const int MAXN = 100005;
int parents[MAXN];
int sizes[MAXN];
int ans;

int find(int x) {
    return parents[x] == x ? x : (parents[x] = find(parents[x]));
}


void unite(int x, int y) {
    int rx = find(x), ry = find(y);
    if(rx != ry) {
        if(sizes[rx] > sizes[ry]) swap(rx, ry);
         sizes[ry] += sizes[rx];
        parents[rx] = ry;
		--ans;
    }
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        sizes[i] = 1;
        parents[i] = i;
    }
	ans = n;
    for(int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        unite(x, y);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int you(int,int);
int main(){
  int x,y,z;
  scanf("%d %d",&x,&y);
  if(x>=y)z=you(x,y);
  else z=you(y,x);
  printf("%d\n",z);
  return 0;
}
int you(int x ,int y){
  int z;
  while(1){
    z=x%y;
    x=y;
    y=z;
    if(y<=0)break;
  }
  return x;

}



Measured memory_bytes: 2084
#include<iostream>
using namespace std;
int main(){
  int N,i,c;
  char A[101],B[101],C[101];
  
  cin >> N >> A >> B >> C;
  
  for(i=0;i<N;i++){
    if(A[i]!=B[i] || A[i]!=C[i] || B[i]!=C[i]){
      c++;
      if(A[i]!=B[i] && A[i]!=C[i] && B[i]!=C[i]) c++;
    }
  }
  
  cout << c << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int sqr(int x) {
	int mi = 0, ma = 10000000000;
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (md*md <= x)mi = md;
		else ma = md;
	}
	return mi;
}

int q;

signed main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		if (a == b)cout << (a - 1) * 2 << endl;
		if (a == b)continue;
		if (a > b)swap(a, b);
		int x = a * b - 1;
		int y = sqr(x);
		int cnt = y - 1;
		cnt += y;
		if (y*y <= x && x < y * (y + 1))cnt--;
		cout << cnt << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/900 < b.F.F/900)
		return 1;
	if(a.F.F/900 > b.F.F/900)
		return 0;
	if(a.F.S <= b.F.S)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 450;

string s, t, ss, tt;

void solve()
{
	ll n, m, l, g;
	int nn, mm, i;
	int factor;
	cin >> nn >> mm;
	cin >> s;
	cin >> t;
	n = nn;
	m = mm;
	g = gcd(n,m);
	l = n*(m/g);
	if(l > n && l > m)
	{
		factor = n/g;
		ss = "";
		fo(i,0,nn)
			if(i % factor == 0)
				ss += s[i];
		factor = m/g;
		tt = "";
		fo(i,0,mm)
			if(i % factor == 0)
				tt += t[i];
		if(ss != tt)
			cout << -1 << '\n';
		else
			cout << l << '\n';
		return;
	}
	if(nn > mm)
	{
		swap(nn,mm);
		swap(s,t);
		swap(n,m);
	}
	factor = mm/nn;
	fo(i,0,mm)
		if(i % factor == 0 && t[i] != s[i/factor])
		{
			cout << -1 << '\n';
			return;
		}
	cout << mm << '\n';
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

fn main() {
    let abcd = get!(String).chars().map(|c| c.to_string().parse::<i32>().unwrap()).collect::<Vec<_>>();
    let a = abcd[0];
    let b = abcd[1];
    let c = abcd[2];
    let d = abcd[3];

    for &o1 in ["+", "-"].into_iter() {
        for &o2 in ["+", "-"].into_iter() {
            for &o3 in ["+", "-"].into_iter() {
                let mut s = a;
                if o1 == "+" {
                    s += b;
                } else {
                    s -= b;
                }
                if o2 == "+" {
                    s += c;
                } else {
                    s -= c;
                }
                if o3 == "+" {
                    s += d;
                } else {
                    s -= d;
                }
                if s == 7 {
                    println!("{}{}{}{}{}{}{}=7", a, o1, b, o2, c, o3, d);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 2064
#include <iostream>
#define MAX_N 10000

using namespace std;

int N;
int k[MAX_N];

//void solve();

int main()
{
	while (cin>>N&&N) {
		//for (int i=0; i<N; i++) cin>>k[i];
		//solve();
		int ans=N+1,t;
		bool check=false;
		for (int i=0; i<N; i++) {
			cin>>t;
			if (t==0) ans--;
			else if (t>1) check=true;
		}
		if (check) {
			cout<<ans<<endl;
		} else {
			cout<<"NA"<<endl;
		}
	}
}

Measured memory_bytes: 1172
import java.util.*
import java.math.*

fun main(args: Array<String>) {

//    var (A,B,C,D) = readLine()!!.split(" ").map { it.toLong() }
    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
    var ans = 0
    var pre = '-'
    for (c in readLine()!!){
        if (c == pre) continue
        pre = c
        ans++
    }
    println(ans)
}


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

using namespace std;

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

    int h[ 100010 ];
    for ( int i = 0; i < N; ++i ) cin >> h[ i ];

    vector<long long> dp(100010);
    for ( int i = 0; i < 100010; ++i ) dp[ i ] = 1LL << 60;
    dp[ 1 ] = 0;
    for ( int i = 1; i < N; ++i )
    {
        dp[ i + 1 ] = min( dp[ i + 1 ], dp[ i ] + abs( h[ i ] - h[ i - 1 ] ) );
        dp[ i + 2 ] = min( dp[ i + 2 ], dp[ i ] + abs( h[ i + 1 ] - h[ i - 1 ] ) );
    }

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

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))




void solve(){
    ll n;cin>>n;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    for(int i=n-1;i>=0;i-=2){
        cout<<a[i]<<" ";
    }
    int start=n&1?1:0;
    for(int i=start;i<n;i+=2){
        cout<<a[i]<<" ";
    }


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3712
import random

D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

plus=0
minus=0
data=[[1 for i in range(D)] for j in range(26)]
ans=[0]*D
for i in range(D):
    t=(i+1)%26+1
    ans[i]=t
    plus+=s[i][t-1]
    if i!=0:
        for j in range(26):
            data[j][i]=data[j][i-1]+1
    data[t-1][i]=0
    minus+=sum(c[j]*data[j][i] for j in range(26))

eval=plus-minus
count=2000000
check=[]
while count:
    d=random.randint(2,D)
    q=random.randint(1,26)
    if ans[d-1]==q:
        continue
    if c[ans[d-1]-1]*data[ans[d-1]-1][d-2]>c[q-1]*data[q-1][d-2] or s[d-1][q-1]>s[d-1][ans[d-1]-1]:
        testplus=plus+s[d-1][q-1]-s[d-1][ans[d-1]-1]
        testminus=minus
        pre=ans[d-1]
        #print("pre",pre)

        day=0
        for j in range(d-1,D):
            if data[q-1][j]!=0:
                if j==d-1:
                    testminus+=day*c[q-1]-data[q-1][d-1]*c[q-1]
                else:
                    testminus+=(day+1-data[q-1][j])*c[q-1]
                    day+=1
            else:
                break

        day=0
        for j in range(d-1,D):
            if j==d-1:
                if j==0:
                    day=1
                    testminus+=c[pre-1]*day
                else:
                    day=1+data[pre-1][j-1]
                    testminus+=c[pre-1]*day
            elif data[pre-1][j]!=0:
                testminus+=(day+1-data[pre-1][j])*c[pre-1]
                day+=1
            else:
                break

        if testplus-testminus>eval:
            eval=testplus-testminus
            plus=testplus
            minus=testminus
            ans[d-1]=q
            for j in range(d-1,D):
                if data[q-1][j]!=0:
                    if j==d-1:
                        data[q-1][d-1]=0
                    else:
                        data[q-1][j]=data[q-1][j-1]+1
                else:
                    break

            for j in range(d-1,D):
                if j==d-1:
                    if j==0:
                        data[pre-1][j]=1
                    else:
                        data[pre-1][j]=1+data[pre-1][j-1]
                elif data[pre-1][j]!=0:
                    data[pre-1][j]=data[pre-1][j-1]+1
                else:
                    break
    else:
        continue

    count-=1
#print(eval)
for i in range(D):
    print(ans[i])


Measured memory_bytes: 93900
N, T, *AB = map(int, open(0).read().split())

dp = [0] * (T + max(AB[::2]))
for w, v in sorted(zip(*[iter(AB)] * 2)):
    for i in reversed(range(T)):
        dp[i + w] = max(dp[i + w], dp[i] + v)

print(max(dp))


Measured memory_bytes: 42972
#include <stack>
#include <string>
#include <iostream>
#include <utility>
using namespace std;
int main(void){
    string c;
    cin >> c;
    int length = c.length();
    int depth[length+10];
    for(int i = 0;i < length + 10; i++)
        depth[i] = 0;
     
    stack<pair<int,int> > S;
    for(int i = 0;i<length;i++){
        if(c[i] == '\\'){
            S.push(make_pair(0,i));
        }
         
        else if(c[i] == '_'){
            S.push(make_pair(1,i));
        }
        else if(c[i] == '/'){
            while(!S.empty() && S.top().first != 0 ){
                S.pop();
            }
            if(!S.empty()){
                for(int j=S.top().second;j < i;j++){
                    depth[j+1]++;
                }
                S.pop();
            }
        }
    }
    float amounts[length+10] = {};
    float sum = 0.0;
    int cnt = 0;
    int start = 0;
    for(int i = start;i < length+1;i++){
        if(depth[i] == 0 && amounts[cnt] >= 1.0){
            cnt++;
        }
        amounts[cnt] += (depth[i] + depth[i+1])*0.50;
        sum += (depth[i] + depth[i+1])*0.50;
         
    }
     
    cout << (int)sum << endl;
    cout << cnt;
    if(cnt>0)
        cout << ' ';
    else cout << endl;
    for(int i = 0;i < cnt-1;i++){
        cout << amounts[i] << ' ';
    }
    if(cnt > 0)
        cout << (int)amounts[cnt-1] << endl;
    return 0;
}

Measured memory_bytes: 3484