akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int sum(int n) {
  if (n == 0) {
    return 0;
  }
  int s = sum(n - 1);  
  return s + n;  
}
  
int main(){
 int  N; cin >> N;
 vector<vector<int>> ball(N, vector<int>(2));
 for (int i=0;i<N;i++){
 	for (int j=0;j<2;j++){
 		cin >> ball.at(i).at(j);
 	}
 }
 int k=sum(N-1);
 vector<vector<int>> m(k, vector<int>(2));
 int now=0;
  for (int i=0;i<N-1;i++){
 	for (int j=i+1;j<N;j++){
 		if (ball.at(i).at(0)>ball.at(j).at(0)){
 			m.at(now).at(0)=ball.at(i).at(0)-ball.at(j).at(0);
 			m.at(now).at(1)=ball.at(i).at(1)-ball.at(j).at(1);
 			now++;
 		}
        if (ball.at(i).at(0)==ball.at(j).at(0) && ball.at(i).at(1)>=ball.at(j).at(1)){
            m.at(now).at(0)=ball.at(i).at(0)-ball.at(j).at(0);
 			m.at(now).at(1)=ball.at(i).at(1)-ball.at(j).at(1);
 			now++;
        }
        if (ball.at(i).at(0)==ball.at(j).at(0) && ball.at(i).at(1)<ball.at(j).at(1)){
            m.at(now).at(0)=ball.at(i).at(0)-ball.at(j).at(0);
 			m.at(now).at(1)=ball.at(j).at(1)-ball.at(i).at(1);
 			now++;
        }
 		if (ball.at(i).at(0)<ball.at(j).at(0)){
 			m.at(now).at(0)=ball.at(j).at(0)-ball.at(i).at(0);
 			m.at(now).at(1)=ball.at(j).at(1)-ball.at(i).at(1);
 			now++;
 		}
 	}
 }
 int count=0;
 int max=0;
 for (int i=0;i<k-1;i++){
 	for (int j=i+1;j<k;j++){
 		if (m.at(i).at(0)==m.at(j).at(0) && m.at(i).at(1)==m.at(j).at(1)){
 			count++;
 		}
    }
  if (max < count) max=count;
  count =0;
 }
 if (N==1) cout << 1 << endl;
 else cout << N-max-1 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

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

  int a = 1;
  REP(i,M) {
    a *= 2;
  }

  cout << (1900*M+100*(N-M))*a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
vector <string>ans;
vector <string>m[150];
map<string ,int >id;
int vis[1500];
int n;
char   s[150000];
char tmp[1500];
void gao(int now)
{
     vis[now]=1;
     for(int i=0;i<m[now].size();i++)
     {
         string haha  = m[now][i];
         //printf ("%d\n",id[haha]);
         if (id.count(haha))
         {
             if (vis[id[haha]])
                continue;
             else
                gao(id[haha]);
         }
         else{
            ans.push_back(haha);
         }
     }
}
int main()
{
    while(scanf("%d",&n),n)
    {
            id.clear();
            ans.clear();
            for(int i=0;i<=n;i++)
                m[i].clear();
            memset(vis,0,sizeof(vis));
       for(int i=1;i<=n;i++)
       {
            scanf("%s",s+1);
            int len = strlen(s+1);
            int now=0;
            for (int j=1;j<=len;j++)
            {
                 if (s[j]==':')
                 {
                     tmp[now]=0;
                     now=0;
                     id[string(tmp)] = i;
                     //printf ("%d",id[string(tmp)]);
                     //cout<<string(tmp)<<endl;
                     //cout<<string(tmp)<<endl;
                 }
                 else if (s[j]==',' || s[j]=='.')
                 {
                     tmp[now]=0;
                     now =0;
                     m[i].push_back(string(tmp));

                 }
                 else{
                    tmp[now++]=s[j];
                 }
            }
       }
        gao(1);
        sort(ans.begin(), ans.end());
        ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
        printf ("%d\n", ans.size());
        //for(int i=0;i<ans.size();i++)
            //cout<<ans[i]<<endl;

    }
    return 0;
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin >> n;
  std::vector<pair<int,int>> data(n);
  for(int i=0;i<n;++i){
    cin >> data[i].first;
    data[i].second = i+1;
  }
  sort(data.begin(),data.end());
  for(int i=0;i<n;++i){
    cout << data[i].second << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vvl f(n, vl(10));
    rep(i, n) {
        rep(j, 10) {
            cin >> f[i][j];
        }
    }

    vvl p(n, vl(11));
    rep(i, n) {
        rep(j, 11) {
            cin >> p[i][j];
        }
    }

    ll ans = -INF;
    rep(b, 1<<10) {
        if(b == 0) {
            continue;
        }
        ll now = 0;
        rep(i, n) {
            ll c = 0;
            rep(j, 10) {
                if(b & 1<<(9 - j)) {
                    if(f[i][j]) {
                        c++;
                    }
                }
            }
            now += p[i][c];
        }
        chmax(ans, now);
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b = mi()
    if a == 0:
        a = 1
    if b == 0:
        b = 1
    print((a*(a-1)//2)+(b*(b-1)//2))






main()





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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s;

int main() {
    cin >> s;
    forn(i, 4) cout << s[i];
    cout << ' ';
    forn(i, 8) cout << s[4 + i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, A, B;


signed main(){
    cin >> N >> A >> B;

    cout << N/(A+B)*A+min(N%(A+B), A) << endl;

    return 0;
}

Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var nm = data[0].split( ' ' );
  var n = parseInt( nm[0] );
  var m = parseInt( nm[1] );
  
  
  var A = new Array(n);
  var k = 0;
  for( var i=1; i<=n; i++ ) {
    var x = data[i].split( ' ' ).map( Number );
    A[k] = new Array();
    for( var j=0; j<m; j++ ) {
      A[k][j] = x[j];
    }
    k++;
  }
  var b = new Array(m);
  k = 0;
  for( var i=n+1; i<=n+m; i++ ) {
    var x = data[i].split( ' ' ).map( Number );
    b[k++] = x;
  }
  var c = new Array( n );
  for( var i=0; i<n; i++ ) {
    c[i] = 0;
    for( var j=0; j<m; j++ ) {
      c[i] += A[i][j]*b[j];
    }
  }
  console.log( c.join( '\n' ) );
});
 

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int r;
    cin >> r;
    double ans = 2 * r * 3.14159265358979323846;
    cout << ans << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> count(N + 1, 0);
  
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    count.at(A)++;
    count.at(B)++;
  }
  
  for (int i = 0; i < N; i++)
    cout << count.at(i + 1) << endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
#define mian main
string s;
int l;
int mian()
{
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int[] sum = new int[1000];
        sum[1] = 1;
        for (int i = 2; i < 1000; i++) {
            sum[i] = sum[i - 1] + i;
        }
        int diff = b - a;
        int result = sum[diff - 1] - a;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23632
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func checkBi(n int, k int) int {
	pow := 0
	div := n
	for {
		if div < k {
			div = div * 2
			pow++
		} else {
			return pow
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	p := 0.0

	ptmp := float64(1) / float64(n)
	for i := 1; i < n+1; i++ {
		p += ptmp / float64(math.Pow(2.0, float64(checkBi(i, k))))
	}

	fmt.Printf("%.12f\n", p)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
using namespace std;
INT a, b, A, B;

int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b; a--;
    if( b > 2 )
    {
        if( b%4 == 3 ) B = 0;
        else if( b%4 == 2 ) B = b+1;
        else if( b%4 == 1 ) B = 1;
        else if( b%4 == 0 ) B = b;
    }
    else for(INT i = 0 ; i <= b ; i++ ) B^=i;
    if( a > 2 )
    {
        if( a%4 == 3 ) A = 0;
        else if( a%4 == 2 ) A = a+1;
        else if( a%4 == 1 ) A = 1;
        else if( a%4 == 0 ) A = a;
    }
    else for(INT i = 0 ; i <= a ; i++ ) A^=i;
    cout<<(B^A)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main() {
	speed;
	int a, b,k;
	cin >> a >> b >> b >> b >> b >> k;
	string s;
	cout << (b - a <= k ? "Yay!" : ":(");
	ed;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  scanf("%d",&N);
  int n;
  int flag = -1;
  for(n = 0;n < N;n++){
    int t,x,y;
    scanf("%d %d %d",&t,&x,&y);
    if( !( (0 == (t - (x + y) ) % 2) && (x + y <= t) ) ) flag = flag + 1;
  }
  if(-1 == flag) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
const int N = 1e5 + 5;

string alp = "abcdefghijklmnopqrstuvwxyz";

void solve(){
    int n; cin >> n;
    string a, b; cin >> a >> b;
    int indf, inds;
    vector<pair<int, int>> d;
    for(int i = 0; i < n; i++){
        indf = (int)a[i] - 'a';
        inds = (int)b[i] - 'a';
        if(indf > inds){
            cout << -1 << endl;
            return;
        }
        if(indf != inds){
            d.pb({indf, inds});
        }
    }
        int sz = d.size();
        if(sz == 0){
            cout << 0 << endl;
            return ;
        }
        sort(d.begin(), d.end());
        pair<int, int> now = d[0];
        int ans = 0;
        for(int i = 1; i < sz; i++){
            //cout << now.f << ' ' << now.s << endl;
            if(now == d[i])continue;
            if(d[i].f >= now.s){
                ans++;
                now = d[i];
            }
            else{
                if(now.s <= d[i].s){
                    if(now.f != d[i].f)ans++;
                    now.f = now.s;
                    now.s = d[i].s;
                    ans++;
                }
                else ans++;
             }
        }
        //cout << now.f << ' ' << now.s << endl;
        if(now.f != now.s)ans++;
        cout << min(ans, n) << endl;

}

int main(){
    fast;
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(a >= b){
        int num = log2(a / b) + 1;
        b = b * pow(2, num);
        k -= num;
    }
    if(b >= c){
        int num = log2(b / c) + 1;
        c = c * pow(2, num);
        k -= num;
    }
    if(k >= 0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 4064
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int getdiv(int r,int d){
	return (r/d);
}
int conta(int l,int r,int d){
	int k = getdiv(r,d) - getdiv(l-1,d);
	//cout << l << " " << r << " " << d << ":" <<  k << endl;
	return k;
}
main(){
    fastio;
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int qnt = b-a + 1;
	int w = lcm(c,d);
	int qc = conta(a,b,c);
	int qd = conta(a,b,d);
	int qw = conta(a,b,w);
	cout << qnt - (qc + qd - qw) << endl;	
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<map>

using namespace std;

#define MAX		110
#define PII pair<int , int>
#define INF -1
#define MP make_pair


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

int bfs_map[MAX][MAX];

int H , W;


int wh_map[MAX][MAX];
vector<PII >v;



int bfs()
{
	int ans = 0;

	queue<PII >que;

	for (int i = 0; i < MAX; i++)
	{
		for (int j = 0; j < MAX; j++)
		{
			bfs_map[i][j] = INF;
			if (wh_map[i][j] == 1)
			{
				bfs_map[i][j] = 1;
			}
		}
	}

	bfs_map[0][0] = 0;
	que.push(MP(0 , 0));

	while(!que.empty())
	{
		int yy = que.front().first;
		int xx = que.front().second;
		que.pop();

		for (int i = 0; i < 6; i++)
		{
			int nextY = yy + dy[i];
			int nextX = xx + dx[yy & 1][i];

			//範囲外または探索済み又は建物
			if (nextY < 0 || H + 1 < nextY ||
				nextX < 0 || W + 1 < nextX ||
				bfs_map[nextY][nextX] != INF ||
				wh_map[nextY][nextX] == 1)
			{
				continue;
			}

			que.push(MP(nextY , nextX));
			bfs_map[nextY][nextX] = 0;
		}
	}

	//長さを求める
	for (int i = 0; i < v.size(); i++)
	{
		for (int j = 0; j < 6; j++)
		{
			//indexを調べる必要はない
			int yy = v[i].first + dy[j];
			int xx = v[i].second + dx[v[i].first & 1][j];

			if (bfs_map[yy][xx] == 0)
			{
				ans++;
			}
		}
	}
	return ans;
}



int main()
{
	cin >> W >> H;

	for (int i = 1 ; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			cin >> wh_map[i][j];
			if (wh_map[i][j])
			{
				v.push_back(MP(i , j));
			}
		}
	}

	cout << bfs() << endl;

	return 0;
}

Measured memory_bytes: 1416
use proconio::{input, fastout};
use proconio::marker::{Chars, Isize1};
use std::collections::{HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        h: isize,
        w: isize,
        start: (Isize1, Isize1),
        goal: (Isize1, Isize1),
        s: [Chars; h as usize]
    }

    let mut seen: HashSet<(isize, isize)> = HashSet::new();
    let mut deq: VecDeque<(isize, isize, isize)> = VecDeque::new();
    deq.push_back((start.1, start.0, 0));

    while !deq.is_empty() {
        let (x, y, point) = deq.pop_front().unwrap();
        if x == goal.1 && y == goal.0 {
            println!("{}", point);
            return
        }
        if seen.contains(&(x, y)) { continue }
        seen.insert((x, y));

        for r in -2..=2isize {
            for c in -2..=2isize {
                if r == 0 && c == 0 { continue }

                let nx = x + c;
                let ny = y + r;
                if nx < 0 || w <= nx || ny < 0 || h <= ny { continue }
                if s[ny as usize][nx as usize] != '.' { continue }
                if seen.contains(&(nx, ny)) { continue }
                if r.abs() + c.abs() == 1 {
                    deq.push_front((nx, ny, point));
                }else{
                    deq.push_back((nx, ny, point + 1));
                }
            }
        }
    }

    println!("-1");
}


Measured memory_bytes: 21564
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
#define Size 1000111
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

int ans[4];
int N, Y;
int mem[2002][10002];

bool slv(int cnt, int x, int s)
{
   if(mem[cnt+x][s] != -1)return(mem[cnt+x][s]);

   if(cnt + x + s  == N){
      ans[0] = cnt, ans[1] = x, ans[2] = s;
   }
   if(s < 0 || cnt+x > N)return(false);

   bool ret = false;
   if(s >= 10)ret |= slv(cnt+1, x, s-10);
   if(!ret && s >= 5)ret |= slv(cnt, x+1, s-5);
   return(mem[cnt+x][s] = ret);
}

signed main()
{
   FAST();
   cin >> N >> Y;

   Y /= 1000;

   memset(mem, -1, sizeof(mem));
   memset(ans, -1, sizeof(ans));
   slv(0, 0, Y);
   cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl;
}



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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll T[3], AB[3][3];
ll mk[202020];
ll i, j,ans;
int main(){
    fornum(i,0,2){
        scanf("%lld", &T[i]);
    }
    fornum(i,0,2){
        fornum(j,0,2){
            scanf("%lld", &AB[i][j]);
        }
    }
    ll a = T[0] * AB[0][0] + T[1] * AB[0][1];
    ll b = T[0] * AB[1][0] + T[1] * AB[1][1];
    if(a==b){
        printf("infinity");
        return 0;
    }
    if((a<b)==(T[0]* AB[0][0]<T[0]* AB[1][0])){
        printf("0");
        return 0;
    }
    ll c = abs(a - b);
    ll d = abs(T[0] * AB[0][0] - T[0] * AB[1][0]);

    printf("%lld", d / c * 2 + 1 - (d % c==0));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, C, K,ans;
ll T[100005];

int main() {
	cin >> N >> C >> K;
	FOR(i, 0, N) {
		cin >> T[i];
	}
	sort(T, T + N);

	ll unti = 0,cnt=0;
	FOR(i, 0, N) {
		if (T[i] > unti ||cnt>=C) {


			cnt=1;
			ans++;
			unti = T[i]+K;
		}
		else cnt++;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
N = int(input())
S = input()

ans = 0
l1 = []
for i in range(N):
    l2 = []
    if S[i] in l1:
        continue
    else:
        l1.append(S[i])
    for j in range(i + 1, N):
        if S[j] in l2:
            continue
        else:
            l2.append(S[j])
        s = S[j + 1:]
        ans += len(set(s))

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
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 () {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h==0 && w==0) break;
    rep(i,h) {
      rep(j,w) {
        if ((i+j)%2==0) cout << '#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> countm(int N,int sum){
    int n;
    int z;
    int csum;
    vector<int> satu(3,0);

    for (satu[0] = 0; satu[0] < N + 1 ; ++satu[0]) {
        for (satu[1] = 0; satu[1] < N - satu[0]  + 1 ; ++satu[1]) {
            satu[2] = N - satu[0] - satu[1];
            csum = satu[0] * 1000 + satu[1] * 5000 + satu[2] * 10000;
            if(csum == sum){
                return satu;
            }
        }
    }

    satu[0] = -1;
    satu[1] = -1;
    satu[2] = -1;

    return satu;
}

int main(){
    int N;
    int sum;
    vector<int> satu(3);

    cin >> N;
    cin >>  sum;

    satu = countm(N,sum);

    cout << satu[2]<< " " << satu[1]<<" "<<satu[0]<<endl;

}





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

int main() {
	int n, t, e;
	cin >> n >> t >> e;
	
	for(int i=1; i<=n; ++i) {
		int x;
		cin >> x;
		int d = t - x*(t/x);
		if(d <= e || x - d <= e) {
			cout << i << endl;
			return EXIT_SUCCESS;
		}
	}

	cout << -1 << endl;
	return EXIT_SUCCESS;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int N,M,X,Y;cin>>N>>M>>X>>Y;
  int Z = X + 1;
  for(int i=0;i<N;i++){
    int t;cin>>t;
    if(t >=Z){
      Z = t + 1;
    }
  }
  for(int i=0;i<M;i++){
    int t;
    cin>>t;
    if(t<Z){
      cout<<"War"<<endl; return 0;
    }
  }
  if(Z<=Y){
    cout<<"No War"<<endl; return 0;
  }else{
    cout<<"War"<<endl; return 0;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
house = [[[0*10 for i in range(10)] for j in range(3)] for k in range(4)]

for x in range(n):
    b, f, r, v = map(int, input().split())
    house[b - 1][f - 1][r - 1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print("", house[i][j][k], end="")
        print()
    if i < 3:
        print("#" * 20)



Measured memory_bytes: 5636
s = input()
a = s.count(s[0])
if a == 4:
    print("No")
    exit()
for i in range(2):
    if s[0] != s[i+1]:
        b = s.count(s[i+1])
        if a + b == 4:
            print("Yes")
        else:
            print("No")
        exit()
        


Measured memory_bytes: 2940
def main():
    H,W,A,B = map(int, input().split())
    
    ans = [[0]*W for i in range(H)]

    for i in range(B):
        for j in range(A):
            ans[i][j] = 1
    
    for i in range(H-B):
        for j in range(W-A):
            ans[B+i][A+j] = 1

    for i in ans:
        print("".join(map(str, i)))


if __name__ == "__main__":
    main()


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

using namespace std;

#define MAX 51
typedef pair<int, int> edge;

struct union_find {
    int v[MAX];
    
    union_find() {
        fill(v, v+MAX, -1);
    }
    int root(int i) {
        if(v[i]<0) return i;
        return v[i] = root(v[i]);
    }
    int size(int i) {
        return -v[root(i)];
    }
    int unite(int i, int j) {
        i = root(i);
        j = root(j);
        if(i!=j) {
            v[j] += v[i];
            v[i] = j;
        }
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    edge es[MAX];
    for(int i=0; i<m; i++) {
        cin >> es[i].first >> es[i].second;
    }
    int ct = 0;
    for(int i=0; i<m; i++) {
        union_find uf;
        for(int j=0; j<m; j++) {
            if(i!=j) {
                uf.unite(es[j].first, es[j].second);
            }
        }
        if(uf.size(1)!=n) ct++;
    }
    cout << ct << endl;
}


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


int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1 && b == 2) {
		cout << 3 << endl;
	}
	if (a == 1 && b == 3) {
		cout << 2 << endl;
	}
	if (a == 2 && b == 1) {
		cout << 3 << endl;
	}
	if (a == 2 && b == 3) {
		cout << 1 << endl;
	}
	if (a == 3 && b == 2) {
		cout << 1 << endl;
	}
	if (a == 3 && b == 1) {
		cout << 2 << endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	queue<string> que;
	
	unordered_map<string, int> m;
	
	string fs = "";
	
	for(int i = 0; i < 9; i++){
		string s;
		cin >> s;
		fs += s;
	}
	
	que.push(fs);
	
	for(int loop = 0; loop < 1000; loop++){
		if(que.empty()){
			break;
		}
		int sz = que.size();
		for(int num = 0; num < sz; num++){
			string str = que.front();
			que.pop();
			if(m.find(str) != m.end()){
				continue;
			}
			m[str] = loop;
			for(int i = 0; i < 9; i++){
				if(str[i] == '0'){
					if(i >= 3){
						swap(str[i], str[i - 3]);
						que.push(str);
						swap(str[i], str[i - 3]);
					}
					if(i < 6){
						swap(str[i], str[i + 3]);
						que.push(str);
						swap(str[i], str[i + 3]);
					}
					if(i % 3 > 0){
						swap(str[i], str[i - 1]);
						que.push(str);
						swap(str[i], str[i - 1]);
					}
					if(i % 3 < 2){
						swap(str[i], str[i + 1]);
						que.push(str);
						swap(str[i], str[i + 1]);
					}
				}
			}
		}
	}
	
	cout << m["123456780"] << endl;
	
	return 0;
}


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

int main(void) {
  int M;
  cin >> M;

  cout << 48 - M << endl;
  return 0;
}

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

const int INF=1e9;

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

    int mn=a[0],ans=-INF;
    for(int i=1;i<N;i++){
        ans=max(ans,a[i]-mn);
        mn=min(mn,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		BigInteger bm = BigInteger.valueOf(m);
		BigInteger b = BigInteger.ONE;
		for (int i = 0; i < n; i++) {
			BigInteger ai = BigInteger.valueOf(a[i] / 2);
			BigInteger gcd = b.gcd(ai);
			b = b.multiply(ai).divide(gcd);
			if (b.compareTo(bm) > 0) {
				System.out.println(0);
				return;
			}
		}

		int lcm = b.intValue();
		for (int i = 0; i < n; i++) {
			if (lcm % a[i] == 0) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(m / lcm - m / 2 / lcm);
	}
}


Measured memory_bytes: 62072
N = int(input())
s = raw_input().split()
h = [0]*N

for i in range(N):
    h[i] = int(s[i])
    h[i] = (h[i], i+1)

#print h
h.sort()
#print h

for i in range(N-1):
    print h[i][1],

print h[N-1][1]


Measured memory_bytes: 24496
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N,X; cin>>N>>X;
    vint m(N);
    REP(i,N) cin>>m[i];

    int Min=1e9;
    REP(i,N){
        X-=m[i];
        Min=min(Min,m[i]);
    }
    cout<<N+X/Min<<endl;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(a) (a.size)
#define lb lower_bound
#define ub upper_bound
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef unsigned long long ull;
const int MOD=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const int N=2e3+5;
const int dir[4][2]= {0,1,1,0,0,-1,-1,0};
int a[N],b[N],dp[N];
int main()
{
    ll x,y;
    while(cin>>x>>y)
    {
        ll ans=0;
        while(x<=y)
        {
            ans++;
            x*=2;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
num=list(map(int,input().split()))
ans=10**9
s,e=min(num),max(num)
for j in range(s,e+1):
  c=0
  for i in range(n):
    c+=(num[i]-j)**2
  if c<ans:
    ans=c
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class T, class F>
struct SegTree {
  size_t n;
  vector<T> a;
  F f;
  T zero;

  template<class U>
  static U floor2(U x) {
    U y = 1;
    for (; y < x; y <<= 1);
    return y;
  }
  SegTree(size_t n, F f, T zero) 
    : n(floor2(n)), a(2 * floor2(n), zero), f(f), zero(zero) {}
  void set(size_t i, T x) {
    i += n;
    a[i] = x;
    while (i >>= 1) a[i] = f(a[2 * i], a[2 * i + 1]);
  }
  // [l, r)
  T seg(size_t l, size_t r) const {
    T x = zero, y = zero;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        x = f(x, a[l]);
        ++l;
      }
      if (r & 1) {
        --r;
        y = f(a[r], y);
      }
    }
    return f(x, y);
  }
  T operator[](size_t i) const { return a[n + i]; }
};
template<class T, class F>
SegTree<T, F> make_seg_tree(size_t n, F f, T zero) { 
  return SegTree<T, F>(n, f, zero); 
}
int main() {
  i64 n, q;
  cin >> n >> q;
  auto st = make_seg_tree(
      n, [](i64 x, i64 y) { return min(x, y); }, (1ll << 31) - 1);
  while (q--) {
    i64 c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      st.set(x, y);
    } else {
      cout << st.seg(x, y + 1) << endl;
    }
  }
  return 0;
}



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

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

    int max = 0;
    int tmp = 0;
    int i = 0;
    while(s[i] != '\0'){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            tmp++;
        }
        else{
            if(tmp > max){
                max = tmp;
            }
            tmp = 0;
        }
        i++;
    }

    if(tmp > max){
        max = tmp;
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
  	 int b=sc.nextInt();
    if(a<10&&b<10){
    System.out.println(a*b);
    }else{
    System.out.println(-1);
    }
    
    
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define int long long
#define pb       push_back
#define io    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(a)      (a).begin(),(a).end()
#define endl        '\n'
#define F    first
#define S second
#define mod 1000000007 
#define N 4005
#define pii pair<int,int>
using namespace std;
int n,m;
long double dp[N][N];
vector<double> v(N);
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>v[i];
    dp[0][0]=1;
    
    for(int i=1;i<=n;i++)
        for(int j=0;j<=i;j++)
        {
            if(j==0)
                dp[i][j]=dp[i-1][j]*(1-v[i-1]);
            else
                dp[i][j]=dp[i-1][j]*(1-v[i-1]) + dp[i-1][j-1]*v[i-1];
        }
        
   /* for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n;j++)   
        cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    
    double ans=0;
    for(int i=(n+1)/2;i<=n;i++)
        ans+=dp[n][i];
    cout<<fixed<<setprecision(10)<<ans;
}
signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 186880
#include <bits/stdc++.h>
using namespace std;
struct node {
    vector<int> e;
    bool v = false;
};
void dfs(int u, node g[], int dp[]) {
    g[u].v = true;
    for(int i = 0; i < g[u].e.size(); i++) {
        if(!g[g[u].e[i]].v) 
            dfs(g[u].e[i],g,dp);
        dp[u] = max(dp[u],1 + dp[g[u].e[i]]);
    }
}
int main() {
    int n,m,u,v;
    cin>>n>>m;
    int dp[n+1] = {0};
    node g[n+1];
    for(int i = 0; i < m; i++) {
        cin>>u>>v;
        g[u].e.push_back(v);
    }
    for(int i = 1; i <= n; i++) {
        if(!g[i].v)
            dfs(i,g,dp);
    }
    int* ans = max_element(dp+1,dp+n+1);
    cout<<*ans<<endl;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans = 0;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
	string s; cin >> s;
	reverse(ALL(s));
	string t[4] = {"resare","esare","remaerd","maerd"};
	rep(i, s.size()) {
		string c = s.substr(i, 5);
		if (c == t[1] || c == t[3]) {
			i += 4;
			continue;
		}
		c = s.substr(i, 6);
		if (c == t[0]) {
			i += 5;
			continue;
		}
		c = s.substr(i, 7);
		if (c == t[2]) {
			i += 6;
			continue;
		}
		cout << "NO"  << endl;
		return 0;
	}cout << "YES" << endl;
}

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

typedef long long lli;
typedef vector<lli> vcL;

int main() {
	int n;
	while ( cin >> n ) {
		lli _size[ n+5 ], sSum[ n+5 ];
		sSum[0] = 0;
		vector<vcL> dp( n+5, vcL( n+5, 0 ) );
		
		for (int i = 0; i < n; ++i) { cin >> _size[i]; sSum[ i+1 ] = sSum[i] + _size[i]; }
		
//		for (int i = 0; i < n-1; ++i) dp[i][ i+1 ] = _size[i]+_size[ i+1 ];
		
		for (int i = 1; i < n; ++i) {
			for (int j = 0, k = i; j < n and k < n; ++j, ++k ) {
				lli _min = 1LL << 60;
				for (int l = j; l < k; ++l) {
					_min = min( _min, dp[j][l]+dp[ l+1 ][k] );
				}
				dp[j][k] = _min + sSum[ k+1 ] - sSum[j];
			}
		}
		
		cout << dp[0][ n-1 ] << '\n';
	}
	return 0;
}

Measured memory_bytes: 1536
S =raw_input()
a = S[:2]
b = S[2:]
a = int(a)
b = int(b)
if a<=12 and a!=0:
    a = 0
else:
    a = 1
if b<=12 and b!=0:
    b = 0
else:
    b = 1
if a+b ==0:
    print 'AMBIGUOUS'
elif a+b ==1:
    if a ==0:
        print 'MMYY'
    else:
        print 'YYMM'
else:
    print 'NA'

Measured memory_bytes: 2568
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vi R(N);
	for (int i = 0; i < N; i++) {
		cin >> R[i];
	}
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int t = R[i] - 1;
		if (t < i) {
			continue;
		}
		if (R[t] - 1 == i) {
			cnt++;
		}
	}
	cout << cnt << endl;
}



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

using namespace std;
#define ll long long

const int N = 1e5+7;
int arr[N];
int  n,m,a,b,ans;
map< string, int >mp;
map< string, int >mp2;
vector < string >vi;
int main()
{
    string s;
    cin>>n;
    for( int i = 0 ; i<n; i++)
    {
        cin>>s;
        vi.push_back(s);
        mp[s]++;
    }
    cin>>m;
    for( int i = 0 ; i<m; i++)
    {
        cin>>s;
        mp2[s]++;
    }

    for( auto x:vi)
    {
        int val =mp[x]-mp2[x];
        if(val>=0)
            ans= max(val,ans);

    }


    cout<<ans;
}





Measured memory_bytes: 256
s = input()
ls = list(s)
rls = list(reversed(ls))
words = []

temp = ls.pop(0)
words.append(temp)
temp = ""
for w in ls:
    temp += w
    if temp == words[-1]:
        temp = w
    else:
        words.append(temp)
        temp = ""
n = len(words)

ls = rls

words = []
temp = ls.pop(0)
words.append(temp)
temp = ""
for w in ls:
    temp += w
    if temp == words[-1]:
        temp = w
    else:
        words.append(temp)
        temp = ""
n = max(n,len(words))

print(n)


Measured memory_bytes: 11572
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Monad.Primitive
import qualified Data.Vector as V 
import qualified Data.Vector.Mutable as VM
import Control.Monad.ST
import Data.Foldable

main :: IO ()
main = breads >>= main'
    where
        main' nm = breads >>= main'' nm
        main'' [n, m] ps = replicateM m breads >>= print . solve n m ps

solve :: Int -> Int -> [Int] -> [[Int]] -> Int
solve n m ps xys = runST solveST
    where
        solveST :: ST s Int
        solveST = initTree >>= count
        initTree :: ST s (UFTree s)
        initTree = makeTreeM n >>= (\t -> t <$ mapM_ (\[x, y] -> unionNodesM (x - 1) (y - 1) t) xys)
        count uft = foldlM ff 0 $ zip [0..] ps
            where
                ff acc (i, p) = check acc <$> isSameM i (p - 1) uft 
                check acc b
                    | b = acc + 1
                    | otherwise = acc
            

newtype UFTree s = UFTree (VM.MVector s (Int, Int))

makeTreeM :: (PrimMonad m) => Int -> m (UFTree (PrimState m))
makeTreeM n = UFTree <$> V.unsafeThaw vec
    where
        vec = V.fromListN n $ zip (repeat 0) [0..]

findRootM :: (PrimMonad m) => Int -> UFTree (PrimState m) -> m Int
findRootM v t@(UFTree vs) = VM.unsafeRead vs v >>= checkRoot
    where
        checkRoot (_, root)
            | v == root = return v
            | otherwise = findRootM root t
            
unionNodesM :: (PrimMonad m) => Int -> Int -> UFTree (PrimState m) -> m ()
unionNodesM a b t@(UFTree vs) = mapM (flip findRootM t) [a, b] >>= checkRoot
    where
        checkRoot [c, d]
            | c == d = return ()
            | otherwise = mapM (VM.unsafeRead vs) [c, d] >>= checkRank c d 
        checkRank c d [ra, rb]
            | ra < rb = VM.unsafeModify vs (second (const d)) c
            | ra > rb = VM.unsafeModify vs (second (const c)) d
            | otherwise = VM.unsafeModify vs (\(x, _) -> (x + 1, c)) d
            
isSameM :: (PrimMonad m) => Int -> Int -> UFTree (PrimState m) -> m Bool
isSameM a b t = (==) <$> findRootM a t <*> findRootM b t
        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 42364
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
int main(){
    int n; cin>>n;
    string s; cin>>s;
    ll r=0,g=0,b=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R')r++;
        else if(s[i]=='G')g++;
        else b++;
    }
    
    ll rta = r*g*b;
    for(int i = 0; i<n; i++){
  		for(int j = i+1; j<n; j++){
  			int ind =2*j - i;
  			if(ind<n && s[i] != s[j] && s[j] != s[ind] && s[i] != s[ind])
				rta--;
		}
  	}
    cout<<rta<<endl;
}

Measured memory_bytes: 3636