akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        while(true){
            int n=sc.nextInt();
            int r=sc.nextInt();
            /*System.out.println("n="+n+" r="+r);*/
            if(n==0&&r==0)break;
            
            int[] a=new int[n];
            /*System.out.print("a["+n+"]:");*/
            for(int i=0;i<n;i++){
                a[i]=i+1;
                /*System.out.print(a[i]);*/
            }
            /*System.out.println("");*/
            
            for(int i=0;i<r;i++){
                int p=sc.nextInt();
                int c=sc.nextInt();
                /*System.out.println("p="+p+" c="+c);*/
                if(p<2) continue;
                
                int[] b=new int[c];
                /*System.out.print("b["+c+"]:");*/
                for(int j=0;j<c;j++){
                    b[j]=a[n-p-c+1+j];
                    /*System.out.print(b[j]);*/
                }
                /*System.out.println("");*/
                
                /*System.out.print("a["+n+"]:");
                for(int j=0;j<n;j++){
                    System.out.print(a[j]);
                }
                 System.out.print("->");*/
                for(int j=0;j<p-1;j++){
                    a[n-p-c+1+j]=a[n-p+1+j];
                }
               
                /*for(int j=0;j<n;j++){
                    System.out.print(a[j]);
                }
                System.out.print("->");*/
                for(int j=0;j<c;j++){
                    a[n-c+j]=b[j];
                }
                /*for(int j=0;j<n;j++){
                    System.out.print(a[j]);
                }
                System.out.println("");*/
            }
            System.out.println(a[n-1]);
        }
    }
}


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

using namespace std;

int main()
{
  //freopen("in.txt", "r", stdin);
  int N;
  while (scanf("%d", &N) != EOF) {
    if (N % 10 == N / 100) puts("Yes");
    else puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
      cin >> H[i];
  }
  for(int i=N-1; i>0; i--){
      if(H[i-1] > H[i]+1){
          cout << "No" << endl;
          return 0;
      }
      if(H[i-1] == H[i]+1){
           H[i-1]--;
      }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 640
N = int(input())

def make_divisor(n):
    divisors = []
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
cnt = 0
for i in range(1, N+1):
    if len(make_divisor(i)) == 8 and  i%2 == 1:
        cnt += 1
print(cnt)




Measured memory_bytes: 9268
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, K;
    cin >> N >> K;

    vll A(N);
    REP(i, N) cin >> A[i];

    int cnt = 0;
    REP(i, N) if (A[i] >= K) cnt++;

    print(cnt);
}


Measured memory_bytes: 3964
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            Console.WriteLine(a * b - a - b + 1);
        }
    }
}


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

main(){
  int n;
  while(cin >> n,n){
    queue<int>k;
    int a;
    int qs;
    int g;
    int cheak=-1;
    for(int i=0;i<n;i++){
      cin >> a;
      k.push(a);
    }
    for(int i=0;i<10000;i++){
      qs=k.size();
      g=1;
      for(int j=0;j<qs;j++){
	  if(g==1 && k.front()!=j+1)g=0;
	  k.push(k.front());
	  k.pop();
      }
      if(g==1){
	  cheak=i;
	  break;
      }
      
      for(int j=0;j<qs;j++){
	if(k.front()-1>0) k.push(k.front()-1);
	k.pop();
      }
      k.push(qs);
    }
    cout << cheak << endl;
  }
}

Measured memory_bytes: 1228
#include <stdio.h>

int main() {

    int k, s;
    scanf("%d %d", &k, &s);

    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {


            int z = s - x - y;
            //printf("%d %d %d\n", x, y, z);
            if (z < 0) {
                break;
            }
            if (z <= k) {
                cnt++;
            }

        }
    }

    printf("%d", cnt);



    return 0;
}


Measured memory_bytes: 1708
num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(num_list[int(input())-1])

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();

int gcd(int a,int b);
int main() {

	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(e-a<=k){
	puts("Yay!");
		return 0;
	}
	else
		puts(":(");

}







