akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  double v;
  while(cin>>v){
    double t=v/9.8;
    double y=4.9*pow(t,2);
    for(int i=1;;i++){
      int N=5*i-5;
      if(N>y){
        cout<<i<<endl;
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
#define maxn 0x3f3f3f



int main()
{
    long long x,k,l;
    scanf("%lld %lld %lld",&x,&k,&l);
    long long d;

    long long r;
    if (x==0)
    {
        if(k%2==0) cout<<0<<endl;
        else  cout<<l<<endl;
    }

    else
    {
        
        if(x<0)
            x=-x;
        d=x/l;
        if(d<k)
        {
            if((k-d)%2==0)
                printf("%lld\n",x%l);
            else
                printf("%lld\n",min((x%l)+l,llabs((x%l)-l)));
        }
        else
        {
            printf("%lld\n",x-(l*k));
        }
    }
    return 0;
}


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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<4;i++) cout<<s[i];
    cout<<' ';
    for(int i=4;i<12;i++) cout<<s[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    # n = int(input())
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in range(n)]

    x.sort()

    subs = []

    for i in range(1, m):
        subs.append(abs(x[i]-x[i-1]))

    subs.sort()
    if (m < n):
        print(0)
    else:
        print(sum(subs[0:m-n]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 90192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;
using  v = vector<int>;

int main(){
   int n,m;
   cin >> n >> m;
   //auto a = v(m,0);
   //auto b = v(m,0);
   auto M = vector<v>(2,v(n,0));

   for (int i = 0; i < m; i++)
   {
      int a,b;
      cin >> a;
      cin >> b;
      a--;
      b--;
      if(a==0){
         M[0][b]=1;
      }else if(b==0){
         M[0][a]=1;
      }else if(a==n-1){
         M[1][b]=1;
      }else if(b==n-1){
         M[1][a]=1;
      }
   }
   
   bool f=false;
   for (size_t i = 0; i < n; i++)
   {
      if(M[0][i]==1&&M[1][i]==1){
         f=true;
         break;
      }
   }
   
   cout << (f?"POSSIBLE":"IMPOSSIBLE");

   return 0;
}
  
  

Measured memory_bytes: 2560
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(){
    int N;
    cin >> N;
    int A[N];
    int num_decre=0,num_incre=0;
    for(int i=0;i<N;++i){
        cin >> A[i];
    }
    int pos=0;
    int res=0;
    while(pos<N){
        num_decre=0,num_incre=0;
        while(A[pos+num_decre]<=A[pos+num_decre+1]){
            ++num_decre;
        }
        
        while(A[pos+num_incre]>=A[pos+num_incre+1]){
            ++num_incre;
        }
        ++res;
        pos+=max(num_incre,num_decre)+1;
    }
    cout << res;
}

Measured memory_bytes: 640
#include<iostream>
int cnt;
void insertionSort(int* arr, int len, int g) {
	for (int i = g; i < len; i++) {
		int v = arr[i];
		int j;
		for (j = i - g; j >= 0 && arr[j] > v; j -= g) {
			arr[j + g] = arr[j];
			cnt++;
		}
		arr[j + g] = v;
	}
}
void shellSort(int* arr, int len) {
	using namespace std;
	cnt = 0;
	int m;
	int h = 0;
	for (m = -1; h <= len; m++)
		h = 3 * h + 1;
	cout << m << endl;
	int* G = new int[m];
	G[0] = 1;
	for (int i = 1; i < m; i++) 
		G[i] = 3 * G[i - 1] + 1;
	for (int i = m - 1; i >= 0; i--) {
		if (i != m - 1)
			cout << " " << G[i];
		else
			cout << G[i];
		insertionSort(arr, len, G[i]);
	}
	cout << endl;
	cout << cnt << endl;
}
void printAns(int* arr, int len) {
	for (int i = 0; i < len; i++) {
		if (i)
			std::cout << " " << arr[i];
		else
			std::cout << arr[i];
	}
	std:: cout << std::endl;
}
int main() {
	using namespace std;
	int len;
	cin >> len;
	int* arr =new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	shellSort(arr, len);
	for (int i = 0; i < len; i++)
		cout << arr[i] << endl;
	delete[]arr;
	return 0;
}


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

void rekkyo_div(int64_t x,set<int64_t> &koho){
    for(int i=1;i<=sqrt(x);i++){
        if(x%i == 0){
            koho.insert(i);
            koho.insert(x/i);
        }
    }
}
bool ok(int64_t kk,int64_t N){
    while(N%kk == 0){
        N /= kk;
    }
    if(N%kk == 1) return true;
    else return false;
}

void count_K(set<int64_t> &koho,int64_t &cnt,int64_t N){
    for(auto kk:koho){
        if(kk ==1){}
        else if(kk == 2){cnt++;}
        else {
            if(ok(kk,N)) cnt++;
        }
    }
    return;
}

int main(){
    int64_t N;
    cin >> N;
    set<int64_t> koho;
    int64_t cnt =0;

    if(N >= 4){
        rekkyo_div(N,koho);
        rekkyo_div(N-1,koho);
        count_K(koho,cnt,N);
    }else if(N == 3){
        cnt = 2;
    }else if(N == 2){
        cnt = 1;
    }

    cout << cnt << endl;
}   

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

ll a[100100];
ii p[100100];

bool f(ii a, ii b){
	return a.ss < b.ss;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; ++i){
    	cin >> a[i];
    }
    sort(a, a+n);
    for (int i = 0; i < m; ++i){
    	cin >> p[i].ff >> p[i].ss;
    }
    sort(p, p+m, f);
    reverse(p, p+m);

    int at = 0;
    for (int i = 0; i < m; ++i){
    	while(p[i].ff && a[at] < p[i].ss && at < n){
    		a[at] = p[i].ss;
    		at++;
    		p[i].ff--;
    	}
    	if(a[at] >= p[i].ss || at >= n) break;
    }
    ll sum = 0;
    for (int i = 0; i < n; ++i){
    	sum+=a[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 2560
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n;
    cin>>n;
    int a[n+4];
    a[n+1]=inf;
    f(i,1,n)cin>>a[i];
    int cnt=0;
    int ses=0;
    f(i,1,n)
    {
        if(a[i]==a[i+1])
        {
            cnt++;
        }
        else
        {
            cnt++;
            ses+=(cnt/2);
            cnt=0;
        }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 3652
import Data.List
import Control.Monad

rr :: IO [String]
rr = words <$> getLine

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- replicateM n rr
    let [vs,us] = transpose xs
    let res = sum $ zipWith convert us (map read vs)
    print res


toJPY :: Double -> Double
toJPY = (*380000.0)


convert :: String -> Double -> Double
convert "JPY" = id
convert "BTC" = toJPY


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






int main(){
  int n;
  cin>>n;
  if(n==0){cout<<1<<endl;}
  if(n==1){cout<<2<<endl;}
  if(n==2){cout<<1<<endl;}
  if(n>2){cout<<0<<endl;}

  return 0;  
}



Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;

bool odd_dig(int i){
    if(i < 100){
        return i < 10;
    } 
    return odd_dig(i/100);
}

void sub_main(istream &is) {
    ll N;
    is >> N;
    if(!is) return;
    ll mendo = 0;
    for (int i = 1; i <= N; ++i) {
        mendo += odd_dig(i);
    } // end i
    cout << mendo << endl;
    

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_B.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split(' '))

heights = np.array(tuple(map(int, input().split(' '))))

dp = np.zeros(shape=N, dtype=int)

for i in range(1, N):
    dp[i] = np.min(np.abs(heights[i] - heights[max(0, i - K):i]) + dp[max(0, i - K):i])

print(dp[N - 1])


Measured memory_bytes: 23196
/*
Author: miitbh1
*/
#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<n; i++)
#define repA(i, a, n) for(int i=a; i<n; i++)
#define repD(i, a, n) for(int i=a; i>=n; i--)
#define trav(it, ctr) for(auto it=ctr.begin(); it!=ctr.end(); it++)
#define p(x) cout<<x<<"\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pp(x, y) cout<<x<<" "<<y<<"\n"
#define btc __builtin_popcount
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef priority_queue<int> pq;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
using ll=long long int;
const int N=100001;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    ll sum=0;
    rep(i, n){
        cin>>a[i];
        if(i){
            if(a[i-1]>a[i]){
                sum+=a[i-1]-a[i];
                a[i]=a[i-1];
            }
        }
    }
    p(sum);
    return 0;
}

Measured memory_bytes: 4392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdlib.h>

using namespace std;

const int nax = 1e5 + 5;

vector <int> edges[nax];
int		in_degree[nax];
int		visited[nax];
int		dist[nax];

void	dfs(int a)
{
	visited[a] = 1;
	for (int b : edges[a])
	{
		dist[b] = max(dist[b], dist[a] + 1);
		in_degree[b]--;
		if (in_degree[b] == 0)
			dfs(b);
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < nax; i++)
		visited[i] = 0;
	while (m--)
	{
		int a,b;
		cin >> a >> b;
		edges[a].push_back(b);
		in_degree[b]++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (!visited[i] && in_degree[i] == 0)
			dfs(i);
	}
	int answer = 0;
	for (int i = 1; i <= n; i++)
		answer = max(answer, dist[i]);
	cout << answer;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x1 jfkljfewlkjfwekl
#define x2 jkfwejklfwej
#define y1 kfewfe
#define y2 jfwekj3w3e

int bomb[50][50];


int a[4][4] = {
	{0,0,0,0},
	{0,0,0,0},
	{1,1,0,0},
	{1,1,0,0},
};
int myquery(int x1,int x2,int y1,int y2){
	int sum = 0;
	for(int i = y1 ; i <= y2 ; i++)
		for(int j = x1 ; j <= x2 ; j++)
			sum += a[i][j];
	return sum;
}
int query(int x1,int x2,int y1,int y2){
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	//return myquery(x1,x2,y1,y2);
	int sum;
	cin >> sum;
	return sum;
}
void dfs(int x1,int x2,int y1,int y2,int prv){
	if( x1 > x2 or y1 > y2 ) return;
	if( x1 == x2 and y1 == y2 ){
		bomb[y1][x1] = query(x1,x2,y1,y2);
		
		return;
	}else{
		int ask = query(x1,x2,y1,y2);
		
		if(!ask) return;
		int X = (x1+x2) / 2;
		int Y = (y1+y2) / 2;
		dfs(x1,X,y1,Y,ask);
		dfs(X+1,x2,y1,Y,ask);
		dfs(x1,X,Y+1,y2,ask);
		dfs(X+1,x2,Y+1,y2,ask);
	}
	
}
signed main(){
	int H,W,N,K;
	cin >> H >> W >> N >> K;
	for(int i = 0 ; i < H ; i++){
		dfs(0,W-1,i,i,-1);
	}
	long long ans = 0;
	long long w = 1;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			ans += w * bomb[i][j];
			ans %= K;
			w *= 2;
			w %= K;
		}
	}
	cout << "!" << " " << ans << endl;
}

Measured memory_bytes: 724
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/24
Solved on 2019/2/24
@author: shinjisu
"""


# ABC 119
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probB():
    N = getInt()
    dmp(N)
    sm = 0.0
    for i in range(N):
        x, u = [a for a in input().split()]
        dmp((x,u))
        if u == 'JPY':
            x = int(x)
        else:
            x = float(x) * 380000.0
        sm += x
    return sm


debug = False  # True False
print(probB())


def gcd(x, y):  # 最大公約数
    m = max(x, y)
    n = min(x, y)
    while m % n != 0:
        w = m % n
        m = n
        n = w
    return n


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hp = A[N-1]
    for i in range(N-1):
        hp = gcd(hp, A[i])
        dmp(hp)
    return hp


def probD():
    N, M = getIntList()
    A = getIntList()
    dmp((N, M))
    dmp(A)
    return num


def probA():
    S = input()
    dmp(S)
    y = int(S[0:4])
    m = int(S[5:7])
    d = int(S[8:10])
    dmp((y,m,d))
    HEI = 'Heisei'
    if y <= 2018:
        return HEI
    if m <= 4:
        return HEI
    else:
        return 'TBD'




Measured memory_bytes: 3192
A, B, C, D = map(int, input().split())

while (A > 0) & (C > 0):
    C = C - B
    if(C > 0):
        pass
    else:
        print('Yes')
        break
    A = A - D
    if(A > 0):
        pass
    else:
        print('No')
        break

Measured memory_bytes: 9168
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}

		Arrays.sort(a);

		PriorityQueue<long[]> pq = new PriorityQueue<>((x, y) -> -Long.compare(x[1], y[1]));
		while (m-- > 0) {
			pq.offer(new long[]{sc.nextLong(), sc.nextLong()});
		}

		long answer = 0;
		long[] x = pq.poll();
		int count = 0;
		int idx = n - 1;
		while (count < n) {
			if (x != null && a[idx] < x[1] && x[0] > 0) {
				answer += x[1];
				x[0]--;
				if (x[0] == 0) x = pq.poll();
			} else {
				answer += a[idx--];
			}
			count++;
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 95812
#include<cstdio>
#include<iostream>
using namespace std;
int m,n;
int main(){
    cin>>m>>n;
    if(m*10000<n){
        printf("-1 -1 -1\n");
        return 0;
    }
    if(m*1000>n){
        printf("-1 -1 -1\n");
        return 0;
    }
    if(n%1000!=0){
        printf("-1 -1 -1\n");
        return 0;
    }
    for(int i=0;i<=m;i++)
    for(int j=0;j<=m;j++)
    for(int k=0;k<=m,i+j+k<=m;k++)
    {
        if(i+j+k==m&&i*1000+j*5000+k*10000==n)
        {
            printf("%d %d %d",k,j,i);
            return 0;   
        }
    }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from collections import defaultdict
import json
from copy import deepcopy
import sys
sys.setrecursionlimit(10**4)

def dfs(graph, s):
  dist = [-1 for _ in range(len(graph))]
  dist[s] = 0
  stack = [s]
  while len(stack) != 0:
    s = stack.pop()
    for t in graph[s]:
      dist[t] = dist[s]+1
      if s in graph[t]:
        graph[t].remove(s)
      stack.append(t)
  return dist

if __name__=='__main__':
  graph = defaultdict(list)
  n, u, v = map(int, input().strip().split())
  for _ in range(n-1):
    ai, bi = map(int, input().strip().split())
    graph[ai-1].append(bi-1)
    graph[bi-1].append(ai-1)
  du = dfs(deepcopy(graph), u-1)
  dv = dfs(deepcopy(graph), v-1)
  costv = [0]
  for duv, dvv in zip(du, dv):
    if duv < dvv:
      costv.append(dvv)
  print(max(costv) - 1)

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

int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

ll c[505]; //到一个车站的花费时间
ll s[505]; //一个车站出发的等待时间
ll f[505];  //一个车站每f秒出发一个车
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        scanf("%ld%ld%ld",&c[i],&s[i],&f[i]);
    for(int i=1;i<=n;i++){
        ll time=0;
        for(int j=i;j<n;j++){
            if(time<s[j])   //小于等待时间重新赋值
                time=s[j];
            if(time%f[j]!=0)    //是否处于间隔时间
                time=time+f[j]-time%f[j];
            time+=c[j];
        }
        printf("%ld\n",time);
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twol pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
ll n,ans,d,d1;
twol a[55],b[55];
int main(){FAST;xRand;
cin>>n;
if(n==1){
	cout<<1<<endl;
	return 0;
}
for(int i=1;i<=n;i++){
	cin>>a[i].f>>a[i].s;
}
ans=n;
for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
		if(i==j) continue;
		d=a[i].f-a[j].f;
		d1=a[i].s-a[j].s;
		if(d==0&&d1==0) continue;
		ll o=0;
		for(int k=1;k<=n;k++){
			for(int p=1;p<=n;p++){
				if((a[k].f-d==a[p].f&&a[k].s-d1==a[p].s))
				   o++;
			}
		}
//		cout<<d<<" "<<d1<<" "<<o<<endl;
		ans=min(ans,n-o);
	}
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/






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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = 1e6;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int h, w;
char A[55][55];

vector < vector < pair<int,int> > > g (2555);

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

    cin>>h>>w;

    int black = 0;
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            cin>>A[i][j];
            if(A[i][j] == '#') {
                black++;
            }
        }
    }

    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(A[i][j] == '#') {
                continue;
            }

            int x = i, y = j, u = w * (x - 1) + y;

            for(int k = 0; k < 4; k++) {
                int xx = x + dx[k];
                int yy = y + dy[k];

                if(1 <= xx and xx <= h and 1 <= yy and yy <= w and A[xx][yy] != '#') {
                    int v = w * (xx - 1) + yy;
                    g[u].pb({v, 1});
                    g[v].pb({u, 1});
                }
            }
        }
    }

    // code taken from http://e-maxx.ru/algo/dijkstra_sparse
    int s = 1;
    int n = h * w + 5;
    vector<int> d (n, INF),  p (n);
	d[s] = 0;
	set < pair<int,int> > q;
	q.insert (make_pair (d[s], s));
	while (!q.empty()) {
		int v = q.begin()->second;
		q.erase (q.begin());

		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				q.erase (make_pair (d[to], to));
				d[to] = d[v] + len;
				p[to] = v;
				q.insert (make_pair (d[to], to));
			}
		}
	}

	if(d[h*w] == INF) {
        cout<<"-1\n";
	}
	else {
        int white = h*w - black;
        cout<<white - (d[h*w] + 1)<<"\n";
	}

    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B = mi()
print((A+B+1)//2)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string S;

int main(void){
    
    cin >> S;
    
    string ans;
    for(int i = 0; i < S.size(); ++i){
        if((i + 1) % 2 == 1) ans.push_back(S[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	map<string, uint64_t> map;

	for (auto i = 0; i < N; i++) {
		string str;
		cin >> str;
		sort(str.begin(), str.end());
		map[str]++;
	}

	uint64_t result = 0;
	for (auto& e : map) {
		result += (e.second) * (e.second - 1) / 2;
	}
	cout << result << endl;
	return 0;
}


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

int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(0 >= b-a){
    cout << "delicious" << endl;
    }
    else if(x >= b-a){
    cout << "safe" << endl;
    }
    else{cout << "dangerous" << endl;}
    
    return 0;
}


Measured memory_bytes: 256
<?php
/*
    Problem URL : http://abc054.contest.atcoder.jp/tasks/abc054_d

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

$ans = PHP_INT_MAX;

fscanf(STDIN, "%d %d %d", $N, $Ma, $Mb);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d %d", $data[$i]['a'], $data[$i]['b'], $data[$i]['c']);
    $tmpA = $data[$i]['a'] / $Ma;
    $tmpB = $data[$i]['b'] / $Mb;
    if ($tmpA != $tmpB) continue;
    if ($tmpA != floor($tmpA)) continue;
    if ($tmpB != floor($tmpB)) continue;
    $ans = min($ans, $data[$i]['c']);
}

for ($i = 0; $i < $N-1; $i++) {
    for ($j = $i + 1; $j < $N; $j++) {
        $tmpA = ($data[$i]['a'] + $data[$j]['a']) / $Ma;
        $tmpB = ($data[$i]['b'] + $data[$j]['b']) / $Mb;
        if ($tmpA != $tmpB) continue;
        if ($tmpA != floor($tmpA)) continue;
        if ($tmpB != floor($tmpB)) continue;
        // echo "{$i} {$j}\n";
        $ans = min($ans, $data[$i]['c'] + $data[$j]['c']);
    }
}

for ($i = 0; $i < $N-2; $i++) {
    for ($j = $i + 1; $j < $N - 1; $j++) {
        for ($k = $j + 1; $k < $N; $k++) {
            $tmpA = ($data[$i]['a'] + $data[$j]['a'] + $data[$k]['a']) / $Ma;
            $tmpB = ($data[$i]['b'] + $data[$j]['b'] + $data[$k]['b']) / $Mb;
            if ($tmpA != $tmpB) continue;
            if ($tmpA != floor($tmpA)) continue;
            if ($tmpB != floor($tmpB)) continue;
            // echo "{$i} {$j}\n";
            $ans = min($ans, $data[$i]['c'] + $data[$j]['c'] + $data[$k]['c']);
        }
    }
}

for ($i = 0; $i < $N-3; $i++) {
    for ($j = $i + 1; $j < $N - 2; $j++) {
        for ($k = $j + 1; $k < $N - 1; $k++) {
            for ($l = $k + 1; $l < $N; $l++) {
                $tmpA = ($data[$i]['a'] + $data[$j]['a'] + $data[$k]['a'] + $data[$l]['a']) / $Ma;
                $tmpB = ($data[$i]['b'] + $data[$j]['b'] + $data[$k]['b'] + $data[$l]['b']) / $Mb;
                if ($tmpA != $tmpB) continue;
                if ($tmpA != floor($tmpA)) continue;
                if ($tmpB != floor($tmpB)) continue;
                // echo "{$i} {$j}\n";
                $ans = min($ans, $data[$i]['c'] + $data[$j]['c'] + $data[$k]['c'] + $data[$l]['c']);
            }
        }
    }
}

if ($ans === PHP_INT_MAX) {
    echo "-1\n";
} else {
    echo $ans . PHP_EOL;    
}


Measured memory_bytes: 3064
/**
 *      purpose : CODE FESTIVAL 2016 Final
 *      author  : kyomukyomupurin
 *      created : 2018-11-13 01:40:20
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int square(int N){
    for (int i = 1; ; ++i){
        if (N > (i - 1) * i / 2 && N <= i * (i + 1) / 2) return i;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    while (N > 0){
        print(square(N)); N -= square(N);
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BI18n solver = new BI18n();
        solver.solve(1, in, out);
        out.close();
    }

    static class BI18n {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            out.print(s.charAt(0));
            out.print(s.length() - 2);
            out.println(s.charAt(s.length() - 1));
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

ll f(ll b,ll n){
  if(n<b)return n;
  return f(b,n/b)+n%b;
}

int main(){
  ll n,s;
  cin>>n>>s;

  if(n==s){
    cout<<n+1<<endl;
    return 0;
  }

  for(ll i=2;i*i<=n;i++){
    if(f(i,n)==s){
	 cout<<i<<endl;
	 return 0;
    }
  }

  ll ans=1e18;
  for(ll i=1;i*i<=n;i++){
    ll b=(n-s+i)/i;
    if(b<2)continue;
    if(f(b,n)==s){
	 ans=min(ans,b);
    }
  }

  if(ans!=1e18){
    cout<<ans<<endl;
    return 0;	
  }

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


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

#define N 101
typedef long long ll;
int n, m, k, d;

int expmod(int a, int b) {
	int rlt = 1;
	for (a %= d; b; b >>= 1, a = 1ll * a * a % d) if (b&1) rlt = 1ll * rlt * a % d;
	return rlt;
}

int C[N][N];

void comb() {
	C[0][0] = 1;
	for (int i = 1; i < N; i ++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j ++) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % d;
	}
}

int dp[2][N][N];

void add(int &a, ll b) {
	a = (a + b) % d;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>n>>m>>k>>d;
	comb();
	int u = 0, v = 1;
	dp[u][n][m] = 1;
	for (int i = 1; i <= k; i ++) {
		memset(dp[v], 0, sizeof dp[v]);
		for (int r = 0; r <= n; r ++) {
			for (int c = 0; c <= m; c ++) if (dp[u][r][c]) {
				int fa = expmod(i, c) - expmod(i - 1, c) + d, fb = expmod(k - i + 1, m - c);
				for (int x = 0, ca = 1, cb = 1; x <= r; x ++, ca = 1ll * ca * fa % d, cb = 1ll * cb * fb % d) {
					add(dp[v][r-x][c], 1ll * C[r][x] * ca % d * cb % d * dp[u][r][c]);
				}
			}
		}
		swap(u, v);
		memset(dp[v], 0, sizeof dp[v]);
		for (int r = 0; r <= n; r ++) {
			for (int c = 0; c <= m; c ++) if (dp[u][r][c]) {
				int fa = expmod(k - i + 1, n - r) - expmod(k - i, n - r) + d, fb = expmod(i, r);
				for (int y = 0, ca = 1, cb = 1; y <= c; y ++, ca = 1ll * ca * fa % d, cb = 1ll * cb * fb % d) {
					add(dp[v][r][c-y], 1ll * C[c][y] * ca % d * cb % d * dp[u][r][c]);
				}
			}
		}
		swap(u, v);
	}
	cout<<dp[u][0][0];
}


Measured memory_bytes: 3708
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 33000
#define INF 0x3f3f3f3f
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define Mod 1000000007
#define i64 __int64
#define LIMIT_ULL 100000000000000000
#define LL long long
using namespace std;
long long s[105];
long long gcd(long long a,long long b)
{
     if(b==0)
          return a;
     return gcd(b,a%b);
}
int main()
{
     int n;
     scanf("%d",&n);
     for(int i=0;i<n;i++)
          scanf("%lld",&s[i]);
     long long sum=1;
     for(int i=0;i<n;i++)
     {
          long long d=gcd(sum,s[i]);
          //cout<<sum<<endl;
          sum=sum/d*s[i];
     }
     cout<<sum<<endl;
}


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

int main() {

int N,M,ans=0;
  string k;
  cin>>N;
  vector<string> A(N);
  map<string,int> map;
  for(int i=0;i<N;i++){
    cin>>A.at(i); 
    map.count(A.at(i)) ? map[A.at(i)]++ : map[A.at(i)]=1;}
  cin>>M;
      for(int i=0;i<M;i++){
    cin>>k;
    map.count(k) ? map[k]-- : map[k]=-1;}
for(int i=0; i<N; i++){
  if(ans<map[A.at(i)]) ans=map[A.at(i)];
  //cout<<map[A.at(i)]<<endl;
     } cout<<ans<<endl;
 
}


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

const long long MOD = 1e9 + 7;
const int NMAX = 2e5 + 5;
int n;
long long a[NMAX], sum[NMAX], sol;

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = n; i >= 1; i--) {
        sum[i] = (a[i] + sum[i + 1]) % MOD;
    }
    for(int i = 1; i < n; i++) {
        sol = (sol + a[i] * sum[i + 1]) % MOD;
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 6752
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++)
#define MAX 200
#define INFTY (1<<21)

int N, M, R, L[MAX][MAX], S[MAX][MAX];
vector<int> O;

void floyd(int D[MAX][MAX], int n){
    rep(k, n) rep(i, n){
	if ( D[i][k] == INFTY ) continue;
	rep(j, n){
	    if ( D[k][j] == INFTY ) continue;
	    D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
	}
    }
}

int compute(){
    floyd(L, N);
    floyd(S, N);
    int T[1000][MAX];
    rep(i, O.size()) rep(j, N) T[i][j] = INFTY;
    
    T[0][O[0]] = 0;

    for ( int i = 1; i < R; i++ ){
	for ( int j = 0; j < N; j++ ){
	    T[i][j] = min(T[i][j], T[i-1][j] + L[O[i-1]][O[i]]);
	    for ( int k = 0; k < N; k++ ){
		T[i][k] = min(T[i][k], T[i-1][j] + L[O[i-1]][j] + S[j][k] + L[k][O[i]]);
	    }

	}
    }

    int minv = INFTY;
    rep(i, N) minv = min(minv, T[O.size()-1][i]);
    return minv;

}

main(){
    int s, t, c;
    char ch;
    while(cin >> N >> M && N ){
	O.clear();
	rep(i, N) rep(j, N) L[i][j] = S[i][j] = INFTY;
	rep(i, N) L[i][i] = S[i][i] = 0;
	rep(i, M){
	    scanf("%d %d %d", &s, &t, &c); cin >> ch;
	    s--; t--;
	    if ( ch == 'L' ) L[s][t] = L[t][s] = min(L[s][t], c);
	    else S[s][t] = S[t][s] = min(S[s][t], c);
	}
	cin >> R;
	rep(i, R){
	    cin >> s; s--;
	    O.push_back(s);
	}
	cout << compute() << endl;
    }
}

Measured memory_bytes: 2048
import java.util.*;
import java.lang.*;
public class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s=sc.nextLine();
        if(s.charAt(1)=='R')
            System.out.println("ABC");
        else
            System.out.println("ARC");
    }
}

Measured memory_bytes: 35516
#include <stdio.h>
#define N 100
int main()
{
  int i, j, n, minj, A[N], temp, ccount=0;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&A[i]);
    }
  for(i = 0 ; i < n ; i++)
    {
      minj=i;
      for(j = i ; j < n ; j++)
	{
	  if(A[j] < A[minj])
	    {
	      minj=j;
	    }
	}
      if(A[i]!=A[minj]) ccount++;

      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;
    }
  for(i = 0 ; i < n ; i++)
    {
      if(i==n-1)
	{
	  printf("%d\n",A[i]);
	}else{
	printf("%d ",A[i]);
      }
    }
  printf("%d\n",ccount);
  return 0;
}

Measured memory_bytes: 600
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	if (a!=b)
		cout<<max(a,b)*2-1<<endl;
	else
		cout<<a*2<<endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(h: usize, w:usize, aa:Vec<usize>) -> Vec<Vec<usize>> {
    let mut v = Vec::new();

    for (n, &a) in aa.iter().enumerate() {
        for _ in 0..a {
            v.push(n+1);
        }
    }

    let mut ret = Vec::new();

    for i in 0..h {
        ret.push(if i % 2 == 0 {
            v[i*w..i*w+w].iter().cloned().collect()
        } else {
            v[i*w..i*w+w].iter().cloned().rev().collect()
        })
    }

    ret
}

fn main() {
    let (h, w) = parse_line!(usize, usize);
    read_line!();

    let aa = parse_vec!(usize);

    for l in solve(h, w, aa).iter() {
        println!("{}", l.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(" "));
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(2, 2, vec![2,1,1]),
               vec![vec![1,1],
                    vec![3,2]]);
}


Measured memory_bytes: 4352
N = int(input())
X = [int(x) for x in input().split()]

ave = sum(X) // N
E1 = []
E2 = []

for i in X:
    E1.append((i - ave-1) ** 2)
    E2.append((i - ave) ** 2)
    
print(min(sum(E1), sum(E2)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
vector<int> V;
vector<int> V1;
int s, s1;
int dp0[1000005];
int dp1[1000005];
int solve0(int n) {
    if(n == 0) {
        return dp0[0] = 0;
    }
    if(dp0[n] != -1) return dp0[n];
    int res = INF;
    rep(i, s) {
        if(V[i] > n) break;
        res = min(res, solve0(n - V[i]) + 1);
    }
    return dp0[n] = res;
}

int solve1(int n) {
    if(n == 0) {
        return dp1[0] = 0;
    }
    if(dp1[n] != -1) return dp1[n];
    int res = INF;
    rep(i, s1) {
        if(V1[i] > n) break;
        res = min(res, solve1(n - V1[i]) + 1);
    }
    return dp1[n] = res;
}
signed main(void) {
    for(int i = 1;; i++) {
        int n = i * (i + 1) * (i + 2) / 6;
        if(n < 1000000) {
            V.push_back(n);
            if(n % 2 == 1) V1.push_back(n);
        } else
            break;
    }
    s = V.size();
    s1 = V1.size();
    rep(i, 1000005) dp0[i] = -1;
    rep(i, 1000005) dp1[i] = -1;
    while(true) {
        int n;
        cin >> n;
        if(n == 0) return 0;
        cout << solve0(n) << ' ' << solve1(n) << endl;
    }
}



Measured memory_bytes: 38056
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0.0, double y = 0.0): x(x), y(y) {};

    Point operator + (Point &p) {return Point(x + p.x, y + p.y);}
    Point operator - (Point &p) {return Point(x - p.x, y - p.y);}
    Point operator * (double k) {return Point(x * k, y * k);}
    Point operator / (double k) {return Point(x / k, y / k);}

    double norm(void) {return x * x + y * y;}
    double abs(void) {return sqrt(norm());}

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    double dot(Point a) {
        return x * a.x + y * a.y;
    }

    double cross(Point a) {
        return x * a.y - y * a.x;
    }
};

typedef Point Vector;

struct Segment {
    Point p1, p2;
};

typedef Segment Line;

Point getCrossPoint(Segment s1, Segment s2) {
    Vector base = s2.p2 - s2.p1;
    double d1 = abs(base.cross(s1.p1 - s2.p1));
    double d2 = abs(base.cross(s1.p2 - s2.p1));
    double t = d1 / (d1 + d2);
    return (s1.p2 - s1.p1) * t + s1.p1;
}

int main(void) {
    int x1, x2, x3, x4, y1, y2, y3, y4, q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d %d %d %d %d",
                &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
        Segment s1, s2;
        s1.p1 = Point(x1, y1);
        s1.p2 = Point(x2, y2);
        s2.p1 = Point(x3, y3);
        s2.p2 = Point(x4, y4);
        Point ret = getCrossPoint(s1, s2);
        printf("%.10f %.10f\n", ret.x, ret.y);
    }

    return 0;
}

Measured memory_bytes: 1068
n = int(input())
m = map(int , input().split())

#入れ替える必要のある要素のインデントを格納
l = []
for i,item in enumerate(m):
  if i+1 == item:
    l.append(i)

ans = len(l)

for i in range(len(l)):
  if i == 0:
    continue

  if l[i] == l[i-1] + 1:
    ans -= 1
    l[i] = l[i-1] - 1


print(ans)

Measured memory_bytes: 13880
def solve(text, count):
    if len(text) == 1:
        return count // 2

    # split chars into first part & last part & middle parts & joint parts
    first_ch = text[0]

    # Endpoints exclusive
    first_index = -1
    middle_index = -1

    for i, ch in enumerate(text):
        if ch == first_ch:
            continue
        else:
            first_index = i
            break

    if first_index == -1:
        # All Same Character
        return (len(text) * count) // 2

    for i in range(len(text) - 1, first_index - 1, -1):
        if text[i] == first_ch:
            continue
        else:
            middle_index = i + 1
            break

    first_part = text[:first_index]
    middle_part = text[first_index:middle_index]
    end_part = text[middle_index:]
    joint_part = end_part + first_part

    def calc_changes(raw_part):
        change = 0

        part = [ch for ch in raw_part]

        for i, ch in enumerate(part):
            if i == 0:
                continue
            if part[i - 1] == part[i] and part[i - 1] != '!':
                part[i] = '!'  # Any char fine since we can choose any
                change += 1
                continue

        return change

    return calc_changes(first_part) + calc_changes(middle_part) * count + \
           calc_changes(joint_part) * (count - 1) + calc_changes(end_part)


if __name__ == "__main__":
    s = input()
    k = int(input())
    print(solve(s, k))


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 5555
const int MOD=1e9+7;
int n,m,l[SZ],r[SZ],x[SZ];
vector<int> qry[SZ];
int f[333][333][333];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
		scanf("%d%d%d",l+i,r+i,x+i),--x[i],qry[r[i]].pb(i);
	f[1][0][0]=3;
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<=i;++j)
		{
			for(int k=0;k<=j;++k)
			{
				if(!f[i][j][k]) continue;
				bool gg=0;
				for(auto q:qry[i])
				{
					int g=(l[q]<=j)+(l[q]<=k);
					if(g!=x[q]) {gg=1; break;}
				}
				if(gg) f[i][j][k]=0;
				if(!f[i][j][k]) continue;
				for(int r=0;r<=2;++r)
				{
					int x[]={i,j,k}; x[r]=i+1; sort(x,x+3);
					int&F=f[x[2]][x[1]][x[0]];
					F+=f[i][j][k]; (F>=MOD)?(F-=MOD):0;
				}
			}
		}
	}
	int ans=0;
	for(int j=0;j<=n;++j)
		for(int k=0;k<=n;++k)
			(ans+=f[n][j][k])%=MOD;
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",ans);
}

Measured memory_bytes: 129536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int n = N % 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "bon" << endl;
}

Measured memory_bytes: 3636