akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var xi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var x = nx[1];
            Array.Sort(xi);
            var answer = Math.Abs(xi[0] - nx[1]);
            for (var i = 1; i < xi.Length; i++)
            {
                answer = GCD(answer, xi[i] - xi[i - 1]);
            }
            Console.WriteLine(answer);
        }
        static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    }
}


Measured memory_bytes: 19680
#include <iostream>

using namespace std;

struct node {
    int key;
    node *left;
    node *right;
};

void walkInOrder(node *cur) {
    if (cur == nullptr) return;
    walkInOrder(cur->left);
    printf(" %d", cur->key);
    walkInOrder(cur->right);
}

void walkPreOrder(node *cur) {
    if (cur == nullptr) return;
    printf(" %d", cur->key);
    walkPreOrder(cur->left);
    walkPreOrder(cur->right);
}

struct binaryTree {
    node *root;

    binaryTree() {
        root = nullptr;
    }

    void insert(int x) {
        node **v = &root;
        node *nodeX = (node *) malloc(sizeof(node));
        nodeX->key = x;
        nodeX->left = nodeX->right = nullptr;
        while (*v != nullptr) {
            if ((*v)->key <= x) v = &(*v)->right;
            else v = &(*v)->left;
        }
        *v = nodeX;
    }

    void print() {
        walkInOrder(root);
        printf("\n");
        walkPreOrder(root);
        printf("\n");
    }
};

int main() {
    int n;
    binaryTree tree;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string op;
        int x;
        cin >> op;
        if (op == "print") tree.print();
        else if (op == "insert") {
            cin >> x;
            tree.insert(x);
        }
    }
    return 0;
}



Measured memory_bytes: 18752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,l,r,i,ll,rr;
  cin>>n>>m;
  ll=1;
  rr=n;
  for(i=0;i<m;i++){
    cin>>l>>r;
    ll=max(ll,l);
    rr=min(rr,r);
  }
  if(ll>rr) cout<<0<<endl;
  else cout<<rr-ll+1<<endl;
}

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n, y; readV(n, y);

  foreach (i; 0..n+1)
    foreach (j; 0..n-i+1) {
      auto k = n-i-j;
      if (i*10000 + j*5000 + k*1000 == y) {
        writeln(i, " ", j, " ", k);
        return;
      }
    }

  writeln("-1 -1 -1");
}


Measured memory_bytes: 256
n=int(input())
A=[0]+list(map(int,input().split()))+[0]*2
ans=0
cnt=[0]*(n+1)
for i in range(n+1):
    ans+=abs(A[i]-A[i+1])

for i in range(n):
    temp=abs(A[i]-A[i+1])+abs(A[i+1]-A[i+2])-abs(A[i]-A[i+2])
    print(ans-temp)

Measured memory_bytes: 14048
import itertools

n = int(input())
l = [i for i in range(1, n + 1)]
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
cnt = 0
for check in itertools.permutations(l, n):
    cnt += 1
    if a == check:
        cnta = cnt
    if b == check:
        cntb = cnt

print(abs(cnta - cntb))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
ll N,M,Q;
ll ans=0;
ll a[50],b[50],c[50],d[50];

