akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int a,b;
   cin >> a >> b;
   cout << ((a*b % 2 == 0) ? "Even":"Odd") << endl;

   return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let s_t = lines.next().unwrap().unwrap();
    let mut s_t = s_t.split_whitespace();
    let s: String = s_t.next().unwrap().parse().unwrap();
    let t: String = s_t.next().unwrap().parse().unwrap();
    let a_b = lines.next().unwrap().unwrap();
    let mut a_b = a_b.split_whitespace();
    let a: i32 = a_b.next().unwrap().parse().unwrap();
    let b: i32 = a_b.next().unwrap().parse().unwrap();
    let u: String = lines.next().unwrap().unwrap();

    if s == u {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 100005;
const int NIL = -1;
enum T { root, leaf, internalNode };
struct Node
{
	int parent;
	int child;
	int sibling;
	T type;
	vector<int> childList;

}Tree[MAX];
int depth[MAX];
int n;
void print(int u)
{
	cout << "node " << u << ": ";
	cout << "parent = " << Tree[u].parent << ", ";
	cout << "depth = " << depth[u] << ", ";
	if (Tree[u].type == root)
		cout << "root, ";
	else if (Tree[u].type == leaf)
		cout << "leaf, ";
	else
		cout << "internal node, ";
	cout << "[";
	for (int i = 0; i < Tree[u].childList.size(); i++)
	{
		if (i)
			cout << ", ";
		cout << Tree[u].childList[i];
	}
	cout << "]" << endl;
}
void getDepth()
{
	for (int i = 0; i < n; i++)
	{
		int d = 0;
		int u = i;
		while (Tree[u].parent != NIL)
		{
			u = Tree[u].parent;
			d++;
		}
		depth[i] = d;
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		Tree[i].child = Tree[i].sibling = Tree[i].parent = NIL;
	}
	for (int i = 0; i < n; i++)
	{
		int p, d;
		cin >> p >> d;
		Tree[p].type = (d != 0) ? internalNode : leaf;
		int c, fc;
		for (int i = 0; i < d; i++)
		{
			cin >> c;
			Tree[p].childList.push_back(c);
			if (i == 0)
			{
				fc = c;
				Tree[p].child = c;
			}
			else
				Tree[fc].sibling = c;
			Tree[c].parent = p;
		}
	}
	int r;
	for (int i = 0; i < n; i++)
		if (Tree[i].parent == NIL)
		{
			r = i;
			Tree[i].type = root;
		}
	getDepth();
	for (int i = 0; i < n; i++)
		print(i);
}



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

using namespace std;

int main() {
    long long X;
    cin >> X;
    for (long long a = 0; a <= 200; a++)
    {
        for (long long b = -200; b <= 200; b++)
        {
            if(pow(a, 5) - pow(b, 5) == X){
                cout << a << " " << b << endl;
                return 0;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>

using namespace std;

bool match(string s1, string s2) {
	if(s1.size() > s2.size()) return false;

	for(int i = 0 ; i < s1.size(); i++) {
		if (s1[i] != s2[i]) return false;
	}
	return true;
}

int main(int argc, char *argv[])
{
	string s1, s2;
	cin >> s1 >> s2;
	cout << (match(s1, s2) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3548
import java.util.*;
public class Main {
	static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		while (true) {
			int n = Integer.parseInt(sc.nextLine());	// 1..10^4
			if (n==0) break;
			int t[] = new int[86400];
			for (int i=0; i<n; i++) {
				String ge = sc.nextLine();
				t[Integer.parseInt(ge.substring(0,2))*3600 + 
				  Integer.parseInt(ge.substring(3,5))*60 + 
				  Integer.parseInt(ge.substring(6,8))] ++;
				t[Integer.parseInt(ge.substring(9,11))*3600 + 
				  Integer.parseInt(ge.substring(12,14))*60 + 
				  Integer.parseInt(ge.substring(15,17))] --;
			}
			
			int ans = 0;
			int cnt = 0;
			for (int i=0; i<86400; i++) {
				if (t[i]!=0) cnt += t[i];
				if (cnt>ans) ans = cnt;
			}
			
			System.out.println(ans);
			
		}
		
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int min_color = 0, max_color = 0;
vector<int> color(8, 1);

void count(int c) {
    if (color[c]) {
        min_color++;
        max_color++;
        color[c] = 0;
    }
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        int a, c;
        cin >> a;
        if (a <= 399) {
            c = 0;
            count(c);
        } else if (a <= 799) {
            c = 1;
            count(c);

        } else if (a <= 1199) {
            c = 2;
            count(c);

        } else if (a <= 1599) {
            c = 3;
            count(c);

        } else if (a <= 1999) {
            c = 4;
            count(c);
        } else if (a <= 2399) {
            c = 5;
            count(c);
        } else if (a <= 2799) {
            c = 6;
            count(c);
        } else if (a <= 3199) {
            c = 7;
            count(c);
        }else{
            max_color++;
        }
    }

    min_color = min_color ? min_color : 1;


    cout << min_color << " " << max_color << endl;

    return 0;
}

Measured memory_bytes: 3524
n = int(input())
a = list(map(int,input().split()))
p = [0 for i in range(n+1)]
ans = 0
q = []
for i in reversed(range(1,n+1)):
    if sum(p[i:n+1:i]) % 2 != a[i-1]:
        p[i] += 1
        ans += 1
        q.append(i)
print(ans)
print(*q)

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	int n; cin >> n;
	int arr[n];
	//unordered_map<int, int> m;
	int cnt = 0, sum = 0;
	for(int i=0; i<n; i++) {cin >> arr[i];
	    /*if(m.find(arr[i]) == m.end()){
	        m[arr[i]] = 1;
	        sum += arr[i];
	        cnt++;
	    }*/
	    sum += arr[i];
	}
	int avg = sum / n;
	int avg_2 = avg + 1;
	int ans = 0, sec = 0;
	for(int i=0; i<n; i++){
	    ans += (arr[i] - avg)* (arr[i]-avg);
	    sec += (arr[i] - avg_2) * (arr[i] - avg_2);
	}
	cout << min(ans,sec) << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        Reader.init();
        int a=Reader.nextInt();
      	String S=Reader.next();
      	if(a>=3200){
        	print(S);
        }
      	else{
        	print("red");
        }
    }

    static int mod=1000000007;
    
    public static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.nextInt(); } }
    public static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.next(); } }
    
    public static void print(Object O){ System.out.println(O); }
    
    public static void display(int arr[]){ System.out.println(Arrays.toString(arr)); }
    public static void display(int arr[][], int N){ for(int i=0;i<N;i++){ System.out.println(Arrays.toString(arr[i])); } }
  
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init() {
        reader=new BufferedReader(new InputStreamReader(System.in));
        tokenizer=new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException { return Integer.parseInt(next()); }
    static double nextDouble() throws IOException { return Double.parseDouble(next()); }
    static long nextLong() throws IOException { return Long.parseLong(next()); }
    static String nextLine() throws IOException { return reader.readLine(); }
}

Measured memory_bytes: 23120
import java.util.*;

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

	while(true){
	    int t=scan.nextInt();
	    if(t==0){
		break;
	    }
	    int n=scan.nextInt();
	    for(int i=0;i<n;i++){
		int from=scan.nextInt();
		int to=scan.nextInt();
		t-=to-from;
	    }
	    if(t<=0){
		System.out.println("OK");
	    }else{
		System.out.println(t);
	    }
	}
    }
}

