akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define msn(x) (memset((x),0,sizeof((x))))
#define msi(x) (memset((x),-1,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
typedef long long ll;
using namespace std;
const int maxn=107;
const int maxm=1e4+7;
struct node
{
    int o,u,v;
}q[maxm];
vector<node>cmp;
int n,m;
bool dp[maxn][maxn];
bool emp[maxn][maxn];
vector<int>a,b;
bool check(int x)
{
    //queue< pair<int ,int> >q;
    cmp.clear();
    msn(dp);
    msn(emp);
    for(int i=1;i<=n;i++)dp[i][i]=1;
    for(int i=0;i<x;i++)
    {
        node &now=q[i];
        if(now.o==1)
        {
            dp[now.u][now.v]=1;
        }
        else if(now.o==2)
        {
            dp[now.u][now.v]=dp[now.v][now.u]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
                dp[j][k]|=(dp[j][i]&&dp[i][k]);
        }
    }

    for(int i=0;i<x;i++)
    {
         node &now=q[i];
        if(now.o==4)cmp.push_back(now);
    }
   // random_shuffle(cmp.begin(),cmp.end());
    for(int z=0;z<cmp.size();z++)
    {
         node &now=cmp[z];
        if(emp[now.u][now.v])continue;
            a.clear(),b.clear();
            for(int i=1;i<=n;i++)if(dp[i][now.u])a.push_back(i);
            for(int i=1;i<=n;i++)if(dp[i][now.v])b.push_back(i);
             for(int i=0;i<a.size();i++)
            {
                for(int j=0;j<b.size();j++)
                emp[b[j]][a[i]]=emp[a[i]][b[j]]=1;
            }
    }
    for(int i=0;i<x;i++)
    {
         node &now=q[i];
        if(now.o==5)
        {
            if(emp[now.u][now.v]||emp[now.u][now.u]||emp[now.v][now.v])return 0;
        }
    }
    for(int i=0;i<x;i++)
    {
         node &now=q[i];
         if(now.o==3)
         {
             if(emp[now.u][now.u]==1&&emp[now.v][now.v]==1)return 0;
             if(dp[now.u][now.v]==1&&dp[now.v][now.u]==1)return 0;
         }
    }
    return 1;
}
int main()
{
    while(scanf("%d %d",&n,&m))
    {
        if(n==0&&m==0)break;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&q[i].o,&q[i].u,&q[i].v);
        }
    int l=0,r=m;
        while(l<r)
        {
            int mid=(l+r)/2+1;
            if(check(mid))l=mid;
            else r=mid-1;
        }
       printf("%d\n",l);
    }
    return 0;
}

Measured memory_bytes: 1556
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>

void koch(int n, double d, double x, double y, int w)
{
	double r;
	double x1, y1;
	if(n == 0){
		r = w*M_PI/180.0;
		x1 = x + d * cos(r);
		y1 = y + d * sin(r);
		printf("%.8lf %.8lf\n", x1, y1);
		return;
	}

	d /= 3;
	koch(n - 1, d, x, y, w);

	r = w*M_PI/180.0;
	x = x + d * cos(r);
	y = y + d * sin(r);

	w += 60;
	koch(n - 1, d, x, y, w);

	r = w*M_PI/180.0;
	x = x + d * cos(r);
	y = y + d * sin(r);

	w += -120;
	koch(n - 1, d, x, y, w);

	r = w*M_PI/180.0;
	x = x + d * cos(r);
	y = y + d * sin(r);

	w += 60;
	koch(n - 1, d, x, y, w);

	return;
}

int main()
{
	int n;
	double x, y;

	scanf("%d", &n);
	x = y = 0;
	printf("%.8lf %.8lf\n", x, y);
	koch(n, 100, x, y, 0);

	return(0);
}

Measured memory_bytes: 644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main()
{
	string inp;
	cin >> inp;
	rep(i,inp.size()){
		if(inp[i] == '9') inp[i] = '1';
		else if(inp[i] == '1') inp[i] = '9';
	}

	cout << inp << endl;

    return 0;
}

