akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    string s; cin>>s;
    int n = s.size();

    bool valid = true;
    for(int i=0; i<n; i++){
        if(s[i] != s[n - i - 1]) valid = false;
    }

    string head = s.substr(0, (n - 1) / 2);
    //cout << head << endl;
    for(int i=0; i<head.size(); i++){
        if(head[i] != head[head.size() - i - 1]) valid = false;
    }

    string tail = s.substr((n + 3) / 2 - 1);
    //cout << tail << endl;
    for(int i=0; i<tail.size(); i++){
        if(tail[i] != tail[tail.size() - i - 1]) valid = false;
    }

    cout << (valid ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
H,W=list(map(int,input().split()))
S=''
for i in range(W+2):
    S=S+'.'
grid=[]
grid.append(S)
for i in range(H):
    grid.append('.'+input()+'.')
grid.append(S)

for i in range(1, H+1):
    for j in range(1,W+1):
        if grid[i][j]=='#':
            if grid[i-1][j]=='.' and grid[i][j-1]=='.' and grid[i+1][j]=='.' and grid[i][j+1]=='.':
                print("No")
                quit()
        else:
            pass
print('Yes')


Measured memory_bytes: 3064
import sys
from sys import stdin
input = stdin.readline

cnt = 0
INF = 10000000000

def merge(A, left, mid,  right):
  global cnt
  L = A[left:mid] + [INF]
  R = A[mid:right] + [INF]
  i = 0
  j = 0
  for k  in range(left , right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
      cnt += 1
    else:
      A[k] = R[j]
      j = j + 1
      cnt += 1

def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

n = int(input())
A =[int(x) for x in input().split()]
mergeSort(A, 0, n)

print(*A)
print(cnt)


Measured memory_bytes: 61644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,k,n) for(int i = k; i <= n; i++) 
#define per(i,k,n) for(int i = k; i >= n; i--)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii; 
typedef vector<ii> vii;
typedef vector<char> vchar;
typedef vector<int> vi;
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"


   //=\/=\/=\/=\/=\/=\/=\/=\/=\/=\        Jai Hind Dosto        /=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\
  //=\/=\/=\/=\                    ̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿                             /=\/=\/=\/=\\
 //=\/=\/=\/=\                                                                               /=\/=\/=\/=\\
//=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\



int modPow(int a, int b);           

                
void solve(){
    int n ,d;
    cin >> n >> d ;
    int cnt = 0;
    while(n--){
        int a,b;
        cin >> a >>b;
        if(a*a + b*b<=d*d)cnt++;
    }
    cout << cnt;
    
}






signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed;
    //cout <<setprecision(6);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
   // int test=1; cin >> test; while(test--)
    solve();
}

int modPow(int a, int b){
    if(b==0)return 1;
    if(b%2==0){
        int x = a*a;
        x%=mod;
        return modPow(x,b/2);
    }
    return (a*modPow(a,b-1))%mod;
}




Measured memory_bytes: 3656
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const [n, m] = args[0].map(x => parseInt(x));
const h = args[1].map(x => parseInt(x));
const good: boolean[] = Array(n).fill(true);
for (let i = 0; i < m; i++) {
    const [a, b] = args[i + 2].map(x => parseInt(x) - 1);
    if (h[a] < h[b]) {
        good[a] = false;
    } else if (h[a] > h[b]) {
        good[b] = false;
    } else {
        good[a] = good[b] = false;
    }
}

const cnt = good.filter(x => x).length;

console.log(cnt);




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

enum { maxn = 20, INF = 10000000000000LL };

typedef long long LL;
LL G[maxn][maxn];
int vis[maxn];
LL d[maxn][maxn];
int inq[maxn];
int m;

void spfa(int src)
{
    memset(inq, 0, sizeof inq);
    for(int i = 0; i < maxn; i++) d[src][i] = INF;
    d[src][src] = 0LL;
    queue< int > q;
    while(!q.empty()) q.pop();
    q.push(src);
    inq[src] = 1;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = 0; i < maxn; i++)
        {
            if(G[u][i] != -1)
            {
                if(d[src][u] + G[u][i] < d[src][i])
                {
                    d[src][i] = d[src][u] + G[u][i];
                    if(!inq[i])
                    {
                        inq[i] = 1;
                        q.push(i);
                    }
                }
            }
        }
        inq[u] = 0;
    }
}

