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

int main(){
	int i,j,n,x,y,px,py,dx,dy;
	int ans,w,h;
	
	scanf("%d%d%d",&w,&h,&n);
	scanf("%d%d",&px,&py);
	ans=0;
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		dx=x-px;
		dy=y-py;
		if(dx*dy>0){
			if(dx<0)dx=-1*dx;
			if(dy<0)dy=-1*dy;
			
			if(dy>=dx)ans+=dy;
			else ans+=dx;
		}
		else{
			if(dx<0)dx=-1*dx;
			if(dy<0)dy=-1*dy;
			ans+=dx+dy;
		}
		px=x;
		py=y;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 596
#AC済み
x,y,z,k=map(int,input().split())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
ab=[a[i]+b[j] for j in range(y) for i in range(x)]
ab.sort(reverse=True)
ab=ab[:k]
l=len(ab)
abc=[ab[i]+c[j] for j in range(z) for i in range(l)]
abc.sort(reverse=True)
for i in range(k):
    print(abc[i])


Measured memory_bytes: 161088
#include <bits/stdc++.h>
#include <numeric>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 1; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	int cnt = 0;
	REP1(i, n) {
		int AB = n - i;
		int ab = sqrt(AB);
		REP1(i, ab + 1) {
			if (i * i == AB) {
				cnt++;
			}
			else if (AB % i == 0) {
				cnt += 2;
			}
		}
	}
	cout << cnt << endl;
}

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

namespace ABC135_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var B = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long ans = 0;
            long restB = 0;
            for (long i = 0; i < B.Length; i++)
            {
                if (A[i] < restB)
                {
                    ans += A[i];
                    restB = B[i];
                    continue;
                }

                ans += restB;
                var restA = A[i] - restB;

                if (restA > B[i])
                {
                    ans += B[i];
                    restB = 0;
                }
                else
                {
                    ans += restA;
                    restB = B[i] - restA;
                }
            }

            ans += Math.Min(A.Last(), restB);

            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

const int MX = 100 * 1000 + 7;

int c[MX], s[MX], f[MX];
bool o(char c) {
    return isdigit(c);
}
void n() {
    cout << "No" << endl;
    exit(0);
}
int main() {
    int n;
    cin >> n;
    cout << 48 - n << endl;
}

Measured memory_bytes: 256
n,y=map(int,input().split())
flag=False
list=[]
for i in range(n,-1,-1):
  for j in range(0, n-i+1):
    k=n-i-j
    if i*10000+j*5000+k*1000 == y and not(flag):
      flag=True
      list=[i,j,k]
if not(flag):
  print('{} {} {}'.format(-1,-1,-1))
else:
  print('{} {} {}'.format(list[0],list[1],list[2]))

Measured memory_bytes: 3064
n = 55555
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    if i not in primes:
        i += 1
    else:
        ran = range(i*2, n+1,i)
        primes.difference_update(ran)
primes = list(primes)

N = int(input())
res = []
for i in primes:
    if len(res) >= N:
        print(*res)
        exit()
    if i % 5 == 2:
        res.append(i)
       

Measured memory_bytes: 8812
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  string s;
  cin>>s;
  int n=s.size();
  rep(i,n){
    if(s.at(i)=='?')
      s.at(i)='D';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3756
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        
        if (str.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (str.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}


Measured memory_bytes: 21844
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	for i, _ := range h {
		fmt.Scan(&h[i])
	}

	sort.Ints(h)
	var temp []int

	for i := n - 1 - k; i >= 0; i-- {
		temp = append(temp, h[i])
	}
	ans := 0
	for _, v := range temp {
		ans += v
	}
	fmt.Println(ans)
}

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

long long n;
vector<long long> h;

bool solve();

int main() {
  cin >> n;
  h.resize(n);
  for(int i = 0; i < n; ++i) cin >> h[i];
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  long long now = -1;
  for(int i = 0; i < n; ++i) {
    if(now < h[i])
      now = h[i] - 1;
    else if(now > h[i])
      return 0;
  }
  return 1;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AB = ReadSplitInt();
            var max = Max(AB[0], AB[1]);
            var min = Min(AB[0], AB[1]);
            if (min == max || min + 1 == max)
                Println("Yay!");
            else
                Println(":(");
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11348
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const double PI = acos(-1.0);

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt& pt) : x(pt.x), y(pt.y) {}

  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }

  Pt<T> rot90() { return Pt<T>(-y, x); }

  bool operator<(const Pt& pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }

  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};

