akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	class Node {
		int p = -1, l, r;
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++)
			nodes[i] = new Node();
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			int l = Integer.parseInt(st.nextToken());
			int r = Integer.parseInt(st.nextToken());
			nodes[id].l = l;
			nodes[id].r = r;
			if (l != -1)
				nodes[l].p = id;
			if (r != -1)
				nodes[r].p = id;
		}
		reader.close();

		int rootId = -1;
		for (int i = 0; i < n; i++) {
			if (nodes[i].p == -1) {
				rootId = i;
				break;
			}
		}
		System.out.println("Preorder");
		preOrderItr(nodes, rootId);
		System.out.println();

		System.out.println("Inorder");
		inOrderItr(nodes, rootId);
		System.out.println();

		System.out.println("Postorder");
		postOrderItr(nodes, rootId);
		System.out.println();
	}

	private void preOrderItr(Node[] nodes, int rootId) {
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(rootId);
		while (!stack.isEmpty()) {
			int cur = stack.pop();
			System.out.print(" " + cur);
			if (nodes[cur].r != -1)
				stack.push(nodes[cur].r);
			if (nodes[cur].l != -1)
				stack.push(nodes[cur].l);
		}
	}

	private void inOrderItr(Node[] nodes, int rootId) {
		Stack<Integer> stack = new Stack<Integer>();
		int cur = rootId;
		while (cur != -1 || !stack.isEmpty()) {
			while (cur != -1) {
				stack.push(cur);
				cur = nodes[cur].l;
			}
			cur = stack.pop();
			System.out.print(" " + cur);
			cur = nodes[cur].r;
		}
	}


	private void postOrderItr(Node[] nodes, int rootId) {
		Stack<Integer> stack = new Stack<Integer>();
		int lastNodeVisited = -1;
		int cur = rootId;
		while (cur != -1 || !stack.isEmpty()) {
			if (cur != -1) {
				stack.push(cur);
				cur = nodes[cur].l;
			} else {
				int peekId = stack.peek();
				if (nodes[peekId].r != -1 && lastNodeVisited != nodes[peekId].r) {
					cur = nodes[peekId].r;
				} else {
					System.out.print(" " + peekId);
					lastNodeVisited = stack.pop();
				}
			}
		}
	}
	
//	private void preOrder(Node[] nodes, int u) {
//		if (u == -1)
//			return;
//		System.out.print(" " + u);
//		preOrder(nodes, nodes[u].l);
//		preOrder(nodes, nodes[u].r);
//	}	
//	private void inOrder(Node[] nodes, int u) {
//		if (u == -1)
//			return;
//		inOrder(nodes, nodes[u].l);
//		System.out.print(" " + u);
//		inOrder(nodes, nodes[u].r);
//	}
//	private void postOrder(Node[] nodes, int u) {
//		if (u == -1)
//			return;
//		postOrder(nodes, nodes[u].l);
//		postOrder(nodes, nodes[u].r);
//		System.out.print(" " + u);
//	}	
}



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

int bubbleSort(int* A, int N){

  bool flag = true;
  int count = 0;

  while(flag){
    flag = false;

    for(int i = N-1; i > 0; i--){
      if(A[i] < A[i-1]){
        int tmp = A[i];
        A[i] = A[i-1];
        A[i-1] = tmp;
        flag = true;
        count++;
      }
    }
  }

  return count;

}

void showA(int *A, int N){

  for(int i = 0; i < N; i++){
    if(i < N-1)
      std::cout << A[i] << ' ';
    else
      std::cout << A[i] << std::endl;
  }

  return;

}


int main(){
  int* A;
  int N;

  std::cin >> N;

  A = (int*)malloc(sizeof(int) * N);

  for(int i = 0; i < N; i++){
    std::cin >> A[i];
  }

  int c = bubbleSort(A, N);

  showA(A, N);
  std::cout << c << std::endl;

  return 0;
}

Measured memory_bytes: 3096
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)

