akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 205, MOD = 998244353;

class Point {
public:
  int x, y;
  Point(int _x = 0, int _y = 0) {
    x = _x, y = _y;
  }
  inline friend Point operator + (const Point &a, const Point &b) {
    return Point(a.x + b.x, a.y + b.y);
  }
  inline friend Point operator - (const Point &a, const Point &b) {
    return Point(a.x - b.x, a.y - b.y);
  }
} P[MAX_N];

int pw[MAX_N];

int cross(Point a, Point b) {
  return a.x * b.y - a.y * b.x;
}

int vis[MAX_N][MAX_N], st[MAX_N];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d%d", &P[i].x, &P[i].y);
  pw[0] = 1;
  for (int i = 1; i <= N; ++i) pw[i] = (pw[i - 1] + pw[i - 1]) % MOD;

  int result = pw[N] - 1;

  for (int i = 1; i <= N; ++i)
    for (int j = i + 1; j <= N; ++j) 
      if (!vis[i][j]) {
	int top = 0;
	for (int k = 1; k <= N; ++k)
	  if (cross(P[k] - P[i], P[k] - P[j]) == 0) st[++top] = k;
	result = (result - pw[top] + 1 + top) % MOD;
	for (int k1 = 1; k1 <= top; ++k1)
	  for (int k2 = 1; k2 <= top; ++k2)
	    vis[st[k1]][st[k2]] = 1;
      }
  result = (result - N) % MOD;
  printf("%d\n", (result + MOD) % MOD);
  return 0;
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 1e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