typedef Pt<double> pt;
typedef vector<pt> vpt;

/* global variables */

/* subroutines */

void rec(int n, vpt &ps, pt p4) {
  if (n <= 0) {
    ps.push_back(p4);
    return;
  }

  pt &p0 = ps.back();

  pt p1 = (p0 * 2 + p4) / 3;
  pt p2 = p1 + (p1 - p0).rot(PI / 3);
  pt p3 = (p0 + p4 * 2) / 3;

  rec(n - 1, ps, p1);
  rec(n - 1, ps, p2);
  rec(n - 1, ps, p3);
  rec(n - 1, ps, p4);
}

/* main */

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

  vpt ps;
  ps.push_back(pt(0.0, 0.0));

  rec(n, ps, pt(100.0, 0.0));

  for (int i = 0; i < ps.size(); i++)
    printf("%.8lf %.8lf\n", ps[i].x, ps[i].y);
  return 0;
}

Measured memory_bytes: 1356
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

typedef long long int ll;

using namespace std;

double foo(vector<double>& prob)
{
	int n = prob.size();
	vector<vector<double>> dp(n+1,vector<double>(n+1));

	dp[0][0] = 1;

	for (int i=1;i<=n;++i)
    {
        dp[i][0] = dp[i-1][0]*(1-prob[i-1]);
    }

    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=n;++j)
        {
            dp[i][j] = dp[i-1][j-1]*prob[i-1] + dp[i-1][j]*(1-prob[i-1]);
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    /**
    for (int i=0;i<=n;++i)
    {
        for (int j=0;j<=n;++j)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    **/
    double ans = 0;

    int x = ceil(double(n)/2);

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

    return ans;

}

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

    vector<double> prob(n);

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

    cout<<setprecision(10)<<foo(prob)<<endl;

    return 0;
}


Measured memory_bytes: 73808
#include <cstdio>
#include <map>
using namespace std;

int mp[144], m, n, hs, ch;
int dir[] = { -12, -1, 1, 12 };
map<int,int> memo;

int func( int p, int d, int u ){
	while(1){
		int h = mp[p];
		if( h >= 0 ){
			int s = 0;
			mp[p] = -1;
			hs ^= 1 << h;
			if( u > 12 ){
				for(int i = 0; i < 4; i++ )
					s += func( p + dir[i], dir[i], u - 1 );
			}else{
				int mi = h << 23 | hs;
				map<int,int>::iterator it = memo.find(mi);
				if( it == memo.end() ){
					for(int i = 0; i < 4; i++ )
						s += func( p + dir[i], dir[i], u - 1 );
					memo[mi] = s;
				}else{
					s = it->second;
				}
			}
			hs |= 1 << h;
			mp[p] = h;
			return s;
		}
		if( h == -9 )break;
		p += d;
	}
	return 0;
}

