akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

#define INF 1000000007

bool pairComp(const pair<long long, long long>& f, const pair<long long, long long>& s){
  return f.first < s.first;
}

int main(){
  long long n, d, a;
  cin >> n >> d >> a;

  vector<pair<long long, long long> > m(n);
  long long x, h;
  for(long long i = 0; i < n; i++){
    cin >> x >> h;
    m[i] = {x, h};
  }

  sort(m.begin(), m.end(), pairComp);

  vector<long long> cum(n+1, 0);
  long long ans = 0;
  vector<long long> mx(n);
  for(long long i = 0; i < n; i++){
    mx[i] = m[i].first;
  }
  for(long long i = 0; i < n ; i++){
    if(i > 0)cum[i] += cum[i-1];
    if(m[i].second <= cum[i]) continue;
    long long r = m[i].first + 2*d;
    long long mr = upper_bound(mx.begin(), mx.end(), r) - mx.begin();
    ans += (m[i].second - cum[i] + a-1)/a;
    cum[mr] -= (m[i].second - cum[i] + a-1)/a * a;
    cum[i] += (m[i].second - cum[i] + a-1)/a * a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define INF (1e9)
#define N 52
using namespace std;
int n,m,a[N],b[N],A[N],B[N];
int memo[N][N][N][N][2][3];
bool used[N][N][N][N][2][3];
 
int func(int kA,int kB,int sA,int sB,int turn,int pass,int sa,int sb){
  int z=sa-sb;
  if(pass==3)return z;
  if(used[kA][kB][sA][sB][turn][pass])return memo[kA][kB][sA][sB][turn][pass]+z;
  used[kA][kB][sA][sB][turn][pass]=true;
  int res=-INF;
  if(turn==1)res=INF;
  if(turn==0)res=max(res,func(kA,kB,kA,kB,!turn,pass+1,sa+A[kA-1]-A[sA-1],sb+B[kB-1]-B[sB-1])-z);
  else res=min(res,func(kA,kB,kA,kB,!turn,pass+1,sa+A[kA-1]-A[sA-1],sb+B[kB-1]-B[sB-1])-z);
  if(turn==0&&kA<=n){
    if(a[kA])res=max(res,func(kA+1,kB,sA,sB,!turn,0,sa,sb)-z);
    else res=max(res,func(kA+1,kB,sA,kB,!turn,0,sa,sb)-z);
  }
  if(turn==1&&kB<=m){
    if(b[kB])res=min(res,func(kA,kB+1,sA,sB,!turn,0,sa,sb)-z);
    else res=min(res,func(kA,kB+1,kA,sB,!turn,0,sa,sb)-z);
  }
  memo[kA][kB][sA][sB][turn][pass]=res;
  return res+z;
}
 
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(a[i]<0)a[i]=0;
    A[i]=A[i-1]+a[i];
  }
  for(int i=1;i<=m;i++){
    cin>>b[i];
    if(b[i]<0)b[i]=0;
    B[i]=B[i-1]+b[i];
  }
  cout<<func(1,1,1,1,0,0,0,0)<<endl;
  return 0;
}

Measured memory_bytes: 92360
#include <stdio.h>
int A[20];
int n;
int tmp;
void search( int, int );
int main(){
	int i;
	int q;
	int M[200];
	scanf("%d",&n);
	for( i=0; i<n; i++ ) scanf("%d", &A[i]);
	scanf("%d", &q);
	for( i=0; i<q; i++ ){
		scanf("%d", &M[i]);
		search(M[i],0);
		if( tmp == 1 ) printf("yes\n");
		else printf("no\n");
		tmp = 0;
	}
	return 0;
}
void search( int m, int i ){
	if( m == 0 ){
		tmp = 1;
		return;
	}
	else if ( n > i && m > 0){
		search( m-A[i], i+1 );
		search( m, i+1);
	}
}

