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

#define nil NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void transplant(Node,Node);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, a, x;
  char command[20];
  scanf("%d",&n);

  for(a = 0; a < n; a++){
    scanf("%s",command);
    if(command[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t != nil) printf("yes\n");
      else printf("no\n");
    }
    else if(command[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(command[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(command[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}

Node treeMinimum(Node x){
  while(x->left != nil) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != nil) x = x->right;
  return x;
}

Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left,k);
  else return treeSearch(x->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != nil) return treeMinimum(x->right);
  y = x->p;
  while(y != nil && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  if(z->left == nil) transplant(z,z->right);
  else if(z->right == nil) transplant(z,z->left);
  else{
    y = treeMinimum(z->right);
    if(y->p != z){
      transplant(y,y->right);
      y->right = z->right;
      y->right->p = y;
    }
    transplant(z,y);
    y->left = z->left;
    y->left->p = y;
  }
}

void transplant(Node u, Node v){
  if(u->p == nil) root = v;
  else if(u == u->p->left) u->p->left = v;
  else u->p->right = v;
  if(v != nil) v->p = u->p;
}

void insert(int k){
  Node y = nil;
  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->p = y;
  if(y == nil) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

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);
  }
}



Measured memory_bytes: 20452
#include<bits/stdc++.h>
#define int long long
using namespace std;
string lcs(string s,string t){	
	int x=s.size(), y=t.size();
	int arr[x+1][y+1];
	for(int i=0;i<=x;++i){
		for(int j=0;j<=y;++j){
			if(i==0 || j==0)
			arr[i][j]=0;
			else if(s[i-1]==t[j-1])
			arr[i][j]=1+arr[i-1][j-1];
			else 
			arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
		}
	}
	string ret="";
	int i=x,j=y;
	while(i>0 && j>0){
		if(arr[i][j]-arr[i-1][j-1]==1 && s[i-1]==t[j-1]){
			ret+=s[i-1];
			i--; j--;
		}else if(arr[i][j]==arr[i-1][j]){
			i--; 
		}else 
		j--;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
int32_t main(){
  	string p,pp;
  cin>>p>>pp;
  cout<<lcs(p,pp);
  return 0;
	int n; cin>>n;
	int arr[n];
	for(int i=0;i<n;++i)
	cin>>arr[i];
	sort(arr,arr+n);
	int f=arr[n-1];
	int s;
	for(int i=n-2;i>=0;--i){
		int xp=arr[i];
		int l=__gcd(xp,f);
		int pro=xp*f;
		pro/=l;
		if(pro>f){
			s=arr[i];
			break;
		}
	}
	cout<<f<<" "<<s;
	return 0;
}


Measured memory_bytes: 70656
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] m = new int[N];
		for(int i = 0; i <N;i++) {
			m[i] = sc.nextInt();
		}
		int cnt = 1,num = 1;
		for(int j = 0;j<N-1;j++) {
			for(int i = 0; i < num+1;i++) {
				if(m[i] > m[num]) {
					break;
				}else if(i == num-1){
					cnt++;
				}
			}
			num++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23252
import java.util.Scanner;

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

        String s = sc.next();
        
        for (char i = 'a'; i <= 'z'; i++) {
            if (s.indexOf(i) >= 0) {
                continue;
            } else {
                System.out.println(i);
                System.exit(0);
            }
        }
        System.out.println("None");
    }
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  // TODO
  int x;
  cin >> x;
  int a;
  if (400 <= x && x <= 599) a = 8;
  if (600 <= x && x <= 799) a = 7;
  if (800 <= x && x <= 999) a = 6;
  if (1000 <= x && x <= 1199) a = 5;
  if (1200 <= x && x <= 1399) a = 4;
  if (1400 <= x && x <= 1599) a = 3;
  if (1600 <= x && x <= 1799) a = 2;
  if (1800 <= x && x <= 1999) a = 1;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3628
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
t = []

for i in range(x):
    for j in range(y):
        for r in range(z):
            if (i+1)*(j+1)*(r+1) > k:
                break
            else:
                t.append(a[i]+b[j]+c[r])

t.sort(reverse = True)

for i in range(k):
    print(t[i])

Measured memory_bytes: 8708
#include<stdio.h>

int main()
{
	int a = 0;
	char b = 0;
	int c = 0;
	int d = 0;
	int i;
	char s[101];

	scanf("%d", &a);
	scanf("%s", s);

	for (i = 0; i < a; i++) {
		b = s[i];
		if (b == 'B') {
			c++;
		}
		else if (b == 'R') {
			d++;
		}
		else {
			;
		}
	}

	if (d > c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger A[] = new BigInteger[N];
    BigInteger B[] = new BigInteger[N];
    BigInteger two = new BigInteger("2");
 
    for (int i=0; i<=N-1; i++) {
      A[i] = sc.nextBigInteger();
    }
    BigInteger all = new BigInteger("0");
    BigInteger all_a1 = new BigInteger("0");
 
    for(int i=0; i<=N-1; i++){
      all = all.add(A[i]);
    }
    all = all.divide(two);
 
    for(int i=0; i<=N-1; i+=2){
      all_a1 = all_a1.add(A[i]);
    }
 
     B[0] = all_a1.subtract(all);
    for(int i=1; i<=N-1; i++){
      B[i] = A[i-1].subtract(B[i-1]);
    }
 
    for(int i=0; i<=N-1; i++){
      System.out.print(B[i].multiply(two)+" ");
    }
    System.out.println();
  }
}

Measured memory_bytes: 105680
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;

int main() {
	
	int n, x;

	int count = 0;
	int c = 0;
	for (;;) {
		count = 0;
		cin >> n >> x;

		if (n == 0 && x == 0)break;


		for (int i = 1; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)count++;
				}
			}
		}
		printf("%d\n", count);
	}


	//system("pause");
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    multiset <int> ms;
    for(int a,i=0; i<1<<n; i++){
        cin >> a;
        ms.insert(a);
    }

    vector <int> added{*prev(ms.end())};
    ms.erase(prev(ms.end()));
    for(int p=0; p<n; p++){
        for(int i=0; i<(1<<p); i++){
            auto it = ms.lower_bound(added[i]);
            if(it == ms.begin()){
                printf("No\n");
                return 0;
            }
            added.push_back(*prev(it));
            ms.erase(prev(it));
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 13692
package main

import (
	"fmt"
)

func main() {
  
	Bingo()

}

//Bingo 3*3
func Bingo() {

	bingo := make([][]int, 3)

	for x := range bingo {

		bingo[x] = make([]int, 3)
	}

	allkumi := make([][]int, 8)

	for x := range allkumi {
		allkumi[x] = make([]int, 3)
	}

	var N int

	for i := 0; i < 3; i++ {

		for j := 0; j < 3; j++ {

			fmt.Scan(&bingo[i][j])
		}
	}

	fmt.Scan(&N)

	numbers := make([]int, N)

	for n := 0; n < N; n++ {

		fmt.Scan(&numbers[n])
	}

	//横３つ
	for i := 0; i < 3; i++ {

		for j := 0; j < 3; j++ {

			allkumi[i][j] = bingo[i][j]

		}
	}

	//縦３つ
	for i := 0; i < 3; i++ {

		for j := 0; j < 3; j++ {

			allkumi[i+3][j] = bingo[j][i]

		}
	}

	//斜め二つ

	allkumi[6][0] = bingo[0][0]
	allkumi[6][1] = bingo[1][1]
	allkumi[6][2] = bingo[2][2]

	allkumi[7][0] = bingo[0][2]
	allkumi[7][1] = bingo[1][1]
	allkumi[7][2] = bingo[2][0]

	count := 0

	for i := 0; i < 8; i++ {

		count=0

		for j := 0; j < 3; j++ {

			for n := 0; n < N; n++ {

				if allkumi[i][j] == numbers[n] {

					count++
					break
				}
				

			}

		}

		if count == 3 {

			fmt.Println("Yes")

			return
		}

	}

	fmt.Println("No")

}


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

def it(i,n):
    if i == N:
        yield [None]*N
    else:
        for x in range(n):
            for d in it(i+1,n):
                d[i] = x
                yield d
        for d in it(i+1,n+1):
            d[i] = n
            yield d

print(*(''.join(chr(x+ord('a')) for x in d) for d in it(0,0)), sep='\n')



Measured memory_bytes: 13576
var
	n,ans,i,j:Longint;
	c,s,f:array[1..499]of Longint;
begin
	read(n);
	for i:=1 to n-1 do read(c[i],s[i],f[i]);
	for i:=1 to n-1 do begin
		ans:=0;
		for j:=i to n-1 do begin
			if ans<s[j] then ans:=s[j]+c[j]
			else ans:=(ans+f[j]-1)div f[j]*f[j]+c[j];
		end;
		writeln(ans);
	end;
	writeln(0);
end.

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

int n;
int a[3003];
ll dp[3003][3003];

ll find(int l, int r) {
  if (r < l) return 0;
  if (dp[l][r] == -1) {
    if ((r - l) % 2 == (n - 1) % 2) {
      dp[l][r] = max(a[l] + find(l + 1, r), a[r] + find(l, r - 1));
    } else {
      dp[l][r] = min(-a[l] + find(l + 1, r), -a[r] + find(l, r - 1));
    }
  }
  return dp[l][r];
}

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << find(0, n - 1) << '\n';

  return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if ( a<10&&a>0 && b<10&&b>0 && c<10&&c>0)
	{
		if (a==b && a!=c)
	{
		cout << "Yes";
	}
	else if (a==c && a!=b)
	{
		cout << "Yes";
	}
	else if (c==b && c!=a)
	{
		cout << "Yes";
	}
	else
	cout  << "No";
	return 0;
	}
	else
	cout << "No";
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var A int64
    var B int64
    fmt.Scan(&A)
    fmt.Scan(&B)
    if A <= 9 && B <= 9 {
        fmt.Println(A * B)
    } else {
        fmt.Println(-1)
    }
}

Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N;
  while(cin>>N,N){
	VS vs(N);
	REP(i,N) cin >> vs[i];
	int dist[32][32];
	fill((int*)dist, (int*)dist+32*32, 100);

	bool ans = true;
	for(int i=0;i<N;++i)
	  for(int j=i+1;j<N;++j){
		int k;
		for(k=0;k<min(SZ(vs[i]),SZ(vs[j]));++k){
		  if(vs[i][k] != vs[j][k]){
			dist[vs[i][k]-'a'][vs[j][k]-'a'] = 0;
			break;
		  }
		}
		if(k == SZ(vs[j]) && SZ(vs[i]) > SZ(vs[j])) ans = false;
	  }

	REP(k,32) REP(i,32) REP(j,32)
	  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	REP(i,32) if(!dist[i][i]) ans = false;
	
	cout << (ans? "yes": "no") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <set>

using namespace std;

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

  set<int> s;

  bool ans = true;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }

  if (s.size() == n) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif


int main(int argc, char **argv){
	int n;
	std::vector<int> a;
	std::vector<int> p;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	a.resize(n);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> a[i];
#else
		std::cin >> a[i];
#endif
	}

	p = a;
	if(std::prev_permutation(p.begin(), p.end())){
		std::cout << p[0];
		for(int i = 1; i < n; i++){
			std::cout << " " << p[i];
		}
		std::cout << std::endl;
	}
	std::cout << a[0];
	for(int i = 1; i < n; i++){
		std::cout << " " << a[i];
	}
	std::cout << std::endl;

	if(std::next_permutation(a.begin(), a.end())){
		std::cout << a[0];
		for(int i = 1; i < n; i++){
			std::cout << " " << a[i];
		}
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+5

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int n;
vector<double> p;
vector<vector<double>> dp;

double dfs(int index, int h)
{
	if (index == n)
	{
		if (h > n - h) return 1;
		else return 0;
	}
	if (dp[index][h] != -1) return dp[index][h];
	dp[index][h] = p[index] * dfs(index + 1, h + 1) + (1 - p[index]) * dfs(index + 1, h);
	//cout << index << " " << dp[index] << "\n";
	return dp[index][h];
}

int main()
{
	IOS;

	cin >> n;
	p.resize(n);
	dp.resize(n);
	rep(i, 0, n) dp[i].resize(n), fill(all(dp[i]), -1);
	rep(i, 0, n) cin >> p[i];
	cout << fixed;
	cout << setprecision(9);
	cout << dfs(0, 0);

	return 0;
}


Measured memory_bytes: 74328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b[9] = {}, z = 0;
    cin >> n;
    while (n--) {
        cin >> a;
        if (a < 3200) b[a / 400] = 1;
        else b[8]++;
    }
    for (int i = 0; i < 8; i++) z += b[i];
    cout << max(z, 1) << ' ' << z + b[8];
}


Measured memory_bytes: 256
n = int(input())
a = []
b = []
c = []

for _ in range(n):
    x, y, z = [int(e) for e in input().split()]
    a.append(x)
    b.append(y)
    c.append(z)

q, w, r = a[0], b[0], c[0]
for i in range(1, n):
    q, w, r = a[i] + max(w, r), b[i] + max(q, r), c[i] + max(q, w)
ans = max(q, w, r)
print(ans)




Measured memory_bytes: 15000
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int w, h, n;
    cin >> w >> h >> n;

    int x[2] = {0, w}, y[2] = {0, h};
    REP(i, n){
        int a, b, c;
        cin >> a >> b >> c;
        if(c == 1){
            x[0] = max(x[0], a);
        }else if(c == 2){
            x[1] = min(x[1], a);
        }else if(c == 3){
            y[0] = max(y[0], b);
        }else{
            y[1] = min(y[1], b);
        }
    }
    cout << (x[1] > x[0] && y[1] > y[0] ? (x[1] - x[0]) * (y[1] - y[0]) : 0) << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	if (n > 9) {
		cout << "-1" << endl;

	}
	else if (m > 9) {
		cout << "-1" << endl;
	}
	else {
		cout << n * m << endl;
		return 0;
	}
}

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

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

	int cnt = 700;

	if (s[0] == 'o') cnt += 100;
	if (s[1] == 'o') cnt += 100;
	if (s[2] == 'o') cnt += 100;

	cout << cnt << endl;
}

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

