akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc163/tasks/abc163_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;
    vector<int> A(M); for(auto& in:A) cin >> in;
    int sum = accumulate(A.begin(),A.end(),0);
    res = sum>N?-1:N-sum;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int n, k;

bool f(int x, V<int> &a) {
  int cnt = 0;
  rep(i,n) {
    cnt += ceil(a[i],x) - 1;
  }
  return cnt <= k;
}

int main(){

  cin >> n >> k;
  V<int> a(n);
  rep(i,n) cin >> a[i];
  sort(rall(a));
  int l = 0;
  int r = a[0];
  while(abs(r-l) > 1) {
    int mid = (l+r)/2;
    if(f(mid, a)) r = mid;
    else l = mid;
  }
  cout << r << endl;
}

Measured memory_bytes: 4060
#include<stdio.h>
int prime[1000001];
int main(){
  int n,i,k;
  int count=0;
  for(i=2;i<=1000000;i++){
    prime[i]=1;
  }
  for(i=2;i*i<1000000;i++){
    if(prime[i]){
      for(k=2*i;k<=1000000;k+=i){
        prime[k]=0;
      }
    }
  }
  while(1){
    if(scanf("%d",&n)==EOF){
      break;
    }
    for(i=2;i<=n;i++){
      if(prime[i]==1){
        count++;
      }
    }
    printf("%d\n",count);
    count=0;
  }
  return 0;
}

Measured memory_bytes: 4500
n = gets.to_i
ary = gets.split(" ").map(&:to_i)

ary_cnt = ary.group_by(&:itself).map{|k, v| [k, v.count]}.to_h

(1..n).each do |num|
  if ary_cnt[num] == nil
    puts 0
  else
    puts ary_cnt[num]
  end
end

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

namespace Atcoder
{
    class AtCodeeeeeeeeeeeeeeeeeeeeeeeer
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            double N = int.Parse(s[0]);
            int K = int.Parse(s[1]);
            Console.WriteLine(
                Math.Ceiling(N / 2) >= K ? "YES":"NO"
                );
        }
    }
}


Measured memory_bytes: 13140
a,b,c=map(int,input().split())
if a>b:
 if b>c:
    print(c,b,a)
 elif c>a:
    print(b,a,c)
 else:
    print(b,c,a)
if a<=b:
 if a>c:
    print(c,a,b)
 elif c>b:
    print(a,b,c)
 else:
    print(a,c,b)


Measured memory_bytes: 5596
#include<stdio.h>
int main()
{
    int n,a,b;
    scanf("%d",&n);
    if(n%1==0 && n/1<=9)
    {
        printf("Yes\n");
    }
    else if(n%2==0 && n/2<=9)
    {
        printf("Yes\n");
    }
    else if(n%3==0 && n/3<=9)
    {
        printf("Yes\n");
    }
    else if(n%4==0 && n/4<=9)
    {
        printf("Yes\n");
    }
   else if(n%5==0 && n/5<=9)
    {
        printf("Yes\n");
    }
    else if(n%6==0 && n/6<=9)
    {
        printf("Yes\n");
    }
    else if(n%7==0 && n/7<=9)
    {
        printf("Yes\n");
    }
    else if(n%8==0 && n/8<=9)
    {
        printf("Yes\n");
    }
   else if(n%9==0 && n/9<=9)
    {
        printf("Yes\n");
    }

    else
    {
        printf("No\n");
    }

    return 0;
}


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

