akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
    /* top を加算してから
    その位置へ挿入 */
    S[++top] = x;
}

int pop() {
    top--;
    /* top が指していた要素を返す */
    return S[top+1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];
    while( scanf("%s", s) != EOF ) {
        if ( s[0] == '+' ) {
        a = pop();
        b = pop();
        push(a + b);
    } else if ( s[0] == '-' ) {
        b = pop();
        a = pop();
        push(a - b);
    } else if ( s[0] == '*' ) {
        a = pop();
        b = pop();
        push(a * b);
    } else {
        push(atoi(s));
    }
    }

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

    return 0;
}


Measured memory_bytes: 2060
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;

ll A,B,L,R;
ll k;

inline void dec(ll t,ll &a,ll &b)
{
	ll ct=t/(k+1);
	a-=ct*k,b-=ct;
	a-=t%(k+1);
}
inline void inc(ll t,ll &a,ll &b)
{
	ll ct=t/(k+1);
	a=ct,b=ct*k;
	b+=t%(k+1);
}
void solve1()
{
	ll u=A+B+233,d=0,mid;

	while(u>d)
	{
		mid=(u+d+1)>>1;

		ll na=A,nb=B;
		dec(mid,na,nb);

		if(na>=0 && nb>=0 && (na+1)*k-(mid%k==0)>=nb)d=mid;
		else u=mid-1;
	}

	ll cnta;

	if(L<=mid)
	{
		cnta=(L-1)%(k+1);
		dec(L-1,A,B);
	}
	else cnta=0,inc(A+B-L+1,A,B);

	int len=R-L+1;
	while(len--)
	{
		char t;
		if(A*k>=B && cnta<k)
			t='A',A--,cnta++;
		else t='B',B--,cnta=0;

		printf("%c",t);
	}
	printf("\n");

}

void solve()
{
	scanf("%lld%lld%lld%lld",&A,&B,&L,&R);

	ll u=std::max(A,B),v=std::min(A,B)+1;
	k=u/v+(u%v!=0);
	
	solve1();
}

