akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MXS = 2510;
const int MXN = 51;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[MXN][MXN][MXS];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
       
    int n, A;
    cin >> n >> A;
    dp[0][0][0] = 1;
    fi(1, n + 1) {
        int x;
        cin >> x;
        rep(s, 0, MXS) {
            rep(j, 0, i) {
                if (dp[i - 1][j][s])
                    dp[i][j + 1][s + x] += dp[i - 1][j][s];
                dp[i][j][s] += dp[i - 1][j][s];
            }
        }
    } 
    int ans = 0;
    rep(s, 1, MXS) rep(j, 1, MXN) if (s == j * A) ans += dp[n][j][s];
    cout << ans << '\n';
}

Measured memory_bytes: 28944
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func modPow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if (n & 1) > 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	D := make([]int, N)
	for i := 0; i < N; i++ {
		D[i] = sc.nextInt()
	}
	if D[0] != 0 {
		fmt.Println(0)
		return
	}

	set := make(map[int]int)
	var maxKey int
	for _, v := range D {
		set[v]++
		maxKey = max(maxKey, v)
	}
	if maxKey != len(set)-1 {
		fmt.Println(0)
		return
	}

	counter := make([]int, len(set))
	for k, v := range set {
		counter[k] = v
	}
	if counter[0] != 1 {
		fmt.Println(0)
		return
	}
	total := 1
	for i := 1; i < len(counter); i++ {
		total *= modPow(counter[i-1], counter[i], 998244353)
		total %= 998244353
	}
	fmt.Println(total)
}


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

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

int H, W = 5;
int map[10][5];

int main(){
    while(scanf("%d", &H), H){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                scanf("%d", &map[i][j]);
            }
        }

        int res = 0;
        while(true){
            bool updated = false;
            for(int i=0;i<H;i++){
                for(int j=0,k=0;j<W;){
                    while(k < W && map[i][k] == map[i][j]){k++;}
                    if(k-j >= 3 && ~map[i][j]){
                        res += (k-j) * map[i][j];
                        for(;j<k;j++){
                            map[i][j] = -1;
                        }
                        updated = true;
                    }else{
                        j = k;
                    }
                }
            }

            // for(int i=0;i<H;i++){
            //     for(int j=0;j<W;j++){
            //         printf("%3d ", map[i][j]);
            //     }
            //     puts("");
            // }
            // puts(std::string(40, '-').c_str());
        
        
            if(!updated){break;}

            for(int i=0;i<5;i++){
                for(int j=H-1,k=H-1;j>=0;j--,k--){
                    while(k >= 0 && !~map[k][i]){k--;}
                    if(k == -1){break;}
                    std::swap(map[j][i], map[k][i]);
                }
            }      
        }

        printf("%d\n", res);
    }
}

Measured memory_bytes: 1012
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define PI acos(-1)
#define sz(a) long long(a.size())
#define ff first
#define ss second
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
///priority_queue <int, vector<int>, greater<int>> g
#define MS(a,b) memset(a,b,sizeof(a));
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};

typedef vector<ll> vll;
typedef vector<string> vss;
typedef vector<pair<ll,ll > > vpr;
typedef vector<pair<string,ll > > vspr;
typedef list<ll> li;
typedef list<string> ls;
typedef list<pair<ll,ll> > lpr;
typedef list<pair<string,ll> > lspr;
#define tc() ll t;cin>>t;while(t--)
bool rs(ll a, ll b){return(a>b);}
ll spd(ll n){ if(n%2==0)return 2; for(ll i=3; i*i<=n; i++){if(n%i==0)return i;}return n;}

int main(){
   ll n; cin>>n; ll m=0,ma=0;
   while(n--){
    ll x,y; cin>>x>>y;
    if(x==y){m++;}
    else {
        ma=max(ma,m);
        m=0;
    }
   }
   ma=max(m,ma);
   if(ma>=3)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    for (int i=0; i<N; i++){
        cout << S.at(i) << T.at(i);
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.ReadLine();
        var a = Console.ReadLine().Split().Select(int.Parse);
        var b = Enumerable.Range(a.Min(), a.Max() - a.Min() + 1);
        var c = b.Min(x => a.Sum(y => (y-x) * (y-x)));
        Console.WriteLine(c);
    }
}

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

using namespace std;

#define getchar getchar_unlocked
#define putchar putchar_unlocked

inline int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) return -1;
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

inline void out(long long n) {
    short res[20], i = 0;
    do { res[i++] = n % 10, n /= 10; } while (n);
    while (i) putchar(res[--i] + '0');
    putchar('\n');
}

#define T long long

