akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
S=input()

DP = [[0]*(N+1) for i in range(N+1)]
for j in range(1, N)[::-1]:
    for i in range(0, j)[::-1]:
        if S[i] == S[j]:
            DP[i][j] = DP[i+1][j+1] + 1
        else:
            DP[i][j] = 0

# print(DP)
res = 0
for i in range(N-1):
    for j in range(i+1,N):
        res = max(res, min(DP[i][j], j-i))
print(res)


Measured memory_bytes: 231560
#include <bits/stdc++.h>
using namespace std;
using ll =  long long;
const ll INTF = 1e9 + 7;

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

   int v[25][25];
   for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
        cin >> v[i][j];

    vector<int> dp(1<<n);
    dp[0] = 1;
    for(int mask=0; mask<(1<<n)-1; mask++)
    {
        int a = __builtin_popcount(mask);
        for(int i=0; i<n; i++)
        {
            if(v[a][i] && !(mask & (1<<i)))
            {
                int nm = mask | (1<<i); 
                dp[nm] = (dp[nm] + dp[mask])%INTF;
            }
        }
    }

    cout<<dp[(1<<n)-1];
    return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
    ll h, w;

    cin >> h >> w;

    ll ans = INF;
    
    for(ll i = 1; i < h; i++){
        ll a, b, c;

        a = w * i;
        b = (h - i + 1) / 2 * w;
        c = (h - i) / 2 * w;

        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
        b = (h - i) * ((w + 1) / 2);
        c = (h - i) * (w / 2);

        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }

    ll t;
    t = h;
    h = w;
    w = t;

    for(ll i = 1; i < h; i++){
        ll a, b, c;

        a = w * i;
        b = (h - i + 1) / 2 * w;
        c = (h - i) / 2 * w;

        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));

        b = (h - i) * ((w + 1) / 2);
        c = (h - i) * (w / 2);

        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }

    cout << ans << endl;
}

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