int main()
{
    while(~scanf("%d", &m), m)
    {
        memset(vis, 0, sizeof(vis));
        memset(G, -1, sizeof(G));
        memset(d, 0, sizeof(d));
        for(int i = 0; i < m; i++)
        {
            int a, b;
            LL c;
            scanf("%d%d%lld", &a, &b, &c);
            G[a][b] = G[a][b] == -1? c : min(G[a][b], c);
            G[b][a] = G[b][a] == -1? c: min(c, G[b][a]);
            vis[a] = vis[b] = 1;
        }
        for(int i = 0; i < maxn; i++)
            if(vis[i])
                spfa(i);
        LL ans = INF;
        int pt = -1;
        for(int i = 0; i < maxn; i++)
        {
            LL sum = 0;
            if(vis[i])
            {
                for(int j = 0; j < maxn; j++)
                {
                    if(vis[j])
                    {
                        sum += d[i][j];
                    }
                }
                if(sum < ans)
                {
                    ans = sum;
                    pt = i;
                }
            }
        }
        printf("%d %lld\n", pt, ans);
    }
    return 0;
}
/*

6     
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0


*/

Measured memory_bytes: 1196
# 2019/04/27
# AtCoder Beginner Contest 087 - C

# Input
n = int(input())
u = list(map(int, input().split()))
d = list(map(int, input().split()))
ul = list()
dl = list()
ul.append(0)
dl.append(0)

# Make Accumulated List
for i in range(n):
    ul.append(u[i] + ul[i])
    dl.append(d[i] + dl[i])

# Search Max
maxcdy = 0
for i in range(1, n+1):
    cdy = ul[i] + (dl[n] - dl[i-1])
    if maxcdy < cdy:
        maxcdy = cdy

# Output
print(maxcdy)
    


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[111111];
bool used[111111];
int deg[111111];

signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        G[a].pb(b);G[b].pb(a);
    }

    queue<int>que;
    rep(i,N)if(G[i].size()==1)que.push(i),used[i]=true;
    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto u:G[v]){
            if(used[u])continue;
            if(G[u].size()==2){
                used[u]=true;
                que.push(u);
            }
            deg[u]++;
        }
    }

    int ans=0;
    if(count(used,used+N,1)==N)ans=1;
    else{
        rep(i,N){
            if(used[i])continue;
            ans+=max(0ll,deg[i]-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <algorithm>

using namespace std;

void tasu(string s1, string s2){
	int num[2][max(s1.length(), s2.length())+1];
	for(int i = 0; i < sizeof(num[0])/sizeof(int); i++){
		if(s1.length() > i){
			num[0][i] = (int)s1.at(s1.length()-1-i) - (int)'0';
		}else{
			num[0][i] = 0;
		}
		if(s2.length() > i){
			num[1][i] = (int)s2.at(s2.length()-1-i) - (int)'0';
		}else{
			num[1][i] = 0;
		}
	}
	for(int i = 0; i < sizeof(num[0])/sizeof(int)-1; i++){
		num[1][i] += num[0][i];
		if(num[1][i] > 9){
			num[1][i+1] += (int)(num[1][i]/10);
			num[1][i] %= 10;
		}
	}
	int keta = sizeof(num[0])/sizeof(int);
	while(keta && !num[1][keta-1]){
		keta--;
	} 
	if(keta > 80){
		cout << "overflow" << endl;
	}else if(keta){
		while(keta--){
			cout << num[1][keta];
		}
		cout << endl;
	}else{
		cout << 0 << endl;
	}
}
int main(){
	int n;
	cin >> n;
	while(n--){
		string s1, s2;
		cin >> s1 >> s2;
		tasu(s1, s2);
	}
}

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

int main(){
    int N;
    cin >> N;
    typedef pair<int, int> Student;
    priority_queue<Student, vector<Student>, greater<Student>> que;

    int num;
    for(int i=0; i<N; i++){
        cin >> num;
        que.push(Student(num, i));
    }

    while (!que.empty()){
        Student student = que.top();
        que.pop();
        cout << student.second + 1 << " ";
    }

    return 0;
    

}

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

int main(){
    int N,tmp;

    cin >> N;
    
    int a[N];
    int b[N];
  
    for(int i = 0; i < N; ++i) {
    	cin >> a[i];
      	b[a[i]-1] = i+1;
    }
	
    for(int i = 0; i < N; ++i) {
	if(i==N-1) cout << b[i];
    	else cout << b[i] << " ";
    }

    return 0;
}


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

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

  int ans = 1;

  for (int i = 0;i < N;i++){
    if (ans <= K){
      ans *= 2;
    }else{
      ans += K;
    }
  }

  cout << ans;

  return 0;
}


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

using namespace std;

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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vector<vector<vector<int>>> F(N, vector<vector<int>>(5, vector<int>(2)));
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 5; ++j) {
      for (int k = 0; k < 2; ++k) {
        cin >> F[i][j][k];
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }
  int ans = -1e9;
  for (int i = 1; i < 1024; ++i) {
    int benefit = 0;
    for (int j = 0; j < N; ++j) {
      int shop = 0;
      for (int k = 0; k < 10; ++k) {
        if (((i >> k) & 1) == 0) continue;
        if (F[j][k / 2][k % 2] == 1) shop++;
      }
      benefit += P[j][shop];
    }
    ans = max(ans, benefit);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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


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

    cout << N - K + 1 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int N = 2e5 + 5;

vector<int> vis(N, 0);
vector<int> adj[N];
int mx = 0;

int dfs(int u){
    int ans = 0;
    if(!vis[u]){
        vis[u] = true;
        ans++;
        for(auto v: adj[u]){
            ans += dfs(v);
        }
    }
    return ans;
}

void solve(){
    int n, m;
    cin >> n >> m;
    for(int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i=0; i<n; i++){
        if(!vis[i]){
            mx = max(mx, dfs(i));
        }
    }
    cout << mx;
}
 
int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 21072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 100000000

using namespace std;

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

    return 0;
}


Measured memory_bytes: 256
import sys
import math
N = int(sys.stdin.readline().strip())
 
def calc(xa, ya, ra, xb, yb, rb):
    dist = math.sqrt((yb - ya) **2 + (xb - xa) **2)
    if dist > (ra + rb):
        return 0
    elif abs(ra - rb) <= dist <= (ra + rb):
        return 1
    elif dist < abs(ra - rb):
        if ra > rb:
            return 2
        else:
            return -2
 
for i in xrange(N):
    line = sys.stdin.readline().strip()
    xa, ya, ra, xb, yb, rb = map(float, line.split())
    print calc(xa, ya, ra, xb, yb, rb)

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

using namespace std;

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;*/
    
    int n;cin>>n;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        v[i]={x,y};
    }
    int mx=0;
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i!=j){
                m[{v[j].first-v[i].first,v[j].second-v[i].second}]++;
                m[{v[i].first-v[j].first,v[i].second-v[j].second}]++;
            }
            mx=max({mx,m[{v[i].first-v[j].first,v[i].second-v[j].second}],m[{v[j].first-v[i].first,v[j].second-v[i].second}]});
        }
    }
    cout<<n-mx;

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

