#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    ll K;
    cin >> K;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
        vec.at(i)--;
    }
    if(K <= 100000) {
        int cnt2 = 0;
        for(int i = 0;i < K;i++) {
            cnt2 = vec.at(cnt2);
        }
        cout << cnt2 + 1 << endl;
        return 0;
    }
    vector<ll> cnt(N,-1);
    cnt.at(0) = 0;
    int cnt2 = 0;
    ll cnt3 = 1;
    ll cnt4 = 0;
    while(true) {
        cnt2 = vec.at(cnt2);
        if(cnt.at(cnt2) != -1) {
            cnt4 = cnt3 - cnt.at(cnt2);
            cnt3 = cnt.at(cnt2);
            break;
        }
        cnt.at(cnt2) = cnt3;
        cnt3++;
    }
    K -= cnt3;
    for(int i = 0;i < N;i++) {
        cnt.at(i) -= cnt3;
    }
    for(int i = 0;i < N;i++) {
        if(cnt.at(i) >= 0 && cnt.at(i) == K % cnt4) {
            cout << i + 1 << endl;
            break;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
//#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define PI          acos(-1)
#define re 			resize
#define un(a)		sort(a.begin(),a.end());a.resize(unique(a.begin(),a.end())-a.begin())

int n;
ull k;
int dp[(ll)2e5+1][61];
signed main(void)
{ios
	cin>>n>>k;
	rep(i,1,n+1)
	cin>>dp[i][0];
	for(int p=1;p<=60;p++)
		for(int i=1;i<=n;i++)
			dp[i][p]=dp[dp[i][p-1]][p-1];
	int cur=1;
	for(int i=60;i>=0;i--)
		if(((1ull)<<i)&k)
			cur=dp[cur][i];
	cout<<cur<<endl;
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


#include <bits/stdc++.h>
using namespace std;
int main()
  {int A, B, C, D; cin >> A >> B >> C >> D;
  while (true)
    {C -= B; if (C <= 0) {puts("Yes"); return 0;}
    A -= D; if (A <= 0) {puts("No"); return 0;}}}

Score : 200 points

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...
Here, an attack decreases the opponent's health by the value equal to the attacker's strength.
The monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

If Takahashi will win, print Yes; if he will lose, print No.

Constraints

1 \leq A,B,C,D \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi will win, print Yes; if he will lose, print No.

Sample Input 1

10 9 10 10

Sample Output 1

No

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

Sample Input 2

46 4 40 5

Sample Output 2

Yes


#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int a, b, c , d, count = 0;
  	cin >> a >> b >> c >> d;
  	while(true)
    {
      count++;
      if(max(a,b) < max(c,d))
      {
        cout << "No\n";
        break;
      }
      else if(max(a,b) > max(c,d))
      {
        cout << "Yes\n";
        break;
      }
      else
      {
      	count % 2 ? cout << "No\n" : cout << "Yes\n";
    	break;
      }
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++)
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;

void solve()
{
	int n,i,j,k=0,l,a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0){
		if(k%2==0)
			c=c-b;
		else
			a=a-d;
		k++;
	}
	if(a==0)
		cout<<"No\n";
	else
		cout<<"Yes\n";
}
int  main()
{
	auto start=clock();
	fast_io;
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    auto stop =clock();
    cerr<<"time taken:"<<double(stop-start)/double(CLOCKS_PER_SEC)<<" s"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int f=1;
    while(a>0&&c>0){
        if(f)c-=b;
        else a-=d;
        f^=1;
    }
    if(a<=0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N);
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modexp((x*x)%M,n/2,M);
    else
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
void solve()
{
    int h1,s1,h2,s2; cin>>h1>>s1>>h2>>s2;
    int x = ceil((double)h2/(double)s1) , y=ceil((double)h1/(double)s2);
    if(x<=y)
    cout<<"Yes";
    else
    cout<<"No";
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {

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


#include <bits/stdc++.h>
using namespace std;

int main(){
  float a,b,c,d;
  cin>>a>>b>>c>>d;
  if(ceil(c/b)>ceil(a/d)){
    cout<<"No";
  }else{cout<<"Yes";}
}


#include<bits/stdc++.h>
using namespace std;
#define  ll  long long  //define a macro variable of long long type
# define  loop(x,n)  for(int x = 0; x < n; ++x)  // define a for loop
#define   constloop(x,a,n) for(int x = a; x < n; ++x)  //define a for loop with start a const
#define  revloop(x,a,n)  for(int x = a; x > n; x--) // rev for loop
//#define   vect vector<ll>  // define a vector of longlong type;

int  main() {

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

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
int a,b,c,d;
cin>>a>>b>>c>>d;
int l=a;
int m=c;
bool s=true;
while(l>0 && m>0)
{
    if(s)
    {
        m -=b;
        s=false;

    }
    else
    {
        l -=d;
        s=true;
    }

}
//cout<<l<<" "<<m;
if(l<=0)
{
    cout<<"No"<<endl;
}
else
    cout<<"Yes"<<endl;

   return 0;

}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  while(1){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }

    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int bp(int pow, int n){
    int d = 1;
    while(n)
    {
        if(n%2==1)d=(d*pow)%mod;
        pow=(pow*pow)%mod;
        n/=2;
    }
    return d;
}
void solve(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    a=max(a, b);
    c=max(c, d);
    if(a>c)cout<<"Yes\n";
    else cout<<"No\n";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >>d;
	bool turn = true;
	while(a > 0 && c > 0)
	{
		if(turn)
			c -= b;
		else
			a -= d;
		turn = !turn;
	}
	if(a > 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


//please refer from line no. 207
/////*31022618*/////
//_MONU KUMAR
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tc ll t=1; cin>>t; while(t--)
#define ll long long int
#define ld long double
#define ull unsigned long long
#define p1(x) cout <<x<<"\n";
#define p2(x,y) cout <<x<<" "<<y<<"\n";
#define p3(x,y,z) cout <<x<<" "<<y<<" "<<z<<"\n";
#define p4(x,y,z,w) cout <<x<<" "<<y<<" "<<z<<" "<<w<<"\n";
#define trace(x) cout<<#x<<": "<<x<<" "<<"\n";
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<"\n";
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"\n";
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<"\n";
#define nL cout<<"\n";
#define lp(i,l,r) for (long long int i = l; i < r; i++)
#define lpr(i,r,l) for (long long int i = r-1; i >=l ; i--)
#define mem(a,x) memset(a,x,sizeof(a))              //set elements of array to some value
#define pi 3.1415926535897932384626
#define mod 1000000007
#define big 1e18
#define small -big
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define ff first
#define ss second
#define siz 256
#define leadzero(a) __builtin_clz(a)        // count leading zeroes
#define trailzero(a) __builtin_ctz(a)       // count trailing zeroes
#define bitcount(a) __builtin_popcount(a)   // count set bits
#define all(v) v.begin(),v.end()
#define lps(v,x) (lower_bound(all(v),x)-v.begin())
#define ups(v,x) (upper_bound(all(v),x)-v.begin())
//#########################################################################################
bool anagram(char *s1, char *s2)
{
  ll count[siz];
    mem(count,0) ;
    ll i;
    for (i = 0; s1[i] && s2[i];  i++)
    {
        count[s1[i]]++;
        count[s2[i]]--;
    }
    if (s1[i] || s2[i])
    {
      return false;
    }
    lp(i,0,siz)
    {
       if (count[i])
       {
          return false;
       }
    }
     return true;

}
//###########################################################################################
// modulo Multiplication
ll moduloMultiplication(ll  a, ll  b,  ll  zz)
{
    ll res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % zz;

        a = (2 * a) % zz;

        b >>= 1;
    }
    return res;
}
//###########################################################################################

ll convert(string s)
{
    bool o = true ;
    ll ans = 0 ;
    for(ll i=0;i<s.length();i++)
    {
        ans = ans*10 + (s[i]-48) ;
    }
    return ans ;
}
//###########################################################################################
//function to calculate a^b under mod...
ll powmod(ll a,ll b, ll modulo)
{
    if(b==0 || a==1) return 1;
    ll half=powmod(a,(b/2),modulo) % modulo;
    ll full = (half*half)%modulo;

    if(b%2) return (full*a)%modulo;
    return full%modulo;
}
//###########################################################################################
//function to calculate inverse modulo under mod...assuming gcd is 1
ll invmod(ll a,ll modulo)
{
    ll check=powmod(a,modulo-2,modulo) %modulo;
    return check;
}
//###########################################################################################

ll max(ll a,ll b)
{
  if (a>b) {
    /* code */
    return a;
  }
  return b;
}
//###########################################################################################
ll min(ll a,ll b)
{
  if (a<b) {
    /* code */
    return a;
  }
  return b;
}
//###########################################################################################
ll min(ll a,ll b, ll c)
{
  if (a<b) {
    /* code */
    return min(a,c);
  }
  else
  {
      return min(b,c);
  }

}
//###########################################################################################
ll max(ll a,ll b, ll c)
{
  if (a<b) {
    /* code */
    return max(b,c);
  }
  else
  {
      return min(a,c);
  }

}
//###########################################################################################
ll min(ll a,int b)
{
  if (a<b) return a;
  return b;
}
//###########################################################################################
ll min(int a,ll b)
{
  if (a<b) return a;
  return b;
}
//###########################################################################################
ll max(ll a,int b)
{
  if (a>b) return a;
  return b;
}
//###########################################################################################
ll max(int a,ll b)
{
  if (a>b) return a;
  return b;
}
//###########################################################################################
ll gcd(ll a,ll b)
{
  if (b==0) return a;
  return gcd(b,a%b);
}
//###########################################################################################
ll lcm(ll a,ll b)
{
  return a/gcd(a,b)*b;
}
//###########################################################################################
void yes()
{
  cout<<"YES"<<"\n";
}
//###########################################################################################
void no()
{
  cout<<"NO"<<"\n";
}
//###########################################################################################
int main()
{
  fast
//  clock_t launch=clock();
  // string r = s1.substr(1, 3);
  //while(clock()<CLOCKS_PER_SEC*10)
  //using num = modnum<int(1e9)+7>;
 //num len = s.size();
  ll n,k,ans=0,flag=0,temp=0,f1=0,count=0,f2=0,sum=0,xx=0,minn1=big,minn2=big,maxx1=small,maxx2=small;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  if (a>0 && c>0  ) {
    /* code */
    c-=b;
    a-=d;
  }
  for (ll i = 0; a>0 && c>0; i++) {
    /* code */
    if (i%2==0) {
      /* code */
      c-=b;

    }
    else
    {
      a-=d;
    }
  }
  if (c<=0) {
    /* code */
    p1("Yes")
  }
  else
  {
    p1("No")
  }

  //clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
  return 0;
}
//////////*********************end of program*********************//////////


#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  string s;
  cin >> s;

  map<int, int> mods;
  mods[0] = 1;

  REP(i,s.size()){
    // string->lint
    string tmp = s.substr(s.size()-(i+1), s.size());
    istringstream ss = istringstream(tmp);
    lint num;
    ss >> num;
    //cout << num << "\n";
    mods[num%2019]++;
  }

  lint sum = 0;
  auto itr = begin(mods);
  while(itr != end(mods)){
    sum += (*itr).second/2*((*itr).second-1);
    itr++;
  }

  cout << sum << "\n";
  return 0;
}

Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

char od[200020];
char buf[200020];

void keta(int idx, int adv)
{
  while(adv>0){
    int tmp = adv % 10;
    buf[idx] += tmp;
    adv /= 10;
    if( buf[idx] >= 10 ){
      adv += (buf[idx] / 10);
      buf[idx] = (buf[idx] % 10);
    }
    idx--;
  }
}

/*
void pketa(int idx)
{
  for(int i=0;i<idx;i++){
    cout << (int)(buf[i]);
  }
  cout<<endl;
}
*/

int main()
{
  int n;
  string s;

  cin >> s;
  n = 0;
  for(int i=0;i<s.length();i++){
    od[i] = s[i] - '0';
    if( '1'<=s[i] && s[i]<='9' ) n++;
  }

  /*
  for(int i=0;i<n;i++){
    cout << i << ":" << (int)(od[i]) << endl;
  }
  */

  ll rui[n+1];
  rui[0] = 0;
  for(int i=0;i<n;i++){
    rui[i+1] = rui[i] + od[i];
  }

  ll total = 0;
  for(int i=n-1;i>=3;i--){
    memset(buf,0,10);
    memcpy(buf+10,od,i+1);
    for(int j=i-3;j>=0;j--){
      ll tri = rui[i+1] - rui[j+1-1];
      int tmp = 1000 * (int)(buf[10+j]) + 100 * (int)(buf[11+j]) + 10 * (int)(buf[12+j]) + (int)buf[13+j];
      // cout << j << ":" << i << ":" << tri << ":" << tmp << endl;

      if( ( tri % 3 == 0 ) && ( tmp % 673 == 0 ) ){
        total ++;
      }
      tmp = 202 * buf[10+j+3];
      keta(10+j+2,tmp);
      // pketa(10+j+2);
    }
  }

  cout << total << endl;
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string s;
  ll tmp, cnt = 0, N, u, t = 18;
  cin >> s;
  N = s.size();
  // 2019の倍数を文字列でくっつけていく
  for(int i = 4; i <= N; i++){
    for(int j = 0; j <= N - i; j++){
      if (i < t) {
        tmp = stoll(s.substr(j, i)); // longlongで足りなくなったらREになる
        if(tmp % 2019 == 0) cnt++;
      } else { // stollが死ぬ場合
        tmp = stoll(s.substr(j, t));
        // cout << i << " " << tmp << endl;
        u = tmp % 2019;
        for(int k = j + t; k < j + i; k++){
          tmp = stoll(s.substr(k, 1));
          // print(tmp);
          u += 10*u + tmp;
          u %= 2019;
        }
        if(u == 0) cnt++;
      }

    }
  }
  cout << cnt << endl;
}


#include <iostream>
#include <string>

using namespace std;

int main(void){
  string number;
  int num = 2019;
  int cnt = 0;

  cin >> number;

  while(num <= 200000){
    int pos = number.find(to_string(num));
    if(pos != string::npos){
      cnt++;
      string substr = number;
      while(true){
        substr = substr.substr(pos+1);
        if((pos = substr.find(to_string(num))) == string::npos) break;
        else cnt++;
      }
    }
    num += 2019;
  }

  cout << cnt << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    unsigned long long n = (unsigned long long)s.length();
    string judge;
    unsigned long long cnt = 0;
    for(unsigned long long i = 0; i < n - 1; i++){
        for(unsigned long long j = i + 1; j < n; j++){
            judge = s.substr(i,j-i+1);
            if((stoull(judge)) % 2019 == 0){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	int n;
	stringstream ss(s);
	ss >> n;
	if (n < 2019) {
		cout << 0 << '\n';
		return 0;
	}
	if (n == 2019) {
		cout << 1 << '\n';
	}
	int i = 0, j = s.size();
	int cnt = 0;
	for (int i = 0; i < s.size() - 2; ++i) {
		for (int j = s.size(); j > i + 3; --j ) {
			// cout << i << ' ' << j << '\n';
			// cout << s.substr(i, j - i) << '\n';
			stringstream sss(s.substr(i, j - i));
			sss >> n;
			if (!(n % 2019)) cnt++;
		}
	}
	cout << cnt << '\n';
	return 0;
}


#include <cstdio>
#include <cstring>
typedef long long lld;
const int BASE = 10;
const int MAXS = 2e5+5;
const int MOD = 2019;
int cnt[MOD];
char S[MAXS];
int ten[MAXS];
int N;

int main() {
  scanf(" %s", S+1);
  N = strlen(S+1);

  ten[0] = 1;
  for (int i = 1; i <= N; ++i) {
    ten[i] = 1LL * BASE * ten[i-1] % MOD;
  }

  for (int i = 0; i < MOD; ++i) {
    cnt[i] = 0;
  }
  cnt[0] = 1;

  lld ret = 0LL;
  int A = 0;
  for (int i = 1; i <= N; ++i) {
    A = (1LL * BASE * A + (S[i] - '0')) % MOD;

    int key = 1LL * ten[N-i] * A % MOD;
    ret += cnt[key];
    ++cnt[key];
  }
  printf("%lld\n", ret);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

ll table[200010];
ll A[200010];

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    reverse(ALL(S));
    table[0] = 1;
    FOR(i,1,200010){
        table[i] = (table[i-1] * 10) % 2019;
    }
    rep(i,N){
        A[i+1] = ((S[i] - '0') * table[i] + A[i]) % 2019;
    }
    map<ll,ll> mp;
    ll ans = 0;
    rep(i,N+1){
        if(i != 0){
            if(S[i-1] != '0'){
                ans += mp[A[i]];
            }
        }else{
            ans += mp[A[i]];
        }
        mp[A[i]]++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back

#define sec second
#define fir first
#define mo  998244353
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii\
  ios_base::sync_with_stdio(false);\
  cin.tie(NULL);\
  cout.tie(NULL);

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	ll n,m,s;
	cin>>n>>m>>s;
	s = min(s,(ll)2501);
	vector<pair<ll,pair<ll,ll>>> adj[n+1];
	rep(i,0,m){
		ll u,v,a,b;
		cin>>u>>v>>a>>b;
		adj[u].pb({v,{a,b}});
		adj[v].pb({u,{a,b}});
	}
    vector <ll> c(n+1),d(n+1);
    rep(i,1,n+1) cin>>c[i]>>d[i];

    ll time[n+1][2501];
    rep(i,1,n+1) rep(j,0,2501) time[i][j] = inf;
    time[1][s] = 0;
    using P = pair<ll,ll>;
    priority_queue<pair<ll,P> , vector<pair<ll,P>>, greater<pair<ll,P>>>pq;
    pq.push({0,{1,s}});
	while(!pq.empty()){
		ll u = pq.top().second.first;
		ll cs = pq.top().second.second;
		ll du = pq.top().first;
		//cout<<u<<" "<<cs<<endl;
		pq.pop();
		if(time[u][cs] != du) continue;
		if(time[u][cs] + d[u] < time[u][min(cs+c[u],(ll)2500)]){
			time[u][min(cs + c[u],(ll)2500)] = time[u][cs] + d[u];
			pq.push({time[u][cs] + d[u],{u,min(cs + c[u],(ll)2500)}});
		}
		for(auto vp:adj[u]){
		    ll v = vp.first;
		    ll tn =  vp.second.second;
		    ll cr = vp.second.first;
		    if(cr > cs) continue;
		    if(time[v][cs - cr] > time[u][cs] + tn){
				//cout<<v<<" "<<cs - cr<<endl;
				time[v][cs - cr] = time[u][cs] + tn;
				pq.push({time[v][cs-cr],{v,cs-cr}});
			}
		}
	}
	rep(i,2,n+1){
		ll ans = inf;
		rep(j,0,2501){
		  ans = min(ans,time[i][j]);
		}
		cout<<ans<<endl;
	}

}

Score : 500 points

Problem Statement

There are N cities numbered 1 to N, connected by M railroads.

You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.

The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins and takes B_i minutes.
You cannot use gold coins to pay the fare.

There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin.
The transaction takes D_i minutes for each gold coin you give.
You can exchange any number of gold coins at each exchange counter.

For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq 100

0 \leq S \leq 10^9

1 \leq A_i \leq 50

1 \leq B_i,C_i,D_i \leq 10^9

1 \leq U_i < V_i \leq N

There is no pair i, j(i \neq j) such that (U_i,V_i)=(U_j,V_j).

Each city t=2,...,N can be reached from City 1 with some number of railroads.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M S
U_1 V_1 A_1 B_1
:
U_M V_M A_M B_M
C_1 D_1
:
C_N D_N

Output

For each t=2, ..., N in this order, print a line containing the minimum time needed to travel from City 1 to City t.

Sample Input 1

3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5

Sample Output 1

2
14

The railway network in this input is shown in the figure below.

In this figure, each city is labeled as follows:

The first line: the ID number i of the city (i for City i)

The second line: C_i / D_i

Similarly, each railroad is labeled as follows:

The first line: the ID number i of the railroad (i for the i-th railroad in input)

The second line: A_i / B_i

You can travel from City 1 to City 2 in 2 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

You can travel from City 1 to City 3 in 14 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 6 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Sample Input 2

4 4 1
1 2 1 5
1 3 4 4
2 4 2 2
3 4 1 1
3 1
3 1
5 2
6 4

Sample Output 2

5
5
7

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 4 in 7 minutes, as follows:

At the exchange counter in City 1, exchange 2 gold coins for 6 silver coins in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Use the 4-th railroad to move from City 3 to City 4 in 1 minutes.

Sample Input 3

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1

Sample Output 3

1
9003
14606
16510
16576

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 6 in 16576 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 9000 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

At the exchange counter in City 3, exchange 8 gold coins for 8 silver coins in 5600 minutes.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

Use the 3-rd railroad to move from City 2 to City 4 in 1 minute.

At the exchange counter in City 4, exchange 19 gold coins for 19 silver coins in 1900 minutes.

Use the 3-rd railroad to move from City 4 to City 2 in 1 minute.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

Use the 4-th railroad to move from City 3 to City 5 in 1 minute.

At the exchange counter in City 5, exchange 63 gold coins for 63 silver coins in 63 minutes.

Use the 4-th railroad to move from City 5 to City 3 in 1 minute.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 5-th railroad to move from City 1 to City 6 in 1 minute.

Sample Input 4

4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7

Sample Output 4

1
3
5

The railway network in this input is shown in the figure below:

Sample Input 5

2 1 0
1 2 1 1
1 1000000000
1 1

Sample Output 5

1000000001

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 2 in 1000000001 minutes, as follows:

At the exchange counter in City 1, exchange 1 gold coin for 1 silver coin in 1000000000 minutes.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.


#include <bits/stdc++.h>
using namespace std;

template <typename T>
class Graph
{
    void _dfs_toporogical_sort(vector<bool> &visited, const long long n, list<long long> &ret) const
    {
        if (visited[n])
        {
            return;
        }
        visited[n] = true;
        for (auto e : this->edge[n])
        {
            _dfs_toporogical_sort(visited, e.to, ret);
        }
        ret.push_front(n);
    }

    void set_node(const long long N)
    {
        this->node = N + 1;
    }

public:
    struct Edge
    {
        long long to;
        T distance;
        Edge(const long long t, const T d)
        {
            this->to = t;
            this->distance = d;
        }
        bool operator<(const Graph<T>::Edge &e) const
        {
            return this->distance < e.distance;
        }
        bool operator<=(const Graph<T>::Edge &e) const
        {
            return this->distance <= e.distance;
        }
        bool operator>(const Graph<T>::Edge &e) const
        {
            return this->distance > e.distance;
        }
        bool operator>=(const Graph<T>::Edge &e) const
        {
            return this->distance >= e.distance;
        }
        bool operator==(const Graph<T>::Edge &e) const
        {
            return this->distance == e.distance;
        }
    };
    class UnionFind
    {
    public:
        vector<long long> root;

        UnionFind(const long long N)
        {
            this->root = vector<long long>(N + 1, -1);
        }

        long long find_root(const long long A)
        {
            if (this->root[A] < 0)
            {
                return A;
            }
            else
            {
                this->root[A] = find_root(this->root[A]);
            }
            return this->root[A];
        }

        long long size(const long long A)
        {
            return -this->root[find_root(A)];
        }

        bool unite(long long A, long long B)
        {
            A = find_root(A);
            B = find_root(B);
            if (A == B)
            {
                return false;
            }

            if (size(A) < size(B))
            {
                swap(A, B);
            }

            this->root[A] += this->root[B];
            this->root[B] = A;

            return true;
        }

        bool has_same_root(const long long A, const long long B)
        {
            return find_root(A) == find_root(B);
        }
    };
    vector<vector<T>> adjacency_matrix;
    long long node;
    T initial_value;
    vector<vector<Graph<T>::Edge>> edge;

    Graph(const long long N)
    {
        this->set_node(N);
        this->initialize_edge_vector();
    }

    Graph(const long long N, const T init)
    {
        this->set_node(N);
        this->initialize_edge_vector();
        this->set_initial_value(init);
    }

    void set_initial_value(const T init)
    {
        this->initial_value = init;
    }

    void initialize_adjacency_matrix()
    {
        this->adjacency_matrix = vector<vector<T>>(
            this->node, vector<T>(this->node, this->initial_value));
    }

    void initialize_adjacency_matrix(const T init)
    {
        this->set_initial_value(init);
        this->initialize_adjacency_matrix();
    }

    void initialize_edge_vector()
    {
        this->edge = vector<vector<Graph<T>::Edge>>(this->node);
    }

    void update_adjacency_matrix(const long long from, const long long to, const T distance = 1)
    {
        this->adjacency_matrix[from][to] = distance;
    }

    void add_edge(const long long from, const long long to, const T distance = 1)
    {
        this->edge[from].push_back({to, distance});
    }

    // O(V^3)
    // CAUTION: Use adjacency matrix
    vector<vector<T>> run_floyd_warshall() const
    {
        vector<vector<T>> ret(this->adjacency_matrix);
        for (long long i = 0; i < this->node; i++)
        {
            for (long long j = 0; j < this->node; j++)
            {
                for (long long k = 0; k < this->node; k++)
                {
                    ret[j][k] = min(ret[j][k], ret[j][i] + ret[i][k]);
                }
            }
        }
        return ret;
    }

    // O(E)
    // CAUTION: Non-weighted only
    // CAUTION: Use edge vector
    vector<T> run_bfs(const long long from) const
    {
        vector<T> distance(this->node, this->initial_value);
        vector<bool> visited(this->node, false);
        queue<long long> q;
        q.push(from);
        for (long long i = 0; i < this->node && !q.empty(); i++)
        {
            queue<long long> tmp;
            while (!q.empty())
            {
                if (visited[q.front()])
                {
                    q.pop();
                    continue;
                }
                distance[q.front()] = i;
                visited[q.front()] = true;
                for (Graph<T>::Edge e : this->edge[q.front()])
                {
                    if (visited[e.to])
                    {
                        continue;
                    }
                    tmp.push(e.to);
                }
                q.pop();
            }
            q = tmp;
        }
        return distance;
    }

    // O(VE)
    // CAUTION: Use edge vector
    vector<T> run_bellman_ford(const long long from) const
    {
        vector<T> distance(this->node, this->initial_value);
        distance[from] = 0;

        for (long long i = 0; i < this->node - 1; i++)
        {
            for (long long j = 0; j < this->node; j++)
            {
                for (Graph<T>::Edge e : this->edge[j])
                {
                    if (distance[e.to] > distance[j] + e.distance)
                    {
                        distance[e.to] = distance[j] + e.distance;
                    }
                }
            }
        }
        return distance;
    }

    // O(E + VlogV)
    // CAUTION: Use edge vector
    // CAUTION: Node-indices must be [1, N]
    vector<T> run_dijkstra(const long long from) const
    {
        vector<T> distance(this->node, this->initial_value);
        priority_queue<Graph<T>::Edge, vector<Graph<T>::Edge>, greater<Graph<T>::Edge>> queue;
        queue.push(Graph<T>::Edge(from, 0));
        for (long long i = 1; i < this->node && !queue.empty(); i++)
        {
            T d = queue.top().distance;
            long long to = queue.top().to;
            queue.pop();
            if (distance[to] == this->initial_value)
            {
                distance[to] = d;
                for (Graph<T>::Edge e : this->edge[to])
                {
                    if (distance[e.to] == this->initial_value)
                    {
                        queue.push({e.to, e.distance + d});
                    }
                }
            }
            else
            {
                i--;
            }
        }
        return distance;
    }

    // O(ElogV)
    // CAUTION: Use edge vector
    // CAUTION: Node-indices must be [1, N]
    T run_prim() const
    {
        vector<bool> is_visited(this->node, false);
        T cost = 0;
        priority_queue<Graph<T>::Edge, vector<Graph<T>::Edge>, greater<Graph<T>::Edge>> queue;
        queue.push(Graph<T>::Edge(1, 0));
        for (long long i = 1; i < this->node && !queue.empty(); i++)
        {
            T distance = queue.top().distance;
            long long to = queue.top().to;
            queue.pop();
            if (is_visited[to])
            {
                i--;
            }
            else
            {
                cost += distance;
                is_visited[to] = true;
                for (Graph<T>::Edge e : this->edge[to])
                {
                    queue.push({e.to, e.distance});
                }
            }
        }
        return cost;
    }

    // O(ElogV)
    // CAUTION: Use edge vector
    T run_kruskal() const
    {
        T cost = 0;
        vector<pair<Graph<T>::Edge, long long>> edge_from;
        for (long long i = 0; i < this->node; i++)
        {
            for (auto e : this->edge[i])
            {
                edge_from.push_back(make_pair(e, i));
            }
        }
        sort(edge_from.begin(), edge_from.end());

        Graph<T>::UnionFind uf(this->node);
        for (pair<Graph<T>::Edge, long long> e_f : edge_from)
        {
            auto e = e_f.first;
            long long from = e_f.second;
            if (!uf.has_same_root(from, e.to))
            {
                uf.unite(from, e.to);
                cost += e.distance;
            }
        }
        return cost;
    }

    // O(V)
    // CAUTION: Without cycle only
    // CAUTION: Use edge vector
    vector<long long> run_toporogical_sort() const
    {
        list<long long> ret_list;
        vector<bool> visited(this->node, false);
        for (long long i = 0; i < this->node; i++)
        {
            _dfs_toporogical_sort(visited, i, ret_list);
        }

        vector<long long> ret(ret_list.begin(), ret_list.end());
        return ret;
    }
};

int main()
{
    constexpr long long MAX_SILVER = 50 * 50;
    long long N, M, S;
    cin >> N >> M >> S;
    S = min(S, MAX_SILVER - 1);

    Graph<pair<long long, long long>> g(N);
    long long U, V, A, B;
    for (long long i = 0; i < M; i++)
    {
        cin >> U >> V >> A >> B;
        g.add_edge(U, V, make_pair(-A, B));
        g.add_edge(V, U, make_pair(-A, B));
    }

    long long C, D;
    for (long long i = 1; i <= N; i++)
    {
        cin >> C >> D;
        g.add_edge(i, i, make_pair(C, D));
    }

    long long init = LONG_LONG_MAX;
    vector<vector<long long>> ans(N + 1, vector<long long>(MAX_SILVER, init));
    priority_queue<pair<long long, pair<long long, long long>>, vector<pair<long long, pair<long long, long long>>>, greater<pair<long long, pair<long long, long long>>>> q;
    q.push(make_pair(0, make_pair(1, S)));
    for (long long i = 0; i < (N * MAX_SILVER) && !q.empty(); i++)
    {
        long long distance = q.top().first;
        long long to = q.top().second.first;
        long long silver = q.top().second.second;
        q.pop();

        if (ans[to][silver] == init)
        {
            ans[to][silver] = distance;

            for (auto e : g.edge[to])
            {
                long long next_silver = silver + e.distance.first;
                long long next_distance = distance + e.distance.second;
                if (next_silver < 0)
                {
                    continue;
                }
                if (next_silver >= MAX_SILVER)
                {
                    continue;
                }
                q.push(make_pair(next_distance, make_pair(e.to, next_silver)));
            }
        }
    }
    for (long long i = 2; i <= N; i++)
    {
        long long a = init;
        for (long long j = 0; j < MAX_SILVER; j++)
        {
            a = min(a, ans[i][j]);
        }
        cout << a << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M, S;
int U[110], V[110], A[110], B[110];
int C[55], D[55];
int dp[55][5500];
signed main() {
    cin >> N >> M >> S;
    reps(i, M) { cin >> U[i] >> V[i] >> A[i] >> B[i]; }
    reps(i, N) { cin >> C[i] >> D[i]; }
    rep(i, 55)rep(j, 5500) { dp[i][j] = LLONG_MAX; }
    dp[1][min(S, 5499LL)] = 0;
    reps(i, 2 * M) {
        reps(j, N)rep(k, 5500) { if (dp[j][k] < LLONG_MAX) { chmin(dp[j][min(k + C[j], 5499LL)], dp[j][k] + D[j]); }}
        reps(j, M) {
            for (int k = A[j]; k < 5500; k++) {
                if (dp[V[j]][k] < LLONG_MAX) { chmin(dp[U[j]][k - A[j]], dp[V[j]][k] + B[j]); }
                if (dp[U[j]][k] < LLONG_MAX) { chmin(dp[V[j]][k - A[j]], dp[U[j]][k] + B[j]); }
            }
        }
    }
    for (int i = 2; i <= N; i++) {
        int ans = LLONG_MAX;
        rep(j, 5500) { chmin(ans, dp[i][j]); }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    double a;
    cin>>a;
    cout<< a *3.1415*2<<endl;
}

Score : 100 points

Problem Statement

Print the circumference of a circle of radius R.

Constraints

1 \leq R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R

Output

Print the circumference of the circle.
Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

Sample Input 1

1

Sample Output 1

6.28318530717958623200

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

Sample Input 2

73

Sample Output 2

458.67252742410977361942


#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}

int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string s,t,r;
  cin >> n;

  cout << 2*n*M_PI << endl;
  return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
int r;
  cin>>r;
  double c=2*3.14159*r;
  cout<<c<<"\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double r;cin>>r;
    cout << fixed << setprecision(5);
    cout<<2*M_PI*r<<endl;
    return 0;
}


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

int main(){
    int r;
    cin >> r;
    cout << 2*r*3.14 << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int r;
	cin>>r;
	double ans, PI = 3.141592653589793238;
	ans = 2*PI*r;
	cout<<ans;
}


#include <iostream>
using namespace std;

int main(){
  float r;
  cin >> r;
  cout << 2 * r * 3.141592 << '\n';
  return 0;
}


/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    double r;
    cin>>r;
    r = 2*PI*r;
    printf("%.9lf\n",r);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,a,b) for(int i=a;i<b;i++)

using namespace std;

void test(){
	double x;
	cin>>x;
	x = 2*x;
	x = x*(3.14159);
	cout<<x<<"\n";
}

int main(){
	int t=1;
//	cin>>t;
	while(t--){
		test();
	}
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  double R; cin >> R;
  double result = R * 2 * M_PI;
  cout << setprecision(10) << result << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// 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;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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(){
    long long R;
    scanf("%lld",&R);
    // long long M;
    // scanf("%lld",&M);
    // std::vector<long long> A(M);
    // for(int i = 0 ; i < M ; i++){
    //     scanf("%lld",&A[i]);
    // }
    //solve(N, M, std::move(A));
    cout << 2*R*PI << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    double r;
    cin >> r;

    cout << 3.1415 * r * 2.0 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
const int N=1e5+5;
const int p=1e9+7;
#define PI acos(-1)
ll qpow(ll a,ll n){ll res=1;while(n){if(n&1)res=res*a%p;a=a*a%p;n>>=1;}return res;}
void work()
{
    int n;
    scanf("%d",&n);
    printf("%.5f\n",n*2*PI);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    //scanf("%d",&T);
    //cin>>T;
    while(T--){
        work();
    }
}


#include <iostream>

using namespace std;

int main()
{
    int N;
    bool seven = false;

    cin >> N;

    for (int i = 0; i < 3; i++)
    {
        if (N % 10 == 7)
        {
            seven = true;
        }
        N /= 10;
    }
    if (seven)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes


#include <bits/stdc++.h>
using namespace std;
int main() {
  string A;
  cin >> A;
  if(A.at(0) == '7') {
    cout << "Yes" << endl;
  }
  else if(A.at(1) == '7') {
    cout << "Yes" << endl;
  }
  else if(A.at(2) == '7') {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main(){
  string s;
  cin >> s;
  if(s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7') cout << "Yes" << endl;
  else cout << "No" << endl;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main()
{

    long long ai,t,n,a,A,sum=0,b,B,c=0,k,e,f,g;

    cin >> a ;

    while( a != 0)
    {
        b=a%10;

        if(b == 7)
        {
            cout << "Yes";
            return 0;
        }

        a=a/10;

    }
    cout << "No";

return 0;
}


#include <bits/stdc++.h>
//typedef
//-------------------------#include <bits/stdc++.h>

const double pi = 3.141592653589793238462643383279;

using namespace std;

template<typename T=int>inline T readT() {
  char c = getchar_unlocked(); bool neg = (c=='-');
  T res = neg?0:c-'0';
  while(isdigit(c=getchar_unlocked())) res = res*10 + c-'0';
  return neg?-res:res;
}
template<typename T=int>inline void writeT(T x, char c='\n'){
  int d[20],i=0; if(x<0)putchar_unlocked('-'),x*=-1;
  do{d[i++]=x%10;}while(x/=10); while(i--)putchar_unlocked('0'+d[i]);
  putchar_unlocked(c);
}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

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

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

class UnionFind {
public:
    vector <int> par;
    vector <int> siz;

    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }

    int root(int x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;

        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}

#define SIEVE_SIZE 5000000+10
bool sieve[SIEVE_SIZE];
void makeSieve(){
    for(int i=0; i<SIEVE_SIZE; ++i) sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for(int i=2; i*i<SIEVE_SIZE; ++i) if(sieve[i]) for(int j=2; i*j<SIEVE_SIZE; ++j) sieve[i*j] = false;
}

bool isprime(ll n){
    if(n == 0 || n == 1) return false;
    for(ll i=2; i*i<=n; ++i) if(n%i==0) return false;
    return true;
}

const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
// 負の数にも対応した mod (a = -11 とかでも OK)
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}
ll GCD(ll a, ll b){

    if(b == 0) return a;
    return GCD(b, a%b);
}

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A, mat &B) {
    mat C(A.size(), vec((int)B[0].size()));
    for(int i=0; i<A.size(); ++i){
        for(int k=0; k<B.size(); ++k){
            for(int j=0; j<B[0].size(); ++j){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] %MOD) % MOD;
            }
        }
    }
    return C;
}
mat matPow(mat A, ll n) {
    mat B(A.size(), vec((int)A.size()));

    for(int i=0; i<A.size(); ++i){
        B[i][i] = 1;
    }

    while(n > 0) {
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

map<ll,ll> prime_factor(ll n) {
  map<ll,ll> res;
  for(ll i=2; i*i <= n; i++) {
      while(n%i == 0) {
          res[i]++;
          n /= i;
      }
  }

  if(n != 1) res[n] = 1;
  return res;
}
using Point = complex<double>;

istream &operator>>(istream &is, Point &p)
{
    double a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}

ostream &operator<<(ostream &os, Point &p)
{
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

const double  PI = acos(-1);
inline bool eq(double a, double b) { return fabs(b - a) < EPS; }

//二つのスカラーが等しいか
#define EQ(a, b) (abs((a) - (b)) < EPS)
//二つのベクトルが等しいか
#define EQV(a, b) (EQ((a), real(), (b).real()) && EQ((a), imag(), (b).imag()))

namespace std
{
bool operator<(const Point &a, const Point &b)
{
    return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}
} // namespace std

struct Line
{
    Point a, b;
    Line() {}
    Line(Point a, Point b) : a(a), b(b) {}
    //a, bはそれぞれ座標を指す. これより一つの「line」に対して二個の点を持つことになる
    Line(double A, double B, double C) // Ax + By = C
    {
        if (eq(A, 0))
            a = Point(0, C / B), b = Point(1, C / B);
        else if (eq(B, 0))
            b = Point(C / A, 0), b = Point(C / A, 1);
        else
            a = Point(0, C / B), b = Point(C / A, 0);
    }

    friend ostream &operator<<(ostream &os, Line &p)
    {
        return os << p.a << " to " << p.b;
    }

    friend istream &operator>>(istream &is, Line &a)
    {
        return is >> a.a >> a.b;
    }
};

struct Segment : Line
{
    Segment() {}

    Segment(Point a, Point b) : Line(a, b) {}
};

double dot(const Point a, const Point b)
{
    return real(a) * real(b) + imag(a) * imag(b);
}

double cross(const Point a, const Point b)
{
    return real(a) * imag(b) - imag(a) * real(b);
}
int ccw(const Point &a, Point b, Point c)
{
    b = b - a, c = c - a;
    if (cross(b, c) > EPS)
        return +1; // "COUNTER_CLOCKWISE"
    if (cross(b, c) < -EPS)
        return -1; // "CLOCKWISE"
    if (dot(b, c) < 0)
        return +2; // "ONLINE_BACK"
    if (norm(b) < norm(c))
        return -2; // "ONLINE_FRONT"
    return 0;      // "ON_SEGMENT"
}

bool parallel(const Line &a, const Line &b)
{
    return abs(cross(a.b - a.a, b.b - b.a)) < EPS;
}

bool orthogonal(const Line &a, const Line &b)
{
    return abs(dot(a.a - a.b, b.a - b.b)) < EPS;
}

Point projection(const Line &l, const Point &p)
{
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}

Point projection(const Segment &l, const Point &p)
{
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}

Point reflection(const Line &l, const Point &p)
{
    return p + (projection(l, p) - p) * 2.0;
}

bool Intersect(const Line &l, const Point &p)
{
    return abs(ccw(l.a, l.b, p)) != 1;
}

bool intersect(const Line &l, const Line &m)
{
    return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}

bool intersect(const Segment &s, const Point &p)
{
    return ccw(s.a, s.b, p) == 0;
}

bool intersect(const Line &l, const Segment &s)
{
    return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}

bool intersect(const Segment &s, const Segment &t)
{
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

Point crosspoint(const Line &l, const Line &m)
{
    double A = cross(l.b - l.a, m.b - m.a);
    double B = cross(l.b - l.a, l.b - m.a);
    if (abs(A) < EPS && abs(B) < EPS)
        return m.a;
    return m.a + (m.b - m.a) * B / A;
}

Point crosspoint(const Segment &l, const Segment &m)
{
    double A = cross(l.b - l.a, m.b - m.a);
    double B = cross(l.b - l.a, l.b - m.a);
    if (abs(A) < EPS && abs(B) < EPS)
        return m.a;
    return m.a + (m.b - m.a) * B / A;
}

double distance(const Point &a, const Point &b)
{
    return abs(a - b);
}

double distance(const Line &l, const Point &p)
{
    return abs(p - projection(l, p));
}

double distance(const Line &l, const Line &m)
{
    return intersect(l, m) ? 0 : distance(l, m.a);
}

double distance(const Segment &s, const Point &p)
{
    Point r = projection(s, p);
    if (intersect(s, r))
        return abs(r - p);
    return min(abs(s.a - p), abs(s.b - p));
}

double distance(const Segment &a, const Segment &b)
{
    if (intersect(a, b))
        return 0;
    return min({distance(a, b.a), distance(a, b.b), distance(b, a.a), distance(b, a.b)});
}

double distance(const Line &l, const Segment &s)
{
    if (intersect(l, s))
        return 0;
    return min(distance(l, s.a), distance(l, s.b));
}

using ld= long double;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(18);

    int n; cin >> n;
    if(n%10 == 7 || (n/10)%10 == 7 || (n/100)%10  == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    /* code */
    string N;
    cin >> N;
    string res="No";
    for(int i=0;i<3;i++){
        if(N[i]==7)res="Yes";
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include<string>
#define FOR(x, u) for (int x = 0; x < u; x++)
typedef long long ll;
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int flag=1,i;
    FOR(i,3)
    {
        if(s[i]=='7')
        {
            flag=0;
            cout<<"YES";
            break;
        }
    }
    if(flag)
        cout<<"NO";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
        cout << "\n";
    }
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
/*int main()
{
    char s[4];
    cin>>s;
    if((s[0]=='7')|| (s[1]=='7') || (s[2]=='7'))
    {
         cout<<"YES";
    }
    else{
         cout<<"NO";
    }*/
int main()
{
    char s[4];
    scanf("%s",s);
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')
        puts("Yes");
    else
        puts("No");
}


#include <iostream>

using namespace std;

int main() {

  char ch;
  while(cin >> ch){
    if(ch == '7'){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;;
int main(){
    string ptr;
    cin>>ptr;
    if(ptr.find("7")!=-1){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A = N % 10;
    int B = (N - A) % 100;
    int C = N - B - A;
    if (A == 7 || B == 70 || C == 700){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


#include <iostream>
#include <climits>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
	string N;
	cin >> N;
	for (int i = 0; i < 3; i++) {
		if (N[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    string s;cin>>s;
    if(s.find('7')!=string::npos)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    bool ok=false;
    rep(i,s.size()){
        if(s[i]=='7')ok=true;
    }
    cout<<(ok==true?"Yes":"No")<<endl;
}


#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N = 0;
    cin>>N;
    while(N > 1){
        int re = N % 10;
        if(re == 7){
            cout<<"Yes"<<endl;
            return 0;
        }
        N = N / 10;
    }
    cout<<"No"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	if (to_string(n).find("7") != -1) cout << "Yes";
	else cout << "No";
}


#include <bits/stdc++.h>
using namespace std;

struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
#define rep(i, n) for(int i = 0; i < n; ++i)

const int INF = 1e9 + 7;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // vvvi V (50, vvi(50, vi(2500)));

    string s;
    cin >> s;
    rep(i, s.length()){
        if(s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


#include <iostream>
using namespace std;

long long gcd1(long long a, long long b)
{
    if(b == 0) return a;
    return gcd1(b, a%b);
}

long long gcd(long long a, long long b, long long c)
{
    return gcd1(a,gcd1(b,c));
}

int main()
{
    long long k;
    cin >> k;

    long long sum = 0;
    for(long long a = 1; a <= k; ++a)
    {
        for(long long b = 1; b <= k; ++b)
        {
            for(long long c = 1; c <= k; ++c)
            {
                sum += gcd(a,b,c);
            }
        }
    }

    cout << sum << endl;
}

Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int,int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn=5e4+10;
const int maxm=1.5e7+10;
const int mod=998244353;
using namespace std;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int ans=0;
    for(int i=1;i<=a;i++)
        for(int j=1;j<=b;j++)
            for(int k=1;k<=c;k++)
                ans+=__gcd(i,__gcd(j,k));
    printf("%d",ans);
    // system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int gcd1(int m,int n){
	if(m%n==0) return n;
	return gcd1(n,m%n);
}
int gcd(int a,int b,int c){
	return gcd1(gcd1(a,b),c);
}
int main(){
	int k,sum=0;
	scanf("%d",&k);
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int x=1;x<=k;x++){
				sum+=gcd(i,j,x);
			}
		}
	}
	printf("%d",sum);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int K; cin >> K;
  long x = 0;
  for(int i = 1; i <= K; i++) {
    for(int j = 1; j <= K; j++) {
      for(int k = 1; k <= K; k++) {
        x += __gcd(__gcd(i, j), k);
      }
    }
  }
  cout << x << endl;
}


#include <bits/stdc++.h>
using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	long long ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 1; k <= n; k++)
				ans += (__gcd(i, __gcd(j, k)));
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int gcd(int x,int y){
  if(y==0)return x;
  if(x<=y) swap(x,y);
  if(x%y==0) return y;
  else return(gcd(y,x%y));//最大公約数
}

int main(){
    int k;
    cin >> k;
    int ans = 0;
    for(int i=1;i<k+1;i++){
        for(int j=1;j<k+1;j++){
            for(int p=1;p<k+1;p++){
                ans += gcd(i,gcd(j,p));
            }
        }
    }
    COUT(ans);
    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

const int maxn=500005;
typedef long long ll;

int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

int n;
int sum;

int gcd(int x, int y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				sum+=gcd(i,gcd(j,k));
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

// GCD, LCM
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 main(){
  int k;
  cin>>k;
  ll ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans+=gcd(gcd(i,j),l);
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll k;
     cin >> k;
     ll sum = 0;
     for (ll i = 1; i <= k; i++)
     {
          for (ll j = 1; j <= k; j++)
          {
               for (ll l = 1; l <= k; l++)
               {
                    sum += __gcd(__gcd(i, j), l);
               }
          }
     }
     cout << sum << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,A=0;cin>>N;
  string S;cin>>S;
  vector<int> R(0),G(0),B(0);
  for(int i=0;i<N;i++){
    if (S.at(i)=='R'){
      R.push_back(i);
    }
    if (S.at(i)=='G'){
      G.push_back(i);
    }
    if (S.at(i)=='B'){
      B.push_back(i);
    }
  }
  for(int r=0;r<R.size();r++){
    for(int g=0;g<G.size();g++){
      for(int b=0;b<B.size();b++){
        if((R.at(r)+G.at(g)!=2*B.at(b)) &&
           (G.at(g)+B.at(b)!=2*R.at(r)) &&
           (B.at(b)+R.at(r)!=2*G.at(g)) ){
          A++;
        //  cout<<R.at(r)<<" "<<G.at(g)<<" "<<B.at(b)<<endl;
        }
      }
    }
  }
  cout << A <<endl;
}

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    string s;
    int n;
    cin >> n >> s;
    map<char,int> mp;
    rep(i,n) {
        mp[s[i]]++;
    }
    int count = 0;
    rep(i,n) {
        int c = i;
        rep(j,n) {
            int l = i-j;
            int r = i+j;
            if (l < 0 || r > n-1) break;
            if (s[c] != s[l] && s[l] != s[r] && s[r] != s[c]) count++;
        }
    }
    cout << ((mp['R'] * mp['G'] * mp['B']) - count) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

    int N;
    string s;
    cin >> N >> s;

    long int r=0,g=0,b=0;

    for(int i=0; i<N; i++){
        if(s.at(i)=='R')
            r++;
        else if(s.at(i)=='G')
            g++;

    }
    b = N - r - g;

    long int ans =0;
    ans = r*g*b;

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N && 2*j-i < N; j++){
            if(s.at(i)!=s.at(j) && s.at(i)!= s.at(2*j-i) && s.at(j)!= s.at(2*j-i))
                ans--;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);
const long long MOD = 1000000007;

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, r = 0, g = 0, b = 0;
    string s;

    cin >> n >> s;

    REP(i, n) {
        if (s[i]=='R'){
            r++;
        } else if (s[i]=='G') {
            g++;
        } else {
            b++;
        }
    }

    ll cond1 = r*g*b;
    ll cond2 = 0;
    REP(i, ceil(n/2.0)-1){
        REP(j, n-2*(i+1)){
            if (s[j]!=s[j+i+1] && s[j+i+1]!=s[j+2*(i+1)] && s[j+2*(i+1)]!=s[j]){
                cond2++;
            }
        }
    }

  	cout << cond1-cond2 << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main(void)
{
	IOS;
	int n; cin>>n;
	string s; cin>>s;
	vi a(n);
	vector<vi> g(3);
	for(int  i =0 ; i  < n; i++) {
		if(s[i]=='R') {
			a[i]=0;
			g[0].pb(i);
		}
		if(s[i]=='G'){
			a[i]=1;
			g[1].pb(i);
		}
		if(s[i]=='B') {
			a[i]=2;
			g[2].pb(i);
		}
	}
	int ans=0;
	for(int i = 0; i < n; i++) {
		for(int j = i+1; j< n; j++) {
			if(s[i]==s[j]) continue;
			int id=3-a[i]-a[j];
			ans += sz(g[id])-(upper_bound(all(g[id]),j)-g[id].begin());
			auto it=lower_bound(all(g[id]),2*j-i);
			if(it!=g[id].end() && *it==2*j-i)
				ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
template<class T> inline bool chmax(T &a, T b){if(a<b){a=b; return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a>b){a=b; return true;}return false;}

int main(void){
  int n,r=0,g=0,b=0,ans;
  string s;
  cin >> n;
  cin >> s;

  rep(i,0,n){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  ans= r*g*b;
  rep(i,0,n-2){
    rep(d,1,n){
      int j,k;
      j=i+d;
      k=j+d;
      if(k>=n)break;
      if(s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k]){
        ans--;
      }
    }
  }

  cout << ans;

  return 0;
}


#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#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;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a, b, c;
    REP(i, n) {
        if(s[i] == 'R') a.push_back(i+1);
        if(s[i] == 'G') b.push_back(i+1);
        if(s[i] == 'B') c.push_back(i+1);
    }
    ll sum = a.size()*b.size()*c.size();

    //とびとびのものを数えて引く
    for(int i=1; i<n; i++) {
        for(int j=0; j+i+i<n; j++) {
            if(s[j] == s[j+i] || s[j+i] == s[j+i+i] || s[j] == s[j+i+i]) continue;
            sum--;
        }
    }

    cout << sum << endl;
    return 0;
}


// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);

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

    int n;string s;
    cin>>n>>s;
    if(n<=2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(s[i]+s[j]+s[k]-'R'-'G'-'B'==0&&k-j!=j-i) ans++;
            }
        }
    }
    cout<<ans<<endl;

}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

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

    int R_cnt = 0, G_cnt = 0, B_cnt = 0;
    REP(i, 0, N){
        if (S[i] == 'R')
            ++R_cnt;
        else if (S[i] == 'G')
            ++G_cnt;
        else
            ++B_cnt;
    }

    ll sum = R_cnt * G_cnt * B_cnt;

    char i_str, j_str, k_str;
    REP(i, 0, N){
        i_str = S[i];
        for (int width = 1; i + width + width < N; ++width){
            j_str = S[i + width];
            k_str = S[i + width + width];
            if (i_str != j_str && i_str != k_str && j_str != k_str)
                --sum;
        }
    }
    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int i, j, k, Ans = 0;
    vector<int> R, G, B;
    for(i=0;i<n;i++){
        if (s[i] == 'R'){
            R.push_back(i);
        }
        else if(s[i] == 'G'){
            G.push_back(i);
        }
        else{
            B.push_back(i);
        }
    }

    int r = R.size(), g = G.size(), b = B.size();
    for(i=0;i<r;i++){
        for(j=0;j<g;j++){
            if(G[j] < R[i]){
                continue;
            }
            for(k=0;k<b;k++){
                if(B[k] < G[j] || G[j]-R[i] == B[k]-G[j]){
                    continue;
                }
                Ans++;
            }
        }
        for(j=0;j<b;j++){
            if(B[j] < R[i]){
                continue;
            }
            for(k=0;k<g;k++){
                if(G[k] < B[j] || B[j]-R[i] == G[k]-B[j]){
                    continue;
                }
                Ans++;
            }
        }
    }
    for(i=0;i<g;i++){
        for(j=0;j<r;j++){
            if(R[j] < G[i]){
                continue;
            }
            for(k=0;k<b;k++){
                if(B[k] < R[j] || R[j]-G[i] == B[k]-R[j]){
                    continue;
                }
                Ans++;
            }
        }
        for(j=0;j<b;j++){
            if(B[j] < G[i]){
                continue;
            }
            for(k=0;k<r;k++){
                if(R[k] < B[j] || B[j]-G[i] == R[k]-B[j]){
                    continue;
                }
                Ans++;
            }
        }
    }
    for(i=0;i<b;i++){
        for(j=0;j<r;j++){
            if(R[j] < B[i]){
                continue;
            }
            for(k=0;k<g;k++){
                if(G[k] < R[j] || R[j]-B[i] == G[k]-R[j]){
                    continue;
                }
                Ans++;
            }
        }
        for(j=0;j<g;j++){
            if(G[j] < B[i]){
                continue;
            }
            for(k=0;k<r;k++){
                if(R[k] < G[j] || G[j]-B[i] == R[k]-G[j]){
                    continue;
                }
                Ans++;
            }
        }
    }

    cout << Ans << endl;
    return 0;
}


#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    char a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%c",&a[i]);
    }
    for(int i=0;i<n-2;i++)
        for(int j=i+1;j<n-1;j++)
        for(int k=j+1;k<n;k++)
    {
        if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]&&2*j!=i+k)
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <cstring>

using namespace std;

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

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

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }

template<typename T = ll> struct UnionFind {
	vector<T> par, siz;

	UnionFind( T n ) {
		par.resize( n ); siz.resize( n );
		rep( i, n ) {
			par[i] = i; siz[i] = 1;
		}
	}

	T find( T x ) {
		if ( x == par[x] )
			return ( x );
		else
			return( par[x] = find( par[x] ) );
	}

	void unite( T x, T y ) {
		T xx = find( x ); T yy = find( y );
		if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] )
			swap( xx, yy );
		par[yy] = xx;
		siz[xx] += siz[yy];
	}
};

template<typename T = ll> class CompareMax {
public:	T operator()( T a, T b ) { return ( max( a, b ) ); }
};
template<typename T = ll> class CompareMin {
public:	T operator()( T a, T b ) { return ( min( a, b ) ); }
};

template<typename T = ll, typename F = CompareMax<T>, T I = 0> struct SegTree {
	T N; F func; vector<T> v;

	SegTree( T n ) {
		N = n; v.resize( 4 * n );
		rep( i, 4 * n ) v[i] = I;
	}

	void update( T i, T x ) {
		i += N - 1;
		v[i] = x;
		while ( i > 0 ) {
			i = ( i - 1 ) / 2;
			v[i] = func( v[i * 2 + 1], v[i * 2 + 2] );
		}
	}

	T query( T a, T b, T k, T l, T r ) {
		if ( r <= a || b <= l ) return ( I );
		if ( a <= l && r <= b ) return ( v[k] );
		else {
			T vl = query( a, b, k * 2 + 1, l, ( l + r ) / 2 );
			T vr = query( a, b, k * 2 + 2, ( l + r ) / 2, r );
			return ( func( vl, vr ) );
		}
	}
};

template<typename T = ll> T solveLIS( const vector<T> &v ) {
	vector<T> dp( v.size(), numeric_limits<T>::max() );
	rep( i, v.size() ) {
		*lower_bound( ALL( dp ), v[i] ) = v[i];
	}
	return ( distance( dp.begin(), lower_bound( ALL( dp ), numeric_limits<T>::max() ) ) );
}

template<typename T, T MOD> struct Fp {
	T val;

	constexpr Fp( T input ) noexcept : val( input % MOD ) {
		if ( val < 0 ) val += MOD;
	}
	constexpr T getmod() { return ( MOD ); }
	constexpr Fp operator-() const noexcept {
		return ( val ? MOD - val : 0 );
	}
	constexpr Fp operator+( const Fp &r ) const noexcept { return ( ( Fp( *this ) += r ) ); }
	constexpr Fp operator-( const Fp &r ) const noexcept { return ( ( Fp( *this ) -= r ) ); }
	constexpr Fp operator*( const Fp &r ) const noexcept { return ( ( Fp( *this ) *= r ) ); }
	constexpr Fp operator/( const Fp &r ) const noexcept { return ( ( Fp( *this ) /= r ) ); }

	constexpr Fp &operator+=( const Fp &r ) noexcept {
		val += r.val;
		if ( val >= MOD ) val -= MOD;
		return ( *this );
	}

	constexpr Fp &operator-=( const Fp &r ) noexcept {
		val -= r.val;
		if ( val < 0 ) val += MOD;
		return ( *this );
	}

	constexpr Fp &operator*=( const Fp &r ) noexcept {
		val = ( val * r.val ) % MOD;
		return ( *this );
	}

	constexpr Fp &operator/=( const Fp &r ) noexcept {
		T a = r.val, b = MOD, u = 1, v = 0;
		while ( b ) {
			T t = a / b;
			a -= t * b; swap( a, b );
			u -= t * v; swap( u, v );
		}
		val = ( val * u ) % MOD;
		if ( val < 0 ) val += MOD;
		return ( *this );
	}

	constexpr bool operator==( const Fp &r ) noexcept {
		return ( val == r.val );
	}

	constexpr bool operator!=( const Fp &r ) noexcept {
		return ( val != r.val );
	}

	friend constexpr ostream& operator<<( ostream &os, const Fp<T, MOD>&x ) noexcept {
		return ( os << x.val );
	}

	friend constexpr Fp<T, MOD> modpow( const Fp<T, MOD> &a, T n ) noexcept {
		if ( n == 0 ) return ( 1 );
		auto t = modpow( a, n / 2 );
		t = t * t;
		if ( n & 1 ) t = t * a;
        return ( t );
	}
};

template<typename T, T MOD> struct BiCoef {
	using mint = Fp<T, MOD>;
	vector<mint> fact_, inv_, finv_;

	constexpr BiCoef() {}
	constexpr BiCoef( T n ) noexcept :
		fact_( n, 1 ), inv_( n, 1 ), finv_( n, 1 )
	{
		init( n );
	}

	constexpr void init( T n ) {
		fact_.assign( n, 1 ); inv_.assign( n, 1 ); finv_.assign( n, 1 );
		for ( T i = 2; i < n; i++ ) {
			fact_[i] = fact_[i - 1] * i;
			inv_[i] = -inv_[MOD % i] * ( MOD / i );
			finv_[i] = finv_[i - 1] * inv_[i];
       }
    }

    constexpr mint comb( T n, T k ) const noexcept {
		if ( n < k || n < 0 || k < 0 ) return ( 0 );
		if ( n - k < k ) k = n - k;
		return ( fact_[n] * finv_[k] * finv_[n - k] );
    }

    constexpr mint fact( T n ) const noexcept {
		if ( n < 0 ) return ( 0 );
		return ( fact_[n] ) ;
    }

    constexpr mint inv( T n ) const noexcept {
		if ( n < 0 ) return ( 0 );
		return ( inv_[n] );
    }

    constexpr mint finv( T n ) const noexcept {
		if ( n < 0 ) return ( 0 );
		return ( finv_[n] );
    }
};

constexpr ll MOD = 1000000007LL;
using mint = Fp<ll, MOD>;
BiCoef<ll, MOD> bc;

/*
	regex reg( R"(^(dream|dreamer|erase|eraser)+$)" );
	smatch m;

	if ( regex_match( s, m, reg ) )
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
*/
/*
	cout << setprecision( 16 );
	cout << fixed << setprecision( 16 );
*/

template<typename T = int> vector<T> Zalgo( const string &S ) {
	T N = (T)S.size();
	vector<T> res(N);
	res[0] = N;
	T i = 1, j = 0;
	while ( i < N ) {
		while (i+j < N && S[j] == S[i+j]) ++j;
		res[i] = j;
		if ( j == 0 ) { ++i; continue; }
		int k = 1;
		while ( i + k < N && k + res[k] < j ) res[i + k] = res[k], ++k;
		i += k, j -= k;
	}
	return ( res );
}

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}

int main()
{
	ll n; cin >> n;
	string s; cin >> s;
	vector<ll> r( n ), g( n ), b( n );
	map<char, ll> m;
	rep( i, s.size() )
	{
		m[s[i]]++;
		r[i] = m['R'];
		g[i] = m['G'];
		b[i] = m['B'];
	}

//	cout << m['R'] << ", " << m['G'] << ", " << m['B'] << endl;

	ll ans = 0;
	rep( i, s.size() - 2 )
	{
		for ( ll j = i + 1; j < n - 1; ++j )
		{
			ll k = j + j - i;
			switch ( s[i] )
			{
			case 'R':
				if ( s[j] == 'G' )
				{
					ans += ( b[n - 1] - b[j] );
					if ( k < n && s[k] == 'B' )
						--ans;
				}
				if ( s[j] == 'B' )
				{
					ans += ( g[n - 1] - g[j] );
					if ( k < n && s[k] == 'G' )
						--ans;
				}
				break;

			case 'G':
				if ( s[j] == 'R' )
				{
					ans += ( b[n - 1] - b[j] );
					if ( k < n && s[k] == 'B' )
						--ans;
				}
				if ( s[j] == 'B' )
				{
					ans += ( r[n - 1] - r[j] );
					if ( k < n && s[k] == 'R' )
						--ans;
				}
				break;

			case 'B':
				if ( s[j] == 'R' )
				{
					ans += ( g[n - 1] - g[j] );
					if ( k < n && s[k] == 'G' )
						--ans;
				}
				if ( s[j] == 'G' )
				{
					ans += ( r[n - 1] - r[j] );
					if ( k < n && s[k] == 'R' )
						--ans;
				}
				break;
			}
		}
	}

	cout << ans << endl;

	return ( 0 );
}


#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(int i=a;i<n;i++)
int main(){
	long long int n;
  	scanf("%lld",&n);

    char s[4001];
    scanf("%s",s);
    long long int ans = 0;

    vector<int>r,g,b;

    loop(i,0,n){
        if(s[i] == 'R')r.push_back(i);
        else if(s[i] == 'G')g.push_back(i);
        else if(s[i] == 'B')b.push_back(i);
    }

    loop(i,0,n){
        loop(j,i+1,n){
            if(s[i] != s[j]){
                int dist = j-i;
                if(s[i]!= 'R' and s[j]!= 'R'){
                    auto it = upper_bound(r.begin(),r.end(),j);
                    if(it != r.end()){
                        ans += (r.end() - it);
                        if(2*j-i < n and s[2*j-i] == 'R')ans --;
                    }

                }
                else if(s[i]!= 'G' and s[j]!= 'G'){
                    auto it = upper_bound(g.begin(),g.end(),j);
                     if(it != g.end()){
                        ans += (g.end() - it);
                        if(2*j-i < n and s[2*j-i] == 'G')ans --;
                    }
                }
                else{
                    auto it = upper_bound(b.begin(),b.end(),j);
                    if(it != b.end()){
                        ans += (b.end() - it);
                        if(2*j-i < n and s[2*j-i] == 'B')ans --;
                    }
                }
            }
        }
    }

  	printf("%lld",ans);
  	puts("");
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int a;
	int cnt = 0;
	string in;
	cin >> a;
	cin >> in;
	for (int i = 0; i < a; i++) {
		char t1 = in[i];
		for (int j = i + 1; j < a; j++) {
			char t2 = in[j];
			if (t1 == t2) continue;
			for (int k = j + 1; k < a; k++) {
				char t3 = in[k];
				if (k - j == j - i) continue;
				if (t3 == t1 || t3 == t2) continue;
				cnt++;
			}
		}
	}
	cout << cnt << endl;

}