int main() {
    int n, d;
    cin>>n >>d;
    int ans=0;
    vector<long> x(n);
    vector<long> y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        if(sqrt((x[i]*x[i])+(y[i]*y[i])*1.0)<=d) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6484
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

int main() {
    ll n;
    cin >> n;
    pii ab[2 * n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ab[i] = pii(a, 1);
    }
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        ab[i + n] = pii(b, -1);
    }
    sort(ab, ab + 2 * n);
    ll ans = 1;
    ll tmp = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (ab[i].second == 1) {
            if (tmp < 0) {
                ans = multiply(ans, abs(tmp));
            }
            tmp++;
        } else {
            if (tmp > 0) {
                ans = multiply(ans, tmp);
            }
            tmp--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll R, D, X;

int main() {
	scanf("%lld %lld %lld", &R, &D, &X);
	ll val = X;
	for(int i = 0; i < 10; i++) {
		val = R * val - D;
		printf("%lld\n", val);
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int a = ni(),b = ni();
        if(a<=5)b = 0;
        if(a<= 12)b/=2;
        pn(b);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long mod = (long)998244353, IINF = (long)1e18;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()/2;i++)
	{
		if(s[i]!=s[s.size()-i-1])
			ans++;
	}
	cout<<ans;
}

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

int extgcd(int a, int b, int &x, int &y){
  int d = a;
  if(b){
    d = extgcd(b, a%b, y, x);
    y -= (a / b)*x;
  }else{
    x = 1;
    y = 0;
  }
  return d;    
}

int main(){
  int n;
  cin >> n;
  int x, y;
  for(int i = 0; i < n; ++i){
    cin >> x >> y;
    int a, b;
    int d = extgcd(y, x, a, b);
    //cout << d << endl;
    if(d <= (int)5e4){
      printf("%d\n%d %d\n%d %d\n%d %d\n", 3, x, y, 0, 0, abs(a), abs(b));
    }else{
      printf("%d\n%d %d\n%d %d\n%d %d\n%d %d\n", 4, 0, 0, x, y-1, x/d, y/d, x-1, y);
    }
  }
  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int a[3];
  rep(i,3)cin>>a[i];
  sort(a,a+3);
  cout << a[2]*10+a[1]+a[0] << endl;
}


Measured memory_bytes: 3496
#include<bits/stdc++.h>
#define forn(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x)  cout<<it<<endl;
#define pi pair<int,int>
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define mem(a,x) memset(a,x,sizeof(a))
#define copy(b,a) memcpy(a,b,sizeof(a))
#define SZ(x) (int)x.size()
#define VI vector<int>
#define VII vector<pair<int,int>>
#define PI pair<int,int>
using namespace std;
typedef long long ll;
const ll P=998244353;
ll Mod(ll x,ll p=P) {return x%p;}
ll qpow(ll x,ll y,ll p=P){ll ans=1;for(x%=p;y;y>>=1,x=x*x%p)if(y&1) ans=ans*x%p;return ans;}
ll inv(ll x,ll p=P){return x<=1?1:(p-p/x)*inv(p%x,p)%p;}
ll sqrt2(ll x){ll l=1,r=2e9;while(l<r){ll mid=(l+r+1)>>1;if(mid*mid<=x) l=mid;else r=mid-1;}return l;}
ll sqrt3(ll x){ll y=(ll)(powl((long double)x,1.0/3.0)+0.5);while(y*y*y<x) y++;while(y*y*y>x) y--;return y;}
ll comb(ll n,ll m,ll p=P){if(m>n||n<0) return 0;if(m>n-m) m=n-m;ll ans=1;for(int i=1;i<=m;i++)ans=ans*n%p,ans=ans*inv(i,p),n--;return ans;}
ll comb(ll n,ll m){if(m>n||n<0) return 0;if(m>n-m) m=n-m;ll ans=1;for(int i=1;i<=m;i++)ans=ans*n,ans/=i,n--;return ans;}
ll ceil(ll x,ll y){return (x+y-1)/y;}
int lowerbit(int x) {return x&-x;}
int HighBit(int x){for(int i=30;i>=0;i--)if(x>>i&1) return i;return -1;}
char inline nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
template <typename T>
bool rd(T& v){static char ch;while(ch!=EOF && !isdigit(ch)) ch=nc();if(ch==EOF) return false;for(v=0;isdigit(ch);ch=nc())v=v*10+ch-'0';return true;}
template <typename T>
void o(T p){static int stk[70],tp;if(p==0) {putchar('0');return ;}if(p<0) {p=-p;putchar('-');}while(p) stk[++tp]=p%10,p/=10;while(tp) putchar(stk[tp--]+'0');}
const int maxn=1e5+5;
int dp[maxn][10];
int main(){
    forn(i,1,10)
        dp[1][i]=1;
    dp[1][0]=1;
    forn(i,2,1e5){
        forn(j,0,10){
            if(j) dp[i][j]+=dp[i-1][j-1];
            dp[i][j]+=dp[i-1][j];
            if(j!=9) dp[i][j]+=dp[i-1][j+1];
        }
    }
    int k;
    sc(k);
    vector<int> ans;
    int head=-1,len=-1;
    while(1){
        bool Find=false;
        for(int i=1;!Find;i++){
            for(int j=1;j<10 && !Find;j++)
                if(k>dp[i][j]) k-=dp[i][j];
                else {
                    Find=1;
                    head=j;
                    len=i;
                }
        }
        break;
    }
    //pf(head);
    len--;
    ans.pb(head);
    //pf(len);
    for(;len;len--){
        forn(i,0,10){
            if(abs(ans.back()-i)>1) continue;
            if(k>dp[len][i]) {
                k-=dp[len][i];
            }
            else {
                ans.pb(i);break;
            }
        }
    }
    for(auto it:ans)
        cout<<it;
    return 0;
}


Measured memory_bytes: 4096
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
count = 0
 
for i in range(N):
 
  if A[i] >= B[i]:
    count += B[i]
  else:
    B[i] = B[i] - A[i]
    count += A[i]
    if B[i] >= A[i+1]:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] = A[i+1] - B[i]
    
  
print(count)

Measured memory_bytes: 18624
using System;
using System.Collections.Generic;

namespace C_GoHome {
    class Program {
        static void Main(string[] args) {
            int X = int.Parse(Console.ReadLine());
            int x = 0;
            for (int i = 0; i <= X; i++) {
                x += i;
                if (x >= X) {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}


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

using ull = unsigned long long;
using ll = long long;
using namespace std;

ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}

int main(void) {
    int N;
    cin >> N;
    vector<int> s(N);

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

    sort(s.begin(), s.end(), greater<int>());
    int sumv = accumulate(s.begin(), s.end(), 0);

    if (sumv%10 != 0) {
        cout << sumv << endl;
        return 0;
    }

    for(int r = s.size() - 1; r >= 0; --r) {
        int attempt = sumv - s[r];
        if (attempt%10 != 0) {
            cout << attempt << endl;
            return 0;
        }
    }

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

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int v, w; };

int main() {
	int N; cin >> N;
	vector<int> p(N);
	rep(i, N) cin >> p[i];
	vector<bool> a(N + 2);
	for (int i = 1; i <= N; i++) a[i] = (p[i - 1] == i);
	vector<int> v;
	rep(i, N + 1) if (a[i] != a[i + 1]) v.pb(i);
	int M = v.size();
	int ans = 0;
	rep(k, M / 2) ans += (v[k * 2 + 1] - v[k * 2] + 1) / 2;
	cout << ans << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
ll SZ = 262144;
ll* seg = new ll[2*SZ]; //segtree implementation by bqi343's Github


ll combine(ll a, ll b) { return max(a, b); }

void build() { F0Rd(i,SZ) seg[i] = combine(seg[2*i],seg[2*i+1]); }

void update(int p, ll value) {  
    for (seg[p += SZ] = value; p > 1; p >>= 1)
        seg[p>>1] = combine(seg[(p|1)^1], seg[p|1]);
}

ll query(int l, int r) {  // sum on interval [l, r]
    ll resL = 0, resR = 0; r++;
    for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
        if (l&1) resL = combine(resL,seg[l++]);
        if (r&1) resR = combine(seg[--r],resR);
    }
    return combine(resL,resR);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vpl data(N);
    F0R(i, N) cin >> data[i].f >> data[i].s;

    sort(all(data));

    ll dp[N+1]; dp[N] = 1;

    map<ll, int> pos;
    F0R(i, N) pos.insert({data[i].f, i});
    F0R(i, 2*SZ) seg[i] = 0;

    F0Rd(i, N) {
        int last = (--(pos.lb(data[i].f+data[i].s)))->s;
        if (last > i) last = query(i+1, last);
        update(i, last);
        
        dp[i] = dp[i+1] + dp[last+1];
        dp[i] %= MOD;
    }

    cout << dp[0] << endl;
    
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 21504
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, T = MAP()
print(0--N//X*T)


Measured memory_bytes: 9976
def function(data):
    data = data.split(" ")
    a = int(data[0])
    b = int(data[1])
    if (a + b) % 2 == 1:
        print("IMPOSSIBLE")
    else:
        k = int((a + b) / 2)
        print(k)

if __name__ == '__main__':
  d = input()
  function(d)

Measured memory_bytes: 3060
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
mod = 10**9+7

a = [1] * (N+1)
for _ in range(M):
    a[int(input())] = 0

@lru_cache()
def f(x):
    v = 0
    if x<0:
        return 0
    if x == 0:
        return 1
    if a[x-1]:
        v += f(x-1)
    if a[x-2]:
        v += f(x-2)
    v %= mod
    return v

print(f(N))

Measured memory_bytes: 284200
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		long[] b = new long[n];
		for(int i = 0 ; i < n ; i++){
			a[i] = Integer.parseInt(sc.next()) - 1;
			b[a[i]]++;
		}
		sc.close();
		long yono = 0;
		for(int i = 0 ; i < n ; i++){
			yono += b[i] * (b[i] - 1) / 2;
		}
		for(int i = 0 ; i < n ; i++){
			ou.print(yono - b[a[i]] + 1 + "\n");
		}
		ou.flush();
	}
}

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

int main(){	
	int n ;
	register int nm;
	vector<int> v;
	cin>>n;
	nm=n;
	for(int i=2 ; i<=sqrt(n) ; i++){
		if(nm==1) break;
		if(nm%i==0){
			v.push_back(i);
			nm/=i;
			i--;
		}
	}
	if(v.empty()){
		v.push_back(n);
	} else {
		for(int i=(int)sqrt(n); i<=n ; i++){
			if(nm==1) break;
			if(nm%i==0){
				v.push_back(i);
				nm/=i;
				i--;
			}
		}
	}
	
	cout << n << ":";
	for(int i=0 ; i<v.size() ; i++){
		cout << " " <<v[i];
	}
	cout << endl;
	return 0;
}

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

//nCr
ll nCr(ll n,ll r){
    ll x=1;
    for(ll i=n; i>n-r; i--) x*=i;
    for(ll i=1; i<=r; i++) x/=i;
    return x;
}

int main() {
  ll n,p;
  cin>>n>>p;
  ll a;
  ll even=0, odd=0;
  rep(i,n){
    cin>>a;
    if(a%2==0){even++;}
    else{odd++;}
  }
  ll c=pow(2,even);
  ll b=0;
  if(odd==0&&p==1){b=0;}
  else if(p==0){
    for(ll i=0;i<=odd/2;i++){
      ll m= min(2*i, odd-2*i);
      b+=nCr(odd,m);
    }
  }
  else if(p==1){
    for(ll i;i<=(odd-1)/2;i++){
      ll m= min(2*i+1, odd-2*i-1);
      b+=nCr(odd,m);
    }
  }
  
  cout<<c*b;
  
}
      

Measured memory_bytes: 4072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191201
{
    static class D
    {
        static int ans;
        static int n;
        static string s;
        static int memoa;
        static int memob;
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            s = Console.ReadLine();
            ans = 0;
            int memoa = -1, memob = -1;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        if (memoa == -1) { Func(0, 0, i.ToString() + j.ToString() + k.ToString()); }
                        else if (memob == -1) { Func(1, memoa+1, i.ToString() + j.ToString() + k.ToString()); }
                        else { Func(2, memob+1, i.ToString() + j.ToString() + k.ToString()); }
                    }
                    memob = -1;
                }
                memoa = -1;
            }
            Console.WriteLine(ans);
        }
        static int Func(int depth, int index, string pin)
        {
            if (depth == 3) { ans++; return 1; }
            if (index == n) { return 0; }
            int a = 0;
            if (s[index] == (pin[depth])) {
                if (depth == 0) { memoa = index; }
                if (depth == 1) { memob = index; }
                if (depth == 2) { }
                return Func(depth + 1, index + 1, pin);
            }
           
            if (a == 1) { return 1; }
            Func(depth, index + 1, pin);
            return 0;
        }
    }
}