int main() {
  int n;cin>>n;
  vector<vector<int>> vec(n,vector<int>(n,-1));
  rep(i,n){
    int a;cin>>a;
    rep(j,a){
      int x,y;cin>>x>>y;
      x--;
      vec[i][x]=y;
    }
  }
  int ans=0;
  rep(bit,1<<n){
    vector<int> d(n);
    rep(i,n)if(bit&(1<<i))d[i]=1;
    bool ok=true;
    rep(i,n)if(bit&(1<<i)){
      rep(j,n){
        if(vec[i][j]==-1)continue;
        if(vec[i][j]!=d[j])ok=false;
      }
    }
    if(ok)ans=max(ans,__builtin_popcount(bit));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

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

    long long int xsum = 0, ysum = 0;
    for(int i=0; i<n; i++){
        long long int x;
        cin >> x;
        xsum = (xsum + x * (2 * i - n + 1)) % MOD;
    }
    for(int i=0; i<m; i++){
        long long int y;
        cin >> y;
        ysum = (ysum + y * (2 * i - m + 1)) % MOD;
    }
    cout << xsum * ysum % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main {
	public static void main(String srgs[]) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] s = reader.readLine().split(" ");
			int A = Integer.parseInt(s[0]);
			int B = Integer.parseInt(s[1]);

			int c = (B - 1) / (A - 1);
			if ((B - 1) % (A - 1) != 0) {
				c += 1;
			}

			System.out.println(c);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


Measured memory_bytes: 22228
import java.util.*;
import java.lang.*;

public class Main {
  
    public int dp(int[] arr,int[] dp,int n,int index) {
    	if(index==n-1) {
    		dp[n-1]=0;
    		return 0;
    	}
    	if(index==n-2) {
    		dp[n-2]=Math.abs(arr[n-1]-arr[n-2]);
    		return dp[n-2];
    	}
    	int temp1=0;
    	int temp2=0;
    	if(dp[index+1]!=-1) {
    		temp1=dp[index+1];
    	}
    	else {
    		temp1=this.dp(arr, dp, n, index+1);
    	}
    	if(dp[index+2]!=-1) {
    		temp2=dp[index+2];
    	}
    	else {
    		temp2=this.dp(arr, dp, n, index+2);
    	}
    	dp[index]=Math.min(Math.abs(arr[index]-arr[index+1])+temp1, Math.abs(arr[index]-arr[index+2])+temp2);
    	return dp[index];
    }
	public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        int[] dp=new int[n];
        for(int i=0;i<n;i++) {
        	arr[i]=sc.nextInt();
        	
        }
        Main mm=new Main();
        for(int i=0;i<n;i++) {
        	dp[i]=-1;
        }
        System.out.println(mm.dp(arr, dp, n, 0));
        
       }
    
    
}



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

#define M 1113187
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + key % (M - 1); }

int find(char str[]){
  long long key,n,i; 
  key = getKey(str);
  for(i = 0; i < M; i++){
    n = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[n],str) == 0) return 1;
    else if(strlen(H[n]) == 0)return 0;
  }
  return 0;
}

void insert(char str[]){
  long long key,n,i; 
  key = getKey(str);
  for(i = 0; i < M; i++){
    n = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[n],str) == 0) break;
    else if(strlen(H[n]) == 0){
      strcpy(H[n],str);
      break;
    }
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16960
#include<stdio.h>
int main(){
  int d;

  scanf("%d",&d);
  if(d==25){
    printf("Christmas\n");
  }
  if(d==24){
    printf("Christmas Eve\n");
  }
  if(d==23){
    printf("Christmas Eve Eve\n");
  }
  if(d==22){
    printf("Christmas Eve Eve Eve\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n;
char z;

int main(){
  scanf("%d",&n);

  
  
  
  
  printf("%d\n",1000-(n-1)%1000-1);
  
  return 0;
}


Measured memory_bytes: 1728
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int a = scan.nextInt();
		int b = scan.nextInt();
		int C = scan.nextInt();
		double S = (double) 1 / (double) 2 * (double) a
 			* (double) b
			* Math.sin(Math.toRadians((double)C));
		double L = (double) a + (double) b +
			Math.sqrt(Math.pow((double) a, 2) 
			+ Math.pow((double) b, 2)
			- (double) 2 * (double) a * (double) b
			* Math.cos(Math.toRadians((double) C)));
		double h = (double) b 
			* Math.sin(Math.toRadians((double) C));
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);
	}
}

Measured memory_bytes: 26308
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

ll n,k,s[210000];
const ll MOD=1000000007;

ll mypow(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1){
			re=re*a%MOD;
		}
		b>>=1,a=a*a%MOD;
	}
	return re;
}

ll rev(ll a){
	return mypow(a,MOD-2);
}

ll C(ll a,ll b){
	ll re=s[a];
	re=re*rev(s[a-b])%MOD;
	re=re*rev(s[b])%MOD;
	return re;
}

