akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int D,N;

    cin >> D >> N;

    int T[D];
    int MN[D],MX[D];

    for(int i=0; i<D; ++i) cin >> T[i];

    int A[N],B[N],C[N];

    for(int i=0; i<N; ++i) cin >> A[i] >> B[i] >> C[i];


    for(int i=0; i<D; ++i) {
        MN[i]=101; MX[i]=-1;
        for(int j=0; j<N; ++j) {
            if(A[j]<=T[i] && T[i]<=B[j]) {
                MN[i]=min(MN[i],C[j]);
                MX[i]=max(MX[i],C[j]);
            }
        }
    }

    int dp[2][D];

    dp[0][0]=0;
    dp[1][0]=0;

    for(int i=1; i<D; ++i) {
        dp[0][i]=max(dp[0][i-1]+abs(MN[i-1]-MN[i]),dp[1][i-1]+abs(MX[i-1]-MN[i]));
        dp[1][i]=max(dp[0][i-1]+abs(MN[i-1]-MX[i]),dp[1][i-1]+abs(MX[i-1]-MX[i]));
    }

    cout << max(dp[0][D-1],dp[1][D-1]) << endl;

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


signed main()
{
    showoff;
    int n,ans = 0;
    cin >> n;
    vector<int>a(n+5),b(n+5),c(n+5);
    FOR(i,1,n+1)cin >> a[i];
    FOR(i,1,n+1)cin >> b[i];
    FOR(i,1,n)cin >> c[i];
    FOR(i,1,n+1){
        ans += b[a[i]];
        if(i <= n-1 && a[i+1] == a[i]+1)ans += c[a[i]];
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...   

Measured memory_bytes: 256
NM = input().split()
N, M = int(NM[0]), int(NM[1])

if [N, M] == [1, 1]:
    print(1)
    
elif N == 1 and M != 1:
    print(M-2)
    
elif N != 1 and M == 1:
    print(N-2)
    
else:
    print((N-2)*(M-2))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <complex>
using namespace std;

typedef complex<double> Point;
namespace std {
  bool operator<(Point a, Point b) {
    if (a.real() == b.real())
      return a.imag() < b.imag();
    else
      return a.real() < b.real();
  }
}

int ccw(Point p1, Point p2, Point p3)
{
  p2 -= p1;
  p3 -= p1;
  double det = (conj(p2)*p3).imag();
  if (det > 0) return 1;
  if (det < 0) return -1;
  return 0;
}

vector<Point> convex_hull(vector<Point>& ps)
{
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<Point> ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

int main()
{
  int N;
  while (scanf("%d", &N), N) {
    vector<Point> ps;
    for (int i = 0; i < N; ++i) {
      double x, y;
      scanf("%lf,%lf", &x, &y);
      ps.push_back(Point(x, y));
    }
    vector<Point> ch(convex_hull(ps));
    printf("%d\n", N - ch.size());
  }
}

Measured memory_bytes: 0
fun main(args:Array<String>) {
  val n = readLine()!!.toInt()
  val ms = readLine()!!.split(" ").map(String::toInt)

  val num_freq = mutableMapOf<Int, Int>()
  ms.map { num ->
    if( num_freq.get(num) == null )
      num_freq[num] = 0
    num_freq[num] = num_freq[num]!! + 1
  }
  //println(num_freq)

  // 全部取り除くべき人か
  // 一部取りのぞくか

  var remove = 0
  num_freq.toList().map { kv ->
    val (num, freq) = kv
    if( num <= freq )
      remove += freq - num
    else
      remove += freq
  }
  println( remove)
}

Measured memory_bytes: 59880
#include <stdio.h>
int main()
{
        int  a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if((a == b) && (a == c) )
                printf("1");
        else if(( a == b) || ( a == c) || (b == c))
                printf("2");
        else
                printf("3");
        return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;

int main(){
  int n; cin >> n;
  vs s(n); rep(i,n) cin >> s[i];
  int c = 0;
  rep(i,n){
    if(s[i] == "A") c++;
    else c--;
    if(c < 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  if(c != 0) cout << "NO" << endl;
  else cout << "YES" << endl;
}



Measured memory_bytes: 3176
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A == B:
    print('YES')
    exit()

if W > V:
    print('NO')
    exit()

d = abs(B - A)
if (V - W) * T >= d:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mof = 1e9+7;
ll dp[55][55][55*55];

ll solve(int n,int k)
{
    //init: row = 1, skip = 0, value = 0, skip = 1, value = 1
    dp[1][0][0] = 1;
    dp[1][1][1] = 1;

    for(int row=1;row<n;++row)
    {
        int MAX_SKIP_NUM = min(row, n-row);
        int MAX_SKIP_NUM_NEXT = min(row+1,n-row-1);
        for(int skipnum = 0; skipnum<=MAX_SKIP_NUM; ++skipnum)
        {
            for(int val = 0; val <= k; ++val)
            {
                (dp[row+1][skipnum][val+skipnum] += (skipnum+1+skipnum) * dp[row][skipnum][val]) %= mof;
                
                if(skipnum+1 <= MAX_SKIP_NUM_NEXT)
                    (dp[row+1][skipnum+1][val+skipnum+1] += dp[row][skipnum][val]) %= mof;
                
                if(skipnum-1 >= 0)
                    (dp[row+1][skipnum-1][val+skipnum-1] += skipnum * skipnum * dp[row][skipnum][val]) %= mof;
            }
        }
    }
    return dp[n][0][k];
}
int main()
{
    int n,k;
    cin>>n>>k;
    if(k%2==1)
    {
        cout<<0<<endl;
        return 0;
    }
    cout<<solve(n,k/2)<<endl;
}


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


int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if((500*i+100*j+50*k)==x){
                    cnt++;
                 }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N, R;

int main() {
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    }
    else {
        cout << (R + 100 * (10 - N)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <stack>
#include <limits.h>
#include <ios>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(k,n)    for( ll i=k;i<n;i++)
#define ll long long int
#define mp make_pair
//#define edge pair<ll, pair<ll, int>> 
using namespace std;

int main() {
	int n, m;
	cin>>n>>m;
	int a, b;
	cin>>a;
	bool arr[40], tmp[40];
	memset(arr, false, sizeof(arr));
	memset(tmp, false, sizeof(tmp));
    int cnt = 0;
	f(0, a) {
	    cin>>b;
	    arr[b] = true;
        
	}
    cnt = a;
	f(1, n){
	    cin>>a;
	     cnt = 0;
         memset(tmp, false, sizeof(tmp));
	    for(int j = 0; j < a; j ++){
	        cin>>b;
            
	        
	        if(arr[b]){
	            tmp[b] = true;
	           // cout<<b<<" ";
                cnt ++;
	        }
	    }
       // cout<<endl;
       cnt = 0;
	    for(int j = 0; j < 40; j ++)    {arr[j] = tmp [j]; cnt += tmp[j];}
	}
  //  int cnt = 0;
//	f(0, 40)    if(arr[i])  cnt ++;
    cout<<cnt<<endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i < n; i++)
using namespace std;

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

    if (s.at(2) == s.at(3) && s.at(4) == s.at(5))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

#define ll   	long long
#define pb	    push_back
#define F   	first
#define S	    second
#define B   	begin()
#define E	    end()
#define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std ;


const int BIG = 1e5 + 7 ;
int l[BIG] , r[BIG] ;
int main()
{
    FASTIO
    int n , m ;
    cin >> n >> m ;
    int mx = -1 , mn = BIG ;
    while ( m-- )
    {
        int l , r ;
        cin >> l >> r ;
        mx = max ( mx , l ) ;
        mn = min ( mn , r ) ;
    }
    cout << max ( mn - mx + 1 , 0 ) ;
    return 0 ;
}



Measured memory_bytes: 3608
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const ll INF = (ll)1e16;

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

  vector<vector<pii>> edge(N, vector<pii>());

  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a-1].push_back(make_pair(b-1, -c));
  }
  ll dist[N];
  REP(i, N) dist[i] = INF;
  dist[0] = 0;
  REP(i, N-1) REP(from, N) {
    for (const auto& e : edge[from])
      if (dist[from] != INF && dist[e.first] > dist[from] + e.second)
        dist[e.first] = dist[from] + e.second;
  }
  ll ans = dist[N-1];
  bool negative[N];
  REP(i, N) negative[i] = false;
  // REP(i, N) REP(from, N) {
  REP(from, N) {
    for (const auto& e : edge[from]) {
      if (dist[from] != INF && dist[e.first] > dist[from] + e.second) {
        dist[e.first] = dist[from] + e.second;
        negative[e.first] = true;
      }
      if (negative[from])
        negative[e.first] = true;
    }
  }
  if (negative[N-1])
    printf("inf\n");
  else
    printf("%lld\n", -ans);
  return 0;
}


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

signed main(){
	int N, i, j;
	scanf("%lld", &N);
	vector<vector<char>> s(N, vector<char>(10));
	for(i = 0; i < N; i++){
		string sub;
		cin >> sub;
		for(j = 0; j < 10; j++){
			s[i][j] = sub[j];
		}
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end());
	int now = 1, ans = 0;
	for(i = 1; i < N; i++){
		if(s[i] == s[i - 1]){
			now++;
		}
		else{
			now = 1;
		}
		ans += now - 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 S;
  std::cin >> S;
  constexpr i64 I64_1E9 = 1000000000;
  std::cout << I64_1E9 << ' ' << tools::ceil(S, I64_1E9) * I64_1E9 - S << ' ' << 1 << ' ' << tools::ceil(S, I64_1E9) << ' ' << 0 << ' ' << 0 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    ll d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
ll invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[200010],finv[200010],inv[200010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,200010){
        fac[i]=fac[i-1]*i%inf;
        inv[i]=invmod(i,inf);
        finv[i]=finv[i-1]*inv[i]%inf;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%inf)%inf;
}
int main(){
    combinit();
    ll n,m,k;cin>>n>>m>>k;
    ll d=comb(n*m-2,k-2)%inf;
    ll cntn=0,cntm=0;
    REP(i,1,n+1)cntn=(cntn+(2*i-n-1)%inf*i%inf)%inf;
    REP(i,1,m+1)cntm=(cntm+(2*i-m-1)%inf*i%inf)%inf;
    ll ans=((m*m%inf)*d%inf*cntn%inf+(n*d%inf)*n%inf*cntm%inf)%inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
import           Data.List

solve :: [String] -> (Int, Int, Int, Int)
solve = foldl f (0, 0, 0, 0)
  where f (a, b, ab, o) s
          | "AB" `isSuffixOf` s = (a, b, ab + 1, o)
          | "B"  `isSuffixOf` s = (a, b + 1, ab, o)
          | "A"  `isSuffixOf` s = (a + 1, b, ab, o)
          | "O"  `isSuffixOf` s = (a, b, ab, o + 1)
          | otherwise           = (a, b, ab, o)

main :: IO ()
main = getContents >>= printResult . solve . lines
  where printResult (a, b, ab, o) = do
          print a
          print b
          print ab
          print o

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a.begin(),a.end());

    double sum=0;
    for(int i=0;i<n;i++)sum+=a[i];
    bool ans = true;
    for(int i=0;i<m;i++){
        int votes = a[n-1-i];
        //cout << "debug " << sum/4/m << " " << votes << endl;
        if(votes<sum/4/m)ans = false;
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
/* ex6_2
    fmuacshai */
#include <stdio.h>

int main(void){
    char word[100];
    int count,i;
    count=0;
    scanf("%s",word);
    for(i=0;word[i]!='\0';i++){
        count++;
    }
    count-=2;
    printf("%c",word[0]);
    printf("%d",count);
    printf("%c",word[count+1]);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0233
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                Stack<string> res = new Stack<string>();
                while (n != 0)
                {
                    int q = n / -10;
                    int r = n - (q * -10);

                    if (r < 0)
                    {
                        r += 10;
                        q += 1;
                    }

                    res.Push(r.ToString());
                    n = q;
                }
                Console.WriteLine(WAr(res, string.Empty));
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



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

int main(){
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    else if (b == 'T') cout << 'A' << endl;
    else if (b == 'G') cout << 'C' << endl;
    else cout << 'G' << endl;
}

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

int main() {
    int n, a, b;
    cin >>n >> a >>b;
    int ret = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = i;
        int c = 0;
        while (tmp!=0) {
            c += tmp % 10;
            tmp /= 10;
        }
        if (a<=c && c<=b) ret += i;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
# https://beta.atcoder.jp/contests/abc061/tasks/abc061_b


def solve():
    n, m = map(int, input().split())
    roads = {}

    for i in range(1, n+1):
        roads[i] = 0

    for _ in range(m):
        road = input().split()
        for r in road:
            roads[int(r)] += 1

    for road in roads.values():
        print(road)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        mut S: Chars,
        mut T: Chars,
    }

    S.reverse();
    T.reverse();

    let s = S.len();
    let t = T.len();

    if t > s {
        println!("UNRESTORABLE");
        return;
    }

    // できるだけ後ろでハメて、残りの?をaにする
    // ...のは面倒なので、逆順にして最も前の一致を見る

    for i in 0..(s - t + 1) {
        let mut new_s = S.clone();

        let mut is_ok = true;
        for j in 0..t {
            if new_s[i + j] == '?' {
                new_s[i + j] = T[j];
            } else if new_s[i + j] == T[j] {
                // pass, ok
            } else if new_s[i + j] != T[j] {
                is_ok = false;
                break;
            }
        }

        // 残っている'?'を置き換えて出力
        if is_ok {
            for i in 0..s {
                if new_s[i] == '?' {
                    new_s[i] = 'a';
                }
            }

            let ans: Vec<char> = new_s.clone();
            for c in ans.iter().rev() {
                print!("{}", c);
            }
            println!("");
            return;
        }
    }

    println!("UNRESTORABLE");
}


Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
#include <queue>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	int N,K;
	cin >> N >> K;
	int count = 0;
	for(int i = 0; i < N; i++)
	{
		int h;
		cin >> h;
		if(h >= K) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
import sys
l = 3500
for a in range(1, l):
    for b in range(1, l):
        if (4*a*b - n*(a+b)) > 0 and n*a*b % (4*a*b - n*(a+b)) == 0:
            print(a, b, n*a*b // (4*a*b - n*(a+b)))
            sys.exit()

Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static double a=sc.nextDouble();
	private static double b=sc.nextDouble();
	private static int c=sc.nextInt();
	private static double s,l,h;
	public static void main(String[] args){
		s=(a*b*Math.sin(c*Math.PI/180))/2;
		h=b*Math.sin(c*Math.PI/180);
		l=a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(c*Math.PI/180));
		System.out.println(s);
		System.out.println(l);
		System.out.println(h);
	}
}

Measured memory_bytes: 27992
s = str(input())
t = str(input())

lens = len(s)
lent = len(t)

con = lent;

for x in range(lens - lent + 1):
    zz = 0;
    for y in range(lent):
        if s[x+y] != t[y]:
            zz += 1;
    if zz < con:
        con = zz;

print(con)

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,n,j,t,m=0,s=0;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		s+=t;
		m=max(t,m);
	}
	cout<<s-m/2;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::marker::*;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let res = solve(n);
    println!("{}", res);
}

fn solve(n: usize) -> String {
    let mut ret = "".to_string();
    for _ in 0..n {
        ret.push_str("ACL");
    }
    ret
}


Measured memory_bytes: 2060
S = input()

N = len(S)
ans = [0] * N

back = front = 0
for i in range(N - 1):
    if not (S[i] == "R" and S[i + 1] == "L"):
        continue
    for j in range(i + 1, N):
        if S[j] == "L":
            front = j
        else:
            break

    left, right = i - back + 1, front - i
    ans[i] += (left + 1) // 2 + right // 2
    ans[i + 1] += left // 2 + (right + 1) // 2
    back = front + 1

print(*ans)


Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>

int main(){
    long long a,b,c;
    std::cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0)std::cout<<0<<std::endl;
    else{
        long long ans=1;
        if(a<=b||a<=c)ans=ans*a;
        if(b<a||b<=c)ans=ans*b;
        if(c<a||c<b)ans=ans*c;
        std::cout<<ans<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m,c[2000],gs[2000],b[2000],dp[5000];
int main()
{
    n=read(),m=read();reg int i,j;
    for(i=1;i<=m;++i)
    {
        c[i]=read(),gs[i]=read();
        for(j=1;j<=gs[i];++j)b[i]|=(1<<(read()-1));
    }
    reg int s=1<<n;
    for(i=0;i<s;++i)dp[i]=2e9;
    dp[0]=0;
    for(i=0;i<s;++i)
        for(j=1;j<=m;++j)
            dp[i|b[j]]=min(dp[i|b[j]],dp[i]+c[j]);
    if(dp[s-1]==2e9)puts("-1");
    else cout<<dp[s-1]<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <limits>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

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

    vector<int> x(n,0);
    vector<int> y(n,0);
    rep(i,n){
        cin >> x[i] >> y[i];
    }

    double ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i!=j)
                ans += sqrt(pow((x[i] - x[j]), 2.0) + pow((y[i] - y[j]), 2.0));
        }
    }
    cout << setprecision(10) << ans/n << endl;
}

Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  
 int a, b, c, d, e, x = 0;
 for(int i = A; i < B+1; i++){
 a = i % 10;
 b = (i/10) % 10;
 c = (i/100) % 10;
 d = (i/1000) % 10;
 e = (i/10000) % 10;
 
   
   
  if(a == e && b == d){
   
    x += 1;
  
  }
 }
  cout << x << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll r,x,d;
  cin >> r >> d >> x;
  rep(i,10){
    x = r*x - d;
    cout << x << endl;
  }
 return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

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

const int max_n = 2000+10;

int H,W;
int field[max_n][max_n];
int dpH[max_n][max_n];
int dpW[max_n][max_n];

int main(void) {
    cin>>H>>W;
    string s;
    for(int i = 0;i < H;i++) {
        cin>>s;
        for(int j = 0;j < s.size();j++) {
            if(s[j] == '#')
                field[i][j] = -1;
        }
    }

    for(int i = 0;i < H;i++) {
        int sum = 1;
        for(int col = 0;col < W;col++) {
            if(field[i][col] == -1) {
                sum = 1;
                continue;
            }
            dpH[i][col] = sum;
            sum++;
        }
        for(int col = W-2;col >= 0;col--) {
            if(field[i][col] == -1)
                continue;
            if(field[i][col+1] == -1)
                continue;
            dpH[i][col] = dpH[i][col+1];
        }
    }
    
    for(int i = 0;i < W;i++) {
        int sum = 1;
        for(int row = 0;row < H;row++) {
            if(field[row][i] == -1) {
                sum = 1;
                continue;
            }
            dpW[row][i] = sum;
            sum++;
        }
        for(int row = H-2;row >= 0;row--) {
            if(field[row][i] == -1)
                continue;
            if(field[row+1][i] == -1)
                continue;
            dpW[row][i] = dpW[row+1][i];
        }
    }

    int ans = 0;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            ans = max(ans,dpH[i][j]+dpW[i][j]-1);
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 47488
def main():
    N, M = map(int, input().split())

    # Sから作れる数
    n_cc = M // 2
    n_scc = min(N, n_cc)

    # cから作れる数
    n_s = N - n_scc
    n_c = M - n_scc * 2
    n_add_scc = n_c // 4
    # n_c -= n_add_scc * 4

    ans = n_scc + n_add_scc

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int n, arr[21][21], dp[3000000][21];

long long int recursive(int durum, int konum){
	if(konum==n)return 1;
	if(dp[durum][konum]!=-1)return dp[durum][konum];
	long long int cvp=0;
	for(int i=0;i<n;i++){
		if(!((durum>>i)&1)&&arr[konum][i]==1)
			cvp=(cvp+recursive(durum|(1<<i) , konum+1))%MOD;
	}
	dp[durum][konum]=cvp;
	return cvp;
}

int main(void){
	cin>>n;
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n*n;i++){
		cin>>arr[i/n][i%n];
	}
	cout<<recursive(0, 0);

	return 0;
}

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

typedef long long ll;

int main(){
    ll x;
    cin >> x;
    
    ll ans=0;
    
    ans = x/11*2;
    if(x%11==0){
        cout << ans << endl;
    }
    else if(x%11<=6){
        ans++;
        cout << ans << endl;
    }
    else if(x%11>=7){
        ans += 2;
        cout << ans << endl;
    }
}


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

int main() {
  int N,X;
  cin >>N>>X;
  vector<int> L(N);
     int D=0;
  for (int i=0;i<N;i++){
  cin >>L[i];
  }
  int answer=1;
  for (int i=0;i<N;i++){
    D+=L[i];
     if(D<=X){
      answer++;
     }
  }
  cout << answer <<endl;
}


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

int main() {
	int n;
	cin >> n;
	int maxx = 0;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	int total = 0;
	for(int i = 0; i < n; i++)
	{
		if(i == n-1)
		{
			total += a[i]/2;
		}
		else
		{
			total += a[i];
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define inf 0x3f3f3f3f

using namespace std;

int m,n,temp1,temp2,ans,used[10005],mincost[10005],mindis[10005],mark;

struct road
{
    int from,to,l,w;
}r[20005];

void Dijkstra()
{
    memset(used,0,sizeof(used));
    memset(mincost,inf,sizeof(mincost));
    memset(mindis,inf,sizeof(mindis));
    for(int i=1;i<=n;i++)
    {
        if(r[i].from==1)
        {
            mincost[r[i].to]=r[i].w;
            mindis[r[i].to]=r[i].l;
        }
        if(r[i].to==1)
        {
            mincost[r[i].from]=r[i].w;
            mindis[r[i].from]=r[i].l;
        }
    }
    used[1]=1;
    for(int i=2;i<=m;i++)
    {
        mark=-1;
        for(int i=1;i<=m;i++)
            if(!used[i]&&(mark==-1||mindis[i]<mindis[mark]))
                mark=i;
        used[mark]=1;
        ans+=mincost[mark];
        for(int i=1;i<=n;i++)
        {
            if(r[i].from==mark)
            {
                if(!used[r[i].to])
                {
                    if(mindis[r[i].to]>mindis[r[i].from]+r[i].l)
                    {
                        mindis[r[i].to]=mindis[r[i].from]+r[i].l;
                        mincost[r[i].to]=r[i].w;
                    }
                    if(mindis[r[i].to]==mindis[r[i].from]+r[i].l)
                        mincost[r[i].to]=min(mincost[r[i].to],r[i].w);
                }
            }
            if(r[i].to==mark)
            {
                if(!used[r[i].from])
                {
                    if(mindis[r[i].from]>mindis[r[i].to]+r[i].l)
                    {
                        mindis[r[i].from]=mindis[r[i].to]+r[i].l;
                        mincost[r[i].from]=r[i].w;
                    }
                    if(mindis[r[i].from]==mindis[r[i].to]+r[i].l)
                        mincost[r[i].from]=min(mincost[r[i].from],r[i].w);
                }
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    while(cin>>m>>n&&m)
    {
        ans=0;
        for(int i=1;i<=n;i++)
            cin>>r[i].from>>r[i].to>>r[i].l>>r[i].w;
        Dijkstra();
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3452
def main():
  H,N = map(int,input().split())
  AB = [list(map(int,input().split())) for _ in range(N)]
  ab = min(AB,key = lambda x:x[1])
  INF = float('inf')
  dp = [INF]*(H+1)
  mi_a = ab[0]
  mi_b = ab[1]
  dp[0] = 0
  for i in range(1,H+1):
    if i<=mi_a:
      dp[i]=mi_b
    else:
      mi = float('inf')
      for a,b in AB:
        mi = min(mi,dp[max(0,i-a)]+b)
      if dp[i]>mi:
        dp[i] = mi

  print(dp[H])
  
main()

Measured memory_bytes: 42732
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int cnt = 0;
		String s,t;
		Scanner sc = new Scanner(System.in);
		s = sc.next();
		t = sc.next();
		for(int i = 0; i < 3; ++i) {
			if(s.charAt(i) == t.charAt(i))	++cnt;
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
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; }

const long long INF = 1LL << 60;
long long h[100010]={INF};
long long dp[100010]={INF};

int main() {
    int N,K; cin >> N>>K;
    for (int i = 0; i < N; ++i) cin >> h[i];
    for (int i = 0; i < 100010; ++i) dp[i]=INF;
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
      for(int j=1;j<=K;j++){
        chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1] - a[0]);
	}
}

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

int main(){

    int n,x;
    cin >> n >> x;
    vector<int> a(n);

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

    sort(a.begin(),a.end());
    ll cnt=0;
    for(int i=0;i<n;i++){
        x-=a[i];
        if(i==n-1&&x!=0){
            break;
        }
        if(x<0){
            break;
        }
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
char alphabet[30];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin>>n;
	int level=0;
	int p=1;
	while(n>=p){
		n-=p;
		p*=26;
		level++;
	}
	string str;
	while(n){
		str=char((n%26)+97)+str;
		n/=26;
		level--;
	}
	while(level>0){
		str='a'+str;
		level--;
	}
	cout<<str;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e4+5,D=105,mod=1e9+7;
string str;
ll d,n,dp[N][D][2];
ll solve(ll i,ll sum,bool flg){
    if(i==n)return sum==0;
    if(dp[i][sum][flg]!=-1)return dp[i][sum][flg];
    ll &ans = dp[i][sum][flg];
    ans = 0;
    ll s = 0 , e=9;
    if(!flg)e=(str[i]-'0');
    for(ll dig=s;dig<=e;dig++){
        ll nsum = sum + dig;
        nsum%=d;

        bool nflg = flg || (dig<(str[i]-'0'));
        ans = ans + solve(i+1,nsum,nflg);
        ans%=mod;
    }
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>str>>d;
    n=str.size();
    memset(dp,-1,sizeof(dp));
    cout<<( solve(0,0,0) - 1 + mod)%mod;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int k;
	cin>>k;
	string s;
	cin>>s;
	int n = s.length();
	if(n <= k){
		cout<<s<<endl;
	}
	else{
		cout<< s.substr(0,k) + "...\n";
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<pll> v(n);
  rep(i, n)
  {
    ll x, l;
    cin >> x >> l;
    v[i].first = x + l;
    v[i].second = x - l;
  }
  sort(all(v));
  ll t = -LINF, ans = 0;
  rep(i, n)
  {
    if (v[i].second >= t)
    {
      ans++;
      t = v[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
const int mod=1000000007;
int N,deg[20],g[20],cnt[2][20];
bool G[20][20];
int dfs(int i){
	if(i==1){
		int t=deg[0]+deg[1],s=1<<t,w=1;
		if(G[0][1])--t;
		for(i=0;i<N&&w;i++){
			t-=cnt[0][i]+cnt[1][i];
			s-=w<<t;
			w=(w<<cnt[0][i])-w;
			w=(w<<cnt[1][i])-w;
		}
		return s;
	}
	int t=deg[i],c[t+1];
	long long s=0,w=1;
	for(int j=0;j<=deg[i];j++)c[j]=0;
	for(int j=i+1;j<N;j++)if(G[i][j]&&g[j]<=deg[i])c[g[j]]++;
	for(int j=0;j<=deg[i]&&w;j++){
		t-=c[j];
		g[i]=j;
		if(G[0][i])cnt[0][j]++;
		if(G[1][i])cnt[1][j]++;
		(s+=w*dfs(i-1)%mod<<t)%=mod;
		w=((w<<c[j])-w)%mod;
		if(G[0][i])cnt[0][j]--;
		if(G[1][i])cnt[1][j]--;
	}
	return s;
}
int main(){
	int M;scanf("%d%d",&N,&M);
	while(M--){
		int x,y;scanf("%d%d",&x,&y);
		G[--x][--y]=1;
		deg[x]++;
	}
	printf("%d\n",dfs(N-1));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define SORTR(v,n) sort(v,v+n,greater<int>())
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();



int main(){
  ll n,res=0;
  cin >> n;
  ll a[3*100000+1];
   REP(i, 3*n) cin >> a[i];
   SORTR(a,3*n);

   REP(i,2*n){
     res += a[i + 1];
     i++;
   }

   cout<< res << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            long N = IO.RLong;
            var a = IO.RSLong;

            long oddCnt = 0;
            for (int i = 0; i < N; i++)
            {
                if (a[i] % 2 == 1) oddCnt++;
            }
            IO.WriteLineYES_or_NO(oddCnt % 2 == 0);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 29356
N,M = map(int,input().split())

A = [list(map(int,input().split())) for _ in range(N)]

A.sort()

x = 0
y = 0

for i,j in A:
  if M - x < j:
    y += i * (M-x)
    break    
  else:
    x += j
    y += i * j

print(y)    


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

int main() {
	int m, a, b;
	while (cin >> m >> a >> b,m,a,b) {
		int p[300];
		for (int i = 0;i < m;i++)cin >> p[i];

		int ans = 0;
		int g = 0;

		for (int i = 0;i < m - 1;i++) {
			int c = p[i] - p[i + 1];
			if (g <= c && (i + 1 >= a) && (i + 1 <= b)) {
				ans = i + 1;
				g = c;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
import heapq
def main():
    h, w = map(int, input().split())
    strt_y, strt_x = map(int, input().split())
    goal_y, goal_x = map(int, input().split())
    stage = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h):
        s = input()
        for j in range(w):
            if s[j] == ".":
                stage[i+2][j+2] = float("inf")
    strt_y += 1
    strt_x += 1
    goal_y += 1
    goal_x += 1
    hq = [[0, strt_y, strt_x]]
    stage[strt_y][strt_x] = 0
    while len(hq) > 0:
        pt, crr_y, crr_x = heapq.heappop(hq)
        if stage[crr_y][crr_x] < pt:
            continue
        if crr_y == goal_y and crr_x == goal_x:
            break
        for i in range(crr_y-2, crr_y+2+1):
            for j in range(crr_x-2, crr_x+2+1):
                if abs(crr_y-i) + abs(crr_x-j) == 1:
                    if pt < stage[i][j]:
                        stage[i][j] = pt
                        heapq.heappush(hq, [pt, i, j])
                else:
                    if pt+1 < stage[i][j]:
                        stage[i][j] = pt+1
                        heapq.heappush(hq, [pt+1, i, j])
    if stage[goal_y][goal_x] == float("inf"):
        print(-1)
    else:
        print(stage[goal_y][goal_x])

if __name__ == "__main__":
    main()

Measured memory_bytes: 123412
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>

int main(){

  long long int N;
  scanf("%lld", &N);

  std::string S;
  std::cin >> S;
  
  for(long long int i = 0; i < S.length(); i++){
    S[i] = 'A' + (S[i] -'A'+N)%26;
  }
  
  std::cout << S;
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
///////////////////////////
const int N = 5 + 2e5;

int n;
LL ans,sum,t;
map<LL,int>f;
int main() {
    
    cin>>n;
    f[0]=1;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        sum+=t;
        if(f.count(sum))ans+=f[sum];
        f[sum]++;
    }
    cout<<ans;

    return 0;
}



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

int main(){
  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;

  if ( (x-r < 0) || (x+r > w) ){
    cout << "No" << endl;
  }
  else if ( (y-r < 0) || (y+r > h)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 3072
function Main(input) {
    var data = input.split("\n")
	var req =  data[0].split(" ").map((n) => parseInt(n, 10));
	var height =  data[1].split(" ").map((n) => parseInt(n, 10));
	
	var count = 0;
	for(var i=0; i<req[0];i++){
		if(height[i] >= req[1]){
			count++;
		} 
	}
	console.log(count)
}
 
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16576
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int n, m, x, cf = 0, cb = 0;
  cin >> n >> m >> x;
  vector<int> v(m);
  rep(i, 0, m) {
    cin >> v[i];
    if(v[i] < x) {
      cf++;
    } else {
      cb++;
    }
  }
  cout << min(cf, cb);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long MOD = 1e9 + 7;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll count = 0;
    if(A[0] > X) {
        count += A[0] - X;
        A[0] = X;
    }
    rep(i, 1, N) {
        if(A[i] + A[i - 1] > X) {
            count += A[i] + A[i - 1] - X;
            A[i] -= A[i] + A[i - 1] - X;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3780