void dfs(vl &vec){
    if(vec.size()==N){
        ll res=0;
        rep(i,Q){
            if(vec.at(b[i])-vec.at(a[i])==c[i]){
                res+=d[i];
            }
        }
        chmax(ans,res);
        return;
    }
    ll last=(vec.empty()?1:vec.back());
    rep2(i,last,M+1){
        vec.push_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

int main(){
    cin>>N>>M>>Q;
    rep(i,Q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    vl A;
    dfs(A);
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//絶対値
long long int change_plus(long long int a) {
	if (a < 0) { return -a; }
	if (a >= 0) { return a; }
}
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int n, m, k = 0;
	char str[5];
	scanf("%lld%lld",&n,&m);
	if (n % 3 != 0 && m % 3 != 0 && (n + m) % 3 != 0) {
		printf("Impossible");
	}else{ printf("Possible"); }
	
	

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 using namespace std;
 int main(){
     string s;
     cin>>s;
     int i,l=s.length(),flag=0;
     for(i=0;i<l;i++){
        if(s[i]!=s[l-i-1]){
            flag=1;
            break;
        }
     }
     if(flag==1){
        cout<<"No"<<endl;
     }
     else{
        cout<<"Yes"<<endl;
     }
     return 0;
 }


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n,x,t=MI()
print((n+x-1)//x*t)


Measured memory_bytes: 9120
A,B=input().split()
a=int(A)
b=int(B)

if a>b:
  if (a+a-1)>(a+b):
    print(a+a-1)
  else:
    print(a+b)
else:
  if (b+b-1>a+b):
    print(b+b-1)
  else:
    print(a+b)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    
    int n, x; cin >> n >> x;
    while(n!=0 || x!=0){
        int ans = 0;
        FOR(i,1,n-1){
            if(i > x) break;
            FOR(j,i+1,n){
                if(i+j > x) break;
                FOR(k,j+1,n+1){
                    if(i+j+k > x) break;
                    if(i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;
        cin >> n >> x;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const long long Maxn=100000;
long long n,sum=0;
long long a[Maxn],b[Maxn],c[Maxn];
int main()
{
	long long ans,ant;
	scanf("%lld",&n);
	for(int j=0;j<n;j++)
	scanf("%lld",&a[j]);
	for(int j=0;j<n;j++)
	scanf("%lld",&b[j]);
	for(int j=0;j<n;j++)
	scanf("%lld",&c[j]);
    sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	for(int i=0;i<n;i++)
	{
		ans=lower_bound(a,a+n,b[i])-a;
		ant=upper_bound(c,c+n,b[i])-c;
		sum+=ans*(n-ant);
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 2560
def main():
    from functools import reduce

    def gcd(a, b):
        return a if b == 0 else gcd(b, a % b)

    def lcm(a, b):
        return a * b // gcd(a, b)

    mod = 10 ** 9 + 7

    n = int(input())
    *a, = map(int, input().split())

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75612
# n = int(input())
n,m = [int(j) for j in input().split()]
hts = [int(j) for j in input().split()]
obs = [True for i in range(n)]
for i in range(m):
	u,v = [int(j)-1 for j in input().split()]
	if hts[u]>hts[v]:
		obs[v] = False
	elif hts[u]==hts[v]:
		obs[v] = False
		obs[u] = False
	else:
		obs[u] = False
# print(obs)
print(obs.count(True))

Measured memory_bytes: 84972
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(a, b) = sc.nextLine.split(" ").map(_.toInt)
    if ((a <= 8) & (b <= 8)) println("Yay!")
    else println(":(")
  }

}


Measured memory_bytes: 25776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b) swap(a,b);
	if(b<c) swap(b,c);
	if(a<b) swap(a,b);
	cout<<a*10+b+c<<'\n';
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	arr := []int{a, b, c, d, e}
	sort.Ints(arr)
	if arr[len(arr)-1]-arr[0] <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


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

int main(){
  int a,b;
  while(1){
    cin>>a>>b;
    if(a==0&&b==0)break;
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  map<char, int> mp;
  rep(i, N) {
    string S;
    cin >> S;
    mp[S[0]]++;
  }
  char S[5] = {'M', 'A', 'R', 'C', 'H'};
  int64_t Ans = 0;
  for (int i = 0; i < 32; i++) {
    int cnt = 0;
    int64_t C[5];
    for (int j = 0; j < 5; j++) {
      int k = i & (1 << j);
      if (k) {
        C[cnt++] = mp[S[j]];
      }
    }
    if (cnt == 3) {
      Ans += (C[0] * C[1] * C[2]);
    }
  }
  cout << Ans << endl;
  return 0;
}


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


int main() {

	int N, M;
	cin >> N >> M;

	int A[55] = {};
	int B[55] = {};

	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}
	
	int bucket[55] = {};

	for (int i = 0; i < M; i++) {
		bucket[A[i]] ++;
		bucket[B[i]] ++;
	}

	for (int i = 1; i <= N; i++) {
		cout << bucket[i] << '\n';
	}

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long r,d,x,i;
	scanf("%lld %lld %lld", &r, &d, &x);
	for(i=0; i<10; i++)
	{
		x*=r;
		x-=d;
		printf("%lld\n", x);
	}
	
	return 0;
}

Measured memory_bytes: 128
def inpl(): return list(map(int, input().split()))

N, M = inpl()
T = [[] for _ in range(N)]
for i in range(M):
    _, *S = inpl()
    for s in S:
        T[s-1].append(i)
P = inpl()

ans = 0
for x in range(2**N):
    Q = [0]*M
    for i in range(N):
        if (x >> i) & 1:
            for t in T[i]:
                Q[t] += 1
    ans += P == [q%2 for q in Q]
print(ans)

Measured memory_bytes: 42972
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
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; }
//ミョ(-ω- ?)
int main() {
    pair<int,int> s;
    pair<int,int> t;
    cin >> s.first >> s.second >> t.first >> t.second;
    cout << string(t.second - s.second,'U') << string(t.first - s.first,'R') <<
        string(t.second - s.second,'D') << string(t.first - s.first,'L') << 'L' <<
        string(t.second - s.second+1,'U') << string(t.first - s.first+1,'R') << "DR"<<
        string(t.second - s.second+1,'D') << string(t.first - s.first+1,'L') << "U\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  string s, t;
  cin >> s >> t;
  
  ll ans = INF;

  for (int i = 0; i < s.size() - t.size() + 1; i++){
    ll temp = 0;
    for (int j = 0; j < t.size(); j++){
      if (s[i+j] != t[j]){
        temp++;
      }
    }
    ans = min(ans, temp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
<?php
$input = fgets(STDIN);
list($tate,$yoko) = explode(" ", $input);

function area($a,$b){
return $a * $b;
}

function length($a,$b){
return ($a*2) + ($b*2);
}

print area($tate, $yoko). " ". length($tate, $yoko);

?>

Measured memory_bytes: 15320
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	V<int> c(a);
	int d=0;
	fo(i,a)
	cin>>c[i];
	fo(i,a){
		d+=min(c[i],abs(c[i]-b));
	}
	cout<<2*d<<endl;
}

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

int main(){
	int n;
	long long int sum=0;
	long long int a[10000]={0};
	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> a[i] ;
	}
	for(int i=n-1 ; i>=0 ; i--){
		for (int j=0 ; j<i ; j++){
			if(a[j]>a[j+1]){
				a[j]^=a[j+1];
				a[j+1]^=a[j];
				a[j]^=a[j+1];
			}
		}
	}
	for(int i=0 ; i<n ; i++){
		sum+=a[i];
	}
	cout << a[0] << " " << a[n-1] << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1256
S = input()
ans = []
for i in range(len(S)):
    if S[i] == "0":
        ans.append("0")
    elif S[i] == "1":
        ans.append("1")
    else:
        if len(ans) > 0:
            del ans[-1]
ans_ = ""
for s in ans:
    ans_ += s
print(ans_)

Measured memory_bytes: 61756
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        if(A+B>C+D){
        System.out.println("Left");
    }else if(A+B<C+D) {
        System.out.println("Right");
    } else if(A+B==C+D){
        System.out.println("Balanced");
    }
		
    }
}



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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */



int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}


int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  cout << min(n,k)*x + max(n-k,0)*y << endl;
  
}

Measured memory_bytes: 256
package main

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

func main() {
    r := bufio.NewReader(os.Stdin)

    var H, A int

    if _, e := fmt.Fscan(r, &H, &A); e != nil {
    	return
	}
	baseAtackCount := H / A
	if H % A != 0 {
		baseAtackCount += 1
	}
	fmt.Println(baseAtackCount)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int k, n;
	cin >> k;
	cin >> n;
	int a[n];
	int d[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (i > 1) {
			d[i] = a[i] - a[i - 1];
		}
	}
	d[0] = a[0] + k - a[n - 1];
	sort(d, d + n);
	cout << (k - d[n - 1]) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>

using namespace std;
const int MAX = 2000000;

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2 * i;
    r = 2 * i +1;

    if (l <= H && A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    
    if (r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;
    for (int i = 1; i <= H ; ++i) {
        cin >> A[i];
    }

    for (int i = H/2 ; i >= 1 ; i--) {
        maxHeapify(i);
    }
    for (int i = 1; i <= H ; ++i) {
        cout << " " << A[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)

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

    for(int i = 1; i < s.size(); i++) {
        if(s[i] == s[i - 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
    return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string s,t;
    int ans=0;
    cin>>s>>t;

    map<char,Vi> ma;
    map<char,int> mab;
    REP(i,0,s.size()){
        ma[s[i]].pb(i+1);
        mab[s[i]]++;
    }
    int now=0;
    REP(i,0,t.size()){
        if(mab[t[i]]==0){cout<<-1<<endl; return 0;}
        auto iter = upper_bound(ALL(ma[t[i]]),now);
        if(iter==ma[t[i]].end()){
            ans+=s.size();
            now=ma[t[i]][0];
        }else{
            now=*iter;
        }
    }
    cout<<ans+now<<endl;
    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  map<string, int> m;
  REP(i, N){
    string s;
    cin >> s;
    m[s]++;
  }

  int MAX = 0;
  for(auto p : m) chmax(MAX, p.second);

  for(auto p : m){
    if(p.second == MAX) cout << p.first << "\n";
  }

  return 0;
}

Measured memory_bytes: 23808
#include <stdio.h>
int main() {
	int p,q,r,sum;
	scanf("%d%d%d", &p,&q,&r);
	sum=p+q+r;
	if(p<q){
		p=q;
	}
	if(p<r){
		p=r;
	}
	printf("%d\n", sum-p);
	return 0;
}


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

int main() {
	vector<int> e(12, 0);
	string ans = "no";
	for (int i = 0; i < 12; i++) {
		int temp;
		cin >> temp;
		e[i] = temp;
	}
	sort(e.begin(), e.end());

	if (e[0] == e[1] && e[1] == e[2] && e[2] == e[3]) {
		if (e[4] == e[5] && e[5] == e[6] && e[6] == e[7]) {
			if(e[8] == e[9] && e[9] == e[10] && e[10] == e[11])
			ans = "yes";
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 3204
<?php
$fp = fopen("php://stdin", "r");
$con=array();
while(true){
    $in=trim(fgets($fp));
    if($in){
      //  echo $in;
        $arr=explode(" ",$in);
        if(isset($con[$arr[0]])){
            array_push($con[$arr[0]],$arr[1]);
        }
        else {
            $con[$arr[0]]=array();
            array_push($con[$arr[0]],$arr[1]);
        }
    }
    else break;
}
ksort($con);
//print_r($con);
foreach($con as $k=>$v){
    echo $k."\n";
    sort($v);
    echo implode(" ",$v)."\n";
 
}

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

void fn(vector<int>& xs, int n, int r, vector<int>& d, int a, int b, ll& cnt) {
  if (a == r) {
    ll tmp = 1;
    rep(j, r) tmp *= d[j];
    cnt += tmp;
    return;
  }
  if (b >= n)
    return;
  d[a] = xs[b];
  fn(xs, n, r, d, a + 1, b + 1, cnt);
  fn(xs, n, r, d, a, b + 1, cnt);
};

void comb(vector<int>& xs, int n, int r, ll& cnt) {
  vector<int> d(r);
  fn(xs, n, r, d, 0, 0, cnt);
}

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

  vector<string> S(N);
  rep(i, N) cin >> S[i];

  auto march = {'M', 'A', 'R', 'C', 'H'};

  map<char, int> m;
  for (auto c : march)
    m.emplace(c, 0);

  rep(i, N) {
    char c = S[i][0];
    if (m.find(c) != m.end())
      m[c]++;
  }

  vector<int> counts;
  for (auto c : march)
    if (m[c] != 0)
      counts.push_back(m[c]);

  ll ans = 0;
  if (counts.size() >= 3)
    comb(counts, counts.size(), 3, ans);

  cout << ans << endl;
}

Measured memory_bytes: 6144
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let N = lines.shift() - 0;
    let Ln = lines[0].split(" ").map((v) => v - 0);
    Ln.sort(function(a,b) { return b - a; });
    let max = Ln.shift();
    let sum = Ln.reduce((ac, value) => ac + value, 0);

    console.log(max < sum ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
	string s;
	cin >> s;
	int st = 0;
	int gl = 0;
	for(int i =0;i<s.size();i++){
		if(s.at(i) == 'A'){
			st = i;
			break;
		}
	}
	for(int j = s.size()-1; j>=0;j--){
		if(s.at(j) == 'Z'){
			gl = j;
			break;
		}
	}
	int sum = gl-st+1;
	cout << sum << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    vector<string> sv(3); cin >>sv;
    string ans;
    ans += sv[0][0];
    ans += sv[1][1];
    ans += sv[2][2];
    ANS(ans);
}


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

int main() {
	int sum, val[9];
	while (1) {
		cin >> sum;
		if (sum == 0) break;
		
		for (int i = 0; i < 9; i++)
			cin >> val[i];
	
		for (int i = 0; i < 9; i++)
			sum -= val[i];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26));

int get_score(vector<int> t){
    int ans = 0;
    vector<int> last(26, 0);
    rep(i, d){
        ans += s[i][t[i]];
        rep(j, 26){
            if(t[i] == j)last[j] = i+1;
            ans -= c[j] * ((i+1)-last[j]);
        }
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<int> t(d, 0);
    int m;
    cin >> m;
    clock_t now = clock();
    while(now < 1800000){
        int D = rand() % d, q = rand() % 26;
        int old = t[D], olds = get_score(t);
        t[D] = q;
        if(get_score(t) < olds)t[D] = old;
        now = clock();
    }
    rep(i, d)cout << t[i]+1 << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main()
{
	int i, j, N, M, K[31], A[31][31];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(K[i]));
		for (j = 1; j <= K[i]; j++)	scanf("%d", &(A[i][j]));
	}
	
	int ans = 0, count[31] = {};
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= K[i]; j++) count[A[i][j]]++;
	}
	
	for (j = 1; j <= M; j++) if (count[j] == N) ans++;
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
using vi = vector<int>;

string str;
string stra;
int id = 0;

void pt(vector<int> v){
  for(int r=0;r<v.size();r++){
    cout << v[r];
  }
  cout << endl;
}

vi number(){
  vi res;
  for (;'0'<=stra[id]&&stra[id]<='9'; id++) {
    res.push_back(stra[id] - '0');
  }
  reverse(res.begin(),res.end());
  return res;
}
int solve(){
  stra = str;
  for (int i = 9; i >= 0; i--) {
    id = 0;
    for (int j = 0; j <(int)str.size(); j++) {
      if (str[j] == 'X') {
        stra[j] = i + '0';
      }
    }
    vi a = number();
    if (stra[id] == '+' ) {
      id++;
    }
    vi b = number();
    
    //a.resize(max(b.size() + 1,a.size()+1),0);
    
    // a.push_back(0);
    // while(a.size()<=b.size()){
    //   a.push_back(0);
    // }

    vi ab;
    int q;
    for(q=0;q<a.size()&&q<b.size();q++){
      ab.push_back(a[q]+b[q]);
    }
    for(;q<a.size();q++){
      ab.push_back(a[q]);
    }
    for(;q<b.size();q++){
      ab.push_back(b[q]);
    }
    ab.push_back(0);
    
    // for (int j = 0; j < (int)b.size(); j++) {
    //   a[j] += b[j];
    //   // if (a[j]>=10) {
    //   //   a[j] -= 10;
    //   //   a[j+1]++;
    //   // }
    // }

    
    // for (int j = b.size(); j < (int)(a.size()-1); j++) {
    //   if (a[j] >= 10) {
    //     a[j] -= 10;
    //     a[j+1]++;
    //   }
    // }
    for(int j=0;j<(int)ab.size()-1;j++){
      if(ab[j]>=10){
        ab[j]-=10;
        ab[j+1]++;
      }
    }
    
    if(ab[ab.size()-1]==0){
      ab.pop_back();
    }
    a=ab;
    //pt(a);
    // int j;
    // int k=0;
    // int l=0;
    // vi ab;
    // for(j=0;j<int(a.size())&&j<int(b.size());j++){
    //   k=0;
    //   if(a[j]+b[j]+l>=10){
    //     k++;
    //     ab.push_back(a[j]+b[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(a[j]+b[j]+l);
    //   }
    //   l=k;
    // }
    // for(;j<int(a.size());j++){
    //   k=0;
    //   if(a[j]+l>=10){
    //     k++;
    //     ab.push_back(a[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(a[j]+l);
    //   }
    //   l=k;
    // }
    // for(;j<int(b.size());j++){
    //   k=0;
    //   if(b[j]+l>=10){
    //     k++;
    //     ab.push_back(b[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(b[j]+l);
    //   }
    //   l=k;
    // }
    // if(l>0){
    //   ab.push_back(l);
    // }
    // a=ab;
    /////////
    if (stra[id] == '=') {
      id++;
    }

    vi c = number();
    if (a.size() != c.size()) {
      continue;
    }
    int flag = 0;
    for (int j = 0; j < (int)a.size(); j++) {
      if (a[j] == c[j]) {
        flag++;
      }
    }
    if (flag ==(int)a.size()) {
      return i;
    }

  }
  return -1;
}
int main(){
  cin >> str;
  while(str.size()){
  int ans = solve();
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  str="";
  cin >> str;
}
  return 0;
}



Measured memory_bytes: 2988
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int a[15],b[15],c[15],d[15],e[15],f[15][1<<15],n;
double mn=1<<30;
void fn(int p,int q,int r,int s,double t){
  int i;
  if(p==n){
    if(mn>t){
      mn=t;
      memcpy(e,d,sizeof(d));
    }
  }else{
    if(f[r][q]>t){
      f[r][q]=t;
      for(i=0;i<n;i++){
	if((q&(1<<i))==0){
	  d[p]=a[i];
	  fn(p+1,q|(1<<i),i,s+c[i],t+fabs(b[r]-b[i])*(70+s)/2000); 
	}
      }
    }
  }
  return;
}
int main(){
  int i,j;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
    c[i]*=20;
  }
  for(i=0;i<n;i++)
    for(j=0;j<(1<<n);j++)
      f[i][j]=1<<30;
  for(i=0;i<n;i++){
    d[0]=a[i];
    fn(1,1<<i,i,c[i],0);
  }
  for(i=0;i<n-1;i++)
    cout<<e[i]<<" ";
  cout<<e[i]<<endl;
  return 0;
}

Measured memory_bytes: 2744
import copy
S = input()
Slen = len(S)

Sc=[0]*Slen
for i in range(Slen):
    if S[i:i+2] == 'RL':
        for j in range(i,-1,-1):
            if S[j]=='R':
                Sc[(i-j)%2 + i] += 1
            else:
                break
        for j in range(i+1,Slen):
            if S[j] == 'L':
                Sc[(j-i)%2 +i] += 1
            else:
                break    

print(" ".join(map(str,Sc)))



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

using namespace std;
const int mn = 1e5 + 5;
#define pb push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
using pii=pair<int, int>;

int m, d;

int main() {
    //cin.sync_with_stdio(0);
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    cin >> m >> d;

    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= d; j++) {
            int u = j % 10, v = j / 10;
            if (u >= 2 && v >= 2)
                if (j % 10 * (j / 10) == i) ans++;
        }
    }
    cout << ans << "\n";
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> H(N); REP(i, N) cin >> H[i];
  vector<long long> A(M), B(M); REP(i, M) cin >> A[i] >> B[i];

  vector<vector<ll>> a(N + 1);

  REP(i, M) {
    if(vector_finder(a[A[i]], B[i]) == 0) {
      a[A[i]].push_back(B[i]);
      a[B[i]].push_back(A[i]);
    }
  }

  // check1: 上記でN + 1番目を指定できていないことがおかしい
  // 対策: at関数を使って値にアクセスする
  /*
  cout << "--- 入力が正しいかどうかを検証する ---" << endl;
  for(int i = 1; i <= N; ++i) {
    REP(k, a[i].size()) {
      cout << a[i][k] << " ";
    }
    cout << endl;
  }
  cout << "--- 入力が正しいかどうかを検証する ---" << endl;
  */

  // check2: 添字が地獄。
  // 対策: 
  vector<ll> ans(N + 1);
  for(int i = 1; i <= N; ++i) {
    REP(k, a[i].size()) {
      if(i > a[i][k]) continue;
      //cout << "i check " << i << " " << a[i][k] << endl;
      //cout << i << " test " << H[i - 1] << " " << H[a[i][k] - 1] << endl;
            
      if(H[i - 1] > H[a[i][k] - 1]) {
        ans[i]++;
      } else if(H[i - 1] < H[a[i][k] - 1]) {
        ans[a[i][k]]++;
      }
    }
  }

  /*
  for(int i = 1; i <= N; ++i) {
    cout << "toosu " << ans[i] << " " << a[i].size() << endl;
  }
  */

  ll cnt = 0;
  for(int i = 1; i <= N; ++i) {
    if(ans[i] == a[i].size()) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 12164
n = int(input())
cout = ""
for i in range(1,n+1):
    x = i
    if x%3 == 0:
        cout += " " + str(i)
    else:
        while x > 0:
            if x%10 == 3:
                cout += " " + str(i)
                break
            x //= 10
print (cout)

Measured memory_bytes: 7660
#include <bits/stdc++.h>
using namespace std;
int dig[10];
int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < k; i++){
        int t;
        cin >> t;
        dig[t]++;
    }
    while(1){
        int notYet = 0;
        string test = to_string(n);
        int len = test.size();
        for(int i = len - 1; i >= 0; i--){
            if(dig[test[i] - '0']){
                n++;
                test = to_string(n);
                i = len - 1;
                notYet = 1;
            }
        }
        if(!notYet){
            cout << n << '\n';
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            int T = nint(sc);
            List<long[]> inputLine = new ArrayList<>();
            for (int i= 0 ; i < T; i++){
                long[] line = longLine(sc, 4);
                inputLine.add(line);
            }
            for (int i=0; i<T; i++){
                long A = inputLine.get(i)[0];
                long B = inputLine.get(i)[1];
                long C = inputLine.get(i)[2];
                long D = inputLine.get(i)[3];

                if (A < B){
                    // 初日アウト
                    out.println("No");
                    continue;
                }
                if(B > D){
                    // 必ずいつか尽きる
                    out.println("No");
                    continue;
                }
                if (C  >=  B ){
                    // 危ない状況にならない
                    out.println("Yes");
                    continue;
                }
                long gcd = gcd(B, D);
                if ( B -gcd +  (A % gcd) > C){
                    out.println("No");
                }else {
                    out.println("Yes");
                }

            }
        }
    }

    private static long gcd(long a, long b){
        if (a < b) return gcd(b ,a);
        return b == 0 ? a : gcd( b, a % b);
    }
    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  z = 1;
  FOR(i,1,n+1){
    z = (z*i)%MOD;
  }
  OUT(z);
}

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

int main()
{
  int n;
  cin >> n;
  // long long 型は64ビット以上の値を表現できる
  ll a[n+1] = {};
  ll p[n+1] = {};
  p[0] = 0;
  for(int i=1;i<=n;++i)
  {
    cin >> a[i];
    // 累積和を求める
    p[i] = p[i-1] + a[i];
  }
  ll ans = 1e16; // 1*10^16
  ll dif[4];
  int l=1,r=3;
  for(int i=2;i<=n-2;i++)
  {
    // iを仕切りに左右に分けて考えている
    // 各領域の和を累積和から計算し, その和の差がより少ないものが見つかったら領域の区切りを1つずつずらしていくという方式
    // l<i : 左の区切りlは真ん中の区切りiよりも左にいなければならない
    while( l<i && abs(p[l]-(p[i]-p[l])) >= abs(p[l+1]-(p[i]-p[l+1])) )
    l++;

    // r<n : 右の区切りは当然nよりも左
    while( r<n && abs(p[r]-p[i]-(p[n]-p[r])) >= abs(p[r+1]-p[i]-(p[n]-p[r+1])) )
    r++;

    // 4つの区間の値を計算する
    dif[0]=p[l];dif[1]=p[i]-p[l];dif[2]=p[r]-p[i];dif[3]=p[n]-p[r];

    // 配列を昇順に並べ替える
    sort(dif,dif+4);

    // 一番小さいものを出力
    ans=min(ans,dif[3]-dif[0]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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


const ll mod = 1e9 + 7;
const ll N = 1e5 + 8;


int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL); 
    
    ll n;
    cin >> n;
    vector <ll> v(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    vector <ll> dp(n + 1);
    dp[0] = dp[1] = 0;
    dp[2] = abs(v[2] - v[1]);
    for(int i = 3; i <= n; i++) {
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1792