int main() {
	int n, k;
	long long l, r;
	cin >> n >> k >> l >> r;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	int n1 = n / 2, n2 = (n - n1);
	
	int coin = 0;
	long long cost = 0, ans = 0;
	vector<vector<long long>> dat(n + 1);
	dat[0].push_back(0);
	
	auto f = [&](int i, long long high, long long low) {
		auto h = upper_bound(dat[i].begin(), dat[i].end(), high);
		auto w = lower_bound(dat[i].begin(), dat[i].end(), low);
		return (h - w);
	};
	
	for (int s = 1; s < (1 << n1); s++) {
		int bit = (s ^ (s >> 1));
		int i = __builtin_ctz(s);
		
		if (bit & (1 << i)) {
			cost += a[i];
			coin++;
		} else {
			cost -= a[i];
			coin--;
		}
		
		if (coin == k and l <= cost and cost <= r) ans++;
		dat[coin].push_back(cost);
	}
	
	cost = 0; coin = 0;
	for (int i = 0; i <= n; i++) {
		sort(dat[i].begin(), dat[i].end());
	}
	
	for (int s = 1; s < (1 << n2); s++) {
		int bit = (s ^ (s >> 1));
		int i = __builtin_ctz(s);
		
		if (bit & (1 << i)) {
			cost += a[n1 + i];
			coin++;
		} else {
			cost -= a[n1 + i];
			coin--;
		}
		
		if (k >= coin) {
			ans += f(k - coin, r - cost, l - cost);
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 12204
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define erep(i, N) for(int i=0; i<=(int)N; i++)
#define mp make_pair
#define pb push_back

// Type
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

// Constants
const int MOD = (int)1e9 + 7;
int dy[] = {0, 1, -1, 0};
int dx[] = {1, 0, 0, -1};

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

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

  p += 3 * a;
  cout << p / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005
ll n,m,x,y;
vi a[N];
ll in[N],mx[N];
ll dfs(ll node){
	if(mx[node]!=0)return mx[node];
	for(auto i:a[node]){
		mx[node]=max(mx[node],1+dfs(i));
	}
	if(a[node].size()==0)return 0;
	return mx[node];
}
int main()
{
	ios
	ll i,j,ans=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>x>>y;
		a[x].pb(y);
		in[y]++;
	}
	for(i=1;i<=n;i++){
		if(in[i]==0)dfs(i);
	}
	//for(i=1;i<=n;i++)cout<<mx[i]<<" ";
	for(i=1;i<=n;i++)ans=max(ans,mx[i]);
		cout<<ans;
	return 0;
}

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

int main()
{
    // 整数の入力
    int N,M;
    cin >> N >> M;

    //高さ入力
    int H[N] = {0};
    for (int i = 0; i < N; i++){
        cin >> H[i];
    }

    set<int> st[N];

    for (int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        st[a-1].insert(b-1);
        st[b-1].insert(a-1);
    }

    //接続展望台リスト作成
    // for (int i = 0; i < N; i++){
    //     for (auto itr = st[i].begin(); itr != st[i].end(); ++itr) {
    //         cout << *itr + 1 << endl;
    //     }
    //     cout << "------------" << endl;
    // }

    //良い展望台判定
    int count = 0;
    int other_max[N] = {0};  
    for (int i = 0; i < N; i++){
        for(auto itr = st[i].begin(); itr != st[i].end(); ++itr) {
            other_max[i] = max(H[*itr],other_max[i]);
        }

        if(H[i] > other_max[i]){
            count++;
        }
        //cout << other_max[i] << endl;
        //cout << "------------" << endl;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 18360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

int main()
{
  ll S, W;
  cin >> S >> W;
  (S <= W) ? cout << "unsafe" << "\n" : cout << "safe" << "\n";
}


Measured memory_bytes: 3572
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int n, k, a[maxn], dp[maxn], t, q;

void solve(){    
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	dp[2] = abs(a[2] - a[1]);

	for (int i = 3; i <= n; i++){
		dp[i] = dp[i - 1] + abs(a[i - 1] - a[i]);
		for (int j = 2; j <= k && i - j > 0; j++)
			dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
	}
	cout << dp[n];
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

Measured memory_bytes: 3072
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,m;
    cin >> n >> m;
    vector<ll>a[3];
    rep(i,3)a[i].resize(n);
    rep(i,n)rep(j,3)cin >> a[j][i];
    ll ans = 0;
    for(int x:{-1,1}){
        for(int y:{-1,1}){
            for(int z:{-1,1}){
                multiset<ll,greater<ll>>st;
                rep(i,n){
                    st.insert(a[0][i]*x+a[1][i]*y+a[2][i]*z);
                }
                auto it = st.begin();
                ll temp = 0;
                rep(i,m){
                    temp+=*it;
                    it++;
                }
                ans = max(ans,temp);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt4 = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      cnt4++;
    } else if (a % 2 == 0) {
      cnt2++;
    }
  }
  if ((cnt4 * 2 + cnt2 / 2 * 2) + 1 >= n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define SZ(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define MP make_pair
#define PB push_back

int a[2000],b[2000];
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
	//if(n<m)swap(n,m);
	int sum=0;
	bool used[2000]= {0};
	REP(i,2000)a[i]=b[i]=0;
	REP(i,n)cin>>a[i];
	REP(i,m){
	cin>>b[i];
	sum+=b[i];
	}
	sort(a,a+n);
	sort(b,b+m);
	for(int i=0;i<m;i++){
		int now=b[i];
		for(int j=0;j<n;j++){
			if(now==a[j]&&used[j]==0){used[j]=1;break;}
		}
	}
	for(int i=0;i<n;i++)if(used[i]==0)sum+=a[i];
	cout<<sum<<endl;
	
	}

	return 0;
} 

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  int sum=1;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==0)sum*=2;
    else sum*=1;
  }
  cout<<pow(3,n)-sum<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int h, w, cnt[26]{}, b[3]{};
    bool used[105][105]{}, ok = true;;
    cin >> h >> w;
    REP(i,h){
        string a;
        cin >> a;
        REP(j,w){
            cnt[a[j]-'a']++;
        }
    }

    b[0] = (h%2)*(w%2);
    b[1] = (h/2)*(w%2) + (w/2)*(h%2);
    b[2] = (h/2)*(w/2);

    REP(i,26){
        if(cnt[i]%2){
            if(b[0]==0){
                ok = false;
                break;
            }
            cnt[i]--;
            b[0]--;
        }
    }
    REP(i,26){
        if(cnt[i]%4){
            if(b[1]==0){
                ok = false;
                break;
            }
            cnt[i]-=2;
            b[1]--;
        }
    }

    cout << (ok?"Yes":"No") << endl;

    return 0;
}

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int N,K;
  int out;
  cin >> N >> K;
  int temp = K;
  int count = 1;;
  while(1){
    if( N >= temp ){
     temp *= K; 
      ++count;
    }else{
     break;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int , input().split())
a = []
b = []
cnt = 0
for i in range(n):
    atem, btem = map(int , input().split())
    a.append(atem)
    b.append(btem)
c = list(zip(a, b))
c.sort()
a, b = zip(*c)
for i in range(n):
    cnt += b[i]
    if cnt >= k:
        print(a[i])
        break


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

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

  in(int, a, b);
  int c = b - a;
  out(c * (c - 1) / 2 - a);
}


Measured memory_bytes: 3512
import qualified Data.ByteString.Char8 as C
import qualified Data.IntMap.Strict as M
import Data.List
import Data.Maybe

main = sol <$> get >>= print

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents 

sol ([_,k]:ab) = fst . fromJust . find ((k<=) . snd)
  . scanl1 (\(a,b) (a',b') -> (a',b+b')) . M.toAscList
  . M.fromListWith (+) $ (\[a,b] -> (a,b)) <$> ab

Measured memory_bytes: 18044
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const int MAX_N = int(1e5) + 10;

int N;
int h[MAX_N];
int dp[MAX_N];

int main()
{
  cin >> N;
  REP(i,0,N) cin >> h[i];

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  REP(i,2,N) {
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]),
                dp[i-1] + abs(h[i]-h[i-1]));
  }

  // 添字ずれ
  cout << dp[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N;
int A[5];

signed main()
{
	cin >> N;
	rep(i, 5) cin >> A[i];

	int mn = LLONG_MAX/3;
	rep(i, 5) chmin(mn, A[i]);

	cout << 4 + (N + mn - 1) / mn << endl;
}




Measured memory_bytes: 256
L=[]
K,X=map(int,input().split())
if X-(K-1)<=-1000000:
  S=-1000000
  for i in range(S,S+(K*2-1)):
    L.append(str(i))
  print(" ".join(map(str,L)))
elif X+(K-1)>=1000000:
  E=1000000
  for i in range(E,E-(K*2-1),-1):
    L.append(str(i))
  print(" ".join(map(str,L)))
else:
  S=X-(K-1)
  for i in range(S,S+(K*2-1)):
    L.append(str(i))
  print(" ".join(map(str,L)))

Measured memory_bytes: 38384
//
// Created by 11297 on 2018/11/11.
//

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

static const int MAX = 200005;

int a[MAX];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int maxv = -2000000000;
    int minv = a[0];
    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, a[i] - minv);
        minv = min(minv, a[i]);
    }
    cout << maxv << endl;
    return 0;
}





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