int main(void){
	int i,j,p,t;
	for(; scanf("%d%d",&m,&n),m;){
		hs = 0;
		memo.clear();
		for( i = 0; i < 144; i++ ) mp[i] = -9;
		for( i = 1; i <= n; i++ )
			for( j = 1; j <= m; j++ ){
				p = i * 12 + j;
				scanf("%d",&t);
				switch( t ){
					case 2:
						ch = p;
					case 0:
						mp[p] = -1; break;
					case 1:
						memo[hs<<23] = 0;
						mp[p] = hs++;
						break;
				}
			}
		for( i = 0; i < 4; i++ ){
			t = dir[i];
			for( j = ch; mp[j+=t] != -9; )
				if( mp[j] >= 0 )memo[ mp[j]<<23 ] = 1;
		}
		j = hs;
		hs = ( 1 << hs ) - 1;
		t = 0;
		for( i = 0; i < 4; i++ ){
			t += func( ch + dir[i], dir[i], j );
		}
		printf("%d\n", t );
	}
}

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

template<typename T> void chmin(T &a,T b){if(a>b) a=b;}
template<typename T> void chmax(T &a,T b){if(a<b) a=b;}


signed main(){
  Int m,n;
  cin>>m>>n;
  Int ans=0;
  for(Int i=0;i<m;i++){
    Int tmp=0;
    for(Int j=0;j<n;j++){
      Int x;
      cin>>x;
      tmp+=x;
    }
    chmax(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v;
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        v.push_back(make_pair(A, B));
    }

    sort(v.begin(), v.end());

    long long int ans = 0;
    priority_queue<int> q;
    int k = 0;

    for (int i = 1; i <= M; ++i) {
        while (v[k].first == i && k < N) {
            q.push(v[k].second);
            ++k;
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << '\n';
}

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

using namespace std;

int n, dp[100001], heights[100001];

int main() {
    cin.sync_with_stdio(0); cin.tie(0); 
    cin >> n;
    
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;

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

    for(int i = 0; i < n-1; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(heights[i + 1] - heights[i]));
        if (i < n-2) {
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(heights[i + 2] - heights[i]));
        }
    }
    
    cout << dp[n - 1] << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define F first
#define pll pair<ll,ll>
#define S second
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

ll n,m,k;
bool give(auto& s,int x,int y)
{
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if((x&(1<<i))==0 && (y&(1<<j))==0 && s[i][j] == '#') ans++;
        }
    }
    return ans == k;
}

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

    cin>>n>>m>>k;
    vector<string> s(n);
    for(auto& i:s) cin>>i;

    ll ans = 0;
    for(int i = 0; i < (1<<n);i++)
    {
        for(int j = 0; j < (1<<m); j++)
        {
            ans += give(s,i,j);
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int passed[1001];

struct team {
	int i, u, a, p;
	team(int I, int U, int A, int P) {
		i = I;
		u = U;
		a = A;
		p = P;
	}
};

bool operator<(const team& l, const team& r) {
	if( l.a == r.a ) {
		if( l.p == r.p ) {
			return l.i < r.i;
		}
		return l.p < r.p;
	}
	return l.a > r.a;
}

int main() {
	int n;
	while(cin >> n, n) {
		memset(passed, 0, sizeof(passed));
		vector<team> t;
		rep(i, n) {
			int I, U, A, P;
			cin >> I >> U >> A >> P;
			t.push_back( team(I,U,A,P) );
		}
		sort( t.begin(), t.end() );
		vector<int> id;
		rep(i, n) {
			if(id.size() < 10) {
				if( passed[t[i].u] < 3 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
			else if(id.size() < 20) {
				if( passed[t[i].u] < 2 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
			else if(id.size()<26) {
				if( passed[t[i].u] < 1 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
		}
		rep(i, id.size()) {
			cout << id[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<utility>
#include<map>
#include<string>
using namespace std;
pair<int,int> a[100005];
int n; 

int main()
{
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&j);
		a[i]=make_pair(j,i);
	}
	sort(a+1,a+1+n);
	for(i=1;i<=n;i++)
		printf("%d ",a[i].second);
		
	return 0;
}

Measured memory_bytes: 1664
import           Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as U
import           Data.List

readPair :: IO (Int, Int)
readPair = (\[x, y] -> (x, y)) . unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main :: IO ()
main = do
  [n, h, w] <- map read . words <$> getLine
  abs <- U.replicateM n readPair
  print $ solve h w abs

solve :: Int -> Int -> U.Vector (Int, Int) -> Int
solve h w = U.length . U.filter ((>= w) . snd) . U.filter ((>= h) . fst)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(c) begin(c), end(c)
using namespace std;

template <class T>
void scrib_impl(char const* title, T v){
    cout << title << " ...... " << v << endl;
}
#define SCRIB(EXPR) (scrib_impl(#EXPR, (EXPR)))

using bint = int64_t;


int main() {
    std::string s,t;
    cin >> s >> t;
    cout << t << s << endl;
        
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main() {
    FAST
    ll x;
    cin>>x;
    ll p=100;
    ll ans=0;
    for(;p<x;p=p+p/100) ans++;
    cout<<ans;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  bool judge = false;
  for (int i = 0; i <= n / 4; i++) {
    if ((n - 4 * i) % 7 == 0) {
      judge = true;
      break;
    }
  }
  cout << (judge ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch;
    cin>>ch;
    if(ch=='A')
        cout<<"T"<<endl;
    else if(ch=='T')
        cout<<"A"<<endl;
    else if(ch=='G')
        cout<<"C"<<endl;
    else
        cout<<"G"<<endl;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

using namespace std;
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};


int main(void) {
	long N,M;
	cin >> N >> M;
	VI x(N),y(N),z(N);
	REP(i,N) {
		cin >> x[i] >> y[i] >> z[i];
	}
	long long sum = -1;
	REP(a,2) {
		REP(b,2) {
			REP(c,2) {
				VI xyz(N,0);
				REP(i,N) {
					if (a % 2) xyz[i] += x[i];
					else xyz[i] -= x[i];
					if (b % 2) xyz[i] += y[i];
					else xyz[i] -= y[i];
					if (c % 2) xyz[i] += z[i];
					else xyz[i] -= z[i];
				}
				SORT(xyz);
				long long tmp = 0;
				REP(i,M) {
					tmp += xyz[N-i-1];
				}
				sum = max(tmp,sum);
			}
		}
	}
		
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int>cnt;
const int nax = 1e6 + 44;

int divs[nax];

main()
{
    int n;
    cin>>n;
    int a[n+5],ans=0;

    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    for(int i=1; i<nax; i++)
    {
        for(int j=i; j<nax; j+=i)
        {
            divs[j]+=cnt[i];
        }
    }
    for(int i=1; i<nax; i++)
    {
        if(cnt[i]&&divs[i]==1)
        {
            ans+=cnt[i];
        }
    }
    cout<<ans<<endl;

}



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

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

using namespace std;


int main()
{
	int N;
	cin>>N;
	
	int D=N%10;
	N=N/10;
	int C=N%10;
	N=N/10;
	int B=N%10;
	N=N/10;
	int A=N%10;
	
	if(A+B+C+D==7){
		cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
	}else{
		if(A+B+C-D==7){
			cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
		}else{
			if(A+B-C+D==7){
				cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
			}else{
				if(A+B-C-D==7){
					cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
				}else{
					if(A-B+C+D==7){
						cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
					}else{
						if(A-B+C-D==7){
							cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
						}else{
							if(A-B-C+D==7){
								cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
							}else{
								if(A-B-C-D==7){
									cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
								}
							}
						}
					}
				}
			}
		}
	}
	
		
	
}

Measured memory_bytes: 256
n,t = map(int,input().split())

a = []
for i in range(n):
    c,tt = map(int,input().split())
    if tt <= t :
        a.append([c,tt])

if len(a) > 0 :
    a.sort(key=lambda x : x[0])
    print(a[0][0])
else :
    print("TLE")




Measured memory_bytes: 38384
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

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

    ll ans=1e18;
    rep(i,0,n-k+1){
        ll go_r=abs(v[i+k-1])+abs(v[i+k-1]-v[i]);
        ll go_l=abs(v[i])+abs(v[i+k-1]-v[i]);
        ans=min(ans,min(go_r,go_l));
    }
    cout<<ans<<endl;

    return 0;
}





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

int main(){
  int l,n,x,w,txw=0,cnt =0;
  int ret[31]={};
  int flg=0;
  cin >> l >> n;
  for (int i=0;i<n;i++){
    cin >> x >> w;
    txw += x*w;
  }
  if (txw<0){
    flg=1;
    txw*=-1;
  }
  for (int i=l;i>0;i--){
    ret[i]=txw/i;
    if (ret[i]!=0){txw-=ret[i]*i;cnt++;}
  }
  cout << cnt << endl;
  for (int i=0;i<31;i++){
    if (ret[i]!=0){
      if (flg){
	cout << i << " "<< ret[i]<< endl;
      }else{
	cout << -i << " " << ret[i] << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3092
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
import Data.IORef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

toSecond h m s = s + (m + h * 60) * 60
toHMSStr s = intercalate ":" $ map show' [div s 3600, (flip mod 60 . flip div 60) s, mod s 60]
  where show' n = if n<10 then "0" ++ show n else show n

main = takeWhile (any (/=(-1))) . map (map readInt . words) . lines <$> getContents >>= mapM_ (\[h,m,s] -> let remain = toSecond 2 0 0 - toSecond h m s in putStrLn (toHMSStr remain) >> putStrLn (toHMSStr (3 * remain)))

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) {
  for (auto &e : vec) cout << e << " \n"[&e==&vec.back()];
}

template <class T>
void OUTS(vector<vector<T>> &df) {
  for (auto &vec : df) OUTS(vec);
}

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) {
  for (auto &e : vec) cout << e << "\n";
}

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, N);
  if (N == 1) OUTL("Hello World");
  else {
    VAR(int, A, B);
    OUTL(A + B);
  }
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define N 500010
#define MOD 998244353


struct S {
	ll c0, c1, cc;
};

struct F {
	bool rev;
};

S op(S l, S r) { return S{ l.c0 + r.c0,l.c1 + r.c1,l.cc + r.cc + ((l.c1)*(r.c0))}; }

S e() { return S{ 0, 0,0 }; }

S mapping(F l, S r) {
	if (l.rev)return S{ r.c1,r.c0,(r.c0*r.c1) - r.cc };
	else return r;
}

F composition(F l, F r) { return { (r.rev && (!(l.rev))) || ((l.rev) && (!(r.rev))) }; }

F id() { return F{ false }; }

int main() {
	int n, q;
	cin >> n >> q;
	ll ans;
	vector<S> a(n);
	rep(i, n) {
		int x;
		cin >> x;
		if (x == 0)a[i] = S{ 1,0,0 };
		else a[i] = S{ 0,1,0 };
	}

	lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

	rep(i, q) {
		int t, l, r;
		cin >> t >> l >> r;
		l--;
		if (t == 1) {
			seg.apply(l , r, F{ true });
		}
		else {
			ans = (seg.prod(l, r)).cc;
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 20436
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    cout << abs(a[n-1]-a[0]) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
using namespace std;

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

    sort(S.begin(), S.end());

    cout << ((S == "abc") ? "Yes" : "No") << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int main()
{
	fastIO;
	int a,b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

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

int main(int argc, char *argv[]) {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int count = 0;
  count += a[2] - a[1];
  a[0] += a[2] - a[1];
  count += (a[2] - a[0]) / 2;
  if((a[2] - a[0]) % 2 == 1) {
    count += 2;
  }
  cout << count << endl;
  return 0;
}


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

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


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

using namespace std;

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

    int max = 0, second = 0, input;
    int numbers[N];
    for (int i = 0; i < N; i++)
    {
        cin >> input;
        numbers[i] = input;
        if (input > max) {
            max = input;
        } else if (input > second) {
            second = input;
        }
    } 

    for (int i = 0; i < N; i++)
    {
        if (numbers[i] == max) {
            cout << second << "\n";
        } else {
            cout << max << "\n";
        }
    }
}


Measured memory_bytes: 2432
using System;

public class Hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var v = double.Parse(line.Trim());
            var f = Math.Pow(v / 9.8, 2) * 4.9 / 5 + 1;
            var ans = (int)f + 1;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9284
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int Q = 2e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,s,e;
ll m,cum[N];
vector<int> a;

ll cnt(int b) {

    ll ret = 0;

    for(auto i:a) {

        ret += n-(lower_bound(a.rbegin(),a.rend(),b-i)-a.rbegin());

    }

    return ret;

}

ll sum(int b) {

    ll ret = 0;

    for(auto i:a) {

        int idx = n-1-(lower_bound(a.rbegin(),a.rend(),b-i)-a.rbegin());

        if(idx==-1) continue;

        ret += 1LL*i*(idx+1) + cum[idx];

    }

    return ret;

}

bool f(int b) {

    return cnt(b)>=m;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;

    a.resize(n);

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

    sort(a.rbegin(),a.rend());

    for(int i=0;i<n;++i) cum[i] = (i ? cum[i-1] : 0) + a[i];

    s = 2*a.back();
    e = 2*a[0];

    while(s<e) {

        int mid = (s+e+1)/2;

        if(f(mid)) s = mid;
        else e = mid-1;

    }

    cout << sum(s) - (cnt(s)-m)*s << '\n';

    return 0;
}

Measured memory_bytes: 1408
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

/*lld fac[100001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=100000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}*/


lld gcd(lld a,lld b)
{
    if(a>b) return gcd(b,a);
    if(b%a==0) return a;
    else return gcd(b%a,a);
}

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;



void solve()
{
    lld a,b;
    char c;
    cin>>n>>k;
    vector<lld> v;
    for(i=0;i<n;i++)
    {
        cin>>l;
        v.pb(l);

    }
    sort(all(v));
    x=0;
    for(i=0;i<k;i++)
    {
        x+=v[i];
    }
    cout<<x;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
   //  getfac(p2);
    //check the value by which modulo is to be taken
    lld ans=0;
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
                  solve();
       cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
	int n,m;
	char *Pn;
	char *str;
	char *p;
	char IO2[3]="IO";
	int i;
	int ans;
	
	while(1){
		scanf("%d\n",&n);
		if(!n)break;
		scanf("%d\n",&m);
		
		Pn=(char *)malloc(sizeof(char)*(2*n+1+1));
		str=(char *)malloc(sizeof(char)*(m+1));
		
		scanf("%s",str);
		
		for(i=0;i<2*n;i++)Pn[i]=IO2[i%2];
		Pn[2*n+1-1]='I';
		Pn[2*n+1]='\0';
		
		
		ans=0;
		for(p=&str[m-(2*n+1)];p>=str;p--){
			if(!strcmp(p,Pn))ans++;
			p[2*n+1-1]='\0';
		}
		
		printf("%d\n",ans);
		
		free(str);
		free(Pn);
		
	}
	return 0;
}

Measured memory_bytes: 1416
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;

namespace competitive
{
    class Program
    {
        static void Main(string[] args)
        {
            var scanner = new Scanner();
            var n = scanner.NextInt();
            var k = scanner.NextInt();
            var dk = scanner.NextLineToIntList();
            var ls = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            while (true)
            {
                if (!Contain(n, dk))
                {
                    Console.WriteLine(n);
                    return;
                }
                n++;
            }
        }
        public static bool Contain(int number, IEnumerable<int> numbers)
        {
            while (number != 0)
            {
                var mod = number % 10;
                if (numbers.Contains(mod))
                {
                    return true;
                }
                number /= 10;
            }
            return false;
        }
    }


    #region
    public static class Extensions
    {
        public static int ToInt(this string str) => int.Parse(str);
        public static double ToDouble(this string str) => double.Parse(str);
        public static long ToLong(this string str) => long.Parse(str);
        public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    }

    public class Scanner
    {
        private TextReader reader;
        public Scanner()
        {
            reader = Console.In;
        }
        public Scanner(TextReader reader)
        {
            this.reader = reader;
        }
        private string NextWord()
        {
            var sb = new StringBuilder();
            while (true)
            {
                var c = reader.Read();
                if ((c == 13 || c == 10 || c == 32) && sb.Length > 0 || c == -1)
                {
                    break;
                }
                sb.Append((char)c);
            }
            return sb.ToString();
        }
        public int NextInt() => NextWord().ToInt();
        public string Next() => NextWord();
        public double NextDouble() => NextWord().ToDouble();
        public long NextLong() => NextWord().ToLong();
        public BigInteger NextBigInteger() => NextWord().ToBigInteger();
        public string NextLine()
        {
            var str = reader.ReadLine();
            if (string.IsNullOrWhiteSpace(str))
            {
                return reader.ReadLine();
            }
            else
            {
                return str;
            }
        }
        private List<string> NextLineToList() => NextLine().Split(new char[] { ' ' },
                                                                  StringSplitOptions.RemoveEmptyEntries)
                                                           .ToList();
        public List<int> NextLineToIntList() => NextLineToList().Select(x => int.Parse(x))
                                                                .ToList();
    }
    #endregion
}


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

int main() {
  string S;
  cin >> S;
  string ans = "No";
  for (int i=1; i<S.size(); i++) if (S[i-1] == 'A' && S[i] == 'C') {ans = "Yes"; break;}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re register
#define SIZE 3005
#define LL long long
using namespace std;
int n;
LL a[SIZE],dp[SIZE][SIZE];
int main()
{
	cin>>n;
	for(re int i=1;i<=n;++i)
		cin>>a[i],dp[i][i]=a[i];
	for(re int len=1;len<=n;++len)
		for(re int l=1;l<n;++l)
		{
			int r=l+len-1;
			if(r>n)
				break;
			dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	cout<<dp[1][n]<<endl;
	return 0;
} 

Measured memory_bytes: 70016
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
int main(){
    ll TC;
    cin>>TC;
    vector<P> lv,rv;
    for(;TC>0;TC--){
        cin>>N;
        ll ans=0;
        lv.clear();
        rv.clear();
        for(ll i=0;i<N;i++){
            ll K,L,R;
            cin>>K>>L>>R;
            ans+=min(L,R);
            if(L==R)continue;
            if(L>R){
                lv.push_back(P(K,L-R));
            }else{
                rv.push_back(P(N-K,R-L));   
            }
        }
        sort(lv.begin(),lv.end());
        sort(rv.begin(),rv.end());
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        for(auto p:lv){
            if(pq.size()>=p.first){
                if(pq.top()<p.second){
                    pq.pop();
                    pq.push(p.second);
                }
            }else{
                pq.push(p.second);
            }
        }
        while(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
        for(auto p:rv){
            if(p.first==0)continue;
            if(pq.size()>=p.first){
                pq.pop();
                pq.push(p.second);
            }else{
                pq.push(p.second);
            }
        }
        while(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 8228
#include<stdio.h>
#define NIL -1
#define MAX 500000
int root = NIL;
int key[MAX];
int left[MAX];
int right[MAX];
//int T[MAX];
int p[MAX];
void tree_insert(int z){
  int y = NIL;
  int x = root;
  while(x!=NIL){
    y = x;
    if(key[z] < key[x])x = left[x];
    else x = right[x];
  }
  p[z] = y;
  if(y == NIL)root = z;
  else if(key[z]<key[y])left[y] = z;
  else right[y] = z;
  
}
void preorder(int t){
  if(t==NIL)return;
  printf(" %d",key[t]);
  preorder(left[t]);
  preorder(right[t]);
}

void inorder(int t){
  if(t==NIL)return;
  inorder(left[t]);
  printf(" %d",key[t]);
  inorder(right[t]);
}

void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

int main(){
  
  int i,n,x;
  int z = 0;
  char A[10];
  scanf("%d",&n);
  for(i=0;i<MAX;i++){
    key[i]=NIL;
    left[i]=NIL;
    right[i]=NIL;
    //   T[MAX]=NIL;
    p[i]=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%s", A);
    if(A[0]=='i'){
      scanf("%d",&x);
      key[z]=x;
      tree_insert(z);
      z++;
    }
    else if(A[0]=='p')print();
  }
  
  return 0;
}

Measured memory_bytes: 8232
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

#define ALL(x) x.begin(), x.end()
using namespace std;

typedef vector<vector<int>> G;
const int inf = 1e9;

int n, m;
G graph;
vector<int> ans;

int visited[100100];

void dfs(int u) {

    ans.push_back(u);
    visited[u] = 1;

    for(int i = 0; i < graph[u].size(); i++) {
        int v = graph[u][i];
        if(!(visited[v])) {
            return dfs(v);
        }
    }
    return;
}

int main(void) {
    cin >> n >> m;
    graph = G(n + 100);
    for(int i = 0; i < m; i++) {

        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    dfs(1);
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    dfs(1);

    cout << ans.size() << endl;

    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }

    cout << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    string S, T;
    cin >> S >> T;

    ll m = 1000;
    rep(i, S.length()-T.length()+1){
        ll count = 0;
        rep(j, T.length()){
            if(S[i+j]==T[j]) ++count;
        }
        ll t = T.length() - count;
        m = min(m, t);
    }
    cout << m << endl;
}


Measured memory_bytes: 3616
import bisect

N = int(input())
if N in [1,2]:
  print(N)
  exit()

acms = [0]
for i in range(1,N+1):
  acms.append(acms[i-1]+i)

ans = []
while 1:  
  ans1 = bisect.bisect_left(acms,N)
  if N-ans1<ans1:
    ans.append(ans1)
    ans.append(N-ans1)
    break
  else:
    ans.append(ans1)
    N = N-ans1
    
[print(val) for val in sorted(ans)]

Measured memory_bytes: 189876
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;





int main(void) {
  ll N;
  cin >> N;
  ll a[MAX], b[MAX], c[MAX], d[MAX];
  ll i, j;
  ll sa=0, sb=0;
  
  for(i=0; i<N; i++) cin >> a[i];
  for(i=0; i<N; i++) cin >> b[i];
  
  for(i=0; i<N; i++) {
    c[i]=a[i]-b[i];
    d[i]=c[i];
  }
  sort(c, c+N);
  sort(d, d+N);
  
  ll l=0, r=N-1;
  while(l<r && d[l]<0 && d[r]>0) {
    
    if(d[l]+d[r]==0) {
      d[l]=d[r]=0;
      l++; r--;
    }else if(d[l]+d[r]>0) {
      d[r]+=d[l];
      d[l]=0;
      l++;
    }else {
      d[l]+=d[r];
      d[r]=0;
      r--;
    }
    
  }
  
  ll ans=0;
  for(i=0; i<N; i++) {
    if(d[i]<0) {
      pt(-1);
      return 0;
    }
    
    if(c[i]!=d[i]) ans++;
    
  }
  
  pt(ans);
}





Measured memory_bytes: 3328
from collections import Counter

n = int(input())
L = [Counter(str(input())) for _ in range(n)]
C = sorted(L[0])
ans = ''
for k in C:
    m = L[0][k]
    for i in range(n):
        m = min(m, L[i][k])
    ans += k * m
print(ans)


Measured memory_bytes: 3316