ll solve(ll p,ll t){
	ll re=C(p+t-1,t-1);
//	ll re=mypow(p+1,t-1);
//	re=re*rev(s[t-1])%MOD;
	re=re*C(n,t)%MOD;
	return re;
}

int main(){Tie
	s[0]=1;
	for(int i=1;i<=200000;i++){
		s[i]=s[i-1]*i%MOD;
	}
	cin>>n>>k;
	ll ans=1;
	for(int i=1;i<n;i++){
		if(n-i<=k){
//			cout<<i<<' '<<solve(n-i,i)<<'\n';
			ans=(ans+solve(n-i,i))%MOD;
		}
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 1792
import sys
m=500000;a=[1]*m
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*((m-1-i*i//2)//i+1)
for e in map(int,sys.stdin):print([e-1,sum(a[:(e+1)//2])][e>3])


Measured memory_bytes: 14896
#include<stdio.h>
#include<stdlib.h>
#define N NULL

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;

Node root;
void insert(int);
void inorder(Node );
void preorder(Node );

int main(){
  int s, i, x;
  char c[10];

  scanf("%d", &s);

  for ( i = 0; i < s; i++ ){
    scanf("%s", c);
    if ( c[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    if ( c[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  return 0;
}

void insert(int k){
  Node y = N;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = N;
  z->r = N;
 
  while(x != N){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }

  z->p = y;
  if(y == N) root = z;
  else if(z->key < y->key) y->l = z;
  else y->r = z;
}

void inorder(Node u){
  if(u != N){
    inorder(u->l);
    printf(" %d",u->key);
    inorder(u -> r);
  }
}
void preorder(Node u){
  if(u != N){
    printf(" %d",u->key);
    preorder(u->l);
    preorder(u->r);
  }
}

Measured memory_bytes: 24036
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	// input
	h := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&h[i])
	}

	// initialize dp
	dp := make([]int, N)
	dp[1] = abs(h[1] - h[0])

	for i := 2; i < N; i++ {
		dp[i] = min(
			dp[i-2]+abs(h[i]-h[i-2]),
			dp[i-1]+abs(h[i]-h[i-1]),
		)
	}
	fmt.Println(dp[N-1])
}

func abs(a int) int {
	if a < 0 {
		return (-1) * a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 6312
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

template<class T>
i64 largest_rect(const T& h) {
    int n = h.size();
    vector<pair<int, i64>> stk;
    i64 ans = 0;
    for (int i = 0; i <= n; ++i) {
        int left = i;
        while (!stk.empty() && (i == n || h[i] < stk.back().second)) {
            left = stk.back().first;
            ans = max(ans, (i - left) * stk.back().second);
            stk.pop_back();
        }
        if (stk.empty() || (i != n && h[i] > stk.back().second)) {
            stk.emplace_back(left, h[i]);
        }
    }
    return ans;
}

int main() {
    i64 n;
    cin >> n;
    vector<i64> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    cout << largest_rect(h) << endl;
    return 0;
}


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(rall(a));
    ll ans = a[0];
    if (n % 2 == 0) {
        for (int i = 1; i <= (n-2)/2; ++i) {
            ans += 2 * a[i];
        }
    } else {
        for (int i = 1; i <= (n-3)/2; ++i) {
            ans += 2 * a[i];
        }
        ans += a[(n-1)/2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = INF;
    for(int i = 0; i <= 100; i++)
    {
        ll length = 0;
        for(int j = 0; j < n; j++)
        {
            length += (A[j] - i) * (A[j] - i);
        }
        ans = min(ans, length);
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 161 -B
int main(void) {
	int i,n,m,a[101];
	int t = 0;

	scanf("%d %d", &n,&m);

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

	int c = 0;
	for(i=0;i<n;i++)
		if (a[i]*4*m >= t) c++;

    if(c>=m) printf("Yes\n");
	else     printf("No\n");
	return 0;
}

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

int a[100005];

int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[tmp-1]++;  a[tmp]++; a[tmp+1]++;
    }
    cout << *max_element(begin(a), end(a)) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define ll              long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
//#define sort(x)         sort(all(x))
#define umii            unordered_map<int,int>
#define lli             list<int>             
#define gcd(m,n)        __gcd(m,n)   
#define mib             map<int,bool>

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
 
//////////////////////////////code//////////////////////////////
vpii a(2001);
int dp[2001][2001];
int n;

int sol(int l,int r)
{
	if(l>r)
	return 0;
	
	if(dp[l][r]!=-1)
	return dp[l][r];
	
	int i = n - r + l;
	
	int a1=0,a2=0;
	a1 = a[i].ff*abs(a[i].ss-l)+sol(l+1,r);
	a2 = a[i].ff*abs(a[i].ss-r)+sol(l,r-1);
	
	return dp[l][r]=max(a1,a2);

}
int32_t main()
{
  fast();
  //int n;
  cin>>n;
  
  
  for(int i=1;i<=n;i++)
  {
  	cin>>a[i].ff;
  	a[i].ss=i;
  }
  
  memset(dp,-1,sizeof(dp));
  
  sort(a.begin()+1,a.end(),greater<pii>());
  
  cout<<sol(1,n);

}

Measured memory_bytes: 35064
int a[100000];
int ok(int M,int N,int C){
	int sum=0,ret=1,i=0;
	for(;i<N;i++){
		if(a[i]>M)return 0;
		sum+=a[i];
		if(sum>M)sum=a[i],ret++;
	}
	return ret<=C;
}
main(){
	int N,C,i=0;
	scanf("%d%d",&N,&C);
	for(;i<N;i++)scanf("%d",a+i);
	int l=0,h=1LL<<30;
	for(;l+1<h;){
		int m=(l+h)/2;
		if(ok(m,N,C))h=m;else l=m;
	}
	printf("%d\n",l+1);
	exit(0);
}

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

int main() {
    int x;
    cin >> x;
    int mx = x/100;
    for(int i = 0; i <= mx; ++i) {
        int y = x-100*i;
        if(i >= 0 && y <= 5*i) {cout << 1 << endl; return 0;}
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sec = sc.nextInt();
        int hours = sec / 3600;
        int minutes = (sec - hours * 3600) / 60;
        int seconds = (sec - hours * 3600) % 60;
        System.out.println(hours + ":" + minutes + ":" + seconds);
    }
}

Measured memory_bytes: 26260
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);

		Console.WriteLine((a+b+c >= 22)?"bust":"win");
	}
}

Measured memory_bytes: 13140
n=int(input())
max_res, cur_res = 0, 0
prev_h = 0
for h in map(int, input().split(' ')):
    if prev_h >= h:
        cur_res += 1
    else:
        max_res = max(max_res, cur_res)
        cur_res = 0
    prev_h = h
max_res = max(max_res, cur_res)
print(max_res)

Measured memory_bytes: 11296
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll mi[300010];
ll ma[300010];

int main()
{
	int n;cin >> n;
	
	vector<int> v;
	
	REP(i,3*n)
	{
		int tmp;cin >> tmp;
		v.PB(tmp);
	}
	
	priority_queue<int> pq1;
	priority_queue<int,vector<int>,greater<int> > pq2;
	
	ll A = 0;
	ll B = 0;
	REP(i,3*n)
	{
		A += v[i];B += v[3*n-1-i];
		pq2.push(v[i]);
		pq1.push(v[3*n-1-i]);
		if(i >= n)
		{
	//		cout << pq2.top() << ' ' << pq1.top() << endl;
			A -= pq2.top();pq2.pop();
			B -= pq1.top();pq1.pop();
		}
		ma[i] = A;
		mi[3*n-1-i] = B;
	}
	
	ll ans = -1000000000000000000;
	REP(i,n+1)
	{
	//	cout << ma[i+n-1] << ' ' << mi[i+n] << endl;
		ans = max(ans,ma[i+n-1] - mi[i+n]);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7408
import sys
import heapq
imput = sys.stdin.readline

def main():
    n,m = map(int,input().split())
    money = [[] for _ in range(10**5)]
    dp = [0] * m
    hq = []
    heapq.heapify(hq)

    for _ in range(n):
        a,b = map(int,input().split())
        money[a-1] += [b]

    for i in range(m):
        for j in money[i]:
            heapq.heappush(hq,-j)
        if hq:
            dp[i] += -heapq.heappop(hq)
        if i >= 1:
            dp[i] += dp[i-1]
    print(dp[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 76448
#include <stdio.h>
int main() {
	int i;
	int N, K;
	int h[100000];
	int cnt = 0;

	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) {
		scanf("%d", &h[i]);
		if (h[i] >= K) {
			cnt++;
		}
	}

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

	return 0;
}

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

// sum((i-th bit of a), a=1..x)
uint64_t bitcount(uint64_t x, int i)
{
    if (i==0) return x/2+x%2;
    auto b=1ULL<<i;
    auto c=b<<1;
    auto res=x/c*b;
    auto m=(x+1)%c;
    if (m<b) return res;
    return res+m-b;
}

long g(long x)
{
    long res=0;
    for(int i=0; i<50; ++i) res|=(bitcount(x, i)&1)<<i;
    return res;
}

long f(long a, long b) { return g(b)^g(a-1); }

int main()
{
    long a, b; cin>>a>>b;
    cout<<f(a, b)<<endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

if N == 1:
    print("Yes")
    exit()

if H[0] - H[1] >= 2:
    print("No")
    exit()
elif H[0] - H[1] < 0:
    H[1] -= 1

for i in range(1,N-1):
    if H[i+1] - H[i] > 0:
        H[i+1] -= 1
    elif H[i+1] - H[i] < 0:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).elen()
#define F flen
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int,int> P;
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}

int main()
{
    int m,d;
    cin>>m>>d;
    int cnt=0;
    FOR(i,1,m+1){
        FOR(j,1,d+1){
            int tmp=j;
            int d1=tmp%10;
            int d10=tmp/10%10;
            if(d1*d10==i&&d1>=2&&d10>=2){
               // cout<<d10<<" "<<d1<<endl;
                cnt++;
            }

        }
        
    }
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define ll long long int

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

int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	ll sum=0;
	for ( i=1; i<=n; i++ )
	{
		for ( j=1; j<=n; j++ )
		{
			for ( k=1; k<=n; k++ )
			{
				sum = sum + gcd(i,gcd(j,k));
			}
		}
	}
	printf("%lli\n",sum);
	return 0;
}


Measured memory_bytes: 1684
#include<iostream>
#include<omp.h>
using namespace std;

int main()
{
  int R,G,B,N;
  cin>>R>>G>>B>>N;
  int cnt=0;
  
  #pragma omp parallel for
  for(int r=0;R*r<=N;r++)
  {
    #pragma omp parallel for
    for(int g=0;G*g<=N-R*r;g++)
    {
      if((N-R*r-G*g)%B==0)
      {
        cnt++;
      }
    }
  }
  
  cout<<cnt;
}


Measured memory_bytes: 256
s = list(input())
status = 0
c = 0
word = [chr(ord('A') + i) for i in range(26)]

#print(s.count("C"))
#print(s.index("C"))
#print(len(s)-2)
#print(s)

if s[0] != "A":
    status = 1
elif s.count("C") == 0:
    status = 1
else:
    if s.count("C") == 1 and 2<=s.index("C")<=len(s)-2:
        del s[0]
        del (s[s.index("C")])
        for i in word:
            if i in s:
                status = 1
                break
    else:
        status = 1

if status == 0:
    print("AC")
else:
    print("WA")


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

int main(){
  int N, M;
  string b, r;
  vector<string> b_card, r_card, list;
  cin >> N;
  rep(i,N){
    cin >> b;
    b_card.push_back(b);
  }
  b = b_card.at(0);
  list.push_back(b);
  bool str_exist;
  rep(i,N){
    b = b_card.at(i);
    str_exist = false;
    rep(j,list.size()){
      if (list.at(j) == b) str_exist = true;
    }
    if (!str_exist) list.push_back(b);
  }
  cin >> M;
  rep(i,M){
    cin >> r;
    r_card.push_back(r);
  }
  rep(i,M){
    r = r_card.at(i);
    str_exist = false;
    rep(j,list.size()){
      if (list.at(j) == r) str_exist = true;
    }
    if (str_exist) list.push_back(b);
  }
  int l_size = list.size();
  int b_size = b_card.size();
  int r_size = r_card.size();
  int score, max_score=0;
  string a;
  rep(i,l_size){
    a = list.at(i);
    score=0;
    rep(j, b_size){
      if(b_card.at(j) == a) score++;
    }
    rep(j,r_size){
      if(r_card.at(j) == a) score--;
    }
    if(score > max_score) max_score = score;
  }
  cout << max_score << endl;  
}
  
  
  

Measured memory_bytes: 256
<?php
  
  list($x, $y) = explode(" ", trim(fgets(STDIN)));

  if(($x+$y)%3!=0){
    echo "0";
    exit;
  }
  // 移動回数
  $move_count=($x+$y)/3;
  // 下への移動回数を$n, 右への移動回数を$mとすると
  // $n+2*$m=$x, $m+2*$n=$yの連立方程式ができる
  $n=(2*$y-$x)/3;
  $m=$move_count-$n;

  if($n<0 || $m<0){
    echo "0";
    exit;
  }

  // ($n+$m)C$n
  echo combination($n+$m, $n, 1000000007);

  function combination($n, $a, $m)
{
    $x=1; // bunbo
    $y=1; // bunshi
    for($i=0;$i<$a;$i++)
    {
        $x=$x*($n-$i)%$m;
        $y=$y*($i+1)%$m;
    }
    // フェルマーの小定理 
    // Y^(P-1)≡1 (mod P) より
    // Y^(P-2)≡1/Y (mod P)
    // つまり
    // $x / $y = $x * $y^($m-2) (mod P)
    $y=repeatSqrt($y, $m-2, $m);
    return ($x*$y)%$m;
}

function repeatSqrt($b, $p, $m){
  if($p==1)
  {
    return $b;
  }
  else if($p%2 == 0)
  {
    $t = repeatSqrt($b, floor($p/2), $m);
    return ($t * $t) % $m;
  }
  else
  {
    return ($b * repeatSqrt($b, $p-1, $m)) % $m;
  }
}

Measured memory_bytes: 4604
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

cnt = {}

for i in range(n):
    if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1

for i in range(m):
    b, c = list(map(int, input().split()))

    if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b

cnts = sorted(cnt.items())
cnt = 0
tot = 0
last = (0, 0)

while cnt < n:
    last = cnts.pop()
    tot += last[0] * last[1]
    cnt += last[1]

tot -= (cnt-n)*last[0]
print(tot)

Measured memory_bytes: 44496
#include <bits/stdc++.h>   
 
#define for0(i, n) for (long long  i = 0; i < n; i++) 
#define for1(i, n) for (long long  i = 1; i <= n; i++) 
#define forc(i, l, r) for (long long  i = l; i <= r; ++i) 
#define forr0(i, n) for (long long  i = n - 1; i >= 0; i--) 
#define forr1(i, n) for (long long  i = n; i >= 1; i--) 
 
#define pb push_back
#define fi first
#define se second
 
#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef long long int lli;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
 
const ll N = 1e5 + 115;
const ll mod = 1e9 + 7;
 
int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    ll i,j,k,n;
    cin>>n>>k;
    ll a[N],dp[N];
    for0(i,n) cin>>a[i];
    for0(i,N) dp[i]=1e15;
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<=i+k;j++)
        {
            dp[j]=min(dp[j],dp[i]+(ll)abs(a[j]-a[i]));
        }
    }
    // for0(i,n) cout<<dp[i]<<" ";
    cout<<dp[n-1]<<endl;
    
    return 0;
}

Measured memory_bytes: 5172
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

vector<int> calc1(int L, vector<int> &A) {
	vector<int> dp(L + 1);
	int sum = 0;
	for(int i = 1; i <= L; ++i) {
		sum += A[i];
		if (A[i] == 0) {
			dp[i] = min(sum, dp[i - 1] + 2);
		} else if(A[i] % 2 == 0) {
			dp[i] = min(sum, dp[i - 1]);
		} else {
			dp[i] = min(sum, dp[i - 1] + 1);
		}
	}
	return dp;
}
vector<int> calc2(int L, vector<int> &A, vector<int> &B) {
	vector<int> dp(L + 1);
	for(int i = 1; i <= L; ++i) {
		int c;
		if(A[i] % 2 == 0) {
			c = 1;
		} else {
			c = 0;
		}
		dp[i] = min(B[i], dp[i - 1] + c);
	}
	return dp;
}

signed main(){
	int L;
	cin >> L;
	vector<int> A(L + 2);
	for(int i = 1; i <= L; ++i) {
		cin >> A[i];
	}
	vector<int> dp1 = calc1(L, A);
	vector<int> dp2 = calc2(L, A, dp1);

	reverse(ALL(A));
	vector<int> rdp1 = calc1(L, A);
	vector<int> rdp2 = calc2(L, A, rdp1);
	reverse(ALL(rdp1));
	reverse(ALL(rdp2));
	int res = (int)(1e17);
	/*
	for(int i = 0; i <= L; ++i) {
		cout << dp1[i] << "," << dp2[i] << "," << rdp1[i] << "," << rdp2[i] << endl;
	}
	*/
	for(int i = 1; i <= L; ++i) {
		res = min(res, dp1[i] + rdp2[i]);
		res = min(res, rdp1[i] + dp2[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>

main(){

	int i=1,n,x,j,l;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	    x=i;
		l=i;
		if(x%3==0){
			printf(" %d",i);
			continue;
		}else{
			for(j=0;j<4;j++){
				if((l%10)==3){
					printf(" %d",i);
					break;
				}
				l /= 10;
			}
		}
	}
	printf("\n");
}



Measured memory_bytes: 2128
package main
import "fmt"
func main(){
    var a, b, c int
    fmt.Scan(&a, &b, &c)
    for i := 1; i <= 100; i++ {
        x := a * i
        if x%b == c {
            fmt.Println("YES")
            return
        }
    }
    fmt.Println("NO")
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 998244353;

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    vint a(n);
    rep(i,n) {cin >> a[i]; a[i]--;}
    vvint move(70,vint(n));
    move[0] = a;
    REP(i,70)rep(j,n) {
        move[i][j] = move[i-1][move[i-1][j]];
    }
    vint x;
    while (k > 0) {
        x.push_back(k%2);
        k >>= 1;
    }
    int pos = 0;
    rep(i,x.size()) {
        if (x[i] == 0) continue;
        pos = move[i][pos];
    }
    cout << pos+1 << endl;
}

Measured memory_bytes: 59680
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const int MAXN = 100;
int f[MAXN + 1][MAXN + 1];
int a[MAXN * MAXN + 100];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int col = 1, dir = 1;
    for(int i = 1; i <= h; i++) {
        if(dir == 1) {
            for(int j = 1; j <= w; j++) {
                if(!a[col])
                    col++;
                f[i][j] = col;
                a[col]--;
            }
        }
        else {
            for(int j = w; j >= 1; j--) {
                if(!a[col])
                    col++;
                f[i][j] = col;
                a[col]--;
            }
        }
        dir *= -1;
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++)
            cout << f[i][j] << " ";
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
import itertools

N, K = map(int, input().split())
mod = (10 ** 9 + 7)

def calc(i):
    small = i * (i - 1) //2
    large = i * (2 * N - i + 1) // 2
    return large - small + 1

total = 0
for i in range(K, N+2):
    total += calc(i)
    total %= mod

print(total)

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

int main() {

ll sum=0;
ll n;
cin >> n;

for (size_t i = 1; i <= n; i++)
{
if (i%3!=0&&i%5!=0)
{
  sum+=i;
}

}

cout << sum <<endl;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
be = 22
cu = 0

for i in range(N):
    cu = A[i] -1
    ans += B[cu]
    if cu == be+1:
        ans += C[be]
    
    be = cu
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
   int a,b,c;
   cin>>a>>b>>c;
   int m=a;
   if (m<b) m=b;
   if(m<c) m=c;
   int k;
   cin>>k;
   cout<<a+b+c+m*(intpow(2,k)-1);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, d[400][400];
bool used[110000];
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

struct Edge {
	ll a, b, cost;
	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

vector<Edge> es;  // 隣接リスト a, b, cost

ll kruskal() {
	sort(es.begin(), es.end());
	UnionFind uf(210000);
	ll min_cost = 0;
	REP(ei, es.size()) {
		Edge& e = es[ei];
		if (!uf.findSet(e.a, e.b)) {
			min_cost += e.cost;
			uf.unionSet(e.a, e.b);
			used[ei] = true;
		}
	}
	return min_cost;
}

int main() {
	bool ok = true;
	cin >> n;
	REP(i, n) {
		REP(j, n) {
			cin >> d[i][j];
			if (i < j)es.push_back({ i,j,d[i][j] });
		}
	}
	REP(k, n)REP(i, n)REP(j, n)if (d[i][j] > d[i][k] + d[k][j])ok = false;
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	ll ans = kruskal();
	REP(ei, es.size()) {
		Edge& e = es[ei];
		bool bo = false;
		REP(k, n) {
			if (k != e.a and k != e.b) {
				if (d[e.a][k] + d[k][e.b] == d[e.a][e.b])bo = true;
			}
		}
		if (!bo and !used[ei])ans += d[e.a][e.b];
	}
	cout << ans << endl;
}




Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a1, k = 2;
  cin >> n >> a1;
  ll ans = a1 - 1;
  rep(i, n - 1) {
    ll a;
    cin >> a;
    if(a == k) {
      k++;
    } else
      ans += (a - 1) / k;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
parseInt(x) = parse(Int, x)

function main()
	c = Array{Int}(3,3)
	for i in 1:3
		c[i,:] = parseInt.(split(readline()))
	end
	if c[1,1]-c[2,1] == c[1,2]-c[2,2] == c[1,3]-c[2,3] && c[1,1]-c[3,1] == c[1,2]-c[3,2] == c[1,3]-c[3,3] && c[1,1]-c[1,2] == c[2,1]-c[2,2] == c[3,1]-c[3,2] && c[1,1]-c[1,3] == c[2,1]-c[2,3] == c[3,1]-c[3,3]
		print("Yes")
	else
		print("No")
	end
end

main()

Measured memory_bytes: 174748
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int M = sc.nextInt();
		
		int[] a = new int[A];
		int[] b = new int[B];

		int minA = Integer.MAX_VALUE;
		int minB = Integer.MAX_VALUE;
		for(int i=0; i<A; i++) {
			a[i] = sc.nextInt();
			minA = Math.min(minA, a[i]);
		}
		for(int i=0; i<B; i++) {
			b[i] = sc.nextInt();
			minB = Math.min(minB, b[i]);
		}
		int ans = minA + minB;
		
		for(int i=0; i<M; i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int c = sc.nextInt();
			ans = Math.min(ans, a[x]+b[y]-c);
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 132700
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  multiset<ll> s;
  rep(i,n){
      ll tmp ;cin >> tmp;
      auto it = s.lower_bound(tmp);
      if(it==s.begin()){
          s.insert(tmp);
      }else{
          it--;
          s.erase(it);
          s.insert(tmp);
      }
  }
  cout << s.size() << endl;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  for (int i{}; i <= Y / 10000; ++i) {
    for (int j{}; j <= (Y - i * 10000) / 5000; ++j) {
      int k = (Y - i * 10000 - j * 5000) / 1000;
      if (i + j + k == N) {
        cout << i << ' ' << j << ' ' << k  << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] ints = new int[2];

		do {
			for(int i = 0; i < 2; i++) {
				ints[i] = sc.nextInt();
			}

			if (ints[0] == 0 && ints[1] == 0) {
				break;
			}

			for (int i = 0; i < ints[0]; i++) {
				if ( i == 0 || i == ints[0] - 1) {
					for (int j = 0; j < ints[1]; j++) {
						System.out.print("#");
					}
				}else {
					System.out.print("#");
					for (int j = 1; j < ints[1] - 1; j++) {
						System.out.print(".");
					}
					System.out.print("#");
				}

				System.out.println();
			}

			System.out.println();

		}while(true);

		sc.close();

	}

}


Measured memory_bytes: 33952
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	return n, as
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int, as []int) int {
	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	num := len(as)
	if num == 1 {
		return 0
	}
	sum := 0
	for i := 1; i < num; i++ {
		sum += as[i/2]
	}
	return sum
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6004