int N, Q, t;
long long res;
int parent[100010];
bool mark[100010];
string op;

int main()
{
    while(cin >> N >> Q && N)
    {
        res = 0;
        fill_n(mark, 100010, false);
        mark[1] = true;
        for(int i = 2; i <= N; ++i)
        {
            cin >> t; parent[i] = t;
        }
        for(int i = 0; i < Q; ++i)
        {
            cin >> op >> t;
            if(op == "M")
                mark[t] = true;
            if(op == "Q")
            {
                while(!mark[t]) t = parent[t];
                res += t;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1408
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = list(s())
T = list(s())
if S == T:
    print('No')
    exit()
S.sort()
T.sort(reverse=True)
for i in range(min(len(S),len(T))):
    if ord(S[i]) > ord(T[i]):
        print('No')
        exit()
    if ord(S[i]) < ord(T[i]):
        print('Yes')
        exit()
if len(S) > len(T):
    print('No')
else:
    print('Yes')

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

int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if ( x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3100
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    ans = 0
    S_rev = S[::-1]
    kuriage = 0
    for i, s in enumerate(S_rev):
        if i == len(S) - 1:
            if int(s) == 9 and kuriage == 1:
                ans += 1
            elif int(s) + kuriage >= 6:
                ans += 10 - int(s) - kuriage + 1
            else:
                ans += int(s) + kuriage
        else:
            if int(s) == 9 and kuriage == 1:
                continue
            if int(s) + kuriage >= 6:
                ans += 10 - int(s) - kuriage
                kuriage = 1
            elif int(s) + kuriage == 5 and int(S_rev[i + 1]) >= 5:
                ans += 10 - int(s) - kuriage
                kuriage = 1
            else:
                ans += int(s) + kuriage
                kuriage = 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5492
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

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

	REP(i, m) {
		string str;
		set<string> trains;

		cin >> str;

		int size = str.size();

		FOR(j, 1, size) {
			string str1, str2;

			str1 = str.substr(0, j);
			str2 = str.substr(j);

			string rstr1, rstr2;

			FOR(k, 0, str1.size()) {
				rstr1 += str1[str1.size()-k-1];
			}

			FOR(k, 0, str2.size()) {
				rstr2 += str2[str2.size()-k-1];
			}

			string train[8];

			train[0] = str1 + str2;
			train[1] = str1 + rstr2;
			train[2] = rstr1 + str2;
			train[3] = rstr1 + rstr2;
			
			train[4] = str2 + str1;
			train[5] = str2 + rstr1;
			train[6] = rstr2 + str1;
			train[7] = rstr2 + rstr1;

			FOR(k, 0, 8) {
				trains.insert(train[k]);
			}
		}
		
		cout << trains.size() << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int main(){
  int n,i;
  int num;
  char chr[2];
  bool s[13],h[13],c[13],d[13];

  for(i=0;i<13;i++){
    s[i]=true;
    h[i]=true;
    c[i]=true;
    d[i]=true;
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",chr,&num);
    if(chr[0]=='S') s[num-1]=false;
    if(chr[0]=='H') h[num-1]=false;
    if(chr[0]=='C') c[num-1]=false;
    if(chr[0]=='D') d[num-1]=false;
  }

  for(i=0;i<13;i++){
    if(s[i]==true) printf("S %d\n",i+1);
  }
  for(i=0;i<13;i++){
    if(h[i]==true) printf("H %d\n",i+1);
  }
  for(i=0;i<13;i++){
    if(c[i]==true) printf("C %d\n",i+1);
  }
  for(i=0;i<13;i++){
    if(d[i]==true) printf("D %d\n",i+1);
  }

  return 0;
}


Measured memory_bytes: 2096
s[9],c[9];main(n,m,b){for(;scanf("%d%d",&m,&n)*m;){int q[1024]={0},i,t,p=m;for(t=i=1;i<=n;i++){scanf("%s",s,*c=0);i%3||strcat(c,"Fizz");i%5||strcat(c,"Buzz");*c||sprintf(c,"%d",i);for(strcmp(s,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);}for(t=i=1;i<=m;i++)q[i]||(t=!printf(" %d"+t,i));puts("");}}

Measured memory_bytes: 632
#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 n;
    string s;
    cin >> n >> s;
    string ans;
    rep(i, n){
        if(i == 0){
            ans.push_back(s[i]);            
        }else{
            if(s[i] != s[i - 1]){
                ans.push_back(s[i]);
            }
        }
    }
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m,u[N][N],d[N][N],l[N][N],r[N][N];
char s[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        if(s[i][j]=='.')
        {
            u[i][j]=u[i-1][j]+1;
            l[i][j]=l[i][j-1]+1;
        }
    }
    for(int i=n;i>=1;i--)
        for(int j=m;j>=1;j--)
            if(s[i][j]=='.')
        {
            d[i][j]=d[i+1][j]+1;
            r[i][j]=r[i][j+1]+1;
        }
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        if(s[i][j]=='.')
        {
            ans=max(ans,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3);
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 66944
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>

int main(void){
    int K, S;
    scanf("%d %d", &K, &S);
    int x, y, z;
    int count = 0;
    for(x=0; x<=K; x++) {
        for(y=x; y<=K; y++) {
            for(z=y; z<=K; z++) {
                if(x + y + z == S) {
                    if(x==y && y==z) {
                        count++;
                    }
                    else if((x!=y || y!=z) && ((x==y && y!=z) || (y==z && x!=y))) { 
                        count +=3;
                    }
                    else {
                        count +=6;
                    }
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//入力
		String a = sc.next();
		String b = sc.next();
		//設定
		String h = "H";
		String d = "D";
		//出力
		if(a.equals(h) && b.equals(h)){
			System.out.println(h);
		}else if(a.equals(h) && b.equals(d)){
			System.out.println("D");
		}else if(a.equals(d) && b.equals(h)){
			System.out.println("D");
		}else if(a.equals(d) && b.equals(d)){
			System.out.println("H");
		}else{
			
		}
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int N;
long P=0,S=0,m=1e9+7;
main()
{
    cin>>N;
    long S=0;
    for(int i=0;i<N;++i){
        long a;cin>>a;
        P=(P+a*S)%m;
        S=(S+a)%m;
    }
    cout<<P<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    bool exist_odd = false;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    while (true)
    {
        for (int i = 0; i < n; i++)
        {
            if (a[i] % 2 == 0)
            {
                a[i] /= 2;
            }
            else
            {
                exist_odd = true;
            }
        }
        if (exist_odd)
        {
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a[1000],i,x;
	while(1){
		scanf("%d",&n);
		if(n==-1) break;
		x=0;
		while(n>3){
			a[x]=n%4;
			n/=4;
			x++;
		}
		printf("%d",n);
		for(i=x-1;i>=0;i--) printf("%d",a[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2700
#include <iostream>
#include <cmath>

static bool sieve[100000];

int main()
{
    long long n;
    std::cin >> n;
    long long size = std::sqrt(n) + 2;
    long long p = 2;
    std::cout << n << ":";
    while(n!=1&p<size){
        while(n%p==0){
            n/=p;
            std::cout << " " << p;
        }
        for(long long i=p*2;i<size;i+=p){
            sieve[i]=true;
        }
        long long cp = p;
        for(long long i=p+1;i<size;i++){
            if(!sieve[i]){
                 p = i;
                 break;
            }
        }
        if(cp==p){
            break;
        }
    }
    if(n!=1){
        std::cout << " " << n;
    }
    std::cout << "\n";
    return 0;
}



Measured memory_bytes: 3140
import java.util.concurrent.LinkedBlockingQueue


fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val (n, q) = intList()
    class Vertex(val myNumber: Int) {
        private var connectedNode: MutableList<Vertex> = mutableListOf()
        private var count: Long = 0L
        fun addConnectedNode(v: Vertex) {
            connectedNode.add(v)
        }
        fun connectedNode() = connectedNode

        fun addCount(c: Long) {
            count += c
        }
        fun count() = count
    }

    val v = Array(n) { Vertex(it) }
    repeat(n - 1) {
        val (a, b) = intList()
        v[a - 1].addConnectedNode(v[b - 1])
        v[b - 1].addConnectedNode(v[a - 1])
    }
    repeat(q) {
        val (p, x) = intList()
        v[p - 1].addCount(x.toLong())
    }
    val counts = Array(n) { 0L }
    val visited = Array(n) { false }
    val queue = LinkedBlockingQueue<Vertex>()
    queue.offer(v.first())
    while (queue.isNotEmpty()) {
        val vv = queue.poll()
        val count = vv.count()
        counts[vv.myNumber] = count
        visited[vv.myNumber] = true
        vv.connectedNode().forEach {
            if (!visited[it.myNumber]) {
                it.addCount(count)
                queue.offer(it)
            }
        }
    }
    println(counts.joinToString(" "))
}


Measured memory_bytes: 99040
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,k=parseMap(split(readline()))
    s=chomp(readline())
    print(s[1:k-1])
    print(lowercase(s[k]))
  	print(s[k+1:n])
end
main()

Measured memory_bytes: 108032
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main() {
ll N, Q;cin >> N >> Q;
string S;cin >> S;
vector<pair<ll, ll>> range(Q);
vector<ll> V;

rep(i, 0, Q)cin >> range[i].first >> range[i].second;

rep(i, 1, N){
if(S[i - 1] == 'A' && S[i] == 'C')V.push_back(i - 1);
}

if(V.empty()){
rep(i, 0, Q)cout << 0 << endl;
exit(0);
}

for(auto x : range){
ll l = 0, r  = V.size() - 1;

if(x.second - 1 <= V[0] || x.first - 1 >= V[r] + 1){
cout << 0 << endl;continue;}

    while(V[l] < x.first - 1){
    l++;
    }

    while(V[r] + 1 > x.second - 1){
    r--;
    }

cout <<  r - l + 1 << endl;

}


}

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

#define ll long long
#define ld long long
#define pi 3.14159265359

int main() {
    ll A, B, N; cin >> A >> B >> N;
    ll m;
    if (N < B) {
        m = (A * N) / B - A * (N / B);
    }
    else {
        m = (A * (B - 1)) / B - A * ((B - 1) / B);
    }
    cout << m << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	for( int i = 0; i < n; ++i ){
		cin >> a.at(i);
	}
	a.at(n) = -1;
	int cnt = 0;
	int ans = 0;
	for( int i = 1; i <= n; ++i ){
		if( a.at(i-1) == a.at(i) ){
			cnt++;
		} else {
			ans += ceil((double)cnt/2.0);
			cnt = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(0)
#define pb push_back
#define mp make_pair
using namespace std ;
typedef long long ll ;
typedef pair<int,int> pii ;

int main(){
    ll a,b,c,d ;
    cin >> a >> b >> c >> d ;
    cout << max(a*c,max(a*d,max(b*c,b*d))) ;
    return 0;
}



Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long int

typedef struct{
	ll a;
	ll b;
} data;//data型を作成

int compare(const void *x, const void *y){
	return (((data*)x)->a - ((data*)y)->a);
}//data型のポインタのメンバaのこと


int main(void){
	int n,m,i;
	scanf("%d %d",&n,&m);
	ll ans=0;
	data d[n];
	for(i=0;i<n;i++)scanf("%lld %lld",&d[i].a,&d[i].b);
	
	qsort(d, n, sizeof(data), compare);
	i=0;
	while(m>0){
		if(m>d[i].b){
			ans += d[i].a*d[i].b;
			m -= d[i].b;
		}else{
			ans += d[i].a * m;
			break;
		}
		i++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3324
use std::io;

fn is_beautiful(s: &str) -> bool {
    let cnts = count_occurences(s);
    is_beautiful_occurences(cnts)
}

fn count_occurences(s: &str) -> Vec<usize> {
    let mut cnts = vec![0; 26];
    for b in s.as_bytes() {
        cnts[(b - 97) as usize] += 1;
    }
    cnts
}

fn is_beautiful_occurences(cnts: Vec<usize>) -> bool {
    for c in cnts {
        if c % 2 != 0 {
            return false;
        }
    }
    true
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let s = input.split_whitespace().next().unwrap();
    if is_beautiful(s) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352