class BIT {
private:
    int n;
    vector<T> bit;
public:
    // 0_indexed で i 番目の要素に x を加える
    void add(int i, T x){
        i++;
        while(i < n){
            bit[i] += x, i += i & -i;
        }
    }
    // 0_indexed で [0,i] の要素の和(両閉区間！！)
    T sum(int i){
        i++;
        T s = 0;
        while(i > 0){
            s += bit[i], i -= i & -i;
        }
        return s;
    }
    BIT(){}
    //初期値がすべて0の場合
    BIT(int sz) : n(sz+1), bit(n, 0){}
    BIT(vector<T>& v) : n((int)v.size()+1), bit(n, 0){
        for(int i = 0; i < n-1; i++){
            add(i,v[i]);
        }
    }
    void print(){
        for(int i = 0; i < n-1; i++){
            cout<<sum(i)-sum(i-1)<< " ";
        }
        cout<<endl;
    }
    //-1スタート
    void print_sum(){
        for(int i = 0; i < n; i++){
            cout<<sum(i-1)<<" ";
        }
        cout<<endl;
    }
};

class BIT_1D_RangeAdd_RangeSum {
private:
    int n;
    BIT bitc, biti;
    void add(BIT& bit, int l, int r, T val){
        bit.add(l, val), bit.add(r, -val);
    }
public:
    BIT_1D_RangeAdd_RangeSum(int sz) : n(sz), bitc(sz), biti(sz){}
    void add(int l, int r, T val){
        add(bitc, l, r, val), add(biti, l, r, -val*(l-1)), add(biti, r, n, val*(r-l));
    }
    T sum(int x){
        return (long long)bitc.sum(x) * x + biti.sum(x);
    }
    T sum(int l, int r){
        return sum(r-1) - sum(l-1);
    }
    void print(){
        for(int i = 0; i < n; i++){
            cout<<sum(i,i+1)<< " ";
        }
        cout<<endl;
    }
};


int main()
{
    int n = in(), q = in();
    BIT_1D_RangeAdd_RangeSum bt(n);
    rep(i,q){
        int x = in();
        if(x){
            int s = in(), t = in();
            out(bt.sum(s-1,t));
        }else{
            int s = in(), t = in(), u = in();
            bt.add(s-1,t,u);
        }
    }
    return 0;
}



Measured memory_bytes: 4288
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    if(N/A+(N%A>0)>B || N<A+B-1){
        cout << -1 << endl;
        return 0;
    }else if(B==1){
        for(int i=0; i<N; i++){
            if(i!=0){
                cout << ' ';
            }
            cout << i+1;
        }
        cout << endl;
        return 0;
    }

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

    int fact = (N-A)/(B-1);
    int r = (N-A)%(B-1);
    int k=A;
    int c=N-A;
    for(int j=1; k<N; j++){
        int h=fact;
        if(r>0){
            h++;
        }
        c-=h;
        for(int i=1; i<=h; i++){
            ans[k]=c+i;
            k++;
        }
        r--;
    }
    cout_vec(ans);
}

Measured memory_bytes: 4232
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int i, j, k, tmp;

int main(void) {
	int N, cnt = 0, tmp = 10,ans = 0;
	scanf("%d", &N);
	bool f = true;

	
	for (i = 1; i <= N; i++) {
		if (i % tmp == 0) {
			f = !f;
			tmp *= 10;
			if (f) {
				cnt++;
			}
		}
		else if(f){
			cnt++;
		}
	}
	printf("%d", cnt);



	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<lint> v[8];
int main()
{
	int n,m;lint a,b,c,out=0;
	cin>>n>>m;
	rep(i,n){
		cin>>a>>b>>c;
		rep(j,8){
			lint sum=0;
			if(j%2==0) sum+=a;else sum-=a;
			if((j&2)>0) sum+=b;else sum-=b;
			if((j&4)>0) sum+=c;else sum-=c;
			v[j].pb(sum);
		}
		//x[0].pb(a);x[1].pb(-a);y[0].pb(b);y[1].pb(-b);z[0].pb(c);z[1].pb(-c);
		//v.pb(a+b+c);
	}
	rep(i,8){
		sort(All(v[i]));reverse(All(v[i]));
		lint sum=0;
		rep(j,m) sum+=v[i][j];
		out=max(out,sum);
	}
	//sort(All(x[0]));sort(All(x[1]));sort(All(y[0]));sort(All(y[1]));sort(All(z[0]));sort(All(z[1]));
	//reverse(All(x[0]));reverse(All(y[0]));reverse(All(z[0]));reverse(All(x[1]));reverse(All(y[1]));reverse(All(z[1]));
	/*rep(i,8){
		lint sum=0;
		int X=i%2,Y=(i/2)%2,Z=(i/4)%2;
		rep(j,m){
			sum+=
		}
	}*/
	cout<<out<<endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int n = s.size();
	int cnt = 0;
	for (int ii = 0; ii < n/2; ++ii){
		if (s[ii] != s[n-1-ii]){
			cnt++;
		}
	}

	cout << cnt << "\n";

	return 0;
}


Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String totalStr = input.readLine();
		
		int total = Integer.parseInt(totalStr);
		
		String[] numbers = input.readLine().split(" ");
		
		for(int reverse = total; reverse > 0; reverse--)
		{
			System.out.print(numbers[reverse - 1]);
			
			if(reverse != 1)
			{
				System.out.print(" ");
			}
			
			else
			{
				System.out.println();
			}
		}
	}
}



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

