akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(long long)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
}


Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if h==0 and w==0:
        break
    
    for i in range(h):
        for k in range(w):
            if i==0 or i==h-1 or k==0 or k==w-1:
                print("#",end="")
                
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll X;
	cin >> X;
	ll C = 360;
	while (C % X != 0) {
		C += 360;
	}
	cout << C / X << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int n, q, l, r;
    string s;
    cin >> n >> q >> s;

    int a[n + 1] = {};
    for (int i = 1; i < n; i++)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            a[i] = a[i - 1] + 1;
        }
        else
        {
            a[i] = a[i - 1];
        }
    }
    // for (int i = 0; i < n; i++)
    // {
    //     cout << a[i];
    // }
    // cout << endl;
    for (int i = 0; i < q; i++)
    {
        cin >> l >> r;
        cout << a[r - 1] - a[l - 1] << endl;
    }
}


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

using namespace std;

using ll = long long;

#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopill(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)

int main() {
	int k; cin >> k;
	queue <ll> q;
	loopill(i, 1, 10) q.push(i);
	ll d = 10;
	loop(i, k - 1) {
		ll x = q.front();
		q.pop();
		if (x % d != 0) q.push(d * x + x % d - 1);
		q.push(d * x + x % d);
		if (x % d != 9) q.push(d * x + x % d + 1);
	}
	cout << q.front() << endl;
}

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

int main(){
    vector<char> s1(3),s2(3),rs1(3),rs2(3);

    for(int i = 0;i < 3;i++){
        cin >> s1.at(i);
    }

    for(int i = 0;i < 3;i++){
        cin >> s2.at(i);
    }

    rs1 = s1;
    rs2 = s2;
    
    s1.at(0) = s2.at(2);
    s1.at(1) = s2.at(1);
    s1.at(2) = s2.at(0);

    s2.at(0) = rs1.at(2);
    s2.at(1) = rs1.at(1);
    s2.at(2) = rs1.at(0); 

    if(s1 == rs1 && s2 == rs2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 305
using namespace std;

int n, s;
string a[N];
int f() {
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (a[i][j] != a[j][i]) return 0;
		}
	}
	return 1;
}
int main()
{
	int i, j, k;
	cin >> n;
	for (i = 0; i <n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		s += f() * n;
		for (j = 0; j < n; j++) rotate(a[j].begin(), a[j].begin() + 1, a[j].end());
	}
    cout << s;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

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

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    cout<<n*n*n<<endl;
    
    return 0;   
}


 
 


Measured memory_bytes: 256
MOD = 1000000007

N = int(input())
C = list(map(int,input().split()))

C.sort(reverse=True)

ans = 0

if N > 1:
    for i in range(N):
        ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
        ans %= MOD
else:
    ans = 2*C[0]%MOD

print(ans)

Measured memory_bytes: 26800
n,m,x = map(int,input().split())
ls = []
mi = 10**18
for i in range(n):
  ls.append(list(map(int,input().split())))
for i in range(2**n+1):
  cost = 0
  f = "{{:0{}b}}".format(n)
  now = f.format(i)
  understand = [0]*m
  for j in range(len(now)):
    if now[j] == "1":
      cost += ls[j][0]
      for k in range(m):
        understand[k] += ls[j][k+1]
  if min(understand) >= x:
    if mi > cost:
      mi = cost
if mi == 10**18:
  print(-1)