/*
/^[\w!\x22\#$%&@\'() * +,-.\/;:]+$/
*/


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int>a(N);
    vector<int>nums(N);
    rep(i,N)
    {
        cin >> a[i];
        nums[a[i]-1]++;
    }
    sort(all(nums),greater<int>());
    //rep(i,nums.size()) cout << nums[i] << endl;
    int ans = 0;
    for(int i = K;i < nums.size();i++)
    {
        if(nums[i] == 0) break;
        ans += nums[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int k,a,b; 
	scanf("%lld%lld%lld",&k,&a,&b);
	long long int ans=0;
	if(k>=a+1)
	{
			long long int t=k;
			if(b>a)
			{
				k-=a+1;
				ans=b;
				ans+=(k/2)*(b-a);
				ans+=k%2;
				printf("%lld\n",max(ans,t+1));
			}
			else
			printf("%lld\n",t+1);
	}
	else
	printf("%lld\n",k+1);
	return 0;
}

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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int ss = n/2;
	bool flag = 1;
	if(n%2==0){
		int i=0, j=ss;
		while(j!=s.size()){
			if(s[i]!=s[j]){
				flag=false;
				break;
			}
			i++, j++;
		}	
	}
	else
	{
		cout<<"No\n";
		exit(0);
	}
	if(flag==true)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}	


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

int main()
{

	int N, p = 0;
	cin >> N;
	vector<int> a(N);

	for (int i = 0; i < N; i++)
		cin >> a.at(i);
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0)
			p += a.at(i);
		else
			p -= a.at(i);
	}
	cout << p << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            int n = sc.nextInt();
            int [] a = new int[n];
            for (int i = 0; i < a.length; i++ ){
                a[i] = sc.nextInt();
            }
            String delimiter = "";
            for (int i = a.length - 1; i >= 0; i--){
                System.out.print(delimiter);
                System.out.print(a[i]);
                delimiter = " ";
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 26192
import queue


def m():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    q = queue.Queue()
    for i in range(1, n+1):
        for _ in range(a[i-1]):
            q.put(i)
    # a.sort(reverse=True)
    ans = [[0 for _ in range(w+1)] for _ in range(h+1)]

    for i in range(1, h+1):
        if i % 2 == 1:
            for k in range(1, w+1):
                ans[i][k] = q.get()
        else:
            for k in range(w, 0, -1):
                ans[i][k] = q.get()

    for i in range(1, h+1):
        for k in range(1, w+1):
            print(ans[i][k], end=' ')
        print('')

m()

Measured memory_bytes: 4844
def solve():
  D = int(input())
  C = list(map(int, input().split()))
  S = [list(map(int, input().split())) for _ in range(D)]

  ans = [0]*D

  for d in range(D):
    ans[d] = d%26+1
  
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 9396
def f(x, y):
    a = [[1,3,5,7,8,10,12], [4,6,9,11], [2]]
    for b in a:
        if x in b and y in b:
            return True
    return False

x, y = [int(x) for x in input().split(' ')]

print('Yes' if f(x, y) else 'No')




Measured memory_bytes: 3064
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, a: [[i32; 3];n]};
    let a: Vec<Vec<i32>> = a;
    let mut v = vec![vec![-1; 3]; n];
    v[0][0] = a[0][0];
    v[0][1] = a[0][1];
    v[0][2] = a[0][2];

    for i in 0..a.len() - 1 {
        // i => いまのくみ
        for j in 0..3 {
            // j => 今のやつ
            for k in 0..3 {
                if k == j {
                    continue;
                }
                v[i + 1][k] = std::cmp::max(v[i + 1][k], v[i][j] + a[i + 1][k])
            }
        }
    }

    println!("{}", v[v.len() - 1].iter().max().unwrap());
}


Measured memory_bytes: 14636
from collections import deque           
#頂点数と辺数
N, M = map(int, input().split())

#グラフ入力受取(無向グラフを想定)
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

#BFSのためのデータ構造
dist = [False]*N #全頂点を「未訪問」に初期化
que = deque()

#初期条件（頂点0を初期ノードとする）
dist[0] = True
que.append(0) #0を訪問予定頂点にする
ans = [0]*N

#BFS開始（キューが空になるまで探索を行う）
while len(que)!=0:
    v = que.popleft() #キューから先頭頂点を取り出す

    #v から辿れる頂点を全て調べる
    for nv in G[v]:
        #すでに発見済みの頂点は探索しない
        if dist[nv]:
            continue 

        #新たな白色頂点 nv について距離情報を更新してキューに追加する
        dist[nv] = True
        ans[nv] = v 
        que.append(nv)

    #結果出力（各頂点の頂点 0 からの距離を見る）
if any(dist):
    print("Yes")
    for v in range(1,N):
        print(ans[v]+1)
else:
    print("No")