int main(void)
{
	int n, m;
	scanf("%d%d", &n, &m);
	if(n==m) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    string s;
    cin >> s;

    int n = s.size();

    for (int i = 0; i < n; i++) {
        if (s[i] != s[n - 1 - i]) {
            cout << "No\n";
            return 0;
        }
    }

    int h = n / 2;

    for (int i = 0; i < h; i++) {
        if (s[i] != s[h - 1 - i]) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;   
}   

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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in();
    vector<double> v(n);
    for (int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    double pl=(v[0]+v[1])/2;
    for (int i=2;i<n;i++) pl=(pl+v[i])/2;
    cout << pl << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)


int main() {
  string s; cin >> s;
  int n = s.size();
  ll ans = 0;
  loop(i,0,n) {
    ans += (s[i]-'0');
  }
  if (ans%9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(void){
    string s;
    cin >> s;
    int pointA,pointZ;
    int N=s.size();
    for (int i=0;i<N;i++){
        if (s[i]=='A'){
            pointA =i;
            break;
        }
    }
    for (int j=N-1;j>0;j--){
        
        if (s[j]=='Z'){
            
            pointZ =j;
            break;
        }
    }
    cout<<pointZ-pointA+1<<endl;
    return 0;

}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0, m = 0;
    cin >> n >> m;
    priority_queue<ll> que;
    ll tmp = 0;
    for (int i=0; i<n; i++) {
        cin >> tmp;
        que.push(tmp);
    }
    for (int i=0; i<m; i++) {
        tmp = que.top();
        que.pop();
        if (tmp == 0) {
            break;
        }
        tmp /= 2;
        que.push(tmp);
    }
    ll ans = 0;
    while (!que.empty()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin >> n >> m;

	vector<edge> es[n];
	int a,b,c;
	for(int i=0;i<m;i++){
		cin >> a >> b >> c;
		a--;b--;
		es[a].push_back({b,-c});
	}

	ll d[n]={};
	for(int i=1;i<n;i++){
		d[i] = LINF;
	}

	edge e;
	bool update=true;
	int num=0;
	ll ans;
	while(update){
		update=false;
		for(int i=0;i<n;i++){
			if(d[i]==LINF) continue;
			for(int j=0;j<es[i].size();j++){
				e = es[i][j];
				if(d[e.to] > d[i]+e.cost){
					d[e.to]=d[i]+e.cost;
					update=true;
				}
			}
		}
		num++;
		if(num==n-1) ans=d[n-1];
		else if(num==n*2){
			if(ans == d[n-1]) break;
			cout << "inf\n";
			return 0;
		}
	}
	cout << -d[n-1] << "\n";
				
	return 0;
}

Measured memory_bytes: 384
/*
    Problem 20
    https://atcoder.jp/contests/abc077/tasks/arc084_a
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll candidateA = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll candidateC = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        candidateC = N - candidateC;
        ans += candidateA * candidateC;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1408
k= int(input())

if k % 2 == 0 or k % 5 == 0:
    print("-1")
    
else:
    ans = len(str(k))
    s = int(str(7)* ans)
    while True:
        if s % k == 0:
            print(ans)
            break
        else:
            s = (s % k)*10 + 7
            ans += 1

Measured memory_bytes: 9104
N = int(input())
a_list = []
for _ in range(N):
    a_list.append(int(input()))

iindex = 1
count = 0
for n in range(N):
    if iindex == 2:
        print(count)
        break
    elif count >= N - 1:
        print(-1)
    else:
        count += 1
        iindex = a_list[iindex - 1]





Measured memory_bytes: 7084
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b,t;
    cin >> a >> b >> t;
    
    pr((t/a) * b);

}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int n, k;
int t[100000];
int check(ll p)
{
    int i = 0;
    rep(j, k)
    {
        ll sum = 0;
        while (sum + t[i] <= p)
        {
            sum += t[i];
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

int main()
{

    cin >> n >> k;

    rep(i, n) cin >> t[i];

    ll left = 0, right = 100000 * 10000 + 1, mid;

    while (right - left > 0)
    {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v == n)
            right = mid;
        else if (v < n)
            left = mid + 1;
    }

    OP(left);

    return 0;
}


Measured memory_bytes: 3512
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

int main(){
	char Data[20010];
	int height[20010];
	int height_max[20010];
	scanf("%s",Data);
	queue<int> Ans;
	int len = strlen(Data);
	int h = 0,Max_h = 0;
	height[len] = 0;
	height_max[len] = 0;
	for(int i = len-1; i >= 0; --i){
		switch(Data[i]){
			case '\\':
				h++;
				break;
			case '/':
				h--;
				break;
			case '_':
				break;
			default:
				break;
		}
		height[i] = h;
		Max_h = max(Max_h,h);
		height_max[i] = Max_h;
	}

	int area = 0, n = 0;
	int p = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0;
	bool flag;
	for(int i = 0; i < len + 1; ++i){
		flag = true;
		if (height_max[i+1] < height[i]){
			p = 0;
			flag = false;
		}
		// cout << (flag?1:0);
		if(flag){
			switch(height[i]-height[i+1]){
				case 1:
					// tmp2++;
					p++;
					break;
				case -1:
					// tmp3++;
					p--;
					break;
				case 0:
					break;
				default:
					break;
			}
			if(p > 0){
				tmp1 += p;
			}
			if(p == 0){
				if(tmp1!=0){
					n++;
					area += tmp1;
					Ans.push(tmp1);
				}
				tmp1 = 0;
				// tmp2 = 0;
				// tmp3 = 0;
			}
			if(p < 0){
				p = 0;
				tmp1 = 0;
				// tmp2 = 0;
				// tmp3 = 0;
			}
			// cout << p << " ";
		}
	}
	cout << area << endl << n;
	while(!Ans.empty()){
		cout << " " <<Ans.front();
		Ans.pop();
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1388
n=int(input())
arr=[list(input()) for _ in range(n)]
ans=0
for k in range(n):
  flag=True
  for i in range(1,n//2+1):
    for j in range(n):
      if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
        flag=False
        break
    if flag==False:
      break
  else:
    ans+=n
print(ans)

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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 2e3 + 5;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

int n , m;
int a[N];

void solve(int cs){
    scanf("%d " , &n);
    for(int i = 0 ; i < n ; i ++){
            scanf("%d" , &a[i]);
    }
    sort(a , a + n);

    ll ans = 0;
    for(int i = 0 ; i < n ; i ++){
            for(int j = i + 1 ; j < n ; j ++){
                    int mn = abs(a[i] - a[j]);
                    int mx = a[i] + a[j];

                    int L = upper_bound(a , a + n , mn) - a;
                    int R = lower_bound(a , a + n , mx) - a - 1;

                    int add = R - L + 1;
                    if(i >= L && i <= R)add --;
                    if(j >= L && j <= R)add --;

                    ans += 1ll * max(add , 0);
            }
    }

    printf("%lld\n" , ans / (1ll * 3));
}

main(){

    int t = 1;
    //scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    for(int i = 0; i < H; i++){
      String str = sc.next();
      System.out.println(str);
      System.out.println(str);
    }
  }
}

Measured memory_bytes: 25172
#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
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();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int M, vector<int>& a) {
    ll answer = 1;
    ll prevprev = 1, prev = a.empty() || a[0] != 1 ? 1 : 0;
    int index = 0;
    REP(i,2,N+1) {
        while (index < M && a[index] < i) {
            index++;
        }
        answer = (prevprev + prev) % MOD;
        if (index < M && a[index] == i) answer = 0;
        prevprev = prev;
        prev = answer;
    }

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, M;
    cin >> N >> M;
    
    vector<int> a(N);
    REP(i,0,M) cin >> a[i];
    
    solve(N, M, a);

    return 0;
}



Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(N-1):
    if A[i] == A[i+1]:
        for j in range(i+2, N-1):
            if A[j] == A[j+1]:
                print(A[i]*A[j])
                exit()
else:
    print(0)


Measured memory_bytes: 85388
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        System.out.println(solve(a, b, K));

        sc.close();
    }

    static int solve(int[] a, int[] b, long K) {
        int[] sortedIndices = IntStream.range(0, a.length).boxed().sorted((i1, i2) -> Integer.compare(a[i1], a[i2]))
                .mapToInt(x -> x).toArray();
        for (int i = 0;; ++i) {
            int sortedIndex = sortedIndices[i];
            if (b[sortedIndex] >= K) {
                return a[sortedIndex];
            }

            K -= b[sortedIndex];
        }
    }
}

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

int gcd(int a,int b){
  if(b==0){
    return a;
  }

  return gcd(b,a%b);
}

int main(){
  int W,H,C;

  cin >> W >> H >> C;

  int g=gcd(W,H);
  int ans=(W*H)/(g*g);

  cout << ans*C << endl;

  return 0;
}



Measured memory_bytes: 3100
s = []
for i in range(5):
    s.append(int(input()))
s1 = [str(e)[-1] for e in s]
s2 = [int(e) if e != '0' else 10 for e in s1]
time_min = s2.index(min(s2))
s_min = s.pop(time_min)
s3 = [-(-e//10)*10 for e in s]
result = sum(s3) + s_min
print(result)

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

menu = [a, b, c, d, e]

mintime = 9
minindex = 4
for i, m in enumerate(menu):
    if m % 10 == 0:
        continue

    if m % 10 < mintime:
        minindex = i
        mintime = m % 10

ans = menu[minindex]
for i, m in enumerate(menu):
    if i == minindex:
        continue
    if m % 10 != 0:
        m += 10 - m % 10
    ans += m

print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N;
ll A[100100];
bool X, Y, Z;

ll dfs(int i, ll x, ll y, ll z){
    if(i == N){
        return 1;
    }

    ll a = A[i];
    int num = 0;
    bool update = false;
    ll ret = 0;

    if(a == 0 && x == 0){
        X = true;
        return dfs(i+1, x+1, y, z);
    }
    if(a == 0 && y == 0){
        Y = true;
        return dfs(i+1, x, y+1, z);
    }
    if(a == 0 && z == 0){
        Z = true;
        return dfs(i+1, x, y, z+1);
    }

    if(x == a){
        num++;
        X = true;
        if(!update){
            ret = dfs(i+1, x+1, y, z);
            update = true;
        }
    }
    ret %= MOD;

    if(y == a){
        num++;
        Y = true;
        if(!update){
            ret = dfs(i+1, x, y+1, z);
            update = true;
        }
    }
    ret %= MOD;

    if(z == a){
        num++;
        Z = true;
        if(!update){
            ret = dfs(i+1, x, y, z+1);
            update = true;
        }
    }
    ret %= MOD;

    ret *= num;
    ret %= MOD;
    return ret;
}

int main(){
    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    ll ans = 0;
    //if(A[0] == 0)
    ans = dfs(0, 0, 0, 0);
    //else{
    //    cout << 0 << endl;
    //    return 0;
    //}
    //cout << ans << endl;

    int num = 0;
    if(X) num++;
    if(Y) num++;
    if(Z) num++;

    if(num == 1){
        ans *= 3;
    }
    else if(num == 2)
        ans *= 6;
    else if(num == 3)
        ans *= 6;

    cout << ans%MOD << endl;
    return 0;
}


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

int pnjg, j;
string normal1, normal2, kebalik1, kebalik2;

int main (){
	cin>>normal1>>normal2; 	//yey input
	for (int i=2; i>=0; i--){  //yey dibalik
		kebalik2+=normal1[i];
		kebalik1+=normal2[i];
	}
	if (kebalik1==normal1 && kebalik2==normal2){ //yey dicek
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

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

#define bb      begin()
#define ee      end()
#define ff      first
#define ss      second
#define pb      push_back
#define pf      push_front
#define popb    pop_back()
#define popf    pop_front()
#define mem(a , v)    memset(a , v , sizeof(a))

typedef long long ll;
typedef long double ld;

using namespace std;

const int BIG = 1e5+9;
const int INF = 1e9+9;
const ll BINF = 1e18+9;
const double SML = (1e-7);

string a;

int main()
{
    //freopen("output.txt" , "w" , stdout);
    //freopen("input.txt" , "r" , stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>a;
    if(a!="AAA" && a!="BBB")
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f3f3f
#define pi 3.1415926535898
#define mod 998244353
#define N 240
using namespace std;
typedef pair<int, int> par;
int head[N],tot,n,m,s;
ll dis[N][2510];
ll c[N],d[N];
struct A
{
    int next;
    int to;
    ll a,b;
} e[N*2];
void add(int u,int v,ll a,ll b)
{
    tot++;
    e[tot].to=v;
    e[tot].next=head[u];
    e[tot].a=a;
    e[tot].b=b;
    head[u]=tot;
}
void spfa()
{
    queue < par > q;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= 2500; j++)
        {
            dis[i][j] = inf;
        }
    }
    dis[1][s]=0;
    q.push({1,s});
    while(!q.empty())
    {
        int u=q.front().first;
        int w=q.front().second;
        q.pop();
        for(int d=head[u]; d; d=e[d].next)
        {
            int v=e[d].to;
            ll a=e[d].a;
            ll b=e[d].b;
            if(w>=a&&dis[v][w-a]>dis[u][w]+b)
            {
                dis[v][w-a]=dis[u][w]+b;
                q.push({v,w-a});
            }
        }
        if(dis[u][min(w + c[u], (ll)2500)] > dis[u][w] + d[u])
        {
            dis[u][min(w + c[u], (ll)2500)] = dis[u][w] + d[u];
            q.push({u, min(w + c[u], (ll)2500)});
        }
    }
}
int main()
{
    cin>>n>>m>>s;
    s=min(s,2500);
    while(m--)
    {
        ll a,b,u,v;
        cin>>u>>v>>a>>b;
        add(u,v,a,b);
        add(v,u,a,b);
    }
    for(int i=1; i<=n; i++)
    {
        cin>>c[i]>>d[i];
    }
    spfa();
    for(int i=2; i<=n; i++)
    {
        ll res=inf;
        for(int j=0; j<=2500; j++)
        {
            res=min(dis[i][j],res);
        }
        cout<<res<<endl;
    }
    return 0;
}


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


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int m = s[0];
            int d = s[1];

            long ans = 0;
            for (int i = 1; i <= m; i++)
            {
                for (int j = 10; j <= d; j++)
                {
                    int d1 = j % 10;int d2 = j / 10;
                    if (d1 >= 2 && d2 >=2 && d1* d2 == i)
                    {
                        ans++;
                    }
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <cstdlib>
#include <iostream>

using namespace std;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) {
        cout << "A";
    } else {
        cout << "B";
    }
    return 0;
}

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

  int a[10],b[10],topA,topB,i,j,blank;

  for(i = 0; i < 10; i++){

    scanf("%d",&a[i]);

  }

  for(i = 0; i < 10; i++){

    scanf("%d",&b[i]);

  }

  for(i = 0; i < 10; i++){

    for(j = 0; j < 10; j++){

      if(a[i] > a[j]){

	blank=a[i];
	a[i]=a[j];
	a[j]=blank;

      }

    }

  }

  for(i = 0; i < 10; i++){

    for(j = 0; j < 10; j++){

      if(b[i] > b[j]){

	blank=b[i];
	b[i]=b[j];
	b[j]=blank;

      }

    }

  }

  /* debug
  for(i = 0; i < 10; i++){

    printf("%d ",a[i]);

  }

  printf("\n");

  for(i = 0; i < 10; i++){

    printf("%d ",b[i]);

  }

  printf("\n");
  */

  topA=a[0]+a[1]+a[2];
  topB=b[0]+b[1]+b[2];

  printf("%d %d\n",topA,topB);
  
  return 0;

}

Measured memory_bytes: 596
#include <stdio.h>


int main() 
{
	int n, i, p10 = 1, x, y, j;
	int c[10][10] = {0}, ans = 0;
			
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		x = i / p10;
		if(x > 9) x /= 10, p10 *= 10;
		y = i % 10;
		c[x][y]++;
	}
	for(i = 1; i <= 9; i++){
		for(j = 1; j <= 9; j++){
			ans += c[i][j] * c[j][i];
		}
	}
	printf("%d\n", ans);
			
	return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

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

int
main()
{
  unsigned short r;
  cin >> r;
  cout << 3 * pow(r, 2) << endl;

	return 0;
}


Measured memory_bytes: 256
class Node:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.p = None

def insert(T,z,root):
    y = None
    x = root
    T.append(z)
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

    return T, root

def printPreorderList(p):
    if p == None:
        return
    print("",p.key,end = "")
    printPreorderList(p.left)
    printPreorderList(p.right)

def printInorderList(p):
    if p == None:
        return
    printInorderList(p.left)
    print("",p.key,end = "")
    printInorderList(p.right)
'''
def findRoot(T):
    if T == []:
        return None
    root = T[0].p
    while root != None:
        root = root.p
    return root
'''
n = int(input())
T=[]
root = None
for ni in range(n):
    s = input()
    if s[0] == "i":
        s, key = s.split()
        key = int(key)
        T, root = insert(T, Node(key), root)
    elif s[0] == "p":
        printInorderList(root)
        print()
        printPreorderList(root)
        print()


Measured memory_bytes: 109224
import sys
from typing import List, Set


sys.setrecursionlimit(200000)


def dfs(cur : int, prev: int) -> None:
    global prenum, parent, lowest, counter, bridges
    prenum[cur] = lowest[cur] = counter
    counter += 1
    for edge in edges[cur]:
        if prenum[edge] != sys.maxsize:
            if edge != prev:
                lowest[cur] = min(lowest[cur], prenum[edge])
            continue
        parent[edge] = cur
        dfs(edge, cur)
        lowest[cur] = min(lowest[cur], lowest[edge])
    if prenum[cur] == lowest[cur]:
        bridges.add((cur, prev) if cur < prev else (prev, cur))


if __name__ == "__main__":
    V, E = map(int, input().split())
    edges: List[Set[int]] = [set() for _ in range(V)]

    for _ in range(E):
        s, t = map(int, input().split())
        edges[s].add(t)
        edges[t].add(s)

    prenum = [sys.maxsize] * V
    parent = [sys.maxsize] * V
    lowest = [sys.maxsize] * V
    counter = 0
    bridges = set()  # type: ignore

    dfs(0, -1)
    for bridge in sorted(bridges)[1:]:
        print(*bridge)



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

int find(string S){
    vector<string> alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};    
    for(int i=0;i<alpha.size();i++){
        if(S == alpha.at(i)){
            return i;
        }
    }
    return(-1);
}

int main(){
    vector<string> alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    int N;
    string S;
    string T ="";
    cin >> N >> S;
    for(int i=0;i<(int)S.length();i++){
        if(find(S.substr(i,1)) == -1){
            return(0);
        }
        T += alpha.at( (find(S.substr(i,1)) + N) % 26 );
    }

    cout << T << endl;
    return 0;
}

Measured memory_bytes: 256
import io.StdIn.readLine


object Main {

  def main(args: Array[String]): Unit = {
    val str = readLine()
    val tf = for (i <- 0 to 15) yield (if (str(i) == "CODEFESTIVAL2016"(i)) 0 else 1)
    println(tf.sum)
  }

}


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

typedef long long int ll;

int main(){
  ll N;
  cin>>N;
  ll A[100010];
  for(ll i = 0;i<N;i++){
     cin >> A[i];
  }
  ll ans = 0;
  int a = 0;
  bool fragd = 1,fragi = 1;
  for(ll i = 0;i < N-1;i++){
     if(A[i+1] >= A[i]){
        a++;
     }else{
        fragi = 0;
     }
     if(A[i+1] <= A[i]){
        a++;
     }else{
        fragd = 0;
     }
     if(fragi || fragd){
        a++;
     }else{
        ans++;
        fragi = 1,fragd = 1;
     }
  }
  cout << ans + 1<< endl; 
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int const static N_MAX = 1000 * 100 + 100;

int N,Q;
string s;
int dp[N_MAX];

int main(){
  cin>>N>>Q;
  cin>>s;
  for(int i=0;i<s.size()-1;){
    if(s[i] == 'A' && s[i+1] == 'C'){
      dp[i+1] = dp[i] + 1;
      i = i + 1;
    }else{
      dp[i+1] = dp[i];
      i = i + 1; 
    }
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<< dp[r-1] - dp[l-1] <<endl;
  }

}

Measured memory_bytes: 1408
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long ans = 0;
        long res = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'W') {
                ans += res;
            } else {
                res++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27716
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			int[][] map=new int[n][n];
			boolean[][] flag=new boolean[n][n];
			int x=n/2;
			int y=n/2+1;
			map[y][x]=1;
			flag[y][x]=true;
			for(int i=2;i<=n*n;i++){
				x++;
				y++;
				if(x==n&&y==n){
					x--;
					for(int j=0;j<n;j++){
						if(!flag[j][x]){
							y=j;
							break;
						}
					}
				}else if(x==-1&&y==n){
					x++;
					for(int j=0;j<n;j++){
						if(!flag[j][x]){
							y=j;
							break;
						}
					}
				}else if(x==n){
					x=0;
				}else if(y==n){
					y=0;
				}else if(x==-1){
					x=n-1;
				}
				if(flag[y][x]){
					x-=2;
					i--;
				}else{
					map[y][x]=i;
					flag[y][x]=true;
				}
			}
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					System.out.printf("%4d",map[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 20272
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  string _s, _t;
  cin >> _s >> _t;

  if(_s.size() < _t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  string s = "", t = "";
  rep(i, 0, _s.size()) s = _s[i] + s;
  rep(i, 0, _t.size()) t = _t[i] + t;

  string rsl = "";
  bool isUnrestorable = true;
  bool isOnce = true;
  int i = 0;
  while(i < s.size() - t.size() + 1) {
    bool flag = false;
    if(isOnce) {
      for(int j = 0; j < t.size(); ++j) {
        if(!(s[i + j] == t[j] || s[i + j] == '?')) {
          flag = true;
          break;
        }
      }
    }
    if(flag || !isOnce) {
      if(s[i] == '?') rsl = 'a' + rsl;
      else rsl = s[i] + rsl;
      ++i;
    } else {
      isUnrestorable = false;
      isOnce = false;
      for(int j = 0; j < t.size(); ++j) {
        rsl = t[j] + rsl;
      }
      i += t.size();
    }
  }
  if(rsl.size() < s.size()) {
    for(int i = s.size() - rsl.size() - 1; i >= 0; --i) {
      if(_s[i] == '?') rsl = 'a' + rsl;
      else rsl = _s[i] + rsl;
    }
  }

  if(isUnrestorable) cout << "UNRESTORABLE" << endl;
  else cout << rsl << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# input
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

# solve
ans = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i][j] * B[j]
    sum += C
    if sum > 0:
        ans += 1

# output
print(ans)


Measured memory_bytes: 3060
N,A,B = map(int,input().split())
ans_list = []

for i in range(0,N+1):
    if i < 10:
        if i >= A and i <=B:
            ans_list.append(i)
    else:
        temp = list(map(int,str(i)))
        temp=sum(temp)
        if temp >=A and temp<=B:
            ans_list.append(i)
            
print(sum(ans_list))

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;

int main(){
    int n, x ,t;
    cin >> n >> x >> t;
    int ans = 0;
    while(n > 0){
        ans += t;
        n -= x;
    }
    cout << ans << endl;
}

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

int main () {
  int N , M , X , Y ;
  int A[10000] , B[10000] ;
  cin >> N >> M >> X >> Y ;
  for(int i = 0 ; i < N ; i++ ) cin >> A[i] ;
  for(int j = 0 ; j < M ; j++ ) cin >> B[j] ;
  sort(A,A+N) ; sort(B,B+M) ;
  bool can = true ;
  if(B[0]<=A[N-1]) can = false ;
  if(!(X < B[0] && B[0] <= Y )) can = false ;
  if(can) cout << "No " ;
  cout << "War" << endl ;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    char[] k=sc.next().toCharArray();
    char[] g=sc.next().toCharArray();
    for(int i=0;i<g.length;i++){
      System.out.print(k[i]);
      System.out.print(g[i]);
    }
    if(k.length==g.length){
      System.out.println("");
    }else{
      System.out.println(k[k.length-1]);
    }
  }
}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
#define ll long long int
const int MOD =1e9+7;
using namespace std;
signed main()
{
	int n,m;
	cin>>n>>m;
	int dp[n+1][m+1];
	//cout<<"h"<<endl;
	for (int i = 0; i < m+1; ++i)
	{
		dp[0][i]=0;
	}
	for (int i = 0; i < n+1; ++i)
	{
		dp[i][0]=0;
	}
	int a[n][m];
	int x=0;
	
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin>>s;
		int c=0;
		for (int i = 0; i < m; ++i)
		{
			if(s[i]=='.')
			{
				a[x][c]=1;
				c++;
			}
			else if(s[i]=='#')
			{
				a[x][c]=0;
				c++;
			}

		}
		x++;
	}
	dp[1][0]=1;
	for(int i=1; i<n+1; i++)
	{
		for(int j=1; j<m+1; j++)
		{
			if(a[i-1][j-1]==1)
			{
				dp[i][j]= (dp[i-1][j]+dp[i][j-1])%MOD;
			}
			else dp[i][j]=0;
		}
	}
	
	cout<<dp[n][m]%MOD<<endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;

unsigned long H, W, D, Q;

int main() {
  cin >> H >> W >> D;
  vector<pair<int, int>> v(H*W+1);
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      unsigned long a;
      cin >> a;
      v.at(a) = make_pair(i, j);
    }
  }
  cin >> Q;
  vector<int> ans(H*W+1);
  for (unsigned long i=1; i<=D; i++) {
    for (unsigned long j=i; j<=H*W; j+=D) {
      if (j<D) {
        ans.at(j) = 0;
      } else {
        pair<int, int> first = v.at(j-D);
        pair<int, int> second = v.at(j);
        ans.at(j) = ans.at(j-D) + abs(first.first - second.first) + abs(first.second - second.second);
      }
    }
  }
  for (int i=0; i<Q; i++) {
    unsigned long L, R;
    cin >> L >> R;
    cout << ans.at(R) - ans.at(L) << endl;
  }
}

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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}
ll A[maxs];
ll a[maxs];
ll b[maxs];
ll c[maxs];
ll d[maxs];