Measured memory_bytes: 384
N=int(input())
a=[[] for i in range(N)]
for i in range(N):
  a1,b1=map(int,input().split())
  a[i].extend([a1,b1])
a.sort()
c=[]
d=[]
for i in range(N):
  c1,d1=map(int,input().split())
  c.append(c1)
  d.append(d1)
count=0
flag=[0 for i in range(N)]
for i in range(N):
  y=a[N-1-i][1]
  tmp=-1
  minb=max(d)
  fl=False
  for j in range(N):
    if(c[j]>a[N-1-i][0]):
      if(d[j]<=minb and d[j]>y and flag[j]==0):
        fl=True
        tmp=j
        minb=d[j]
  if fl:
    flag[tmp]=1
    count+=1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 50005;
int mx = -1e9 , mn = 1e9 ;

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> x(X);
    vector<long long> y(Y);
    vector<long long> z(Z);

    for (int i = 0; i < X; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < Y; ++i) {
        cin >> y[i];
    }
    for (int i = 0; i < Z; ++i) {
        cin >> z[i];
    }

    vector<long long> tmp;
    for (int i = 0; i < X; ++i) {
        for (int j = 0; j < Y; ++j) {
            tmp.push_back(x[i] + y[j]);
        }
    }

    sort(tmp.rbegin(), tmp.rend());

    vector<long long> ans;
    for (int i = 0; i < Z; ++i) {
        for (int j = 0; j < min(K, (int)tmp.size()); ++j) {
            ans.push_back(tmp[j] + z[i]);
        }
    }

    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < K; ++i) {
        cout << ans[i] << '\n';
    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int H[N];
  int count=1;
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  int max=H[0];
  for(int i=0;i<N-1;i++){
    if (max<H[i])max=H[i];
    if(max<=H[i+1]){
      count++;
    }else {
      continue;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
void rensa();
int n;
 int i,A[101],B[101],C[101];//A gyou B retu C kiroku C umarumade saiki
int m[101][201];
int main(){
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&A[i],&B[i]);
    C[i]=A[i];
  }
  C[i]=B[i-1];
  rensa();
  if(n>3)
  printf("%d\n",m[1][n]);
  else
    printf("%d\n",C[0]*C[1]*C[2]);

  return 0;
}
void rensa(){
  
  int i,j,k,l,q;
  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+C[i-1]*C[k]*C[j];
      	if(m[i][j]>q)
	  m[i][j]=q;

      }
    }
  }
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
bool isPalindrome(string s, int start, int end){
    for(int i = start;i<=end/2;++i){
        if(s[i] != s[end-i]){
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    cin>>s;
    int n = s.length();
    if(isPalindrome(s,0,n-1) && isPalindrome(s,0,(n-1)/2-1) && isPalindrome(s,(n+3)/2-1,n-1)  ){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"\nDEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis; vector<int> color;
bool pos=true;
#define red 1
#define blue 2
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
double pow(double a, int n) {
  if(n == 0) return 1;if(n == 1) return a;
  double t = pow(a, n/2);return t * t * pow(a, n%2);
}
void DFS(ll u){
	vis[u]=true;
	for(auto v: adj[u]){
		if(vis[v]){
			if(color[v]==color[u]) pos=false;
		}
		else{
			if(color[u]==red) color[v]=blue; else color[v]=red;
			DFS(v);
		}
	}
}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0);   cout<<fixed; cerr<<fixed;
  cout<<setprecision(3); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	ll n,a,b,ans=0; cin>>n>>a>>b;
	for(ll i=1;i<=n;++i){
		ll s=0, t=i; while(t){s+=t%10; t/=10;}
		if(s>=a && s<=b)  ans+=i;
	}
	cout<<ans<<'\n';

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1000<<"ms.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
break_flg = false
check = 0
count = 0
A = gets.chomp.split(" ").map(&:to_i)
while break_flg == false
    for i in 0..N-1 do #配列のすべての要素に対して偶数かどうかのチェックを行う。
        if A[i] % 2 == 0 
            check = check + 1
        else
            break_flg = true
        end
    end

    if check == N #全部偶数だから処理を実行させる。
        for i in 0..N-1 do
            A[i] = A[i] / 2
        end
        count = count + 1
        check = 0
    end
end
puts count


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k;
    }
    else if(k<=a+b){
        cout << a;
    }
    else{
        cout << a-(k-a-b);
    }
    return 0;
}

Measured memory_bytes: 3652
s = input().strip()
n = len(s)
res = 0
left = 0
right = 0
while left < n:
    if s[left] not in ['A', 'T', 'C', 'G']:
        left += 1
        continue
    right = left + 1
    while right < n:
        if s[right] in ['A', 'T', 'C', 'G']:
            right += 1
        else:
            break
    res = max(res, right - left)
    left = right
print(res)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0) break;
		for(int i = 0; i < x; i++){   //縦のループ
			for(int j = 0; j < y; j++){  //横のループ
				if(i == 0 || i == x-1){  //1行目とx行目を全て#にする
				printf("#");
				}
				else if(i != 0 && i != x-1 && j == 0 || j == y-1){  //1行目、x行目以外の1列目とy列目を全て＃にする
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
    int a,b;
    cin>>a>>b;
    if(a!=1&&b!=1)
    {
       if(a>b)
         cout<<"Alice";
       else if(b>a)
         cout<<"Bob";
       else
         cout<<"Draw";
    }
    else if(a==1&&b!=1)
      cout<<"Alice";
    else if(b==1&&a!=1)
      cout<<"Bob";
    else
      cout<<"Draw";
    cout<<nl;
    return 0;
}


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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define llong long long

int main(){
	int N; scanf("%d",&N);
	int flag = 0;
	rep(i,0,3){
		if( N%10 == 7 ) flag = 1;
		N /= 10;
	}
	if( flag ) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= 0 && b >= 0)
    {
        cout << "Zero\n";
    }
    else if(a > 0)
    {
        cout << "Positive\n";
    }
    else
    {
        if((b - a) % 2 == 1)
        {
            cout << "Positive\n";
        }
        else
        {
            cout << "Negative\n";
        }
    }
    
    return 0;
}

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

int main()
{
  int n, k, count = 0;
  cin >> n >> k;
  int h[n];
  rep(i, n) cin >> h[i];
  rep(i, n) if(h[i] >= k) count++;
  cout << count << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int N; scanf("%d", &N);

	char S[100];
	printf("0\n"); fflush(stdout);
	scanf("%s", S);

	int g = 0;
	if (S[0] == 'F') g = 1;
	else if (S[0] == 'V') return 0;

	int l = 1, r = N - 1;
	while (l <= r) {
		int m = (l + r) / 2;
		printf("%d\n", m); fflush(stdout);
		scanf("%s", S);
		if (S[0] == 'V') return 0;
		if ((m + g) % 2 == (S[0] == 'F')) {
			l = m + 1;
		}
		else r = m - 1;
	}
	return 0;
}

Measured memory_bytes: 760
#include<bits/stdc++.h> 
using namespace std ;
//priority_queue<int,vector<int>,greater<int> >x ;
int h[100008] , dp[100008] ;
int main(){
    int n ;
    cin >> n ;
    for(int i=0 ; i<n ; i++){
        cin >> h[i] ;
    }
    
    dp[0]=0 ;
    dp[1]=abs(h[1]-h[0]) ;
    for(int i=2 ; i<n ; i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) ;
    }
    cout << dp[n-1] ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
const int N = 1e4 + 5 ;
int n, ans[N];
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	n = read<int>() ;
	for( ri i = 1; ( i + 1 ) * ( i + 1 ) + 4 <= 2 * n; ++i )
		for( ri j = 1; ( i + j ) * ( i + j ) + ( i + 1 ) * ( i + 1 ) + ( j + 1 ) * ( j + 1 ) <= 2 * n; ++j )
			for( ri k = 1; ( i + j ) * ( i + j ) + ( i + k ) * ( i + k ) + ( j + k ) * ( j + k ) <= 2 * n; ++k ) {
				int tmp = ( i + j ) * ( i + j ) + ( i + k ) * ( i + k ) + ( j + k ) * ( j + k ) ;
				if( tmp & 1 )
					continue ;
				ans[tmp / 2] += 1 ;
			}
	for( ri i = 1; i <= n; ++i )
		print( ans[i] ), puts( "" ) ;
	cerr << 1. * clock() / CLOCKS_PER_SEC << "\n" ;
	return 0;
}

