akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

import sys

n,k = [ int(x) for x in sys.stdin.readline().split() ]
d1 = [ [] for _ in range(n) ]
for _ in range(n-1):
    ai,bi = [ int(x)-1 for x in sys.stdin.readline().split() ]
    d1[ai].append( bi )
    d1[bi].append( ai )
#
flag = [ True ] * n
flag[0] = False
total = k
now = k
nxt = [ d1[0] ]
while nxt:
    tmp= []
    for points in nxt:
        if now!=k: now= k-1
        for v in points:
            if not flag[v]: continue
            flag[v]= False
            tmp.append(v)
            now -= 1
            total= ( total * now ) % 1000000007
    #
    nxt= []
    for v in tmp:
        a= [ vv for vv in d1[v] if flag[vv] ]
        if a: nxt.append( a )
#
print( total )


Measured memory_bytes: 25148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
 
ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<"\n";
}

Measured memory_bytes: 3636
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

#pragma endregion 

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

	int n;
	cin >> n;
	vs s(n);
	f_vI(s, n);
	sort(all(s));
	if (n == 1) {
		sort(all(s[0]));
		cout << s[0];
		return 0;
	}
	vector<map<char, LL>>m(n);
	f(i, 0, n) {
		f(j, 0, size(s[i])) {
			m[i][s[i][j]]++;
		}
	}
	for (char a = 'a'; a <= 'z'; a++) {
		LL num = (LL)1e9;
		f(i, 1, n) {
			num = min(num, m[i][a]);
			if (num == 0) {
				break;
			}
		}
		f(i, 1, num + 1) {
			cout << a;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int *a = new int[n];
	for (int i = 0; i<n; i++)
	{
		scanf("%d", a + i);
	}
	int nn = n / 2;
	if (n % 2 == 0)
	{
		for (int i = 0; i<nn; i++)
		{
			printf("%d ", a[n - 2 * i - 1]);
		}
		for (int i = 0; i<nn; i++)
		{
			printf("%d ", a[2 * i]);
		}
	}
	else
	{
		for (int i = 0; i<nn; i++)
		{
			printf("%d ", a[n - 2 * i - 1]);
		}
		printf("%d ", a[0]);
		for (int i = 0; i<nn; i++)
		{
			printf("%d ", a[2 * i + 1]);
		}
	}
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed main(){
	int K, i, l, r;
	scanf("%lld", &K);
	int *a = (int *)malloc(sizeof(int) * K);
	for(i = 0; i < K; i++){
		scanf("%lld", &a[i]);
	}
	int maxN = 2, minN = 2;
	for(i = K - 1; i >= 0; i--){
		l = (minN + a[i] - 1) / a[i];
		r = maxN / a[i];
		if(l > r){
			printf("-1\n");
			return 0;
		}
		else{
			minN = l * a[i];
			maxN = r * a[i] + a[i] - 1;
		}
	}
	printf("%lld %lld\n", minN, maxN);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
using namespace std;
typedef unsigned int uint;
uint maxv;
void solve(uint now,uint m,uint *a,int n){
  int r=n-1,l=0,mid;
  while(l <=r){
    mid = (l+r)/2;
    if ( a[mid]+now>m)r=mid-1;
    else if ( a[mid]+now <=m){
      if ( a[mid]+now >maxv)maxv=a[mid]+now;
      l=mid+1;
    }
    //else break;
  }
  //if ( now+a[mid]>maxv&& now+a[mid]<=m)maxv=now+a[mid];
}


main(){
  int n;
  uint m;
  while(scanf("%d%u",&n,&m) && n){
    uint one[n];
    uint two[n*n];
    int p=0;
    maxv=0;
    for(int i=0;i<n;i++)scanf("%u",&one[i]);
    for(int i=0;i<n;i++){
      if ( one[i]>maxv &&one[i] <=m)maxv=one[i];
      for(int j=i;j<n;j++){
	if ( one[i]+one[j]>m)continue;
	two[p++]=one[i]+one[j];
	if (two[p-1]>maxv)maxv=two[p-1];
      }
    }
    sort(one,one+n);
    sort(two,two+p);
    for(int i=0;i<p;i++){
      if ( two[i]+one[0]>m)break;
      //      if ( two[i]+two[0]<=m)solve(two[i],m,two,p);
      //if ( two[i]+one[0]<=m)solve(two[i],m,one,n);
      solve(two[i],m,two,p);
      solve(two[i],m,one,n);
    }
    printf("%u\n",maxv);
  }
  return false;
}

Measured memory_bytes: 3052
#include<stdio.h>
#include<string.h>

int main(void){
int i,j,n,m1,m2,ta=0,ha=0;
char taro[101],hanako[101];
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%s%s",taro,hanako);
m1=strlen(taro);
m2=strlen(hanako);
if(m1<m2) m1=m2;

for(j=0;j<m1;j++){
   // printf("  %d %d\n",taro[j],hanako[j]);
if(taro[j]<hanako[j]){
    
ha+=3;
break;
}else if (taro[j]>hanako[j]){
ta+=3;
break;
}else{
    if(m1==j+1){
ta+=1;
ha+=1;
}

}
}

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

}


Measured memory_bytes: 2084
package main

import "fmt"

func main() {
  var n, m, c int
  fmt.Scan(&n,&m,&c)

  bs := make([]int, m)
  for i := 0; i<m; i++ {
    fmt.Scan(&bs[i])
  }
  arr := make([][]int, n)
  for i:=0; i<n; i++{
    arr[i] = make([]int, m)
  }

  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      fmt.Scan(&arr[i][j])
    }
  }
  var result int
  for i := 0; i < n; i++ {
    tmp := c
    for j := 0; j < m; j++ {
      tmp += bs[j] * arr[i][j]
    }
    if 0 < tmp {
      // fmt.Println(tmp)
      result ++
    }
  }

  fmt.Println(result)
}


Measured memory_bytes: 512
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in.head
  val w = S.count(_ == 'o')
  val l = S.count(_ == 'x')
  val pos = (l <= 7)
  val ret = if(pos) "YES" else "NO"
  println(ret)
}


