akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
bool pos[100000];
vector<int> x[100000];
int n,m,dp[100000];
void idi(int i){
	pos[i]=1;
	for(int j=0;j<x[i].size();j++){
		if(!pos[x[i][j]])
			idi(x[i][j]);
		dp[i]=max(dp[i],dp[x[i][j]]+1);
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)pos[i]=dp[i]=0;
	for(int i=0,a,b;i<m;i++){
		cin>>a>>b;
		--a;--b;
		x[a].pb(b);
	}
	for(int i=0;i<n;i++)
		if(!pos[i])
			idi(i);
	int ma=0;
	for(int i=0;i<n;i++)
		ma=max(ma,dp[i]);
	cout<<ma;
	return 0;
}

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

int main(void) {
    int N,M;
    int ktemp,stemp;
    int mtemp;
    int cnt = 0;
    cin >> N >> M;

    vector<int> k(M,0);
    vector<int> p(M);
    for(int i=0;i<M;i++) {
        cin >> ktemp;
        for(int j=0;j<ktemp;j++) {
            cin >> stemp;
            k[i] |= (1 << (stemp-1));
        }
    }

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

    for(int i=0;i<(1<<N);i++) {
        bool sw = true;
        for(int j=0;j<M;j++) {
//printf("all:0x%x j:%d k[%d]:%d sw:0x%x bit:%d p:%d\n", i, j,j,k[j], (i&k[j]), __builtin_popcount(i&k[j]), p[j]);
            if((__builtin_popcount(i & k[j])%2) == p[j]) {
            } else {
                sw = false;
                break;
            }
        }

        if(sw) cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

dishes = [int(input()) for _ in range(5)]

min_loss = 10
min_dish = dishes[0]
cooking_time = []
for d in dishes:
    loss = 0 if d % 10 == 0 else d % 10
    if loss != 0 and min_loss > loss:
        min_loss = loss
        min_dish = d
dishes.remove(min_dish)
for d in dishes:
    loss = 0 if d % 10 == 0 else 10 - d % 10
    cooking_time.append(d + loss)
print(sum(cooking_time) + min_dish)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC138
{
    class Program
    {
        static void Main(string[] args)
        {
            C();

            Console.Read();
        }

        static void C()
        {
            int N = int.Parse(Read());
            List<int> v = new List<int>();
            string[] input = Read().Split(' ');
            for (int i = 0; i < N; i++) v.Add(int.Parse(input[i]));
            v = v.OrderBy(x => x).ToList();

            //for (int i = 0; i < N; i++) Show(v[i].ToString());

            double temp = ((double)v[0] + (double)v[1]) / 2;
            for(int i = 2; i < N ; i++)
            {
                temp = (temp + v[i]) / 2;
            }
            Show(temp.ToString());
        }
        static void B()
        {
            int N = int.Parse(Read());
            string[] s = Read().Split(' ');
            int[] A = new int[N];
            for (int i = 0; i < N; i++) A[i] = int.Parse(s[i]);

            double sum = 0;
            foreach (int itemp in A) sum += 1 / (double)itemp;
            double answer = 1 / sum;
            Show(answer.ToString());

        }

        static void A()
        {
            int a = int.Parse(Read());
            string s = Read();
            if (a >= 3200) Show(s);
            else Show("red");
        }

        




        static string Read() { return Console.ReadLine(); }
        static void Show(string s) { Console.WriteLine(s); }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;

int main(){
    vector<char> s(4);
    rep(i, 4) cin >> s[i];
    cout << count(all(s), '+') - count(all(s), '-') << endl;

}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc119/tasks/abc119_a

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>


using namespace std;
int main(){
	string s;
	string x1;
	int x2;
	string ans;
	
	cin>>s;
	x1=s.substr(5,2);
	x2=stoi(x1);
	
	if(x2<5) ans="Heisei";
	else ans="TBD";

	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,ans;
    cin>>a>>b>>c>>d;
    ans=a*c;
    ans=max(ans,b*d);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    cout<<ans<<endl;

}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

ll N, K;
vector<ll> A;

void input() {
    cin >> N >> K;
    A.resize(N);
    for (auto &v : A)
        cin >> v;
}

ll maxBeauty(vector<ll>& beauties, int width, ll getAns) {
    vector<ll> mapLog2(width, 0);
    for (auto b : beauties) {
        for (int s = 0; s < width && (b >> s) > 0; s++) {
            if ((b >> s) & 1)
                mapLog2[s]++;
        }
    }
    
    ll ans = 0;
    for (int i = width - 1; i >= 0; i--) {
        if (mapLog2[i] >= K) {
            vector<ll> newB;
            for (auto b : beauties) {
                if ((b >> i) & 1) {
                    newB.push_back(b);
                }
            }
            ans = maxBeauty(newB, i, getAns | (1ULL << i));
            break;
        }
    }
    
    if (ans == 0)
        return getAns;
    return ans;
}

ll solve() {
    ll ca[N];
    ca[0] = A[0];
    for (int i = 1; i < N; i++) {
        ca[i] = ca[i - 1] + A[i];
    }
    auto beauty = [&ca](ll b, ll e) {
        if (b == 0)
            return ca[e];
        return ca[e] - ca[b - 1];
    };
    
    vector<ll> beauties;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            beauties.push_back(beauty(i, j));
        }
    }
    sort(beauties.begin(), beauties.end(), [](auto l, auto r) {
        return l > r;
    });
    
    return maxBeauty(beauties, 64, 0);
}


int main() {
    input();
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 6628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N;
  cin >> N;
  vector<P> X(N);
  REP(i, N) cin >> X[i].first >> X[i].second;
  vector<P> ps(N);
  REP(i, N) { ps[i] = P(X[i].first + X[i].second, X[i].first - X[i].second); }
  sort(ps.begin(), ps.end());
  int cur = -1000000000;
  int ans = 0;
  REP(i, N) {
    if (cur <= ps[i].second) {
      ans++;
      cur = ps[i].first;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second

ll cnt[300]={};
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll x,n,y;
        cin>>x>>n;
        if(!n){cout<<x;break;}
        for(int i=0;i<n;i++){cin>>y;cnt[y]++;}
        ll i=0;
        while(1)
        {
            if(!cnt[x-i]){cout<<x-i;break;}
            else if(!cnt[x+i]){cout<<x+i;break;}
            i++;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int h, w;
  scanf("%d %d", &h, &w);
  vector<string> board(h);
  for (int i = 0; i < h; ++i) { cin >> board[i]; }
  for (int r = 0; r < h; ++r) {
    for (int c = 0; c < w; ++c) {
      if (board[r][c] != '.') { continue; }
      int cnt = 0;
      for (int dr = -1; dr <= 1; ++dr) {
        for (int dc = -1; dc <= 1; ++dc) {
          if (dr == 0 and dc == 0) { continue; }
          int nr = r + dr, nc = c + dc;
          if (0 <= nr and nr < h and 0 <= nc and nc < w and board[nr][nc] == '#') {
            ++cnt;
          }
        }
      }
      board[r][c] = '0' + cnt;
    }
  }
  for (int i = 0; i < h; ++i) {
    printf("%s\n", board[i].c_str());
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 100005
#define ll long long
using namespace std;
const int P=1e9+7;
int n,ans=0;
char A[M];
int cnt[30];
int main(){
    scanf("%d%s",&n,A+1);
    for(int i=1;i<=n;i++){
        int &c=cnt[A[i]-'a'];
        int res=1;
        for(int j=0;j<26;j++)
            if(j!=A[i]-'a')res=(ll)res*(cnt[j]+1)%P;
        ans=(ans+res)%P;
        c++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;


int rec(int n)
{
	while(n>=10)
	{
		n/=10;
	}
	return n;
}

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> m(10,vector<int>(10));

	for(int i=1;i<=n;i++)
	{
		m[rec(i)][i%10]++;
	}
	int ans = 0;
	for(int i = 1;i<10;i++)
	{
		for(int j=1;j<10;j++)
		{
			ans += m[i][j]*m[j][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>

auto toTimeFormat(int inSec) -> std::string {
	int hour   = inSec / 3600;
	int minute = (inSec % 3600) / 60;
	int sec    = (inSec % 3600) % 60;

	std::stringstream ss;
	ss << hour << ":" << minute << ":" << sec;
	return ss.str();
}

auto main() -> int {
	int sec;
	std::cin >> sec;
	std::cout << toTimeFormat(sec) << std::endl;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
   	ll N, K;
    cin >> N >> K;
  	ll A[N];
  	int ans = 0;
    for(int i = 0; i < N; ++i){
   		cin >> A[i];
    }
  	ll table[N] = {0};
   	for(int i = 0; i < N; ++i){
   		table[A[i]-1]++;
    }
  	sort(table, table + N, greater<int>());
  	for(int i = K; i < N; i++){
      ans += table[i];
    }
   
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  
  vector<long long> s(N + 1);
  s[0] = 0;
  for(int i = 0; i < N; i++) s[i + 1] = s[i] + a[i];
  
  queue<long long> q;
  for(int l = 0; l < N; l++){
    for(int r = l + 1; r <= N; r++){
      q.push(s[r] - s[l]);
    }
  }
  
  long long beauty = 0ll;
  for(int b = 63; b >= 0; b--){
    int bit_count = 0;
    for(int j = q.size(); j > 0; j--){
      long long qf = q.front();
      q.pop();
      if(qf & (1ll << b)) bit_count++;
      q.push(qf);
    }
    
    if(bit_count < K) continue;
    
    beauty += (1ll << b);
    for(int j = q.size(); j > 0; j--){
      long long qf = q.front();
      q.pop();
      if(qf & (1ll << b)) q.push(qf);
    }
  }
  
  cout << beauty << endl;
  
  return 0;
}

Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
 
def dfs(now, prev):
    ans[now]+=(h[now]+ans[prev])
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        if next != prev:
            dfs(next, now)
 
 
n, q = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
 
h=[0]*n
for i in range(q):
    u, v = map(int, input().split())
    u -= 1
    h[u]+=v
 
ans=[0]*n
dfs(0,0)
 
print(' '.join(map(str, ans)))

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

using namespace std;

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

  int count = 0;

  for (int i = 0; i < N; i++) {
    if (p[i] != i+1) count++;
  }

  if (count <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            ll sum=0;
            for(i=1;i<=n;++i)
            {
                if(i%3!=0 && i%5!=0)
                {
                    sum=sum+i;
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3648
def String_palind(s):

    ans = "No"
    scount = int((len(s) - 1) / 2)
    ecount = int((len(s) + 3) / 2)
    slen = s[:scount]
    elen = s[ecount - 1:]

    if s == s[::-1] and slen == slen[::-1] and elen == elen[::-1]:
        ans = "Yes"

    return ans

def main():
    s = str(input())
    print(String_palind(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
h,w,k=map(int,input().split())
s=[input() for i in range(h)]
# print(s)
chk="."*w
li=[]
for i in range(h):
    if s[i]==chk:
        li.append(i)
cnt=1
flag=0
flag2=0
ans=[[0]*w for i in range(h)]
# print(ans)
# ans[2]=ans[1]
# ans[2][0]=1
# print(ans)
for i in range(h):
    flag2=0
    # if i in li:
    #     if flag==0:
    #         ans[i]=ans[i+1]
    #         if i+1 not in li:
    #             flag=1
    #     else:
    #         ans[i]=ans[i-1]
    #     continue
    for j in range(w):
        if flag2==0 and s[i][j]==".":
            ans[i][j]=cnt
        elif flag2==0 and s[i][j]=="#":
            ans[i][j]=cnt
            flag2=1
            cnt+=1
        elif (flag2==1 or flag2==2) and s[i][j]==".":
            ans[i][j]=ans[i][j-1]
        elif flag2==1 and s[i][j]=="#":
            ans[i][j]=cnt
            cnt+=1
    # cnt+=1
cnt2=0
last=0
for i in range(h):
    if i in li:
        cnt2+=1
    else:
        flag=1
        for j in range(cnt2):
            print(" ".join(map(str,ans[i])))
        print(" ".join(map(str,ans[i])))
        cnt2=0
        last=i
for i in range(cnt2):
    print(" ".join(map(str,ans[last])))

Measured memory_bytes: 42988
from math import gcd as g
n=int(input())
ans=n*(n+1)//2
for i in range(1,n):
  for j in range(i+1,n+1):
    ans+=6*g(i,j)
for i in range(1,n-1):
  for j in range(i+1,n):
    x=g(i,j)
    for k in range(j+1,n+1):
      ans+=6*g(x,k)
print(ans)

Measured memory_bytes: 9144
def main():
    N = int(input())
    if N == 1:
        print(1)
        return
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))

    d = {}
    for i in range(N):
        tmp = set()
        for j in range(N):
            if i == j:
                continue
            dx = xy[i][0] - xy[j][0]
            dy = xy[i][1] - xy[j][1]

            if (dx, dy) in tmp:
                continue
            if (dx, dy) not in d:
                d[(dx, dy)] = 1
            else:
                d[(dx, dy)] += 1
            tmp.add((dx, dy))

    d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    cnt = d[0][1]
    print(N - cnt)

main()

Measured memory_bytes: 3572
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int A,B,h=0;
	cin >> A >> B;
	for (int i = 1; i < abs(A-B); i++)
	{
		h += i;
	}
	cout << h - A;
}


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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int n, m; cin >> n >> m;
   vector<vector<int>> s(m);
   for (int i = 0; i < m; ++i) {
      int k; cin >> k;
      s[i].resize(k);
      for (int j = 0; j < k; ++j) {
         cin >> s[i][j];
         --s[i][j];
      }
   }
   vector<int> p(m);
   for (int i = 0; i < m; ++i) {
      cin >> p[i];
   }

   int ans = 0;
   for (int S = 0; S < 1<<n; ++S) {
      bool flag = true;
      for (int i = 0; i < m; ++i) {
         int sum = 0;
         for (auto j : s[i]) {
            if (S >> j & 1) {
               ++sum;
            }
         }
         if ((sum - p[i]) % 2 != 0) {
            flag = false;
            break;
         }
      }
      if (flag) {
         ++ans;
      }
   }
   cout << ans << endl;

   return 0;
}


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

#define HEAP_SIZE 2000000
long int heap[HEAP_SIZE + 1];
int heap_size;

void maxHeapify(long int heap[], int i)
{
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;
    long int w;

    if ((l <= heap_size) && (heap[l] > heap[i]))
    {
        largest = l;
    }
    else
    {
        largest = i;
    }
    if ((r <= heap_size) && (heap[r] > heap[largest]))
    {
        largest = r;
    }
    if (largest != i)
    {
        w = heap[i];
        heap[i] = heap[largest];
        heap[largest] = w;
        maxHeapify(heap, largest);
    }

    return;
}

void heapIncreaseKey(long int heap[], int i, long int key)
{
    int w;
    if (key < heap[i])
    {
        return;
    }
    heap[i] = key;
    while (i > 1 && heap[i / 2] < heap[i])
    {
        w = heap[i / 2];
        heap[i / 2] = heap[i];
        heap[i] = w;
        i = i / 2;
    }
    return;
}

void maxHeapInsert(long int heap[], long int key)
{
    heap_size = heap_size + 1;
    heap[heap_size] = -1;
    heapIncreaseKey(heap, heap_size, key);
    return;
}

long int heapExtractMax(long int heap[])
{
    long int max;
    if (heap_size < 1)
    {
        return (-1);
    }
    max = heap[1];
    heap[1] = heap[heap_size];
    heap_size = heap_size - 1;
    maxHeapify(heap, 1);
    return (max);
}

int main()
{
    char cmd[30];
    long int key;

    do
    {
        scanf("%s", cmd);
        if (strcmp("insert", cmd) == 0)
        {
            scanf("%ld", &key);
            maxHeapInsert(heap, key);
        }
        else if (strcmp("extract", cmd) == 0)
        {
            printf("%ld\n", heapExtractMax(heap));
        }
    } while (strcmp("end", cmd) != 0);

    return (0);
}


Measured memory_bytes: 9592
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N,M = II()
A,B = Line(N)
a = []
for i in range(N):
  a.append([A[i],-B[i]])
a.sort(key = lambda x:(x[0]))

from bisect import bisect_left, bisect_right
import heapq

ans = 0
p = 0
h = []

for i in range(1,M+1):
  while p<N and a[p][0]==i:
    heapq.heappush(h,a[p][1])
    p += 1
  if h:
    x = heapq.heappop(h)
    ans += -x

print(ans)

Measured memory_bytes: 95320
package main

import "fmt"

func main() {
	var n, d, x, ans int
	fmt.Scan(&n, &d, &x)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := 1; i <= d; i++ {
		for j := range a {
			if (i-1)%a[j] == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans + x)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K;
  cin >> K;
  if(K%2==1){
  int M=K/2;
  cout << (M+1)*M << endl;
  }
  if(K%2==0){
  cout << (K/2)*(K/2) << endl;
  }
}
  

  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int num = min(x,y); x-= num; y -= num;
    int ans = min(num*a+num*b, c*num*2);
    if(x > 0) ans += min(x*a, x*c*2);
    else if(y > 0) ans += min(y*b, y*c*2);
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	// ( n * a ) % b == c


	std::string ans = "NO";
	for( int i = 0; i <= b; i++ ) {
		if( ( i * a ) % b == c ) {
			ans = "YES";
			break;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}



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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n, m;
vi adj[N];
bool in[N];
int dp[N];

int dfs(int cur, int par = -1) {
	int &ret = dp[cur];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int to : adj[cur]) {
		if (to == par)
			continue;
		ret = max(ret, dfs(to, cur));
	}
	ret++;
	return ret;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		in[v] = 1;
		adj[u].pb(v);
	}
	MMS(dp, -1);
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (!in[i]) {
			res = max(res, dfs(i));
		}
	}
	cout << res - 1 << endl;
	return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
#define N 100002
#define mod 1000000007
#define lld long long 
int main()
{
   lld n,x,y; cin>>n>>x>>y;
   int dp[n+1][n+1];
   memset(dp,0,sizeof(dp));
   int len=(y-x+1);
   for(int i=1;i<n;++i){
    for(int j=i+1;j<=n;j++){
            int pp=0;
            int xx=i;
            int yy=j;
            if(xx<=x)pp=x-xx,xx=x;
            if(yy>=y) pp+=(yy-y),yy=y;
            dp[i][j]=pp+min(yy-xx,len-yy+xx);
           // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    }
   }
   int res[n];
   memset(res,0,sizeof(res));
   for(int i=1;i<n;++i)
   {
    for(int j=i+1;j<=n;++j)res[dp[i][j]]++;
   }

   for(int i=1;i<n;++i)cout<<res[i]<<endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll mod = 1000000007;

ll frac(ll n) {
  if (n == 0) return 1;
  return (n * frac(n-1)) % mod;
}

int main()
{
  ll n,m;
  cin>>n>>m;
  if (n<m) swap(n,m);
  if (n > m+1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  if (n == m) ans = 2;
  ans *= frac(n);
  ans %= mod;
  ans *= frac(m);
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
s = input()
n = len(s)
dp = [[0] * 2 for _ in range(n)]
dp[0][0] = 1
dp[0][1] = 1
dp[1][0] = dp[0][1] + (s[0] != s[1])
dp[1][1] = dp[0][1] + 1
for i in range(2, n):
    for j in range(2):
        for k in range(2):
            now = s[i - k - 1:i]
            nxt = s[i:i + j + 1]
            dp[i][j] = max(dp[i][j], dp[i - k - 1][k] + (now != nxt))
print(max(dp[n - 1]))


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

int main() {
  int N;
  cin >> N;
  vector<unsigned long> a(N);
  bitset<32> s(0uL);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    s ^= bitset<32>(a[i]);
  }

  for (int i = 0; i < N; i++) {
    cout << (s ^ bitset<32>(a[i])).to_ulong() << " ";
  }
  cout << endl;
}


Measured memory_bytes: 4708
def read_values():
    return map(int, input().split())


def read_list():
    return list(map(int, input().split()))


def main():
    N, X = read_values()
    A = read_list()

    pre = A[0]
    res = 0
    for i in range(1, N):
        a = A[i]
        count = max(0, (pre + a) - X)
        if count > 0:
            if A[i] < count:
                A[i] = 0
            A[i] = max(0, A[i] - count)
            res += count
        pre = A[i]
    
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    string s,t;
    cin >> s >> t;
    
    if(s == t.substr(0,int(s.length()))) cyes;
    else cno;
    
    

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

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

long long read(void) {
	long long d;
	cin >> d;
	return d;
}
void println(void) {
	cout << endl;
}
void printFixed(double d, int digit) {
	cout << fixed << setprecision(digit) << d;
}
void printlnFixed(double d, int digit) {
	printFixed(d, digit);
	println();
}

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

	const int DIGITS = 6;
	int div = read();
	vector<int> x(div);
	vector<int> y(div);
	REP(i, div) {
		x[i] = read();
	}
	REP(i, div) {
		y[i] = read();
	}

	long long manhattan_dist = 0;
	long long euclidean_sum = 0;
	long long minkowski3_sum = 0;
	int chevyshev_dist = 0;
	REP(i, div) {
		int diff = abs(x[i] - y[i]);
		if (chevyshev_dist < diff) {
			chevyshev_dist = diff;
		}
		manhattan_dist += diff;
		int diff_sq = diff * diff;
		euclidean_sum += diff_sq;
		minkowski3_sum += diff_sq * diff;
	}
	double euclidean_dist = sqrt(euclidean_sum);
	double minkowski3_dist = cbrt(minkowski3_sum);
	printlnFixed(manhattan_dist, DIGITS);
	printlnFixed(euclidean_dist, DIGITS);
	printlnFixed(minkowski3_dist, DIGITS);
	printlnFixed(chevyshev_dist, DIGITS);
	return 0;
}



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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
string s[4];
int cnt[2][26] = {0};

int main() {
  cin >> s[0] >> s[1];
  for(int i = 0; i < 2; ++i) {
    for(int j = 0; j < s[i].size(); ++j)
      ++cnt[i][s[i][j] - 'a'];
  }
  for(int i = 0; i < 26; ++i)
    for(int j = 0; j < cnt[0][i]; ++j) s[2] += i + 'a';
  for(int i = 25; i >= 0; --i)
    for(int j = 0; j < cnt[1][i]; ++j) s[3] += i + 'a';
  prians(s[2] < s[3]);
  return 0;
}

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

int main() {
  ll q;
  cin>>q;
  vector<ll> v;

  rep(i,q){
    ll a1,b1;
    cin>>a1>>b1;
    if (a1>b1)swap(a1,b1);
    if (a1==b1){
      cout<<(2*a1-2)<<endl;
    }
    else if (a1==(b1+1)){
      cout<<(2*a1-2)<<endl;
    }
    else{
      double temp=sqrt(a1*b1);
      temp=ceil(temp);
      ll idx=temp;
      //ll now=v[idx-1];
    //  cout<<idx<<"now"<<endl;
    idx--;
  //  cout<<idx<<'i'<<endl;
    if ((idx*(idx+1))<a1*b1) cout<<2*idx-1<<endl;
    if ((idx*(idx+1))>=a1*b1) cout<<2*idx-2<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int H, W;
	int cH, cW, dH, dW;
	
	cin >> H >> W;
	cin >> cH >> cW >> dH >> dW;
	--cH, --cW, --dH, --dW;
	
	vector<vector<bool>> processed(H, vector<bool>(W, false));
	vector<vector<char>> g(H, vector<char>(W));
	for(int j=0; j<H; ++j) {
		for(int i=0; i<W; ++i) {
			cin >> g[j][i];
		}
	}
	
	vector<vl> cost(H, vl(W, INF));
	
	cost[cH][cW]=0;
	priority_queue<pair<int,pi>> q;
	q.push({0,{cH,cW}});
	
	while(!q.empty()) {
		
		int j, i, c;
		tie(j,i)=q.top().s;
		c=cost[j][i];
		q.pop();
		
		if(processed[j][i]) continue;
		processed[j][i]=true;
		
		if(j-1>=0 && g[j-1][i]!='#' && cost[j-1][i]>c) cost[j-1][i]=c, q.push({-c,{j-1,i}});
		if(j+1<H && g[j+1][i]!='#' && cost[j+1][i]>c) cost[j+1][i]=c, q.push({-c,{j+1,i}});
		if(i-1>=0 && g[j][i-1]!='#' && cost[j][i-1]>c) cost[j][i-1]=c, q.push({-c,{j,i-1}});
		if(i+1<W && g[j][i+1]!='#' && cost[j][i+1]>c) cost[j][i+1]=c,  q.push({-c,{j,i+1}});
		
		for(int dy=-2; dy<=2; ++dy) {
			if(j+dy<0 || j+dy>=H) continue;
			for(int dx=-2; dx<=2; ++dx) {
				if(i+dx<0 || i+dx>=W) continue;
				
				if(g[j+dy][i+dx]=='#') continue;
				if (cost[j+dy][i+dx]<=c+1) continue;
				else cost[j+dy][i+dx]=c+1, q.push({-(c+1),{j+dy,i+dx}});
			}
		}
		
		//if(cost[dH][dW]!=INF) break;
	}
	
	if(cost[dH][dW]==INF) cout<<"-1\n";
	else cout << cost[dH][dW] << "\n";
	
	/*for(int j=0; j<H; ++j) {
		for(int i=0; i<W; ++i) {
			if(g[j][i]=='#') cout <<"# ";
			else if(cost[j][i]==INF) cout << "INF ";
			else cout << cost[j][i] << " ";
		}
		cout << "\n";
	}*/
	
	return 0;
}


Measured memory_bytes: 12560
n,x= map(int, input().split())
a= list(map(int, input().split()))

ans=0
for i in range(1,n):
    if a[i] + a[i - 1] > x:
        # どれだけ減らさないといけないか
        v = a[i] + a[i - 1] - x
        ans += v
        if i == n - 1:
            a[n - 1] -= v
        else:
            # できるだけ次の値から減算する
            if a[i] - v >= 0:
                a[i] -= v
            else:
                # a[i+1]の項で削りきれなかった分。
                a[i-1] -= v - a[i]
                a[i] = 0
print(ans)


Measured memory_bytes: 63856
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static double a, b, c, d, e, f;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }
    static boolean read(){
        if(!sc.hasNext())return false;
        a = sc.nextDouble();
        b = sc.nextDouble();
        e = sc.nextDouble();
        c = sc.nextDouble();
        d = sc.nextDouble();
        f = sc.nextDouble();
        return true;
    }
    static void solve(){
        double det = a*d - b*c;
        double x = (d*e - b*f)/det, y = (-c*e + a*f)/det;
        x = Math.floor(x*1000 + 0.5)/1000;
        y = Math.floor(y*1000 + 0.5)/1000;
        System.out.printf("%.3f %.3f\n", x, y);
    }
}

Measured memory_bytes: 0
#include<stdio.h>
long long int A[100][100],B[100][100],C[100][100];
main()
{
    int n,m,l,k;
     
    int c1,c2;
     
    scanf("%d %d %d",&n,&m,&l);
     
    for(c1=0;c1<n;c1++){
        for(c2=0;c2<m;c2++){
            scanf("%d",&A[c1][c2]);
        }
    }
     
    for(c1=0;c1<m;c1++){
        for(c2=0;c2<l;c2++){
            scanf("%d",&B[c1][c2]);
        }
    }
     
     
    for(c1=0;c1<n;c1++){
        for(c2=0;c2<l;c2++){
            for(k=0;k<m;k++){
                C[c1][c2]+=A[c1][k]*B[k][c2];
            }
        }
    }
     
    for(c1=0;c1<n;c1++){
        for(c2=0;c2<l;c2++){
            printf("%lld",C[c1][c2]);
            if(c2!=l-1)printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 836
package main

import "fmt"

func main() {
    var n, y int
    fmt.Scan(&n, &y)

    for i := 0; i <= n; i++ {
        for j := 0; i+j <= n; j++ {
            if 10000*i+5000*j+1000*(n-i-j) == y {
                fmt.Println(i, j, (n - i - j))
                return
            }
        }
    }
    fmt.Println(-1, -1, -1)
}

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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b;
	cin >> a >> b;
	if((a + b) & 1){
		cout << "IMPOSSIBLE" << '\n';
	} else {
		cout << (a + b) / 2 << '\n';
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int x, y;
    scanf("%d %d", &x, &y);
    while (x!= 0 || y!= 0)
    {
        if (x < y)
            printf("%d %d\n", x, y);
        else
            printf("%d %d\n", y, x);
        scanf("%d %d", &x, &y);
    }
    return 0;
}



Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

const int N = 1e4 + 1;
int p[N], sz[N];

int  get(int x){
  if (x == p[x]) return x;
  return p[x] = get(p[x]);	
}

void unite(int x, int y){
  x = get(x), y = get(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  p[y] = x;	
}

void solve(){
  int n, q;
  cin >> n >> q;
  for(int i = 1; i <= n; i++){
	  p[i] = i;
	  sz[i] = 1;  
	}	
  for(int i = 0; i < q; i++){
	  int cmd;
	  cin >> cmd;
	  if (cmd == 0){
		  int x, y;
		  cin >> x >> y;
		  unite(x, y);  
		}
	  if (cmd == 1){
		  int x, y;
		  cin >> x >> y;
		  bool ok = (get(x) == get(y));
		  cout << ok << endl;  
		}  
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int MOD = 998244353;
	Int N, S;
	cin >> N >> S;
	vector<Int> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	vector<vector<Int>> dp(N, vector<Int>(S + 10, 0));
	dp[0][0] = 1;
	dp[0][min(S + 1, A[0])] = 1;
	for (int i = 1; i < N; ++i) {
		(dp[i][min(S + 1, A[i])] += 1) %= MOD;
		(dp[i][0] += 1) %= MOD;
		for (int j = 0; j <= S; ++j) {
			(dp[i][j] += dp[i - 1][j]) %= MOD;
		}
		for (int j = 0; j <= S; ++j) {
			Int idx = min(S + 1, j + A[i]);
			(dp[i][idx] += dp[i - 1][j]) %= MOD;
			(dp[i][j] += dp[i - 1][j]) %= MOD;
		}
	}
	cout << dp[N - 1][S] % MOD << endl; 

	return 0;
}


Measured memory_bytes: 73980
#include <iostream>
#include <cstdio>

using namespace std;

int main() {

	while (1) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}

		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				if (y == 0 || y == h-1 || x == 0 || x == w-1) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1112
program main
	implicit none
	integer :: N, x
	integer, allocatable :: a(:)
	integer :: i, counter
	
	read(*, *) N, x
	allocate(a(1:N))
	read(*, *) a
	counter = 0
	
	call heapsort(N,a)
	
	do i = 1, N-1
		if(x-a(i) >= 0 ) then
			counter = counter + 1
			x = x-a(i)
		else
			exit
		end if
	end do
	if(x-a(N) == 0) then
		counter = counter + 1
	end if
	write(*, *) counter
	
	contains
	subroutine heapsort(n,array)
		implicit none
		integer,intent(in) :: n
		integer,intent(inout) :: array(1:n)
  
		integer ::i,k,j,l
		double precision :: t
  
		if(n.le.0)then
			write(6,*)"Error, at heapsort"; stop
		endif
		if(n.eq.1)return
 
		l=n/2+1
		k=n
		do while(k.ne.1)
			if(l.gt.1)then
				l=l-1
				t=array(L)
			else
				t=array(k)
				array(k)=array(1)
				k=k-1
				if(k.eq.1) then
					array(1)=t
					exit
				endif
			endif
			i=l
			j=l+l
			do while(j.le.k)
				if(j.lt.k)then
					if(array(j).lt.array(j+1))j=j+1
				endif
				if (t.lt.array(j))then
					array(i)=array(j)
					i=j
					j=j+j
				else
					j=k+1
				endif
			enddo
			array(i)=t
		enddo
 
		return
	end subroutine heapsort
end program main

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;

struct Node{
  int data;
  Node* left = NULL;
  Node* right = NULL;
};

Node* insert(Node* root, int data){
  if(root==NULL){
    Node* new_node = new Node;
    new_node->data = data;
    return new_node;
  }  
  if(root->data > data) root->left = insert(root->left, data);
  if(root->data < data) root->right = insert(root->right, data);
  
  return root;
  
  // if root == NULL, return new node
  // root->data > data --> insert(root->right, data)
  // root->data < data --> insert(root->left,  data)  
}

void print_inorder(Node* root){
  if(root == NULL) return;
  print_inorder(root->left);
  cout << " " << root->data;
  print_inorder(root->right);
}

void print_preorder(Node* root){
  if(root == NULL) return;
  cout << " " << root->data;
  print_preorder(root->left);
  print_preorder(root->right);
}

int main(){
  int n;
  cin >> n;
  Node* root = NULL;
  
  rep(i, 0, n){
    string order;
    int data;
    cin >> order;
    if(order == "insert") cin >> data;

    if(order=="insert"){
      root = insert(root, data);
    }
    else{
      print_inorder(root);
      cout << endl;
      print_preorder(root);
      cout << endl;
    }
  }

  return 0;
}



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

int main(){
int x,n;
cin >> n>>x;
vector<int> ta(n);
  for(int i = 0;i<n;i++)
    cin >> ta.at(i);
  
  int hane =0;
  int count =0;
for(int i = 0;i<n+1;i++){
if(hane <=x){
  count ++;
  if(i<n)
  hane += ta.at(i);
}
else
  break;
}
  
cout << count << endl;  

}

Measured memory_bytes: 256
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    vll b(n);
    REP(i, n) cin >> b[i];
    ll rec = n, flg, del;
    vll ans;
    while(rec){
        flg = 1;
        REPR(i, rec){
            if(b[i] == i + 1){
                del = i;
                flg = 0;
                break;
            }
        }
        if(flg){
            cout << -1 << endl;
            return 0;
        }
        b.erase(b.begin() + del);
        ans.push_back(del + 1);
        rec--;
    }
    REPR(i, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	public static void main(String[] args) {
		new Main();
	}

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

		int n = sc.nextInt();
		String s = sc.nextString();
		long r = 0;
		long g = 0;
		long b = 0;
		long sol;
		for (int i = 0; i < n; i++) {
			char c = s.charAt(i);
			if (c == 'R') r++;
			if (c == 'G') g++;
			if (c == 'B') b++;
		}
		sol = r*g*b;
		for (int i = 0; i < n; i++) {
			char a = s.charAt(i);
			for (int j = 1; ((i+j) < n) && ((i-j) >= 0); j++) {
				char d = s.charAt(i+j);
				char c = s.charAt(i-j);
				if (a != d && a != c && d != c) sol--;
			}
		}
		
		System.out.println(sol);
				
		sc.close();
	}
	
	class FasterScanner {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FasterScanner() {
			this(System.in);
		}

		public FasterScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void close() {
			try {
				mIs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


Measured memory_bytes: 32880
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    cout << n*n*n << endl;
}


Measured memory_bytes: 256