int tax(int, int);

int main(){
    int x, y, s, i, j;
    while(cin >> x >> y >> s && 0 < x && x < 100 && 0 < y && y < 100 && 10 < s && s < 1000 ){
        int maximum = 0;
        for (i = 1; i < s; i++){
            for (j = 1; j < s; j++){
                if(tax(x,i) + tax(x,j) == s){
                    maximum = max(maximum, tax(y,i) + tax(y,j));
                }
            }
        }
        cout << maximum << endl;
    }
}

int tax(int s, int t){
    return (s+100)*t/100;
}

Measured memory_bytes: 1160
h,w,k=map(int,input().split())
c = [input()for _ in range(h)]
ans = 0
for bit in range(1<<(h+w)):
    cnt = 0
    for i in range(h):
        if (bit>>i)&1:continue
        for j in range(w):
            if(bit>>(h+j))&1:continue
            if c[i][j] == '#':
                cnt += 1
    if cnt == k:
        ans += 1
print(ans)

Measured memory_bytes: 73832
#include<iostream>

using namespace std;

int main(){
 long n;
  cin >> n;
 long a[n+1];
 long sum=0;
   
  for(long i=1;i<=n;i++) {cin >> a[i];
    
    if(i%2==0) sum-=a[i];
    else sum+=a[i];                     
                         }
  
  long m[n+1]={0};
   m[1]=sum;
  
  for(long i=2;i<=n;i++) m[i]=2*a[i-1]-m[i-1];
  
  for(long i=1;i<n;i++) cout << m[i] << " ";
   
   cout << m[n] << endl;

}

Measured memory_bytes: 2816
#include<stdio.h>
int F(int, int [],int);
int main()
{
  int sum=0,i,mid,l,r,n,k,w[1000000];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
  }
  w[n]=-1;
  l=0;
  r=2000000000;
  while(l<r){
    mid=(l+r)/2;
    sum=F(mid,w,k);
    if(sum==n && F(mid-1,w,k)!=sum)break;   
    if(sum<n){
      l=mid+1;
    }
    else if(sum==n &&F(mid-1,w,k)==sum){
      r=mid;
    }
  }

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

int F(int P,int w[],int k){
  int i,sum=0,a=0;
  for(i=0;i<k;i++){
    if(w[a]<=P){
      while(sum+w[a]<=P && w[a]!=-1){
	sum+=w[a];
	a++;
      }
    }
    sum=0;
  }
  return a;
}

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




