akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;

int main()
{
	int N, D, X;
	scanf("%d%d%d", &N, &D, &X);
	int A[N];
	for(int i = 0; i < N; i++) scanf("%d", &A[i]);
	int chocolate;
	for (int j = 0; j < N; j++) {
		chocolate++;
		for (int k = 1; k <= D; k++) {
			int day = k * A[j] + 1;
			if (day <= D) chocolate++;
		}
	}
	chocolate += X;
	printf("%d\n", chocolate);
	return 0;
}

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

#define ll long long
const ll inf = 1e18L + 5;

int main(){

	int n;
	ll w;
	cin >> n >> w;
	vector<ll>value(n),weight(n);
	for(int i=0;i<n;++i){
		cin >> weight[i] >> value[i];
	}

	ll value_sum = 0;
	for(int i=0;i<n;++i){
		value_sum+=value[i];
	}

	vector<ll>dp(value_sum + 1,inf) ;
	dp[0] = 0;
	//cout << 1 << endl;
	for( ll j=0;j<n;++j){
		for(ll i = value_sum-value[j] ; i>=0 ; --i){
			dp[i + value[j]] = min(dp[i + value[j]] , dp[i] + weight[j]);
		}
	}
	 

	ll ans = 0;
	//cout << 1 << endl;
	for(ll i = 0; i<=value_sum ; ++i ){
		if(dp[i] <= w){
			ans = max(i,ans);
		}
	}

	cout << ans << endl;





	return 0;
}

Measured memory_bytes: 1024
<?php

class Node {
	public $left;
	public $right;
	public $value;
	public $largest;

	public function __construct($value) {
		$this->value = $value;
	}

	public function max_value() {
		if ($this->largest !== null) {
			return $this->largest;
		}
		if (is_null($this->left) && is_null($this->right)) {
			return $this->value;
		}
		$left  = is_null($this->left)  ? -1 : $this->left->max_value();
		$right = is_null($this->right) ? -1 : $this->right->max_value();

		return $this->largest = $this->value + max($left, $right);
	}
}

$diamond = array();

while ($line = trim(fgets(STDIN))) {
	$diamond[] = explode(',', $line);
}

$nodes = array();
for ($i = 0; $i < count($diamond); $i++) {
	for ($j = 0; $j < count($diamond[$i]); $j++) {
		$nodes[$i][$j] = new Node($diamond[$i][$j]);
	}
}

for ($i = 0; $i < count($nodes); $i++) {
	for ($j = 0; $j < count($nodes[$i]); $j++) {
		$n = $nodes[$i][$j];
		if ($i < count($diamond)/2 - 1) {
			$n->left  = isset($nodes[$i + 1][$j])     ? $nodes[$i + 1][$j]     : null;
			$n->right = isset($nodes[$i + 1][$j + 1]) ? $nodes[$i + 1][$j + 1] : null;
		} else {
			$n->left  = isset($nodes[$i + 1][$j - 1]) ? $nodes[$i + 1][$j - 1] : null;
			$n->right = isset($nodes[$i + 1][$j])     ? $nodes[$i + 1][$j]     : null;
		}
	}
}

$top = $nodes[0][0];

echo $top->max_value() . "\n";

Measured memory_bytes: 9672
#include <stdio.h>

struct trade{
  int before;
  int after;
};

int main(void){
  int w,n;
  int ans[30];
  struct trade trd[30];
  int i,j;
  int now;

  scanf("%d%d",&w,&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&trd[i].before,&trd[i].after);
  }
  for(i=1;i<=w;i++){
    now=i;
    for(j=0;j<n;j++){
      if(trd[j].before == now){
//        printf("\t\tnum:%d  now:%d  <-> after:%d\n",i,now,trd[j].after);
        now = trd[j].after;
      } else if(trd[j].after == now) {
//        printf("\t\tnum:%d  now:%d  <-> after:%d\n",i,now,trd[j].before);
        now = trd[j].before;
      }
//      printf("\tnum:%d now:%d\n",i,now);
    }
//    printf("num:%d now:%d\n",i,now);
    ans[now]=i;
  }

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

  return 0;
}

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

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

  bool flag =false;
  
  for(int c=1; c<=3; c++)
  {
      if((a*b*c) % 2 != 0)
      {
         flag = true;
          break;
      }
  }


  if(flag == true) cout<<"Yes";
  else cout<<"No";
  cout<<endl;
	return 0;
}


Measured memory_bytes: 256
//# include <stdio.h>
# include <iostream>
# include <cstring>
//# include <cstdio>

//# include <conio.h>

/*
Next Letter
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
Mr. Takahashi has a string s consisting of lowercase English letters.
He repeats the following operation on s exactly K times.
    Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of z is a.
For example, if you perform an operation for the second letter on aaz, aaz becomes abz.
If you then perform an operation for the third letter on abz, abz becomes aba.
Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s.
Find the such string.
Constraints
    1 <= |s| <= 10^5
    All letters in s are lowercase English letters.
    1 <= K <= 10^9
Input
The input is given from Standard Input in the following format:
s
K
Output
Print the lexicographically smallest string after performing exactly K operations on s.
Sample Input 1
xyz
4
Sample Output 1
aya
For example, you can perform the following operations: xyz, yyz, zyz, ayz, aya.
Sample Input 2
a
25
Sample Output 2
z
You have to perform exactly K operations.
Sample Input 3
codefestival
100
Sample Output 3
aaaafeaaivap


*/