Measured memory_bytes: 12628
import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<List<Integer>> from = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      from.add(new ArrayList<>());
    }
    
    for (int i = 0; i < N-1; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      from.get(a-1).add(b-1);
      from.get(b-1).add(a-1);
    }
    int[] c = new int[N];
    for (int i = 0; i < N; i++) {
      c[i] = sc.nextInt();
    }
    Arrays.sort(c);
    
    int idx = N-1;
    int[] d = new int[N];
    boolean[] visit = new boolean[N];
    long M = 0;
    //PriorityQueue<Pair> q = new PriorityQueue<>((a,b)->b.b-a.b);
    Queue<Pair> q = new LinkedList<>();
    d[0] = c[idx--];
    q.offer(new Pair(0, d[0]));
    visit[0] = true;
    while (!q.isEmpty()) {
      Pair now = q.poll();
      for (int next : from.get(now.a)) {
        if (!visit[next]) {
          d[next] = c[idx--];
          M += Math.min(d[now.a], d[next]);
          q.offer(new Pair(next, d[next]));
          visit[next] = true;
        }
      }
    }
      
    StringBuilder ans = new StringBuilder();
    ans.append(M+"\n");
    for (int i = 0; i < N; i++) {
      ans.append(d[i]);
      if (i < N-1) {
        ans.append(' ');
      } else {
        ans.append('\n');
      }
    }
    System.out.print(ans.toString());
  }
  
  private static class Pair {
    private final int a;
    private final int b;
    private Pair(int a, int b) {
      this.a = a;
      this.b = b;
    }
  }
}