ll h[MAXN];
ll dp[MAXN];
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(dp, 31 , sizeof dp);
	ll n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> h[i];
	dp[0] = 0;
	//dp[1] = abs(h[0] - h[1]);
	for(int i = 1;i<n;i++){
		for(int j = i - 1; j >= max(i - k, 0ll); j--) dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	//debug(dp[4]);
	cout << dp[n-1];

	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


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

int main(int, char**) {
        int H, W;
        std::cin >> H >> W;
        std::vector<std::string> input(H);
        for (int i=0; i<H; i++) {
                std::cin >> input.at(i);
        }
        for (int i=0; i<H; i++) {
                std::cout << input.at(i) << std::endl;
                std::cout << input.at(i) << std::endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n&&n!=-1){
        int sum=3130,num[3]={125,140,160};
        for(int i=0;i<3;i++){
            n-=10;
            if(n>10&&i!=2)sum-=num[i]*10;
            else if(n>0)sum-=num[i]*n;
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1160
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn input<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn main() {
    let q = input::<i64>();
    let mut vec = Vec::new();
    for i in 0..q{
        let mut a = read_vec::<i64>();
        if a[0] == 0{
            vec.push(a[1]);
        }
        if a[0] == 1{
            let b = a[1] as usize;
            println!("{}", vec[b]);
        }
        if a[0] == 2{
            vec.pop();
        }
    }
}


Measured memory_bytes: 7084
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


vector<ll> a(6001);
ll dp[6001][6001];


void solve(int n){
    vector<ll> w(n);
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }
    ll dp[n+1][n+1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = 0;
        }
    }

    for(int len = 1; len <= n; len++){
        for(int l = 0; l < n; l++){
            int r = l+len;
            if(r > n) break;
            if(r-1 != l && dp[l+1][r-1] == len-2 &&abs(w[r-1]-w[l]) <= 1){
                dp[l][r] = dp[l+1][r-1]+2;
            }
            for(int mid = l; mid <= r; mid++){
                dp[l][r] = max(dp[l][r],dp[l][mid]+dp[mid][r]);
            }
        }
    }

    cout << dp[0][n] << endl;
}

int main(){
    int n;
    while(true){
        cin >> n;
        if(n == 0) break;
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <memory>
#include <map>
#include <array>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)



template<typename node_type>
class Node{
public:
    explicit Node(vector<node_type> _children,node_type _parent) : children(_children),parent(_parent){};
    ~Node(){};
    vector<node_type> children=NULL;
    node_type parent;
    int depth = -1;
    int condition_num;

    void children_print(){
        if(children.size()==0){
              return;
        }else{
            int n = children.size()-1;
            REP(i,n){
                cout << children[i] << ", ";
            }
            cout << children[n];
        }
    }
};

template<typename node_type>
class Tree{
public:
    map<node_type, Node<node_type> > tree;
    
    void parent_set(){
        for(auto x:tree){
            for(auto y :x.second.children){

                tree.at(y).parent = x.first;

            }
        }
    }
    void depth_set(){
        for(auto &x:tree){
        int tmp = 0;
        node_type tmp_node_key = x.first;
        while(tree.at(tmp_node_key).parent!=tmp_node_key){
            tmp++;
            
            tmp_node_key = tree.at(tmp_node_key).parent;
            
        }

        x.second.depth = tmp;
    }
    }
};

int main(){
    int n;
    cin >> n;
    Tree<int> t;

    int tmp,m,tmp_node_key;
    vector<int> tmp_node_children;
    REP(i,n){
        cin >> tmp_node_key;
        
        cin >> m;
        REP(j,m){
            cin >> tmp;

            tmp_node_children.push_back(tmp);

        }
        t.tree.insert(make_pair(tmp_node_key, Node<int>(tmp_node_children,tmp_node_key)));
        tmp_node_children.clear();
    }

    t.parent_set();
    t.depth_set();

    for(auto x:t.tree){
        cout << "node " << x.first << ": parent = "<<((x.second.parent!=x.first) ? x.second.parent : -1);

        cout << ", depth = "<<x.second.depth;
        cout << ", ";

    
        if(x.second.parent==x.first){
            cout << "root";
        }else{

            if(x.second.children.size()==0){
                cout << "leaf";
            }else{
                cout << "internal node";
            }
       }
        cout<< ", [";
        x.second.children_print();
        
        cout <<"]"<<  endl;
    }

    return 0;
}


Measured memory_bytes: 13240
S = input()
Q = int(input())
muki = True
sento = []
matubi = []
for _ in range(Q):
    L = input()
    if L[0] == '1':
        muki = not muki
    else:
        _, F, C = L.split()
        F = int(F)
        if (muki and F == 1) or ((not muki) and F == 2):
            sento.append(C)
        else:
            matubi.append(C)          

if muki:
    print(''.join(reversed(sento)), end='')
    print(S, end='')
    print(''.join(matubi))
else:
    print(''.join(reversed(matubi)), end='')
    print(''.join(list(reversed(S))), end='')
    print(''.join(sento))

Measured memory_bytes: 70232
import java.lang.*;
import java.math.*;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class a {
		LinkedList<Integer> list = new LinkedList<Integer>();

		a() {
			list = new LinkedList<Integer>();
		}
	}

	public void run() {
		for (;;) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if ((w | h) == 0) {
				break;
			}

			int[][] map = new int[w * h][4];
			a[] l = new a[h * w];
			int j;
			for (int z = 0; z < h * w; z++) {
				l[z] = new a();
			}

			for (j = 0; j < h - 1; j++) {
				for (int i = 0; i < w - 1; i++) {
					int d = sc.nextInt();
					if (d == 0) {
						l[i + 1 + j * w].list.add(i + j * w);
						l[i + j * w].list.add(i + 1 + j * w);
					}
				}
				for (int i = 0; i < w; i++) {
					int d = sc.nextInt();
					if (d == 0) {
						l[i + w + j * w].list.add(i + j * w);
						l[i + j * w].list.add(i + w + j * w);
					}
				}
			}
			for (int i = 0; i < w - 1; i++) {
				int d = sc.nextInt();
				if (d == 0) {
					l[i + 1 + j * w].list.add(i + j * w);
					l[i + j * w].list.add(i + 1 + j * w);
				}
			}

			boolean[] visited = new boolean[w * h];
			LinkedList<Integer> Q = new LinkedList<Integer>();
			Q.add(0);
			int now = 1;
			int depth[] = new int[h * w];
			boolean flag = true;
			int res = 0;
			for (; flag;) {
				LinkedList<Integer> nextQ = new LinkedList<Integer>();
				if (Q.isEmpty()) {
					res = 0;
					flag = false;
					break;
				}
				for (int k : Q) {
					depth[k] = now;
					visited[k] = true;
					for (int z : l[k].list) {
						if (!visited[z]) {
							if (!nextQ.contains(z)) {
								nextQ.add(z);
							}
						}
					}
					if (k == w * h - 1) {
						flag = false;
						res = now;
						break;
					}
				}
				Q = nextQ;
				now++;
			}
			System.out.println(res);
		}
	}

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

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

int main() {
	int n, d[100001];
	cin>>n; for(int i=0;i<n;i++) cin>>d[i];
	
	sort(d,d+n);
	
	cout<<d[n/2]-d[n/2-1];
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<pair<double,string>> a(n);
   cout << fixed << setprecision(8);
  for(int i=0;i<n;i++){
    double aa;
    string s;
    cin>>aa>>s;
   
    a[i]=make_pair(aa,s);
  }
  
  double ans=0;
  for(int i=0;i<n;i++){
    if(a[i].second=="JPY"){
      ans+=a[i].first;
    }
    else{
      ans+=a[i].first*380000.0;
      
    }
  }
  cout<<ans<<endl;
}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int r;cin>>r;
  if(r<1200){
    P("ABC");
    return 0;
  }else if(r<2800){
    P("ARC");
    return 0;
  }else{
    P("AGC");
  }
  return 0;
}


Measured memory_bytes: 256
#define _DEBUG 1

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve(ll A, ll B) {
  ll x = -1;

  rep(i, 1099) {
    if (floor(0.08 * i) == A && floor(0.10 * i) == B) {
      x = i;
      break;
    }
  }

  cout << x << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) (n int, err error) {
	sc.Scan()
	s := sc.Text()
	n, err = strconv.Atoi(s)
	return
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for {
		if a, err := nextInt(sc); err == nil {
			b, _ := nextInt(sc)
			switch {
			case a < b:
				fmt.Println("a < b")
			case a > b:
				fmt.Println("a > b")
			case a == b:
				fmt.Println("a == b")
			}
		} else {
			break
		}
	}
}



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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    cout << (N / X) * T + (N % X > 0 ? T : 0) << endl;
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;

typedef map <int, int> mii;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

int n;
llong a[MXN], pref[MXN];

int main () {
    android;
    //freopen ("input.txt", "r", stdin);
    //freopen ("output1.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    llong ans = 0, cur = 1;
    sort (pref, pref + n + 1);
    for (int i = 1; i <= n; i ++) {
        if (pref[i] == pref[i - 1]) {
            cur ++;
        }
        else {
            ans += cur * (cur - 1) / 2;
            cur = 1;
        }
    }
    ans += cur * (cur - 1) / 2;
    cout << ans;
    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;



signed main(){
	int n;
	ll x;
	cin>>n>>x;
	vector<ll>a(n);
	ll cnt=0;
	rep(i,n)cin>>a[i];
	rep(i,n-1){
		if(a[i]+a[i+1]>x){
			ll sub=a[i]+a[i+1]-x;
			ll cmp=min(sub,a[i+1]);
			cnt+=sub;
			a[i+1]-=cmp;
			a[i]-=sub-cmp;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int N;
int main(){
  cin >> N;
  bool judge = false;
  for(int i=0;i<=25;i++){
	if((N-4*i)%7==0 && N>=4*i) judge = true;
  }
  cout << (judge? "Yes":"No") << endl;
}

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

typedef string::const_iterator state;

string Cipher(state &begin);
string String(state &begin);
string Letter(state &begin);

string Letter(state &begin){
	string s;
	int count = 0;
	while(1){
		if(*begin=='+'){
			count +=1;
			begin++;
		}else if(*begin=='-'){
			count -=1;
			begin++;
		}else{
			break;
		}
	}
	char k = *begin;
	begin++;
	if(k=='?'){
		k = 'A';
	}else if(k+count>'Z'){
		k = 'A'+(k+count-'Z'-1)%26;
	}else if(k+count<'A'){
		k = 'Z'-('A'-k-count-1)%26;
	}else{
		k += count;
	}
	s.push_back(k);
	return s;
}

string String(state &begin){
	if(*begin =='['){
		begin++;
		string s = Cipher(begin);
		reverse(s.begin(),s.end());
		begin++;
		return s;
	}else{
		string s = Letter(begin);
		return s;
	}
}

string Cipher(state &begin){
	string s;
	while(1){
		if(*begin =='['){
			s += String(begin);
		}else if((*begin>='A'&&*begin<='Z')||*begin=='+'||*begin=='-'||*begin=='?'){
			s += Letter(begin);
		}else{
			break;
		}
	}
	return s;
}



int main(){
	string s;
	while(cin>>s && s!="."){
		state begin = s.begin();
		cout << Cipher(begin) << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
N = input()

if(N[-1] == "2" or N[-1] =="4"or N[-1] =="5" or N[-1] =="7" or N[-1] =="9"):
    print("hon")
elif(N[-1] == "0" or N[-1] =="1" or N[-1] =="6" or N[-1] =="8"):
    print("pon")
elif(N[-1] == "3"):
    print("bon")


Measured memory_bytes: 9056
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=0, ans=0;
	vector<int> pref(n+1);
	for(int i=0; i<n; ++i) {
		if(i!=0) pref[i] = pref[i-1];
		if(s[i]=='W') pref[i]++;
	}
	for(int i=n-1; i>=0; --i) {
		if(s[i]=='R') {
			if(pref[i]>cnt) {
				ans++;
				cnt++;
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 4400
program main
implicit none

integer*8 n,d,i,j
integer*8 :: x,y


read*,n,d
j=0
do i=1,n
  read*,x,y 
  if(((x**2+y**2)).le.d**2)then
    j = j+1
  endif
enddo
write(*,*) j
end program


Measured memory_bytes: 2880
// Date: 2020-02-28

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, m, p[N], a[N], b[N];

int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }

int main() {
    scanf("%d%d", &n, &m);
    rep(i, 1, n) scanf("%d", &a[i]), p[i] = i, b[a[i]] = i;
    rep(i, 1, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        u = Find(u), v = Find(v);
        if(u != v) p[u] = v;
    }
    int ans = 0;
    rep(i, 1, n) {
        int u = Find(b[i]), v = Find(i);
        if(u == v) ans++;
    }
    printf("%d\n", ans);


    return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
from collections import *
from bisect import *

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)

    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort(key=lambda t: t[0])
Xs = [X for X, _ in XH]
bit = BIT(N+1)
ans = 0

for i in range(N):
    X = XH[i][0]
    H = max(0, XH[i][1]-A*bit.acc(i+1))
    cnt = (H+A-1)//A
    ans += cnt
    j = bisect_right(Xs, X+2*D)
    bit.add(i, cnt)
    bit.add(j, -cnt)

print(ans)

Measured memory_bytes: 89692
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define VIN(i,n,v) REP(i,n){ \
	lli TMP; \
	cin>>TMP; \
	v.push_back(TMP);\
}

#define DEBUG 0

lli chmin(lli a,lli b){
	if(a>=b)return b;
	else return a;
}


	lli **d;
	lli **c;
	lli **nowC;
lli ans=10000000000;

void calc(lli now,lli *flag,lli C,lli targetC,lli cost){
	if(DEBUG)cout<<"now="<<now<< "targetC = "<<targetC<<endl;
	if(now==3){
		if(DEBUG)cout<<"cost="<<cost<<endl;
		ans = chmin(ans,cost);
	}
	else{
		for(lli i=1;i<=C;i++){
			cost += d[i-1][targetC-1] * nowC[now][i];
		}
		if(now==2){
			calc(now+1,flag,C,0,cost);
		}
		else{
			for(lli i=1;i<=C;i++){
				if(flag[i]==1)continue;
				flag[i]=1;
				calc(now+1,flag,C,i,cost);
				flag[i]=0;
			}
		}
	}
}

int main(){


	lli N,C;
	cin>>N>>C;

	d = new lli* [C];
	REP(i,C){
		d[i] = new lli[C];
		REP(j,C){
			cin>>d[i][j];
		}
	}

	c = new lli* [N];
	nowC = new lli* [3];
	REP(i,3){
		nowC[i] = new lli[C+1];
		REP(j,C+1){
			nowC[i][j]=0;
		}
	}
	REP(i,N){
		c[i] = new lli[N];
		REP(j,N){
			cin>>c[i][j];
			nowC[(i+j)%3][c[i][j]]++;
		}
	}

	lli *flag;
	flag = new lli[C];
	REP(i,C){
		flag[i]=0;
	}

	for(lli i=1;i<=C;i++){
		flag[i]=1;
		calc(0,flag,C,i,0);
		flag[i]=0;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2176
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
//#include <cstdio>
//#include <cstdlib>
//#include <cmath>
#include <iostream>
#include <algorithm>
//#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int a, b;
	
	while(cin >> a >> b){
	int num = a + b;
	int result = 0;
	
	if(num == 0) result++;
	while(num != 0){
		result++;
		num /= 10;
	}
	
	cout << result << endl;
	}

	return 0;
}

/*
for(i=0;i<N;i++){
	cin >> X[i];
}


for(i=0;i<N;i++){
	for(j=0;j<N;j++){
		cin >> X[i][j];
	}
}
*/

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

	set<string> st;
	set<string>::iterator it;
	string s1, s2;
	int n;
	cin >> n;

	while (n--) {
		cin >> s1 >> s2;
		if (s1 == "insert") {
			st.insert(s2);
		}
		else {
			it = st.find(s2);
			if (it != st.end()) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 27816
#include<bits/stdc++.h>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int p[8],q;
signed main(){
	int i,j;
	cin>>a;
	for(i=0;i<a;i++){
		int u;
		cin>>u;
		if(u>=3200)
			q++;
		else
			p[u/400]++;
	}
	int ans=0;
	for(i=0;i<8;i++)
		if(p[i])
			ans++;
	cout<<((ans==0)?1:ans)<<" "<<ans+q<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(M: "List[int]", D: "List[int]"):
    if M[0] != M[1]:
        print(1)
    else:
        print(0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = [int()] * (2)  # type: "List[int]"
    D = [int()] * (2)  # type: "List[int]"
    for i in range(2):
        M[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(M, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    string s; cin >> s;
    int a = 0, z = 0;
    rep(i, s.size() - 1) {
        if(s[i] == 'A') {
            a = i;
            break;
        }
    }
    for(int i = s.size() - 1;i >= a + 1; --i) {
        if(s[i] == 'Z') {
            z = i;
            break;
        }
    }
    print(z - a + 1);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define min_pq priority_queue<pll, vector<pll>, greater<pll> >
#define vpii vector<pair<int,int> >
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define modulo %
#define moduloe %=

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
ll add(ll a, ll b) {a+=b; while(a >= mod) a-= mod; while(a<0) a+= mod;}
ll mul(ll a, ll b) {return (a * 1LL *b % mod);}
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 500006;
const lf EPS = 0.000000001;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[102][100010];
ll w[110], v[110];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        ll W;
        cin>>n>>W;
        rep1(i, 1, n)
            cin>>w[i]>>v[i];

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=W;j++)
            {
                dp[i][j] = dp[i-1][j];
                if(j - w[i] >= 0)
                    dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
            }
        }

        ll ans = 0;
        for(i=0;i<=W;i++)
            ans = max(ans, dp[n][i]);
        cout<<ans<<endl;

    }
    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
    for (int i = g; i < n; i++){
        int v = A[i];
        int j = i - g;
        while( j >= 0 && A[j] > v ){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n){
    for (int h = 1;;){
        if (h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }
    
    for (int i = G.size()-1; i >= 0; i--){
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> A[i];
    }
    cnt = 0;
    
    shellSort(A, n);
    
    cout << G.size() << endl;
    for (int i = G.size()-1; i >= 0; i--){
        cout << G[i];
        if(i)   cout << " ";
    }
    cout << endl;
    cout << cnt << endl;
    for (int i = 0; i < n; i++){
        cout << A[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 7020
using System;
using System.Linq;

namespace B_001_60
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var logic = new LogicClass();
            var str = Console.ReadLine().Split(' ');
            var a = str[0];
            var b = str[1];
            var c = str[2];

            if (a.Last() == b.First() && b.Last() == c.First())
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        public class LogicClass
        {
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

vector<ll> edge[200100];
ll in[200100];
int used[200100];
vector<ll> lis;
ll ans[200100];

void go(int x) {
    int y, i;
    used[x] = 1;
    ll st(0), ed(sz(lis));
    while (st != ed) {
        ll mi = (st + ed) / 2;
        if (lis[mi] >= in[x]) {
            ed = mi;
        } else {
            st = mi + 1;
        }
    }
    ll prev(-1);
    if (st == sz(lis)) {
        lis.pb(in[x]);
    } else {
        prev = lis[st];
        lis[st] = in[x];
    }
    ans[x] = sz(lis);
    rep(i, sz(edge[x])) {
        y = edge[x][i];
        if (used[y]) continue;
        go(y);
    }
    if (prev == -1) {
        lis.pop_back();
    } else {
        lis[st] = prev;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    int i;
    cin >> n;
    rep(i, n) cin >> in[i+1];
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        edge[x].pb(y);
        edge[y].pb(x);
    }
    go(1);
    xrep(i, 1, n + 1) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 27008
#include<bits/stdc++.h>
using namespace std;
int a[35]={0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
int main()
{
	int n;
	cin>>n;
	cout<<a[n];
	return 0;
}

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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> a(N);

  for (auto& a_i: a) {
    cin >> a_i;
    a_i--;
  }
  // ボタン1が光ってる
  int on_index = 0;
  vector<bool> visited(N, false);
  bool is_ok = true;

  int count = 0;
  while (true) {
    count++;
    if (a.at(on_index) == 1) {
      break;
    }
    if (visited.at(on_index)) {
      is_ok = false;
      break;
    }
    visited.at(on_index) = true;
    on_index = a.at(on_index);
  }

  if (is_ok) {
    printf("%d\n", count);
  } else {
    printf("%d\n", -1);
  }
}

void answer2() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> a(N);

  for (auto& a_i: a) {
    cin >> a_i;
    a_i--;
  }

  int count = 0;
  int index = 0;
  bool is_ok = false;
  while (count < N) {
    if (index == 1) {
      is_ok = true;
      break;
    }
    index = a.at(index);
    count++;
  }
  if (is_ok) {
    printf("%d\n", count);
  } else {
    printf("%d\n", -1);
  }
}

int main() {
  //answer1();
  answer2();
}


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

int main(){
	int n, d; cin >> n >> d;
	vector<vector<int>> vec(n, vector<int>(d));
	int ans =0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < d; ++j){
			cin >> vec[i][j];
		}
	}
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			int norm = 0;
			for(int k = 0; k < d; ++k){
				int diff = abs(vec[i][k] - vec[j][k]);
				norm += diff * diff;
			}
			bool flag = false;
			for(int k = 0; k <= norm; ++k){
				if(k * k == norm){
					flag = true;
				}
			}
			if(flag) ++ans;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,c;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  if(((a == b)&&(a != c))||((a != b)&&(a == c))||((b == c)&&(a != b))){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll N;
ll A[222222];
ll Max = 0;

ll calc(ll b) {
   ll ret = 0;
   rep (i, N) {
      ret += abs(A[i] - (b+i+1));
   }
   return ret;
}

int main() {
   cin >> N;
   rep (i, N) {
      cin >> A[i];
      A[i] -= (i+1);
   }
   sort(A, A+N);

   int b = N/2;
   int c = (N+2-1)/2;

   ll ans1 = 0, ans2 = 0;
   rep (i, N) {
      ans1 += abs(A[i]-A[b]);
   }
   rep (i, N) {
      ans2 += abs(A[i]-A[c]);
   }

   cout << min(ans1, ans2) << endl;
   exit(0);

   for (int b = -10; b <= 10; b++) {
      int ret = 0;
      rep (i, N) {
         ret += abs(A[i] - b);
         cout << abs(A[i]-b) << " ";
      }
      cout << endl;
      printf("b: %3d, ret: %3d\n", b, ret);
   }


   return 0;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    s = [int(input()) for i in range(N)]
    s.sort()
    ans = sum(s)
    i = 0
    while ans%10 == 0:
        if i == len(s):
            ans = 0
            break
        ans -= s[i]
        if i != 0:
            ans += s[i-1]
        i += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string> 
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int main(){
	ll n,m;
	read(n),read(m);
	cout<<max((ll)0,n-2*m)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

ll a[100003];
ll dp[2][100003];
ll sum[2][100003];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	if (a[0] > 0) {
		dp[0][0] = 0;
		dp[1][0] = a[0] + 1;
		sum[0][0] = a[0];
		sum[1][0] = -1;
	}
	else if (a[0] == 0) {
		dp[0][0] = dp[1][0] = 1;
		sum[0][0] = 1;
		sum[1][0] = -1;
	}
	else {
		dp[0][0] = abs(a[0]) + 1;
		dp[1][0] = 0;
		sum[0][0] = 1;
		sum[1][0] = a[0];
	}
	for (int i = 1; i < n; ++i) {
		ll s = sum[0][i - 1] + a[i];
		if (s >= 0) {
			dp[1][i] = dp[0][i - 1] + s + 1;
			sum[1][i] = -1;
		}
		else {
			dp[1][i] = dp[0][i - 1];
			sum[1][i] = s;
		}
		s = sum[1][i - 1] + a[i];
		if (s <= 0) {
			dp[0][i] = dp[1][i - 1] + abs(s) + 1;
			sum[0][i] = 1;
		}
		else {
			dp[0][i] = dp[1][i - 1];
			sum[0][i] = s;
		}
	}

	
	cout << min(dp[0][n - 1], dp[1][n - 1]) << endl;
	return 0;
}

Measured memory_bytes: 4096
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

L, R = get_ints

MOD = 2019

if R - L >= MOD
  puts 0
else
  l = L % MOD
  r = R % MOD

  if r < l
    r += MOD
  end

  min = nil
  [*l..r].combination(2) do |a, b|
    res = (a * b) % MOD
    min = res if min.nil? || res < min
  end

  min = min + 1 - 1
  puts min
end


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

int main(){
    int n, k; cin >> n >> k;
    vector<int> l(n);
    rep(i,n) cin >> l[i];

    sort(l.begin(), l.end(), greater<int>());

    put(accumulate(l.begin(), l.begin() + k, 0));
}

Measured memory_bytes: 256
#include <cstdio>
#define rg register

const int N=200001,p=1e9+7;
int fac[N],inv[N],n,a,W,H,A,B;

inline int c(int x,int y) {return 1ll*fac[x]*inv[y]%p*inv[x-y]%p;}

inline int qpow(int A,int B){int r=1;for(;B;B>>=1,A=1ll*A*A%p)if(B&1)r=1ll*r*A%p;return r;}
inline void pls(int&A,long long B){A=A+B<p?A+B:A+B-p;}
inline int max(int A,int B){return A>B?A:B;}

int main(){
	scanf("%d%d%d%d",&H,&W,&A,&B);
	int lim=max(H-A+B-2,W-B+H);
	fac[0]=inv[0]=1;
	for(rg int i=1;i<=lim;++i)fac[i]=1ll*fac[i-1]*i%p;
	inv[lim]=qpow(fac[lim],p-2);
	for(rg int i=lim-1;i;--i)inv[i]=1ll*inv[i+1]*(i+1)%p;
	for(rg int i=0;i<H-A;++i)
		pls(a,1ll*c(i+B-1,i)*c(W-B+H-i-2,W-B-1)%p);
	printf("%d\n",a);return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<functional>
typedef long long ll;

using namespace std;

void dfs(int now, vector<vector<int>>& G, int fromCol, map<pair<int, int> , int>& cols){
    int cnt=1;
    for(auto nei:G[now]){
        int a = nei<now ? nei : now;
        int b = nei<now ? now : nei;
        auto key=make_pair(a,b);
        if(cols.count(key) == 0){
            if(fromCol == cnt){cnt++;}
            cols[key] = cnt;
            dfs(nei, G, cnt, cols);
            cnt++;
        }
    }
}


int main(){
    int N;
    cin >> N;
    vector<vector<int>> mp(N, vector<int>());
    map<pair<int, int>, int> vertex;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        mp[a-1].push_back(b-1);
        mp[b-1].push_back(a-1);
        vertex[make_pair(a-1, b-1)] = i;
    }
    int mxCol = 0;
    int start = -1;
    for(int i=0;i<N;i++){
        if(mxCol < mp[i].size()){
            mxCol = mp[i].size();
            start = i;
        }
    }
    vector<int> res(N-1, -1);
    map<pair<int, int> , int> cols;

    dfs(start, mp, 0, cols);
    for(auto k:cols){
        res[vertex[k.first]] = k.second;
    }
    cout << mxCol << endl;
    for(int i=0;i<N-1;i++){
        cout << res[i] << endl;
    }
    return 0;
}


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

int main(){
  int N;
  cin >>N;
  vector<int> a(N+1);
  rep(i,N) cin >> a[i+1];
  vector<int> b(N+1);
  int count = 0;
  for(int i=N; i>0; i--){
    int sum = 0;
    for(int j = i+i; j<N+1; j += i){
      sum += b[j];
    }
    if(sum%2 == a[i]){
    }else{
      b[i] = 1;
      count ++;
    }
  }
  cout << count << endl;
  if(count){
    rep(i,N) if(b[i+1]) cout << i+1 << " ";
    cout << endl;
  }
}

Measured memory_bytes: 2432
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int n, m;

  vector<int> visited;
  vector<vector<int>> g;
  int num_visited = 0;
  int ans = 0;

  void dfs(int now){
    visited[now] = 1;
    num_visited++;

    if(num_visited == n){
      ans++;
    }
    for(int i=0; i<g[now].size(); i++){
      int next = g[now][i];
      if(! visited[next]) dfs(next);
    }
    visited[now] = 0;
    num_visited--;
  }

int main()
{
  
  cin >> n >> m;
  g = vector<vector<int> > (n);
  visited = vector<int> (n, 0);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;

    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
  cout << ans << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()

int main()
{
    int n, d;
    cin >> n >> d;
    int w = 2 * d + 1;
    cout << (n + w - 1) / w << endl;
    return 0;
}

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

if 400<=x<600:
  print(8)
  
elif 600<=x<800:
  print(7)
elif 800<=x<1000:
  print(6)
elif 1000<=x<1200:
  print(5)
elif 1200<=x<1400:
  print(4)
elif 1400<=x<1600:
  print(3)
elif 1600<=x<1800:
  print(2)
else:
  print(1)

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

int main()
{
  ll N; cin >> N;
  vector<pair<int, int>> A(N);
  for (int i=0; i<N; i++){
    int t; cin >> t;
    A[i] = make_pair(t, i+1);
  }
  sort(A.begin(),A.end());
  for (int i=0; i<N; i++) {
    if (i==0) cout << A[i].second;
    else cout << " " << A[i].second;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<pair<string,int>> s={{"a",1}},ns;
    fr(i,n-1){
        for(auto&p:s){
            string t;
            int q;
            tie(t,q)=p;
            fr(j,q) ns.emplace_back(t+(char)('a'+j),q);
            ns.emplace_back(t+(char)('a'+q),q+1);
        }
        s.swap(ns);
        ns.clear();
    }
    sort(s.begin(),s.end());
    for(auto&p:s) cout<<p.first<<'\n';
    cout<<endl;

}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  double r1, r2;
  cin >> r1 >> r2;

  cout << fixed << setprecision(15) << (r1*r2)/(r1+r2) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int H=0, W=0;
		String str = null;
		String[] input = new String[2];
		int i, j;

		while(true){
			str = scan.nextLine();
			input = str.split(" ");
			H = Integer.parseInt(input[0]);
			W = Integer.parseInt(input[1]);
			if(H==0 && W==0){
				break;
			}
			for(i=0; i<H; i++){
				for(j=0; j<W; j++){
					if(((i+j)%2) == 0){
						System.out.print("#");
					}
					else{
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 34688
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld float
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell (ll)1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll n ;
    string s ;
    cin >> s ;
    n = sz(s) ;
    ll cnt = 0 ;
    rep( i , 0 , n )
        cnt += (s[i]=='o');
    cnt + 15 - n >= 8 ? cout << "YES" : cout << "NO" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


Measured memory_bytes: 256