Measured memory_bytes: 34812
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut kv: Vec<Vec<usize>> = vec![[].to_vec(); m];
    for mi in 0..m {
        let k = read::<usize>();
        for _ in 0..k {
            let v = read::<usize>();
            kv[mi].push(v);
        }
    }

    let mut pv: Vec<usize> = vec![];
    for _ in 0..m {
        let p = read::<usize>();
        pv.push(p);
    }

    let mut ans = 0;
    for i in 0..(1 << n) {
        let mut num_on = 0;
        for (p, vi) in pv.iter().zip(kv.iter()) {
            let mut cnt: usize = 0;
            for vj in vi {
                if i & (1 << (vj - 1)) > 0 {
                    cnt += 1;
                }
            }
            if cnt % 2 == *p {
                num_on += 1;
            }
        }
        if num_on == m {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;


     
int main()
{
	fast;
		
		
	string s,t;
	cin>>s>>t;
	
	ll i;
	ll n=s.size();
	ll m=t.size();
	
	ll ans=m;
	
	for(i=0;i<=n-m;i++)
	{
		ll cnt=0;
		ll fuck=0;
		for(ll j=0;j<m && i+j<n;j++)
		{
				if(s[i+j]!=t[j])
				{
					
					cnt++;
				}	
				fuck++;
		}
		if(fuck)
		ans=min(cnt,ans);
	}
	
		cout<<ans<<endl;	
		
	return 0;
}
     
     
     
     
     
     
     
     
     
     
     
     

Measured memory_bytes: 3676
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

//func readLine(reader *bufio.Reader) string {
//	str, _, err := reader.ReadLine()
//	if err == io.EOF {
//		return ""
//	}
//	return string(str)
//}
func readLine() []string {
	reader := bufio.NewReaderSize(os.Stdin, 1)
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return []string{}
	}
	return strings.Split(string(str), " ")
}

func round(f float64) float64 {
	return math.Floor(f + .5)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	defer out.Flush()
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	winner := make(map[int]bool, n)
	hs := make([]int64, n)
	for i := 0; i < n; i++ {
		h := next()
		a, _ := strconv.ParseInt(h, 10, 64)
		hs[i] = a
		winner[i] = true
	}
	for i := 0; i < m; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		if hs[a] == hs[b] {
			winner[a] = false
			winner[b] = false
			continue
		}
		if hs[a] < hs[b] {
			winner[a] = false
		} else {
			winner[b] = false
		}
	}
	count := 0
	for _, v := range winner {
		if v {
			count++
		}
	}
	fmt.Fprintln(out, count)
}


Measured memory_bytes: 6084
l = input()
a = 0
if int(l[0]) == 1:
    a = a + 1
else:
    pass
if int(l[1]) == 1:
    a = a + 1
else:
    pass
if int(l[2]) == 1:
    a = a + 1
else:
    pass
print(a)

Measured memory_bytes: 2940
#B - Collecting Balls (Easy Version)
N = int(input())
K = int(input())
x = list(map(int,input().split()))

distance = 0
for i in x:#全てのyでの試行
    if abs(i - K) < i:
        distance += 2 * abs(i - K)
    else :
        distance += 2 * i
print(distance)

Measured memory_bytes: 9136
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int hight[10];
	for (int i = 0; i < 10; i++) {
		cin>>hight[i];
	}
	sort(hight,hight+10);
	for (int i = 0; i < 3; i++) {
		cout<<hight[9-i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

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

Measured memory_bytes: 3600
N,K = map(int,input().split())
S = input()
if S[0] == '0':
  divide = []
else:
  divide = [0]
tmp = 1
for i in range(1,N):
  if S[i] == S[i-1]:
    tmp += 1
  else:
    divide += [tmp]
    tmp = 1
divide += [tmp]
le = len(divide)
zero = [0]*2*le + divide + [0]*2*le
su = [0]
for i in range(0,5*le):
  su += [su[-1]+zero[i]]
del su[0]
lle = len(su)
mxm = 0
for k in range(K,lle):
  if 2*k+1 >= lle:
    break
  cd = su[2*k+1] - su[2*k-2*K]
  if cd > mxm:
    mxm = cd
xmx = max(divide)
print(max(mxm,xmx))

Measured memory_bytes: 24500
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}

bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}