using namespace std;

const int N = 100100;

int n, k;
char s [N];
bool ok;

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

   ok = true;
   n = strlen (s);
   for ( int i=0; s [i]; i++ )
   {
      if ( s [i] == 'a' )
         ;
      else if ( 'z' - s [i] < k )
         k -= 'z' - s [i] + 1,
         s [i] = 'a',
         ok = true;
      else
         ok = false;
   }

   if ( k > 0 )
   {
      s [n-1] = 'a' + ((s [n-1] - 'a') + k) % 26;
   }

   cout << s << endl;

//getch();

   return 0;
}


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

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

int main(){
    int k;
    cin>>k;
    string s;
    rep(i,k){
        s+="ACL";
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int counter(int n);

int main(){
    int a, b, n;
    while(scanf("%d%d",&a,&b)!=EOF){
        n=counter(a+b);
        cout<<n<<endl;
    }
    return 0;
}

int counter(int n){
    int count1 = 0;
    while(n > 0)
    {
        // n = n/10
        n /= 10;
        ++count1;
    }
    return count1;
}

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

char field[100][100];

void search(int y,int x)
{
	if(field[y][x] == '.')
		cout << x << " " << y << endl;
	else if(field[y][x] == '0')
		cout << "LOOP" << endl;
	else{
		if(field[y][x] == '>'){
			field[y][x] = '0';
			search(y,x+1);
		}
		else if(field[y][x] == '<'){
			field[y][x] = '0';
			search(y,x-1);
		}
		else if(field[y][x] == 'v'){
			field[y][x] = '0';
			search(y+1,x);
		}
		else if(field[y][x] == '^'){
			field[y][x] = '0';
			search(y-1,x);
		}
	}
}

int main()
{
	int w,h;
	while(cin >> w >> h){
		if(!w && !h)
			break;
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				cin >> field[i][j];
			}
		}
		search(0,0);
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<string,int> s;
    rep(i,n){
        string input;
         cin >> input;
        s[input]++; 
    }
    int max_n = 0;
    for(auto m : s){
        max_n = max(max_n, m.second);
    }
    for(auto m : s){
        if(m.second == max_n) cout << m.first << endl;
    }
}

Measured memory_bytes: 25216
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n;

int check(int n)
{
    return n<10?n:n%10+check(n/10);
}

int main()
{
    cin>>n;
    puts(n%check(n)?"No":"Yes");
}

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

ans = 0
f = 2
while True:
  if N%f==0:
    c = 0
    while N%f==0:
      N /= f
      c += 1
    n = 1
    while n*(n+1)//2<=c:
      n += 1
    ans += n-1
  if f*f>N:
    break
  f += 1
if N>1:
  ans += 1
print(ans)


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

int main() {
  
  int k, x;
  cin >> k >> x;
  
  REP(i,k*2-1) { 
    cout << x-k+i+1 << " ";
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int m, f, r;
	while (true) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) { return 0; }
		if (m == -1 || f == -1) { cout << 'F' << endl; }
		else if (m + f >= 80) { cout << 'A' << endl; }
		else if (m + f >= 65) { cout << 'B' << endl; }
		else if (m + f >= 50) { cout << 'C' << endl; }
		else if (m + f >= 30 && r >= 50) { cout << 'C' << endl; }
		else if (m + f >= 30) { cout << 'D' << endl; }
		else { cout << 'F' << endl; }
	}
	cin >> m;
}


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