Measured memory_bytes: 25416
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;

template<typename T>
T add(T a,T b){
  return a+b;
}

namespace A
{
  int f(void){
    return 1;
  }
}


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

  for(int i=0;i<n;i++){
    double x1,y1,x2,y2,x3,y3,x4,y4;
    std::cin >> x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;

    if(abs((x1-x2)*(y3-y4)-(x3-x4)*(y1-y2))<1.0e-10){
      std::cout << "YES" << '\n';
    }else{
      std::cout << "NO" << '\n';
    }
  }
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if (c <= a + b)
        cout << c + b << endl;
    else
        cout << a + b + b + 1 << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	static Scanner s = new Scanner(System.in);
	public static void main(String __[]){
		solve(
				s.nextInt(),
				s.nextInt(),
				s.nextInt()
				);
	}
	private static final void solve(int a,int b,int c) {
		if((a%2)*(b%2)*(c%2)%2==0) {
			System.out.println(0);
			return;
		}
		long[] ar = {a,b,c};
		Arrays.sort(ar);
		System.out.println(ar[0]*ar[1]);
	}
}


Measured memory_bytes: 23764
// ALDS1_14_A/B: String search (DFA)

import java.io.PrintWriter;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] T = sc.next().toCharArray();
    char[] P = sc.next().toCharArray();
    PrintWriter pw = new PrintWriter(System.out);

    // preprocess
    int[] pi = new int[P.length + 1];
    pi[0] = -1;
    int k = -1;
    for (int i = 1; i <= P.length; ++i) {
      while (k >= 0 && P[k] != P[i - 1]) k = pi[k];
      pi[i] = ++k;
    }

    // search
    int j = 0;
    for (int i = 1; i <= T.length; ++i) {
      while (j >= 0 && P[j] != T[i - 1]) j = pi[j];
      ++j;
      if (j == P.length) {
        pw.println(i - P.length);
        j = pi[j];
      }
    }
    pw.flush();
  }
}