Measured memory_bytes: 46900
import java.util.Scanner;

//Smart Calculator
public class Main{

	static char[] s;
	static int id;
	
	static int exp(){
		int r = term();
		while(true){
			char c = s[id++];
			if(c=='+')r+=term();
			else if(c=='-')r-=term();
			else break;
		}
//		id--;
		return r;
	}
	
	static int term(){
		int r = fact();
		while(true){
			char c = s[id++];
			if(c=='*') r*=fact();
			else if(c=='/')r/=fact();
			else break;
		}
		id--;
		return r;
	}
	
	static int fact(){
		char c = s[id++];
		if(c=='(')return exp();
		if(c=='-'){
			return -fact();
		}
		if(c=='+'){
			return fact();
		}
		int x = c-'0';
		while(true){
			c = s[id++];
			if(Character.isDigit(c)){
				x *= 10;
				x += c-'0';
			}
			else break;
		}
		id--;
		return x;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			s = sc.next().toCharArray();
			id = 0;
			System.out.println(exp());
		}
	}
}

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

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }

    return 0;
}

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

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> ans(N + 1);
	for(i = 1; i <= N; i++){
//		printf("i = %d\n", i);
		int A;
		scanf("%d", &A);
//		printf("test%d\n", i);
		ans[A] = i;
//		printf("ans[%d] = %d\n", A, i);
	}