Measured memory_bytes: 3760
#include <vector>
#include <algorithm>
#include <cstdint>
#include <iostream>

using std::vector;
using std::uint64_t;

const unsigned int NMAX = 8;
constexpr unsigned int MMAX = NMAX * (NMAX - 1) / 2;

uint64_t search(vector<vector<unsigned int>>& e, vector<unsigned int>& stack, const unsigned int max) {
    unsigned int root = stack.back();
    if (stack.size() == max) {
        return 1;
    }

    uint64_t sum = 0;
    for (unsigned int v : e[root]) {
        if (std::find(stack.begin(), stack.end(), v) != stack.end()) {
            continue;
        }
        stack.push_back(v);
        sum += search(e, stack, max);
        stack.pop_back();
    }

    return sum;
}

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

    vector<vector<unsigned int>> e;
    e.reserve(n);
    for (int i = 0; i < n; i++) {
        vector<unsigned int> tmp;
        e.emplace_back(tmp);
    }
    for (int i = 0; i < m; i++) {
        unsigned int src, dst;
        std::cin >> src >> dst;
        src -= 1; dst -= 1;
        e[src].push_back(dst);
        e[dst].push_back(src);
    }
    
    vector<unsigned int> stack;
    stack.push_back(0);
    unsigned int ans = search(e, stack, n);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    int n,k;
    cin>>n>>k;
    vector<int> hp(n);
    rep(i,n) cin >> hp.at(i);
    
    sort(hp.rbegin(),hp.rend());
    k=min(k,n);
    long long ans=accumulate(hp.begin()+k, hp.end(), 0ll);
    dunk(ans);
}