Measured memory_bytes: 67508
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    bool po[101] = {false};
    int cnt = 0;
    int n;
    int d;
    cin >> n;
    rep(i,n){
        cin >> d;
        if(po[d]) continue;
        po[d] = true;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
#define putn(x,n) cout<< fixed<< setprecision(n)<< x << endl;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,y;
	cin>>n>>y;

	rep(a,0,n+1){
		rep(b,0,n+1-a){
			if(a*10000+b*5000+(n-a-b)*1000 == y){
				cout << a <<" "<<b<<" "<<n-a-b<<endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1"<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main
{
  public static void main(String[] args) throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String input = br.readLine();
    String[] param = input.split("/");
    
    int n1 = Integer.parseInt(param[0]);
    int n2 = Integer.parseInt(param[1]);
    int n3 = Integer.parseInt(param[2]);
    
    if(n1!=2018){
      n1 = 2018;
    }
    
    
    if(n3>=10){
    System.out.println("2018/01/"+n3);
  }else{
  	System.out.println("2018/01/0" +n3);
  }
  }
}
    
    

Measured memory_bytes: 20052
#include <stdio.h>
#include <string.h>
#define N 200000000
#define M 2000000001

int size;
int heap[N];

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= size && heap[l] > heap[i]) valM = l;
  else valM = i;
  if(r <= size && heap[r] > heap[valM]) valM = r;
  if(valM != i){
    swap(&heap[i], &heap[valM]);
    maxHeapify(valM);
  }
}

void heapIncreaseKey(int i, int key){
  if(key < heap[i]) return;
  heap[i] = key;
  while(i>1 && heap[i/2]<heap[i]){
    swap(&heap[i], &heap[i/2]);
    i = i/2;
  }
}

void maxHeapInsert(int key){
  size++;
  heap[size] = -M;
  heapIncreaseKey(size, key);
}

int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = heap[1];
  heap[1] = heap[size--];
  maxHeapify(1);
  return valM;
}

main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end")) break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}



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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> vi(N);
    REP(i, N)
    cin >> vi[i];
    set<int> si;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (vi[a] < vi[b])
            si.insert(a);
        if (vi[a] > vi[b])
            si.insert(b);
        if (vi[a] == vi[b]) {
            si.insert(a);
            si.insert(b);
        }
    }
    cout << N - si.size() << endl;
}

Measured memory_bytes: 6332
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;

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

    int n;
    ll res = 0, a[312345];

    cin >> n;
    REP(i, n * 3)
    cin >> a[i];

    sort(a, a + n * 3);

    for (int i = 3 * n - 2; i >= n; i -= 2)
        res += a[i];

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int A, B, C;

int main(void){
	cin >> A >> B >> C;
	for (int sum = 0; sum <= 300; ++sum){
		int D = sum - A - B;
		int E = sum - B - C;
		int F = sum - A - C;
		int G = sum - D - F;
		int H = sum - E - F;
		if(D + C + H != sum) continue;
		int I = sum - A - H;
		if(I + C + G == sum){
			printf("%d %d %d\n", A, B, D);
			printf("%d %d %d\n", I, C, G);
			printf("%d %d %d\n", H, E, F);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    ll a, b, n;
    cin >> a >> b >> n;

    ll ans = (a*min(n, (b-1)))/b;
    cout << ans << "\n";
}


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

int main(){
    int n;
    cin>>n;
    int a[100];
    rep(i,n){
        cin>>a[i];
    }
    bool flg=true;
    int count=0;
    int i=0;
    while(flg){
        flg=false;
        for(int j=n-1;j>=i+1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flg=true;
                count++;
            }
        }
        i++;
    }
    rep(i,n-1){
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<count<<endl;
}
            





Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        while (temp != 0 && temp % 2 == 0)
        {
            ans++;
            temp /= 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int abc[3];
  int ans;

  scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);


  if(abc[0] != abc[1] || abc[1] != abc[2]){
    int i, j;
    int tmp;
    for(i = 0; i < 3; i++){
      for(j = i + 1; j < 3; j++){
	if(abc[i] < abc[j]){
	  tmp = abc[i];
	  abc[i] = abc[j];
	  abc[j] = tmp;
	}
      }
    }
  }

  //  printf("%d %d %d\n", abc[0], abc[1], abc[2]);
  ans = abc[0] * 10 + abc[1] + abc[2];

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [[]]

for _ in range(N):
    a = int(input())
    if len(A[-1]) > 0 and a < A[-1][-1]:
        A.append([])
    A[-1].append(a)

def isOk():
    for l, r in zip(A, A[1:]):
        if l[-1] + 1 < r[0]:
            return False
    for grp in A:
        for l, r in zip(grp, grp[1:]):
            if l + 1 < r:
                return False

    return A[0][0] == 0

if not isOk():
    print(-1)
    exit()

B = []
for a in A:
    B.extend(a)
B = [-10**18] + B[::-1]

ans = 0
for r, l in zip(B, B[1:]):
    if l >= r:
        ans += l
print(ans)


Measured memory_bytes: 22056
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}
template <class T1, class T2>
std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) { return in >> x.first >> x.second; }

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    out_impl(std::forward<Args>(args)...);
}
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    auto h = read<int>(read<int>());
    int res = 0;
    for (;; ++res) {
        int l = 0, r = 0;
        for (; l < h.size() && h[l] == 0; ++l) continue;
        if (l == h.size()) break;
        r = l;
        for (; r < h.size() && h[r] != 0; ++r) continue;
        for (int i = l; i < r; ++i) h[i]--;
    }
    out(res);
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