int main(){
  int sum = 0;
  string n;
  cin >> n;
  rep(i, n.length()){
    sum += n[i]-'0';
  }
  // cout << "[" << sum << "]";
  if(sum%9==0)cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 3700
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
//END OF TEMPLATE

void main(){
    auto k=scan!size_t;
    auto s=scan!string;
    (s.length<=k?s:s[0..k]~"...").writeln;
}


Measured memory_bytes: 3704
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void chmax(int &X,int Y)
{
	if(X < Y) X = Y;
}
struct Kumi{
	int first;
	int second;
	int third;
	int fourth;
};
void rec(vector<vector<int>> &all,int N,int M,vector<int> tmp,int num)
{
	if(num == N) 
	{
		all.push_back(tmp);
		return;
	}
	for(int i = tmp[num-1];i <= M;i++)
	{
		tmp[num] = i;
		rec(all,N,M,tmp,num + 1);
	}
}
int main()
{
	vector<vector<int>> all;
	long long N,M,Q;
	cin >> N >> M >> Q;
	int i;
	Kumi kumi[Q];
	for(i = 0;i < Q;i++)
	{
		cin >> kumi[i].first >> kumi[i].second >> kumi[i].third >> kumi[i].fourth;
	}
	vector<int> tmp(N);
	for(i = 1;i <= M;i++)
	{
		tmp[0] = i;
		rec(all,N,M,tmp,1);
	}
	int max = -1;
	for(i = 0;i < all.size();i++)
	{
		int sum = 0;
		for(int j = 0;j < Q;j++)
		{
			if(all[i][kumi[j].second-1]-all[i][kumi[j].first-1]
			== kumi[j].third)
			{ sum += kumi[j].fourth; }
		}
		chmax(max,sum);
	}
	/*
	for(i = 0;i < all.size();i++)
	{
		for(int j = 0;j < N;j++)
		{
			cout << all[i][j] << endl;
		}
	}
	*/
	cout << max;
	return 0;
}
	

Measured memory_bytes: 9836
#include <iostream>
#include <map>
using namespace std;
int n;
string s;
map<string,int> a;
const string x[]={"AC","WA","TLE","RE"};
int main(){
	cin>>n;
	while(n--){
		cin>>s;
		a[s]++;
	}
	for(int i=0;i<4;i++){
		cout<<x[i]<<" x "<<(a.count(x[i])?a[x[i]]:0)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3640
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    dp = [0] * (N+10)
    dp[2] = abs(A[1] - A[0])
    for i in range(2,N):
        res = []
        if K > i:
            kk = i+1
        else:
            kk = K + 1
        for j in range(1,kk):
            res.append(abs(A[i] - A[i-j])+dp[i-j+1])
        dp[i+1] = min(res)
    
    print(dp[N])
if __name__ == "__main__":
    main()

Measured memory_bytes: 52448
#include<iostream>
#include<cstdio>
#include<cstring>
namespace YuanTi
{
	const int N=200100;
	int s[N],t[N];
	int n,m;
	void initialize()
	{
		scanf("%d",&n),m=n*2-1;
		for(int i=1;i<=m;i++)
			scanf("%d",s+i);
	}
	bool check(int x)
	{
		for(int i=1;i<=m;i++)t[i]=(s[i]<=x);

		int a=-1,b=-1;
		for(int i=n;i>1;i--)
			if(t[i]==t[i-1]){a=i;break;}
		for(int i=n;i<m;i++)
			if(t[i]==t[i+1]){b=i;break;}
		if(a<0 && b<0)return t[n]^((n-1)&1);
		if(a<0)return t[b];
		if(b<0)return t[a];
		if(n-a<b-n)return t[a];
		return t[b];
	}
	int getans()
	{
		int u=m,d=1,mid;
		while(u>d)
		{
			if(check(mid=(u+d)>>1))u=mid;
			else d=mid+1;
		}
		return d;
	}
	void solve()
	{
		initialize();

		printf("%d\n",getans());
	}
}
int main()
{
	YuanTi::solve();
	return 0;
}


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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int A, B, M;
    cin>>A>>B>>M;
    int mina = 1000000, minb = 1000000;
    vector<int> a(A), b(B);
    for (int i = 0; i < A; ++i) {
        cin>>a[i];
        mina = min(mina, a[i]);
    }
    for (int i = 0; i < B; ++i) {
        cin>>b[i];
        minb = min(minb, b[i]);
    }

    int ans = mina + minb;

    for(int i=0;i<M;i++){
        int x, y, c;
        cin>>x>>y>>c;
        x--;
        y--;
        ans = min(ans, a[x]+b[y]-c);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
def f():
    import sys
    input=sys.stdin.buffer.readline
    inputs=sys.stdin.buffer.readlines
    n,m,s,t=map(int,input().split())
    yedge=[[]for i in range(n+1)]
    sedge=[[]for i in range(n+1)]
    for i in inputs():
        fro,to,cy,cs=map(int,i.split())
        yedge[fro].append((to,cy))
        yedge[to].append((fro,cy))
        sedge[fro].append((to,cs))
        sedge[to].append((fro,cs))
    from heapq import  heappop, heappush
    def dijkstra(edges,start):
        #edges->edges[from]=[(to,cost)]
        #1-based-index->|edges|=n+1
        #return ->distance(no path, then -1)
        d=[-1]*len(edges)
        #fr=[[]for i in range(len(edges))]
        hq=[(0,start)]
        while hq:
            c,v=heappop(hq)
            if d[v]!=-1:continue
            d[v]=c
            #fr[v]=f
            for to,cos in edges[v]:
                if d[to]==-1:heappush(hq,(c+cos,to))
        return d#,fr
    yd=dijkstra(yedge,s)
    sd=dijkstra(sedge,t)
    ret=[]
    ans=0
    k=10**15
    for i in range(n,0,-1):
        ans=max(ans,k-yd[i]-sd[i])
        ret.append(ans)
    ret.reverse()
    print(*ret,sep="\n")
if __name__ == "__main__":
    f()

Measured memory_bytes: 81468
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    let N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const kRegexp = new RegExp("["+arg[1].replace(" ","")+"]");
    
    while(kRegexp.test(String(N))) {
        N++;
    }
    
    let answer = N;
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10548
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(3, vector<int>(N));
    for (auto& v : A) {
        for (int& i : v) cin >> i;
        sort(v.begin(), v.end());
    }
    long long ans {};
    for (int j : A[1]) {
        auto itr1 = lower_bound(A[0].begin(), A[0].end(), j);
        auto itr2 = upper_bound(A[2].begin(), A[2].end(), j);
        ans += distance(A[0].begin(), itr1) * distance(itr2, A[2].end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    while(scan.hasNext()){
      int na=scan.nextInt();
      int nb=scan.nextInt();
      int nc=scan.nextInt();
      if(na*nb*nc==0)
        return;
      int n=scan.nextInt();
      int a[]=new int [na];
      int b[]=new int [nb];
      int c[]=new int [nc];
      Arrays.fill(a,2);
      Arrays.fill(b,2);
      Arrays.fill(c,2);
      //ok=1; not ok=0; dont know=2
      
      int ta,tb,tc;
      int res;
     
      int table[][]=new int [n][4];
      for(int ix=0;ix<n;ix++)
        for(int iy=0;iy<4;iy++)
          table[ix][iy]=-1;

      for(int i=0;i<n;i++){
        ta=scan.nextInt();
        ta-=1;
        tb=scan.nextInt();
        tb-=(na+1);
        tc=scan.nextInt();
        tc-=(na+nb+1);
        res=scan.nextInt();

        if(res==1){
          a[ta]=1;b[tb]=1;c[tc]=1;
        }
        if(res==0){
          table[i][0]=ta;
          table[i][1]=tb;
          table[i][2]=tc;
          table[i][3]=res;
        }
      }
      for(int i=0;i<n;i++){
        if(table[i][3]==0)
          twoOfThree(table[i][0],table[i][1],table[i][2],
              a,b,c);
      }


      for(int i=0;i<na;i++)
        System.out.println(a[i]);
      for(int i=0;i<nb;i++)
        System.out.println(b[i]);
      for(int i=0;i<nc;i++)
        System.out.println(c[i]);

    }
  }//main
  static void twoOfThree(int ta,int tb,int tc,int []a,int []b,int []c){
    if(a[ta]==1&&b[tb]==1){
      c[tc]=0;return;
    }
    else if(a[ta]==1&&c[tc]==1){
      b[tb]=0;return;
    }
    else if(b[tb]==1&&c[tc]==1){
      a[ta]=0;return;
    }
    
  }
    
}


Measured memory_bytes: 37192
// Start: 2018/03/10 23:36
// End  : 2018/03/10 23:42

#include <iostream>
#include <cstdio>
using namespace std;

string march = "MARCH";

int main(){
  int n;
  scanf("%d", &n);

  long long d[5];
  for (int i = 0; i < 5; i++){
    d[i] = 0;
  }

  string str;
  for(int i = 0; i < n; i++){
    cin >> str;
    for (int j = 0; j < 5; j++){
      if (str[0] == march[j]){
        d[j]++;
        break;
      }
    }
  }

  long long sum = 0;
  for (int i = 0; i < 5; i++){
    for (int j = i + 1; j < 5; j++){
      for (int k = j + 1; k < 5; k++){
        sum += d[i] * d[j] * d[k];
      }
    }
  }

  printf("%lld\n", sum);

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextList().map(String::toBigDecimal)
    println(A.multiply(B).toPlainString().split(".")[0])
}

Measured memory_bytes: 36724
n = int(raw_input())
h = map(int, raw_input().split())
c = [0] * n
for i in xrange(n-1, -1, -1):
  if i == n - 1:
    c[i] = 0
  else:
    c[i] = c[i+1] + 1 if h[i] >= h[i+1] else 0
print max(c)


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

int main()
{
    long long X;
    cin >> X;
    long long amount = 100;
    long long year = 0;

    long long risi = 0;
    while (amount < X)
    {
        risi = amount / 100;
        amount += risi;
        year++;
    }

    cout << year << endl;
}

Measured memory_bytes: 3576
class Node:
    def __init__(self, k):
        self.parent = None
        self.childs = [None, None]
        self.key = k


class Tree:
    def __init__(self):
        self.root = None

    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.childs[0]
            else:
                x = x.childs[1]
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.childs[0] = z
        else:
            y.childs[1] = z

    def find(self, k):
        x = self.root
        while x != None:
            if k == x.key:
                return x
            if k < x.key:
                x = x.childs[0]
            else:
                x = x.childs[1]
        return None

    def delete(self, k):
        z = self.find(k)
        if z == None:
            return
        if z.childs[0] == None and z.childs[1] == None:
            p = z.parent
            if p != None:
                for i, v in enumerate(p.childs):
                    if v == z:
                        p.childs[i] = None
                        break
        elif z.childs[0] != None and z.childs[1] != None:
            y = z.childs[1]
            while y.childs[0] != None:
                y = y.childs[0]
            nk = y.key
            self.delete(nk)
            z.key = nk
        else:
            p = z.parent
            c = z.childs[0] if z.childs[0] != None else z.childs[1]
            c.parent = p
            if p != None:
                for i, v in enumerate(p.childs):
                    if v == z:
                        p.childs[i] = c
                        break


def preorder(p):
    s = ""
    if p == None:
        return ""
    s += f"{p.key} "
    s += preorder(p.childs[0])
    s += preorder(p.childs[1])
    return s


def inorder(p):
    s = ""
    if p == None:
        return ""
    s += inorder(p.childs[0])
    s += f"{p.key} "
    s += inorder(p.childs[1])
    return s


n = int(input())

t = Tree()
for i in range(n):
    v = input().split()
    if v[0] == "insert":
        t.insert(Node(int(v[1])))
    elif v[0] == "find":
        print("yes" if t.find(int(v[1])) != None else "no")
    elif v[0] == "delete":
        t.delete(int(v[1]))
    else:
        print(" "+inorder(t.root).strip())
        print(" "+preorder(t.root).strip())



Measured memory_bytes: 126564
var n,i:Longint;
s,t,m:int64;
a:Array[1..200000]of Longint;
begin
read(n);
for i:=1 to n do begin
read(a[i]);
inc(s,a[i]);
end;
m:=s;
for i:=1 to n-1 do begin
inc(t,a[i]);dec(s,a[i]);
if(s<t)and(m>t-s)then m:=t-s else if(s>=t)and(m>s-t)then m:=s-t;
end;
writeln(m);
end.

Measured memory_bytes: 896
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,t;
	cin>>n>>t;
	int ta=t,ans=1E9;
	for(int i=0;i!=n;++i){
		int a,b;
		cin>>a>>b;
		if(b<=t && a<=ans)
			ans=a;
	}
	if(ans==1E9)
		cout<<"TLE";
	else
		cout<<ans;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>

int prime[10000],s;
int flg[10001];

int isPrime(int x){
  int i;
  for(i=0;i<s && prime[i]<=sqrt(x);i++){
    if(x%prime[i] == 0) return 0;
  }
  return 1;
}

void mkPrime(void){
  int i;

  prime[0]=2,s=1;
  flg[0]=flg[1]=0;
  flg[2]=1;
  for(i=3;i<=10000;i++){
    if(isPrime(i)){
      prime[s++] = i;
      flg[i] = 1;
    }
    else{
      flg[i] = 0;
    }
  }
}

int main(void){
  int i,j,n,count;

  mkPrime();

  while(scanf("%d",&n) != EOF){
    count = 0;
    for(i=1,j=n;i<=n;i++,j--){
      if(flg[i] && flg[j]) count++;
    }
    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 0
a = int(input().strip())
import sys
sys.setrecursionlimit(1000000)
tmp = []
res = []
ind = 1

def bar(foo,hoge):
    if(foo == 0):
        return
    if foo == 1:
        res.append(1)
        return
    elif foo == 2:
        res.append(2)
        return
    for i in reversed(range(hoge)):
        if (tmp[i] <= foo):
            res.append(i + 1)
            bar(foo - (i + 1) , i)
            return
        
        
    
for i in range(10000000):
    ind = ind + i
    tmp.append(ind)
    if ind >= a :
        bar(a, i + 1 )
        break
for i in res:
    print(i)


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionset(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findset(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>x(n),y(n);
  map<ll,ll> a,b;
  for(i=0;i<n;i++)cin>>x[i]>>y[i];  
  UnionFind tree(n);
  for(i=0;i<n;i++){
    if(a.find(x[i])==a.end()){
      a.insert({x[i],i});
    }
    else{
      tree.unionset(i,a[x[i]]);
    }
    if(b.find(y[i])==b.end()){
      b.insert({y[i],i});
    }
    else{
      tree.unionset(i,b[y[i]]);
    }
  }
  vector<pair<ll,ll>>t(n);
  for(auto z:a){
    t[tree.root(z.second)].first++;
  }
  for(auto z:b){
    t[tree.root(z.second)].second++;
  }
  for(i=0;i<n;i++){
    if(t[i].first*t[i].second>0){
      res+=(t[i].first*t[i].second)-tree.size(i);
    }
    //cout<<res<<endl;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void)
{

 int S,h,m,s;

	scanf("%d",&S);
	
	h=S/3600;
	m=S%3600/60;
	s=S%3600%60;

	printf("%d:%d:%d\n",h,m,s);

return 0;
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a+b<=16)
    {
        int c=max(a,b);
        int d=max(a,b);
       if(((16-c-d)+d)<=c)
       {
           if(a!=b)
            printf(":(\n");
           else
             printf("Yay!\n");
       }
       else
        printf("Yay!\n");
    }
    else
    printf(":(\n");
}


Measured memory_bytes: 256
def lower_bound(a, x, index=False):
    from bisect import bisect_left
    i = bisect_left(a, x)
    if (i != len(a)):
        if (index):
            return i
        else:
            return a[i]
    raise ValueError

import sys
import string
s = input()
t = input()
s2 = s*2
lc = string.ascii_lowercase
cd = {}
for c in lc:
    cd[c] = []
for i in range(len(s2)):
    cd[s2[i]].append(i)
p = 0
ans = 0
for c in t:
    if (len(cd[c]) == 0):
        print('-1')
        sys.exit()
    p = lower_bound(cd[c],p)+1
    if (p >= len(s)):
        p -= len(s)
        ans += len(s)
ans += p
print(ans)


Measured memory_bytes: 12536
#include <stdio.h>
int main()
{
	int m,count = 0;
	int i = 0;
	long long n;
	scanf("%lld\n", &n);
	while(n)
	{
		m = n % 10;
		if(m == 9)count++;
		n = n / 10;
		i++;
	}
	if(count == i)
	{
		printf("%d\n",9 * i);
	}
	if(count == i - 1 && m == 9)
	{
		printf("%d\n",9 * i - 1);
	}
	if(count == i - 1 && m != 9)
	{
		printf("%d\n", m + 9 * (i - 1));
	}
	if(count != i - 1 && count != i)
	{
		printf("%d\n", 9 * (i - 1) + m - 1);
	}
	return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    *P, = map(int, input().split())

    mi = N + 1
    ret = 0
    for x in P:
        if mi > x:
            mi = x
            ret += 1

    print(ret)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 32292
h, w = map(int, input().split())
f = [input() for _ in range(h)]

def next(pos):
    x, y = pos
    ret = []
    for dx, dy in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
        i = x + dx
        j = y + dy
        if 0 <= i < h and 0 <= j < w and f[i][j] != '#':
            ret.append((i, j))
    return ret

ans = 0
for i in range(h):
    for j in range(w):
        if f[i][j] != '#':
            s = {(i, j)}
            ng = set()
            dis = 0
            while s:
                t = set()
                for p in s:
                    ng.add(p)
                    for x, y in next(p):
                        if (x, y) not in ng:
                            t.add((x, y))
                s = t
                dis += 1
            ans = max(ans, dis - 1)
print(ans)

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = long.Parse(ReadLine());
			var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();

			var maxLeaf = line.Max();
			long node = 0;
			var nodes = new long[n + 1];
			for(var i = 0; i <= n; i++)
			{
				if(i == 0)
				{
					node = 1;
				}
				else
				{
					if (node >= (long.MaxValue - 100000000) / 2)
					{
						node = long.MaxValue - 100000000;
					}
					else
					{
						node *= 2;
					}
				}
				node -= line[i];

				if (node < 0)
				{
					WriteLine(-1);
					return;
				}

				if (i != n)
				{
					nodes[i] = node + line[i];
				}
				else
				{
					nodes[i] = line[i];
				}
			}

			for(var i = n; i >= 1; i--)
			{
				if(nodes[i - 1] - line[i - 1] > nodes[i])
				{
					nodes[i - 1] = nodes[i] + line[i - 1]; 
				}
			}

			WriteLine(nodes.Sum());
		}
	}
}


Measured memory_bytes: 29660
n = int(input())
H = list(map(int,input().split()))
dp=[10**5 for i in range(n)]
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(n-2):
    dp[i+2]=min(dp[i]+abs(H[i]-H[i+2]),dp[i+1]+abs(H[i+2]-H[i+1]))
print(dp[n-1])


Measured memory_bytes: 20584
n=int(input())
happy=[list(map(int,input().split())) for i in range(n)]
dp=[[0,0,0] for i in range(n)]
for i in range(n):
  if i==0:
    dp[i][0]=happy[0][0]
    dp[i][1]=happy[0][1]
    dp[i][2]=happy[0][2]
  else:
    dp[i][0]=max(dp[i-1][1]+happy[i][0],dp[i-1][2]+happy[i][0])
    dp[i][1]=max(dp[i-1][2]+happy[i][1],dp[i-1][0]+happy[i][1])
    dp[i][2]=max(dp[i-1][0]+happy[i][2],dp[i-1][1]+happy[i][2])
print(max(dp[-1]))

Measured memory_bytes: 47368
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;

void main()
{
  auto s = new string[](3);
  foreach (i; 0..3) {
    s[i] = readln.chomp;
  }

  auto idx = new int[](3);
  int i;
  while (idx[i] < s[i].length) {
    idx[i]++;
    i = s[i][idx[i]-1]-'a';
  }
  writeln(('A'+i).to!char);
}


Measured memory_bytes: 256
s = list(input())
y = int("".join(s[0:4]))
m = int("".join(s[5:7]))
d = int("".join(s[8:10]))

if y > 2019:
    print("TBD")
elif y < 2019:
    print("Heisei")
else:
    if m > 4:
        print("TBD")
    else:
        print("Heisei")

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.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; }

vector<double> p;

vector<vector<double>> table;
double dp(ll n,ll k){
  if(k<=0) return 1;
  if(n<0) return 0;
  if(table.at(n).at(k)>-1) return table.at(n).at(k);
  
  table.at(n).at(k)=0;
  table.at(n).at(k)+=dp(n-1,k);
  if(k>0) table.at(n).at(k)+=(dp(n-1,k-1)-dp(n-1,k))*p.at(n);
  
  return table.at(n).at(k);
}

int main()
{
  ll N; cin>>N;
  p=vector<double>(N); rep(i,N) cin>>p.at(i);
  /*
  rep(i,N){
    if(i!=0) cout<<" ";
    cout<<p.at(i);
  }
  cout<<endl;
  */
  
  //dp
  table=vector<vector<double>>(N,vector<double>(N+1,-1));
  
  cout<<fixed<<setprecision(15)<<dp(N-1,N/2+1)<<endl;
  
  /*
  rep(i,N){
    rep(j,N+1){
      if(j!=0) cout<<" ";
      cout<<dp(i,j);//table.at(i).at(j);
    }
    cout<<endl;
  }
  */
  
  return 0;
}

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

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a > c) swap(a, c), swap(b, d);

	if(b < c) {
		printf("%d\n", 0);
	}else if(d < b) {
		printf("%d\n", d - c);
	}else {
		printf("%d\n", b - c);
	}
	return 0;
}

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

using namespace std;

int dp[101][4][4][4];
int mod = 1000000007;

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

    dp[0][3][3][3] = 1;   
    for(int len=0; len<n; len++){
        for(int c3=0; c3<4; c3++){
            for(int c2=0; c2<4; c2++){
                for(int c1=0; c1<4; c1++){
                    if(dp[len][c3][c2][c1] == 0)continue;
                    for(int plus=0; plus<4; plus++){
                        if(c2==0 && c1==1 && plus==2)continue;
                        if(c2==1 && c1==0 && plus==2)continue;
                        if(c2==0 && c1==2 && plus==1)continue;
                        if(c3==0 && c1==1 && plus==2)continue;
                        if(c3==0 && c2==1 && plus==2)continue;
           
                        dp[len+1][c2][c1][plus] += dp[len][c3][c2][c1];   
                        dp[len+1][c2][c1][plus] %= mod;                     
                    } 
                }    
            } 
        }
    }
    
    int ans = 0;

    for(int c3=0; c3<4; c3++){
        for(int c2=0; c2<4; c2++){
            for(int c1=0; c1<4; c1++){
                ans += dp[n][c3][c2][c1]; 
                ans%=mod;           
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  YES((n+1) / 2 >= k);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int ans=0;
	fx(N/R+1){
		fy(N/G+1){
			if((N-x*R-y*G)>=0&&(N-x*R-y*G)%B==0){
				ans++;

			}
		}
	}
	ce(ans)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=1,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		if(ans>k)
		{
			ans+=k;
		}
		else
		{
			ans+=ans;
		}
	}
	cout<<ans;
	return 0;
}

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

int main() {
  unordered_map<string, int> m;
  int n;
  cin>>n;
  int mx = 0;
  for(int i = 0; i < n; i++){
    string s;
    cin>>s;
    m[s]++;
    mx = max(mx, m[s]);
  }
  vector<string> results;
  for(pair<string, int> p: m){
  	if(p.second == mx){
    	results.push_back(p.first);
    }
  }
  sort(results.begin(), results.end());
  for(string str: results) {
  	cout<<str<<"\n";
  }
}

Measured memory_bytes: 26692
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int l = 0;
    int r = 0;
    ll sum = a[0];
    ll ans = 0;
    for(int l=0; l<n-1; l++){
        while(r<n-1){
            //cout << (sum^a[r+1]) << endl;
            if(sum+a[r+1] == (sum^a[r+1])){
                sum += a[r+1];
                r = r+1;
                //cout << "l=" << l << " r=" << r << " sum=" << sum << endl;
            }else{
                break;
            }
        }
        sum -= a[l];
        ans += r-l;
        //out << "l=" << l << " sum=" << sum << endl;
    }
    cout << ans+n << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.length();
    vector<int> ans(n);
    vector<int> cnt(2);
    int pos = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            cnt[(i - pos) % 2]++;
        } else {
            ans[i] += cnt[(i - pos) % 2];
            ans[i - 1] += cnt[(i - pos + 1) % 2];
            pos = i + 1;
            cnt[0] = cnt[1] = 0;
        }
    }
    pos = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i]  == 'L') {
            cnt[(pos - i) % 2]++;
        } else {
            ans[i] += cnt[(pos - i) % 2];
            ans[i + 1] += cnt[(pos - i + 1) % 2];
            pos = i - 1;
            cnt[0] = cnt[1] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}