//	printf("test5\n");
	for(i = 1; i <= N; i++){
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1152
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, t: usize);
    parse!(it, ab: [(usize, usize); n]);
    let mut ab: Vec<(usize, usize)> = ab;
    ab.sort();
    let mut dp = vec![0; t + 1];
    for i in 0..n {
        let (a, b) = ab[i];
        for j in (0..t).rev() {
            let nj = min(t, j + a);
            dp[nj] = max(dp[nj], dp[j] + b);
        }
    }
    println!("{}", dp.iter().max().unwrap());
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2308
#include <stdio.h>

int main(void) {
	int a,b,c,x;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
	x=a;
	a=b;
	b=x;
	}
	if(b>c){
	x=b;
	b=c;
	c=x;
	}
	if(a>b){
	x=a;
	a=b;
	b=x;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>


int main(void){

  int a,b,c,i;
  int count=0;

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

  for(i=a;i<=b;i++){
    if(c%i==0)
      count++;
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}


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

using namespace std;

int n = 0;
int cnt[2];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a = 0;
		scanf("%d", &a);
		cnt[a & 1] ++;
	}
	if (cnt[1] & 1) {
		if (cnt[1] > 1 || cnt[0]) puts("NO");
		else puts("YES");
	} else {
		puts("YES");
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  int N, T;
  cin >> N >> T;
  ll ans = 0;
  int prev_swi = 0;
  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    if (i == 0) {
      prev_swi = 0;
      continue;
    }
    if (t - prev_swi >= T) {
      ans += T;
      prev_swi = t;
    } else {
      ans += (t - prev_swi);
      prev_swi = t;
    }
  }
  ans += T;  // 最後に流せる
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int a[10];
int main()
{
    int sum=0;
    int maxx=0;
    for(int i=0; i<3; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        if(maxx<a[i])maxx=a[i];
    }
    printf("%d\n",sum-maxx);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <string.h>
#define inf 1000000007;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
	int a,b,c,i,j,k;
	char x,y;
	scanf("%c %c",&x,&y);
	a=x-'0';
	b=y-'0';
	if (a>b) printf(">\n");
	if (a==b) printf("=\n");
	if (a<b) printf("<\n");
	return 0;
}


Measured memory_bytes: 128
from collections import deque

n,m = map(int,input().split())
step = [i for i in range(2, n+1)]
broken = []
for i in range(m):
    broken += [int(input())]

mod = pow(10,9) + 7 #10**9+7
dp = [0 for _ in range(n+1)]
dp[0] = 1

if m == 0:
    dp[1] = 1
    for i in step:
        dp[i] = dp[i-1] + dp[i-2]
else:
    b = deque(broken)
    if not broken[0] == 1:
        dp[1] = 1
    elif len(b) > 1:
        b.popleft()
    if len(broken) != 0:
        bad_one = b.popleft()
    for i in step:
        if i != bad_one:
            dp[i] = (dp[i-1]+dp[i-2]) % mod
        elif i == bad_one and len(b) != 0:
            bad_one = b.popleft()
print(dp[n] % mod)


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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

#define MAX_H 50
#define MAX_W 50
using P = pair<int, int>;

int H, W;
char maze[MAX_H][MAX_W+1];
int cnt[MAX_H][MAX_W];
int white_num;

int dh[]{-1,  0,  1,  0};
int dw[]{ 0, -1,  0,  1};

int bfs(int h, int w) {
  queue<P> que;
  cnt[h][w] = 0;
  que.push(make_pair(h, w));

  while (que.size()) {
    P p = que.front(); que.pop();
    int count = cnt[p.first][p.second];
    if (p.first == H - 1 && p.second == W - 1) {
      return white_num - count;
    }
    ++count;
    for (int i{}; i < 4; ++i) {
      int nh = p.first + dh[i];
      int nw = p.second + dw[i];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W ||
          cnt[nh][nw] >= 0 || maze[nh][nw] == '#')
        continue;
      cnt[nh][nw] = count;
      que.push(make_pair(nh, nw));
    }

  }
  return -1;
}