Measured memory_bytes: 256
n = int(input())

a = {}
b = []
for i in range(n):
  s, p = input().split()
  p = int(p)
  
  b.append(s)
  
  if s in a:
    a[s].append([p, i+1])
  else:
    a[s] = [[p, i+1]]
    
b = sorted(list(set(b)))

for i in b:
  tmp = a[i]
  for j in sorted(tmp, reverse = True):
    print(j[1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,s=0,a;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>a;
        s+=a;
    }
    if(s<=n) cout<<n-s<<endl;
    else{
        cout<<"-1"<<endl;
    }
}


Measured memory_bytes: 3636
n, k  = STDIN.gets.split(" ").map do |s|
    s.to_i
end

l = STDIN.gets.split(" ").map do |s|
    s.to_i
end

sorted = l.sort do |a,b|
    b <=> a
end

STDOUT.puts sorted[0..k-1].inject(:+)


Measured memory_bytes: 1788
using System;

namespace ABC065C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int N = Int32.Parse(bufs[0]);
            int M = Int32.Parse(bufs[1]);

            long dog = 1;
            long monkey = 1;
            long res = 0;

            int div = 1000000007;

            if (Math.Abs(N - M) > 1)
            {
                Console.WriteLine(0);
                return;
            }

            if (Math.Abs(N - M) == 1)
            {
                res = 1;
            }
            else
            {
                res = 2;
            }

            for (int i = 1; i <= N; i++)
            {
                dog = (dog * i) % div;
            }
            for (int i = 1; i <= M; i++)
            {
                monkey = (monkey * i) % div;
            }


            Console.WriteLine((((res * dog) % div) * monkey) % div);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------



int main(){
    ios::sync_with_stdio(false);
    vector<vector<ll>> dp(55,vector<ll> (55,0));
    dp[0][0] = 1;
    for(int i=1; i<=50; i++){
        dp[i][0] = dp[i][i] = 1;
        for(int j=1; j<i; j++){
            dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
        }
    }
    int N,A,B;
    cin >> N >> A >> B;
    double ave = 0;
    vector<ll> v(N);
    map<ll,int> mp;
    for(int i=0; i<N; i++){
        cin >> v[i];
        mp[v[i]]++;
    }
    sort(v.rbegin(),v.rend());
    for(int i=0; i<A; i++){
        ave += v[i];
    }
    ave /= A;
    ll ans = 0;
    map<ll,int> used;
    for(int i=0; i<A; i++){
        used[v[i]]++;
    }
    for(int i=A; i<=B; i++){
        ans += dp[mp[v[i-1]]][used[v[i-1]]];
        used[v[i-1]]++;
        if(v[0] != v[i]) break;
        // cout << mp[v[i-1]] << " " << used[v[i-1]] << "\n";
    }
    cout << fixed << setprecision(10) << ave << "\n";
    cout << ans << "\n";
    return 0;
}

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

int **wall_h;
int **wall_v;
int **tile;
int w,h;

void dfs(int x,int y,int depth);

int main(){
	while(1){
		cin >> w >> h ;
		if(!w){
			break;
		}
		wall_h = new int*[w];
		wall_v = new int*[w];
		for (int i=0;i<w;i++){
			wall_h[i] = new int[h];
			wall_v[i] = new int[h];
		}
		
		for (int i=0; i<h-1; i++) {
			for (int j=0; j<w-1; j++) {
				cin >> wall_v[j][i];
			}
			wall_v[w-1][i] = 1;
			for (int j=0; j<w; j++) {
				cin >> wall_h[j][i];
			}
		}
		for (int j=0; j<w-1; j++) {
			cin >> wall_v[j][h-1];
		}
		wall_v[w-1][h-1] = 1;
		for (int j=0; j<w; j++) {
			wall_h[j][h-1] = 0;
		}
		
		tile = new int*[w];
		for (int i=0; i<w; i++) {
			tile[i] = new int[h];
			for (int j=0; j<h; j++) {
				tile[i][j] = 0;
			}
		}
		dfs(0,0,1);

		cout << tile[w-1][h-1] << endl;
		
		
		for (int i=0; i<w; i++) {
			delete [] tile[i];
			delete [] wall_v[i];
			delete [] wall_h[i];
		}
		delete [] tile;
		delete [] wall_v;
		delete [] wall_h;
	}
	return 0;
}