Measured memory_bytes: 31524
from itertools import combinations
n = int(input())
m = []
a = []
r = []
c = []
h = []
for i in range(n):
  t = input()
  if t[0] == 'M':
    m.append(t)
  elif t[0] == 'A':
    a.append(t)
  elif t[0] == 'R':
    r.append(t)
  elif t[0] == 'C':
    c.append(t)
  elif t[0] == 'H':
    h.append(t)

names = [m,a,r,c,h]
com = list(combinations(names,3))
cnt = 0
for i in range(len(com)):
  cnt += len(com[i][0]) * len(com[i][1]) * len(com[i][2])
print(cnt)

Measured memory_bytes: 10100
#include <iostream>
#include <array>
#include <string>
 
using namespace std;
 
const int maxn = 2005;
 
array<array<int, maxn>, maxn> l, r, u, d;
array<string, maxn> s;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    for (int j = 0; j < w; ++j) {
      r[i][j] = w;
      d[i][j] = h;
      if (s[i][j] == '.') {
      	l[i][j] = j;
        u[i][j] = i;
        if (j > 0 && s[i][j-1] == '.') l[i][j] = l[i][j-1];
        if (i > 0 && s[i-1][j] == '.') u[i][j] = u[i-1][j];
      }
    }
  }
  int ans = 0;
  for (int i = h - 1; i >= 0; --i)
    for (int j = w - 1; j >= 0; --j) {
      if (s[i][j] == '#') {
        r[i][j] = j;
        d[i][j] = i;
      } else {
        if (j < w - 1) r[i][j] = r[i][j+1];
        if (i < h - 1) d[i][j] = d[i+1][j];
        ans = max(ans, r[i][j] - l[i][j] + d[i][j] - u[i][j] - 1);
      }
    }
  cout << ans << '\n';
}

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

int main() {
  
  string s;
  
  rip(i, 3){
	cin >> s;
    cout << s.at(0);
  }
  cout << endl;
    
  
  	
}


Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2018/04/26
 *      Author: mac
 */

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>


using namespace std;