int main()
{
//	freopen("in","r",stdin);
	int T;
	for(scanf("%d",&T);T--;)
		solve();
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
mul = 1
flag = 0

for j in range(n):
  if a[j]==0:
    print(0)
    flag = 1

if flag == 0:
  for i in range(n):
    mul *= a[i]
    if mul > 10**18:
      print(-1)
      flag=1
      break

  if flag == 0:
    print(mul)

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> num(n, 0);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        num[a-1]++;
        num[b-1]++;
    }
    for(int i=0; i<n; i++){
        cout << num[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
MOD = 998244353
N, K = map(int, input().split()) #Nはマス目の数、Kは区間の数(Kは10以下)
kukan = [tuple(map(int, input().split())) for _ in range(K)]

dp = [0] * (N+1)
dp[1] = 1

sumdp = [0] * (N+1)
sumdp[1] = 1

for i in range(2, N+1):
    for l, r in kukan:
        li = max(i - l, 0)
        ri = max(i - r - 1, 0)

        dp[i] += sumdp[li] - sumdp[ri]
        dp[i] %= MOD

    sumdp[i] = sumdp[i-1] + dp[i]

print(dp[N])

Measured memory_bytes: 27988
#include <cstdio>
#include <vector>

std::vector<int> bs;

int seq[105];

int main(){
  int N;
  scanf("%d",&N);
  bs.resize(N+1);
  for(int i=1;i<=N;i++){
    scanf("%d",&bs[i]);
  }
  for(int t=N;t>0;t--){
    for(int j=t;;j--){
      if(j==0){
	printf("-1\n");
	return 0;
      }
      if(bs[j]==j){
	seq[t]=j;
	bs.erase(bs.begin()+j);
	break;
      }
    }
  }
  for(int i=1;i<=N;i++){
    printf("%d\n",seq[i]);
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n; cin >> n;
    while (n--) {
        string s; cin >> s;
        char key = s[0], befkey = s[0];
        int c = 0;
        string table[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        rrep(i, 1, s.size()) {
            key = s[i];
            if (key == '0' && befkey != '0') cout << table[befkey - '0'][c];
            if (key == befkey) {c++; if (table[befkey - '0'][c] == '\0') c = 0;}
            else c = 0;
            befkey = key;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3204
#include <iostream>
#include <string>
using namespace std;
void tbd(){

    string s; cin >> s;
    int month = stoi( s.substr(5,2) );
    int day = stoi( s.substr(8,2) );
    if (month >= 5){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }

}

void gift(){
    int N; cin >> N;
    double bit_sum = 0.0;
    int jpy_sum = 0;

    for(int i= 0; i < N; i++){
        string x_i,u_i; cin >> x_i >> u_i;

        if( u_i == "JPY"){
            jpy_sum += stoi(x_i);
        }else if( u_i == "BTC"){
            bit_sum += stod(x_i);
        }
    }

    double ans;
    ans = 380000.0 * bit_sum + static_cast<double>(jpy_sum);

    cout << ans;



}
int main(){

    gift();
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val K = nextInt()
    val ans = mutableListOf<Long>()
    (0L .. 9L).forEach { ans.add(it) }
    var p = 1
    while (p < K) {
        val x = ans[p++]
        for (a in -1 .. 1) {
            val d = x % 10 + a
            if (d < 0 || d > 9) continue
            ans.add(10 * x + d)
        }
    }
    println(ans[K])
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


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

int main()
{
  int M,D ;
  cin>>M>>D ;
  
  /*m月d日:d=10*e+f
    e>=2 && f>=2 && e*f==m */
  int count=0 ;
  for(int e=2;e<=D/10;e++){
    for(int f=2;e*10+f<=D&&f<=9;f++){
      if(e*f<=M) count++ ;
    }
  }
  cout<<count<<endl ;
  
  return 0 ;
}


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

int main() {
    string s;
    cin>>s;
    string k = "keyence";
    int n = s.length();
    bool flag = false;
    for(int i=0; i<=7; i++) {
        string t = s.substr(0,(7-i)) + s.substr(n-i,i);
        if(k == t) flag = true;
    }
    if(flag) cout<<"YES"<<"\n";
    else cout<<"NO"<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

LL ssum(int n){
	return (LL)n*(n+1)/2;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	map<string,int> m;
	REP(i,n){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		m[s]++;
	}
	LL res=0;
	for (auto i:m){
		res+=ssum(i.S-1);
	}
	cout<<res<<endl;
}


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

bool judge(int i, int sum, int m, int n, int A[]) {
  if (sum == m) return 1;
  if (i >= n) return 0;
  return judge(i+1, sum, m, n, A) || judge(i+1, sum+A[i], m, n, A);
}

const int N = 20;

int main() {
  int n, q, m;
  int A[N];

  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> m;
    if (judge(0, 0, m, n, A)) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}



Measured memory_bytes: 3116
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int a = n/100;		//100の位
		int c = (n%100)%10;	//1の位
		
		if(a==c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
		sc.close();
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 50, MAX_M = 50;

int N, M;
int a[MAX_M], b[MAX_M];

vector<int> G[MAX_N];
bool visited[MAX_N];

void dfs(int pos) {
    visited[pos] = true;
    REP(i, G[pos].size()) {
        int to = G[pos][i];
        if (visited[to]) continue;
        dfs(to);
    }
    return;
}

int main() {
    cin >> N >> M;
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    int num_bridge = 0;
    REP(i, M) {
        REP(j, N) {
            G[j] = {};
            visited[j] = false;
        }

        REP(j, M) {
            if (i == j) continue;
            G[a[j]].PB(b[j]);
            G[b[j]].PB(a[j]);
        }

        int cnt = 0;
        REP(j, N) {
            if (visited[j] == false) {
                dfs(j);
                cnt++;
            }
        }
        if (cnt != 1) num_bridge++;
    }
    PRINT(num_bridge);
    return 0;
}

Measured memory_bytes: 3636
import re

def main():
    H, W = map(int, raw_input().split())
    prev_end = 0
    HASH_RE = re.compile(r"#+")
    for i in range(H):
        A = raw_input()
        if HASH_RE.search(A, endpos=prev_end-1) is not None:
            print "Impossible"
            return 0

        m = HASH_RE.search(A, pos=prev_end-1)
        if m is None:
            print "Impossible"
            return 0

        if HASH_RE.search(A, pos=m.end()):
            print "Impossible"
            return 0

        prev_end = m.end()

    print "Possible"

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cnt[26];
    for (int i = 0;i < 26;++i) cnt[i] = 1;
    for (int i = 0;i < n;++i) cnt[s[i]-'a']++;
    ll ans = 1;
    for (int i = 0;i < 26;++i) (ans *= cnt[i]) %= mod;
    cout << (ans-1+mod)%mod;
}

Measured memory_bytes: 512
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 2e5+10;  
ll n,m; 
ll a[maxn];
int cnt[maxn];

int main(){
	cin>>n;
	F(i,2,n){
		cin>>a[i];
			cnt[a[i]]++;
	}
	F(i,1,n){
		cout<<cnt[i]<<endl; 
	}
}
/*
double r;
	cin>>r;
	r = acos(-1)*2.0*r;
	printf("%.10lf\n",r);
	*/

Measured memory_bytes: 5932
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        int n, w;
        scanf("%d %d", &n, &w);
        std::vector<int> weight(n), value(n);
        for(int i=0; i<n; i++) scanf("%d %d", &weight[i], &value[i]);

        std::vector<std::vector<ll>> dp(n+1, std::vector<ll>(w+1, 0));
        for(int i=0; i<n; i++){
                for(int j=0; j<=w; j++){
                        dp[i+1][j] = std::max(dp[i+1][j], dp[i][j]);
                        if(j-weight[i]>=0){
                                dp[i+1][j] = std::max(dp[i+1][j], dp[i][j-weight[i]]+value[i]);
                        }
                }
        }

        printf("%ld\n", dp[n][w]);
        return 0;
}

Measured memory_bytes: 80256
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))

    tmp_max = sum(P[:K])
    tmp = sum(P[:K])
    for i in range(N-K):
        tmp += P[i+K]
        tmp -= P[i]

        if tmp > tmp_max:
            tmp_max = tmp

    print((tmp_max + K) / 2)

main()


Measured memory_bytes: 24404
/**
 *   created: 20 August 2019  11:36:13
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n,k;
		cin>>n>>k;
		vi h(n);
		rep(i,0,n)
			cin>>h[i];
		vi mem(n);
		mem[0] = 0;
		// mem[1] = abs(h[0]-h[1]);
		rep(i,1,n){
			int res = INF;
			rep(j,1,k+1){
				if(i-j<0)
					break;
				res = min(res, abs(h[i]-h[i-j])+mem[i-j]);
			}
			mem[i] = res;
		}
		cout<<mem[n-1];
	}
	return 0;
}


Measured memory_bytes: 1024
while true
    x, y, s = gets.chomp.split.map(&:to_i)
    break if [x, y, s] == [0, 0, 0]

    arr = []
    for x2 in 1...s
        arr[x2 * (x + 100) / 100] = [] if arr[x2 * (x + 100) / 100].nil?
        arr[x2 * (x + 100) / 100] << x2
    end

    max = nil
    for x2 in 1...s
        y2 = s - x2
        xarr = arr[x2]
        yarr = arr[y2]
        if !xarr.nil? && !yarr.nil?
            xarr.product(yarr){|a, b| max = a * (y + 100) / 100 + b * (y + 100) / 100 if max.nil? || max < a * (y + 100) / 100 + b * (y + 100) / 100}
        end
    end
    puts max
end


Measured memory_bytes: 7036
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var text = new Stack<char>();
            foreach(var s in ReadText().ToArray())
            {
                if(s == '0' || s == '1')
                {
                    text.Push(s);
                }
                else if(text.Any())
                {
                    text.Pop();
                }
            }
            return new string(text.Reverse().ToArray());
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 26544
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader(); 
        int[] a = r.ii();
        print((int)((a[2]+0.5)/a[0])*a[1]);
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static int max(int[] ii){
        int max = ii[0];
        for(int i : ii) if(max < i) max = i;
        return max;
    }
    static int min(int[] ii){
        int min = ii[0];
        for(int i : ii) if(i < min) min = i;
        return min;
    }
    static long max(long[] ll){
        long max = ll[0];
        for(long l : ll) if(max < l) max = l;     
        return max;
    }
    static long min(long[] ll){
        long min = ll[0];
        for(long l : ll) if(l < min) min = l;
        return min;
    }
    static double max(double[] dd){
        double max = dd[0];
        for(double d : dd) if(max < d) max = d;
        return max;
    }
    static double min(double[] dd){
        double min = dd[0];
        for(double d : dd) if(d < min) min = d;
        return min;
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return readLine().split(" ");
        }
        int i() throws IOException{
            return Integer.parseInt(readLine());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        int[] ii(int N) throws IOException{
            int[] ii = new int[N];
            for(int j = 0; j < N; j++) ii[j] = i();
            return ii;
        }
        long l() throws IOException{
            return Long.parseLong(readLine());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
        long[] ll(int N) throws IOException{
            long[] ll = new long[N];
            for(int j = 0; j < N; j++) ll[j] = i();            
            return ll;
        }
    }
}

Measured memory_bytes: 21588
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    private static boolean isValid(int n, Set<Integer> valid) {
        while (n > 0) {
            if (!valid.contains(n % 10)) {
                return false;
            }
            n /= 10;
        }
        return true;
    }

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            Set<Integer> valid = new HashSet<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
            for (int i = 0; i < K; i++) {
                valid.remove(sc.nextInt());
            }
            for (; !isValid(N, valid); N++) ;
            System.out.println(N);
        }
    }
}

Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

class WF{
	public:
	ll N;
	ll makeFlg;
	vector<vector<ll> >cost;
	WF(ll _N, ll INF = 1145141919){
		N = _N + 1;
		cost = vector<vector<ll> >(N, vector<ll>(N, INF));
		makeFlg = 0;
	}
	void add(ll a, ll b, ll c){
		cost[a][b] = min(cost[a][b], c);
		makeFlg = 0;
	}
	void make(){
		if(makeFlg)return;
		makeFlg = 1;
		for(ll i = 0; i < N; i++){
			for(ll j = 0; j < N; j++){
				for(ll k = 0; k < N; k++){
					cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
				}
			}
		}
	}
	ll get(ll a, ll b){
		if(makeFlg == 0)make();
		return cost[a][b];
	}
};

int main(){

    ll N, M, R;
    cin >> N >> M >> R;
    vector<ll>r(R);
    for(ll i = 0; i < R; i++)cin >> r[i];
    sort(r.begin(), r.end());
    WF wf(200);
    for(ll i = 0; i < M; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        wf.add(a, b, c);
        wf.add(b, a, c);
    }
    ll ans = 200000000;
    do{
        ll tmp = 0;
        for(ll i = 1; i < r.size(); i++){
            tmp += wf.get(r[i - 1], r[i]);
        }
        ans = min(ans, tmp);
    }while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
	int n, k;
	cin>>n>>k;
	int a[n];
	for(int i=0; i<n; ++i)
	    cin>>a[i];
	sort(a, a+n);
	bool dp[2][k+5];
	dp[0][0]=1;
	dp[1][0]=0;
	for(int i=1; i<=k; ++i)
	{
	    dp[0][i]=1;
	    dp[1][i]=0;
	    for(int j=0; j<n; ++j)
	    {
	        if(a[j]>i) break;
	        if(dp[0][i]==1)
	        {
	            dp[0][i]=dp[1][i-a[j]];
	        }
	        if(dp[1][i]==0)
	        {
	            dp[1][i]=dp[0][i-a[j]];
	        }
	    }
	}
	if(dp[1][k])
	    cout<<"First";
	else
	    cout<<"Second";
}

Measured memory_bytes: 384
N = int(input())
S = [input() for _ in range(N)]

m = set(S[0])
for s in S[1:]:
	m &= set(s)

c = {}
for a in m:
	min_c = 2 ** 31 - 1
	for s in S:
		min_c = min(min_c, s.count(a))
	c[a] = min_c

for a in sorted(m):
	print(a * c[a], end="")
print()


Measured memory_bytes: 3060
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Measured memory_bytes: 9312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int x;
    cin >> x;

    int y,ans;
    y=x/500;
    ans+=y*1000;
    x=x%500;
    y=x/5;
    ans+=y*5;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
long long solve(long long x){
    if(x <= 6){
        return 1;
    }
    if(x <= 11){
        return 2;
    }
    long long res;
    res = x % 11;
    if(res == 0){
        return x / 11 * 2;
    }
    if(res <= 6){
        return x / 11 * 2 + 1;
    }
    else{
        return x / 11 * 2 + 2;
    }
}
int main(void){
    long long x;
    cin >> x;
    long long ans = solve(x);
    cout << ans << endl;
    
}


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n;
ll m;
int cd[5010];
ll p[2][5010][5010];

ll f(int b, int d) {
  if (d == 0)
    return 1;
  if (b == 0)
    return d + 1;
  while (cd[b] <= min(b, d)) {
    int c = cd[b];
    ll r = f(b - c, c);
    p[0][b][c] = r + (c > 0 ? p[0][b][c - 1] : 0);
    if (p[0][b][c] >= m)
      p[0][b][c] -= m;
    p[1][b][c] = (c * r + (c > 0 ? p[1][b][c - 1] : 0)) % m;
    cd[b]++;
  }
  ll r = (d + 1) * p[0][b][min(b, d)] - p[1][b][min(b, d)];
  return (r % m + m) % m;
}

ll g(int b, int d) {
  if (d == 0)
    return b * 2 + (n % 2 == 1);
  if (b == 0)
    return (d + 1) * (n % 2 == 1);
  while (cd[b] <= min(b, d)) {
    int c = cd[b];
    ll r = g(b - c, c);
    p[0][b][c] = r + (c > 0 ? p[0][b][c - 1] : 0);
    if (p[0][b][c] >= m)
      p[0][b][c] -= m;
    p[1][b][c] = (c * r + (c > 0 ? p[1][b][c - 1] : 0)) % m;
    cd[b]++;
  }
  ll r = (d + 1) * p[0][b][min(b, d)] - p[1][b][min(b, d)];
  return (r % m + m) % m;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> m;
  ll r = 0;
  for (int s = 1; s <= n; s++)
    r += f(s - 1, n - s);
  for (int i = 0; i < 5010; i++)
    cd[i] = 0;
  for (int s = (n - 1) / 2 + 1; s < n; s++)
    r -= g(s - 1 - (n - 1) / 2, n - s - 1);
  r = (r % m + m) % m;
  cout << r << "\n";
}


Measured memory_bytes: 389632
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b = m()

print((a*(a-1))//2 + (b*(b-1))//2)

Measured memory_bytes: 38384
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String s = saori.nextHayami();
		s = s.replaceAll(",", " ");
		System.out.println(s);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main() {
	char s[202] = { 0 };
	char p[101] = { 0 };

	scanf("%s", s);
	scanf("%s", p);

	strncat(s, s, strlen(p));
	if (strstr(s, p) == NULL) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef map<int,int> mapii;
typedef map<int,bool> mapib;
typedef map<char,int> mapci;
typedef priority_queue<int> pr;

#define small 1e-9
#define big5 1000000005
#define big7 1000000007
#define big 1000000
#define pi 3.1415926

#define inp(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define cum(arr,n,cumm) cumm[0]=0;for(int i=0;i<n;i++)cumm[i+1]=cumm[i]+arr[i];
#define bsdk ios_base::sync_with_stdio(false);cin.tie(NULL);
#define disp(arr) for(auto i:arr)cout<<i<<" ";cout<<"\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define yess cout<<"Yes\n"
#define noo cout<<"No\n"
#define m1 cout<<"-1\n"
#define nl <<endl
#define hs cout<<"#"

#define fori(a, b, c) for (a = (b); (a) <= (c); ++(a))
#define ford(a, b, c) for (a = (b); (a) >= (c); --(a))
#define rep(i,n) fori(i,0,n-1)
#define repi(i,n) fori(i,1,n-1)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound
#define allv(v) v.begin(), v.end()
#define sorti(v) sort(allv(v))
/*bool isprime[big+1];
vector<int> primes;
void makesieve()
{
    ll i,j;
    rep(i,1000001)
        isprime[i]=false;
    isprime[2]=true;
    for(i=3;i<=big;i+=2)
        isprime[i]=true;
    for(i=3;i<=big;i+=2)
    {
        if(isprime[i])
            for(j=i*i;j<=big;j+=i)
            isprime[j]=false;
    }
    rep(i,big+1)
    {
        if(isprime[i])
            primes.pb(i);
    }
}
ll poww(ll n,ll m){
    if(m==0)return 1;
    if(m==1)return n;
    ll ans = poww(n,m/2);
    if(m%2==1) return (ans*ans)*n;
    else return (ans*ans);
}*/
void solve()
{
    int a;
    cin>>a;
    cout<<(a+a*a+a*a*a);
}
int main()
{
    bsdk
    int t;
    //cin>>t;
    t=1;
    while(t--) solve();
    return 0;
}


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

bool isPrime(int num){
  if(num < 2) return false;
  else if(num == 2) return true;
  else if(num % 2 == 0) return false;

  for(int i = 3; i*i < num; i+=2){
    if (num % i == 0) return false;
  }

  return true;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  set<int> ans;  
  set<int> minus;
  for(int i = 0; i < n; i++){
    int now = a.at(i);
    bool ok = true;
    for(int j = 1; j * j <= now; j++){
      if(now % j) continue;
      if(ans.count(j) || ans.count(now/j)){
        ok = false;
        break;
      }
    }
    if(ans.count(now)) minus.insert(now);
    if(ok) ans.insert(now);
  }
  
  cout << ans.size() - minus.size() << endl;
}


Measured memory_bytes: 13136
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  bool flag = true;
  if(sz(S) % 2 != 0) flag = false;
  for(int i = 0; i < sz(S); i++){
    if(i % 2 == 0 && S[i] != 'h') flag = false;
    else if(i % 2 != 0 && S[i] != 'i') flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

N += 1

fact = [0] * N
inv = [0] * N
inv_cal = [0] * N

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, N):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    print(comb(R+1, k) * comb(K-1, k-1) % mod)

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


int main(){
ll N;
cin >> N;
vector<vector<char>> A(N, vector<char>(10, ' '));
for(int i=0;i<N;i++){
 for(int j=0;j<10;j++){
     cin>>A[i][j]
 ;}
;}
for(int i=0;i<N;i++){
    sort(A[i].begin(), A[i].end());
;}
vector<string> B(N,"");
for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
        B[i]+=A[i][j]
    ;}
;}
sort(B.begin(), B.end());
ll counter=0;
deque<ll> dq;
for(int i=0;i<N-1;i++){
    if(B[i]==B[i+1]){
        counter++;
    }
    else{
        if(counter!=0){
            dq.emplace_back(counter+1);
            counter=0;
        }
    }
;}
if(counter!=0){
    dq.emplace_back(counter+1);
}
ll Ans=0;
while(dq.size()){
    Ans+=(dq.front()-1)*(dq.front())/2;
    dq.pop_front();
}
cout<<Ans<<endl;

return 0;


}  



Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll dp[1010][1<<13];
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
const ll inf = 1LL<<60;
int main() {
  int n,m;
  cin >> n >> m;
  vi a(m),c(m);
  Fill(dp,inf);
  rep(i,m){
    int b;
    cin >> a[i] >> b;
    int key=0;
    rep(j,b){
      int tmp;
      cin >> tmp;
      key|=(1<<(tmp-1));
    }
    c[i] = key;
  }
  dp[0][0] = 0;
  rep(i,m){
    rep(j,(1<<n)){
      mins(dp[i+1][j],dp[i][j]);
      dp[i][j|c[i]] = min(dp[i][j|c[i]],dp[i][j]+a[i]);
    }
  }
  cout<<((dp[m][(1<<n)-1] == inf)?-1:dp[m][(1<<n)-1])<<endl;
  return 0;
}

Measured memory_bytes: 68288
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	string s;
    IN(s);
    string t[3]={"Sunny","Cloudy","Rainy"};
    REP(i,3){
        if(s==t[i]){
            s=t[(i+1)%3];
            break;
        }
    }
    OUT(s);
	return 0;
}

Measured memory_bytes: 256
# 0..aの累積XORを求める
def solve(a)
  if a.odd?
    if (a/2).odd?
      0
    else
      1
    end
  else
    if (a/2).odd?
      a+1
    else
      a
    end
  end
end

a,b = gets.split.map &:to_i
ans = a.zero? ? solve(b) : solve(b) ^ solve(a-1)
puts ans



Measured memory_bytes: 1788
// ~maqsat~

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

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

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
#define ever ;;

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
#ifdef ZVER
	cerr << "Ready\n";
#endif
	fre("");
	ACCELERATE;
	
	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	
	k--;
	cout << v[k] << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;
Node treeMinimum(Node x){

}
Node treeMaximum(Node x){

}
Node treeSearch(Node u, int k){

  }
Node treeSuccessor(Node x){

}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  }
void insert(int k){ //k=(加える整数)
  Node y = NIL;//xの親
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key)x = x->left;// 左の子へ移動
    else x = x->right;// 右の子へ移動
  }
  z->parent=y;
  if(y==NIL)root=z; // T が空の場合
  else if(z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}
void inorder(Node x){
  if(x!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
void preorder(Node x){
  if(x!=NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}
int main(){
  int n, i,x;
  char com[20];
  
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d",&x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}



Measured memory_bytes: 25128
#include<iostream>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  for(int i=0;i<2;i++){
  if(a<b){
    c+=b;
    b--;
    }else{c+=a; a--;}
  }cout<<c;
  return 0;
  }

Measured memory_bytes: 256
N, M, K = map(int, input().split())
ans = 0

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for i in range(K+1):
    res_i = (M * pow(M-1, N-i-1, p)) % p
    res_i = (res_i * cmb(N-1, i, p)) % p
    ans = (ans + res_i) % p

print(ans)


Measured memory_bytes: 32780
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for( ll pick = k; pick <= n+1; ++pick ){
		ll smin = pick*(pick-1)/2;
		ll smax = n*(n+1)/2 - (n-pick)*(n-pick+1)/2;
		// cout << smax << ' ' << smin << endl;
		ans += (smax-smin+1);
		// cout << ans << endl;
		ans %= mod;
	}
	 cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 1000000
using namespace std;
int n,q;
int c[maxn];
pair<int,pair<int,int> > a[maxn];
int ans[maxn];
int lp[maxn];
int seg[4*maxn];
void add(int id,int l,int r,int p,int v) {
    if(p<l || p>r) return;
    if(l==r) {
        seg[id]+=v;
        return;
    }
    int m=(l+r)>>1;
    add(id*2+1,l,m,p,v);
    add(id*2+2,m+1,r,p,v);
    seg[id]=seg[id*2+1]+seg[id*2+2];
}
int query(int id,int l,int r,int x,int y) {
    if(y<l || r<x) return 0;
    if(x<=l && r<=y) return seg[id];
    int m=(l+r)>>1;
    return query(id*2+1,l,m,x,y)+query(id*2+2,m+1,r,x,y);
}
int main() {
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++) {
        scanf("%d",&c[i]);
        c[i]--;
    }
    for(int i=0;i<q;i++) {
        int l,r;
        scanf("%d %d",&l,&r);
        l--;
        r--;
        a[i]={r,{l,i}};
    }
    for(int i=0;i<n;i++) lp[i]=-1;
    sort(a,a+q);
    int p=0;
    for(int i=0;i<q;i++) {
        //cout<<i<<endl;
        while(p<=a[i].first) {
            //scout<<p<<" "<<c[p]<<" "<<lp[c[p]]<<endl;
            add(0,0,n-1,lp[c[p]],-1);
            add(0,0,n-1,p,1);
            lp[c[p]]=p;
            p++;
        }
        ans[a[i].second.second]=query(0,0,n-1,a[i].second.first,a[i].first);
    }
    for(int i=0;i<q;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 19608
using System;
using System.Linq;
class c
{
  public static void Main()
  {
    int[] xab=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int x=xab[0];
    int a=xab[1];
    int b=xab[2];
    if(Math.Abs(x-a)>Math.Abs(x-b))Console.WriteLine("B");
    else Console.WriteLine("A");
  }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#define inf 0x3fffffff
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int M=8000000;
const int MOD=1000000007;
LL invf[M], fac[M] = {1};
LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
void fac_inv_init(LL n, LL p) {
    FOR (i, 1, n)
        fac[i] = i * fac[i - 1] % p;
    invf[n - 1] = bin(fac[n - 1], p - 2, p);
    FORD (i, n - 2, -1)
        invf[i] = invf[i + 1] * (i + 1) % p;
}

inline LL C(LL n, LL m) { // n >= m >= 0
    return n < m || m < 0 ? 0 : fac[n] * invf[m] % MOD * invf[n - m] % MOD;
}

LL calc(LL x,LL y)
{
    LL ans=y%MOD;
    for (LL i=1;i<=x;i++)
        ans=(ans+C(y+i+1LL,i+1LL))%MOD;
        //cout<<ans<<endl;
    return ans;
}
LL a,b,c,d;
int main()
{
    fac_inv_init(4000000,MOD);
    //cout<<calc(2,2)<<endl;
    //return 0;
    cin>>a>>b>>c>>d;
    LL ans=(calc(c,d)+calc(a-1,b-1))%MOD;
    ans=(ans+MOD-calc(a-1,d))%MOD;
    ans=(ans+MOD-calc(c,b-1))%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 63232
#include "bits/stdc++.h"
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	long long x, y;

	cin>>x>>y;

	if(x>=y){
		if(x%y){
			cout<<x<<endl;
		}else{
			cout<<-1<<endl;
		}
	}else{
		cout<<x<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
#define MAXN 10200
#define EPS 1E-7

using namespace std;
int a[MAXN];
int main()
{
    int a=0,b=0,c;
    for(int i=0;i<3;i++)
    {
        cin>>c;
        if(c==5)
            a++;
        if(c==7)
            b++;

    }
    if(a==2&&b==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

int main(){
    long long n,m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    long long g=__gcd(n,m);
    long long l=n/g*m;
    bool flag=true;
    n/=g;
    m/=g;
    for(long long i=0;i<g;i++){
        if(s[i*n]!=t[i*m]){
            flag=false;
            break;
        }
    }
    if(flag) cout << l << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n - 1; i++)
    {
        int target = p[i];
        vector<int> v;
        for(int j = i - 1; j <= i + 1; j++) v.push_back(p[j]);
        sort(v.begin(), v.end());
        if(v[1] == target) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

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

	if (a >= 13) {
		fare = b;
	}
	else if (a >= 6){
		fare = b / 2;
	}
	else {
		fare = 0;
	}
	cout << fare << endl;
}

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

using namespace std;

int main(void){
	string str; cin >> str;
	int ans = 0;
	int count = 0;
	for(int i=0; i<str.size(); i++){
		if(str[i] != 'A' && str[i] != 'T' && str[i] != 'C' && str[i] != 'G'){
			ans = max(ans, count);
			count = 0;
		} else count++;
	}
	ans = max(ans, count);
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int hannpenn;
        
        hannpenn=(a+b)/2;
        System.out.println(hannpenn);
        
        }
    }



Measured memory_bytes: 26160