void dfs(int x,int y,int depth){
	if (tile[x][y] == 0 || tile[x][y] > depth) {
		tile[x][y] = depth;
		if (x != 0 && wall_v[x-1][y] == 0) {
			dfs(x-1,y,depth+1);
		}
		if (x!=w-1 && wall_v[x][y] == 0) {
			dfs(x+1,y,depth+1);
		}
		if (y!=0 && wall_h[x][y-1] ==0) {
			dfs(x,y-1,depth+1);
		}
		if (y!=h-1 && wall_h[x][y] ==0) {
			dfs(x,y+1,depth+1);
		}
	}
	return;
	
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    ll a,b;cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

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

int main() {
  int K,A,B;
  cin >> K>>A>>B;
  int ans=0;

  for(int i=1;i<1000;i++){
    if(A<=(K*i)&&B>=(K*i)){
      ans+=1;
      break;
    }
  }
  if(ans>0){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
}


Measured memory_bytes: 3632
N = int(input())
A = [int(_) for _ in input().split()]


def judge(x, y):
    return x & y == 0


l = 0
r = -1
x = 0
ans = 0
while l < N:

    while r + 1 < N and judge(x, A[r + 1]):
        x ^= A[r + 1]
        r += 1

    ans += r - l + 1
    x ^= A[l]
    l += 1
print(ans)


Measured memory_bytes: 23560
#include<iostream>
#include<vector>
using namespace std;
int N,K,S;
vector<int>ans;
main()
{
	cin>>N>>K>>S;
	for(int i=0;i<K;i++)ans.push_back(S);
	if(S<=2)
	{
		for(int i=K;i<N;i++)ans.push_back(3);
	}
	else
	{
		for(int i=K;i<N;i++)ans.push_back(S-1);
	}
	for(int i=0;i<N;i++)cout<<ans[i]<<(i+1==N?"\n":" ");
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n, c, k;
    cin >> n >> c >> k;
    vi t(n);
    rep(i, n)
    {
        cin >> t[i];
    }
    sort(all(t));
    int ans = 0;
    rep(i, n)
    {
        int cnt = 0;
        for (int j = i; j <= i + c - 1 && j < n; j++)
        {
            if (t[j] <= t[i] + k)
            {
                cnt++;
            }
        }
        //        cerr << cnt << endl;
        ans++;
        i += cnt - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<map>
#include<stdexcept>

template<typename T>
class union_find{
	std::map<T, T> parent;
	std::map<T, T> rank;
public:
	void add(const T& t){ parent[t] = t; rank[t] = 0; }
	const T& find(T t)const{
		while (true){
			typename std::map<T, T>::const_iterator it = parent.lower_bound(t);
			/*if(it != parent.end() && it->first == t)*/if (t != it->second)t = it->second;
			else return it->second;
			//throw std::runtime_error("union_find not found");
		}
	}
	void unite(T l, T r){
		l = find(l);
		r = find(r);
		if (l == r)return;
		if (rank[l] < rank[r])
			parent[l] = r;
		else{
			parent[r] = l;
			if (rank[l] == rank[r])++rank[l];
		}
	}
	bool is_same(const T& l, const T& r)const{
		return find(l) == find(r);
	}
};



int n, q;
union_find<int> U;

int main(){
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; ++i)U.add(i);
	for (int i = 0; i < q; ++i){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (a == 0){
			U.unite(b, c);
		}
		else {
			//if (U.is_same(b, c))printf("1\n");
			//else printf("0\n");
			printf("%d\n", int(U.is_same(b, c)));
		}
	}
	return 0;
}

Measured memory_bytes: 1956
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, a[100100], b[100100], m;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a[i];
        if (a[i]<0) m++;
        b[i] = abs(a[i]);
    }
    sort(b,b+n);
    int s = accumulate(b,b+n,0ll);
    if (m%2==0) cout << s << endl;
    else cout << s - b[0]*2 << endl;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    // 頂点番号，各頂点から出る複数のエッジ
    static List<Edge>[] graph;

    // 最短コスト
    static int[] dist;
    static long[] mindist;

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

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

        mindist = new long[1000000];
        solve_0(N, K);
        System.out.println(mindist[N - 1]);
    }

    static void solve_0(int N, int K) {
        Arrays.fill(mindist, Long.MAX_VALUE);
        mindist[0] = 0;

        for (int i = 0; i < N; i++) {
            for (int k = 1; k < K + 1; k++) {
                long a = mindist[i] + Math.abs(dist[i] - dist[i + k]);
                mindist[i + k] = Math.min(a, mindist[i + k]);
            }
        }
    }
}