ll MAX=-1;
ll n,m,q;

void dfs(ll dep,ll x){
    if(dep==n){
        ll sum=0;
        for(ll i=0;i<q;i++){
            if( A[b[i]] - A[a[i]] == c[i] ){
                sum += d[i];
            }
        }
        MAX = max(MAX , sum);
        return;
    }
    else{
        for(ll i=x;i<=m;i++){
            A[dep] = i;
            dfs(dep+1,i);
        }
    }
}


void solve(){
    cin >> n >> m >> q;
    for(ll i=0;i<q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;b[i]--;
    }
    dfs(0,1);
    cout << MAX << endl;
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
typedef long long ll;
const int MAXN = 1e2 + 5;
const int MAXW = 1e5 + 5;
const int MOD = 1e9 + 7;

using namespace std;
ll mem[MAXN][MAXW];
int v[MAXN] , sz[MAXN];
int n,w;
ll solve(int i,int w)
{
	if(w < 0)
		 return -1e9;
	if(i == n || w == 0)
		  return 0;

    ll &ret = mem[i][w];
    if(ret != -1) return ret;
    ret = max(solve(i + 1 , w) , solve(i + 1 , w - sz[i]) + v[i]);

    return ret;


   
}

int main()
{
cin >> n >> w;
for(int i = 0 ; i < n ; i++)
	 cin >> sz[i] >> v[i];

memset(mem,-1,sizeof(mem));
cout << solve(0,w) ;

}

 

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

int main() {
  string s;
  cin >> s;
  ll count=0;
  for(ll i=0;i<s.size();i++) {
    if(s[i]=='1') count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int xs[5];
	for (auto &x : xs) {
		cin >> x;
	}
	for (int i = 1; i <= 5; ++i) {
		if (xs[i - 1] != i) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3572
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   	int n, q;
   	cin >> n >> q;
   	vector< priority_queue<int> > v(n);
   	for(int i = 0; i < q; i++){
	  	 int cmd;
	  	 cin >> cmd;
	  	 if (cmd == 0){
		  int t, x;
		  cin >> t >> x;
		  v[t].push(x);	 
		}
		 if (cmd == 1){
		  	 int t;
		  	 cin >> t;
		  	 if (!v[t].empty())cout << v[t].top() << endl;
		}
		if (cmd == 2){
		  	int t;
		  	cin >> t;
		  	if (!v[t].empty()) v[t].pop();
		}
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node)); // *zはinsert関数内でしか存在しないのでmallocの必要あり
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;

  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
};

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
};

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
};

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
};