lld fact(lld n);
lld nCr(lld n,lld r){ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
lld fact(lld n){ 
    lld res = 1; 
    for(lld i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 

// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];

// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int n;
    cin>>n;
    // vector<string> v;
    unordered_map<string,int> ump;
    for(int i=0;i<n;++i){
        string temp;
        cin>>temp;
        sort(temp.begin(),temp.end());
        ump[temp]++;
    }
    // for(auto x:ump){
    //     cout<<x.ff<<" "<<x.ss<<endl;
    // }
    long long sum=0;
    for(auto x:ump){
        sum+=(long long)(x.ss)*(x.ss-1)/2;
    }
    test(sum);
    // int cnt=0;
    // for(int i=0;i<n;++i){
    //     for(int j=i+1;j<n;++j){
    //         if(v[i]==v[j]){
    //             ++cnt;
    //         }
    //     }
    // }
    // test(cnt);
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 10660
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 5;

ll dp[N];
ll no[N];
int a[N];
ll sum[N];
int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	F(i, 0, n)
		cin >> a[i];
	no[n - 1] = 1;
	sum[a[n - 1]] = 1;
	DF(i, n - 2, 0){
		if(a[i] == a[i + 1]){
			no[i] = dp[i + 1] + no[i + 1];
			no[i] %= mod;
			cont;
		}
		no[i] = dp[i + 1] + no[i + 1];
		no[i] %= mod;
		dp[i] = sum[a[i]];
		sum[a[i]] += no[i];
		sum[a[i]] %= mod;
	}
	ll res = dp[0] + no[0];
	cout << res%mod << endl;
	return 0;
}


Measured memory_bytes: 5760
// AOJ 2342 Light Road
// 2018.4.8 bal4u

#include <stdio.h>

#define QMAX 51000
typedef struct { char r, c, d, a, b; } Q;
Q que[QMAX+2]; int top, end;
char map[103][103];
char mk[103][103][4][11][11];
int  mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int  ma[4][4] = {{0,-1,-1,1},{-1,0,1,-1},{-1,1,0,-1},{1,-1,-1,0}};
int  mb[4][4] = {{0,1,-1,-1},{1,0,-1,-1},{-1,-1,0,1},{-1,-1,1,0}};

int main()
{
	int H, W, A, B, r, c, d, a, b, nr, nc, nd, na, nb, ans;
	int sr, sc, gr, gc;
	char buf[20];

	fgets(buf, 20, stdin), sscanf(buf, "%d%d%d", &H, &W, &A), B = A;
	for (r = 0; r < H; r++) {
		fgets(map[r], 103, stdin);
		for (c = 0; c < W; c++) {
			if (map[r][c] == 'S') sr = r, sc = c;
			if (map[r][c] == 'G') gr = r, gc = c;
		}
	}
	if (sr == H-1 || map[sr+1][sc] == '#') { puts("-1"); return 0; }
	que[0].r = sr+1, que[0].c = sc, que[0].d = 2, que[0].a = que[0].b = 0;
	for (a = 0; a <= A; a++) for (b = 0; b <= B; b++) mk[sr][sc][0][a][b] = 1;
	top = 0, end = 1;
	ans = 100;
	while (top != end) {
		r = que[top].r, c = que[top].c, d = que[top].d, a = que[top].a, b = que[top].b;
		if (++top == QMAX) top = 0;
		if (r == gr && c == gc) {
			if (a+b < ans) ans = a+b;
			continue;
		}
		if (mk[r][c][d][a][b]) continue;
		mk[r][c][d][a][b] = 1;
		for (nd = 0; nd < 4; nd++) {
			nr = r + mv[nd][0], nc = c + mv[nd][1], na = ma[d][nd], nb = mb[d][nd];
			if (na < 0 && nb < 0) continue;
			if (nr < 0 || nr >= H || nc < 0 || nc >= W || map[nr][nc] == '#') continue;
			que[end].r = nr, que[end].c = nc, que[end].d = nd;
			if (na > 0) {
				if (a+1 > A || map[r][c] == 'S') continue;
				if (mk[nr][nc][nd][a+1][b]) continue;
				que[end].a = a+1, que[end].b = b;
			} else if (nb > 0) {
				if (b+1 > B || map[r][c] == 'S') continue;
				if (mk[nr][nc][nd][a][b+1]) continue;
				que[end].a = a, que[end].b = b+1;
			} else if (!na)	{
				que[end].a = a, que[end].b = b;
				if (mk[nr][nc][nd][a][b]) continue;
			}
			if (++end == QMAX) end = 0;
		}
	}
	if (ans > 20) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5412
#define INF 1000000
int graph[101][101],n,c,d;

void warshall_floyd(){
  int i,j;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
}

int min(int x,int y){
  return x<y?x:y;
}

int main(){
  int k,i,j,x,e,a,b;

  while(scanf("%d %d",&n,&k),n,k){

    for(i=0;i<=n;i++)
      for(j=0;j<=n;j++)
	graph[i][j]=i==j?0:INF;

    for(i=0;i<k;i++){
      if(scanf("%d",&x),x){
	scanf("%d %d %d",&c,&d,&e);

	if(graph[c][d]>e){
	graph[c][d]=e;
	graph[d][c]=e;
	warshall_floyd();
	}
      }else{
	scanf("%d %d",&a,&b);
	printf(graph[a][b]>=INF?"-1\n":"%d\n",graph[a][b]);
      }
    }
  }
  return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

const int mod = 1e9 + 7;

#define pow abcdef
int pow(int a, int b) {
  if (b == 0) return 1;
  int t = pow(a, b / 2);
  t = (t * t) % mod;
  if (b % 2) return (t * a) % mod;
  return t;
}

void Main() {
  int n; cin >> n;
  vector<int> a(n), b(60);
  for (auto &i : a) {
    cin >> i;
    for (int j = 0; j < 60; j++) {
      b[j] += getBit(i, j);
    }
  }
  int cal = 0;
  for (int j = 0; j < 60; j++) {
    cal += ((1ll << j) % mod) * ((b[j] * (n - b[j])) % mod);
    cal %= mod;
  }
  cout << cal << '\n';
}

signed main() {
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 5520
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner fsc = new FastScanner();
        int n = fsc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = fsc.nextLong();
        }
        long cnt = 0;
        while (true) {
            long s = 0;
            long[] c = new long[n];
            for (int i = 0; i < n; i++) {
                long k = a[i] / n;
                s += c[i] = k;
                a[i] %= n;
            }
            for (int i = 0; i < n; i++) {
                a[i] += s - c[i];
            }
            cnt += s;
            if (s == 0) {
                break;
            }
        }
        System.out.println(cnt);
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 23252
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)

d=c-(a+b)
# print(d)
if(d>0):
    l=4*a*b
    if(d*d>l):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string> ve;
    for(int i=0;i<n;i++){
        string t;
        cin>>t;
        ve.push_back(t);
    }
    cout<<string(m+2,'#')<<endl;
    for(int i=0;i<ve.size();i++){
        cout<<"#"<<ve[i]<<"#"<<endl;
    }
    cout<<string(m+2,'#')<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
  
int main() {
    char s1[1000001];
    char s2[10001];
    int i, j, k;
  
    scanf("%s", s1);
    scanf("%s", s2);
      
    int s1len = strlen(s1);
    int s2len = strlen(s2);
  
    for (i = 0; i < s1len; i++) {
        if(strncmp(s2, &s1[i], s2len)==0) printf("%d\n", i);
    }
  
    return 0;
}


Measured memory_bytes: 2796
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		scanner.close();
		if ((A == 0 && B == 1) || (A == N && B == N - 1)) {
			System.out.println("Borys");
			return;
		}
		
		if ((A - B) % 2 != 0) {
			System.out.println("Borys");
			return;
		} else {
			System.out.println("Alice");
			return;
		}
		
	}
	
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
int n,a[MAXN],b[MAXN],c[MAXN],temp,d[MAXN];
long long ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n+1;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=n+1;i++)
		d[i]=a[i];
	for(int i=1;i<=n;i++){
		c[i]=b[i]-a[i];
		if(c[i]>0){
			a[i+1]=max(0,a[i+1]-c[i]);
			if(i==n)
				temp=c[i];
			c[i]=0;
		}
	}
	for(int i=1;i<=n;i++)
		ans=ans+d[i]+c[i];
	ans=ans+min(temp,d[n+1]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

#define POS(i,j) (((i)&1)*3+(j))

void run(void){
  int n;
  scanf("%d",&n);
  int dp[6]={0,0,0,0,0,0};
  for(int i=0;i<n;i++){
    int v[3];
    int j;
    for(j=0;j<3;j++) scanf("%d",v+j);
    for(j=0;j<3;j++){
      for(int k=0;k<3;k++){
	if(j==k) continue;
	dp[POS(i+1,k)]=MAX(dp[POS(i+1,k)],dp[POS(i,j)]+v[k]);
      }
    }
  }
  printf("%d\n",MAX(MAX(dp[POS(n,0)],dp[POS(n,1)]),dp[POS(n,2)]));
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  int *A, *B, C[VMAX];
  int n;
  int i,j,k = 0;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

  for( i = 0;i < n;i++){
    scanf("%d",&A[i]);
    if(A[i] > k){
      k = A[i];
    }
  }

  for(i = 0;i <= k;i++){
    C[i] = 0;
  }
     
  for( j = 0;j < n;j++){
    C[A[j]]++;
  }
  
  for( i = 1;i <= k;i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j = n - 1;j >= 0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1;i <= n;i++){
    if(i == n ){
      printf("%d",B[i]);
    }
    else printf("%d ",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17400
#include <iostream> // cout, endl, cin
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	char α;
	cin >> α;
	
	if (isupper(α)) {
		cout << "A" << endl;
	}

	else if (islower(α)) {
		cout << "a" << endl;

	}

}


Measured memory_bytes: 3104
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

$arr = array();

fscanf(STDIN, "%d %d", $N, $M);
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $a, $b);
    if ($a == 1 || $b == 1) {
        $aa[$b] = 1;
    }
    if ($a == $N || $b == $N) {
        $bb[$a] = 1;
    }
}

foreach ($aa as $key => $val) {
    if (isset($bb[$key])) {
        echo "POSSIBLE\n";
        exit;
    }
}
echo "IMPOSSIBLE\n";


Measured memory_bytes: 17144
a,b = map(int,input().split())

if (a < 0 and b > 0) or a == 0 or b == 0:
	print("Zero")
elif a > 0:
	print("Positive")
elif b < 0:
	if (b - a + 1) % 2 == 0:
		print("Positive")
	else:
		print("Negative")


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> ss(3);
    ss[0] = a;
    ss[1] = b;
    ss[2] = c;
    sort(ss.begin(), ss.end());

    if(ss[0] == 5 && ss[1] == 5 && ss[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int solve()
{
    string inp;
    int out_cnt = 0;
    int score = 0;
    bool base[3];

    for (int i = 0; i < 3; i++)
        base[i] = false;

    while (out_cnt < 3) {
        cin >> inp;

        if (inp == "OUT") 
            out_cnt++;
        else if (inp == "HIT") {
            if (base[2])
                score++;
            base[2] = base[1];
            base[1] = base[0];
            base[0] = true;
        }
        else if (inp == "HOMERUN") {
            for (int i = 0; i < 3; i++) {
                if (base[i])
                    score++;
                base[i] = false;
            }
            score++;
        }
    }
    return score;
}

int main()
{
    int n;

    cin >> n;
    while (n--) 
        cout << solve() << endl;

    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  ll N;cin>>N;
  map<ll,int> mp;
  // 同じものが４つ存在する場合もある
  // ２つ以上存在する辺を全て取得して、2つ存在するならtmpに一つ、4つ以上なら２つpush_back
  // 最後に後ろから二つとる
  REP(i,N) {
    ll a;cin>>a;
    mp[a]++;
  }
  vector<ll> tmp;
  for (auto m:mp) {
    if (m.second>=2) tmp.push_back(m.first);
    if (m.second>=4) tmp.push_back(m.first);
  }
  if (tmp.size()<=1) {
    OUT(0);
    return 0;
  }

  ll ans = 1;
  REP(i,2) {
    ans *= tmp.back();
    tmp.pop_back();
  }
  OUT(ans);

  return 0;
}

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

int main() {

  int N, sum = 0, i;

  cin >> N;

  int A[N];

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

  i = 0;
  while(true)
  {
    if(A[i] % 2 == 0)
    {
      A[i] = A[i] / 2;
    }
    else
    {
      break;
    }

    i++;
    if(i == N)
    {
      i = 0;
      sum++;
    }
  }

  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define SORT(c) sort(ALL((c)))
#define debug(x)                 \
    do {                         \
        std::cout << #x << ": "; \
        view(x);                 \
    } while (0)

template <typename T>
void view(T e) {
    std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << ", ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= (N + 1); i++) {
        ll mi = i * (i - 1) / 2;
        ll ma = 0;
        rep(j, i) { ma += N - j; }
        ma = i * (2 * (N - i + 1) + (i - 1)) / 2;
        ans += (ma - mi + 1) % (1000000000 + 7);
    }
    cout << ans % (1000000000 + 7) << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    string n;
    cin  >> n;
    for(int i=0;i<n.length();i++){
        if(n[i] == '7'){
            cout << "Yes"<<endl;
            return 0;
        }
    }
    cout << "No"<<endl;
    return 0;
}

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

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

constexpr ll INF = 1e15;
constexpr ll mod = 1e9 + 7;

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

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

int main() {
	ll n;
	cin >> n;
	ll sum = 0;
	for (ll i = 1; i * i < n; i++) {
		//i == j;
		sum++;
		for (ll j = i + 1; i * j < n; j++) {
			sum += 2;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int N;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> N;
    vector<ll> v(N);
    ll minn = 1e12;
    ll sum = 0;
    for(int i=0; i<N; i++) {
        cin >> v[i];
        minn = min(minn, v[i]);
        sum+=v[i];
    }
    //sort the numbers insert the bigger nums first
    sort(v.rbegin(), v.rend());
    //first one already inserted
    ll res = 0;
    //we need to insert n-1 numbers after the first
    //keep track of the max positions open
    deque<ll> s;
    for(int i=1; i<N; i++) {
        if(i==1) {
            res+=v[i-1];
            //two positions available with this elements comfort
            s.push_back(v[i]);
            s.push_back(v[i]);
            continue;
        }
        //pop the front is the value
        ll f = s.front();
        s.pop_front();
        res+=f;
        //adding this position adds 2 spots with comfort v[i];
        s.push_back(v[i]);
        s.push_back(v[i]);
    }
    cout << res << "\n";
    // 3 3 2 2
    // 0 3 3 3
    // 3
    // 3 3
    // 3 2 3
    // 3 2 3 2
    return 0;
}


Measured memory_bytes: 6380
#include<iostream>
#include<vector>
using namespace std;
#define ll long long 

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

    vector<ll> dp(n+1);
    dp[0] = 1; dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3108
#include <cstdio>

int main(){
    int N = 0;
    int leftcnt = 0;
    int cnt = 0;
    char temp = 0;
    char str[101] = {};
    scanf("%d\n", &N);
    for(int i=0; i < N; i++){
        scanf("%c", &temp);
        str[i] = temp;
        if(temp == '('){
            cnt++;
        }else if(temp == ')'){
            cnt--;
            if(cnt == -1){
                cnt = 0;
                leftcnt++;
            }
        }else{
            printf("ERROR!\n");
            return 1;
        }
    }

    /* print */
    for(int i=0; i < leftcnt; i++){
        printf("(");
    }
    printf("%s", str);
    for(int i=0; i < cnt; i++){
        printf(")");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main() {
  string S;
  cin >> S;
  int i=stoi(S.substr(0,4)),j=stoi(S.substr(5,2)),k=stoi(S.substr(8,2));
  if(i<=2018){
    cout << "Heisei" << endl;
    return 0;
  }else if(i==2019 && j<=3){
    cout << "Heisei" << endl;
    return 0;
  }else if(i==2019 && j==4 && k<=30){
    cout << "Heisei" << endl;
    return 0;
  }else{
    cout << "TBD" << endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MIN(a,b) ((a)<(b)?(a):(b))

int main(void){
    int x;
    scanf("%d", &x);
    for(;;){
        int f = 0;
        for (int i = 2; i < MIN(sqrt(x+10),x); i++) {
            if (x % i == 0) { //割り切れたら
                f = 1;
                break;
            }
        }
        if (f) {
            x++;
            continue;
        }
        printf("%d\n",x);
        exit(0);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    vector<vector<ll>> price(2, vector<ll>(3));
    Rep (i, 2) {
        Rep (j, 3) {
            cin >> price[i][j];
        }
    }

    vector<vector<ll>> dp(4, vector<ll>(N+1, 0));
    Rep (i, 3) {
        ll pa = price[0][i];
        ll pb = price[1][i];
        Rep (j, N+1) {
            chmax(dp[i+1][j], dp[i][j]);
            if (j >= pa) {
                chmax(dp[i+1][j], dp[i+1][j-pa] + pb - pa);
            }
        }
    }

    ll M = N + dp[3][N];

    dp.assign(4, vec(M+1, 0));
    Rep (i, 3) {
        ll pa = price[0][i];
        ll pb = price[1][i];
        Rep (j, M+1) {
            chmax(dp[i+1][j], dp[i][j]);
            if (j >= pb) {
                chmax(dp[i+1][j], dp[i+1][j-pb] + pa - pb);
            }
        }
    }

    cout << M + dp[3][M] << "\n";
}

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

using namespace std;

int main()
{
    int N,D,num;
    cin>>N>>D;
    if(N%(2*D+1)==0)
        num=N/(2*D+1);
    else
        num=N/(2*D+1)+1;
    cout<<num<<endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;


        static void Main(string[] args)
        {
            int A = IO.ReadInt();

            int L = A / 100;
            int R = A % 100;

            if (1 <= L && L <= 12)
            {
                if (1 <= R && R <= 12)
                {
                    WriteLine("AMBIGUOUS");
                }
                else WriteLine("MMYY");
            }
            else
            {
                if (1 <= R && R <= 12) WriteLine("YYMM");
                else WriteLine("NA");
            }

        }

        static int ToInt(char c) => c - '0';

        #region MIN,MAX

        /// <summary>
        /// 最大値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MaxValue<T>(params T[] vals) => vals.Max();

        /// <summary>
        /// 最小値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MinValue<T>(params T[] vals) => vals.Min();
        #endregion
    }

    #region IO

    /// <summary>
    /// IO
    /// </summary>
    public class IO
    {
        public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine();
        public static int ReadInt() => int.Parse(ReadStr());

        public static long ReadLong() => long.Parse(ReadStr());

        public static decimal ReadDecimal() => decimal.Parse(ReadStr());
        public static double ReadDouble() => double.Parse(ReadStr());
        public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator);
        public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse);
        public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse);

        public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse);
        public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse);

        public static void Cout<T>(T value) => WriteLine(value);
        public static void CoutJoin<T>(T[] values, string separator = " ") => Cout(string.Join(separator, values));
    }

    #endregion    
}


Measured memory_bytes: 11092
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()

mod = 10 ** 9 + 7

f = [i for i in range(N+1)]
for i in range(2, N+1):
    f[i] *= f[i-1]
    f[i] %= mod
f[0] = 1

q = K - 1
fk = pow(f[q], mod - 2, mod)

total = 0

for i in range(N - K + 1):
    p = N - i - 1

    c = (f[p] * fk * pow(f[p-q], mod-2, mod)) % mod
    total += c * (A[-1 - i] - A[i])
    total %= mod

print(total)


Measured memory_bytes: 14416
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
 
struct State {
  int prev;
  int now;
  int vel; // 到着時
  double e_time;
   
  bool operator < (const State &s) const {
    return e_time > s.e_time;
  }
   
  State() {}
  State(int p, int n, int v, double t) :
    prev(p), now(n), vel(v), e_time(t) {}
};
 
struct Edge {
  int to;
  int cost;
  int lim;
   
  Edge() {}
  Edge(int t, int c, int l) : to(t), cost(c), lim(l) {}
};
 
const double Inf = 1<<23;
int N, M;
vector<Edge> edges[30];
double G_time[31][30][31]; // u, v, vel -> e_time
 
double dijkstra(int s, int g) {
   
  fill(G_time[0][0], G_time[30][30], Inf);
  priority_queue<State> pq;
   
  pq.push(State(s, s, 0, 0.0));
  G_time[s][s][0] = 0.0;
   
  while(!pq.empty()) {
    const State st = pq.top(); pq.pop();
     
    if(G_time[st.prev][st.now][st.vel] < st.e_time) {
      continue;
    }
     
    if(st.now == g && st.vel == 1) {
      return st.e_time;
    }
     
    for(int i=0; i<(int)edges[st.now].size(); i++) {
      const Edge &e = edges[st.now][i];
      
      if(e.to == st.prev) continue;
      
      for(int dvel = -1; dvel <= 1; dvel ++) {
	int nvel = st.vel + dvel;
	// 速度制限
	if(1 <= nvel && nvel <= e.lim) {
	  double ntime = G_time[st.prev][st.now][st.vel] + (double)e.cost / nvel;
	  if(G_time[st.now][e.to][nvel] > ntime) {
	    G_time[st.now][e.to][nvel] = ntime;
	    pq.push(State(st.now, e.to, nvel, ntime));
	  }
	}
      }
      
    }
  }
   
  return 42;
}
 
int main() {
  int s, g;
   
  while(cin >> N >> M && (N|M)) {
    cin >> s >> g;
    s --, g --;
     
    for(int i=0; i<N; i++)
      edges[i].clear();
     
    for(int i=0; i<M; i++) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      x --, y --;
      edges[x].push_back(Edge(y, d, c));
      edges[y].push_back(Edge(x, d, c));
    }
     
    double ans = dijkstra(s, g);
    if(ans == 42) {
      cout << "unreachable" << endl;
    } else {
      printf("%.5lf\n", ans);
    }
  }
   
  return 0;
}

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

int n, east[364364] = {}, west[364364] = {}, ans = 1;
string s;

int calc(int i) {
    return west[i - 1] + east[n] - east[i];
}

int main(void) {
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E')
            east[i + 1] = 1;
        if (s[i] == 'W')
            west[i + 1] = 1;
        east[i + 1] += east[i];
        west[i + 1] += west[i];
    }
    for (int i = 1; i <= n; i++) {
        if (calc(i) < calc(ans))
            ans = i;
    }
    cout << calc(ans) << endl;
}


Measured memory_bytes: 3076