// エッジに関するクラス
class Edge {
    int to, cost;

    public Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}

// 頂点に関するクラス
class Vertex {
    int id;
    long dist;

    public Vertex(int id, long dist) {
        this.id = id;
        this.dist = dist;
    }
}


Measured memory_bytes: 70752
#include <iostream>

using namespace std;

char board[102][102] = {{0}};

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

  for (int i = 0; i < H + H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (i < H) cin >> board[i][j];
      printf("%c", board[i / 2][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n, a , b;
    cin >> n >> a >> b;
    if((n * a) < b){
        cout << n * a;
    } else{
        cout << b;
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    ll h,w;
    cin >> h >> w;

    ll ans;
    if (h % 3 == 0) {
        ans = 0;
    } else if (w % 3 == 0) {
        ans = 0;
    } else {
        ans = 1LL<<60;
        REP(x,2) {
            ll s1,s2,s3,s;
            FOR(i,1,h) {
                s1 = i * w;
                s2 = (h - i) * (w / 2);
                s3 = (h - i) * (w - w / 2);
                //cerr << s1 << " " << s2 << " " << s3 << endl;
                s = max(s1,max(s2,s3)) - min(s1,min(s2,s3));
                ans = min(ans,s);
                
                s2 = (h - i) / 2 * w;
                s3 = ((h - i) - (h - i) / 2) * w;
                s = max(s1,max(s2,s3)) - min(s1,min(s2,s3));
                ans = min(ans,s);
            }
            swap(h,w);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<set>

using namespace std;

int N, M;

vector<int> p, x ,y;

vector<int> Adj[100005];

set<int> S;

int C[100005];

void visit(int k) {

	S.insert(k);
	C[k] = 1; //cout << "visit " << k << endl;

	for (int i = 0; i < Adj[k].size(); i++) {
		if (C[Adj[k][i]] == 0) { visit(Adj[k][i]);  }
	}
}

int main(void) {

	cin >> N >> M;

	p.push_back(-999);

	int tmp;
	for (int i = 1; i <= N; i++) { cin >> tmp; p.push_back(tmp); }

	x.push_back(-888);  y.push_back(-777);
	for (int i = 1; i <= M; i++) {
		cin >> tmp; x.push_back(tmp);
		cin >> tmp; y.push_back(tmp);
	}

	//for (int i = 1; i <= N; i++) { Adj[i].push_back(-555); }
	for (int i = 1; i <= M; i++) {
		Adj[x[i]].push_back(y[i]);
		Adj[y[i]].push_back(x[i]);
	}

	/*for (int i = 1; i <= N; i++) {
		for (int j = 0; j < Adj[i].size(); j++) {
			cout << " " << Adj[i][j];
		}
	}*/

	int count = 0;

	for (int i = 1; i <= N; i++) {
		S.clear();
		if (C[i] == 0) { visit(i); }
		for (auto itr = S.begin(); itr != S.end(); itr++) {
			//cout << " " << *itr;
			if (S.find(p[*itr]) != S.end()) { count++; }
		}
		//cout << endl;
	}

	cout << count << endl;


	return 0;
}


Measured memory_bytes: 14072
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
 
int main()
{
  long long int n;
  cin>>n;
  vector<long long int>v;
  map<long long int,long long int>mp;
  for(long long int i=1;i<=n;i++)
  {
  	long long int a;
  	cin>>a;
  	mp[i-a]++;
  	v.push_back(a);
  }
  long long int sum=0;
  
  for(long long int i=0;i<n;i++)
  {
  	if(mp[v[i]+i+1]>0)
  	{
  		sum+=mp[v[i]+i+1];
	  }
  }
  cout<<sum;
}

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

int main(){
  vector<int> b;
  stack<int> a;
  stack<pair<int,int>> a2;
  string s;
  int ans=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='_') continue;
    else if(s[i]=='/' && a.size()!=0){
      int j=a.top();
      ans+=i-j;
      int c=i-j;
      a.pop();
      while(a2.size()>0 && a2.top().first>j){
	c+=a2.top().second;
	a2.pop();
      }
      a2.push(make_pair(j,c));
    }else if(s[i]=='\\'){
      a.push(i);
    }
  }
  while(a2.size()>0) {b.push_back(a2.top().second); a2.pop();}
  reverse(b.begin(),b.end());
  cout<<ans<<endl;
  if(b.size()==0) cout<<b.size();
  else cout<<b.size()<<" ";
  for(int i=0;i<b.size();i++){
    if(i==b.size()-1) cout<<b[i];
    else cout<<b[i]<<" ";
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,i,x,min = 1000000,max = -1000000;
    long int sum=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        
        scanf("%d",&x);
        sum=sum+x;
        
        if(x>max){
            max=x;
        }
        if(x<min){
            min=x;
        }
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  if(s[5]=='1'){
    cout<<"TBD"<<endl;
  }
  else if(s[6]=='1'||s[6]=='2'||s[6]=='3'||s[6]=='4'){
    cout<<"Heisei"<<endl;
  }
  else{
    cout<<"TBD"<<endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8

def main():
    N = sorted(list(map(int, input().split())))
    ans = N[2] - N[1]
    d = N[1] - N[0]
    if d % 2 != 0:
        ans += 2
    ans += d // 2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
import sys
input = sys.stdin.readline
def main():
    S = list(input().rstrip())
    f = int("".join(S[0:2]))
    b = int("".join(S[2:4]))
    if 0<f<13 and 0<b<13:
        print("AMBIGUOUS")
    elif 0<f<13:
        print("MMYY")
    elif 0<b<13:
        print("YYMM")
    else:
        print('NA')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
a = int(input())
s = input()
A = []
count=0
for i in range(1, a):
    x = list(s[:i])
    y = list(s[i:])

    x = list(set(x))
    y = list(set(y))

    for i in y:
        if(i in x):
            count+=1
    A.append(count)
    count=0
print(max(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int n;
string s;
bool veri(char lef, char mid, char rig, char ck){
	int cnt = 0;
	if( lef == rig ) cnt++;
	if( mid == 'S' ) cnt++;
	if( ck == 'o' ) cnt++;
	if( cnt%2 )return true;
	return false;
}
string check(int fi, int se){
	string res;
	if( fi == 0 )res.pb('S'); else res.pb('W');
	if( se == 0 )res.pb('S'); else res.pb('W');
	for(int i=2;i<n;i++){
		if( ( res[i-1] == 'S' && s[i-1] == 'o') || ( res[i-1] == 'W' && s[i-1] == 'x') )res.pb(res[i-2]);
		else res.pb( 'S'+'W'-res[i-2] );
	}
	if(veri(res[n-1],res[0],res[1],s[0]) && veri(res[n-2],res[n-1],res[0],s[n-1]) )return res;
	else return "x";
}
signed main(){
	cin>>n;
	cin>>s;
	string ans;
	ans = check( 0, 0 );
	if( ans != "x" ){
		cout<<ans<<endl;
		return 0;
	}
	ans = check( 0, 1 );
	if( ans != "x" ){
		cout<<ans<<endl;
		return 0;
	}
	ans = check( 1, 0 );
	if( ans != "x" ){
		cout<<ans<<endl;
		return 0;
	}ans = check( 1, 1 );
	if( ans != "x" ){
		cout<<ans<<endl;
		return 0;
	}
	cout<<-1<<endl;
	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  vector<ll> cnt(4);
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
    if (s[i]=="AC") cnt[0]++;
    else if (s[i]=="WA") cnt[1]++;
    else if (s[i]=="TLE") cnt[2]++;
    else if (s[i]=="RE") cnt[3]++;
  }
  cout << "AC x " << cnt[0] << endl;
  cout << "WA x " << cnt[1] << endl;
  cout << "TLE x " << cnt[2] << endl;
  cout << "RE x " << cnt[3] << endl;
  return 0;
}


Measured memory_bytes: 6428
#include<stdio.h>
#include<math.h>

int main(void)
{
  double S,N,A;
  int i,j;
  double x[8],y[8];
  scanf("%lf\n",&N);
  for(i=0;i<=N-1;i++){
    scanf("%lf%lf\n",&x[i],&y[i]);
  }
  
  S=0;
  for(i=0;i<=N-2;i++){
    for(j=i+1;j<=N-1;j++){
      A=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
      S=S+sqrt(A);
    }
  }
  
  S=S*2/N;
  
  printf("%lf",S);
  
  return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <limits>
#include <iomanip>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class BJudgeStatusSummary {
public:
	void solve(std::istream& in, std::ostream& out) {
        map<string,int> cnt;
        int n;in>>n;
        rep(i,n){
            string s;in>>s;
            ++cnt[s];
        }
        out<<"AC x "<<cnt["AC"]<<endl;
        out<<"WA x "<<cnt["WA"]<<endl;
        out<<"TLE x "<<cnt["TLE"]<<endl;
        out<<"RE x "<<cnt["RE"]<<endl;

    }
};


int main() {
	BJudgeStatusSummary solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    if (a <= x && x - a <= b)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

int main(void)
{
	int r, c;
	int num[256][256] = {0};

	cin >> r >> c;

	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			cin >> num[i][j];
			num[i][c] += num[i][j];
			num[r][j] += num[i][j];
			num[r][c] += num[i][j];
		}
	}

	for(int i = 0; i <= r; i++)
		for(int j = 0; j <= c; j++)
			cout << num[i][j] << (j == c ? '\n' : ' ');

	return 0;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
  ll N,ans=0;
  cin >> N;
  vector<ll> d(N);
  rep(i,N) cin >> d[i];
  
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  	int n;
  	cin>>n;
  
	string s,t;
  	cin>>s>>t;
  
  	rep(i,n){
    	cout<<s[i];
        cout<<t[i];
    }
  
  
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int mypow(int x,int n){
	int res = 1;
	while(n>0){		
		if(n & 1) res = res*x;
		x = x * x;
		n>>=1;
	}
	return res;
}


int conv(vector<int>& sets,int n){
	int res = 0;
	for(int i=0;i<sets.size();i++){
		for(int j=0;j<n;j++){
			if(sets[i] & (1<<j)){
				res += i * mypow(3,j);
			}
		}
	}
	return res;
}

int bfs(int m,int n,vector<int>& root,bool* visited){

	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,root));
	visited[conv(root,n)] = 0;
	vector<int> tmp;
	vector<int> sets;
	while(!que.empty()){
		int cost = que.top().first;
		
		sets = que.top().second;

		if(sets[1]==0 && sets[2]==0) return cost;
		if(sets[0]==0 && sets[1]==0) return cost;

		if(cost >= m) break;
		que.pop();
		for(int i=0;i+1<sets.size();i++){
			if((sets[i] && sets[i+1] && sets[i] < sets[i+1]) 
				|| (!sets[i] && sets[i+1])){
				tmp = sets;

				int pos=0;
				for(int j=n-1;j>=0;j--){
					if(tmp[i+1] & (1<<j)){
						pos = j;
						break;
					}
				}
				tmp[i+1] &= ~(1<<pos);
				tmp[i] |= (1<<pos);

				
				int next;
				if(!visited[(next = conv(tmp,n))]){
					visited[next] = cost+1;
					que.push(P(cost+1,tmp));
				}
			}

			else if((sets[i] && sets[i+1] && sets[i] > sets[i+1]) 
				|| (sets[i] && !sets[i+1])){
				tmp = sets;

				int pos=0;
				for(int j=n-1;j>=0;j--){
					if(tmp[i] & (1<<j)){
						pos = j;
						break;
					}
				}
				tmp[i] &= ~(1<<pos);
				tmp[i+1] |= (1<<pos);

				int next;
				if(!visited[(next = conv(tmp,n))]){
					visited[next] = cost+1;
					que.push(P(cost+1,tmp));
				}
			}
		}
	}
	return -1;
}

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		vector<int> sets(3);
		bool* visited = new bool[mypow(3,n)]();
		for(int i=0;i<3;i++){
			int amount;
			scanf("%d",&amount);
			for(int j=0;j<amount;j++){
				int size;
				scanf("%d",&size);
				sets[i] |= (1<<(size-1)); 
			}
		}

		printf("%d\n",bfs(m,n,sets,visited));
		delete[] visited;
	}
	//printf("%d %d %d\n",mypow(3,0),mypow(3,1),mypow(3,2));
}

Measured memory_bytes: 14000