Measured memory_bytes: 580
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N, M;
  int T[100], P[100], X[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if (j == P[i] - 1) sum += X[i];
      else sum += T[j];
    }
    cout << sum << endl;
  }
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, T;
  cin >> N >> T;
  ll ans = 0;
  vector<ll> t(N);
  REP(i, N) cin >> t[i];
  for(ll i = 0; i < N - 1; i++) {
    ll itvl = t[i + 1] - t[i];
    if(itvl < T) {
      ans += itvl;
    } else {
      ans += T;
    }
  }
  ans += T;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
<?php
  	fscanf(STDIN, '%d %d %d', $end, $min, $max);

	for($i = 1; $i <= $end; $i++){
      	$num = $i;
      	$digit_sum = 0;
      	while($num > 0){
          	$digit_sum += $num % 10;
          	$num = (int) $num / 10;
        }
      	if($digit_sum >= $min && $digit_sum <= $max){
          	$result += $i;
        }
    }
	echo $result;


Measured memory_bytes: 4604
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

int main(int argc, char *argv[])
{
  int N; cin >> N;
  vector<int> A(N);
  int prev = -1;
  int res = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a == prev) {
      prev = -1;
      res++;
    } else {
      prev = a;
    }
      
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long list[] = {0,0,0,0,0};
        for(int x=1;x<=n;x++) {
            String first = sc.next();
            String top = first.substring(0,1);
            if(top.equals("M")) {
                list[0] += 1;
            }
            if(top.equals("A")) {
                list[1] += 1;
            }
            if(top.equals("R")) {
                list[2] += 1;
            }
            if(top.equals("C")) {
                list[3] += 1;
            }
            if(top.equals("H")) {
                list[4] += 1;
            }
        }
        System.out.println(list[0]*list[1]*list[2]+list[0]*list[1]*list[3]+list[0]*list[1]*list[4]+list[0]*list[2]*list[3]+list[0]*list[2]*list[4]+list[0]*list[3]*list[4]+list[1]*list[2]*list[3]+list[1]*list[2]*list[4]+list[1]*list[3]*list[4]+list[2]*list[3]*list[4]);
    }
}


Measured memory_bytes: 44548
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const double PI=(acos(-1));

ll all(ll n){
    return 4*pow(2,n)-3;
}

ll pa(ll n){
    return all(n)/2+1;
}

ll f(ll n,ll x){
    if(n==1){
        if(x==1)return 0;
        else if(x==2)return 1;
        else if(x==3)return 2;
        else if(x==4)return 3;
        else if(x==5)return 3;
        else return 0;
    }else{
        if(x==1)return 0;
        else if(x>1&&x<=all(n-1)+1)return f(n-1,x-1);
        else if(x==2+all(n-1))return pa(n-1)+1; 
        else if(x>2+all(n-1)&&x<=2+2*all(n-1))return pa(n-1)+1+f(n-1,x-2-all(n-1));
        else if(x==3+2*all(n-1))return 2*pa(n-1)+1; 
        else return 0;
    }
}

int main(){
    ll n,x;
    cin>>n>>x;
    cout<<f(n,x)<<endl;
}

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