int main() {
  scanf("%d%d", &H, &W);
  for (int h{}; h < H; ++h) {
    scanf("%s", maze[h]);
    for (int w{}; w < W; ++w) {
      cnt[h][w] = -1;
      if (maze[h][w] == '.') ++white_num;
    }
  }
  white_num -= 1;

  printf("%d\n", bfs(0, 0));
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  char c; cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A' << endl;
  else 
    cout << 'a' << endl;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<long long>pos,neg;
    for(int i=0;i<n;i++){
        long long tm;
        cin>>tm;
        if(tm>=0)
            pos.push_back(tm);
        else
            neg.push_back(tm);
    }
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end(),greater<long long>());

    int ipos=pos.size()-1;
    int ineg=neg.size()-1;
    long long ans=1ll;
    if(k%2){
        if(pos.size()){
            k--;
            ans*=pos[ipos];
            ipos--;
            ans%=(long long)(1e9+7);
        }else{
            for(int i=0;i<k;i++){
                ans*=neg[i];
                ans%=(long long)(1e9+7);
                ans+=(long long)(1e9+7);
                ans%=(long long)(1e9+7);
            }
            cout<<ans<<'\n';
            return 0;
        }
    }
    while(k){
        long long mul=-1ll;
        if(ipos>=1&&ineg<1){
            mul=(pos[ipos]*pos[ipos-1])%(long long)(1e9+7);
            ipos-=2;
        }else if(ineg>=1&&ipos<1){
            mul=(neg[ineg]*neg[ineg-1])%(long long)(1e9+7);
            ineg-=2;
        }else if(ineg>=1&&ipos>=1){
            if(neg[ineg]*neg[ineg-1]>=pos[ipos]*pos[ipos-1]){
                mul=(neg[ineg]*neg[ineg-1])%(long long)(1e9+7);
                ineg-=2;
            }else{
                mul=(pos[ipos]*pos[ipos-1])%(long long)(1e9+7);
                ipos-=2;
            }
        }else {
            break;
        }
        k-=2;
        ans*=mul;
        ans%=(long long)(1e9+7);
    }
    if(k){
        ans*=neg[0]*pos[0];
        ans%=(long long)(1e9+7);
        ans+=(long long)(1e9+7);
        ans%=(long long)(1e9+7);
    }
    cout<<ans<<'\n';
    return 0;
}
/**
10 10
1000000000
100000000
10000000
1000000
100000
10000
1000
100
10
1
*/


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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 1e9;
  rep(si, s.size()){
    if(si + t.size() > s.size()) break;
    int cnt = 0;
    rep(i, t.size()){
      if(s[si + i] != t[i]) cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(a, b, c, i) for (int i = a; i < b; i += c)
#define MAX_INT 1000000007
#define ll long long
#define p(t1, t2, x) pair<t1, t2> x
#define v(t, x) vector<t> x
#define newl "\n"

using namespace std;

class HAndV{
public:
	int choices(vector<string> &grid, int k){
		int ans = 0;
		int h = grid.size();
		int w = grid[0].size();
		int bl;
		rep(0, (1 << h), 1, i){
			rep(0, (1 << w), 1, j){
				bl = 0;
				rep(0, h, 1, x){
					rep(0, w, 1, y){
						if ((((i >> x) & 1) == 0) && (((j >> y) & 1) == 0)){
							if (grid[x][y] == '#') ++bl;
						}
					}
				}
				if (bl == k) ++ans;
			}
		}
		return ans;
	}
};

int main(){
	int h, w, k;
	cin >> h >> w >> k;
	HAndV hnv;
	vector<string> grid;
	rep(0, h, 1, i){
		string s;
		cin >> s;
		grid.push_back(s);
	}
	cout << hnv.choices(grid, k) << newl;
}


Measured memory_bytes: 3572
local s=io.read()
local t=io.read()

sanagram={}
tanagram={}
for i=1,#s do
    table.insert(sanagram,s:sub(i,i))
end
for i=1,#t do
    table.insert(tanagram,t:sub(i,i))
end
table.sort(sanagram)
table.sort(tanagram,function(a,b)
    return a>b
end)

if table.concat(sanagram,"")<table.concat(tanagram,"") then
    print("Yes")
else
    print("No")
end

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	a := float64(sc.ReadInt())
	b := float64(sc.ReadInt())
	h := sc.ReadInt()
	m := sc.ReadInt()

	minutes := (float64)(60*h + m)

	theta := math.Remainder((11.0/360)*minutes, 2) * math.Pi

	c := math.Sqrt(a*a + b*b - 2.0*a*b*math.Cos(theta))

	fmt.Println(c)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1760
#include <iostream>

using namespace std;

void func_A() {

    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe";
    else cout << "safe";
}

void func_B() {


}

void func_C() {


}

void func_D() {


}

int main() {

    func_A();
    //func_B();
    //func_C();
    //func_D();

    return 0;

}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> groups;
	if(n % 2 == 0){
		for(int i = 0; i < n / 2; ++i){
			groups.emplace_back();
			groups.back().push_back(i + 1);
			groups.back().push_back(n - i);
		}
	}else{
		groups.emplace_back();
		groups.back().push_back(n);
		for(int i = 0; i < n / 2; ++i){
			groups.emplace_back();
			groups.back().push_back(i + 1);
			groups.back().push_back(n - i - 1);
		}
	}
	const int m = groups.size();
	vector<pii> edges;
	for(int i = 0; i < m; ++i){
		const int j = (i + 1) % m;
		if(i == 1 && j == 0){ continue; }
		for(const auto u : groups[i]){
			for(const auto v : groups[j]){
				edges.emplace_back(u, v);
			}
		}
	}
	cout << edges.size() << endl;
	for(const auto& p : edges){
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}


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

int main() {
  vector<int> num (3, 0);
  int f = 0, s = 0;
  
  for (int i = 0; i < 3; i++) {
    cin >> num.at(i);
  }
  
  for (int i = 0; i < 3; i++) {
    if (num.at(i) == 5) {
      f += 1;
    }
    
    else if (num.at(i) == 7) {
      s += 1;
    }
  
  }
    
  if (f == 2 && s == 1) {
    cout << "YES" << endl;
  }

  else {
    cout << "NO" << endl;
  }
  
}
  

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


int main(){
    /*A
    int a,b,c;
    cin>>a>>b>>c;
    int x = a-b;
    if(c-x>=0)
    {
        cout<<c-x<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    */

    int n;
    cin>>n;
    vector <int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    bool flag = true;
    for(int i=n-1;i>0;i--)
    {
       if(h[i]-h[i-1]>=0)
       {
           continue;
       }
       else if(h[i]-h[i-1]==-1)
       {
           h[i-1]=h[i-1]-1;
       }
       else
       {
           flag = false;
       }
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3772
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 230, mod = 1e9 + 7, lg = 19;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	ll ans = 0;
	cin >> n >> s;
	ll r = 0, g = 0, b = 0;
	for(auto i : s) {
		if(i == 'R') r++;
		if(i == 'G') g++;
		if(i == 'B') b++;
	}
	ans = r*g*b;
	for(int d = 1; d <= n; d++)
		for(int i = 0; i + 2*d < n; i++) {
			if(s[i]!=s[i+d]&&s[i]!=s[i+2*d]&&s[i+d]!=s[i+2*d]) ans--;
		}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#include<math.h>
#include<set>
#include<string>
using namespace std;

#define jaldichal          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                 push_back
#define mk                 make_pair
#define R                  return
#define line               "\n"
#define space              " "
#define all(x)             x.begin(),x.end()
#define w(x)               int x;cin>>x;for(int i=1;i<=x;i++)
#define vi                 vector<int>
#define setbits(x)         __builtin_popcountll(x)

int n,m;

long long int dp[110][100010];

long long int knapsack(int v[][2], int W, int i){
  if(i <0){
    return 0;
  }
  if(dp[i][W] !=0){
    return dp[i][W];
  }

  else if(W - v[i][0] <0){
    dp[i][W] =  knapsack(v,W,i-1);
    return dp[i][W];
  }

  dp[i][W] = max(knapsack(v,W,i-1),v[i][1] + knapsack(v,W- v[i][0],i-1));

  return dp[i][W];
}

void solve()
{
  cin>>n;
  int W;
  cin>>W;
  int v[n][2];
  for(int i=0;i<n;i++){
    cin>>v[i][0]>>v[i][1];
  }

  cout<< knapsack(v,W,n-1)<<line;


  // for(int i=0;i<n;i++){
  //   for(int j =0;j<=W;j++){
  //     cout<<dp[i][j]<<space;
  //   }
  //   cout<<line;
  // }
}

signed main()
{    
  jaldichal
  solve();

  return 0;
}



Measured memory_bytes: 75084
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] ch = str.toCharArray();
        
        int a = 0;
        int b = 0;
        int c = 0;
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == 'a') {
                a++;
            } else if (ch[i] == 'b') {
                b++;
            } else {
                c++;
            }
        }
        
        
        boolean ok = true;
        int max = Math.max(a, Math.max(b, c));
        int min = Math.min(a, Math.min(b, c));
        if (max - min > 1) {
            ok = false;
        }
        
        if (ok) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
        // return;
        // 2文字以上の回文を持たない
        // -> abc, acb, bac, bca, cab, cba
        // -> abcabcabcab
    }
}


