akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long LL;
#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

using namespace std;


LL inputValue(){
  LL a;
  cin >> a;
  return a;
};

vector<LL> inputVector(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, vector<LL>& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL& i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
  // source code
  LL k = inputValue();
  LL x = inputValue();
  bool b = false;
  REPD(i, x-k+1, x+k) {
   if (b) {
     cout << " ";
   }
   b=true;
   cout << i;
  }
  cout << endl;


  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N)cin>>A[i];

    int special_count = 0;
    rep(i,N){
        int point = A[i];
        if(point <= 399)A[i] = 0;
        if(point >= 400 && point <= 799)A[i] = 1;
        if(point >= 800 && point <= 1199)A[i] = 2;
        if(point >= 1200 && point <= 1599)A[i] = 3;
        if(point >= 1600 && point <= 1999)A[i] = 4;
        if(point >= 2000 && point <= 2399)A[i] = 5;
        if(point >= 2400 && point <= 2799)A[i] = 6;
        if(point >= 2800 && point <= 3199)A[i] = 7;
        if(point >= 3200){
            A[i] = 8;
            special_count++;
        }
            
    }

    int count = 0;
    set<int> set1(A.begin(), A.end());
    for(int j: set1){
        if(j!=8){
            count+=1;
        }
    }

    int min_count = max({1, count});
    int max_count = special_count + count;

    cout << min_count << " " << max_count << endl;
    
    return 0;

}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys

YES = "Yay!"
NO = ":("

