akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;
int main(){
  double N; cin >> N;
  long long n = floor(sqrt(N));
  if (n*n == N && N != 1) {
    n--;
  }
  long long ans = 0;
  for(long long r = 1; r <= n; r++) {
    //long long ar = N - r;
    //if (ar % r == 0) {
    if(N == r*(r+1)) continue;
    if ((long long)N % r == 0) {
      //ans = ans + (ar / r);
      ans = ans + N / r - 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

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

    int cnt = 0;
    REP(i, N - 2) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#define nl              "\n"
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define SIZE(a)         (int)a.size()
#define SORT(v)         sort(v.begin(),v.end())
#define RSORT(v)        sort(v.rbegin(),v.rend())
#define REV(v)          reverse(v.begin(),v.end())
#define ff              first
#define ss              second
#define sq(a)           ((a)*(a))
#define For(i,a,b)      for(i=a;i<=b;i++)
#define Rof(i,a,b)      for(i=a;i>=b;i--)
#define Rep(i,b)        for(i=0;i<b;i++)
#define MOD             1000000007
#define PI              acos(-1.0)
#define eps             1e-9
#define Linf            2e18
#define inf             1<<30
#define MX5             100005
#define MX6             1000006
#define GCD(a,b)	    __gcd(a,b)
#define Abs(a)		    abs(a)
#define input(a,b)	    scanf("%lld%lld",&a,&b)
#define in1(a)		    scanf("%lld",&a)
#define output(a)	    printf("%lld\n",a);
#define mem(a)          memset(a,-1,sizeof(a))
#define clr(a)          memset(a,0,sizeof a)
#define mk              make_pair
#define pLL             pair<ll,ll>
#define ff              first
#define ss              second
#define invcos(a)	    (acos(a)*(180/3.14159265))
#define pip		        printf("pip")
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
///8direction ->        int del_x[]={-1,0,1,0,1,-1,-1,1},del_y[]={0,1,0,-1,-1,-1,1,1};


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

//ll bigmod(ll n,ll p){if(p==0) return 1;if(p==1)return (n+mod)%mod;if(p%2)return (bigmod(n,p-1)*n+mod)%mod;else{ll x=bigmod(n,p/2);return (x*x+mod)%mod;}}
//ll modinverse(ll n){return bigmod(n,mod-2)%mod;}

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/
int main()
{
    ll n,a,b;
    in1(n);
    input(a,b);
    a*=n;

    output(min(a,b));
}




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

int main() {
	int n,i,m,p,x,cur=0,ans=0;
	cin >> n;
	vector<int> t(n);
	for(i=0; i<n; i++){
		cin >> t[i];
		cur+=t[i];
	}
	cin >> m;
	for(i=0; i<m; i++){
		cin >> p >> x;
		ans=cur-t[p-1]+x;
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
int main() {
	int a, b, k; cin >> a >> b >> k;
	int d = 0;
	int ans = 0;
	for (int i = min(a,b); i >=1; i--) {
		if (a % i == 0 && b % i == 0) {
			d++;
			if (d == k) {
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

  int N, K; cin>>N>>K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
	A[i] -= 1;
    if (i > 0)
      A[i] += A[i-1];
    A[i] %= K;
  }

  unordered_map<int, size_t> cands;
  for (int i = 0; i < min(K-1, N); i++)
    cands[A[i]]++;
  long ans = cands[0];
  for (int i = 0; i < N-1; i++) {
	if (i+K-1 < N)
	  cands[A[i+K-1]]++;
    ans += --cands[A[i]];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9288
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let N = readInt()

seq {
  for i in 1..N do
    if i%3<>0&&i%5<>0 then yield (int64 i)
}
|> Seq.sum
|> printfn "%d"

Measured memory_bytes: 30040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int par[2111111],ran[2111111];
void init(int n){
	rep(i,n){
		par[i]=i;
		ran[i]=0;
	}
}
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(ran[x]<ran[y])par[x]=y;
	else{
		par[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}
int n,m;
int k,a;
signed main(){
	cin>>n>>m;
	init(n+1111000);
	rep(i,n){
		cin>>k;
		rep(j,k){
			cin>>a;
			unite(i,a+1000000);
		}
	}
	rep(i,n-1){
		if(!same(i,i+1)){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 20736
n,m=map(int,input().split())
ks=[]
for i in range(m):
    ks.append(list(map(int,input().split())))
p=list(map(int,input().split()))
ans=0
bi="1"*n
for i in range(int(bi,2)+1):
    c="0"*(n-len(bin(i))+2)+bin(i)[2:]
    #ここで1つ1つの電球に注目
    for j in range(m):
        sum=0
        for l in range(ks[j][0]):
            sum+=int(c[ks[j][l+1]-1])
        if sum%2!=p[j]:
            break
        if j==m-1:
            ans+=1
print(ans)


Measured memory_bytes: 3064
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static long B;
  static long C;
  // static int[][] map;
  static double min = 9999999;
  static long ans = 0;

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

    int N = scanner.nextInt();
    int[] map = new int[N];

    int[] tree = new int[N];

    for (int i = 0; i < N; i++) {
      tree[i] = scanner.nextInt();
    }

    map[0] = 0;
    map[1] = Math.abs(tree[0] - tree[1]);

    for (int i = 2; i < N; i++) {
      map[i] = Math.min(map[i - 1] + Math.abs(tree[i - 1] - tree[i]),
              map[i - 2] + Math.abs(tree[i - 2] - tree[i]));
    }

    System.out.println(map[N - 1]);

  }
}


Measured memory_bytes: 60548
#include <iostream>
#include <string>

using namespace std;

int main()
{

    string s;
    cin >> s;
    int flg_a = 0, flg_b = 0, flg_c = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'a')
        {
            flg_a++;
        }
        else if (s[i] == 'b')
        {
            flg_b++;
        }
        else if (s[i] == 'c')
        {
            flg_c++;
        }
    }
    if (flg_a == 1 && flg_b == 1 && flg_c == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
L = []
for i in range(n):
  L.append(list(map(int, input().split())))
  
L.sort(key=lambda store: store[0])
price = 0
for i in range(n):
    price += L[i][0] * min(m, L[i][1])
    m -= min(m, L[i][1])
    if m <= 0:
      print(price)    
      exit()

Measured memory_bytes: 29024
#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

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

  vector<double> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  ll sum = 0;
  // rep(i, n) cout << v.at(i);
  rep(i, n - 1) { v.at(i + 1) = (v.at(i) + v.at(i + 1)) / 2; }
  cout << v.at(n - 1);

  return 0;
}
 

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int A, B, C, X, Y;
int main(int argc, char const *argv[])
{
    cin >> A >> B >> C >> X >> Y;
    int first=A*X+B*Y;
    int second=C*2*X+max(Y-X,0)*B;
    int third=C*2*Y+max(X-Y,0)*A;
    int ans=min(first,min(second,third));
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> p64;
typedef vector<ll> v420;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define mem(x, y) memset(x, y, sizeof(x))
#define DANGER                        \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

int main()
{
    int n, k;
    cin >> n >> k;
    v420 v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<ll> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i + j < n)
            {
                dp[i + j] = min(dp[i + j], dp[i] + abs(v[i] - v[i + j]));
            }
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define p(x) cout << x << endl;
#define all(v) (v).begin(), (v).end()

#define MOD 1000000007
#define PI 3.14159265359

int a[256][256];

int like[100] = {0};

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

    int n, m;
    cin >> n >> m;

    int k[n];

    for(int i = 0; i < n; i++){
        cin >> k[i];
        for (int j = 0; j < k[i]; j++){
            cin >> a[i][j];
        }
    }

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

    int cnt = 0;
    for (int i = 1; i <= m; i++){
        if(like[i] == n){
            cnt++;
        }
    }
    
    p(cnt);
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll N; cin >> N; int cnt = 0;
  while(N>1){
    N/=2; cnt++;
  }
  cout << (ll)pow(2, cnt+1) - 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------


int main(void)
{
	float h,a;
	cin>>h>>a;

	cout<<ceil(h/a)<<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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

    int n,h,w;cin>>n>>h>>w;
    cout<<(n+1-h)*(n+1-w)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    if(n%1000!=0)
    System.out.println(1000-(n%1000));
    else
      System.out.println("0");
  }
}

Measured memory_bytes: 35672
import sys
for l in sys.stdin:
  H, W = map(int,l.split())
  if H == 0 and W == 0:
    break
  for i,h in enumerate(range(H)):
      if i != 0 and i!=H-1:
          print ('#' + ('.' * (W -2)) +'#')
      else:
          print ('#' * W)
  print ('')

Measured memory_bytes: 6424
import heapq
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n):
  res = 0
  for x in a:
    res += (n-x)**2
  return res

N = I()
a = IL()

ans = MAX_INT
for i in range(1,101):
  ans = min(ans, tami(i))
print(ans)

Measured memory_bytes: 38512
s = input()
max = 0
for i in range(len(s)):
    c = 0
    if s[i] != 'A' and s[i] != 'T' and s[i] != 'G' and s[i] != 'C':
        continue
    c += 1
    for j in range(i + 1, len(s)):
        if s[j] == 'A' or s[j] == 'T' or s[j] == 'G' or s[j] == 'C':
            c += 1
        else:
            break
    if max < c:
         max = c
print(max)

Measured memory_bytes: 3060
/*
(͡ ° ͜ʖ ͡ °): Hi, be careful of overflow.
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define v(x) vector<x>
#define pb push_back 
#define mp make_pair
#define maxint 1e18
#define mint -1e18

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(auto &i:a)cin>>i;
	int mx = 0;
	ll res = 0;
	for(int i=0;i<n;i++){
		if(a[i]< mx){
			res += mx - a[i];
		}else mx = max(mx,a[i]);
	}
	cout<<res<<'\n';
	return 0;
}

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

long long a,b,ans=0,xorsum=0;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a&1){
		long long len=b-(a+1)+1;
		len%=4;
		for(int i=len;i>=1;i--){
			ans^=b;		
			b--;
		}
		ans^=a;
	}
	else{
		long long len=b-a+1;
		len%=4;
		for(int i=len;i>=1;i--){
			ans^=b;
			b--;	
		}
	}
	cout<<ans<<endl;		
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;


int main() {
	int N;
	std::cin >> N;
	std::vector<int>sum(N), sort(N);
	for (int i = 0; i < (N - 1)*N / 2; i++) {
		int a, b, c, d;
		std::cin >> a >> b >> c >> d;
		if (c > d) {
			sum[a - 1] += 3;
		}
		else if (d > c) {
			sum[b - 1] += 3;
		}
		else {
			sum[a - 1] += 1;
			sum[b - 1] += 1;
		}
	}
	for (int i = 0; i < N; i += 1) {
		sort[i] = sum[i];
	}
	std::sort(sort.begin(), sort.end());
	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j >= 0; j -= 1) {
			if (sum[i] == sort[j]) {
				std::cout << N - j << std::endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3152
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

string dp[11000];
int num[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
  REP(i, 11000) dp[i] = "#";
  dp[0] = "";
  int N, M; cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  REP(i, N) {
    REP(j, M) {
      if (dp[i] == "#") continue;
      string& s = dp[i + num[A[j]]];
      string t = dp[i] + (char)(A[j] + '0');
      if (s.size() < t.size() || (s.size() == t.size() && s < t)) {
        s = t;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 45056
#include<iostream>
#include"bits/stdc++.h"
#include<math.h>
#include<string.h>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve()
{
	int n,flag=0;
	cin>>n;
	while(n>0)
	{
		int x=n%10;
		if(x==7)
			{
				flag=-1;
			}
		n=n/10;
	}
	if(flag==-1)
		cout<<"Yes";
	else
		cout<<"No";
}
void solve1()
{
	ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0)
			continue;
		if(i%5==0)
			continue;
		sum+=i;
	}
	cout<<sum;
}

int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);

}
void solve2()
{
	ll k,sum=0;
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int p=1;p<=k;p++)
			{
				sum+=gcd(gcd(i,j),p);
			}
		}
	}
	cout<<sum;
}
void solve3()
{
	ll n,count[4]={0};
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
			count[1]++;
		if(s[i]=='G')
			count[2]++;
		if(s[i]=='B')
			count[3]++;
	}
	ll count1=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i-1,k=i+1;(j>=0)&&(k<n);j--,k++)
		{
			if((s[i]!=s[j])&&(s[i]!=s[k]))
			{
				if(s[j]!=s[k])
					count1++;
			}
		}
	}
	cout<<count[1]*count[2]*count[3]-count1;
}
int main()
{
	fastio();
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	//solve();
	//solve1();
	//cout<<gcd(gcd(10,30),10);
	solve3();
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/


int main(){
    int n;
    sf(n);
    int arr[n+3],brr[n+3];

    for(int i=1; i<=n; i++) sf(arr[i]);
    for(int i=1; i<=n; i++) brr[arr[i]] = i;
    for(int i=1; i<n; i++) pf("%d ",brr[i]);
    pf("%d\n",brr[n]);

    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 1e5 + 500;

int a[N], n;

int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++)
		scanf("%d", a + i);
	sort(a, a + n);
	reverse(a, a + n);
	int pivot = 0;
	while(a[pivot] > pivot + 1)
		pivot++;
	int ans = 0;
	if(a[pivot] == pivot + 1){
		if(a[pivot + 1] == a[pivot]){
			int jos = pivot;
			while(a[pivot] == a[jos])
				jos++;
			jos--;
			ans = (jos - pivot) % 2;			
		}
		else{
			ans = 0;
		}
	}
	else{
		if(a[pivot - 1] == a[pivot]){
			int jos = pivot;
			while(a[pivot] == a[jos])
				jos++;
			jos--;
			ans = (jos - pivot + 1) % 2;
		}
		else{
			ans = (a[pivot - 1] - pivot) % 2;
			if(pivot == a[pivot]){
				int jos = pivot;
				while(a[pivot] == a[jos])
					jos++;
				jos--;
				ans |= (jos - pivot + 1) % 2;	
			}
		}
	}
	printf(ans ? "First\n" : "Second\n");
}

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

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

}

Measured memory_bytes: 3916
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
l=[]
for i in range(n):
  if t[i] == 'r':
    l.append(p)
  elif t[i] == 's':
    l.append(r)
  else:
    l.append(s)

score=sum(l)
for j in range(k,n):
  if t[j] == t[j-k]:
    t[j]='-'
    score-=l[j]

print(score)

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

long long N, M, K, ANS = 0, MOD = 1000000007;
long long F[200010] = {}, RF[200010] = {};

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

void init() {
	F[0] = 1, F[1] = 1, RF[0] = 1, RF[1] = 1;
	for (int i = 2; i <= 200000; i++) {
		F[i] = F[i - 1] * i;
		F[i] = F[i] % MOD;
		RF[i] = Calc(F[i], MOD - 2);
		RF[i] = RF[i] % MOD;
	}
}

long long Comb(long long A, long long B) {
	long long RET = F[A];
	RET = RET * RF[B];
	RET = RET % MOD;
	RET = RET * RF[A - B];
	RET = RET % MOD;
	return RET;
}

int main() {
	cin >> N >> M >> K;
	init();
	for (int i = 0; i <= N; i++) {
		long long COUNT = i;
		COUNT *= Comb(N * M - 2, K - 2);
		COUNT = COUNT % MOD;
		COUNT *= ((N - i) * Calc(M, 2)) % MOD;
		COUNT = COUNT % MOD;
		ANS += COUNT;
		ANS = ANS % MOD;
	}
	for (int i = 0; i <= M; i++) {
		long long COUNT = i;
		COUNT *= Comb(N * M - 2, K - 2);
		COUNT = COUNT % MOD;
		COUNT *= ((M - i) * Calc(N, 2)) % MOD;
		COUNT = COUNT % MOD;
		ANS += COUNT;
		ANS = ANS % MOD;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

d = 10**9 + 7
n, m = map(int, input().split(' '))

ans = 0

ans1 = 1
n1 = n
m1 = m
while n1 >= 1:
    ans1 *= n1 * m1
    ans1 %= d
    n1 -= 1
    m1 -= 1

if m1 > 1:
    ans1 = 0

ans2 = 1
n2 = n
m2 = m
while m2 >= 1:
    ans2 *= m2 * n2
    ans2 %= d
    n2 -= 1
    m2 -= 1

if n2 > 1:
    ans2 = 0


print((ans1 + ans2) % d)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int a=0,b=0;
    rep(i,s.size()){
        if(i%2==0){
            if(s.at(i)=='0'){
                a++;
            }else{
                b++;
            }
        }else{
            if(s.at(i)=='0'){
                b++;
            }else{
                a++;
            }
        }
    }
    cout<<min(a,b)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    x = n%10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9){
        cout << "hon";
    }
    else if(x == 3){
        cout << "bon";
    }
    else{
        cout << "pon";
    }


    return 0;
}


Measured memory_bytes: 3608
n = int(input())
ans = []
if n % 2 == 0:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i + j != n+1:
                ans.append([i,j])
if n % 2 == 1:
    for i in range(1,n):
        for j in range(i+1,n+1):
            if i + j != n:
                ans.append([i,j])    
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    ll tmp=0;
    rep(i,m){
        ll a;cin>>a;
        tmp+=a;
    }
    ll res=n-tmp;
    if(res<0)cout<<-1<<endl;
    else cout<<res<<endl;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  string s; cin >> s;
  vector<pair<char, int> > a;
  char now = s.front();
  int cnt2 = 1;
  FOR(i, 1, n) {
    if (s[i] != now) {
      a.emplace_back(now, cnt2);
      now = s[i];
      cnt2 = 1;
    } else {
      ++cnt2;
    }
  }
  a.emplace_back(now, cnt2);
  // vector<int> sum(a.size() + 1, 0);
  // FOR(i, 1, a.size()) sum[i] = sum[i - 1] + a[i - 1].second;
  int ans = 0, j = 0, tmp = 0, cnt = 0;
  REP(i, a.size()) {
    while (j < a.size() && (a[j].first == '1' ? true : cnt + 1 <= k)) {
      tmp += a[j].second;
      if (a[j].first == '0') ++cnt;
      ++j;
    }
    ans = max(ans, tmp);
    if (i == j) {
      if (a[j].first == '0') ++cnt;
      tmp += a[j].second;
      ++j;
    }
    tmp -= a[i].second;
    if (a[i].first == '0') --cnt;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1528
#include<stdio.h>

int main(){
	int i,j,k,l,a,b,n,m,N[100][100],M[100],A[100]={0};
	scanf("%d %d",&n,&m);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			scanf("%d",&N[i][j]);
		}
	}
	
	for(k = 0; k < m; k++){
		scanf("%d",&M[k]);
	}
	
	for(l = 0; l < n; l++){
		for(a = 0; a < m; a++){
			A[l] += N[l][a] * M[a];
		}
	}
	
	for(b = 0; b < n; b++){
		printf("%d\n",A[b]);
	}
	
	return 0;
}


Measured memory_bytes: 2108
day = gets.to_i
jap = gets.to_i
eng = gets.to_i
tjap = gets.to_i
teng = gets.to_i
rjap = jap/tjap
rjap +=	1 if jap % tjap	!= 0
reng = eng/teng
reng +=	1 if eng % teng	!= 0
if rjap > reng
  i = rjap
else
  i = reng
end
p (day-i)




Measured memory_bytes: 6868
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define debug(x) if(MODE==x && x!=0)
#define MODE 0

using namespace std;

int N;
int bit[100007]={};

void add(int x, int d)
{
    while(x<=N)
    {
        bit[x] += d;
        x += x&(-x);
    }
}

int sum(int x)
{
    int s = 0;
    while(x)
    {
        s += bit[x];
        x -= x&(-x);
    }
    return s;
}

int query(int L, int R)
{
    if(L>R)
        swap(L,R);
    return sum(R) - sum(L-1);
}

int bs1( int L, int R, int x, int y)
{
    debug(0) printf(">>>(%d,%d)\n",L,R);
    if( L>R)
        return 0;
    if( L==R)
        return L;
    int M = (L+R)/2;
    if( query(M,x)==y )
        return bs1(   L, M, x, y);
    else
        return bs1( M+1, R, x, y);
}

int bs2( int L, int R, int x, int y)
{
    debug(1) printf(">>>(%d,%d)\n",L,R);
    if(L>R)
        return 0;
    if(L==R)
        return L;
    int M = (L+R)/2;
    if( query( x, M+1)==y )
        return bs2( M+1, R, x, y);
    else
        return bs2(   L, M, x, y);
}

int P[100007];
int chart[100007];

int main()
{
    int i,j;

    scanf("%d",&N);
    for( i=1; i<=N; i++)
    {
        scanf("%d",&P[i]);
        chart[P[i]] = i;
    }

    LLI total = 0;

    add(chart[N],1);
    for( i=N-1; i>=1; i--)
    {
        int idx = chart[i];
        int l = bs1(1,idx,idx,0);
        int r = bs2(idx,N,idx,0);
        LLI sum = 0;
        if( l!=1)
        {
            int ll = bs1(1,l-1,idx,1);
            debug(1) printf("1>>>(%d,%d,%d,%d)\n",ll,l,idx,r);
            sum += (l-ll) * (r-idx+1);
        }
        if( r!=N)
        {
            int rr = bs2(r+1,N,idx,1);
            debug(1) printf("2>>>(%d,%d,%d,%d)\n",l,idx,r,rr);
            sum += (idx-l+1) * (rr-r);
        }
        total += sum * i;
        debug(1) printf("\n",l,r);
        add(idx,1);
    }

    printf("%lld\n",total);




    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<numeric>
#include<cmath>
#include<vector>
#include<string>

using namespace std;
/*
int main() {
	int A, N,answer;
	cout << "N,Aを入力。" << endl;
	cin >> N >> A;
	answer = N % 500;
	if (A>=1)
	{
		answer %= 1;
		if (answer==0)
		{
			cout << "Yes" << endl;
		}
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}
*/
int main() {
	int  E,s; 
	
	cin >> E >> s;
	if (E > 8 || s > 8)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!"<<endl;
	}
	return 0;
}

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

int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    while(true){
        if(A == B && B == C && A % 2 == 0){
            ans = -1;
            break;
        }
        if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1) break;
        ans++;
        ll nc = (A+B)/2;
        ll na = (C+B)/2;
        ll nb = (A+C)/2;
        A = na; B = nb; C = nc;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  int n;
  string s;
  cin >> n >> s;

  while(n > al.size()){
    n -= al.size();
  }

  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < al.size(); j++){
      if(s[i] == al[j]){
        if((j + n) <= al.size() - 1){
          cout << al[j + n];
        }
        else{
          cout << al[j + n - al.size()];
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
while true    #loop でも使える
m,f,r=gets.split(" ").map(&:to_i)
break if m==-1 && f==-1 && r==-1        #全て欠席[－１]の場合動かない

grade="F"           #グレード化にする
if m == -1 or f == -1   #m or f どっちか　－１の場合(||でもつかえる)

elsif m + f >=80            #値を選べる
    grade= "A"
elsif m + f >=65
    grade= "B"
elsif m + f>=50
    grade="C"
elsif m + f>=30
    if r >= 50               #mとfが３０より大きい場合またｒが５０より大きければ
        grade= "C"          #Cにもどる
    else
        grade= "D"          #じゃなければ　D
    end
end
puts grade                  #最後で結果
end







Measured memory_bytes: 6876
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            int ans = 0;
            if ( a>b)
            {
                ans = a;
                a--;
            }
            else
            {
                ans = b;
                b--;
            }

            if ( a>b)
            {
                ans += a;
            }
            else
            {
                ans += b;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

long long fibo(int n){
	long long fibodp[200] = {0};
	fibodp[0] =1;
	fibodp[1] =1;
	for(int i=2;i<=n;i++)
		fibodp[i] = fibodp[i-1] + fibodp[i-2];
	return fibodp[n];
}


int main(void){
	int n;
	scanf("%d",&n);
	printf("%lld\n",fibo(n));
	return 0;
	}
	


Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	if (s.length() <= k)
	{
		println(s);
	}
	else
	{
		println(s.substr(0, k) << "...");
	}
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

int main() {
	int A, B; cin >> A >> B;
	if (A <= 9 && B <= 9) {
		cout << A*B << endl;
	} else {
		cout << "-1" << endl;
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

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

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 29; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

	priority_queue<pair<int,int>> que;

	rep(i,n) { 
	  int a;
	  cin >> a;
		que.push({a,1});
	}

	rep(i, m) {
		int b, c;
		cin >> b >> c;
		que.push({c,b});
	}

	ll k = 0, ans = 0;
	while (k < n) {
	  pair<int,int> a = que.top();
		//cout << a.first << "," << a.second << endl;
		que.pop();
		ans += a.first * min((ll)a.second, n - k);
		k += a.second;
	}

	cout << ans;
}


Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int like[100001];

int main(){
	int n;
	cin >> n;
	
	for(int i = 1;i <= n;i++){
		like[i] = -1;
	}
	
	int res = 0;
	for(int i = 1;i <= n;i++){
		int a;
		cin >> a;
		
		like[i] = a;
		if(like[a] == i){
			res++;
		}
	}
	
	cout << res << endl;
	
	return 0;
}

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

using namespace std;

int gcd(int x, int y) {
    if(x < y) {
        swap(x, y);
    }

    while(y > 0) {
        int r = x % y;
        x = y;
        y = r;
    }

    return x;
}

int gcd_cache(int x, int y, int z, int ***cache) {
    if(y < x) {
        swap(x, y);
    }
    if(y < z) {
        swap(y, z);
        if(y < x) {
            swap(x, y);
        }
    }

    if(cache[x][y][z] == -1) {
        int n = gcd(x, y);
        cache[x][y][z] = gcd(n, z);
    }
    return cache[x][y][z];
}

int main() {
    int n;
    cin >> n;
    int ***cache = new int **[n + 1];
    for(int i = 0; i <= n; i++) {
        cache[i] = new int *[n + 1];
        for(int j = 0; j <= n; j++) {
            cache[i][j] = new int[n + 1];
            for(int k = 0; k <= n; k++) {
                cache[i][j][k] = -1;
            }
        }
    }

    long long sum = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                sum += gcd_cache(i, j, k, cache);
            }
        }
    }
    cout << sum << endl;
}


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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  vector<int> A(n), cs;
  for (int i = 0; i < n; ++i) {
    cin >> A[i], --A[i];
    if (A[i] != i) cs.push_back(i);
  }
  if (cs.empty()) cout << "YES\n";
  else if (cs.size() != 2) cout << "NO\n";
  else {
    swap(A[cs[0]], A[cs[1]]);
    if (is_sorted(A.begin(), A.end())) cout << "YES\n";
    else cout << "NO\n";
  }

}


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

const int MAXN = 3e5;
int N;
vector<int> adj[MAXN];
pair<int, int> furthest(int cur, int prv = 0) {
	pair<int, int> ans(0, cur);
	for (int nxt : adj[cur]) {
		if (nxt == prv) continue;
		auto res = furthest(nxt, cur);
		res.first++;
		ans = max(ans, res);
	}
	return ans;
}

int diameter() {
	return furthest(furthest(1).second).first;
}

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

	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	cout << ((diameter() + 1) % 3 == 2 ? "Second" : "First") << '\n';

	return 0;
}


Measured memory_bytes: 29184
h,w,k=map(int,input().split())
sl=[input() for _ in range(h)]
ans=[[0]*w for _ in range(h)]
tl=[0]*h
c=1
for i in range(h):
    flg=False
    for j in range(w):
        if sl[i][j]=='#':
            ans[i][j]=c
            c+=1
            flg=True
    if flg:
        tl[i]=1
c=1
for i in range(h):
    if tl[i]==0:
        continue
    flg=False
    for j in range(w):
        if sl[i][j]=='#':
            if flg:
                c+=1
            flg=True
        ans[i][j]=c
    c+=1
for i in range(h):
    if tl[i]==1:
        ta=ans[i][:]
        break
for i in range(h):
    if tl[i]==0:
        ans[i]=ta[:]
    else:
        ta=ans[i][:]
for i in range(h):
    print(' '.join(map(str,ans[i])))

Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=998244353;

int a[50]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>k;
    cout<<a[k-1]<<'\n';









}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100007;
int a,b,c,x,y,ans;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	int ch1=x*a+y*b,ch2=0,ch3=0;
	ans=ch1;
//	if(a+b>2*c){
		if(x>y){
			ch2=(x-y)*a+y*2*c;
			ch3=2*x*c;
		}
		else{
			ch2=(y-x)*b+x*2*c;
			ch3=2*y*c;
		}
		ans=min(ans,ch2);
		ans=min(ans,ch3);
//	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(void) 
{
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<b)
  printf("a < b\n");
  else if(a > b)
  printf("a > b\n");
  else
  printf("a == b\n");
  return 0;
}


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

using namespace std;

/**************************************************************/

#define int long long
#define tie() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i,from,to) for(int i = from ; i <to ; i++)
#define mem(a , v) memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define what_is(x) cerr << #x << " is : " << x <<endl

const int INF = 1e9 + 7;
const int sz = 1e5 + 20;
const int N =1e5 + 20;
/***************************************************************/

void solve()
{
    int tak , aoki , k;
    cin >> tak >> aoki >> k;

    if(k < tak)
    {
        cout << tak - k <<  " "  << aoki << endl;
    }
    else
    {
        cout << 0 << " " << max( 0ll , aoki - k + tak) << endl;
    }
    return;
}


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


Measured memory_bytes: 256
def solve(x):
    a= int(x[-1])
    if a in [2,4,5,7,9]:
        return ("hon")
    elif a in [0,1,6,8]:
        return ("pon")
    else:
        return "bon"



if __name__ == "__main__":
    x = input()
    print(solve(x))



Measured memory_bytes: 9012
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)1e6+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

string s;
int l, r;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> s;
	r = sz(s) - 1;
	int res = 0;
	while(l < r) {
		if(s[l] == s[r]) {
			l++, r--; continue;
		}
		if(s[l] != 'x' && s[r] != 'x') {
			cout << -1 << nxtl; return 0;
		}
		res++;
		if(s[l] == 'x') l++;
		else r--;
	}
	cout << res << nxtl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define len(x) int((x).size())
#define res(x) cout << ((x) ? "YES\n" : "NO\n" )
#define st first
#define nd second

typedef long long int integer;
typedef long double doble;

void solution() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	int x;
	while(n--) {
		cin >> x;
		if(x >= k) {
			ans++;
		}
	}
	cout << ans;
}
 
int main(){
	int t = 1;
	//cin >> t;
	while(t--) solution();
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int n,m,ans;
    while (~scanf("%d %d",&n,&m)) {
        ans = 0;
        REP(i,1,2) {
            ans += max(n,m);
            if (n==max(n,m)) n--;
            else m--;
        }
        printf("%d\n", ans);
    }
    
    return 0;
}


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

int main() {
    int n, x;

    while(true) {
	cin >> n >> x;
	if(n == 0 && x == 0) {
	    break;
	}

	int count = 0;

	for(int i=1; i<n; i++) {
	    for(int j=i+1; j<n; j++) {
		int k = x - i -j;
		if(k > j && k <= n) {
		    count++;
		}
	    }
	}

	cout << count << endl;
    }

    return 0;
}

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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  int numOdd = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] % 2) numOdd++;
  }
  cout << ((numOdd % 2) ? "NO" : "YES") << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353



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

    // solution comes here

    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    deque<ll> b;
    rep(i, N) {
        if(i%2) b.PB(A[i]);
        else    b.push_front(A[i]);
    }

    if(N%2) {
        rep(i, N-1) cout << b[i] << " ";
        cout << b[N-1] << nl;
    }
    else {
        rep(i, N-1) cout << b[N-1-i] << " ";
        cout << b[0] << nl;
    }
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int gcdo(int a, int b){
    if(a<b) swap(a,b);
    int r=1;
    while(r){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main(){
    int n,x; cin >> n >> x;
    vector<int> p(n);
    rep(i,n){
        int d; cin >> d;
        p[i]=abs(x-d);
    }
    int ans;
    if(n==1) ans=p[0];
    else ans=gcdo(p[0],p[1]);
    for(int i=2; i<n; i++){
        ans = gcdo(ans,p[i]);
    }
 
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> cnt(26, MOD);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		vector <int> c(26);
		for (char g : s) {
			c[g - 'a']++;
		}
		for (int j = 0; j < 26; j++) {
			cnt[j] = min(cnt[j], c[j]);
		}
	}
	for (int i = 0; i < 26; i++) {
		while (cnt[i] > 0) {
			cout << char('a' + i);
			cnt[i]--;
		}
	}
}



Measured memory_bytes: 256