akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
ll n,a[4000005];
ll b[22][22],c[22];
ll solve(ll index,ll g)
{
	if(g==n)return 1;
	ll ans=0;
	if(a[index]>-1)return a[index];
	For(i,n)
	{
		if(b[g][i]==0)continue;
		if(index&c[i])continue;
		ans+=solve(index^c[i],g+1);
		ans%=mod;
	}
	return a[index]=ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	cin>>n;
  	c[0]=1;
  	for(int i=1;i<22;i++)c[i]=c[i-1]*2;
  	For(i,n)For(j,n)cin>>b[i][j];
  	For(i,4000005)a[i]=-1;
  	cout<<solve(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 31488
//二次元幾何ライブラリ
#include <iostream>
#include <complex>
#include <map>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define X real()
#define Y imag()
typedef long double D;
typedef bool B;
typedef complex<D> P;   //点
typedef complex<D> V;   //ベクトル
typedef pair<P,P>  L;   //直線
typedef pair<P,D>  C;   //円
typedef vector<P>  Pol; //多角形

//変数名定義
const D INF = 1e100;
const D EPS = 1e-8;
const D PI = acos(-1);

template<class T> bool operator==(T a, T b){return abs(a - b )< EPS;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}

  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }

// ベクトルaの絶対値を求める
// D Length = abs(a);

// 2点a,b間の距離を求める
// D Distance = abs(a-b); 

// 内積 (Inner Product) : a・b = |a||b|cosθ
D IP(V a, V b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// 外積 (Exterior Product) : a×b = |a||b|sinθ
D EP(V a, V b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

// 点の進行方向について 3
int ccw(P a, P b, P c) {              //点aと点bが与えられた問いに
  b -= a; c -= a;
  if (EP(b, c) > EPS)   return +1;      // counter clockwise
  if (EP(b, c) < -EPS)   return -1;      // clockwise
  if (IP(b, c) < -EPS)     return +2;    // c--a--b on line
  if (norm(b) < norm(c)) return -2;   // a--b--c on line
  return 0;                           // a--c--b on line  aとbの線分判定はこれ
}

int main(void){
	while(true){
		P point[4];	
		int tmp;
		rep(j,4)
		cin >> point[j].X >> point[j].Y;
		if(cin.eof())
			break;
		int ccw1,ccw2,ccw3;
		ccw1=ccw(point[0],point[1],point[3]);
		ccw2=ccw(point[1],point[2],point[3]);
		ccw3=ccw(point[2],point[0],point[3]);
		if(ccw1==ccw2&&ccw2==ccw3)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
h,w = map(int,input().split())
L = [[0] * (w) for _ in range(h)]
#print(L)
for i in range(h):
    tmp = list(input())
    #print(tmp)
    for j in range(w):
        #print(i,j)
        if tmp[j] == "#":
            #print(i,j)
            L[i][j] = "#"

#print(L)

for i in range(h):
    for j in range(w):
        if L[i][j] == "#":
            try:
                L[i+1][j] += 1
            except:
                pass
            try:
                if i-1>=0:
                    L[i-1][j] += 1
            except:
                pass
            try:
                L[i][j+1] += 1
            except:
                pass
            try:
                if j-1>=0:
                    L[i][j-1] += 1
            except:
                pass
            try:
                L[i+1][j+1] += 1
            except:
                pass
            try:
                if i-1>=0 and j-1>=0:
                    L[i-1][j-1] += 1
            except:
                pass
            try:
                if i-1>=0:
                    L[i-1][j+1] += 1
            except:
                pass
            try:
                if j-1>=0:
                    L[i+1][j-1] += 1
            except:
                pass

for i in L:
    i = list(map(str,i))
    print("".join(i))


Measured memory_bytes: 41712
package main

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

const (
	MAX = 1000000000000000000
)

func getStdin() []string {
	stdin := bufio.NewScanner(os.Stdin)
	lines := []string{}
	for stdin.Scan() {
		if err := stdin.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
		lines = append(lines, stdin.Text())
	}
	//	readLine()
	return lines
}

func main() {
	l := strings.Split(getStdin()[0], " ")
	l2 := strings.Split(l[1], ".")
	a, _ := strconv.Atoi(l[0])
	b1, _ := strconv.Atoi(l2[0])
	b2, _ := strconv.Atoi(l2[1])
	b := (b1 * 100) + b2
	r := (a * b) / 100
	fmt.Println(r)
}


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

const int INF = 2147483647;

template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}

int main(){

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

    int min = INF;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(chmin(min,P[i])){cnt++;}
        //cout << min << " " << cnt << endl;
    }

    cout << cnt << endl;
}

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

int main()
{
    int k, a, b, p = 0;
    cin>>k;
    cin>>a>>b;
    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            cout<<"OK"<<"\n";
            p++;
            break;
        }
    }
    if(p == 0)
    {
        cout<<"NG"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int a;
string s, p;

int main()
{    
    cin >> p;
    while (cin >> s)
    {
        if (s == "END_OF_TEXT")
        {
            cout << a << endl;
            return 0;
        }
        for (int i = 0; i < s.size(); i++)
        {
            s[i] = ('A' <= s[i] && s[i] <= 'Z' ? (char)(s[i] + 'a' - 'A') : s[i]);
        }
        a += (s == p);
    }
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
 
using namespace std;
int main()
 
{
  string s;
 
  cin>>s;
 
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
    cout<<"Bad"<<endl;
  }
 
  else {
    cout<<"Good"<<endl;
  }
 
return 0;
 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

	int yama[10];
	
	for(int i = 0; i <= 9; i++) {
	cin >> yama[i];
	}
	
	for(int i = 0; i <= 8; i++) {
		for(int j = i + 1; j <= 9; j++) {
			if(yama[i] < yama[j]){
				int x = yama[i];
				yama[i] = yama[j];
				yama[j] = x;
			}
		}
			
	}
	cout << yama[0] << endl << yama[1] << endl << yama[2] << endl;
	
    return 0;
}

Measured memory_bytes: 1160
import math

n, a, b = map(int, input().split())


def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c


mod = 10**9+7

ans = pow(2, n, mod)
ans -= 1
ans -= cmb(n, a, mod)
ans -= cmb(n, b, mod)

while ans<0:
    ans+=mod
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  int a;
  cin >> a;
  cout << a + pow(a,2) + pow(a,3) << endl;
}

Measured memory_bytes: 4128
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> right(n,0);
    vector<ll> left(n,0);
    REP(i,n){
        cin >> a[i];
        if(i+a[i]<n-1){
            right[i+a[i]]++;
        }
        if(i-a[i]>0){
            left[i-a[i]]++;
        }
    }
    ll ans=0;
    REP(i,n){
        ans+=right[i]*left[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 8028
n = int(input())
dp = [0]
for i in range(1,n+1):
  can = []
  cnt9 = 1
  cnt6 = 1
  while i >= 9 ** cnt9:
    here = i - 9 ** cnt9
    can.append(dp[here] + 1)
    cnt9 += 1
  while i >= 6 ** cnt6:
    here = i - 6 ** cnt6
    can.append(dp[here] + 1)
    cnt6 += 1
  can.append(dp[i-1] + 1)
  dp.append(min(can))
print(dp[-1])

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n; cin>>n;
  vector<int> a(n), b(n);
  forn(i,n) cin>>a[i]>>b[i];
  sort(all(a));
  sort(all(b));
  if(n&1){
  	cout<<(b[n/2] - a[n/2] + 1)<<endl;
  }
  else{
  	cout<<(b[n/2]+b[(n)/2 - 1] - a[(n)/2] - a[(n)/2 - 1] + 1)<<endl;
  }
  return 0;
}

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

int main() {
  int N, A, pre, cnt = 0;
  cin >> N >> pre;
  int b = 3;
  while (cin >> A) {
    if (b == 1 && A < pre) cnt++, b = 3;
    else if (b == 2 && A > pre) cnt++, b = 3;
    else if (b == 3 && A > pre) b = 1;
    else if (b == 3 && A < pre) b = 2;
    pre = A;
  }
  cout << cnt + 1 << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    string s,t;cin>>s>>t;
    ll a=s.size();
    ll ans=0;
    rep(i,a) {
        if(s[i]!=t[i]) {
            ans++;
        }
    }
    cout <<ans<<endl;
}

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

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    vector<bool> isGettable(n, true);
    map<char, int> mp;
    mp['r'] = p;
    mp['s'] = r;
    mp['p'] = s;

    int ans = 0;
    for(int i = 0; i < n - k; i++) {
        if(t[i] == t[i + k] && isGettable[i]) {
            isGettable[i + k] = false;
        }
    }

    for(int i = 0; i < n; i++) {
        if(isGettable[i]) {
            ans += mp[t[i]];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,j,k) for(int i=j;i>=k;--i)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int main() {
	static ll n, m = 0, A[1010101], B[1010101];
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		m += A[i];
	}
	cout << m - n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

 int selection(int A[],int n){
            int i,j,count=0,minj,t;
            for(i=0;i<n;i++){
                     minj=i;
                     for(j=i;j<n;j++){
                             if(A[minj]>A[j])minj=j;
                             }
                     if(i != minj){t=A[minj];A[minj]=A[i];A[i]=t;count++;}
                     }
            return count;
            }

 int main(){
       int i,j,A[100],n,x;
       scanf("%d",&n);
       for(i=0;i<n;i++){scanf("%d",&A[i]);}

       x=selection(A,n);
       for(i=0;i<n;i++){printf("%d%c",A[i],(i==n-1)?'\n':' ');}
       printf("%d\n",x);
       return 0;
       }


Measured memory_bytes: 2124
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let N = Int(input_line)!
 
var Pi = [Int]()
let input_line2 = readLine()!

let splits = input_line2.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
Pi = splits.map {Int($0)!}

var counter = 0

for i in 0..<N - 2 {
    if Pi[i] < Pi[i + 1] && Pi[i + 1] < Pi[i + 2] {
        counter += 1
    } else if Pi[i + 2] < Pi[i + 1] && Pi[i + 1] < Pi[i] {
        counter += 1
    }
}
print(counter)

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

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

using namespace std;

int A[100001];

int partition(int p, int r){
  int i;
  i = p-1;

  REP(j, p, r){
    if(A[j] <= A[r]){
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  
  return i+1;
}


signed main(){
  int n;
  cin >> n;
  rep(i, n){
    cin >> A[i];
  }

  int ret = partition(0, n-1);
  
  rep(i, n){    
    if(i > 0) cout << " ";
    if(ret == i){
      cout << "[" << A[i] << "]";
    }else{
      cout << A[i];
    }
  }
  puts("");
}

Measured memory_bytes: 3380
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static string s = "";
    static string[] ss;
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static int[] arr;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        if (n == 0)
        {
            arr = new int[n];
        }
        if(num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        ss = rls();
        arr = new int[ss.Length];
        for (int i = 0; i < ss.Length; i++)
        {
            arr[i] = Int(ss[i]);
        }
        Array.Sort(arr);

        for (int i = 0; i < ss.Length; i++)
        {
            if (i > 0) sum += arr[i] - arr[i - 1];
        }
        Sum();
    }


}



Measured memory_bytes: 13140
# Data structure
class Edge
	def initialize(src,dst,cost)
		@src = src
		@dst = dst
		@cost = cost
	end
	def <(another)
		if @cost != another.cost
			return @cost < another.cost
		else
			return @src < another.src
		end
	end

	attr_accessor :src, :dst, :cost
end

# SkewHeap for Priority-Queue
class Heap
	class Node
		def initialize(value)
			@left=nil
			@right=nil
			@value=value
		end
		attr_accessor :value,:right,:left
	end
	
	def initialize()
		@size = 0
		@root = nil
	end

	def meld a,b
		if a == nil
			return b
		end
		if( b == nil )
			return a
		end
		if b.value < a.value 
			a,b=b,a
		end
		a.right = meld(a.right,b)
		a.left,a.right=a.right,a.left
		return a
	end
	
	def top
		@root.value
	end
	
	def pop
		@size -= 1
		@root=meld(@root.left,@root.right)
	end

	def push x
		@size += 1
		@root=meld(@root,Node.new(x))
	end
	attr_accessor :size
end
# Main
n,q=gets.split.map{|n|n.to_i}
g = Array.new(n,0);


que = Heap.new();

q.times{
	a,v=gets.split.map{|n|n.to_i}
	a -= 1;
	g[a] -= v;
	que.push(Edge.new(a,a,g[a]));
	while que.size != 0
		q = que.top()
		if g[q.src] != q.cost
			que.pop()
		else
			break
		end
	end	
	puts "#{que.top().src+1} #{-que.top().cost}"
}

Measured memory_bytes: 57300
X, Y = list(map(int, input().split()))

if (Y - 2 * X) % 2 > 0:
    print('No')
    exit()

b = (Y - 2 * X) / 2
a = X - b

if b >= 0 and a >= 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

map < int, int > M;
int n;

int main()
{
    scanf("%d", &n);
    for(int i = 0;i < n;++i)
    {
        int x;
        scanf("%d", &x);
        ++M[x];
    }
    int ans = 0;
    for(map < int, int >::iterator it = M.begin();it != M.end();++it)
    {
        int x = it -> second;
        if(M.find((it->first) + 1) != M.end())
            x += M[(it->first) + 1];

        if(M.find((it->first) - 1) != M.end())
            x += M[(it->first) - 1];
        ans = max(ans, x);
    }

    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

typedef long long ll;

long long test_cases;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    /* cin >> test_cases; */
    test_cases = 1;

    int x, n;
    set<int> p;


    while (test_cases > 0)
    {
        cin >> x >> n;
        for (int i = 0; i < n; i++)
        {
            int pi;
            cin >> pi;
            p.insert(pi);
        }

        if (p.find(x) != p.end())
        {
            int pos_first = x + 1;
            for (int i = x + 1; p.find(i) != p.end(); i++)
            {
                pos_first = i + 1;
            }
            /* cout << "pos_first: " << pos_first << endl; */
            int neg_first = x - 1;
            for (int i = x - 1; p.find(i) != p.end(); i--)
            {
                neg_first = i - 1;
            }
            /* cout << "neg_first: " << neg_first << endl; */
            if ((abs(pos_first - x) == abs(neg_first - x)))
            {
                cout << min(pos_first, neg_first) << endl;
            }
            else
                if (abs(pos_first - x) < abs(neg_first - x))
                    cout << pos_first << endl;
                else
                    cout << neg_first << endl;
        }
        else
            cout << x << endl;
        
        
        test_cases--;
    }

    
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long 
#define fast ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int N=100002;
vector<vector<int>>g;
int dp[N],in_degree[N];
bool vis[N];
void dfs(int node)
{
    vis[node]=true;
    for(auto u:g[node]){
        dp[u]=max(dp[u],dp[node]+1);
        in_degree[u]--;
        if(in_degree[u]==0)dfs(u);
    }
}


int main()
{
    fast
    int ans=0,n,m;cin>>n>>m;
    g.assign(n+1,vector<int>());
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        in_degree[v]++;
    }
    for(int i=1;i<=n;i++)
        if(!vis[i]&&in_degree[i]==0)
            dfs(i);
    for(int i=1;i<=n;i++)
        ans=max(ans,dp[i]);
cout<<ans;
return 0;
}

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

int N;
string S;

int main(){
    cin >> N >> S;
    string number;
    int ans = 0;
    for (int i = 0; i < 1000; i++){
        number = to_string(i);
        if (number.size() == 1){
            number = "00" + number;
        }
        else if (number.size() == 2){
            number = "0" + number;
        }
        int idx = 0;
        for (int j = 0; j < S.size(); j++){
            if (S[j] == number[idx]){
                idx += 1;
            }
            if (idx == 3){
                ans += 1;
                break;
            }
            
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3740
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(((a==1)&&(b==2))||((a==2)&&(b==1)))
    {
        printf("3\n");
    }
     if(((a==2)&&(b==3))||((a==3)&&(b==2)))
    {
        printf("1\n");
    }
     if(((a==1)&&(b==3))||((a==3)&&(b==1)))
    {
        printf("2\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e4+5;
const int M = 1e4;
const int INF = 0x3f3f3f3f;

int main() {
	int n,a,b;
	scanf("%d",&n); 
	scanf("%d%d",&a,&b);
	
	for(int i = a;i <= b;++i){
		if(i % n == 0){
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
    return 0;
}


Measured memory_bytes: 3680
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;

int main() {
    int N, X, L[100], D, ans;
    scanf("%d %d", &N, &X);
    for(int i=0;i<N;i++){
        scanf("%d", &L[i]);
    }

    D = 0;
    ans = 0;
    for(int i=0;i<N;i++){
    	//printf("%d %d\n", D, X);
        if(D<=X){ans += 1;}
        D += L[i];
    }
    if(D<=X){ans += 1;}
    printf("%d\n", ans);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;

int main(int argc, char ** argv) {
	int r;
	scanf("%d", &r);
	printf("%d\n", 3*r*r);
	return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 998244353

int mpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (int64_t) res * a % MOD;
		a = (int64_t) a * a % MOD;
	}
	return res;
}
int main() {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	std::vector<int64_t> cnt(1000001);
	for (int i = 0; i < n; i++) cnt[a[i]] += a[i];
	for (int i = 0; i <= 1000000; i++) cnt[i] %= MOD;
	
	auto converted = cnt;
	for (int x = 1; x <= 1000000; x++) {
		int max = 1000000 / x;
		for (int y = 2; y <= max; y++) converted[x] += converted[y * x];
		converted[x] %= MOD;
	}
	for (auto &i : converted) i *= i, i %= MOD;
	for (int x = 1000000; x >= 1; x--) {
		int max = 1000000 / x;
		for (int y = 2; y <= max; y++) converted[x] -= converted[y * x];
		converted[x] %= MOD;
	}
	for (int i = 0; i < n; i++) converted[a[i]] -= (int64_t) a[i] * a[i];
	int64_t ans = 0;
	for (int i = 1; i <= 1000000; i++) {
		converted[i] = converted[i] % MOD + MOD;
		if (converted[i] >= MOD) converted[i] -= MOD;
		ans += (int64_t) converted[i] * mpow(i, MOD - 2) % MOD;
	}
	std::cout << (ans % MOD * 499122177 % MOD) << std::endl;
	
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>
using namespace std;
int main()
{
  int c[8];
  for(int i=0; i<9; ++i) cin >> c[i];
  bool ans = false;
  if(
      (c[0]-c[3] == c[1]-c[4] && c[1]-c[4] == c[2]-c[5]) // a1 - a2
      &&
      (c[3]-c[6] == c[4]-c[7] && c[4]-c[7] == c[5]-c[8]) // a2 - a3
      &&
      (c[0]-c[1] == c[3]-c[4] && c[3]-c[4] == c[6]-c[7]) // b1 - b2
      &&
      (c[1]-c[2] == c[4]-c[5] && c[4]-c[5] == c[7]-c[8]) // b2 - b3
    )
  {
    ans = true;
  }
  printf("%s\n",ans ? "Yes":"No");
  return 0;
}


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

int main(){
    string s, t;
    int count = 0;
    cin >> s >> t;

    for(int i = 0; i < 3; i++)
        if(s.at(i) == t.at(i)){
            count += 1;
        }
    cout << count << endl;
    return 0;
}

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

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x, file=sys.stderr)


def solve(SOLVE_PARAMS):
    "void()"
    pass


def main():
    from collections import Counter
    N = int(input())
    XS = Counter([input().strip().decode("ascii") for i in range(N)])
    for key in "AC WA TLE RE".split():
        v = XS.get(key, 0)
        print(f"{key} x {v}")


T1 = """
6
AC
TLE
AC
AC
WA
TLE
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    AC x 3
    WA x 1
    TLE x 2
    RE x 0

    """


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 16684
import java.util.Scanner;

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

        int d = sc.nextInt();
        int n = 25 - d;

        System.out.print("Christmas");
        for (int i = n; i > 0; i--) {
            System.out.print(" Eve");
        }
    }
}


Measured memory_bytes: 23124
#include <stdio.h>
    
typedef struct pair* ppair;
    
typedef struct pair {
  int first, second;
} pair;
    
    
int size;
pair v[1000000];
int psize;
pair preorder[1000000];
int sorted;
    
void swap(ppair a, ppair b) {
  pair t = *a;
  *a = *b;
  *b = t;
}
    
int getp(int begin, int end) {
  int i;
  int p = begin;
  for(i = begin+1; i < end; ++i) {
    if(v[i].first < v[p].first) {
      p = i;
    }
  }
  swap(&v[end-1], &v[p]);
  return end-1;
}
    
void qsort(int begin, int end) {
  int i, j;
  if(begin >= end) return;
  getp(begin,end);
  preorder[psize++] = v[end-1];
  if(begin+1 == end) return;
  for(i = begin, j = begin; i < end; ++i) {
    if(v[i].second < v[end-1].second) {
      swap(&v[i], &v[j++]);
    }
  }
  swap(&v[j],&v[end-1]);
  qsort(begin, j);
  qsort(j+1, end);
}
    
int binary_search(int k) {
  int l, r;
  l = 0;
  r = size;
  while(l < r) {
    int m = (l+r)/2;
    if(v[m].second == k) {
      return m;
    } else if(v[m].second < k) {
      l = m+1;
    } else {
      r = m;
    }
  }
  return -1;
}
    
int main() {
  int i, j;
  int n, k;
  char s[100];
  size = 0;
  sorted = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%s", s);
    if(s[0] == 'i') {
      scanf("%d", &k);
      v[size] = (pair){size,k};
      ++size;
      sorted = 0;
    } else if(s[0] == 'p') {
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      for(j = 0; j < size; ++j) {
        printf(" %d", v[j].second);
      }
      printf("\n");
      for(j = 0; j < size; ++j) {
        printf(" %d", preorder[j].second);
      }
      printf("\n");
    } else {
      scanf("%d", &k);
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      printf(binary_search(k)!=-1?"yes\n":"no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 7932
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

typedef long long ll;

int main(int argc, char* argv[])
{
  int n = 3;
  std::vector< int > va(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  ll ans = std::accumulate(va.begin(), va.end(), 0) - *std::max_element(va.begin(), va.end());

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int dp[3005][3005]={0};
string s,t,ans;

void Find(int i,int j)
{  
   if(i==0 || j==0)
     return;
   
   if(s[i-1]==t[j-1])
   {
    ans+=s[i-1];
    Find(i-1,j-1);
   }

   else {
    if(dp[i-1][j]>=dp[i][j-1])
    {
      Find(i-1,j);
    }
    else {
      Find(i,j-1);
    }
   }
return;
}

int main()
{  
   IOS;
      cin>>t>>s;

      fe(i,1,s.size())
       {
         fe(j,1,t.size())
          {
            if(s[i-1]==t[j-1]){
              dp[i][j] = 1 + dp[i-1][j-1];
            }
            else {
              dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
          }
       }

      Find(s.size(),t.size());
      reverse(ans.begin(),ans.end());
      cout<<ans;
    
  return 0;
}


Measured memory_bytes: 38780
a, b, k = gets.chomp.split.map(&:to_i)
c = 0
[a, b].max.times do |i_|
  i = [a, b].max - i_
  if a % i == 0 && b % i == 0
    c += 1
    if c == k
      puts i
      exit
    end
  end
end

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[300005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, 3 * N) {
        cin >> A[i];
    }
    sort(A, A + 3 * N, greater<ll>());

    ll ans = 0;
    REP(i, N) {
        ans += A[2 * i + 1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
n=int(input())
a=list(map(int,input().split()))
flag=True
count=0
while flag:
    flag=False
    for i in range(1,n):
        if a[i]<a[i-1]:
            key=a[i]
            a[i]=a[i-1]
            a[i-1]=key
            count+=1
            flag=True
a=list(map(str,a))
print(' '.join(a))
print(count)


Measured memory_bytes: 5596
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    System.out.println(Math.min(A,B)+Math.min(C,D));
  }
}

Measured memory_bytes: 22228
try:
    i = int(input())
    
    if i < 0:
        print(0)
    else:
        ureshisa = int(i / 500) * 1000
        nokori = i % 500
        ureshisa += int(nokori / 5) * 5
        print(ureshisa)
except:
    print("not integer error")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <string>
#define INF 100000
using namespace std;
int H, W,N;
int sx, sy;
typedef long long ll;

int main(){
    cin >> N;
    if(N%2==0) cout << N/2-1 << endl;
    else cout << N/2 << endl;

    return 0;
    
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, m;
  while (cin >> n >> m, n) {
    vi p(n);
    cin >> p;
    sort(rall(p));
    int s = 0;
    rep(i, n) if ((i + 1) % m != 0) s += p[i];
    cout << s << endl;
  }
}

Measured memory_bytes: 3028
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

struct node {
  long long lazy = 0;
  node *l = nullptr;
  node *r = nullptr;
  int label = -1;
};

struct DSU {
  std::vector<int> dat;
  std::vector<node *> dat2;

  DSU(int n) : dat(n, -1), dat2(n) {
    for (int i = 0; i < n; i++) {
      dat2[i] = new node();
      dat2[i]->label = i;
    }
  }

  int find(int u) {
    if (dat[u] < 0) return u;
    return dat[u] = find(dat[u]);
  }

  void unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) {
      cout << "ng" << endl;
    }
    if (-dat[u] < -dat[v]) std::swap(u, v);
    node *pu = dat2[u];
    node *pv = dat2[v];
    dat2[u] = new node();
    dat2[u]->l = pu;
    dat2[u]->r = pv;
    dat[u] += dat[v];
    dat[v] = u;
  }

  node *find_parent(int u) {
    u = find(u);
    return dat2[u];
  }

  int find_size(int u) {
    return -dat[find(u)];
  }
};

long long ans[202020];

void dfs(node *x, long long lz) {
  if (!x) return;
  lz += x->lazy;
  if (x->label != -1) {
    ans[x->label] = lz;
  }

  dfs(x->l, lz);
  dfs(x->r, lz);
}

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

  vector<tuple<int, int, int>> es;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    es.emplace_back(w, u, v);
  }

  sort(es.begin(), es.end());
  reverse(es.begin(), es.end());

  DSU dsu(n);
  for (auto e : es) {
    int w, u, v;
    tie(w, u, v) = e;
    long long x = dsu.find_size(u);
    long long y = dsu.find_size(v);
    node *px = dsu.find_parent(u);
    node *py = dsu.find_parent(v);
    px->lazy += y * w;
    py->lazy += x * w;
    dsu.unite(u, v);
  }

  dfs(dsu.find_parent(0), 0);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 17268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> p;

int main(void) {
    int N;
    cin >> N;
    vector<p> red, blue;
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        red.emplace_back(make_pair(a, b));
    }
    for (int i = 0; i < N; ++i) {
        int c, d;
        cin >> c >> d;
        blue.emplace_back(make_pair(c, d));
    }

    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());

    int cnt = 0;
    bool flag[N];
    for (int i = 0; i < N; ++i) {
        flag[i] = false;
    }
    for (auto b:blue) {
        int maxtmp = -1;
        int argmax = -1;
        for (int i = 0; i < N; ++i) {
            if (red[i].first > b.first) break;
            if (red[i].second < b.second && !flag[i]) {
                if (red[i].second > maxtmp) {
                    argmax = i;
                    maxtmp = red[i].second;
                }
            }
        }
        if (argmax >= 0) {
            flag[argmax] = true;
            cnt++;
        }
    }

    cout << cnt << 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(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int H,W,N;
  cin>>H>>W>>N;
  int Sr,Sc;
  cin>>Sr>>Sc;
  string S,T;
  cin>>S>>T;
  int X[4]={};
  int f=1;
  rep(i,N){
    if(S[i]=='U') X[0]++;
    else if(S[i]=='D') X[1]++;
    else if(S[i]=='L') X[2]++;
    else if(S[i]=='R') X[3]++;
    if(X[0]==Sr||X[1]==H-Sr+1||X[2]==Sc||X[3]==W-Sc+1){
      cout<<"NO"<<endl;
      f=0;
      break;
    }
    if(T[i]=='U'&&X[1]>1-Sr) X[1]--;
    else if(T[i]=='D'&&X[0]>Sr-H) X[0]--;
    else if(T[i]=='L'&&X[3]>1-Sc) X[3]--;
    else if(T[i]=='R'&&X[2]>Sc-H) X[2]--;
  }
  if(f) cout<<"YES"<<endl;
}

Measured memory_bytes: 776
#include<stdio.h>
int main(void)
{
	char s[101][101];
	char al[26]={"abcdefghijklmnopqrstuvwxyz"};
	int n,l,a,b,x[101]={0},i,j,k,m,min=0,min2;
	scanf("%d%d",&n,&l);
	for(i=0; i<n; i++){
		scanf("%s", &s[i]);
	}
	for(i=0; i<n-1; i++){
		for(j=i+1; j<n; j++){
			for(k=0; k<l; k++){
				a=0;
				b=0;
				for(m=0; m<26; m++){
					if(s[i][k]==al[m]&&s[j][k]!=al[m]){
						a=1;
						break;
					}
					if(s[i][k]!=al[m]&&s[j][k]==al[m]){
						b=1;
						break;
					}
				}
				if(a==1){
					x[j]++;
					break;
				}
				if(b==1){
					x[i]++;
					break;
				}
			}
		}
	}
	for(i=0; i<n; i++){
		min=n;
		for(j=0; j<n; j++){
			if(min>x[j]){
				min=x[j];
				min2=j;
			}
		}
		printf("%s", s[min2]);
		x[min2]=n;
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        vll l(N);
        rep(i, 0, N) cin >> l[i];
        sort(l.rbegin(), l.rend());
        cout << accumulate(l.begin(), l.begin()+K, 0LL) << endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	/**
	 * <p>
	 * 与えられた三辺で直角三角形が作れるかを判定する。
	 * </p>
	 *
	 * @param args
	 *            利用しない。
	 * @throws IOException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int lineCount = Integer.parseInt(br.readLine());
		for (int i = 0; i < lineCount; i++) {

			String line = br.readLine();

			// 三辺の長さをリストに格納し、ソート
			List<Integer> sideList = new ArrayList<Integer>();
			String[] input = line.split(" ");
			sideList.add(Integer.parseInt(input[0]));
			sideList.add(Integer.parseInt(input[1]));
			sideList.add(Integer.parseInt(input[2]));
			Collections.sort(sideList);

			if (isRightTriangle(sideList.get(2), sideList.get(1),
					sideList.get(0))) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	/**
	 * 三辺の長さから、直角三角形であるかどうかを判定する。<br>
	 * 注意：第一引数に最も長い辺を与えること。
	 *
	 * @param side1
	 *            辺1
	 * @param side2
	 *            辺2
	 * @param side3
	 *            辺3
	 * @return 直角三角形であるかどうか
	 */
	private static boolean isRightTriangle(int side1, int side2, int side3) {
		return (side1 * side1 == side2 * side2 + side3 * side3);
	}
}

Measured memory_bytes: 22348
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
int A,B;
int h,w;

int main() {
  cin >> A >> B;
  cin >> h >> w;
  cout << A * B - h * B - w * A + h * w << 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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

string MINUSINF = "-";
long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

void chmax(string &a, string b){
    if(a == MINUSINF) a=b;
    else if(a.size() < b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    int p=0;
    REP(i,s.size()){
        if(s[i]=='p') p++;
    }
    cout<<s.size()/2 - p << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <bitset>
using namespace std;

int main(int args, char *argc[]){
  bitset<30> students;
  int a;
  while(cin>>a)
    students[a-1]=1;
  for(int i=0;i<30;i++)
    if(students[i]==0)
      cout<<i+1<<endl;
  return 0;
}


Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#define INF 1100000000000000000LL
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int n;
	scanf("%d", &n);
	vector<P> v;
	for(int i=0; i<n; i++){
		ll x, y;
		scanf("%lld %lld", &x, &y);
		if(x>y) swap(x, y);
		v.push_back(P(x, y));
	}
	sort(v.begin(), v.end());
	ll min=v[0].first;
	ll max=0;
	multiset<ll> st, st1, st2;
	for(int i=0; i<n; i++){
		st.insert(v[i].second);
		st2.insert(v[i].second);
		st1.insert(v[i].first);
		if(max<v[i].second) max=v[i].second;
	}
	auto itr1=st.begin(), itr2=st.end(); itr2--;
	ll ans1=max-min, ans2=*itr2-*itr1, ans;
	for(int i=n-1; i>=0; i--){
		st.insert(v[i].first);
		auto itr=st.lower_bound(v[i].second);
		st.erase(itr);
		auto itr1=st.begin(), itr2=st.end(); itr2--;
		if(ans2>*itr2-*itr1) ans2=*itr2-*itr1;
	}
	ans=ans1*ans2;
	itr1=st1.end(), itr2=st2.begin(); itr1--;
	if(ans>(*itr1-min)*(max-*itr2)) ans=(*itr1-min)*(max-*itr2);
	for(int i=n-1; i>=0; i--){
		st1.insert(v[i].second);
		auto itr=st1.lower_bound(v[i].first);
		st1.erase(itr);
		st2.insert(v[i].first);
		itr=st2.lower_bound(v[i].second);
		st2.erase(itr);
		auto itr1=st1.end(), itr2=st2.begin(); itr1--;
		if(ans>(*itr1-min)*(max-*itr2)) ans=(*itr1-min)*(max-*itr2);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 33516
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
    if i not in p:
        dic[i] = abs(x-i)
        lis.append(i)

mini = min(dic.values())
for j in lis:
    if mini == dic[j]:
        print(j)
        break

Measured memory_bytes: 9180
#include<stdio.h>
#define NIL NULL
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000
int n,M[1000][1000];

void dijkstra(){
    int d[100],color[100];
    int i,v,minv,u;
    for(i=0;i<n;i++){
        d[i]=INF;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INF;
        u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
        break;
        }
        color[u]=BLACK;
        for(v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INF){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=M[u][v]+d[u];
                    color[v]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
}

int main(){
    int i,j,u,k,v,c;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
                M[i][j]=INF;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 2108
n = gets.to_i
xs,ys = n.times.map{gets.chomp.split.map(&:to_i)}.transpose
dists = Hash.new(0)
n.times do |i|
  n.times do |j|
    next if i == j
    x = xs[j] - xs[i]
    y = ys[j] - ys[i]
    
    dists[x*10**10 + y] += 1
  end
end
m = dists.values.max
if n == 1
  m = 0
end
puts n - m

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

int main()
{
    string s; cin >> s;
    bool a = false, b = false;
    for(char& c: s){
        if(c=='A') a = true;
        if(c=='B') b = true;
    }
    if(a&b) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 20:51:36 2019

@author: Yamazaki Kenichi
"""

N = int(input())
h =list(map(int,input().split()))

ans = h[0]

for i in range(1,N):
    ans += h[i]-h[i-1] if h[i]-h[i-1]>0 else 0

print(ans)

Measured memory_bytes: 3060
def main():
  acc = int(input())
  while True:
    x = input()
    if x == "=":
      print(acc)
      break
    n = int(input())
    if x == "+":
      acc += n
    elif x == "-":
      acc -= n
    elif x == "*":
      acc *= n
    elif x == "/":
      acc //= n
main()


Measured memory_bytes: 5596