Measured memory_bytes: 1024
from collections import deque

S = input()
X, Y = map(int, input().split())
F = [deque() for _ in (0, 1)]

i = 0
tmp = 0
for s in S:
    if s == 'F':
        tmp += 1
    else:
        F[i].append(tmp)
        i = (i + 1) % 2
        tmp = 0
if tmp:
    F[i].append(tmp)

first = F[0].popleft()

T = [{first}, {0}]
for i in range(2):
    for j in F[i]:
        T[i] = {k - j for k in T[i]} | {k + j for k in T[i]}
if X in T[0] and Y in T[1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5228
import java.util.*;
import java.lang.String;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        String strArr[] = str.split("");
        int numArr[] = new int[4];

        for (int i = 0; i < 4; i++){
            numArr[i] = Integer.valueOf(strArr[i]);
        }

        Boolean isYYMM = false;
        Boolean iSMMYY = false;

        isYYMM = isYYMM(numArr);
        iSMMYY = isMMYY(numArr);

        if (isYYMM && iSMMYY) {
            System.out.println("AMBIGUOUS");
        } else if (isYYMM) {
            System.out.println("YYMM");
        } else if (iSMMYY) {
            System.out.println("MMYY");
        } else {
            System.out.println("NA");
        }
    }

    static Boolean isYYMM(int[] numArr) {
        Boolean isYYMM = true;
        String month = Integer.toString(numArr[2]) + Integer.toString(numArr[3]);

        if (Integer.valueOf(month) > 12) {
            isYYMM = false;
        } else if (Integer.valueOf(month) == 0) {
            isYYMM = false;
        }
        return isYYMM;
    }

    static Boolean isMMYY(int[] numArr) {
        Boolean isMMYY = true;
        String month = Integer.toString(numArr[0]) + Integer.toString(numArr[1]);

        if (Integer.valueOf(month) > 12) {
            isMMYY = false;
        } else if (Integer.valueOf(month) == 0) {
            isMMYY = false;
        }

        return isMMYY;
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int h,w,n,ans = 0,cnt = 0;
    cin >> h >> w >> n;
    int mx = max(h,w);
    if(w >= h){
        for (int i = 0; i < h; ++i) {
            ans++;
            cnt += w;
            if(cnt >= n){
                cout << ans << endl;
                return 0;
            }
        }
    }
    if(h > w){
        for (int i = 0; i < w; ++i) {
            ans++;
            cnt += h;
            if(cnt >= n){
                cout << ans << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
			int N=sc.nextInt();
			int ans=0;
			int fans=0;
			int h[]=new int[N];
			h[0]=sc.nextInt();
			for(int i=1;i<N;i++) {
				h[i]=sc.nextInt();
				if(h[i]>h[i-1]) {
					fans=Math.max(fans, ans);
					ans=0;
				}else {
					ans++;
				}
				//p(ans);
			}
			fans=Math.max(fans, ans);
			p(fans);
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 50240
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;

  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

typedef pair<int,int> pii;
map<pii, int> se;
vector<pii> ans;

#define RESIDUE(s,t) (capacity[s][t]-flow[s][t])
Weight edmonds_karp(Graph &g, int s, int t) {
  int n = g.size();
  Matrix flow(n, Array(n)), capacity(n, Array(n));
  REP(u,n) FOR(e,g[u]) capacity[e->src][e->dst] += e->weight;
  
  Weight total = 0;
  while(1) {
    queue<int> Q; Q.push(s);
    vector<int> prev(n, -1); prev[s] = s;
    while(!Q.empty() && prev[t] < 0) { // s ツつゥツづァ t ツづ鳴猟ャツつケツづゥツ路ツづーBFSツづ個ゥツづつつッツづゥツ。
      int u = Q.front(); Q.pop();
      REP(v, n) if (prev[v] < 0 && RESIDUE(u, v) > 0) {
        prev[v] = u;
        Q.push(v);
      }
    }
    if (prev[t] < 0) break;
    Weight inc = INF;
    for (int j=t; prev[j]!=j; j=prev[j])
      inc = min(inc, RESIDUE(prev[j], j));
    for (int j=t; prev[j]!=j; j=prev[j])
      flow[prev[j]][j] += inc, flow[j][prev[j]] -= inc; // ツ逆ツ陛督づ掲low ツつゥツづァツ暗クツつュツつアツづづ可淞つオツ姪淞つケツづゥツづヲツつ、ツづ可つキツづゥツ。
    // ツづつづ慊づィツ、flow ツつェツ猟ャツづェツつスツづつアツづォツづ個逆ツ古シツつォツづ個陛督づ可甘鳴つオツづСESIDUE ツつェツつサツづ個閉ェツ妥・ツつォツつュツづ按づゥツ。
    total += inc;
  }
  REP(i,n) {
    REP(j,n) {
      if (flow[i][j] > 0) {
        if (se.count(pii(i,j)) == 0) {
          ans.push_back(pii(i,j));
        }
      }
    }
  }
  return total;
}

int main() {
  int n,m;
  cin >> n >> m;
  Graph g(n);
  int s,t;
  REP(i,m) {
    int x,y;
    cin >> x >>y;
    x--;y--;
    g[x].push_back(Edge(x,y,1));
    g[y].push_back(Edge(y,x,1));
    se[pii(x,y)] = i+1;
  }
  cin >> s >> t;
  s--;t--;
  cout << edmonds_karp(g, s, t) << endl;
  cout << ans.size() << endl;
  vector<int> v;
  FOR(it, ans) {
    v.push_back(se[pii(it->second, it->first)]);
  }
  sort(ALL(v));
  FOR(it,v)
    cout << *it << endl;
}

Measured memory_bytes: 0
n=int(input())
l=[int(s) for s in input().split()]
cnt=0
for i in range(1,len(l)-1):
  re1=l[i-1]
  re2=l[i]
  re3=l[i+1]
  if( (re2>re1 and re2<re3) or (re2>re3 and re2<re1)):
    cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>


int main() {


	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	std::string s; std::cin >> s;
	std::string a; for (int i = 0; i < s.size(); i++) {//01010101...のとき
		if (i % 2 == 0)a += '0';
		else a += '1';
	}
	std::string b; for (int i = 0; i < s.size(); i++) {//10101010...のとき
		if (i % 2 == 0)b += '1';
		else b += '0';
	}
	int cost_a = 0;
	int cost_b = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != a[i])cost_a++;
		if (s[i] != b[i])cost_b++;
	}

	if (cost_a < cost_b) {
		std::cout << cost_a;
	}
	else {
		std::cout << cost_b;
	}


	return 0;


}

Measured memory_bytes: 720
def main():
	N = int(input()) 
	A = [int(f) for f in input().split()]
	B = [int(f) for f in input().split()]
	
	m = 0
	for i in range(N):
		A[i] = A[i] - B[i]
		m += B[i]
		if A[i] < 0:
			B[i] = -A[i]
			m += A[i]
			A[i] = 0
		else:
			continue
		if B[i] > 0:
			A[i+1] = A[i+1] - B[i]
			m += B[i]
			if A[i+1] < 0:
				B[i] = -A[i+1]
				m += A[i+1]
				A[i+1] = 0
	
	print(m)

if __name__ == "__main__":
	main()

Measured memory_bytes: 18624
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(x) cout << x << endl
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define pb emplace_back
#define vii vector<int>
#define vll vector<ll>
#define vpll vector< pair <ll,ll> >
#define pll pair <ll,ll>
#define pii pair <int,int>
#define pq priority_queue< int >
#define khtm "\n"
#define F first
#define S second
#define fr(i,a,n) for(i=a;i<n;i++)
#define mem(arr,l) memset(arr,l,sizeof arr)
#define ALL(x) x.begin(), x.end()
#define frr(i,a,n) for(i=n-1;i>=a;i--)
#define mod 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase ll T; cin>>T; while(T--)
const int MAX = 1e6 +2;
const int inf = (int) 1e9;
const int N = 1010;

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
//ll a[MAX];

int main()
{

//cout << setprecision(15) << fixed;
fast

string s;
cin >> n >> s;
ll r=0,g=0,b=0;
fr(i,0,n)
{
	if(s[i] == 'R')
		r++;
	if(s[i] == 'G')
		g++;
	if(s[i] == 'B')
		b++;
}
ll ans = r*g*b;
fr(i,0,n-1)
{
	fr(j,i+1,n)
	{
		if(s[i] != s[j])
		{
			if(j+j-i < n && s[j+j-i] != s[i] && s[j+j-i] != s[j])
				ans--;
		}
	}
}
cout << ans;



 
  return 0;
 
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int ans=t.size();
    for(int j=0;j<=(s.size()-t.size());j++)
    {
        int diff=0;
        for(int i=0;i<t.size();i++)
        {
            if(t[i]!=s[j+i])
                diff++;
        }
        ans=min(ans,diff);
    }
    cout<<ans<<" ";
    return 0;
}

Measured memory_bytes: 3600
def extended_gcd(a, b)
  last_remainder, remainder = a.abs, b.abs
  x, last_x, y, last_y = 0, 1, 1, 0
  while remainder != 0
    last_remainder, (quotient, remainder) = remainder, last_remainder.divmod(remainder)
    x, last_x = last_x - quotient*x, x
    y, last_y = last_y - quotient*y, y
  end

  return last_remainder, last_x * (a < 0 ? -1 : 1)
end

def modinv(e, et)
  g, x = extended_gcd(e, et)
  if g != 1
    raise 'The maths are broken!'
  end
  x % et
end

require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,a,b = gets.chomp.split.map(&:to_i)
require 'openssl'

def all(n)
  ret = 2.to_bn.mod_exp(n, MOD) - 1
  ret
end

def nck(n,k)
  ans = 1
  k.times do |i|
    ans = ans * (n-i) % MOD
    ans = ans * modinv(i+1, MOD) % MOD
  end
  ans
end

ans = all(n) - nck(n,a) - nck(n,b)
while ans < 0
  ans += MOD
end
puts (ans + MOD)%MOD


Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
bool flag;
int main(){
	cin>>a>>b;
	if(a>b){
		for(int i=b;i<=a;i++){
		if((a*b*i)%2!=0){
			flag=1;
			break;
		}
	}
	}
	else{

	for(int i=a;i<=b;i++){
		if((a*b*i)%2!=0){
			flag=1;
			break;
		}
	}
}



	if(flag==0) printf("No");
	else printf("Yes");
	return 0;
}


Measured memory_bytes: 256
def calc_hist(array)
  hist = Array.new(10){ 0 }
  array.each{|v|
    hist[v.to_i] += 1
  }
  return hist
end

#
# ??????????????????????????\????????? true
#
def too_many_pai(hist)
  hist.each{|v|
    return true if v > 4
  }
  return false
end

def is_agari(hist, not_yet_atama)
  delete_zero = hist.dup.delete_if{|v| v == 0}
  return true if delete_zero.empty?
  cur_pai = hist.find_index(delete_zero[0])
  
  # ????
  if not_yet_atama && hist[cur_pai] >= 2
    hist[cur_pai] -= 2
    result = is_agari(hist, false)
    return true if result == true
    hist[cur_pai] += 2
  end

  # ???????
  if hist[cur_pai] >= 3
    hist[cur_pai] -= 3
    result = is_agari(hist, not_yet_atama)
    return true if result == true
    hist[cur_pai] += 3
  end

  # ???????
  if cur_pai <= 7 && hist[cur_pai+1] > 0 && hist[cur_pai+2] > 0 
    hist[cur_pai  ] -= 1
    hist[cur_pai+1] -= 1
    hist[cur_pai+2] -= 1
    result = is_agari(hist, not_yet_atama)
    return true if result == true
    hist[cur_pai  ] += 1
    hist[cur_pai+1] += 1
    hist[cur_pai+2] += 1
  end

  return false

end

ARGF.each{|line|
  pai = line.chomp.split(//).map{|c| c.to_i}
  hist = calc_hist(pai)

  # p pai
  # p hist

  ans = []
  (1..9).each{|c|
    hist2 = hist.dup
    hist2[c] += 1

    next if too_many_pai(hist2)

    not_yet_atama = true
    if is_agari(hist2, not_yet_atama)
      ans << c
    end
  }
  if ans.empty?
    puts "0"
  else
    puts ans.join(' ')
  end
}

Measured memory_bytes: 8880
#include <iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

ll GCD(ll m, ll n) { return n?GCD(n,m%n):m; }

vector<pair<ll, int>> Factrize(ll n) {
	vector<pair<ll, int>> ans;
	for (ll i = 2; i*i <= n;++i) {
		if (n%i)continue;
		else ans.emplace_back(i,0);
		while (n%i==0) {
			n /= i;
			ans.back().second++;
		}
	}
	if (n != 1)ans.emplace_back(n,1);
	return ans;
}


int main() {
	ll A, B;
	cin >> A >> B;
	ll gcd;
	gcd = GCD(A,B);
	auto f = Factrize(gcd);
	int ans = f.size() + 1;
	cout << ans << endl;
		return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N, K;
	cin >> N >> K;
	int ans = pow(K - 1, N - 1) * K;
	cout << ans;
}

Measured memory_bytes: 512
N = int(input())
S = list(input())
S1 = []
S2 = S[1:]
n1 = 0
n2 = list.count(S2, 'E')
m = n1 + n2
for i in range(N-1):
    elem1 = S[i]
    elem2 = S[i+1]
    if elem1 == 'W':
        n1 = n1+1
    if elem2 == 'E':
        n2 = n2-1
    m = min(m, n1 + n2)

print(m)

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}

int main(){
  int n;cin >> n;
  cout << lcm(2,n) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define N 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,w,k,i,j, c = 1,a,b,z;
    cin>>h>>w>>k;
    string s[h];
    ll arr[h][w];
    for(i=0;i<h;i++)
        cin>>s[i];
    vector <ll> v[2];
    z = 0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
            if(s[i][j] == '#')
            {
                s[i][j] = '.';
                break;
            }
        if(j == w)
        {
            v[z].pb(i);
            continue;
        }
        z = 1;
        for(j=0;j<w;j++)
        {
            if(s[i][j] == '#')
                c++;
            arr[i][j] = c;
        }
        c++;
    }

    reverse(v[0].begin(), v[0].end());
    for(auto i : v[0])
    {
        for(j=0;j<w;j++)
            arr[i][j] = arr[i+1][j];
    }
    for(auto i : v[1])
    {
        for(j=0;j<w;j++)
            arr[i][j] = arr[i-1][j];   
    }
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
            cout<<arr[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1536
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val datN = readLine.split(" ").map(_.toInt).head
    val datA = readLine.split(" ").map(_.toLong).toList

    val ans = datA.sorted.reverse.slice(0, datN * 2).zipWithIndex.filter(_._2 % 2 == 1).map(_._1).sum

    println(ans)
  }
}


Measured memory_bytes: 113120
#include <bits/stdc++.h>
 
using namespace std;
 
const int c[] = {399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800};
 
int n,i,j,a[105],cnt[10];
 
int main(){
	scanf("%d", &n);
	
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < 9; j++){
			if(a[i] <= c[j]){
				cnt[j]++;
				break;
			}
		}
	}
	
	int tot = 0;
	
	for(i = 0; i < 8; i++)
	tot += (cnt[i] > 0);
	
	int minx = tot;
	int maxx = tot + cnt[8];
	
	if(cnt[8] && minx == 0)
	minx = 1;
	
	printf("%d %d\n", minx, maxx);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100007];
int main()
{
    cin>>n;

    int cnt=0,maxx=0;

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i&&(a[i-1]>=a[i]))
        {
            cnt++;
        }
        else cnt=0;
        maxx=max(maxx,cnt);
    }
    cout<<maxx<<endl;
    return 0;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>t(N+1), x(N+1), y(N+1);
	t[0] = 0;
	x[0] = 0;
	y[0];
	for (int i = 1; i <= N; i++)
	{
		cin >> t[i] >> x[i] >> y[i];
	}

	for (int i = 1; i <= N; i++)
	{
		int tmp = abs(x[i] - x[i - 1] + abs(y[i] - y[i - 1]));
		tmp = t[i] - t[i - 1] - tmp;
		if (tmp < 0 || tmp % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

int main() {
  int n, i, ans;
  double t, a, h, eps = 1000000;
  cin >> n >> t >> a;
  vector<double> T(n);
  for (i = 0; i < n; ++i) {
    cin >> h;
    T[i] = t - h * 0.006;
  }
  for (i = 0; i < n; ++i) {
    if (eps > abs(T[i] - a)) {
      ans = i + 1;
      eps = abs(T[i] - a);
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256