Measured memory_bytes: 1104
#include<stdio.h>
int main(){
  int l=0,r,u,d=0,n=0;
  int x,y,a;
  scanf("%d%d%d",&r,&u,&n);
  for(int i=0;i<n;i++){
    scanf("%d%d%d",&x,&y,&a);
    switch(a){
      case 1:
        l=(x>l)?x:l;
        break;
      case 2:
        r=(r>x)?x:r;
        break;
      case 3:
        d=(y>d)?y:d;
        break;
      case 4:
        u=(u>y)?y:u;
        break;
    }
  }
  if(u>d&&r>l) printf("%d\n",(u-d)*(r-l));
  else printf("0\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define dump(x)      cerr << #x << " = " << (x) << endl;

const LL MOD = 1e9 + 7;

inline LL mod_add(LL a, LL b) {
    return (a + b) % MOD;
}

inline LL mod_sub(LL a, LL b) {
    return (a + MOD - b) % MOD;
}

inline LL mod_mul(LL a, LL b) {
    return ((a % MOD) * (b % MOD)) % MOD;
}

LL mod_bipow(LL x, LL y) {   // power using bisection method
    if (y == 0) return 1;
    else if (y == 1) return x % MOD;
    else if (y % 2 == 0) {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(val, val);
    } else {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(mod_mul(val, val), x);
    }
}

LL mod_inv(LL x) {   // compute x^{-1}=x^{MOD-2} (when MOD is a prime number) using Fermat theorem
    return mod_bipow(x, MOD - 2);
}

LL mod_div(LL a, LL b) {   // using a/b=a*b^{-1}
    return mod_mul(a, mod_inv(b));
}

void calcFactorial(LL N, VI& facts, VI& inv_facts) {
    REP(i, N + 1) facts[i] = i == 0 ? 1 : mod_mul(facts[i - 1], i);
    for (LL i = N; i >= 0; i--) inv_facts[i] = i == N ? mod_inv(facts[N]) : mod_mul(inv_facts[i + 1], i + 1);   // (i!)^{-1}=((i+1)!)^{-1}*(i+1)
}

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

    VI facts(N * M + 1);   // k! for k=0,...,n
    VI inv_facts(N * M + 1);   // (K!)^{-1} for k=0,...,n
    calcFactorial(N * M, facts, inv_facts);
    LL ncr = mod_mul(facts[N * M - 2], mod_mul(inv_facts[K - 2], inv_facts[N * M - K]));
    LL ans = 0;
    FOR(d, 1, N) {
        ans = mod_add(ans, mod_mul(d, mod_mul(mod_mul(mod_sub(N, d), M), M)));
    }
    FOR(d, 1, M) {
        ans = mod_add(ans, mod_mul(d, mod_mul(mod_mul(mod_sub(M, d), N), N)));
    }
    ans = mod_mul(ans, ncr);
    cout << ans << endl;
	
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int a,b;
  cin >> a >> b;
  if((a & 1) && (b & 1))cout << "Yes" << endl;
  else cout << "No" << endl;




  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pal(string s)
{
  int n=s.length();
  for(int i=0;i<n/2;i++)
     if(s.at(i)!=s.at(n-1-i))
        return 0;
      return 1;  
}  
int main()
{
  string s;
  cin>>s;
  int n=s.length();
  if(n%2==1 && pal(s)==1 && pal(s.substr(0,n/2))==1)
     cout<<"Yes"<<endl;
  else cout<<"No"<<endl;   
  return 0;
}  


Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, k = map(int, readline().split())
p = list(map(int, readline().split()))

l = [i for i in range(1, 1001)]
av = np.cumsum(l) / l

tmp = [av[i - 1] for i in p]
cs = list(np.cumsum(tmp))

if n == k:
    print(cs[-1])
    exit()
ans = 0
for i in range(n - k):
    ans = max(ans, cs[i + k] - cs[i])
print(ans)

Measured memory_bytes: 52468
str1 = input()
str2 = input()

if str1 == str2:
    print('Yes')

else:
    for i in range(len(str1) - 1):
    
        str1 = str1[-1] + str1[:-1]
    
        if str1 == str2:
            print('Yes')
            break
    
    if str1 != str2:
        print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int H, W; cin >> H >> W;
  int h, w; cin >> h >> w;
  cout << H * W - (h * W + w * H - h * w) << endl;
}


Measured memory_bytes: 256
package main

import "fmt"
import "bufio"
import "strconv"
import "os"

type point struct {
	h, w int
}

func main() {
	all := make(map[point]int)
	hm := make(map[int]int)
	wm := make(map[int]int)
	var h, w, m int
	fmt.Scanf("%d %d %d", &h, &w, &m)
	//ss := h * w
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		sc.Scan()
		hh, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		ww, _ := strconv.Atoi(sc.Text())
		hm[hh]++
		wm[ww]++
		all[point{h: hh, w: ww}]++
	}
	var hi, wi = []int{0}, []int{0}
	h1, w1 := 0, 0
	for i, j := range hm {
		if h1 < j {
			hi = []int{i}
			h1 = j
		} else if h1 == j {
			hi = append(hi, i)
		}
	}
	for i, j := range wm {
		if w1 < j {
			wi = []int{i}
			w1 = j
		} else if w1 == j {
			wi = append(wi, i)
		}
	}
	//fmt.Println(hi)
	//fmt.Println(wi)
	for _, i := range hi {
		for _, j := range wi {
			if !(all[point{h: i, w: j}] > 0) {
				//fmt.Println(i)
				//fmt.Println(j)
				fmt.Println(w1 + h1)
				return
			}
		}
	}
	fmt.Println(w1 + h1 - 1)
}