int main() {
	
    
    long int N;
  cin>>N;
  
  long int tot=0,M;
  M=N%500;
  tot+=(N/500)*1000;
  tot+=(M/5)*5;
  
  cout<<tot<<endl;
  
  
    
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N],C[N-1];
    int B;
    int ans=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    for(int i=0; i<N; i++){
        cin >> B;
        ans+=B;
    }
    for(int i=0; i<N-1; i++){
        cin >> C[i];
    }
    for(int i=0; i<N-1; i++){
        if(A[i+1]-A[i]==1){
            ans+=C[A[i]-1];
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int res = 0;
    int sum = 0;
    for (int a=0; a<A+1; a++){
        for (int b=0; b<B+1; b++) {
            for (int c=0; c<C+1; c++) {
                sum = 500*a + 100*b + 50*c;
                if (sum == X) {
                    res++;
                }
            }
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
} 

vector<vector<ll> >vii;

int main(){
   //Fast_IO();
   ll h1,m1,h2,m2,k;
   cin>>h1>>m1>>h2>>m2>>k;
   ll x = h1*60+m1;
   ll y = h2*60+m2;
   cout<<y-x-k<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#define N 16

using namespace std;

struct DATA{
  int x1, y1, x2, y2;
  DATA(){}
  DATA(int x1_, int y1_, int x2_, int y2_){
    x1=x1_; y1=y1_; x2=x2_; y2=y2_; }
  bool isEqual(DATA a){
    return (x1==a.x1 && y1==a.y1 && x2==a.x2 && y2==a.y2);
  }
};

int dp[N][N];
vector<DATA> ng;

void input(int n){
  int x1, y1, x2, y2;
  vector<DATA> data(n, DATA());
  for(int i=0; i<n; ++i){
    cin >> x1 >> y1 >> x2 >> y2;
    data[i].x1 = min(x1, x2);
    data[i].y1 = min(y1, y2);
    data[i].x2 = max(x1, x2);
    data[i].y2 = max(y1, y2);
  }
  ng = data;
}

int get(const DATA& a){
  for(int i=0; i<ng.size(); ++i){
    if(ng[i].isEqual(a)) return 0;
  }
  return dp[a.x1][a.y1];
}

int solve(int& x, int& y){
  dp[0][0] = 1;
  for(int j=1; j<=y; ++j){
    dp[0][j] = get(DATA(0, j-1, 0, j));
  }
  for(int i=1; i<=x; ++i){
    for(int j=0; j<=y; ++j){
      if(j == 0)
	dp[i][0] = get(DATA(i-1, 0, i, 0));
      else
	dp[i][j] = get(DATA(i-1, j, i, j)) + get(DATA(i, j-1, i, j));
    }
  }
  return dp[x][y];
}

int main(){
  int n, m, x, y, ans;
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> x >> y;
    cin >> m;
    input(m);
    ans = solve(x, y);
    if(!ans) cout << "Miserable Hokusai!" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n;
    string s;
  	cin>>n>>s;
  	int r=0,g=0,b=0;	
  	for(char ch : s){
    	if(ch == 'R') r++;
        else if(ch == 'G') g++;
        else b++;
  	}
  int ans = r*g*b;
  int rgb = 'R'-'A' + 'G'-'A' + 'B'-'A';
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int o = 2*j-i;
    	int x = s[i]-'A' + s[j]-'A' + s[o]-'A';
    	if(o < n && x == rgb) ans --;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;

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

    int t = 1;
    //cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        int a[n + 1];
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int dp[n + 2][k + 2];
        for (int j = 0; j <= k; j++)
        {
            dp[1][j] = (j > a[1]) ? 0 : 1;
        }
        for (int i = 2; i <= n; i++)
        {
            for (int j = 0; j <= k; j++)
            {
                if (j == 0)
                    dp[i][j] = dp[i - 1][j];
                else {
                    if (j - a[i] - 1 >= 0)
                        dp[i][j] = (MOD + dp[i][j - 1] % MOD + dp[i - 1][j] % MOD - dp[i - 1][j - 1 - a[i]] % MOD) % MOD;
                    else
                        dp[i][j] = (dp[i][j - 1] % MOD + dp[i - 1][j] % MOD) % MOD;
                }
            }
        }
        cout << dp[n][k] % MOD << endl;
    }
    return 0;

}



Measured memory_bytes: 78336
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int solve(int cnt, int x, int y, vint c, vint s, vint f) {
	if (cnt > cnt / f[x]*f[x]) {
		cnt = cnt / f[x] * f[x] + f[x];
	}
	else {
		cnt = cnt / f[x]*f[x];
	}
	if (cnt < s[x]) {
		cnt = s[x];
	}
	cnt += c[x];
	if (x + 1 == y) {
		return cnt;
	}
	else {
		return solve(cnt, x + 1, y, c, s, f);
	}
}

int main() {
	llint n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	llint cnt[5] = {};
	rep(i, n) {
		if (s[i][0] == 'M' || s[i][0] == 'A' || s[i][0] == 'R' || s[i][0] == 'C' || s[i][0] == 'H') {
			if (i != 0) {
					if (s[i][0] == 'M')cnt[0]++;
					if (s[i][0] == 'A')cnt[1]++;
					if (s[i][0] == 'R')cnt[2]++;
					if (s[i][0] == 'C')cnt[3]++;
					if (s[i][0] == 'H')cnt[4]++;
			}
			else {
				if (s[i][0] == 'M')cnt[0]++;
				if (s[i][0] == 'A')cnt[1]++;
				if (s[i][0] == 'R')cnt[2]++;
				if (s[i][0] == 'C')cnt[3]++;
				if (s[i][0] == 'H')cnt[4]++;
			}
		}
	}
	llint ans = 0;
	llint tmp;
	rep(i, 10) {
		tmp = 1;
		if (i <= 5) {
			if (cnt[0] == 0) {
				continue;
			}
			tmp *= cnt[0];
		}
		if (i <= 2 || 6 <= i&&i <= 8) {
			if (cnt[1] == 0) {
				continue;
			}
			tmp *= cnt[1];
		}
		if (i == 0 || i == 3 || i == 4 || 6 <= i&&i <= 7 || i == 9) {
			if (cnt[2] == 0) {
				continue;
			}
			tmp *= cnt[2];
		}
		if (i == 1 || i == 3 || i == 5 || i == 6 || i == 8 || i == 9) {
			if (cnt[3] == 0) {
				continue;
			}
			tmp *= cnt[3];
		}
		if (i == 2 || i == 4 || i == 5 || 7 <= i&&i <= 9) {
			if (cnt[4] == 0) {
				continue;
			}
			tmp *= cnt[4];
		}
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6144
from itertools import permutations as perm
import math

N = int(input())
coo = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for root in list(perm(range(N))):
    for i in range(1, N):
        ans += math.sqrt((coo[root[i]][0]-coo[root[i-1]][0])**2+(coo[root[i]][1]-coo[root[i-1]][1])**2)

print(ans/math.factorial(N))

Measured memory_bytes: 7972
#include <bits/stdc++.h>
//#include<fstream>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

/*ofstream fout("bcount.out");
ifstream fin("bcount.in");*/

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    double d,t,s;
    cin>>d>>t>>s;
    if(d/s <= t)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>

int main(){
    int N=0,count=0;
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<N;i++){
        count+=a[i]%2;
    }
    if(count%2==0){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

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

using namespace std;

int main()
{
	string str1,str2;
	cin >> str1 >> str2;
	int sum = 0;
	for(int i = 0; i < 3; i++)
	{
		if(str1[i] == str2[i])
			sum++;
	}
	cout << sum << endl;
	return 0;
}

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


int main() {
    int N,x; cin>>N>>x;
    vector<ll> a(N);

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

    //vector<ll> t(N,0);

    vector<ll> mini(N);
    ll ans=0ll;
    for (int i = 0; i < N; ++i) {
        mini[i]=a[i];
        ans+=mini[i];
    }
    //cout<<ans<<endl;
    for (int i = 1; i < N; ++i) { //i:何回変色させるか
        ll tmp=0ll;
        for (int j = 0; j < N; ++j) {
            int ref=j-i;
            if(ref<0) ref=N+ref;
            mini[j]=min(mini[j],a[ref]);
            //if(i==1) cout<<ref<<" "<<mini[j]<<endl;
            tmp+=mini[j];
        }
        ans=min(ans,tmp+(ll)x*i);

    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define MN 2000
#define whole(xs) xs.begin(), xs.end()
#define INF (1<<28)

int N, M;

struct Edge {
    int u, v;
    int dist, cost;
    Edge(int u, int v, int dist, int cost) : 
        u(u), v(v), dist(dist), cost(cost) {}
};
typedef vector<Edge> Vertex;

vector<Vertex> Graph;
bool input() {
    scanf("%d %d", &N, &M);
    if (N == 0 && M == 0) return false;
    Graph.clear(); Graph.resize(N);
    for (int i = 0; i < M; i++) {
        int u, v, d, c; scanf("%d %d %d %d", &u, &v, &d, &c);
        u--; v--;
        Graph[u].push_back(Edge(u, v, d, c));
        Graph[v].push_back(Edge(v, u, d, c));
    }
    return true;
}

struct S {
    int v;
    int dist, cost, prev;
    S(int v, int dist, int cost, int prev) : v(v), dist(dist), cost(cost), prev(prev) {}
};
bool operator<(const S& a, const S& b) {
    return (a.dist == b.dist ? a.cost > b.cost : a.dist < b.dist);
}
bool operator>(const S& a, const S& b) {
    return (!(a < b));
}
ostream& operator<<(ostream& os, const S& s) {
    os << "v: " << s.v << " dist: " << s.dist << " cost: " << s.cost << " prev: " << s.prev;
    return os;
}
struct P {
    int v, dist;
    P(int v, int dist) : v(v), dist(dist) {}
};
bool operator<(const P& a, const P& b) {
    return a.dist < b.dist;
}
bool operator>(const P& a, const P& b) {
    return (!(a < b));
}
void CalcDist(vector<S>& V) {
    for (int i = 0; i < N; i++) V[i].v = i;
    priority_queue< P, vector<P>, greater<P> > PQ;
    PQ.push(P(0, 0));
    V[0].dist = 0; V[0].cost = 0; V[0].prev = -1;
    while (!PQ.empty()) {
        P cur = PQ.top(); PQ.pop();
        for (int i = 0; i < Graph[cur.v].size(); i++) {
            Edge& next = Graph[cur.v][i];
            if (V[next.v].dist == V[cur.v].dist + next.dist && V[next.v].cost > next.cost) {
                V[next.v].cost = next.cost;
                V[next.v].prev = cur.v;
                PQ.push(P(V[next.v].v, V[next.v].dist));
            } else if (V[next.v].dist > V[cur.v].dist + next.dist) {
                V[next.v].dist = V[cur.v].dist + next.dist;
                V[next.v].cost = next.cost;
                V[next.v].prev = cur.v;
                PQ.push(P(V[next.v].v, V[next.v].dist));
            }
        }
    }
}

int main() {
    while (input()) {
        vector<S> V(N, S(0, INF, INF, -1));
        CalcDist(V);
        int Ans = 0;
        for (int i = 0; i < N; i++) {
            Ans += V[i].cost;
        }
        cout << Ans << endl;
    }
    return 0;
}

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

using namespace std;

const long long M = 1e9 + 7;

long long qpow(long long x , long long n , long long M){
    long long res = 1;
    x %= M;
    for(;n;n>>=1){
        if(n&1){
            res = (res * x)%M;
        }
        x = (x * x) % M;
    }
    return res;
}

long long qC(long long n , long long r){
    long long res = 1; 
    for(int i = 1 ; i <= r; ++i){
        res = (res * (n + 1 - i))%M;
        res = res * (qpow(i , M - 2 , M));
        res %= M;
    }
    return res;
}

int main() {
    long long a , b , c;
    scanf("%lld %lld %lld" , &a , &b , &c);
    long long ans = (qpow(2 , a , M) - 1LL)%M;
    ans -= qC(a , b);
    ans -= qC(a , c);
    ans += 2 * M;
    printf("%lld\n" , ans % M);
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  REP(i, M) { cin >> L.at(i); }
  sort(L.begin(), L.end());
  vector<int> L2(M - 1);
  REP(i, M - 1) { L2.at(i) = L.at(i + 1) - L.at(i); }
  sort(L2.begin(), L2.end());

  int ans = 0;
  REP(i, M - 1 - (N - 1)) { ans += L2.at(i); }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    b = B[i]
    if b <= A[i]:
        ans += b
    else:
        ans += A[i]
        b -= A[i]
        if b <= A[i + 1]:
            ans += b
            A[i + 1] -= b
        else:
            ans += A[i + 1]
            A[i + 1] = 0

print (ans)

    


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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    int n = (int)s.size();
    int a = 0, ans = 0;
    For(i, n){
        if(s[i] == 'S'){
            a ++;
        }
        else{
            if(a > 0) a --;
            else ans += 2;
        }
    }
    Cout(ans);
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef pair<int, int> ii;

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    int a[40], b[40], c[40];
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    //半分前列挙用に連想配列を作成
    int sep = N / 2;
    map<ii, int> fh, lh;
    for (int bit = 0; bit < 1 << sep; bit++) {
        int sum_a = 0, sum_b = 0, sum_c = 0;
        for (int i = 0; i < sep; i++) {
            if (1 & (bit >> i)) {
                sum_a += a[i];
                sum_b += b[i];
                sum_c += c[i];
            }
        }
        auto it = fh.find(ii(sum_a, sum_b));
        if (it != fh.end()) {
            if (sum_c < it->second) it->second = sum_c;
        }
        else {
            fh.insert(make_pair(ii(sum_a, sum_b), sum_c));
        }

    }
    for (int bit = 0; bit < 1 << (N - sep); bit++) {
        int sum_a = 0, sum_b = 0, sum_c = 0;
        for (int i = 0; i < N - sep; i++) {
            if (1 & (bit >> i)) {
                sum_a += a[i + sep];
                sum_b += b[i + sep];
                sum_c += c[i + sep];
            }
        }
        auto it = lh.find(ii(sum_a, sum_b));
        if (it != lh.end()) {
            if (sum_c < it->second) it->second = sum_c;
        }
        else {
            lh.insert(make_pair(ii(sum_a, sum_b), sum_c));
        }
    }
    //前半の連想配列から必要なa,bを求め後半の連想配列を検索
    int max_la = 0, max_lb = 0;
    for (int i = sep; i < N; i++) {
        max_la += a[i];
        max_lb += b[i];
    }
    int ans = 1000000;
    for (auto it = fh.begin(); it != fh.end(); ++it) {
        int fa = it->first.first, fb = it->first.second;
        int fc = it->second;
        int x, y;
        for (int i = 1; ; i++) {
            x = Ma * i - fa;
            y = Mb * i - fb;
            if (x > max_la || y > max_lb) break;
            // auto result = lh.find(ii(x, y));
            for (auto result = lh.lower_bound(ii(x,y));
                result != lh.upper_bound(ii(x, y));
                ++result) {
                ans = min(ans, fc + result->second);
            }
            // if (result != lh.end()) {
            //     ans = min(ans, fc + result->second);
            // }
        }
    }
    if (ans == 1000000) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    vector<double> A(N);
    REP(i, N) cin >> A[i];
    
    double sum = 0;
    for(int i = 0; i < N; i++) {
        sum += 1/A[i];
    }

    double ans = 1/sum;    

    printf("%.10f", ans);

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

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class A {
public:
	long long v, w;
	A() {
	}
	bool operator>(A &rhs) {
		return this->v < rhs.v;
	}
	bool operator<(A &rhs) {
		return this->v > rhs.v;
	}
};

int main() {
	int n;
	long long W, ans = 0, w1;
	vector<A> a;
	cin >> n >> W;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		long long v, w;
		cin >> w >> v;
		a[i].w = w;
		a[i].v = v;
	}
	w1 = a[0].w;
	sort(a.begin(), a.end());
	vector<vector<A>> b;
	b.resize(4);
	for (int i = 0; i < n; i++) {
		b[a[i].w - w1].push_back(a[i]);
	}
	for (int i = 0; i <= b[0].size(); i++) {
		for (int j = 0; j <= b[1].size(); j++) {
			for (int k = 0; k <= b[2].size(); k++) {
				for (int l = 0; l <= b[3].size(); l++) {
					long long na = 0, o = 0;
					for (int h = 0; h < i; h++) {
						if (o + b[0][h].w <= W) {
							o += b[0][h].w;
							na += b[0][h].v;
						}
						else {
							break;
						}
					}
					for (int h = 0; h < j; h++) {
						if (o + b[1][h].w <= W) {
							o += b[1][h].w;
							na += b[1][h].v;
						}
						else {
							break;
						}
					}
					for (int h = 0; h < k; h++) {
						if (o + b[2][h].w <= W) {
							o += b[2][h].w;
							na += b[2][h].v;
						}
						else {
							break;
						}
					}
					for (int h = 0; h < l; h++) {
						if (o + b[3][h].w <= W) {
							o += b[3][h].w;
							na += b[3][h].v;
						}
						else {
							break;
						}
					}
					if (ans < na) {
						ans = na;
					}
				}
			}
		}
	}
	cout << ans << endl;
	//cin >> n;
	return 0;
}

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

int main() {
	string s;
	while (cin >> s) {
		int length = s.length();
		int left = 0;
		int right = 0;
		int count = 0;
		int max_left = 0;
		int max_right = 0;
		int max=0;
		s[length] = 'Q';
		for (int i = 0; i <= length; i++) {
			if (s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T') {
				right++;
			}
			else {
				if (right - left > max) {
					max = right - left;
					max_left = left;
					max_right = right;
				}
				right++;
				left = right;
			}
		}
		max = max_right - max_left;
		cout << max << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll A, B, C;

ll kadomatsu(vector<ll> l, ll m){
    if(sz(l) < 3){
        return INF;
    }
    if(sz(l) == 3){
        return abs(l.at(0)-A) + abs(l.at(1)-B) + abs(l.at(2)-C) + 10 * m;
    }
    ll a = INF;
    vector<ll> p(sz(l)-1), q(sz(l)-1), r(sz(l)-1), s(sz(l)-1);
    rep(i, sz(l)-1){
        p.at(i) = l.at(i);
        q.at(i) = l.at(i);
        r.at(i) = l.at(i);
        s.at(i) = l.at(i);
    }
    p.at(0) += l.at(sz(l)-1);
    q.at(1) += l.at(sz(l)-1);
    r.at(2) += l.at(sz(l)-1);
    chmin(a, kadomatsu(p, m+1));
    chmin(a, kadomatsu(q, m+1));
    chmin(a, kadomatsu(r, m+1));
    chmin(a, kadomatsu(s, m));
    return a;
}

int main()
{
    ll N;
    cin >> N >> A >> B >> C;
    vector<ll> l(N);
    rep(i, N){
        cin >> l.at(i);
    }
    sort(all(l));
    ll mp = INF;
    do{
        chmin(mp, kadomatsu(l, 0));
    } while(next_permutation(all(l)));
    cout << mp << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n; cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int mx = 1;
  int res = 0;
  rep(i, n){
    res += (x[i] - 1) / mx;
    if(mx == 1 || x[i] == mx){
      mx ++;
    }
  }
  cout << res << endl;
}


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

int main()
{
    int i, j, k, n=0, r ;
    cin >> k ;
   // int a[n];
    for(i=0; i<k; i++)
    {
        n=((n*10)+7)%k ;
        if(n==0)
        {
            cout << i+1 ;
            break ;
        }
    }
    if(n!=0)
        cout << -1 ;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main() {
	int a[11],date[11];
	for (int i = 1; i <= 5; i++) {
		cin >> a[i];
	}
	int dai = -999999;
	int o;
	for (int i = 1; i <= 5; i++) {
		int dai = -999999;
		for (int z = 1; z <= 5; z++) {
			if (dai <= a[z]) {
				dai = a[z];
				o = z;
			}
		}
		date[i] = dai;
		a[o] = -9999999;
	}
	for (int i = 1; i <= 4; i++) {
		cout << date[i]<<" ";
	}
	cout << date[5] << endl;;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, char> P;
ll w, h, xvec, yvec, res;
vector<P> road;
int main(void){
    // Your code here!
    cin >> w >> h;
    for (ll i = 0; i < w; i++) {
        cin >> xvec;
        road.push_back(P(xvec, 'x'));
    }
    for (ll i = 0; i < h; i++) {
        cin >> yvec;
        road.push_back(P(yvec, 'y'));
    }
    sort(road.begin(), road.end());
    for (ll i = 0; i < road.size(); i++){
        P Q = road[i];
        if (Q.second == 'x'){
            res += Q.first * (h + 1);
            w--;
        } else {
            res += Q.first * (w + 1);
            h--;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 6512
def choose(n, a):
    x = 1; y = 1
    for i in range(a):
        x = x * (n-i) % mod
        y = y * (i+1) % mod
    return x * pow(y, mod-2, mod) % mod
mod = 10 ** 9 + 7 
n, a, b = map(int, input().split())
ans = pow(2, n, mod)
ans -= 1
ans -= choose(n, a)
ans -= choose(n, b)
 
print(ans % mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(n); ++i)
const int max_v = 101010;
const long long INF = 1e16;
inline void chmin(long long &a, long long b) {
    if (a > b) a = b;
}

int main() {
    int n, w; cin >> n >> w;
    vector<int> we(n), v(n);
    rep(i, n) cin >> we[i] >> v[i];
    vector<vector<long long>> dp(n+1, vector<long long>(max_v, INF));
    dp[0][0] = 0;
    rep(i, n) {
        rep(sum_v, max_v) {
            if (sum_v >= v[i]) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + we[i]);
            }
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    long long ans = 0;
    rep(sum_v, max_v) {
        if (dp[n][sum_v] <= w) ans = sum_v;
    }
    cout << ans << endl;
}

Measured memory_bytes: 81024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, m;
  while(input(n,m), n || m) {
    vector<int> num(n);
    UnionFind uf(n);
    bool ok = 1;
    REP(i,m) {
      int a, b;
      input(a,b);
      a--;b--;
      if (uf.findSet(a,b)) ok = 0;
      uf.unionSet(a,b);
      if (num[a]++ == 2) ok = 0;
      if (num[b]++ == 2) ok = 0;
    }
    cout << (ok ? "yes" : "no") << endl;
  }
}

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

using namespace std;

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

  vector<long int> L(M);
  vector<long int> R(M);
  for(int i = 0; i < M; i++) cin >> L[i] >> R[i];
    long int min,max;
    min = 1000000;
    max = -100;

    for(int i = 0; i < M; i++){
        if(min > R[i]) min = R[i];
        
        if(max < L[i]) max = L[i];
    }
    if(min >= max){
    cout << min - max + 1;
    }else{
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 1792
#N = int(input())
#S = str(input())
#A, B = map(int, input().split())
#C = list(map(int, input().split()))

S = str(input())
a = int(S[:2])
b = int(S[2:])
#print(a, b)

if a == 0:
  if b == 0:
    print("NA")
  elif b < 13:
    print("YYMM")
  else:
    print("NA")
  quit()  
elif b == 0:
  if a < 13:
    print("MMYY")
  else:
    print("NA")
  quit()  


if (a > 12) and (b > 12):
  print("NA")
elif (a <= 12) and (b <= 12):
  print("AMBIGUOUS")
elif a <= 12:
  print("MMYY")
else:
  print("YYMM")
  
  

Measured memory_bytes: 9184