def solve(A: int, B: int):
    m = "null"
    for i in range(16):
        if A == 0 and B == 0:
            break
        if i != 15:
            if A > 0 and m != "A":
                A -= 1
                m = "A"
            elif B > 0 and m != "B":
                B -= 1
                m = "B"
            else:
                m = "Brank"
        else:
            if B > 0 and m != "B":
                B -= 1

    if A == 0 and B == 0:
        print(YES)
    else:
        print(NO)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main() {
    int n,x,maxi,ans=1;
    cin>>n;
    cin>>maxi;
    for(int i=1;i<n;i++){
        cin>>x;
        if(x>=maxi){
            ans++;
            maxi=x;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MOD = 1e9+7;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(a[0] != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    vector<int> v(n, 0);
    ll ans = 1;
    int count = 3;
    for(int i = 0; i < n; i++)
    {
        if(a[i] == 0)
        {
            ans = ans * count % MOD;
            count--;
            v[0]++;
            continue;
        }
        ans = ans * v[a[i]-1] % MOD;
        v[a[i]]++;
        v[a[i]-1]--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(b == 1){
    cout << 0 << endl;
    return 0;
  }
  if(a >= b){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  int cnt = 1;
  while(cnt < b){
    ans++;
    cnt += a - 1;
  }
  cout << ans << endl;
  return 0;
}


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

signed main() {
  int N, M;
  cin >> N >> M;
  vector<bool> hantei(N+1, false);
  hantei.at(1) = true;
  vector<int> ball(N+1, 1);
  ball.at(0) = 0;
  
  int X, Y;
  for( int i = 0; i < M; i++ ){
    cin >> X >> Y;
    if( hantei.at(X) == true ){
      hantei.at(Y) = true;
      ball.at(Y)++;
      ball.at(X)--;
      if( ball.at(X) == 0 ) hantei.at(X) = false;
    }else{
      ball.at(X)--;
      ball.at(Y)++;
    }
  }
  
  int ans = 0;
  for( int i = 0; i <= N; i++ ){
    if( hantei.at(i) == true ) ans++;
  }
  cout << ans << endl;
    
  
}


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

int main(){
  long A;
  string B;
  cin >> A >> B;
  int C = (B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');
  long ans = (A*C)/100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>

int count(char p, int N, const std::string& S)
{
    int turn = 0;
    for (int i = 0; i < N; i++) {
        if (p == S[i]) {
            turn++;
        }
        p = (p == '0') ? '1' : '0';
    }

    return turn;
}

int main()
{
    std::string S;
    std::cin >> S;

    int N = S.length();
    int ans = std::min(count('0', N, S), count('1', N, S));
    
    std::cout << ans << std::endl;

    return 0;
}

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

bool solve()
{
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;
    if(m == 0) return false;

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

    int res = nmin, gap = P[nmin-1] - P[nmin];
    for(int i = nmin; i <= nmax; ++i) {
        int tmp = P[i - 1] - P[i];
        if(gap <= tmp) res = i, gap = tmp;
    }

    cout << res << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<char> vec(H*W);
  for (int i = 0; i < (H * W); i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < (H + 2); i++) {
    for (int j = 0; j < (W + 2); j++) {
      if (i == 0 || i == (H + 1)) {
         cout << '#';
      }
      else {
        if (j == 0 || j == W + 1) {
         cout << '#';
        }
        else {
          cout << vec.at((i - 1) * W + (j - 1));
        }
      }
      if (j == (W + 1)) {
        cout << endl;
      }
    }
  }
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int m, f, r;
    while(true) {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        if(m == -1 || f == -1){
            say("F")
            continue;
        }
        
        if(m + f >= 80){
            say("A")
            continue;
        }
        
        if(m + f >= 65){
            say("B")
            continue;
        }

        if(m + f >= 50){
            say("C")
            continue;
        }

        if(m + f >= 30){
            if(r >= 50){
                say("C")
            }else{
                say("D")
            }
            continue;
        }
        say("F")
    }
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

multiset<ll> st;

int main(){
    int n, ans = 0;
    cin >> n;
    rep(i, n){
        ll a;
        cin >> a;
        st.insert(a);
    }

    while(st.size()){
        ll a = *st.rbegin();
        st.erase(st.find(a));
        ll p;
        rep(j, 35){
            if(ll(pow(2,j)>a)){
                p = ll(pow(2,j));
                break;
            }
        }
        if (st.find(p-a)!=st.end()){
            st.erase(st.find(p-a));
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13440
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323846

double x[1<<12|10];
double y[1<<12|10];

int main(){
	int n;
	scanf("%d",&n);
	if(n==0){
		puts("0 0\n100 0");
		return 0;
	}
	x[0]= 33.33333333,y[0]= 0.00000000;
	x[1]= 50.00000000,y[1]=28.86751346;
	x[2]= 66.66666667,y[2]= 0.00000000;
	x[3]=100.00000000,y[3]= 0.00000000;

	for(int k=1;k<n;k++){
		int m=1<<(2*k);
		for(int i=0;i<m;i++){
			x[i]/=3;
			y[i]/=3;
			x[m+i]=cos(PI/3)*x[i]-sin(PI/3)*y[i]+100.0/3;
			y[m+i]=sin(PI/3)*x[i]+cos(PI/3)*y[i];
			x[2*m+i]=cos(-PI/3)*(x[i]-100.0/3)-sin(-PI/3)*y[i]+200.0/3;
			y[2*m+i]=sin(-PI/3)*(x[i]-100.0/3)+cos(-PI/3)*y[i];
			x[3*m+i]=x[i]+200.0/3;
			y[3*m+i]=y[i];
		}
	}
	puts("0 0");
	for(int i=0;i<1<<(2*n);i++)printf("%f %f\n",x[i],y[i]);
}


Measured memory_bytes: 2052
import java.util.*;

class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String args[]){
    int[] a = {0,1,2,1,4,1,4,1,1,4,1,4,1};
    int x = sc.nextInt();
    int y = sc.nextInt();
    System.out.println( (a[x]==a[y]?"Yes":"No") );
  }
}

Measured memory_bytes: 21332
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
int n,xx,yy,et,be[110000],B,W,s[110000],st,siz[110000],f[110000],he,ta;
bool isw[110000];
struct edg{
	int y,ne;
};
edg e[220000];
inline void add_edge(int x,int y){
	e[++et].y=y;
	e[et].ne=be[x];
	be[x]=et;
}
void dfs(int x,int fa){
	siz[x]=1;s[x]=1;f[x]=1;
	fe(x){
		int &y=e[i].y;
		if (y!=fa){
			dfs(y,x);
			siz[x]+=siz[y];
			if (!isw[y]) f[x]+=f[y];
			if (isw[y]) isw[x]=1;
		}
	}
	if (isw[x]&&x!=1) s[++st]=x;
	if (x==n){
		W=siz[x];
		f[x]=0;
		isw[x]=1;
	}
}
int main(){
	scanf("%d",&n);
	fo(i,2,n){
		scanf("%d%d",&xx,&yy);
		add_edge(xx,yy);
		add_edge(yy,xx);
	}
	dfs(1,-1);
	B=f[1];
	//printf("%d %d\n",B,W);
	/*printf("%d\n",st);
	fo(i,1,st) printf("%d ",s[i]);*/
	he=0;ta=st+1;
	while (he+1<ta){
		if (he<ta-1){
			ta--;
			B+=f[s[ta]];
		}
		if (he+1<ta){
			he++;
			W+=f[s[he]];
		}
	}
	if (W>=B) printf("Snuke\n");else printf("Fennec\n");
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > vp;
int main()
{
    int n;
    scanf("%d",&n) ;
    int st = n + (n%2 == 0);
    for(int i = 1;i <= n;i++) {
        for(int j = i+1;j <= n;j++) {
            if(i + j != st) vp.push_back(pair<int,int>{i,j});
        }
    }
    printf("%d\n",vp.size());
    for(int i=0;i <vp.size();i++) printf("%d %d\n",vp[i].first , vp[i].second);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int h[500001],w[500001],o,q[500001],f[500001],c[500001],v[500001],qw,wq,a,b,qq=1,ww=1,ans=0;
int get(int y)
{
    if(y==f[y]) return y ; 
    return f[y]=get(f[y]);
}
void dfs(int n, int m)
{
    c[n]=m;
    for (int i=h[n]; i; i=w[i])
    {
        if (q[i]!=f[n])
        {
            f[q[i]]=n;
            dfs(q[i], -m);
            c[n] += c[q[i]];
        }
    }
}
int main()
{
    for (int i = 1; i <= 500000; ++i)
    {
        f[i] = i;
    }
    cin>>a>>b;
    for (int i = 1; i <= b; ++i)
    {
        cin>>qw>>wq;
        if (get(qw) != get(wq))
        {
            f[f[qw]] = f[wq];
        }
        else
        {
            qq = qw;
             ww = wq;
            continue;
        }
        o++;
        w[o] = h[qw];
        q[o] = wq;
        h[qw]=o;
        o++;
        w[o] = h[wq];
        q[o] = qw;
        h[wq]=o;
    }
    f[qq] = 0;
    dfs(qq, 1);
    if (a == b)
    {
        long long u=0;
        for (int i = ww; i; i = f[i])
        {
            u++;
            v[u] = c[i];
        }
        if (u % 2)
        {
            if (c[qq] % 2)
            {
                cout<<"-1";
                return 0;
            }
            for (int i = ww; i; i = f[i])
            {
                c[i] -= c[qq] / 2;
            }
        }
        else
        {
            if (c[qq])
            {
                cout<<"-1";
                return 0;
            }
            sort(v + 1, v + u + 1);
            for (int i = ww; i; i = f[i])
            {
                c[i] -= v[u / 2];
            }
        }
    }
    else if (c[qq])
    {
        cout<<"-1";
        return 0;
    }
    for (int i = 1; i <= a; ++i)
    {
        ans += abs(c[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 16084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

// 整数が2147483647より大きければllを使う
typedef long long ll; 

int F(ll A, ll B){
    int i = 0;
    while (A > 0){
        i++;
        A /= 10;
    }
    int j = 0;
    while (B > 0){
        j++;
        B /= 10;
    }
    if (i < j) return j;
    return i;
}

int main(){
    ll N;
    cin >> N;
    ll A, B;
    int MIN = 1<<30;
    int m;
    for (ll i=1; i<=N; ++i){
        A = i;
        if (N / A < A) break;
        if (N % A == 0){
            B = N / A;
            m = F(A, B);
            // cout << A << " " << B << " " << m << endl;
            if (MIN >= m){
                MIN = m;
            } else {
                cout << MIN << endl;
                return 0;
            }
        }
    }
    cout << MIN << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#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--) //ループ変数は1ずつデクリ
// 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の二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
#define P pair<ll, ll>
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int main() {
    ll H, W, K;
    cin >> H >> W >> K;

    // dp[ i ][ j ] :=
    // 上からi刻み分についての入れかたのうち、0からスタートしてjで終わるようなものの個数
    vector<vector<ll>> dp(H + 1, vector<ll>(W + 1, 0));
    dp[0][0] = 1;
    REP(i, H) {
        REP(j, W) {
            for (ll bit = 0; bit < (1 << W - 1); ++bit) {
                bool ok = true;
                for (ll k = 0; k < W - 2; ++k) {
                    if ((bit & (1 << k) && (bit & (1 << (k + 1))))) {
                        ok = false;
                        break;
                    }
                }

                if (!ok) {
                    continue;
                }

                if ((bit & (1 << j)) && (j < W - 1)) {
                    add(dp[i + 1][j + 1], dp[i][j]);
                } else if ((j > 0) && (bit & (1 << (j - 1)))) {
                    add(dp[i + 1][j - 1], dp[i][j]);
                } else {
                    add(dp[i + 1][j], dp[i][j]);
                }
            }
        }
    }
    cout << dp[H][K - 1] << endl;
}

Measured memory_bytes: 3636
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int k, dist[100005];

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

    cin>>k;
    memset(dist, -1, sizeof(dist));
    deque<ii> dq;
    dq.push_front({1, 1});

    while(!dq.empty()){

        int v = dq.front().ff, d = dq.front().ss;
        dq.pop_front();
        if(dist[v] != -1)   continue;
// cout<<"assigned "<<d<<" to "<<v<<endl;
        dist[v] = d;

        if(dist[(v+1)%k] == -1) dq.push_back({(v+1)%k, d+1});
        if(dist[(10*v)%k] == -1) dq.push_front({(10*v)%k, d});
    }

// for(int i=0;i<k;i++)    cout<<dist[i]<<" ";cout<<endl;

    cout<<dist[0];
    return 0;
}






Measured memory_bytes: 1152
while True:
    n = int(input())
    if n == 0:
        break
    else:
        phlist=[]
        phflag=0
        for i in range(n):
            phlist.append(input())

        for i in range(len(phlist)-4):
            cur=0
            state=0
            for j in range(i, len(phlist)):
                s = phlist[j]
                cur+=len(s)
                if state==0 and cur<5:
                    continue
                elif state==0 and cur==5:
                    cur=0
                    state=1
                elif state==1 and cur<7:
                    continue
                elif state==1 and cur==7:
                    cur=0
                    state=2
                elif state==2 and cur<5:
                    continue
                elif state==2 and cur==5:
                    cur=0
                    state=3
                elif state==3 and cur<7:
                    continue
                elif state==3 and cur==7:
                    cur=0
                    state=4
                elif state==4 and cur<7:
                    continue
                elif state==4 and cur==7:
                    print(i+1)
                    phflag=1
                    break

            if phflag:
                break



Measured memory_bytes: 5620
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  int N;
  std::string S;
  std::cin >> N >> S;
  std::vector<std::array<int, 3>> memo(N);
  memo.back()[0] = 0;
  memo.back()[1] = 0;
  memo.back()[2] = 0;
  auto toIndex = [](char c)
  {
    if(c == 'R')
      return 0;
    else if (c == 'G')
      return 1;
    else
      return 2;
  };
  for(int i = N - 2; 0 <= i; --i)
  {
    memo[i] = memo[i + 1];
    ++memo[i][toIndex(S[i + 1])];
  }
  long long ans = 0;
  for(int i = 0; i < N; ++i)
  {
    for(int j = i + 1; j < N; ++j)
    {
      char c1 = S[i], c2 = S[j];
      if(c1 != c2)
      {
        int inc = 0;
        char c3 = 0;
        if(c1 != 'R' && c2 != 'R')
        {
          inc = memo[j][0];
          c3 = 'R';
        }
        else if(c1 != 'G' && c2 != 'G')
        {
          inc = memo[j][1];
          c3 = 'G';
        }
        else
        {
          inc = memo[j][2];
          c3 = 'B';
        }
        int d = j - i;
        if(j + d < N && c3 == S[j + d])
          --inc;
        ans += inc;
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

// int left[2100][2100], right[2100][2100], up[2100][2100], down[2100][2100];

int main(){

    int h, w;
    cin>>h>>w;
    vector<string> S(h);
    rep(i,h) cin>>S[i];
    vector<vector<int>> left(h+1, vector<int>(w+1));
    vector<vector<int>> right(h+1, vector<int>(w+1));
    vector<vector<int>> up(h+1, vector<int>(w+1));
    vector<vector<int>> down(h+1, vector<int>(w+1));
    

    //前処理
    rep(i,h){
        int cnt = 0;
        rep(j,w){
            if(S[i][j]=='#') cnt = 0;
            else cnt++;
            left[i][j] = cnt;
        }
    }
    rep(i,h){
        int cnt=0;
        for(int j=w-1;j>=0;j--){
            if(S[i][j]=='#') cnt=0;
            else cnt++;
            right[i][j]=cnt;
        }
    }
    rep(j,w){
        int cnt=0;
        rep(i,h){
            if(S[i][j]=='#') cnt=0;
            else cnt++;
            up[i][j]=cnt;
        }
    }
    rep(j,w){
        int cnt=0;
        for(int i=h-1;i>=0;i--){
            if(S[i][j]=='#') cnt=0;
            else cnt++;
            down[i][j]=cnt;
        }
    }
    
    int ans=0;
    rep(i,h){
        rep(j,w){
            if(S[i][j]=='#') continue;
            ans = max(ans, left[i][j]+right[i][j]+up[i][j]+down[i][j]-3);
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 73732
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

int main(){
    int n, m;
    std::cin >> n >> m;

    std::vector<int> k(m), p(m);
    std::vector<std::vector<int>> s(m);
    for(int i = 0; i < m; ++i){
        std::cin >> k.at(i);
        for(int j = 0; j < k.at(i); ++j){
            int val;
            std::cin >> val;
            s.at(i).push_back(val - 1);
        }
    }

    for(int i = 0; i < m; ++i){
        std::cin >> p.at(i);
    }

    int ans = 0;
    for(int bits = 0; bits < (1 << n); ++bits){
        int valves = 0;
        for(int i = 0; i < m; ++i){
           int count = 0;
            for(int j = 0; j < k.at(i); ++j){
                if((bits >> s.at(i).at(j)) & 1){
                    ++count;
                }
            }

            if(p.at(i) == count % 2){
                ++valves;
            }
        }

        if(m == valves){
            ++ans;
        }
    }

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

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    double x;
    string u;
    double sum = 0;

    for (int i = 1; i <= n; i++) {
        cin >> x >> u;
        if (u == "JPY") sum += x;
        if (u == "BTC") sum += x * 380000;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

map<char, int> m={{'A', 1}, {'C', 2}, {'G', 3}, {'T', 4}};

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

    vector<vector<vector<vector<long long> > > > dp(N+1, vector<vector<vector<long long> > >(5,vector<vector<long long> >(5,vector<long long>(5,0))));
    dp[0][0][0][0]=1;

    for(int i=0; i<N; i++){
        for(int j=0; j<5; j++){
            for(int k=0; k<5; k++){
                for(int h=0; h<5; h++){
                    if((j==1 && (k==3 || h==3)) || (k==1 && h==3) || (k==3 && h==1)){
                        for(int r=1; r<5; r++){
                            if(r==2)continue;
                            dp[i+1][k][h][r]=(dp[i+1][k][h][r]+dp[i][j][k][h])%MOD;
                        }
                        continue;
                    }

                    if(k==1 && h==2){
                        for(int r=1; r<5; r++){
                            if(r==3)continue;
                            dp[i+1][k][h][r]=(dp[i+1][k][h][r]+dp[i][j][k][h])%MOD;
                        }
                        continue;
                    }
                    for(int r=1; r<5; r++){
                        dp[i+1][k][h][r]=(dp[i+1][k][h][r]+dp[i][j][k][h])%MOD;
                    }
                }
            }
        }
    }

    long long ans = 0;
    for(int i=1; i<5; i++){
        for(int j=1; j<5; j++){
            for(int k=1; k<5; k++){
                ans=(ans+dp[N][i][j][k])%MOD;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n){
        cin>>v[i];
    }
    
    int ans=0;
    rep(i,0,101){
        int count=0;
        rep(j,0,v.size()){
            if(i<=v[j])count++;
        }
        if(count>=i)ans=i;
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<cstring>
using namespace std;
int main(){

    long long int n,ans=0,i,j,k;
    cin>>n;
    long long int a[n+1][n+1];
    bool p[n+1][n+1];
    memset(p,0,sizeof(p));
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];

    for(k=1;k<=n;k++)      
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j++){
                if(k!=j&&k!=i&&i!=j){
                    if(a[i][j]==a[i][k]+a[k][j])
                        p[i][j]=1; 
                    if(a[i][j]>a[i][k]+a[k][j]){
                        cout<<"-1"<<endl;
                        return 0;
                    }
                }
            }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(p[i][j]==0)
                ans+=a[i][j]; 
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=1e5+5;
int n,fa[MN],siz[MN],id[MN];
ll d[MN];
inline bool cmp(int x,int y){return d[x]<d[y];}
map<ll,int>mp;
ll ans;
int h[MN],cnt,to[MN],nxt[MN];
inline void ins(int s,int t){
	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;
}
void dfs(int st,int fa=0,int dep=0){
	ans+=dep;for(reg int i=h[st];i;i=nxt[i])dfs(to[i],st,dep+1);
}
int main(){
	ios::sync_with_stdio(false);cin>>n;
	for(reg int i=1;i<=n;i++)cin>>d[i],id[i]=i,siz[i]=1,mp[d[i]]=i;
	sort(id+1,id+1+n,cmp);reg int cnt=0;
	for(reg int i=n;i>1;i--){
		reg int pos=id[i];reg ll fad=d[pos]+2ll*siz[pos]-n;
		if(!mp[fad]||fad>=d[pos])return 0*puts("-1");
		reg int fap=mp[fad];siz[fap]+=siz[pos];ins(fap,pos);
	}
	dfs(id[1]);if(d[id[1]]^ans)return 0*puts("-1");
	for(reg int i=1;i<=n;i++)for(reg int j=h[i];j;j=nxt[j])printf("%d %d\n",i,to[j]);
	return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static int T;


	public static void main(String[] args) {
		N = sc.nextInt();

		int[] x = new int[N];
		int[] y = new int[N];
		int[] h = new int[N];

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
		}

		int MAX = 100;

		for (int posY = 0; posY <= MAX ; posY++) {
			for (int posX = 0; posX <= MAX; posX++) {
				int needH = -1;

				for (int i = 0; i < N; i++) {
					if (h[i] > 0) {
						int tmp = h[i] + Math.abs(posX - x[i]) + Math.abs(posY - y[i]);

						if (needH == -1) {
							needH = tmp;
						} else {
							if (needH != tmp) {
								needH = -2;
								break;
							}
						}
					}
				}
				if (needH == -2) continue;

				for (int i = 0; i < N; i++) {
					if (h[i] == 0) {
						int dist =  Math.abs(posX - x[i]) + Math.abs(posY - y[i]);

						if (needH > dist) {
							needH = -2;
							break;
						}
					}
				}
				if (needH == -2) continue;

				System.out.println(posX + " " + posY + " " + needH);
			}
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define INF 1000000000+10

const ll mod = 1000000000+7;
const int N = 100000+5;

int dp[N];
int a[N];

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin >> n >> k;
	for(int i = 0 ; i<n; i++)
	{
		cin >> a[i];
	}
	dp[0] = 1;
	for(int i = 1; i<=k; i++)
	{
		int l = false;
		for(int j = 0; j<n; j++)
		{
			if(i-a[j] >= 0)l|=dp[i-a[j]];
		}
		dp[i] = !l;
	}
	if(dp[k])cout << "Second";
	else cout << "First";
}

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

int main(){
  long double a,b;cin>>a>>b;
  ll ans=floor(a*b);
  cout<<ans;
}

Measured memory_bytes: 3732
H, W, M = map(int, input().split())
HW = set(tuple(map(lambda x: int(x)-1, input().split())) for _ in range(M))

sum_h = [0]*H; sum_w = [0]*W
for h, w in HW:
    sum_h[h] += 1
    sum_w[w] += 1

max_h_num = 0
h_num_ix = {}
for i in range(H):
    num = sum_h[i]
    if num == 0: continue
    if not num in h_num_ix: h_num_ix[num] = set()
    h_num_ix[num].add(i)
    max_h_num = max(max_h_num, num)

max_w_num = 0
w_num_ix = {}
for i in range(W):
    num = sum_w[i]
    if num == 0: continue
    if not num in w_num_ix: w_num_ix[num] = set()
    w_num_ix[num].add(i)
    max_w_num = max(max_w_num, num)

max_num = max_h_num + max_w_num - 1
for h_ix in h_num_ix[max_h_num]:
    for w_ix in w_num_ix[max_w_num]:
        if (h_ix, w_ix) in HW: continue
        print(max_num + 1)
        exit()
print(max_num)


Measured memory_bytes: 102076
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn check(left: usize, central: usize, right: usize, is_sheeps: &Vec<bool>, s: &Vec<char>) -> bool {
    if s[central] == 'o' {
        if is_sheeps[central] {
            if is_sheeps[left] != is_sheeps[right] {
                return false;
            }
        } else {
            if is_sheeps[left] == is_sheeps[right] {
                return false;
            }
        }
    } else {
        if is_sheeps[central] {
            if is_sheeps[left] == is_sheeps[right] {
                return false;
            }
        } else {
            if is_sheeps[left] != is_sheeps[right] {
                return false;
            }
        }
    }
    true
}

/*
fn check(left: usize, central: usize, right: usize, is_sheeps: &Vec<bool>, s: &Vec<char>) -> bool {
    let n = is_sheeps.len();
    if is_sheeps[central] && s[central] == 'o' {
        if !is_sheeps[left] || !is_sheeps[right] {
            return false;
        }
    } else if !is_sheeps[central] && s[central] == 'x' {
        if is_sheeps[left] || is_sheeps[right] {
            return false;
        }
    } else if is_sheeps[left] == is_sheeps[right] {
        return false;
    }
    true
}
*/

fn main() {
    let n: usize = read();
    let s: String = read();
    let s = s.chars().collect::<Vec<_>>();

    let trials = [(true, true), (false, false), (false, true), (true, false)];
    for trial in trials.iter() {
        let mut is_sheeps = vec![false; n];
        is_sheeps[0] = trial.0;
        is_sheeps[1] = trial.1;

        for i in 1..n - 1 {
            if is_sheeps[i] && s[i] == 'o' {
                is_sheeps[i + 1] = is_sheeps[i - 1];
            } else if !is_sheeps[i] && s[i] == 'x' {
                is_sheeps[i + 1] = is_sheeps[i - 1];
            } else {
                is_sheeps[i + 1] = !is_sheeps[i - 1];
            }
        }
        let mut succeeded = true;
        succeeded &= check(n - 2, n - 1, 0, &is_sheeps, &s);
        succeeded &= check(n - 1, 0, 1, &is_sheeps, &s);
        for i in 1..n - 1 {
            succeeded &= check(i - 1, i, i + 1, &is_sheeps, &s);
        }
        if succeeded {
            println!(
                "{}",
                is_sheeps
                    .iter()
                    .map(|&x| if x { "S" } else { "W" })
                    .collect::<Vec<_>>()
                    .join("")
            );
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI dp[110][101000];

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

  int N,W; cin >> N >> W;
  vector<int> w(N), v(N);
  REP(i,N) cin >> w[i] >> v[i];

  REPE(i,N) REPE(j,100000) dp[i][j] = 1e18;
  dp[0][0] = 0;

  REP(i,N){
    REPE(j,100000){
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i+1][j+v[i]], dp[i][j]+w[i]);
    }
  }

  LLI ans = 0;

  REPE(i,100000) if(dp[N][i] <= W) chmax(ans, (LLI)i);

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


Measured memory_bytes: 80128
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    ll N;cin>>N;
    ll a[110],MAX=-999,MIN=999,cn=0,cnMIN=99999999;
    rep(i,0,N){
        cin>>a[i];
        MAX=max(MAX,a[i]);
        MIN=min(MIN,a[i]);
    }
    rep(i,MIN,MAX+1){
        cn=0;
        rep(j,0,N){
            cn+=(a[j]-i)*(a[j]-i);
        }
        cnMIN=min(cnMIN,cn);
    }
    cout<<cnMIN<<endl;
    
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  string s; cin >>s;
  int K; cin >>K;
  for (int i=0; i<s.size(); i++){
    if (s[i] == 'a') continue;
    if ('z' - s[i] + 1 > K) continue;
    K -= 'z' - s[i] + 1;
    s[i] = 'a';
  }
  K %= 26;
  s[s.size()-1] = 'a' + (s[s.size()-1] - 'a' + K)%26;
  cout <<s <<endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int A[55];
int B[55];
int C[55];
int main()
{
  int N;
  cin >> N;
  for (int i=0; i<N; i++) cin >> A[i];
  for (int i=1; i<=N; i++) cin >> B[i];
  for (int i=1; i<=N-1; i++) cin >> C[i];
  int ret = 0;
  for (int i=0; i<N; i++) {
    ret += B[A[i]];
    if (i > 0 && A[i] == A[i-1] + 1) {
      ret += C[A[i]-1];
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
typedef long long int ll;
// #define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define debug(x) cout << #x << " is: " << (x) << endl;
#define debugx(x) cout << #x << " is: " << (x) << endl; exit(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;i<n;i++)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define INF 1000111000111000111LL
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {-1, 0, 1, 0};
const ll N = 5e5+5;
// ll a[N], b[N], dp[N], level[N], vis[N], in[N], out[N];
// vl g[N];
ll n, m;

void solve() {
    cin >> n;
    ll x = 0;
    ll res = 0;
    if(n % 2 == 0){
        cout << -1 << endl;
        return;
    }
    while(1){
        res++;
        x = x*10 + 7;
        x %= n;
        if(x % n == 0){
            cout << res << endl;
            break;
        }
        if(res > n){
            cout << -1 << endl;
            break;
        }
    }
}   
 
int32_t main() {
    IOS
    clock_t begin = clock();
    ll T = 1;
    // cin >> T;
    while(T--)
    solve();
    cerr<<"Time elapsed : "<<(clock()-begin)*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n';
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main(){
	string a, b;
	cin >> a >> b;
	int cnt = 0;
	for(int i=0; i<a.length(); i++){
		if(a[i]==b[i]){
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int t,f,h,s,k;
int a, b, c, x;

scanf("%d %d %d %d", &a, &b, &c, &x);

k = 0;
for(h=0 ;h <= a;h++)
{
for(f=0;f <= b;f++)
{
for(t=0;t <= c;t++)
{
s = 500 * h + 100 * f + 50 * t;
if(s == x)
{
k++;
}
}
}
}
printf("%d",k);
return 0;
}


Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = [int(i) for i in input().split()]
    min_ = p[0]
    cnt = 0
    for i in range(n):
        if p[i] <= min_:
            min_ = p[i]
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

vector<int> D;
void sieve(int N) {
    rep(i,N+1) D[i] = i;
    vector<bool> sieved(N+1, false);
    for (int i = 2; i * i <= N; i++) {
        for (int j = i; j <= N; j += i) {
            if (!sieved[j]) {
                D[j] = i;
                sieved[j] = true;
            }
        }
    }
}

int main() {
    int N; cin >> N;
    D.assign(1000001,0);
    sieve(1000000);
    ll g;
    set<int> factor;
    bool pairwise = true;
    rep(i,N) {
        int A; cin >> A;
        if (i == 0) g = A;
        else {
            g = gcd(g,A);
        }
        int n = A;
        while (pairwise && n > 1) {
            if (factor.count(D[n]) > 0) {
                pairwise = false;
                break;
            }
            factor.insert(D[n]);
            int d = D[n];
            while (n % d == 0) n /= d;
        }
    }

    if (pairwise) {
        cout << "pairwise coprime" << endl;
    } else if (!pairwise && g == 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }
}


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

#define llong long long

void fnInput(int &rnMaxSiz, vector<llong> &rvnSort)
{
  cin >> rnMaxSiz;

  rvnSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
    cin >> rvnSort[i];
}

void fnMerge(vector<llong> &rvnSort, llong &rnInvCnt, int nLeft, int nMid, int nRight)
{
  vector<llong> vnLeft, vnRight;
  int nLeftSiz = nMid - nLeft;
  int nRightSiz = nRight - nMid;
  
  vnLeft.resize(nLeftSiz + 1);
  vnRight.resize(nRightSiz + 1);
  for (int i = 0; i < nLeftSiz; i++)
    vnLeft[i] = rvnSort[nLeft + i];
  for (int i = 0; i < nRightSiz; i++)
    vnRight[i] = rvnSort[nMid + i];

  vnLeft[nLeftSiz] = LLONG_MAX;
  vnRight[nRightSiz] = LLONG_MAX;

  int i = 0, j = 0;
  for (int n = nLeft; n < nRight; n++)
    if (vnLeft[i] <= vnRight[j])
      rvnSort[n] = vnLeft[i++];
    else
    {
      rvnSort[n] = vnRight[j++];
      if (vnLeft[i] != INT_MAX)
        rnInvCnt += (nLeftSiz - i);
      else;
    }  
}

void fnMergeSort(vector<llong> &rvnSort, llong &rnInvCnt, int nLeft, int nRight)
{
  if (nLeft + 1 < nRight)
  {
    int nMid = (nLeft + nRight) / 2;
    fnMergeSort(rvnSort, rnInvCnt, nLeft, nMid);
    fnMergeSort(rvnSort, rnInvCnt, nMid, nRight);
    fnMerge(rvnSort, rnInvCnt, nLeft, nMid, nRight);
  }
}

void fnResult(llong nInvCnt)
{
  cout << nInvCnt << endl; 
}

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

  int nMaxSiz;
  vector<llong> vnSort;

  fnInput(nMaxSiz, vnSort);

  int nLeft = 0;
  int nRight = nMaxSiz;
  llong nInvCnt = 0;
  fnMergeSort(vnSort, nInvCnt, nLeft, nRight);

  fnResult(nInvCnt);

  return 0;
}

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

using namespace std;

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


void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	vector<int> h(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> h[i];
		
	int INF = 1e9;
		
	vector<int> dp(n + 1, INF);
		dp[1] = 0;
	
	for (int i = 1; i <= n; i++) {
		if (i != n)
			dp[i + 1] = min(dp[i+1], dp[i] + abs(h[i + 1] - h[i]));
		if (i < n - 1)
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}
	
	cout << dp[n];
}

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




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[100100];
int n;
ll s[100100];
int go(int idx)
{
    if(idx==n-1)
        return 0;
    ll &ret=dp[idx];
    if(ret!=-1)
        return ret;
    ret=1e12;
    if(idx+2<n)
    {ret=min(ret,abs(s[idx]-s[idx+2])+go(idx+2));

    }
    ret=min(ret,abs(s[idx]-s[idx+1])+go(idx+1));
return ret;
}
int main(){
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)
        scanf("%lld",&s[i]);
    go(0);
    cout<<dp[0];
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    

	int A, B, C, K; cin >> A >> B >> C >> K;
    int M = max(max(A, B),C);
    int sum = A + B + C - M;
    while (K--) {
        M *= 2;
    }

    sum += M;
    
    cout << sum << endl;;

    return 0;
}

Measured memory_bytes: 256