int main(){

	int N;

	cin >> N;

	int t[N];

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

	int sum = 0;

	for(int i = 0;i < N;i++){
		sum += t[i];
	}

	int M;

	cin >> M;

	int p[M];
	int x[M];

	for(int i = 0;i < M;i++){
		cin >> p[i];
		cin >> x[i];
	}

	for(int i = 0;i < M;i++){
		cout << sum - t[p[i] - 1] + x[i] << endl;
	}

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int gcd(int a,int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector< vector<int> > ans(h);
    int cnt=0,s=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<a[i];j++){
            ans[s].push_back(i+1);
            cnt++;
            if(cnt==w){
                s++;
                cnt=0;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                cout << ans[i][j] << (j==w-1?"":" ");
            }
        }else if(i%2==1){
            for(int j=w-1;j>=0;j--){
                cout << ans[i][j] << (j==0?"":" ");
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<set>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
//http://drken1215.hatenablog.com/entry/2018/08/28/193000

int N;
vector<ll> A;
vector<ll> sum;

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

    cin>>N;
    A.resize(N); sum.resize(N+1); sum[0]=0;
    for(int i=0;i<N;i++) cin>>A[i],sum[i+1]=sum[i]+A[i];

    ll res=1LL<<60;
    for(int i=1;i<=N-1;i++){
        int low=0,high=i;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]>=sum[i]-sum[mid]) high=mid;
            else low=mid;
        }
        ll P=sum[low],Q=sum[i]-sum[low];
        ll P2=sum[high],Q2=sum[i]-sum[high];
        ll left_min=min(P,Q),left_max=max(P,Q);
        if(abs(P2-Q2)<abs(P-Q)) left_min=min(P2,Q2),left_max=max(P2,Q2);

        low=i,high=N;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]-sum[i]>=sum[N]-sum[mid]) high=mid;
            else low=mid;
        }
        ll R=sum[low]-sum[i],S=sum[N]-sum[low];
        ll R2=sum[high]-sum[i],S2=sum[N]-sum[high];
        ll right_min=min(R,S),right_max=max(R,S);
        if(abs(R2-S2)<abs(R-S)) right_min=min(R2,S2),right_max=max(R2,S2);

        ll temp=max(left_max,right_max)-min(left_min,right_min);
        chmin(res,temp);
    }
    cout<<res<<endl;
}


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

#define  optimize   ios::sync_with_stdio(0); cin.tie(0);
#define PI  acos(-1.0)
#define RESET(a, b) memset(a, b, sizeof(a))
#define pb push_back
int main()
{
     optimize
     string s;
     cin>>s;
     int n=s.length();
     map<char,int>Map;
     for(int i=0;i<n;i++){
        Map[s[i]]++;
     }
     for(char i='a';i<='z';i++){
        if(Map[i]%2){
            cout<<"No\n";
            return 0;
        }
     }
     cout<<"Yes\n";
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int d,e;
    d = c-(a-b);
    

    if (d > 0) {
        cout << d << endl;
    } else{
        cout << 0 << endl;
    }

    return 0;
}

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

int main()
{
	string str;
	while(1){
		getline(cin, str);
		if(str == "END OF INPUT")
			break;
		int n=0;
		int i;
		for(i=0;i<str.size();i++){
			if(str[i] == ' '){
				cout << n;
				n=0;
			}
			else{
				n++;
			}
		}
		cout << n << endl;
	}
	return 0;
}

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