Measured memory_bytes: 89168
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	int n;
	cin >> n;
	vector<string>s(n);
	map<char, int> m;
	int i;
	rep(i, n) {
		cin >> s[i];
		m[s[i][0]]++;
	}
	ull sum = 0;

	vector<int>b(5, 0);
	vector<char> cc = { 'M', 'A', 'R', 'C', 'H' };
	int d = 0;

	rep(b[0], 2) {
		if (b[0] == 1 && m['M'] == 0)continue;

		rep(b[1], 2) {
			if (b[1] == 1 && m['A'] == 0)continue;
			rep(b[2], 2) {
				if (b[2] == 1 && m['R'] == 0)continue;
				rep(b[3], 2) {
					if (b[3] == 1 && m['C'] == 0)continue;
					rep(b[4], 2) {
						if (b[4] == 1 && m['H'] == 0)continue;
						int ssum = 0;
						int aaa;
						rep(aaa, 5)ssum += b[aaa];

						if (ssum == 3) {
							ull tmp = 1;
							int bbb;
							rep(bbb, 5) if (b[bbb] != 0 && m[cc[bbb]] != 0)tmp *= (ull)b[bbb] * (ull)m[cc[bbb]];
							sum += tmp;
						}
					}
				}
			}
		}
	}
	cout << sum;

	return 0;
}





Measured memory_bytes: 6144
from sys import stdin
import numpy as np
import copy
from itertools import combinations
H,W,K = [int(x) for x in stdin.readline().rstrip().split()]
C = []
for i in range(H):
    c = list(input())
    C.append(c)

ans = 0

for h in range(0,H+1):
    for w in range(0,W+1):
        for i in combinations(range(0,H),h):
            for j in combinations(range(0,W),w):
                tmp = copy.deepcopy(C)
                tmp = np.array(tmp)
                for k in i:
                    tmp[k,] = "."
                for l in j:
                    tmp[:,l] = "."
                if np.sum(tmp == "#") == K:
                    ans += 1
print(ans)

Measured memory_bytes: 27308