int main() {
  int n, i, x;
  string com;
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
};



Measured memory_bytes: 22036
a,b,c,d=map(int,input().split())
dic={"U":"D","D":"U","L":"R","R":"L"}

x=c-a
y=d-b

ans=""
if y>0:
    ans+="U"*y
else:
    ans+="D"*y
if x>0:
    ans+="R"*x
else:
    ans+="L"*x
for i in ans:
    ans+=dic[i]
ans2=""
if x>0:
    ans2+="L"
else:
    ans2+="R"
if y>0:
    ans2+="U"*(y+1)
else:
    ans2+="D"*(y+1)
if x>0:
    ans2+="R"*(x+1)
else:
    ans2+="L"*(x+1)
if y>0:
    ans2+="D"
else:
    ans2+="U"
for i in ans2:
    ans2+=dic[i]
print(ans+ans2)

Measured memory_bytes: 3188
# -*- coding:utf-8 -*-
n = int(input())

PosList = []
TempSum = 0
ReturnSum = 0

PosList = list(map(int,input().split()))


for pos in range(1,101):
    TempSum = 0
    for nPos in range(n):
        TempSum += (pos - PosList[nPos])**2
    if pos == 1:
        ReturnSum = TempSum
    elif ReturnSum > TempSum:
        ReturnSum = TempSum
    """
    print("Position = "+str(pos))
    print("TempSum = "+ str(TempSum))
    print("ReturnSum = " + str(ReturnSum))
    print("----------------------------")
    """