int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, tmpp, m, h, w, x, y, sum, k, q;

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

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

  vector<ll> p(n);
  rep(i, n) p[i] = i;

  // next_permutationはsortしましょう！
  // われます

  do {
    cnt++;
    int ok = 0;
    rep(i, n) {
      if (p[i] != a[i] - 1) ok = 1;
    }
    if (!ok) tmp = cnt;
    ok = 0;
    rep(i, n) {
      if (p[i] != b[i] - 1) ok = 1;
    }
    if (!ok) tmpp = cnt;
  } while (next_permutation(all(p)));

  Cout(abs(tmp - tmpp));
  return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,w,sum=0,res=0;
	cin >> n >> w;
	const int INF=1e9+5;
	vector<int> weight(n),value(n);
	for(int i=0;i<n;i++){
		cin >> weight[i] >> value[i];
		sum+=value[i];
	}
	vector<int> dp(sum+1,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=sum-value[i];j>=0;--j){
			dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
		}
	}
	for(int i=1;i<=sum;i++)
		if(dp[i] <= w)
			res=max(res,i);
	cout<<res<<"\n";	
	return 0;
}

Measured memory_bytes: 3716
import sys


scan = sys.stdin.readline


def main():
    n, a, b, c, d = map(int, scan().rstrip().split())
    stone = [c == "#" for c in scan().rstrip()]

    if (a - b)*(c - d) > 0:
        if a > b:
            front = a
            behind = b
            goal_front = c
            goal_behind = d
        else:
            front = b
            behind = a
            goal_front = d
            goal_behind = c

        for pos, goal in [(front, goal_front), (behind, goal_behind)]:
            while pos != goal:
                if stone[pos] and stone[pos + 1]:
                    print("No")
                    exit(0)
                elif stone[pos]:
                    pos += 2
                else:
                    pos += 1

        print("Yes")
        exit(0)

    else:
        if a > b:
            front = a
            behind = b
            goal_front = c
            goal_behind = d
        else:
            front = b
            behind = a
            goal_front = d
            goal_behind = c
        
        while behind != goal_behind:
            if stone[behind] and stone[behind + 1]:
                print("No")
                exit(0)
            elif stone[behind] and behind + 2 == front:
                if front == goal_front:
                    print("No")
                    exit(0)
                elif stone[front] and stone[front + 1]:
                    print("No")
                    exit(0)
                elif stone[front]:
                    front += 2
                else:
                    front += 1
                behind += 2
            elif behind + 1 == front and stone[behind + 1]:
                if front == goal_front:
                    print("No")
                    exit(0)
                elif stone[front] and stone[front + 1]:
                    print("No")
                    exit(0)
                elif stone[front]:
                    front += 2
                else:
                    front += 1
                behind += 1
            elif behind + 1 == front or stone[behind]:
                behind += 2
            else:
                behind += 1

        while front != goal_front:
            if stone[front] and stone[front + 1]:
                print("No")
                exit(0)
            elif stone[front]:
                front += 2
            else:
                front += 1
        
        print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5016
# -*- coding:utf-8 -*-

N = int(input())

first_plice = int(input())
second_plice = int(input())
min_plice = min(first_plice, second_plice)
max_profit = second_plice - first_plice

for i in range(N-2):
    next_plice = int(input())
    max_profit = max(max_profit, next_plice - min_plice)
    min_plice = min(min_plice, next_plice)    

print(max_profit)


Measured memory_bytes: 5616
import java.util.Scanner;

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

		for (long i = 1; i < (long) Math.sqrt(N) + 1; i++) {
			if (N % i == 0) {
				long m1 = i - 1;
				//System.out.println("m1:"+m1);
				if (m1 != 0) {
					if (N / m1 == N % m1) {
						answer += m1;
					}
				}
				if (i != N / i) {
					long m2 = N / i - 1;
					//System.out.println("m2:"+m2);
					if (N / m2 == N % m2) {
						answer += m2;
					}
				}
			}
		}
		sc.close();
		System.out.println(answer);
	}
}