int main() {
  int n,a;
  cin >> n >> a;
  int c;
  c = n - (n/500)*500;
  if(c <= a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll H;
    cin >> N >> H;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    sort(b.rbegin(), b.rend());
    ll aMax = *max_element(a.begin(), a.end());
    ll ans = 0;
    // max(a[i])より大きいb[j]の刀を投げまくり
    for (int i = 0; 0 < H && i < N; i++) {
        if (aMax < b[i]) {
            H -= b[i];
            ans++;
        }
    }
    // 残ったHPはmax(a[i])を何回も振る
    if (0 < H) {
        ans += (H + aMax-1) / aMax;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 4828
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;
	int c[2] = { 0 };

	rep(i, 1, N + 1)
	{
		if (i%K == 0)
		{
			c[0]++;
		}
		if(i%K==K/2)
		{
			c[1]++;
		}
	}

	int ans = 0;
	ans += c[0] * c[0] * c[0];
	if (K % 2 == 0)
	{
		ans += c[1] * c[1] * c[1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b;
  	int mult;
  	cin >> a >> b;
  	mult = a * b;
    if(mult % 2 == 0){
      cout << "Even";
    }
  	else{
      cout << "Odd";
    }
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
s.reverse()
for i in range(6):
    s.append("x")
s = "".join(s)
i = 0
word = ["maerd", "esare", "resare","remaerd"]
while i<n:
    if s[i:i+5]==word[0]:
        i+=5
    elif s[i:i+5]==word[1]:
        i+=5
    elif s[i:i+6]==word[2]:
        i+=6
    elif s[i:i+7]==word[3]:
        i+=7
    else:
        print("NO")
        exit()
print("YES")
    

Measured memory_bytes: 3956
n=int(input())

c1=0
c2=0
c3=0
c4=0

for i in range(n):
  st=input()
  if st=="AC":
    c1+=1
  if st=="WA":
    c2+=1
  if st=="TLE":
    c3+=1
  if st=="RE":
    c4+=1

print("AC x " + str(c1))
print("WA x " + str(c2))
print("TLE x " + str(c3))
print("RE x " + str(c4))

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(C.begin(), C.end());

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int b = B[i];

    int a = lower_bound(A.begin(), A.end(), b) - A.begin();
    int c = C.end() - upper_bound(C.begin(), C.end(), b);
    
    ans += a*c;
  }

  cout << ans << endl;
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans;
		if (b % a == 0) {
			ans = a + b;
		} else {
			ans = b - a;
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    string S;
    int N;
    cin >> N >> S;
    int ans = 0;
    rep(i,N-2){
        if(S.substr(i,3) == "ABC") ans++;
    }
    out(ans);



    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    long H, W, D;
    readf("%d %d %d\n", &H, &W, &D);

    long[] x = new long[H*W];
    long[] y = new long[H*W];

    foreach (j; 0..H) {
        auto A = readln.split.to!(long[]);
        foreach (i; 0..W) {
            x[A[i]-1] = i;
            y[A[i]-1] = j;
        }
    }
    auto Q = readln.chomp.to!long;
    auto Ls = new long[Q];
    auto Rs = new long[Q];
    foreach (i; 0..Q) {
        long L, R;
        readf("%d %d\n", &L, &R);
        Ls[i] = L-1;
        Rs[i] = R-1;
    }
    long[] cost = new long[H*W];
    foreach (i; D..H*W) {
        cost[i] = abs(x[i] - x[i-D]) + abs(y[i] - y[i-D]);
    }
    foreach (i; 0..cost.length-D) {
        cost[i+D] += cost[i];
    }

    foreach (i; 0..Q) {
        auto L = Ls[i];
        auto R = Rs[i];

        writeln(cost[R] - cost[L]);
    }
}



Measured memory_bytes: 5884
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

ll mpow(ll x, ll n){
    if(n < 0)return 0;
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(){
   ll n;
   cin >> n;
   ll res = mpow(10, n) - mpow(9, n) - mpow(9, n) + mpow(8, n);
   res %= MOD;
   if(res < 0)res += MOD;
   cout << res << endl;
}


Measured memory_bytes: 3636
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i,j,ans=0;
    cin>>n;
    string s;
    for(i=1;i<=n;i++){
    s=to_string(i);
    if(s.length()%2) ans++;
    }
        cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3664
#include<string.h>
#include<stdio.h>
int main()
{
	int h,b,i,j;
	char r[5],a[5];
	while(1){
		scanf("%s %s",r,a);
		if(strcmp(r,"0")==0&&strcmp(a,"0")==0){
			break;
		}
		h=0;
		b=0;
		for(i=0;i<4;i++){
			if(r[i]==a[i]){
				h++;
				r[i]='r';
				a[i]='a';
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(r[i]==a[j]){
					b++;
					r[i]='r';
					a[j]='a';
				}
			}
		}
		printf("%d %d\n",h,b);
	}
	return 0;
}

Measured memory_bytes: 2668
import sys
for line in sys.stdin:
    a, b, c, d, e, f = map(float, line.split())
    print('{0:.3f} {1:.3f}'.format(
        (e * c - f * b) / (e * a - d * b) + 0, (d * c - f * a) / (d * b - e * a) + 0))

Measured memory_bytes: 7260
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[0] == 'a' || s[0] == 'i' || s[0] == 'u' || s[0] == 'e' || s[0] == 'o')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }
    return 0;
}

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

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

        if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
                cout << "YES" << endl;
        }
        else{
                cout << "NO" << endl;
        }
        return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


ll merge_cnt(vector<int> &A){
  int n = A.size();
  if (n <= 1) return 0;
  int n2 = n/2;
  vector<int> B(A.begin(), A.begin()+n/2);
  vector<int> C(A.begin()+n/2, A.end());
  ll res = merge_cnt(B) + merge_cnt(C);
  int bi,ci; bi = ci = 0;
  for (int i=0; i<n; i++){
    if (ci == n-n2 || (bi < n2 && B[bi] < C[ci])){
      A[i] = B[bi++]; res += ci;
    }else{
      A[i] = C[ci++];
    }
  }
  return res;
}

int main() {
  int N; cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  vector<int> Asort = A;
  sort(all(Asort));
  ll res = 0;
  rep(i, N){
    int i2 = lower_bound(all(Asort), A[i]) - Asort.begin();
    if (i%2 != i2%2) res++;
  }
  cout <<res/2 <<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

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

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

  if (isupper(s)) {
    cout<<'A';
  } else {
    cout<<'a';
  }
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  s += 'R';
  int b[n]={};
  vector<int> a;
  char c = s.at(0);
  int d = 1;
  for(int i=0;i<n;i++){
    if(s.at(i+1)==c) d++; 
    else{
      c = s.at(i+1);
      a.push_back(d);
      d = 1;
    }
  }
  int j=0;
  for(int i=0;i<a.size()-1;i+=2){
    int s = a[i]+a[i+1];
    if(s%2==0){
    b[a[i]-1+j]=s/2;
    b[a[i]+j]=s/2;
    }
    else{
      b[a[i]-1+j]=s/2+1-(a[i]-1)%2;
      b[a[i]+j]=s/2+(a[i]-1)%2;
    }
    j += s;
  }
  for(int i=0;i<n-1;i++) cout << b[i] << " ";
  cout << b[n-1] << endl;
}


Measured memory_bytes: 1528
// ABC177Aw.cpp

#include <iostream>
using namespace std;
int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    int tm = (d+s-1) / s;
    if (tm <= t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3124
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=1003;
const ll lmod = 1e9+7;

int N;
vector<int> adj[MAX_N];
ll dp[MAX_N];


int main(){
  string S;
  bool ans;
  cin >> S ;
  if(S.length()<4){
    cout << "No" << endl;
    return 0;
  }
  string ss = "YAKI";
  ans = true;
  rep(i,4){
    if(S[i]!=ss[i]){
      ans = false;
      break;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] a = Console.ReadLine().Split();
		int N = int.Parse(a[0]);
		long D = long.Parse(a[1]);
		int counter = 0;
		for (int i = 0; i < N; i++)
		{
			string[] b = Console.ReadLine().Split();
			long x = long.Parse(b[0]);
			long y = long.Parse(b[1]);
			long xy = (x * x) + (y * y);
			if ((D*D) >= xy) { counter++; }
		}
		Console.WriteLine(counter);
	}
}

Measured memory_bytes: 40580
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

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

    vector<int> a;
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.rbegin(), a.rend());
    int Alice = 0, Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            Alice += a[i];
        } else {
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep(i,n)    for(ll i=1; i<=n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed

    ll i,j,k,a=0,b=0,c=0;
    string s;
    cin>>s;
    for(i=0; s[i]; i++)
    {
        if(s[i]=='a')
            a++;
        else if(s[i]=='b')
            b++;
        else if(s[i]=='c')
            c++;

    }
    if(a&&b&&c)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;






    return 0;
}





Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <map>

using namespace std;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main(void) {
    int N, Q;
    cin >> N >> Q;
    vector<int> c(N+1);
    for(int i=1; i<=N; i++) {
        cin >> c[i];
    }
    vector< tuple<int,int,int> > v(Q);
    for(int j=0; j<Q; j++) {
        int l, r;
        cin >> l >> r;
        v[j] = make_tuple(r, l, j);
    }

    sort(v.begin(), v.end());

    vector<int> ans(Q);
    map<int,int> mp;
    BinaryIndexedTree<int> bit(N+1);

    int i = 1;
    for(auto [r, l, j]: v) {
        while(i <= r) {
            bit.add(mp[c[i]], -1);
            mp[c[i]] = i;
            bit.add(i, 1);
            ++i;
        }
        ans[j] = bit.sum(r) - bit.sum(l-1);
    }

    for(auto e: ans) {
        cout << e << endl;
    }
    return 0;
}


Measured memory_bytes: 38872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 2e5 + 667;
int a[N];
//bool visited[100001];
//vi v[100001];
//vi ans[100001];
//int d[10001];
//queue<int> q;
//int c = 0;

//void dfs(int x){
    //if(visited[x]){
        //c++;
      //  return;
    //}
   // visited[x] = true;
   // for(auto u : v[x]){
    //    dfs(u);
  //  }
//
//}

//void bfs(int x){
   // visited[x] = true;
    //d[x] = 0;
  //  q.push(x);
//    while(!q.empty()){
    //    int s = q.front(); q.pop();
  //      for(auto u : v[s]){
//            //if(visited[u]) continue;
          //  visited[s] = true;
        //    d[u] = d[s] + 1;
      //      q.push(u);
    //    }
  //  }
//}

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

    int n, k;
    ll ans = 0;
    cin >> n >> k;
    vi v;
    for(int i = 0;i<n;i++){
        int x;
        cin >> x;
        ans += x;
        v.pb(x);
    }
    int j = n-1;
    if(k >= n){
        cout << 0;
        return 0;
    }
    sort(v.begin(), v.end());
    for(int i = 0;i<k;i++){
        ans -= v[j];
        j--;
    }
    cout << ans;
    return 0;
}


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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    int odd_num = N / 2;
    if (N % 2 != 0) {odd_num++;}
    
    float ans = (float)odd_num / (float)N;
    std::cout << ans;
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    map<string, int> dict;
    rep(i, n) {
        string s;
        cin >> s;
        sort(all(s)); 
        ++dict[s];
    }

    llong ans = 0;
    stl_rep(itr, dict) {
        llong k = itr->second - 1LL;
        ans += k * (k + 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
#define MAX_N 105
#define MAX_K 100005
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll dp[MAX_N][MAX_K];
int N,K;
int a[MAX_N];

int main() {
    cin>>N>>K;
    rep(i,N){
        cin>>a[i];
    }
    rep(i,MAX_N){
        rep(j,MAX_K){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    rep(i,N){
        rep(j,K+1){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=MOD;
            int temp = min(K+1,j+a[i]+1);
            dp[i+1][temp]+= (MOD-dp[i][j]);
            dp[i+1][temp]%=MOD;
        }
        rep(j,K){
            dp[i+1][j+1]+=dp[i+1][j];
            dp[i+1][j+1]%=MOD;
        }
    }
    cout<<dp[N][K]<<endl;
}



Measured memory_bytes: 82304
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
int vis[MAX];
stack<int>st;
vector<int>adj[MAX];
void dfs(int s){
	vis[s]=1;
	for(int i=0;i<adj[s].size();i++){
		if(vis[adj[s][i]]!=1)
			dfs(adj[s][i]);
	}
	st.push(s);
}
int main(){
	memset(vis, 0, sizeof(vis));
	int n,m;
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	for(int i=0;i<n;i++){
		if(vis[i]==0)
			dfs(i);
	}
	while(!st.empty()){
		cout<<st.top()<<"\n";
		st.pop();
	}
//	cout<<"\n";

}


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

int main(){
  char S[4];
  int flag = 0;
  scanf("%s",S);
  for(int i = 0; i < 3; i ++){
    if(S[i] == S[i+1]){
      flag = 1;
    }
  }
  if(flag){
    printf("%s\n","Bad");
  }else{
    printf("%s\n","Good");
  }
  return 0;
}


Measured memory_bytes: 128
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	k := scanInt()
	a := scanInts(n)

	b := make([]int, 40)

	for i := 0; i < n; i++ {
		for j := 0; j < 40; j++ {
			if a[i]>>uint(j)&1 == 1 {
				b[j]++
			}
		}
	}

	ans := 0
	f := false
	for i := 39; i >= 0; i-- {
		num := 1 << uint(i)
		if !f {
			if k>>uint(i)&1 == 0 {
				ans += b[i] * num
			} else {
				if n-b[i] < b[i] {
					f = true
					ans += b[i] * num
				} else {
					ans += (n - b[i]) * num
				}
			}
		} else {
			ans += max(n-b[i], b[i]) * num
		}
	}
	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 3072
Option Strict On

Module Module1
    Const n As Int32 = 3
    Dim i As Int32
    Dim c(n - 1) As String

    Sub Main()
        For i = 0 To n - 1
            c(i) = Console.ReadLine()
        Next

        For i = 0 To n - 1
            Console.Write(c(i)(i))
        Next

        Console.WriteLine()
    End Sub

End Module

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

for i in a:
    if x[i-1]+1 in x or x[i-1] == 2019:
        pass
    else:
        x[i-1] += 1
for i in x:
    print(i)


Measured memory_bytes: 5608
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;

  cin >>a>>b>>c;
  int t;
  if(a>b){
    t=a;
    a=b;
    b=t;}
  if(b>c){
    t=b;
    b=c;
    c=t;}
  if(a>b){
    t=a;
    a=b;
    b=t;}
  cout<<a<<" " <<b<<" " <<c<<endl;  
  
  
  return 0;

}

Measured memory_bytes: 3068
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s,t = readline() |> chomp |> split
	a,b = readline() |> split |> parseMap
	u = readline() |> chomp
	if u==s
		a-=1
	else
		b-=1
	end
	println(a," ",b)
end

main()

Measured memory_bytes: 165928
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007
#define MOD2 1000000014000000049LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, int M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        inv[0] = 0;
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i+1] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a += fact.inv[i+1];
        if(a > MOD) a -= MOD;
        ans += a * d;
        if(ans > MOD2) ans -= MOD2;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, L;
    cin >> N >> L;
    vector<string> vec(N);
    REP(i, N) cin >> vec.at(i);
    
    // calculation
    sort(vec.begin(), vec.end());
    REP(i, N) {
        cout << vec[i];
    }
    cout << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
int n;
int p[100005],f[100005];
int main()
{
	p[1]=1;
	for (int i=2; i<=100000; i++)
    {
        for (int j=2*i; j<=100000; j+=i)
        p[j]=1;
    }
    for(int i=2;i<=100000;i++)
    {
		if(p[i]==0 && p[(i+1)/2]==0 && i!=2)
		{
			f[i]=f[i-1]+1;
		}
		else f[i]=f[i-1];
    }
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%d\n",f[y]-f[x-1]);

	}
	return 0;
}

Measured memory_bytes: 1408
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    long N = lread();
    auto A = aryread();
    long i;
    auto T = new long[](H * W);
    foreach (j, a; A)
    {
        foreach (_; 0 .. a)
            T[i++] = j + 1;
    }
    foreach (j; 0 .. H)
    {
        if (j & 1)
        {
            foreach_reverse (k; 1 .. W)
            {
                write(T[j * W + k], " ");
            }
            writeln(T[j * W]);
        }
        else
        {
            foreach (k; 0 .. W - 1)
            {
                write(T[j * W + k], " ");
            }
            writeln(T[(j + 1) * W - 1]);
        }
    }
}


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

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, M;
    cin >> N >> M;
    
    // 無限に遠いところの座標値
    int64_t INF = 2e9;
    
    // 座標圧縮前の座標（正負の無限遠を含む）を入れていく。
    vector<int64_t> xs = {-INF, INF}, ys = {-INF, INF};
    // 直線の端点について、それを挟む座標を入れる。
    auto add = [&](int64_t x, int64_t y){
        xs.push_back(x-1);
        xs.push_back(x);
        ys.push_back(y-1);
        ys.push_back(y);
    };

    vector<int64_t> A(N), B(N), C(N), D(M), E(M), F(M);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i] >> C[i];
        add(A[i], C[i]);
        add(B[i], C[i]);
    }
    for(int i=0; i<M; i++){
        cin >> D[i] >> E[i] >> F[i];
        add(D[i], E[i]);
        add(D[i], F[i]);
    }
    xs = compress(xs);
    ys = compress(ys);

    int xsz = xs.size(), ysz = ys.size();

    // リアル座標値が圧縮座標のどのインデックスに含まれるかを求める
    auto find_x = [&](int a)->int{ return lower_bound(xs.begin(), xs.end(), a) - xs.begin(); };
    auto find_y = [&](int a)->int{ return lower_bound(ys.begin(), ys.end(), a) - ys.begin(); };

    // 圧縮後の座標の、真上に線がある/真左に線がある
    static bitset<6100> above[6100], left[6100];

    // 線を引く
    for(int i=0; i<N; i++){
        A[i] = find_x(A[i]);
        B[i] = find_x(B[i]);
        C[i] = find_y(C[i]);
        for(int x=A[i]; x<B[i]; x++) left[x][C[i]] = 1;
    }
    for(int i=0; i<M; i++){
        D[i] = find_x(D[i]);
        E[i] = find_y(E[i]);
        F[i] = find_y(F[i]);
        for(int y=E[i]; y<F[i]; y++) above[D[i]][y] = 1;
    }

    // UnionFindで扱うために1次元に潰す
    auto encode = [&](int i, int j){ return i*ysz+j; };
    UnionFind uf(xsz*ysz);

    // 線が引いていないところを連結
    for(int i=1; i<xsz; i++) for(int j=0; j<ysz-1; j++){
        if(!above[i][j]) uf.unite(encode(i, j), encode(i-1, j));
        if(!left[i][j]) uf.unite(encode(i, j), encode(i, j-1));
    }

    // 牛と同じ連結成分にある座標について面積を足す。無限遠と連結ならINF
    auto fail = [](){
        cout << "INF" << endl;
        exit(0);
    };
    int cow = encode(find_x(0), find_y(0));
    int64_t ans = 0;
    for(int i=0; i<xsz; i++) for(int j=0; j<ysz; j++) if(uf.same(cow, encode(i, j))){
        if(i==0 || i==xsz-1 || j==0 || j==ysz-1) fail();
        int64_t dx = xs[i+1] - xs[i], dy = ys[j+1] - ys[j];
        ans += dx*dy;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 294256
#include <iostream>

using namespace std;

int main(void){
    int r, d, x[11];

    cin >> r >> d >> x[0];

    for(int i = 1;i < 11;i++){
        x[i] = x[i-1] * r -d;
        cout << x[i] << endl;
    }

    return 0;
}

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

const int MAXN = 1e5 + 7;

long long height = 0;
long long dp[MAXN];
long long h[MAXN];
int n;

long long rec(int idx)
{
    if (dp[idx] != -1)
        return dp[idx];
    if (idx == n - 1)
    {
        dp[idx] = 0;
        return dp[idx];
    }
    if (idx == n - 2)
    {
        dp[idx] = abs(h[idx + 1] - h[idx]);
        return dp[idx];
    }
    dp[idx] = min(rec(idx + 1) + abs(h[idx + 1] - h[idx]), rec(idx + 2) + abs(h[idx + 2] - h[idx]));
    return dp[idx];
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = 0; i < n; i++)
        dp[i] = -1;
    cout << rec(0) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

#define MAX (50000)

char prime[MAX + 1];

int main(void)
{
	int n, i, j, num;
	
	prime[0] = prime[1] = 0;
	for (i = 2; i <= MAX; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i <= MAX; i++){
		for (j = i * i; j <= MAX; j += i){
			prime[j] = 0;
		}
	}
	
	while (scanf("%d", &n), n != 0){
		i = 1;
		j = n - 1;
		num = 0;
		
		while (i <= j){
			if (prime[i] == 1 && prime[j] == 1 && n == i + j){
				num++;
				i++;
				j--;
			}
			else if (n < i + j){
				j--;
			}
			else {
				i++;
			}
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

Measured memory_bytes: 648
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> V, std::vector<long long> C){
    ll sum = 0;
    rep(i, N){
        if(V[i]-C[i]>0)
            sum += V[i]-C[i];
    }
    cout << sum << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> V(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&V[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(V), std::move(C));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int n;string s;
    cin>>n>>s;
    
    vector<ll> l(26,0);
    rep(i,n) l.at(s.at(i)-'a')++;
    ll ans=1;
    rep(i,26){
        ans*=(l.at(i)+1);
        ans%=1000000007;
    }
    cout<<ans-1<<endl;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> prices = new ArrayList<Integer>();
        for(int i=0; i < n; i++){
            prices.add(sc.nextInt());
        }

        Integer total = 0;
        for(int i = 0; i < k; i++){
            Integer min = prices.get(0);
            for(int j = 1; j < prices.size(); j++){
                if(min > prices.get(j)){
                    min = prices.get(j);
                }
            }
            total += min;
            prices.remove(min);
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 39160
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
//int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
//int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/
int a[100010],b[100010],c[100010];
bool cmp(int a,int b){return a>b;}
int main()
{
	int i,j,x,y,na=0,nb=0,nc=0,A,B,C,t;
	ll s=0;
	scanf("%d%d%d%d%d",&x,&y,&A,&B,&C);
	for(i=0;i<A;i++)scanf("%d",&a[i]);
	for(i=0;i<B;i++)scanf("%d",&b[i]);
	for(i=0;i<C;i++)scanf("%d",&c[i]);
	sort(a,a+A,cmp),sort(b,b+B,cmp),sort(c,c+C,cmp);
	int xy=x+y;
	while(na+nb+nc<xy)
	{
		if(na<x&&nb<y&&nc<C)
		{
			t=max(a[na],max(b[nb],c[nc]));
			s=s+t;
			if(t==a[na])na++;
			else if(t==b[nb])nb++;
			else nc++;
		}
		else if(na<x&&nb<y)//nc>=C
		{
			t=max(a[na],b[nb]);
			s=s+t;
			if(t==a[na])na++;
			else nb++;
		}
		else if(na<x&&nc<C)//nb>=B
		{
			t=max(a[na],c[nc]);
			s+=t;
			if(t==a[na])na++;
			else nc++;
		}
		else if(na<x)
		{
			s+=a[na];
			na++;
		}
		//na>=x 
		else if(nb<y&&nc<C)
		{
			t=max(b[nb],c[nc]);
			s+=t;
			if(t==b[nb])nb++;
			else nc++;
		}
		else if(nb<y)
		{
			s+=b[nb++];
		}
		else if(nc<C)
		{
			s+=c[nc++];
		}
		else break;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1536