int main() {
  int S, count, i;
  cin >> S;
  count = 0;
  for (i = 0; i < to_string(S).size(); i++) {
    if (to_string(S).at(i) == '1'){
      count += 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll A, B, C, D, cDevide = 0, dDevide = 0, cdDevide = 0, lcm = 0;

ll GCD(ll N, ll M) {
	if (N%M != 0) {
		return GCD(M, N%M);
	}
	else {
		return M;
	}
}

int main() {
	cin >> A >> B >> C >> D;
	if (A%C == 0)cDevide++;
	cDevide += B / C - A / C;
	if (A%D == 0)dDevide++;
	dDevide += B / D - A / D;
	lcm = C*D / GCD(D, C);
	if (A % lcm == 0)cdDevide++;
	cdDevide += B / lcm - A / lcm;
	cout << B - A + 1 - (cDevide + dDevide - cdDevide) << endl;
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int x = ri();
	int n = ri();
	int sum = 0;
	for (int i = 0; i < n; i++) sum += ri();
	puts(x <= sum ? "Yes" : "No");
	return 0;
}



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

int main(){
	int count = 0;
	int m;
	int op;
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());
	op = (v[2] - v[0]) / 2;
	v[0] += op * 2;
	count += op;
	op = (v[2] - v[1]) / 2;
	v[1] += op * 2;
	count += op;
	if(v[2] != v[1] && v[1] == v[0]) cout << count + 1;
	else if(v[2] == v[1] && v[1] == v[0]) cout << count;
	else cout << count + 2;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[20];
int n;

int solve(int p, int t);
int sort(void *a, void *b);

int main(void) {
	int i, q, M;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	
	qsort(A, n, sizeof(A[0]), sort);
	
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &M);
		if (solve(-1, M)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int p, int t) {
	if ((p == n) || (t == 0)) return t == 0;
	if ((t >= A[p + 1]) && (solve(p + 1, t - A[p + 1]))) return 1;
	return solve(p + 1, t);
}

int sort(void *a, void *b) {
	return *(int*)b - *(int*)a;
}

Measured memory_bytes: 584
package main

import (
	"fmt"
	"strings"
)

func main() {
	type pair struct {
		a int
		b int
	}

	var pairList []pair
	var a, b int
	for {
		fmt.Scan(&a, &b)
		if a == 0 && b == 0 {
			break
		}
		pairList = append(pairList, pair{a: a, b: b})
	}

	for _, pair := range pairList {
		for i := 0; i < pair.a; i++ {
			fmt.Println(strings.Repeat("#", pair.b))
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#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)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll d[m][m],a[n][n];
  rep(i,m)rep(j,m) R d[i][j];
  rep(i,n)rep(j,n) R a[i][j];
  vector<int> v[3];
  rep(i,n)rep(j,n) {
    v[(i+j)%3].pb(a[i][j]-1);
  }
  ll c[3][m];
  mem(c);
  rep(k,3) {
    rep(i,m) {
      rep(j,v[k].size()) c[k][i]+=d[v[k][j]][i];
    }
  }
  ll ans=MAXL;
  rep(i,m)rep(j,m)rep(k,m) {
    if(i==j||j==k||i==k) continue;
    ans=min(ans,c[0][i]+c[1][j]+c[2][k]);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();
		int k = cin.nextInt();

		int[] l = new int[n];
		for (int i = 0; i < l.length; i++)
			l[i] = cin.nextInt();

		long start = now();

		int ans = solve(n, k, l);
		cout.println(ans);

		trace("elapsed", now() - start);
	}

	private static int solve(int n, int k, int[] l) {
		Arrays.sort(l);
		int ans = Arrays.stream(l).skip(n - k).sum();
		return ans;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

int main()
{
	int N;
	cin >> N;
	vector<int> H(N);
	for(int i = 0; i < N; i++) cin >> H[i];

	vector<int> C(N);
	C[0] = 0;
	C[1] = abs(H[1] - H[0]);
	for(int i = 2; i < N; i++)
	{
		int a = abs(H[i] - H[i-1]) + C[i-1];
		int b = abs(H[i] - H[i-2]) + C[i-2];
		C[i] = min(a, b);
	}

	cout << C[N-1] << endl;

	return 0;
}


Measured memory_bytes: 1024
N,T = map(int,input().split())
t_list = list(map(int,input().split()))

dup_time = 0

for i in range(1,N):
    if t_list[i] - t_list[i-1] < T:
        dup_time += T - (t_list[i] - t_list[i-1])

print(N*T - dup_time)

Measured memory_bytes: 86224
#include"bits/stdc++.h"
using namespace std;
int main(){
	long long n;
	cin>>n;
	map<long long,long long> x;
	for(long long i=0;i!=n;++i){
		long long temp;
		cin>>temp;
		++x[temp];
	}
	long long ans=1,br=0;
	for(auto it=x.rbegin();it!=x.rend();++it){
		while(br!=2 && it->second>=2){
			ans*=it->first;
			it->second-=2;
			++br;
		}
	}
	if(br==2)
		cout<<ans;
	else
		cout<<0;
}



Measured memory_bytes: 6528
import sys
sys.setrecursionlimit(10 ** 7)
# --------Ø--

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

S = input().strip()
T = input().strip()

for i in range(len(S)):
    if S[i] != T[i]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;



int main(){
ll N;
cin >> N;
vector<ll> A(N,0);
for(ll i=0;i<N;i++){
  cin>>A[i]
;}
//Nが偶数
if(N%2==0){
  vector<ll> yes(N,0);
  vector<ll> no(N,0);
  yes[N-2]=A[N-2];
  no[N-2]=A[N-1];
  for(ll i=N-4;i>=0;i-=2){
    yes[i]=max(A[i]+yes[i+2],A[i]+no[i+2]);
    no[i]=A[i+1]+no[i+2]
  ;}
  cout<<max(yes[0],no[0])<<endl;
}
//Nが奇数
else if(N%2==1){
  vector<ll> yesp(N,0);
  vector<ll> yesm(N,0);
  vector<ll> nom(N,0);
  yesp[N-3]=A[N-1]+A[N-3];
  yesm[N-3]=A[N-3];
  nom[N-3]=max(A[N-2],A[N-1]);
  for(ll i=N-5;i>=0;i-=2){
    yesp[i]=yesp[i+2]+A[i];
    yesm[i]=max(yesm[i+2],nom[i+2])+A[i];
    nom[i]=max(nom[i+2]+A[i+1],yesp[i+2]);
  ;}
  cout<<max(yesm[0],nom[0])<<endl;
}
return 0;
}


Measured memory_bytes: 9532
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> stones;
vector<int> costs;
vector<int> Ks;
int hops(int stone)
{
    if (stone < 1)
    {
        return 0;
    }
    if (stone == 1)
    {
        return abs(costs[stone] - costs[stone - 1]);
    }
    if (stones[stone] != -1)
    {
        return stones[stone];
    }
    int k = Ks.size();
    int mincost = hops(stone - 1) + abs(costs[stone] - costs[stone - 1]);
    for (int i = max(stone - k, 0); i < stone; i++)
    {

        mincost = min((hops(i) + abs(costs[stone] - costs[i])), mincost);
    }
    //int cost1 = hops(stone - 1) + abs(costs[stone] - costs[stone - 1]);
    //int cost2 = hops(stone - 2) + abs(costs[stone] - costs[stone - 2]);
    //int preferable = min(cost1, cost2);
    stones[stone] = mincost;
    //cout << mincost << endl;
    return mincost;
}
int main()
{
    int n;
    cin >> n;
    int k;
    cin >> k;
    stones.assign(n + 1, -1);
    for (int i = 0; i < n; i++)
    {
        int cost;
        cin >> cost;
        costs.push_back(cost);
    }
    for (int i = 1; i <= k; i++)
    {
        Ks.push_back(i);
    }

    cout << hops(n - 1) << endl;
}

Measured memory_bytes: 7416
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;
const int mod=1000000007;

int n,x,y,ans,m;
int a[N],f[N],g[N],fac[N],inv[N],vis[N],h[N];

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

int C(int x,int y){
	if (x<y) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

void init(int n){
	int i;
	fac[0]=inv[0]=1;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2);
	for (i=n-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n+1;i++) scanf("%d",&a[i]);
	init(n+1);
	for (i=0;i<=n+1;i++) f[i]=C(n+1,i);
	for (i=1;i<=n+1;i++){
		if (!vis[a[i]]) vis[a[i]]=i;
		else{
			x=vis[a[i]]; y=i;
			vis[a[i]]=i;
		}
	}
	m=n-y+x;
	for (i=0;i<=m;i++) g[i]=C(m,i);
	for (i=1;i<=n+1;i++){
		ans=f[i]-g[i-1];
		printf("%d\n",(ans+mod)%mod);
	}
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  ll x,y;
  cin>>x>>y;
  int cnt(1);
  while(x*2 <= y){
    x*=2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  int n, a[305];
  while(1){
    cin>>n;
    if(n == 0) break;
    REP(i,0,n) cin>>a[i];

    int dp[305][305];
    REP(i,0,n)REP(j,0,n) dp[i][j] = 0;

    for(int k=1; k<n; k++){
      for(int i = 0; i+k<n; i++){
        if(abs(a[i] - a[i+k]) <= 1 && dp[i+1][i+k-1] == (i+k) - i - 1){
          dp[i][i+k] = dp[i+1][i+k-1] + 2;
        }else{
          int tmp = 0;
          for(int p=i+1; p<i+k; p++){
            if(p+1 < i+k) tmp = max(tmp, dp[i][p] + dp[p+1][i+k]);
            else tmp = max(tmp, max(dp[i][p], dp[i+k-1][i+k]));
          }
          dp[i][i+k] = tmp;
        }
      }
    }
    cout<<dp[0][n-1]<<endl;
  }


  return 0;
}

Measured memory_bytes: 3428
import math
N = int(input())
number = math.ceil((N * 2) ** 0.5)
if number * (number + 1) // 2 == N:
    answers = [n for n in range(1, number + 1)]
    for answer in answers:
        print(answer)
else:
    whole=number*(number+1)//2
    sa=whole-N
    answers = [n for n in range(1, number + 1)]
    bad=[]
    for n in range(N):
        if sa>answers[-n-1]:
            sa-=answers[-n-1]
            bad.append(answers[-n-1])
        elif sa==answers[-n-1]:
            sa-=answers[-n-1]
            bad.append(answers[-n-1])
            break
    for ans in answers:
        if ans in bad:
            continue
        print(ans)
        

Measured memory_bytes: 75228
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    string ans;
    if (a > 0 && b > 0) ans = "Positive";
    else if (a <= 0 && b >= 0) ans = "Zero";
    else {
        if ((b-a+1)%2 == 0) ans = "Positive";
        else ans = "Negative";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (n, m) = (nm[0], nm[1]);
        var seqAB = new (int A, int B)[m];
        for (int i = 0; i < seqAB.Length; ++i)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            seqAB[i] = (ab[0], ab[1]);
        }

        var uf = new UnionFind(n + 1);
        foreach (var (a, b) in seqAB)
        {
            uf.Unite(a, b);
        }

        var clusterIndividual = new HashSet<int>();
        for (int i = 1; i < uf.Count; ++i)
        {
            clusterIndividual.Add(uf.Find(i));
        }

        var max = clusterIndividual.Max(x => uf.GetSize(x));

        Console.WriteLine(max);
    }
}

class UnionFind
{
    int[] nodes;

    public int Count { get; private set; }

    public UnionFind(int size)
    {
        this.nodes = Enumerable.Repeat(-1, size).ToArray();
        Count = size;
    }

    public int Find(int x)
    {
        var p = nodes[x];
        if (p < 0)
        {
            return x;
        }

        return nodes[x] = Find(p);
    }

    public void Unite(int x, int y)
    {
        var p = Find(x);
        var q = Find(y);
        if (p == q)
        {
            return;
        }

        var r = nodes[p];
        var s = nodes[q];
        if (r > s)
        {
            p += q;
            q = p - q;
            p -= q;
        }
        nodes[p] += nodes[q];
        nodes[q] = p;
        Count--;
    }

    public bool Union(int x, int y)
        => Find(x) == Find(y);

    public int GetSize(int x)
        => -nodes[Find(x)];
}


Measured memory_bytes: 43796
A = input()
 
for i in range(2**3):
    ans = A[0]
    for j in range(3):
        if ((i >> j)&1):
           ans += "+"+A[j+1]
        else:
           ans += "-"+A[j+1]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000

/*
時間の締め切りが早い方から消化していきたい
時間の締め切りBiでソートしたい・・・・
N=2*10^5なので、ソートは厳しい

vector<pair>を一つ目の要素でソートするのできるぽい
*/

int main()
{
  ll N;cin>>N;
  vector<pair<ll,ll>> P;
  for (int i=1;i<=N;i++)
  {
    ll a,b;cin>>a>>b;
    P.push_back({b,a});
  }
  
  sort(P.begin(),P.end());
  
  /*
  for (auto p : P)
  {
    cout<<"締め切り "<<p.first<<" かかる時間"<<p.second<<endl; 
  }
  */
  
  ll time=0;
  ll work=0;
  for (auto p : P)
  {
    time += p.second;
    if (time > p.first) 
    {
      cout<<"No"<<endl;
      return (0);
    } 
  }  
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 6512
import java.io.BufferedReader
import java.io.BufferedWriter

fun solve(c: Case) {
    val s = c.string().toCharArray()
    val t = c.string().toCharArray()

    var min = Int.MAX_VALUE
    (0..(s.size - t.size)).forEach { offset ->
        var diff = 0
        t.forEachIndexed { index, char ->
            if (char != s[offset + index]) {
                diff++
            }
        }
        min = min.coerceAtMost(diff)
    }

    c.println(min.toString())
}

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) =
        input.use { out.use { Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024).also { it.start() }.join() } }

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

fun main() = Case().exec(::solve)

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

char ss[25000][6];

int compare_s(const void*a, const void*b){
    int* A = (int*)a;
    int* B = (int*)b;
    return strcmp(ss[*A], ss[*B]);
}

int main(void){
    char s[5001];
    int k;
    scanf("%s", s);
    scanf("%d", &k);

    char *ps;
    int ls = strlen(s);

    // h:sから切り取る文字の長さ
    // ls-h+1:sからh文字切り取る動作の回数
    // ssに、sから長さ1~5の文字列を全て切り取って代入する
    int index = 0;
    for(int h = 1; h <= 5; h++){
        ps = s;
        for(int i = 0; i < ls-h+1; i++){
            strncpy(ss[index], ps, h);
            ss[index][h] = '\0';
            ps++;
            index++;
        }
    }
        
    int num[25000];
    for(int i = 0; i < index; i++){num[i] = i;}
    
    // ssの各要素の大小関係で、numをソートする
    // ソート後のnumの要素の中身xは、ss[x]がss全体の中で
    // 辞書順に並べたときにx+1番目に位置することを意味する
    // (要はssを直接ソートせずにnumをソートすることで、ssがソートできます)
    qsort(num, index, sizeof(int), compare_s);
    
    char tmp[6];
    strcpy(tmp, ss[num[0]]);
    
    int cnt = 1;
    if(index == 1){printf("%s\n", tmp); return 0;}
    
    for(int i = 0; i < index-1; i++){
        // if(strcmp(tmp, ss[num[i+1]])==0){
        //     continue;
        // }else{
        //     cnt++;
        //     strcpy(tmp, ss[num[i+1]]);
        // }
        if(strcmp(tmp, ss[num[i+1]])!=0){
            cnt++;
            strcpy(tmp, ss[num[i+1]]);
        }
        if(cnt == k){printf("%s\n", ss[num[i+1]]); return 0;}
    }
}



Measured memory_bytes: 508
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)

	ans := ""
	for i := 0; i < 3; i++ {
		if n[i] == '1' {
			ans += "9"
		} else {
			ans += "1"
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
n,m=map(int,input().split())
x=[0]*n
y=[0]*n
z=[0]*n
for i in range(n):
    x[i],y[i],z[i]=map(int,input().split())

sign=[0]*3
ans=0
for i in range(8):
    for j in range(3):
        if ((i >> j) & 1):  
            sign[j]=1
        else:
            sign[j]=-1
    tot=0
    arr=[0]*n
    for k in range(n):
        arr[k]=x[k]*sign[0]+y[k]*sign[1]+z[k]*sign[2]
    arr=sorted(arr,reverse=True)
    tot=sum(arr[:m])
    if tot>ans:
        ans=tot
print(ans)

Measured memory_bytes: 3188
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

S = input()
N = len(S)

l = S[:N//2]
r = S[N//2 + 1:]

if S == S[::-1] and l == l[::-1] and r == r[::-1]:
    print("Yes")
else:
    print("No")




    
    

Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;  
int main(){
int x, y;
cin >> x >> y;
if(1<=x && x<=12 && 1<=y && y<=31){
	}if (y>x or x==y){
		cout<<x<<endl;
	}
	else {
	cout<<x-1<<endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll a,b,n,m=0,z=0,z2;
   cin>>a>>b>>n;
   // rep(i,n+1){
   //    ll f1=a*i/b,f2=i/b;
   //    if(m<f1-(a*f2)){
   //       z=i;
   //    }
   //    if(m<=f1-(a*f2)){
   //       z2=i;
   //    }
   //    m=max(m,f1-(a*f2));

   // };
   ll f1;
   if(b<=n){
      f1=a*(b-1)/b;
   }else{
      f1=a*n/b;
   }
   
   cout<<f1<<endl;
   
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum += (ll)a[i];
  }
  ll snuke=0;
  ll ans=ll(1e15);
  for(int i=0;i<n-1;i++){
    snuke += (ll)a[i];
    ans = min(ans, abs(sum-2*snuke));
  }
  cout<<ans<<endl;
}


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

using namespace std;
vector<long long> factors;
#define ll long long


#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//



int main()
{
	IOS

	ll a,b;
	cin >> a >> b;
	ll q;
	cin >> q;
	vector<ll> s(a + 1);
	vector<ll> t(b + 1);
	for(int i = 0;i < a; ++i){
		cin >> s[i];
	}
	for(int i = 0;i < b; ++i){
		cin >> t[i];
	}
	s[a] = (LL_INF);
	t[b] = (LL_INF);
	while(q--){
		ll x;
		cin >> x;
		ll is = lower_bound(all(s),x) - s.begin();
		ll ti = lower_bound(all(t),x) - t.begin();

		ll lt,rt;
		ll ls,rs;
		if(is!=0 && is!= a){
			ls = s[is -1];
			rs = s[is];
		}else if(is == 0){
			rs = s[is];
			ls = -LL_INF;
		}else if(is == a){
			ls = s[is -1];
			rs = LL_INF;
		}


		if(ti!=0 && ti != b){
			lt = t[ti -1];
			rt = t[ti];
		}else if(ti == 0){
			rt = t[ti];
			lt = -LL_INF;
		}else if(ti == b){
			lt = t[ti - 1];
			rt = LL_INF;
		}

		ll w1 = max(abs(lt - x),abs(ls - x));
		ll w2 = max(abs(rt - x),abs(rs - x));
		ll w3 = rt - x + rt - ls;
		ll w4 = rs - x + rs - lt;
		ll w5 = x - ls + rt - ls;
		ll w6 = x - lt + rs - lt;
		cout << min(min(min(min(min(w1,w2),w3),w4),w5),w6) << '\n';
	}

	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<pair<pii, int>> vec;
    rep(t, 2) {
        rep(i, N) {
            int a, b;
            cin >> a >> b;
            vec.eb(mp(a, b), t);
        }
    }
    sort(ALL(vec));
    set<int> st;
    int ans = 0;
    for (auto dt : vec) {
        pii p = dt.fi;
        if (dt.se == 0) {
            st.insert(p.se);
        } else {
            auto it = st.lower_bound(p.se);
            if (it != st.begin()) {
                --it;
                st.erase(it);
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

class stack{
public:
  int S[101];
  int top;
  stack(){}
  void initialize(){ top = 0; }
  bool isEmpty(){ return top == 0; }
  bool isFull(){ return top >= 100; }
  void push(int x){
    if ( isFull() ) {
      cout << "error" << endl;
    }
    top++;
    S[top] = x;
  }
  int pop(){
    if ( isEmpty() ){
      cout << "error" << endl;
    }
    top--;
    return S[top+1];
  }
};

int main(){
  int a, b, x;
  string op;
  stack A;

  A.initialize();
  
  while( cin >> op ){
  	if ( isdigit(op[0]) ){
      A.push(atoi(op.c_str()));
    } else if ( op[0] == '+' ){
      b = A.pop();
      a = A.pop();
      A.push(a+b);
    } else if ( op[0] == '-' ){
      b = A.pop();
      a = A.pop();
      A.push(a-b);
    } else if ( op[0] == '*' ){
      b = A.pop();
      a = A.pop();
      A.push(a*b);
    }
  }
  cout << A.pop() << endl;
  return 0;
}
  


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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	int sn = 0;
	int nn = n;
	while(n){
		sn += n%10;
		n/=10;
	}
	
	if(nn%sn == 0)cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


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

int main(){
  string s, t;
  cin >> s >> t;
  vector<char> str1(s.size());
  vector<char> str2(t.size());
  rep(i, s.size()){
    str1[i] = s[i];
  }
  rep(i, t.size()){
    str2[i] = t[i];
  }
  sort(str1.begin(), str1.end());
  sort(str2.begin(), str2.end(), greater<char>());
  
  rep(i, s.size()){
    s[i] = str1[i];
  }
  rep(i, t.size()){
    t[i] = str2[i];
  }
  
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
      
  
}

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

void push(int);
int pop(void);
void calc(char *);//数値計算するだけの関数

int S[100];
int top=0;//スタックの一番上を記憶するための外部変数

int main(){
  int i,num;
  int answer=0, count=0;
  char n[100];

  while(scanf("%s",n) != EOF){
    if( n[0]=='*' || n[0]=='+' || n[0]=='-'){ //演算子かどうか判別
      calc(n);
      count++;
    }else{
      num = atoi(n);//文字型を数値型に変換
      push(num);
    }
  }
  printf("%d\n",S[0]);
  return 0;
}

void calc(char *n){
  int op;
  
  switch(n[0]){
  case '+':
    push(pop() + pop());
    break;
    
  case '-':
    op = pop();
    push(pop() - op);
    break;

  case '*':
    push(pop() * pop());
    break;
  }
}

void push(int n){
  S[top] = n;
  top++;
}

int pop(){
  return S[--top];
}
  



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef vector<int>   vi;

//Union find.
//O(m^m).
//refering to exp.
struct UnionFind{
	std::vector<int> par;//xの親はpar[x].x自身が親ならpar[x]<0で、-par[x]がその集合のサイズ.
	
	UnionFind(int n):par(n,-1){}//コンストラクタ.
	
	void reset(int n){par.assign(n,-1);}
	int root(int x){return par[x]<0?x:par[x]=root(par[x]);}//再帰.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y) return false;//do nothing.
		if(size(x)<size(y)) swap(x,y);//merge technique.
		par[x]+=par[y];
		par[y]=x;
		return true;
	}
};

int main(){
	int n,m;
	cin>>n>>m;
	
	vi a(m),b(m);
	REP(i,m){
		int aa,bb;
		cin>>aa>>bb;
		a[i]=aa-1;
		b[i]=bb-1;
	}
	
	int ans=0;
	REP(i,m){
		UnionFind uf(n);
		REP(j,m){
			if(i!=j) uf.unite(a[j],b[j]);//point.
		}
		
		int tmp=uf.root(0);
		for(int k=1;k<n;++k){
			if(uf.root(k)!=tmp){
				ans++;
				break;//for(k).
			}
		}
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
static const int MAX_N = 12;
int field[MAX_N][MAX_N];
static const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int stoi(std::string str) {
	int ret;
	std::stringstream ss;
	ss << str;
	ss >> ret;
	return ret;
}

void dfs(int y, int x) {
	field[y][x] = 0;
	for (int i = 0; i < 4; i++) {
		if (0 <= x + dx[i] && x + dx[i] < 12 && 0 <= y + dy[i] && y + dy[i] < 12 && field[y + dy[i]][x + dx[i]] == 1) {
			dfs(y + dy[i], x + dx[i]);
		}
	}
}

void printTable() {
	cout << "------------------" << endl;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 12; j++) {
			cout << field[i][j];
		}
		cout << endl;
	}
}

int main()
{
	string s = "";
	
	while (cin >> s) {
		int cnt = 0;
		if (s == "")break;
		//input
		for (int i = 0; i < 12; i++)field[0][i] = s[i] - '0';// stoi(s[i]);
		for (int i = 1; i < 12; i++) {
			cin >> s;
			for (int j = 0; j < 12; j++) {
				field[i][j] = s[j] - '0';// stoi(s[j]);
			}
		}
		//printTable();
		for (int i = 0; i < 12; i++) {
			for (int j = 0; j < 12; j++) {
				if (field[i][j] == 1) {
					cnt++;
					dfs(i, j);
			//		printTable();
				}
			}
		}	
		cout << cnt << endl;
	
	}


    return 0;
}

Measured memory_bytes: 3152
#include <stdio.h>
int main(void){
    int N, M, C;
    scanf("%d%d%d", &N, &M, &C);
    int B[M];
    int A[N][M];
    for (int i = 0; i < M; i++){
        scanf("%d", &B[i]);
    }
    for (int i = 0; i < N; i++){
        for (int j = 0; j < M; j++){
            scanf("%d", &A[i][j]);
        }
    }

    int ans = 0;
    int tmp;
    for (int i = 0; i < N; i++){
        tmp = 0;
        for (int j = 0; j < M; j++){
            tmp += A[i][j] * B[j];
        }
        if (tmp + C > 0){
            ans += 1;
        }
    }
    printf("%d\n", ans);

    return 0;
}


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


int main(){
    int N;
    int a[110];

    cin >> N;

    for(int i = 0; i < N; i++) cin >> a[i];

    int num[110] = {0};
    for(int i = 0; i < N; i++) num[a[i]] += 1;

    int res=0;

    for(int i = 0; i <= 100; i++){
        if(num[i] > 0) res++;
    }

    cout<<res<<"\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	int l = 0, r = N;
	vector<string> seat(N+1);
	string res, left_ideal, right_ideal;
	int left_dis;
	int query = 0;
	int next;

	cout<<query<<endl<<flush;
	cin>>res;
	if(res == "Vacant"){return 0;}
	seat[0] = res;
	seat[N] = res;
	query = (r+l)/2;
	while(true){
		cout<<query<<endl<<flush;
		cin>>res;
		seat[query] = res;

		if(res == "Vacant"){return 0;}
		left_dis = query-l;
		if(left_dis % 2 == 1){
			if(seat[l] == "Male"){ left_ideal = "Female"; }
			else{ left_ideal = "Male"; }
		}else{
			if(seat[l] == "Male"){ left_ideal = "Male"; }
			else{ left_ideal = "Female"; }
		}

		if(res == left_ideal){
			l = query;
			query = (r+l)/2;
		}else{
			r = query;
			query = (r+l)/2;
		}
	}
	return 0;
}

Measured memory_bytes: 1620