Measured memory_bytes: 21716
loop do
  n = gets.to_i
  break if n == 0
  arr = gets.split(' ').map(&:to_i)
  dp = Array.new(n-1) { Array.new(21, 0) }
  answer = arr[n-1]
  dp[0][arr[0]] = 1

  1.upto(n-2) do |i|
    0.upto(20) do |j|
      next if dp[i-1][j] == 0
      add = j + arr[i]
      sub = j - arr[i]

      dp[i][add] += dp[i-1][j] if add <= 20
      dp[i][sub] += dp[i-1][j] if sub >= 0
    end
  end

  puts dp[n-2][answer]
end

Measured memory_bytes: 8588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    string s;
    int cnt=0;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='+') cnt++;
        else cnt--;
    }
    cout<<cnt;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int ans = INF<int>;
    for (int i = 0; i < (1 << 2*n); ++i) {
        vector<int> u(n);
        for (int j = 0; j < n; ++j) {
            u[j] = ((i & (1 << (2*j))) != 0) *2+((i & (1 << (2*j+1))) != 0);
        }
        array<int, 3> x{}, y{};
        for (int j = 0; j < n; ++j) {
            if(0 <= u[j] && u[j] <= 2) {
                x[u[j]] += v[j];
                y[u[j]]++;
            }
        }
        if(x[0] != 0 && x[1] != 0 && x[2] != 0){
            chmin(ans, abs(x[0]-a)+abs(x[1]-b)+abs(x[2]-c)+(y[0]+y[1]+y[2]-3)*10);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int p, q, r;
   cin >> p >> q >> r;
   cout << (min(p + q, min(q + r, r + p))) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char ch;
    int H,W,i,j,flag=1;
    int a[50][50];
    cin>>H>>W;
    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
        {
            cin>>ch;
            if(ch=='#')
                a[i][j]=1;
            else
                a[i][j]=0;
        }
    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
        {
            if(a[i][j]==1)
            {
                if(i==0&&j==0)
                {
                    if(a[i+1][j]==0&&a[i][j+1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i==H-1&&j==0)
                {
                    if(a[i-1][j]==0&&a[i][j+1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i==0&&j==W-1)
                {
                    if(a[i][j-1]==0&&a[i+1][j]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i==H-1&&j==W-1)
                {
                    if(a[i-1][j]==0&&a[i][j-1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i>0&&i<H-1&&j==0)
                {
                    if(a[i-1][j]==0&&a[i+1][j]==0&&a[i][j+1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(j>0&&j<W-1&&i==0)
                {
                      if(a[i][j+1]==0&&a[i][j-1]==0&&a[i+1][j]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i==H-1&&j>0&&j<W-1)
                {
                      if(a[i][j+1]==0&&a[i][j-1]==0&&a[i-1][j]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(j==W-1&&i>0&&i<H-1)
                {
                      if(a[i+1][j]==0&&a[i-1][j]==0&&a[i][j-1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
                if(i>0&&i<H-1&&j>0&&j<W-1)
                {
                     if(a[i+1][j]==0&&a[i-1][j]==0&&a[i][j-1]==0&&a[i][j+1]==0)
                    {
                        flag=0;
                        break;
                    }
                }
            }
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;	
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll INF = 1e15;

ll lpow(ll a, ll p) {
	ll sum = 1;
	rep(i, p) {
		sum *= a;
	}
	return sum;
}

int main() {
	ll x;
	cin >> x;
	for (ll a = -150; a <= 150; a++) {
		for (ll b = -150; b <= 150; b++) {
			auto ans = lpow(a, 5) - lpow(b, 5);
			if (x == ans) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[700010];

void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 700005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

ll N, K, ans;
ll H[200010];

void solve() {
	cin >> N >> K;
	rep(i, N) {
		cin >> H[i];
	}
	sort(H, H + N);
	reverse(H, H + N);
	if (K >= N) {
		cout << 0 << endl;
	}
	else {
		for (ll i = K; i < N; i++) {
			ans += H[i];
		}
		cout << ans << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;

typedef long long ll;

int
main(int argc, char *argv[])
{
  int n, l[30000];
  cin >> n;
  rep(i, n) {
    cin >> l[i];
    l[i] *= -1;
  }

  sort(l, l + n);
  rep(i, n) {
    l[i] *= -1;
    //cout << l[i] << " ";
  } //cout << endl;
  ll aa = 0;
  
  for(int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = l[i]; int b = l[j];
      if (a - b + 1 > b) continue;
      int le =0, ri = n;
      while (ri - le > 1) {
	int med = (ri + le) / 2;
	if (l[med] <= a - b) ri = med;
	else le = med;
      }
      aa += (ll)(le - j);
    }
  }

  cout << aa << endl;

  return 0;
}
      


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] list = Console.ReadLine().Split(' ');
            int a = int.Parse(list[0]);
            int b = int.Parse(list[1]);
            Console.WriteLine(string.Format("{0} {1}", a * b, 2 * (a + b)));
        }
    }
}



Measured memory_bytes: 9112
#include<iostream>
#include<vector>
#define _USE_MATH_DEFINES
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
#define Rep(i,n) for(int i = 0;i < (n);i++)	
typedef long long ll;

int gcd(int a, int b) { if (b == 0)  return a;  else  return gcd(b, a % b); }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int& a, int& b) { int temp = a; a = b; b = temp; return; }
int ncr(int n, int r) { int a = 1; Rep(i, r) a = (a * (n - i)) / (i + 1); return a; }
int npr(int n, int r) { int a = 1; Rep(i, r) a *= n - i; return a; }
int mod(int a, int b) { return a % b; }

int main() {
	int a;
	int b;
	std::cin >> a >> b;
	std::cout << a * b;

	return 0;
 }

Measured memory_bytes: 3676
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		cout << "Yes\n";
	}
	else if (s[1] == s[2] && s[2] == s[3]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

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

Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int a, b;
	cin >> a>>b;


	cout << lcm(a,b) << "\n";
}


Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

@njit((i8, i8), cache=True)
def main(N, K):
    power = np.zeros(N + 10, np.int64)
    power[0] = 1
    for n in range(1, N + 10):
        power[n] = power[n - 1] * (K + 1) % MOD
    ret = K * (K + 1) // 2 * N * power[N - 1] % MOD

    dp = np.array([1], np.int64)
    dp[0] = 1
    for n in range(N, 0, -1):
        newdp = np.zeros(len(dp) * (n + 1) // n + 1, np.int64)
        for k in range(K + 1):
            for t in range(len(dp)):
                if k > n:
                    x = 0
                else:
                    x = (k + t) // n
                    ret -= x * dp[t] % MOD * power[n - 1] % MOD
                newdp[t + x] += dp[t]
        dp = newdp % MOD
    return ret % MOD

N, K = map(int, read().split())

print(main(N, K))

Measured memory_bytes: 106508
import re
a = input().split(' ')
N = int(a[0])
K = int(a[1])
S = input()

LR = re.findall(r'LR', S)
RL = re.findall(r'RL', S)

num1 = len(LR)
num2 = len(RL)

if num1 < num2:
  num = num1
else:
  num = num2
  
if K < num:
  num = K
  
if ((num1 - num2 == 1) and num1 <= K) or ((num2 - num1 == 1) and num2 <= K):
  point = num * 2 + 1
else:
  point = num * 2
  
for i in range(N):
  if i != 0:
    if S[i] == S[i-1]:
      point = point + 1


print(point)



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

int main(){
  int n,m;
  cin>>n>>m;
  vector<bool> x(n+1,true);
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    x.at(a)=false;
  }
  vector<long long> v(n+1);
  v.at(0)=1;
  if(x.at(1)) v.at(1)=1;
  else v.at(1)=0;
  for(int i=2;i<n+1;i++){
    if(x.at(i)) v.at(i)=v.at(i-1)+v.at(i-2);
    else v.at(i)=0;
    v.at(i)%=1000000007;
  }
  cout<<v.at(n)<<endl;
}
  

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		int[] ans = new int[1000];
		int index = 0;
		
		while( n != 0 || k != 0 ){
			int sum = 0;
			int[] num = new int[n];
			for(int i = 0; i < k; i++){
				num[i] = stdIn.nextInt();
				sum += num[i];
			}
			for(int i = k; i < n; i++){
				num[i] = stdIn.nextInt();
			}
		
			int max = sum;
			for(int i = 0; i < n-k; i++){
				sum = sum-num[i]+num[i+k];
				if( sum > max ){
					max = sum;
				}
				
			}
			ans[index] = max;
			index++;
			n = stdIn.nextInt();
			k = stdIn.nextInt();
		}
		for(int i = 0; i < index; i++){
			System.out.println(ans[i]);
		}
	}
}

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

int a[100005];

int main()
{
	long int n, k, q;
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		a[t]++;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i]+k-q >0  )
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

#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 VIN(x) for(auto&youso_: (x) )cin>>youso_
#define VOUT(x, delim) for(auto&youso_: (x) )cout<<youso_<<delim;cout<<endl

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) i64 __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    CIN(N);
    SCIN(S);

    vector<i64> cr(N + 1, 0);
    REP(i, N) {
        cr[i + 1] = cr[i] + (S[i] == 'R');
    }

    i64 minc = 2 * N;
    REP(i, N + 1) {
        i64 lr = cr[i];
        i64 lw = i - cr[i];
        i64 rr = cr[N] - lr;
        i64 rw = N - lr - lw - rr;

        i64 cnt = 0;
        // swap left white and right red
        i64 swapped = min(lw, rr);
        lw -= swapped;
        rr -= swapped;
        cnt += swapped;
        // left white to red
        cnt += lw;
        // right red to white
        cnt += rr;
        chmin(minc, cnt);
    }
    COUT(minc);

    return 0;
}


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

int main() {
    int n, k, d = 0;
    cin >> n >> k;
    int h[n], a[n-k+1];
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h, h+n);
    for(int i = 0; i < n-k+1; i++) a[i] = h[i+k-1] - h[i];
    sort(a, a+n-k+1);
    cout << a[0] << '\n';
}

Measured memory_bytes: 1024
use proconio;

fn gcd(p:i64, q:i64) -> i64 {
  if p % q == 0 { return q }
  return gcd(q, p%q)
}

fn main(){
  proconio::input! {
    n:i64
  }
  let mut sum:i64 = 0;
  for i in 1..n+1 {
    for j in 1..n+1 {
      for k in 1..n+1 {
        sum += gcd(gcd(i,j),k);
      }
    }
  }
  println!("{}", sum)
}

Measured memory_bytes: 2148
N, C, K = map(int, input().split())
T = []
for i in range(N):
    T.append(int(input()))
sorted_T = sorted(T)
bus_count = 1
pas_count = 0
bus_start = sorted_T[0]
for t in sorted_T:
    if pas_count == C or t - bus_start > K:
        bus_count += 1
        pas_count = 0
        bus_start = t
    pas_count += 1
print(bus_count)

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int m_mul(int x, int y) {
    return 1LL * x * y % MOD;
}
int m_mul(int x, int y, int tails, ...) {
    return m_mul(m_mul(x, y), tails);
}
int m_pow(int x, int y) {
    int r = 1;
    while (y) {
        if (y & 1)
            r = m_mul(r, x);
        x = m_mul(x, x);
        y >>= 1;
    }
    return r;
}
int m_div(int x, int y) {
    return m_mul(x, m_pow(y, MOD - 2));
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
        int n, k;
    cin >> n >> k;
    vector<int> pos, neg, zero;
    for (int i = 0; i < n; i++) {
        int it;
        cin >> it;
        if (it > 0)
            pos.push_back(it);
        else if (it < 0)
            neg.push_back(it);
        else
            zero.push_back(it);
    }
    int ans = 1;
    if (n == k) {
        for (int it : pos)
            ans = m_mul(ans, it);
        for (int it : neg)
            ans = m_mul(ans, it);
        for (int it : zero)
            ans = m_mul(ans, it);
        if (ans < 0)
            ans += MOD;
    } else if (pos.size()) {
        int np = pos.size(), nn = neg.size();
        if (np + nn < k)
            ans = 0;
        else if (np + nn == k && nn % 2 == 1)
            ans = 0;
        else {
            sort(pos.begin(), pos.end(), greater<int>());
            sort(neg.begin(), neg.end());
            int ni = 0, pi = 0;
            for (int i = 0; i < k; i++) {
                if (ni == nn || (pi < np && pos[pi] >= -neg[ni]))
                    pi++;
                else
                    ni++;
            }
            if (ni % 2 == 1) {
                ll nxp = pi == np ? 0 : pos[pi];
                ll lsp = pi == 0 ? 1 : pos[pi - 1];
                ll nxn = ni == nn ? 0 : -neg[ni];
                ll lsn = -neg[ni - 1];
                if (pi == 0 || lsp * nxp > lsn * nxn)
                    pi++, ni--;
                else
                    pi--, ni++;       
            }
            for (int i = 0; i < pi; i++)
                ans = m_mul(ans, pos[i]);
            for (int i = 0; i < ni; i++) 
                ans = m_mul(ans, -neg[i]);
        }
    } else {
        if (k % 2 == 1) {
            if (zero.size())
                ans = 0;
            else {
                sort(neg.begin(), neg.end(), greater<int>());
                for (int i = 0; i < k; i++)
                    ans = m_mul(ans, -neg[i]);
                ans = MOD - ans;
            }
        } else {
            if ((int)neg.size() < k)
                ans = 0;
            else {
                sort(neg.begin(), neg.end());
                for (int i = 0; i < k; i++)
                    ans = m_mul(ans, neg[i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4508
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>

using namespace std;

int n;
int p[31];
int res;

void change(int x){
	if(x==1){
		swap(p[0],p[23]);
		swap(p[3],p[26]);
		swap(p[6],p[29]);
		swap(p[9],p[20]);
		swap(p[15],p[17]);
	}
	if(x==2){
		swap(p[14],p[15]);
		swap(p[0],p[27]);
		swap(p[1],p[28]);
		swap(p[2],p[29]);
		swap(p[18],p[20]);
	}
	if(x==3){
		swap(p[11],p[18]);
		swap(p[2],p[21]);
		swap(p[5],p[24]);
		swap(p[8],p[27]);
		swap(p[12],p[14]);
	}
	if(x==4){
		swap(p[12],p[17]);
		swap(p[6],p[21]);
		swap(p[7],p[22]);
		swap(p[8],p[23]);
		swap(p[9],p[11]);
	}
}

void dice(int x){
	int flag=1;
	int c[6]={p[0],p[9],p[12],p[15],p[18],p[21]};
	for(int i=0;i<9;i++)if(p[i]!=p[0])flag=0;
	for(int i=9;i<12;i++)if(p[i]!=p[9])flag=0;
	for(int i=12;i<15;i++)if(p[i]!=p[12])flag=0;
	for(int i=15;i<18;i++)if(p[i]!=p[15])flag=0;
	for(int i=18;i<21;i++)if(p[i]!=p[18])flag=0;
	for(int i=21;i<30;i++)if(p[i]!=p[21])flag=0;
	if(flag==1)res=min(res,x);
	else if(x<8){
		change(1);
		dice(x+1);
		change(1);
		change(2);
		dice(x+1);
		change(2);
		change(3);
		dice(x+1);
		change(3);
		change(4);
		dice(x+1);
		change(4);
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		res=114514;
		for(int j=0;j<30;j++){
			scanf("%d",&p[j]);
		}
		dice(0);
		printf("%d\n",res);
	}
	return 0;
}

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

vector<complex<double> > fft(vector<complex<double> > a, bool inverse = false){
    int n = a.size();
    int h = 0;
    for(int i = 0; 1 << i < n; i++) h++;
    for(int i = 0; i < n; i++){
        int j = 0;
        for(int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
        if(i < j) swap(a[i], a[j]);
    }
    for(int b = 1; b < n; b *= 2){
        for(int j = 0; j < b; j++){
            complex<double> w =
                polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
            for(int k = 0; k < n; k += b * 2){
                complex<double> s = a[j + k];
                complex<double> t = a[j + k + b] * w;
                a[j + k] = s + t;
                a[j + k + b] = s - t;
            }
        }
    }
    if(inverse)
        for(int i = 0; i < n; i++) a[i] /= n;
    return a;
}

vector<complex<double> > fft(vector<double> a, bool inverse = false){
    vector<complex<double> > a_complex(a.size());
    for(int i = 0; i < a.size(); i++) a_complex[i] = complex<double>(a[i], 0);
    return fft(a_complex, inverse);
}

vector<double> convolve(vector<double> a, vector<double> b){
    int s = a.size() + b.size() - 1;
    int t = 1;
    while(t < s) t *= 2;
    a.resize(t);
    b.resize(t);
    vector<complex<double> > A = fft(a);
    vector<complex<double> > B = fft(b);
    for(int i = 0; i < t; i++) A[i] *= B[i];
    A = fft(A, true);
    a.resize(s);
    for(int i = 0; i < s; i++) a[i] = A[i].real();
    return a;
}

int main(){
    int N;
    long M;
    cin >> N >> M;
    vector<double> a(100001, 0);
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        a[A] = a[A] + 1.0;
    }
    
    vector<double> f = convolve(a, a);
    
    long ans = 0, i = f.size() - 1;
    while(i >= 0){
        if(f[i] > M){
            ans += i * M;
            break;
        }
        ans += i * (long)(f[i] + 0.5);
        M -= (long)(f[i] + 0.5);
        i--;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 19672
#include <iostream>
using namespace std;
string N[50],M[50];
#define rep(i,n) for(int i=0;i<(int)n;i++)
int n,m;
int main(){
    cin>>n>>m;rep(i,n)cin>>N[i];rep(i,m)cin>>M[i];
    bool ans=true;
    rep(i,n-m+1){
        rep(j,n-m+11){
            rep(k,m){
                rep(l,m){
                    if(N[i+k][j+l]!=M[k][l]){
                        ans=false;
                        goto OUT;
                    }
                }
            }
            cout<<"Yes"<<endl;return 0;
            OUT:;
            }
        }
        cout<<"No"<<endl;return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long k,s=1,sum=0,ans=0,n,i,j;
char a[10000001];
int main()
{
    scanf("%s",a);
    for(i=0;i<=strlen(a)-1;i++)
    {
    	if(a[i]=='A'&&a[i+1]=='C')
    	{
    		cout<<"Yes";
    		return 0;
		}
	}
	cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const int maxn=500000;

int main(){
  int n;
  int a[maxn];
  int b[maxn];
  cin>>n;
  a[0]=0;
  int ans=0;
  a[n+1]=0;
  for(int i=0;i<n;i++){
    cin>>a[i+1];
    ans+=abs(a[i+1]-a[i]);
  }
  
  ans+=abs(a[n+1]-a[n]);
  for(int i=0;i<n;i++){
    b[i]=ans-(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2]))+(abs(a[i]-a[i+2]));
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<endl;
  }



  
  
  
  return 0;
}


Measured memory_bytes: 3712
module Main where

solve :: (Int,Int,Int,Int,Int) -> Int
solve (a,b,c,x,y)
    | x > y     =   minimum [a*x+b*y,2*c*y+a*(x-y),2*c*x]
    | otherwise =   minimum [a*x+b*y,2*c*x+b*(y-x),2*c*y]


main :: IO ()
main = do
    [a,b,c,x,y] <- (map read . words) <$> getLine 
    print $ solve (a,b,c,x,y)
    return()

Measured memory_bytes: 508
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Node{

	Node(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	bool operator<(const struct Node &arg) const{
			return cost > arg.cost;
	};

	int to,cost;
};

int main(){

	int N;
	scanf("%d",&N);

	vector<Node> V[N];

	int node,num,to,cost,D[N];;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&node);
		scanf("%d",&num);
		for(int i = 0; i < num; i++){
			scanf("%d %d",&to,&cost);
			V[node].push_back(Node(to,cost));
		}
		D[loop] = BIG_NUM;
	}

	D[0] = 0;

	priority_queue<Node> Q;

	for(int i = 0; i < V[0].size(); i++){
		D[V[0][i].to] = V[0][i].cost;
		Q.push(Node(V[0][i].to,V[0][i].cost));
	}

	int min_index;

	while(!Q.empty()){
		if(Q.top().cost == D[Q.top().to]){
			min_index = Q.top().to;
			Q.pop();
		}else{
			Q.pop();
			continue;
		}

		for(int k = 0; k < V[min_index].size(); k++){
			if(D[V[min_index][k].to] > D[min_index] + V[min_index][k].cost){
				D[V[min_index][k].to] = D[min_index] + V[min_index][k].cost;
				Q.push(Node(V[min_index][k].to,D[V[min_index][k].to]));
			}
		}
	}

	for(int i = 0; i < N; i++)printf("%d %d\n",i,D[i]);

    return 0;
}



Measured memory_bytes: 7340
#include "bits/stdc++.h"
using namespace std;

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

	int no;
	string judge;

	set<int> ac;
	vector<int> wa((n + 1), 0);

	int wacount = 0;
	for (int i = 0; i < m; i++) {
		cin >> no >> judge;
		if (judge == "WA" && ac.find(no) == ac.end()) {
			wa.at(no) += 1;
		}
		else {
			if (ac.find(no) == ac.end()) {
				ac.insert(no);
				wacount += wa.at(no);
			}
		}
	}
	cout << ac.size() << " " << wacount << endl;
}


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

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

    int sen = 0, go = 0;
    sen = x / 500;
    go = (x - sen * 500) / 5;

    cout << sen * 1000 + go * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    v a(5);in(a,5);
    f(i,5)
    {
        if(a[i]==0){
            cout<<i+1;return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
#include <cstdio>

using namespace std;

char s[111111];

int main(void) {
  scanf("%s", s);
  int a, b; a = b = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] - '0' != i%2) a += 1;
    if (s[i] - '0' != (i+1)%2) b += 1;
  }
  printf("%d\n", a < b ? a : b);
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [list(map(int, list(input().replace('.', '0').replace('#', '1')))) for _ in range(h)]

h_list, w_list = [], []
for i in range(h):
    if sum(a[i]) > 0:
        h_list.append(i)
for j in range(w):
    if sum([aa[j] for aa in a]) > 0:
        w_list.append(j)
for i in h_list:
    print(''.join(['.','#'][a[i][j]] for j in w_list))


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <stdint.h>

int64_t as[100005];
int64_t prefix[100005];

int main(){
  int64_t N;
  scanf("%ld",&N);
  for(int64_t i=1;i<=N;i++){
    scanf("%ld",&as[i]);
  }
  std::sort(as+1,as+N+1);
  for(int64_t i=1;i<=N;i++){
    prefix[i]=as[i]+prefix[i-1];
    //print64_tf("%ld\t%ld\t%ld\n",i,as[i],prefix[i]);
  }
  for(int64_t i=N;i>0;i--){
    if(as[i]>prefix[i-1]*2){
      printf("%ld\n",N-i+1);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1664
#include <cstdint>
#include <iostream>

using namespace std;

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

  int64_t mx = 0;
  int64_t steps = 0;
  for (int64_t n = 0; n < N; ++n) {
    int64_t A;
    cin >> A;
    if (mx <= A) {
      mx = A;
    } else {
      steps += mx - A;
    }
  }
  cout << steps << endl;

  return 0;
}


Measured memory_bytes: 3620
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)  # 電球iの光の強さAi
I = np.arange(N)  # 電球i
for i in range(K):
  X = np.zeros(N + 1, int)  # N = 5のとき、[0, 0, 0, 0, 0, 0]
  # いもす法
  np.add.at(X, np.maximum(0, I - A), 1)
  np.add.at(X, np.minimum(N, I + A + 1), -1)
  A = X.cumsum()[:-1]  #累積和の末尾の項を除いたもの
  if np.all(A == N):
    # O(log N) 回操作を繰り返すと数列は収束しすべて N になる
    break
print(*A)  # intの配列をアンパックして出力


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

using ll = long long;

int main() {
    int K, a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> K;
    cout << a[K - 1] << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i,j,k,ans=1;
    int x,n,l[100],d[102];

    scanf("%d %d",&n,&x);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }

    d[0]=0;
    for(i=1;i<n+1;i++){
        d[i] = d[i-1] + l[i-1];
//        printf("%d\n",d[i]);
        if(d[i] <= x){
            ans++;
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128