Measured memory_bytes: 27556
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.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, s, n) for (int i = (s); i < (int)(n); i++)
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main() {
	int n,k;cin>>n>>k;
	vec a(n);
	rep(i,n) cin>>a[i];

	rep(ki,k){
		vec b(n);
		rep(i,n){
			int l = max(0, i-a[i]);
			int r = min(i+a[i]+1, n);
			b[l]++; b[r]--;
		}

		rep(i,n) b[i+1] += b[i];
		if(a==b) break;
		a = b;
	}

	rep(i,n) cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 4776
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

unsigned choose( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}
int NKmin(string S,int K){
    int size=S.length();
    ll ans=0;
    if(K==1){
        if(size>K){
            ans+=choose(size-1,K)*pow(9,K);
        }
        ans+=(S[0]-'0');
    }else{
        ans+=choose(size-1,K)*pow(9,K);
        ans+=(S[0]-'1')*choose(size-1,K-1)*pow(9,K-1);
        string S1;
        int flag=0;
        REP(i,size-1){
            if(S[i+1]!='0'||flag!=0){
                flag=1;
                S1.push_back(S[i+1]);
            }
        }
        if(!S1.empty()){
        ans+=NKmin(S1,K-1);
        }
    }
    return ans;
}

int main(){
    string S;
    cin>>S;
    int K;
    cin>>K;
    //inputend
    int ans=NKmin(S,K);
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	long N, M;
	long result = 0;

	Main() {
		Scanner in = new Scanner(System.in);
		N = in.nextLong();
		M = in.nextLong();
		in.close();
	}

	void calc() {
		if (N >= 2 && M >= 2) {
			result = (N - 2) * (M - 2);
		} else if (N == 1 && M == 1) {
			result = 1;
		} else {
			result = Math.max(N, M) - 2;
		}
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
		System.out.println(ins.result);
	}

}

Measured memory_bytes: 21332
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int n;
    int a[10001];
    long long sum = 0;

    cin >> n;

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

    int max, min;
    max = a[0];
    min = a[0];

    for(int j=1; j<n; j++)
    {
        if(max < a[j]) max = a[j];
        if(min > a[j]) min = a[j];
    }

    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3112
def a_atcoder_contest_scheduling(CONTEST=26):
    D = int(input())
    Satisfaction_decreasing = [int(i) for i in input().split()]
    Satisfaction_difference = [[int(i) for i in input().split()] for j in range(D)]

    # とりあえず満足度の減少は目をつぶり、増加が大きいものを選ぶ
    ans = []
    current_satisfaction = 0
    last = {i: 0 for i in range(1, CONTEST + 1)}
    for day in range(1, D + 1):
        satisfaction = Satisfaction_difference[day - 1]
        max_diff = max(satisfaction)
        contest_type = satisfaction.index(max_diff) + 1
        current_satisfaction += satisfaction[contest_type - 1]
        last[contest_type] = day

        satisfaction_decreasing = sum(satisfaction[i - 1] * (day - last[i])
                                      for i in range(1, CONTEST + 1))
        current_satisfaction -= satisfaction_decreasing
        ans.append(contest_type)
    return '\n'.join(map(str, ans))

print(a_atcoder_contest_scheduling())

Measured memory_bytes: 9456