print(ReturnSum)

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

#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
#define MAX_M   100000


void solve(){
    int m1, m2, d1, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(m1 != m2)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}

int main(){
    solve();
    return 0;
}

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

using namespace std;

int main() {
    long long k, a, b;
    cin >> k >> a >> b;
    if (a >= b - 1 || k <= a) {
        cout << k + 1;
    }
    else {
        long long rem = k - a + 1;
        long long exchanges = rem / 2;
        long long ans = a + exchanges * (b - a);
        if (rem % 2) {
            ans++;
        }
        cout << ans;
    }
}

Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))
count = 0
for i in range(n-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if p1 < p2 and p2 < p3:
        count += 1
    elif p3 < p2 and p2 < p1:
        count += 1
    else:
        continue
print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int count;
		while ((count = in.nextInt()) > 0) {
			int[] ice = new int[10];
			while (count-- > 0) {
				ice[in.nextInt()]++;
			}
			for (int b : ice) {
				sb.setLength(0);
				for (int j = 0; j < b; j++) {
					sb.append('*');
				}
				if (sb.length() != 0) {
					System.out.println(sb);
				} else {
					System.out.println('-');
				}
			}
		}
	}
}

Measured memory_bytes: 51608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n; cin >> n;
  string s; cin >> s;

  string ans = "";
  char cur = s[0];
  ans += cur;
  rep (i, n) {
    if (s[i] == cur) continue;
    else cur = s[i];
    ans += cur;
  }

  cout << ans.size() << endl;
  return 0;
}


Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int W, H;
int field[55][55];

void input(void){
	cin >> W;
	cin >> H;

	for(int i = 0;i < H;i++){
		for(int j = 0;j < W;j++){
			cin >> field[j][i];
		}
	}
}

void dfs(int x, int y){
	field[x][y] = 0;

	for(int dx = -1;dx <= 1;dx++){
		for(int dy = -1;dy <= 1;dy++){
			int nx = x + dx, ny = y + dy;
			if(0 <= nx && nx < W && 0 <= ny && ny < H && field[nx][ny] == 1) dfs(nx, ny);
		}
	}

	return ;
}

int main(){
	while(1){
		int res = 0;
		input();
		if(W == 0 && H == 0) break;

		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(field[j][i] == 1){
					dfs(j, i);
					res++;
				}
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1352