else:
  print(mi)

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    bool w = true;
    if (a < b) {
      w = false;
    } else if (d < b) {
      w = false;
    } else if (d == b) {
      if (a % b > c) {
        w = false;
      }
    } else if (b > c) {
      long long g = __gcd(b, d);
      long long x = (((c + 1) - a) % g + g) % g;
      if (x == 0) {
        x = g;
      }
      long long y = x + b - c - 2;
      if (x <= g && g <= y) {
        w = false;
      }
    }
    cout << (w ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main(){
    int n;
    set<int> s;
    cin>>n;

    int hoge;
    for(int i=0;i<n;i++){
        cin>>hoge;
        s.insert(hoge);
    }

    cout<<s.size()<<endl;

}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> pos[10];
    rep(i, n)
    {
        pos[s[i] - '0'].push_back(i);
    }
    int cnt = 0;
    rep(i, 1000)
    {
        int first = i / 100;
        int second = i / 10;
        second %= 10;
        int third = i % 10;
        if (pos[first].size() == 0 || pos[second].size() == 0 || pos[third].size() == 0)
            continue;
        int f_pos = pos[first][0];
        int s_pos = 0;
        rep(j, pos[second].size())
        {
            if (pos[second][j] > f_pos)
            {
                s_pos = pos[second][j];
                break;
            }
        }
        if (s_pos == 0)
            continue;
        rep(j, pos[third].size())
        {
            if (pos[third][j] > s_pos)
            {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3812
#include <stdio.h>
#include <stdlib.h>

int N = 0;
int Q = 0;
int S1[100000];
int S2[100000];
int S3[100000];
int Com = 0;
int V1 = 0;
int V2 = 0;
int V3 = 0;
void relate();
void query();
void merge();

int main(){
	int i = 0;
	scanf("%d %d",&N,&Q);
	for(i = 0; i<N ; i++){
		S1[i] = i;
		S2[i] = 0;
		S3[i] = 1;
	}

	while(Q>0){
		scanf("%d",&Com);
		if(Com){
			scanf("%d %d",&V1, &V2);
			query();
		}else{
			scanf("%d %d %d",&V1 ,&V2, &V3);
			relate();
		}
		Q--;
	}
}

void relate(){
	//printf("R : %d %d %d\n", V1, V2, V3);
	if(S1[V1] == S1[V2]){
		return;
	}else{
		merge();
	}
}

void merge(){
	int i = 0;
	int s3 = S2[V2] - V3 -S2[V1];
	int s1 = S1[V1];
	int s2 = S1[V2];
	if(S3[s1] == 1){
		S3[s1]--;
		S3[s2]++;
		S1[V1] = s2;
		S2[V1] = S2[V1] + s3;
		//printf("Fast1\n");
		return;
	}else{ 
		if(S3[s2] == 1){
			S3[s1]++;
			S3[s2]--;
			S1[V2] = s1;
			S2[V2] = S2[V2]-s3;
			//printf("Fast2\n");
			return;
		}
	
	}

	for(i = 0; i<N ;i++){
		if(S1[i] == s1){
			//System.out.println("V1 = "+ V1 + "V2 = " + V2+ "V3 = " + V3);
			//printf("V1 = %d, V2 = %d, V3 = %d\n",V1, V2, V3);
			S3[s1]--;
			S3[s2]++;
			S1[i] = s2;
			S2[i] = S2[i] + s3;
			//printf("S2[%d] = %d\n", i, S2[i]);
			//System.out.println("S2[i] = "+ S2[i]);
		}else{
			continue;
		}
	}

}

void query(){
	//printf("Q : %d %d \n", V1, V2);
	if(S1[V1] == S1[V2]){
		printf("%d\n",S2[V2]-S2[V1]);
	}else{
		printf("?\n");
	}

}



Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
struct uzi{
	LL a,b;
}p[N];
const LL mod=1e9+7;
map<pair<LL,LL>,int>m;
LL pm(LL x,LL y){
	LL z=1;
	while(y){
		if(y&1)z=z*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return z;
}
LL fac[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  fac[0]=1;
  for(int i=1;i<=n;i++)fac[i]=fac[i-1]*2%mod;
  for(int i=1;i<=n;i++){
  	cin>>p[i].a>>p[i].b;
  	LL z=__gcd(labs(p[i].a),labs(p[i].b));
  	if(z)p[i].a/=z,p[i].b/=z;
    if(p[i].b<0)p[i].b=-p[i].b,p[i].a=-p[i].a;
    //cout<<p[i].a<<' '<<p[i].b<<endl;
  }
 // cout<<"----------\n";
  LL ans=0,tot=1;
	int npb=0,npa=0,gc=0,typ=0,dx=0,dy=0;
  for(int i=1;i<=n;i++){
    if(!p[i].a && !p[i].b) ans++;
    else if(!p[i].a){
      ans+=fac[npa]*tot%mod;
      ans%=mod;
      npa++;  
    }else if(!p[i].b){
      ans+=fac[npb]*tot%mod;
      ans%=mod;
      npb++;
    }else{
      int x=m[{p[i].a,p[i].b}];
      if(p[i].a<0)p[i].a=-p[i].a,p[i].b=-p[i].b;
      int y=m[{-p[i].b,p[i].a}];
      tot*=pm((fac[x]+fac[y]-1+mod)%mod,mod-2);
      tot%=mod;//cout<<tot<<endl;
      ans+=tot*fac[y]%mod*((fac[npa]+fac[npb]-1+mod)%mod)%mod;
      ans%=mod;
      m[{-p[i].b,p[i].a}]++;
      tot*=(fac[x]+fac[y+1]-1+mod)%mod;
      tot%=mod;
    }
    //cout<<i<<' '<<ans<<endl;
  }
  cout<<ans<<'\n';
 	return 0;
}

Measured memory_bytes: 33180
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	char c1, c2;
	int a, b, c;
	cin >> a >> c1 >> b >> c2 >> c;
	cout << ((b <= 4)? "Heisei" : "TBD") <<endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
ans = ''
ans += 'R' * (c - a) + 'U' * (d - b)
ans += 'L' * (c - a) + 'D' * (d - b)
ans += 'D' + 'R' * (c - a + 1) + 'U' * (d - b + 1) + 'L'
ans += 'U' + 'L' * (c - a + 1) + 'D' * (d - b + 1) + 'R'
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        set<string> ss;
        string s;
        int cnt=0;
        cin>>s;
        for(int i=0;i<s.size()-1;i++){
            string s1=s.substr(0,i+1);
            string s2=s.substr(i+1);
            for(int i=0;i<2;i++){
                for(int j=0;j<2;j++){
                    for(int k=0;k<2;k++){
                        if(i==0) reverse(s1.begin(),s1.end());
                        if(j==0) reverse(s2.begin(),s2.end());
                        if(k==0){
                            string ne = s1+s2;
                            if(ss.find(ne)==ss.end()){
                                ss.insert(ne);
                                cnt++;
                            }
                        }
                        if(k==1){
                            string ne = s2+s1;
                            if(ss.find(ne)==ss.end()){
                                ss.insert(ne);
                                cnt++;
                            }
                        }
                        if(i==0) reverse(s1.begin(),s1.end());
                        if(j==0) reverse(s2.begin(),s2.end());
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

string solve( string str )
{
	REP( i, 0, str.size() )
	{
		str[i] -= 3;
		if ( str[i] < 'A' )
		{
			str[i] += 26;
		}
	}
	return str;
}

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

	string str;
	cin >> str;
	cout << solve( str ) << endl;

	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int field[64][64];
int cnt;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int w, h;

void dfs(int x, int y);

int main()
{
	int x, y;

	while (true){
		cnt = 0;

		scanf("%d %d", &w, &h);
		if (w == 0){
			break;
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				scanf("%d", &field[i][j]);
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (field[i][j]){
					cnt++;
					dfs(j, i);
				}
			}
		}

		printf("%d\n", cnt);
	}

	return (0);
}

void dfs(int x, int y)
{
	field[y][x] = 0;

	for (int i = 0; i < 8; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if (field[ny][nx] && nx >= 0 && ny >= 0 && nx < w && ny < h){
			dfs(nx, ny);
		}
	}
}

Measured memory_bytes: 1268
import numpy as np
N, M =map(int,input().split())
search = np.zeros(M+1)
for i in range(N):
    K = list(map(int,input().split()))
    for j in range(1,K[0]+1):
        search[K[j]]+=1
place = np.where(search==N)
print(len(place[0]))

Measured memory_bytes: 21764
c1 = list(map(int,input().split(" ")))
c2 = list(map(int,input().split(" ")))
c3 = list(map(int,input().split(" ")))
a1 = []
a2 = []
a3 = []
b1 = []
b2 = []
b3 = []
judge1 = False
judge2 = False
judge3 = False
judge4 = False
for i in range(c1[0]+1):
    a1.append(i)
b1 = sorted(a1,reverse = True)
for i in b1:
    a2.append(c2[0]-i)
for i in b1:
    a3.append(c3[0]-i)

for i in a1:
    b2.append(c1[1]-i)
for i in a1:
    b3.append(c1[2]-i)

for i in range(len(a1)):
    if c2[1] == a2[i]+b2[i]:
        judge1 = True
    if c3[2] == a3[i]+b3[i]:
        judge2 = True
    if c2[2] == a2[i]+b3[i]:
        judge3 = True
    if c3[1] == a3[i]+b2[i]:
        judge4 = True 
if judge1 and judge2 and judge3 and judge4 :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int a,b,i,j;
  while(1){
    scanf("%d %d",&a,&b);
    if(a==0&&b==0){
      break;
    }
    for(i=0;i<a;i++){
      if(i==0||i==a-1){
	for(j=0;j<b;j++){
	  printf("#");
	}
	printf("\n");
      }
      else{
	for(j=0;j<b;j++){
	  if(j==0||j==b-1){
	    printf("#");
	  }
	  else{
	    printf(".");
	  }

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

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

int main()
{
  int N;
  cin >> N;
  int P[55];
  int sortedP[55];

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

  memcpy(sortedP, P, sizeof(int) * 55);
  sort(sortedP, sortedP + N);

  // 昇順ソート済みと前で違いを数える、2つ以下ならYES
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if (P[i] != sortedP[i]) {
      count++;
    }
  }

  if (count <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

using namespace std;

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

    vector<int> x(n), y(n), h(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    int cy = -1, cx = -1, ch = -1;
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int h_est = 1;
            for (int k = 0; k < n; k++) {
                if (h[k] > 0) {
                    h_est = abs(i - y[k]) + abs(j - x[k]) + h[k];
                    break;
                }
            }

            bool valid = true;
            for (int k = 0; k < n; k++) {
                if (max(h_est - abs(i - y[k]) - abs(j - x[k]), 0) != h[k]) {
                    valid = false;
                    break;
                }
            }

            if (valid) {
                cy = i;
                cx = j;
                ch = h_est;
            }
        }
    }

    cout << cx << " " << cy << " " << ch << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)

int main(int argc, char** argv) {
	int a,b;
	scanf("%d%d",&a,&b);
	rep(i,1,100000)
	{
		int u=i*0.08;
		int v=i*0.1;
		if(u==a&&v==b)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int N;
int S[30005];
int ans;

int power(int base, int exp)
{
    int ans = 1;
    for (int i = 0; i < exp; i++)
    {
        ans *= base;
    }
    return ans;
}

int main()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        char temp; scanf(" %c", &temp);
        S[i] = temp - '0';
    }
    ans = 0;
    for (int i = 0; i < 1000; i++)
    {
        int ret = 3;
        bool isPossible = false;
        for (int j = 0; j < N && !isPossible; j++)
        {
            if (S[j] == (i % power(10, ret)) / power(10, ret - 1)) ret--;
            if (ret == 0) isPossible = true;
        }
        if (isPossible) ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int N [] = new int [n];
		int m = 1; int total = 0;
		for(int i =0; i< n; i++){
		    N[i] = scan.nextInt();
		    if(N[i]==m){
		        m++;
		        total++;
		    }
		} 
		if(total==0){
		    System.out.println(-1);
		}
		else{
		    System.out.println(n-total);
		}
		
	}
}


Measured memory_bytes: 60472
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
using namespace std;
typedef long long ll;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //文字列入力
    string s;
    cin >> s;

    ll ans = 0;
    REP(i, 4)
    {
        if (s[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 5223372036854775807
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10105;
const int NN=200005;
const ll md=1e9+7;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    dd n;
    cin >> n;
    cout << n*2*3.14159265 << E;
    r0;
}
/*











*/





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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;

// テァツ?。テ・ツ青妥」ツつーテ」ツδゥテ」ツδ陛」ツ?ョテ」ツ?ィテ」ツ??
void add_edge(Graph& graph, int u, int v, int cost){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}
void Dijkstra(const Graph& edges, vector<int>& d, int s){
  using Type = PII;
  priority_queue<Type, vector<Type>, greater<Type> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(MP(0,s));

  while(!pq.empty()){
	Type pii = pq.top(); pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(unsigned int i=0;i<edges[v].size();++i){
	  const Edge& e = edges[v][i];
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		pq.push(MP(d[e.to], e.to));
	  }
	}
  }
}

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

  int N, M, K;
  cin >> N >> M >> K;
  Graph G(N);
  REP(i,M){
	int u, v, l;
	cin >> u >> v >> l;
	--u;
	--v;
	add_edge(G, u, v, l);
  }

  VI mn(N, INF);
  REP(q,K){
	int s;
	cin >> s;
	--s;
	VI dis(N);
	Dijkstra(G, dis, s);
	REP(i,N) mini(mn[i], dis[i]);
  }

  int ans = 0;
  REP(i,N)
	for(auto&& e: G[i]){
	  int j = e.to;
	  int a = min(mn[i], mn[j]);
	  int b = max(mn[i], mn[j]);
	  if(a+e.cost <= b)
		maxi(ans, a+e.cost);
	  else{
		maxi(ans, (a+b+e.cost)/2 + (a+b+e.cost)%2);
	  }
	}
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5980
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>

#define true 1
#define false 0

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)


//2分探索の問題

//考えている区間の min, max　そして、その間の個数 n
int binary(long *array, int N, long k){
  int lb=0;
  int ub=N;
  //解の存在範囲が２個になるまで、繰り返す。
  while(ub-lb>1){
    int mid=(ub+lb)/2;
    if(k>=array[mid]){
      lb=mid;
    }
    else{
      ub=mid;
    }
  }
  //この時点で、ub-lb==1
  //a[lb] <= k <= a[ub]となる
  return lb;
}

long min(long a, long b){
  if(a>=b){
    return b;
  }
  else{
    return a;
  }
}


long shortest(long s, long t, long x){
  if(s-x>=0){
    if(t-x>=0){
      if(s>=t){
        return s-x;
      }
      else{
        return t-x;
      }
    }
    else{
      if(s-x>=x-t){
        return x-t+(s-t);
      }
      else{
        return s-x+(s-t);
      }
    }
  }
  else{
    if(t-x>=0){
      if(t-x>=x-s){
        return x-s+(t-s);
      }
      else{
        return t-x+(t-s);
      }
    }
    else{
      if(s>=t){
        return x-t;
      }
      else{
        return x-s;
      }
    }
  }
}


int main(){
  char buf[1024];
  int A, B, Q;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d %d", &A, &B, &Q);

  long *s=(long *)malloc(sizeof(long)*A);
  long *t=(long *)malloc(sizeof(long)*B);
  long *x=(long *)malloc(sizeof(long)*Q);

  rep(i,A){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%ld", &s[i]);
  }
  rep(i,B){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%ld", &t[i]);
  }
  rep(i,Q){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%ld", &x[i]);
  }


  rep(i,Q){
    int lbs=binary(s, A, x[i]);
    int lbt=binary(t, B, x[i]);
    long answer=10000000000;
    //printf("lbs = %d, lbt = %d\n", lbs, lbt);

    if(lbs==A-1){
      if(lbt==B-1){
        answer=shortest(s[lbs], t[lbt], x[i]);
        printf("%ld\n", answer);
      }
      else{
        rep(k,2){
          long temp=shortest(s[lbs], t[lbt+k], x[i]);
          answer=min(answer, temp);
        }
        printf("%ld\n", answer);
      }
    }
    else{
      if(lbt==B-1){
        rep(j,2){
          long temp=shortest(s[lbs+j], t[lbt], x[i]);
          answer=min(answer, temp);
        }
        printf("%ld\n", answer);
      }
      else{
        rep(j,2){
          rep(k,2){
            long temp=shortest(s[lbs+j], t[lbt+k], x[i]);
            answer=min(answer, temp);
          }
        }
        printf("%ld\n", answer);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 300;
int n;
ll a, b, x;
void No(){ cout << -1 << endl; exit(0);}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> a >> b;
  FOR(_, 0, n-2){
    ll c;
    cin >> c;
    x ^= c;
  }
  ll s = a+b;
  ll ss = s, xx = x;
  V<bool> v(60);
  ll c = 0;
  FORR(i, 59, 0)if(x & bit(i)){
    x -= bit(i);
    s -= bit(i);
    v[i] = true;
  }
  FORR(i, 59, 0)if(bit(i)*2 <= s){
    if(v[i]) No();
    c += bit(i);
    s -= bit(i)*2;
  }
  if(c > a) No();
  FORR(i, 59, 0)if(v[i] && c+bit(i) <= a) c += bit(i);
  if(c == 0) No();
  if(c^(ss-c)^xx) No();
  cout << a-c << endl;
}


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

int main(){
	int n,k,ans = 0;
	vector<int> v;

	cin >> n >> k;
	
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;

		for (int j = 0; j < d; j++) {
			int a;
			cin >> a;
			v.push_back(a);
		}
	}

	for (int l = 1; l <= n; l++) {
		vector<int>::iterator itr = find(v.begin(), v.end(), l);
		if(itr == v.end()) {
			ans++;
		}
	}

	cout << ans;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353a
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;
    cin>>N;
    vector<int>P(N);
    vector<int>Q(N);
    for(int i=0;i<N;i++)cin>>P.at(i);
    for(int i=0;i<N;i++)cin>>Q.at(i);
    if(P>Q)swap(P,Q);
    int ans=0;
    do{
        if(P==Q)break;
        ans++;
    }while(next_permutation(P.begin(),P.end()));

    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n;
cin >> n;

vi t(n+1),x(n+1),y(n+1);
t[0] = 0; x[0] = 0; y[0] = 0;
rrep(i,n) cin >> t[i] >> x[i] >> y[i];

rep(i,n){
    int dist = (x[i+1] + y[i+1]) - (x[i] + y[i]);
    int time = t[i+1] - t[i];
    if(dist > time || (time - dist) % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
} 

cout << "Yes" << endl;

return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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 () {
  double l;
  cin >> l;
  double ans = pow(l/3,3);
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest
import math


def resolve():
    a, b, x = map(int, input().split())

    tan_theta = 2*(b/a-x/math.pow(a, 3))
    tan_theta2 = a * pow(b, 2) / (2 * x)

    if math.pow(a, 3) / 2 * tan_theta < x:
        theta = math.atan(tan_theta)
    else:
        theta = math.atan(tan_theta2)

    print(math.degrees(theta))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2 4"""
        output = """45.0000000000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """12 21 10"""
        output = """89.7834636934"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 1 8"""
        output = """4.2363947991"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 5696
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll k,n;
  cin >> k >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<ll> v;
  ll sum =0;
  for (ll i = 1; i < n; i++) {
    v.push_back(a[i]-a[i-1]);
    sum+=a[i]-a[i-1];
  }
  v.push_back(a[0]+k-a[n-1]);
  sum+=a[0]+k-a[n-1];
  sort(v.begin(),v.end());
  cout << sum - v[n-1];


}


Measured memory_bytes: 3956
#include<stdio.h>
int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    if(a=='H')
        printf("%c",b);
    else if(a=='D')
    {
        if(b=='H')
            printf("D");
        else if(b=='D')
           printf("H");
    }
    return 0;

}

Measured memory_bytes: 128
#include<stdio.h>

#define MAX 10000
#define NIL -1

struct node {
  int p,l,r;
};

struct node T[MAX];
int n;

void pre(int a){
  if(a == NIL) return;
  printf(" %d",a);
  pre(T[a].l);
  pre(T[a].r);
}

void in(int a){
  if(a == NIL) return;
  in(T[a].l);
  printf(" %d",a);
  in(T[a].r);
}

void post(int a){
  if(a == NIL) return;
  post(T[a].l);
  post(T[a].r);
  printf(" %d",a);
}

int main(){
  int i,v,l,r,root;

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

  for(i = 0; i < n; i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  
  printf("Inorder\n");
  in(root);
  printf("\n");

  printf("Postorder\n");
  post(root);
  printf("\n");
  
  return 0;
}



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

int N;
long long int A[300000] = {0};
long long int tA[300000] = {0};


long long int nCr(long long int n,int r){
    return n * (n - 1) / 2;
}

int main(){
    cin >> N;
    priority_queue<long long int> pque;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    tA[0] = A[0];
    for(int i=1;i<N;i++){
        tA[i] = tA[i-1] + A[i];
    }
    sort(tA,tA+N);
    long long int count = 0;
    long long int ind = 1;
    long long int nowN = tA[0];
    for(int i=1;i<N;i++){
        if(nowN == 0){
            if(tA[i]==0) ind++;
            else{
                if(ind > 0) count += nCr(ind+1,2);
                ind = 1;
                nowN = tA[i];
            }
        }else{
            if(tA[i] == nowN) ind++;
            else{
                if(ind > 1) count += nCr(ind,2);
                ind = 1;
                nowN = tA[i];
            }
        }
    }    
    if(nowN==0){
        if(ind>0) count += nCr(ind+1,2);
    }else{
        if(ind>1) count += nCr(ind,2);
    }

    cout << count << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N;
    cin >> N;

    vector<vector<i64>> A(N,vector<i64>(N));
    rep(i,0,N) rep(j,0,N) cin >> A[i][j];

    rep(k,0,N) rep(i,0,N) rep(j,0,N) if(A[i][j]>A[i][k]+A[k][j]){
        cout << -1 << endl;
        return;
    }

    i64 ans=0;
    rep(i,0,N) rep(j,i+1,N){
        bool ok=true;
        rep(k,0,N) if(k!=i and k!=j and A[i][j]>=A[i][k]+A[k][j]){
            ok=false;
            break;
        }
        if(ok) ans+=A[i][j];
    }
    cout << ans << endl;
}


int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val N = Integer.parseInt(readLine())
    var result = 0
    if (N <= 9) {
        result = N
    } else if (N <= 99) {
        result = 9
    } else if (N <= 999) {
        result = 9 + (N - 99)
    } else if (N <= 9999) {
        result = 909
    } else if (N <= 99999) {
        result = 909 + (N - 9999)
    } else {
        result = 90909
    }

    println(result)
}

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

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;

int main(){
  int n,W;cin >> n >>W;
  ll w[110],v[110];
  rep(i,n) cin >> w[i] >> v[i];
  // 10^9回のrepは不可能
  ll dp[110][100010];
  rep(i,110){
    rep(j,100010){
      dp[i][j]=INF;}}
  dp[0][0]=0;
  // nまでで価値sum_vを達成する最小のw
  rep(i,n){
    rep(j,100008){
      if(j>=v[i]){
      chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);}
      chmin(dp[i+1][j],dp[i][j]);
      
    }
  }
  int ans=0;
  for(int i= 0;i<100002;i++){
    if(dp[n][i]<=W) ans=i;}
  cout << ans << endl;
}


Measured memory_bytes: 86144
n, m = map(int, input().split())
a = [1] * (n+1)
for _ in range(m):
    a[int(input())] = 0

for i in range(2,n+1):
    if a[i] != 0:
        a[i] = a[i-1] + a[i-2]
print(a[n]%(10**9 + 7))


Measured memory_bytes: 460020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
ll gcd2(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {   x = 1;  y = 0;  return a;   }
    ll xx, yy;
    ll res = gcd2(b, a%b, xx, yy);
    x = yy;     y = xx - yy * (a / b);
    return res;
}

// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }
// const ll sz = 1e6 + 5;
// vector<ll> fac(sz, 1);

// * ALways PASS arrays, strings etc to functions BY REFERENCE

int main() {
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    int t = 1;
    // cin >> t;
    
    while(t--) {
        int n;
        cin >> n;
        
        vector<ll> arr(n+1);
        vector<ll> posm(n+1);
        for (int i = 0; i < n; i++)
            cin >> arr[i];
        
        for (int i = n-1; i >= 0; i--)
            posm[i] = (arr[i] + posm[i+1]) % mod;
        
        ll res = 0;
        for (int i = 0; i < n-1; i++) {
            ll val = (arr[i] * posm[i+1]) % mod;
            res = (res + val) % mod;
        }
        
        cout << res << endl;
    }
    
	return 0;
}


Measured memory_bytes: 6416
import std.stdio, std.conv, std.array,std.string,std.algorithm;

void main()
{
    auto n=readln.chomp.to!int,a=readln.split;
    int ma=a[0].to!int,mi=a[0].to!int;
    for(int i;i<n;i++){
        ma=max(ma,a[i].to!int);
        mi=min(mi,a[i].to!int);
    }
    writeln(ma-mi);
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    string S;
    cin>>S;
    int N = S.size();
    int cnt = 0;
    stack<int> memo;
  	memo.push(N);
    vector<bool> check(26);
    for(int i = N-1; i >= 0; i--){
        int t = S[i]-'a';
        if(!check[t]){
            cnt++;
            check[t]=true;
        }
        if(cnt == 26){
            for(int j = 0; j < 26; j++) check[j]=false;
            cnt=0;
            memo.push(i);
        }
    }
    int p = 0;
    vector<char> ans;
    while(!memo.empty()){
        int t = memo.top();
        memo.pop();
        vector<bool> alph(26,false);
        for(int i = p; i < t; i++){
            int s = S[i]-'a';
            alph[s]=true;
        }
        for(int i = 0; i < 26; i++){
            if(!alph[i]){
                char c = 'a'+i;
                ans.push_back(c);
                break;
            }
        }
        while(true&&t<N){
            if(S[t]==*ans.rbegin()){
                p=t+1;
                break;
            }
            t++;
        }
    }
    for(auto x:ans) cout<<x;
    cout<<endl;
}

Measured memory_bytes: 3768
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N,dtype=int)
for i in range(1,N):
    dp[i] = (dp[max(0,i-K):i] + np.abs(h[i]-h[max(0,i-K):i])).min()
print(dp[-1])


Measured memory_bytes: 22840
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int e,y;
	cin>>e>>y;
	if(e==0) {
		if(1911>=y) cout<<"M"<<(y-1868)+1<<endl;
		else if(1925>=y) cout<<"T"<<(y-1912)+1<<endl;
		else if(1988>=y) cout<<"S"<<(y-1926)+1<<endl;
		else cout<<"H"<<(y-1989)+1<<endl;
	}
	else {
		if(e==1) cout<<(1868+y)-1<<endl;
		else if(e==2) cout<<(1912+y)-1<<endl;
		else if(e==3) cout<<(1926+y)-1<<endl;
		else cout<<(1989+y)-1<<endl;
	}
}

Measured memory_bytes: 3108
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
    s = list(map(int, input().split()))
    C.append(s[0])
    A.append(s[1:])
ans = float('INF')
for i in range(0, 1 << N):
    scores = [0] * M
    count = 0
    for j in range(N):
        if (i >> j) & 1:
            for s in range(M):
                scores[s] += A[j][s]
            count += C[j]
    if min(scores) < X:
        continue
    else:
        ans = min(ans, count)

if ans == float("INF"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9232
n = int(input())
l = [int(x) for x in input().split()] 
dp = [float('inf')] * n  
dp[0] = 0
for i in range(n):
    for j in (i+1, i+2):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(l[i]-l[j]))
print(dp[n-1])

Measured memory_bytes: 20616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;

vector<pair<long, long>> elementCounter(vector<long> value_array){
	sort(value_array.begin(), value_array.end());

	auto array_iter = value_array.begin();
	auto old_array_iter = array_iter;
	vector<pair<long, long>> element_array;

	while(array_iter++ != value_array.end()){
		if (*array_iter != *old_array_iter){
			element_array.push_back(make_pair(*old_array_iter, static_cast<long>(distance(old_array_iter, array_iter))));
			old_array_iter = array_iter;
		}
	}
	element_array.push_back(make_pair(0l,0l));

	sort(element_array.begin(), element_array.end(), [](auto i, auto j){return i.second > j.second;});

	return element_array;
}

int main () {
	long n;
	cin >> n;
	vector<long> array_odd(n/2);
	vector<long> array_even(n/2);
	for (int i{0}; i < n; ++i)
		cin >> ((i%2) ? array_even[i/2] : array_odd[i/2]);

	vector<pair<long, long>> element_array_odd = elementCounter(array_odd);
	vector<pair<long, long>> element_array_even = elementCounter(array_even);

	if (element_array_odd[0].first == element_array_even[0].first){
		cout << n - ((element_array_odd[0].second + element_array_even[1].second
						< element_array_even[0].second + element_array_odd[1].second)
					? element_array_even[0].second + element_array_odd[1].second
					: element_array_odd[0].second + element_array_even[1].second
				   ) << endl;
	} else 
		cout << n - element_array_odd[0].second - element_array_even[0].second << endl;

	return 0;
}



Measured memory_bytes: 3696