akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
vector<ll> ans;
vector<ll> h;
int cnt=0;
int frog1(int N)
{
    cout<<cnt<<" "<<ans[N]<<endl;

  if(N<=0)return 0;
  if(N==1)return abs(h[1]-h[0]);
  if(ans[N]==-1)
  {
    ans[N] = min(abs(h[N]-h[N-1])+frog1(N-1),abs(h[N]-h[N-2])+frog1(N-2));
  }
  return ans[N];
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
  ll N;
  cin>>N;
  h.resize(N);
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  ans.resize(N);
  for(int i=0;i<N;i++){
    ans[i] = -1;
  }
  ans[0] = 0;
  ans[1] = abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    ans[i] = min(abs(h[i]-h[i-1])+ans[i-1],abs(h[i]-h[i-2])+ans[i-2]);
  }
  cout<<ans[N-1]<<endl;
  return 0;
  /*
  for(int i=0;i<1e5;i++){
    cout<<i+1<<endl;
  }*/
}


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

ans=[0]*N
#print(ans)

for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]<H[B-1]:
        ans[A-1]+=1
    elif H[B-1]<H[A-1]:
        ans[B-1]+=1
    else:
        ans[A-1]+=1
        ans[B-1]+=1
    #print(ans)
#print(ans)

print(ans.count(0))

Measured memory_bytes: 20024
N, M = map(int, input().split())
INF = 10**9
dic = [0]*(M+1)
bit = 0
for i in range(M):
  a, b = map(int, input().split())
  c = [int(x) for x in input().split()]
  j = 0
  s = 0
  for n in range(N):
    if n==c[j]-1:
      s += 2**n
      j += 1 if j<len(c)-1 else 0
    else:
      s += 0
  bit |= s
  dic[i+1] = (a,s)
if bit!=(1<<N)-1:
  print(-1)
else:
  dp = [INF]*(1<<N)
  dp[0] = 0
  for i in range(1,M+1):
    a, s = dic[i]
    for j in range(1<<N):
      dp[j|s] = min(dp[j]+a, dp[j|s])
  print(dp[-1])

Measured memory_bytes: 47064
#include <stdio.h>
#include <stdlib.h>

int house_x[100000];
int house_y[100000];
int house_sort[100000];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main(void) {
	int W,H;
	int N;
	int i;
	int center;
	long long bestkyori;
	long long nowkyori;
	long long kyorisum;
	long long longest;
	int center_x_list[2],center_y_list[2];
	int center_x,center_y;
	int best_x,best_y;
	scanf("%d %d",&W,&H);
	scanf("%d",&N);
	for(i=0;i<N;i++) {
		scanf("%d %d",&house_x[i],&house_y[i]);
	}
	for(i=0;i<N;i++) {
		house_sort[i]=house_x[i];
	}
	qsort(house_sort,N,sizeof(int),qsort_comp);
	if(N%2==0) {
		center_x_list[0]=house_sort[N/2-1];
		center_x_list[1]=house_sort[N/2];
	} else {
		center_x_list[0]=center_x_list[1]=house_sort[N/2];
	}
	center_x=house_sort[(N%2==0)?(N/2-1):(N/2)];
	for(i=0;i<N;i++) {
		house_sort[i]=house_y[i];
	}
	qsort(house_sort,N,sizeof(int),qsort_comp);
	if(N%2==0) {
		center_y_list[0]=house_sort[N/2-1];
		center_y_list[1]=house_sort[N/2];
	} else {
		center_y_list[0]=center_y_list[1]=house_sort[N/2];
	}
	bestkyori=0x7fffffffffffffffLL;
	for(center=0;center<4;center++) {
		center_x=center_x_list[center/2];
		center_y=center_y_list[center%2];
		kyorisum=0;
		longest=0;
		for(i=0;i<N;i++) {
			nowkyori=abs(house_x[i]-center_x)+abs(house_y[i]-center_y);
			kyorisum+=nowkyori*2LL;
			if(nowkyori>longest)longest=nowkyori;
		}
		kyorisum-=longest;
		if(kyorisum<bestkyori) {
			bestkyori=kyorisum;
			best_x=center_x;
			best_y=center_y;
		}
	}
	printf("%lld\n",bestkyori);
	printf("%d %d\n",best_x,best_y);
	return 0;
}

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

using namespace std;

struct UnionFind { /* {{{ */
  vector<int> par;

  UnionFind(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  void unite(int x, int y) { par[root(x)] = root(y); }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
}; /* }}} */

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }
  set<int> s;
  for (int i = 0; i < N; i++) {
    s.insert(uf.root(i));
  }
  cout << s.size() << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 5376
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){function n(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var n=[],t=!0,o=!1,u=void 0;try{for(var i,l=e[Symbol.iterator]();!(t=(i=l.next()).done)&&(n.push(i.value),!r||n.length!==r);t=!0);}catch(e){o=!0,u=e}finally{try{t||null==l.return||l.return()}finally{if(o)throw u}}return n}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){for(var r=e.split("\n"),t=n(r[0].split(" ").map(function(e){return Number(e)}),5),o=t[0],u=t[1],i=t[2],l=t[3],f=t[4],c=r[1].split(""),a=u-1;a<f;a++)if("#"==c[a-1]&&"#"==c[a])return void console.log("No");if(!(l<f)){for(var s=0,d=i-2;d<0;)d+=1;for(var p=d;p<f;p++)if("."==c[p]){if(3==(s+=1))return void console.log("Yes")}else s=0;return f-2>=0&&f-2<o&&"#"==c[f-2]||f>=0&&f<o&&"#"==c[f]?void console.log("No"):void console.log("Yes")}console.log("Yes")}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 9420
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


n,k=map(int,input().split())
h=list(map(int,input().split()))
for hi in h:
    if hi>=k:
        count+=1
print(count)

Measured memory_bytes: 55152
using System;
using System.Linq;

namespace CF2017qA
{
    class B
    {
        static void Main(string[] args)
        {
            //input
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];
            int K = input[2];

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= M; j++)
                {
                    if (i * (M - j) + j * (N - i) == K) { Console.WriteLine("Yes"); return; }
                }
            }
            Console.WriteLine("No");
        }
    }
}


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

int n, k;
vector<int> G[2000];
int a[2000], b[2000];

int d[2000];
const int inf = 1e9 + 9;

int main()
{
  cin >> n >> k;

  for (int i = 0; i < n - 1; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }


  int ans = inf;
  if (k & 1){
    for (int i = 0; i < n - 1; i++){
      fill(d, d + 2000, inf);
      queue<int> q;
      q.push(a[i]);
      q.push(b[i]);
      d[a[i]] = d[b[i]] = 0;

      while (!q.empty()){
        int v = q.front(); q.pop();
        for (int j = 0; j < G[v].size(); j++){
          int t = G[v][j];
          if (d[t] == inf){
            d[t] = d[v] + 1;
            q.push(t);
          }
        }
      }

      int cnt = 0;
      for (int j = 0; j < n; j++){
        if (d[j] > k / 2) cnt++;
      }

      ans = min(ans, cnt);
    }
  }
  else {
    for (int i = 0; i < n; i++){
      queue<int> q;
      q.push(i);
      fill(d, d + 2000, inf);
      d[i] = 0;

      while (!q.empty()){
        int v = q.front(); q.pop();
        for (int j = 0; j < G[v].size(); j++){
          int t = G[v][j];
          if (d[t] == inf){
            d[t] = d[v] + 1;
            q.push(t);
          }
        }
      }

      int cnt = 0;
      for (int j = 0; j < n; j++){
        if (d[j] > k / 2) cnt++;
      }

      ans = min(ans, cnt);
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;


int main() {

	int n;
	cin >> n;

	vector <int> a(n);

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

	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;

	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    int A[N], B[N], C[N];
    FOR(i, 0, N) {
        cin >> A[i];
        A[i]--;
    }
    FOR(i, 0, N)
    cin >> B[i];
    FOR(i, 0, N - 1)
    cin >> C[i];
    int ans = B[A[0]];
    FOR(i, 1, N) {
        ans += B[A[i]];
        if (A[i - 1] + 1 == A[i]) {
            ans += C[A[i - 1]];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,start,end) for(int i=start;i<=end;i++)
#define ll long long

using namespace std;

int main(void){
    ll n; cin >> n;
  ll ans=0;
    vector<ll> e(n+1,0);
    
    FOR(i,1,n){
        for(int j=i;j<=n;j+=i){
            e[j]++;
        }
    }
    FOR(i,1,n) ans+=i*e[i];

    cout << ans << endl;
}


Measured memory_bytes: 81380
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
 
typedef pair<int, int> P;
 
#define MAX_N (100010)
 
int n;
 
vector<P> G[MAX_N];
bool arrived[MAX_N];
 
int main()
{
    scanf("%d", &n);
 
    for ( int i = 0; i < n - 1; i++ ) {
    int s, t, w;
     
    scanf("%d %d %d", &s, &t, &w);
 
    G[s].push_back( make_pair( t, w ) );
    G[t].push_back( make_pair( s, w ) );
    }
 
    // for ( int i = 0; i < n; i++ ) {
    //  for ( int j = 0; j < G[i].size(); j++ ) {
    //      printf("%d to %d: %d\n", i, G[i][j].first, G[i][j].second);
    //  }
    // }
 
    int u, v;
    queue<P> Q;
    int max_dist = -1;
    memset( arrived, false, n + 1 );
    arrived[0] = true;
 
    Q.push( make_pair( 0, 0 ) );
 
    while ( !Q.empty() ) {
 
    P p = Q.front(); Q.pop();
    int cur = p.first;
    int sum_dist = p.second;
 
    if ( max_dist < sum_dist ) {
        max_dist = sum_dist;
        u = cur;
    }
 
 
    for ( int i = 0; i < G[cur].size(); i++ ) {
        int next = G[cur][i].first;
        int dist = G[cur][i].second;
 
 
        if ( !arrived[next] ) {
        arrived[next] = true;
        Q.push( make_pair( next, sum_dist + dist ) );
        }
    }
    }
 
    memset( arrived, false, n + 1 );
 
    max_dist = -1;
    arrived[u] = true;
    Q.push( make_pair( u, 0 ) );
 
    while ( !Q.empty() ) {
    P p = Q.front(); Q.pop();
    int cur = p.first;
    int sum_dist = p.second;
 
    if ( max_dist < sum_dist ) {
        max_dist = sum_dist;
        v = cur;
    }
 
    for ( int i = 0; i < G[cur].size(); i++ ) {
        int next = G[cur][i].first;
        int dist = G[cur][i].second;
         
        if ( !arrived[next] ) {
        arrived[next] = true;
        Q.push( make_pair( next, sum_dist + dist ) );
        }
    }
    }
 
    printf("%d\n", max_dist);
 
    return 0;
}

Measured memory_bytes: 9172
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#include <cmath>


using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();

  int sum[2] = { };
  int t = 0;

  vector<int> ans(n);

  int l = 0;
  int r = n;

  for (int i = 0; i < n; i++) {
    sum[t]++;
    t = 1 - t;

    if (s[i - 1] == 'R' && s[i] == 'L') {
      int r = i + 1;
      t = 1;
      while (s[r] == 'L') {
        sum[t]++;
        r++;
        t = 1 - t;
      }

      t = 0;
      if ((r - l) % 2 == 0) {
        ans[i - 1] = sum[t];
        ans[i] = sum[1 - t];
      } else {
        ans[i - 1] = sum[1 - t];
        ans[i] = sum[t];
      }

      i = r - 1;
      t = 0;
      sum[0] = sum[1] = 0;
      l = r;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << " \n"[i == n -1];
  }

  return 0;
}


Measured memory_bytes: 1024
#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 rep_bit(n) for (int bit = 0; bit < (1<<n); ++bit)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ll long long
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
using namespace std;
typedef vector<vector<int> > Graph;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//条件式 ? 真の場合の文 : 偽の場合の文 
//abs(x) = (x の絶対値)
//string S  S[i],S += T,S += c,S.size(),S.substr(l),S.substr(l, r)
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//swap(a, b)
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1;
//find(all(x), key)boolソート済みのベクトル
//lower_bound(all(x),k)以上,uppper_bound(all(x),k)より大きい
int main(){

    int N;
    cin >> N;
    vl vec;
    rep(i,N){
        ll a;
        cin >> a;
        vec.pb(a);
    }
    sort(all(vec));
    ll ans = 0;
    ans = vec.at(N/2)-vec.at(N/2-1);

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


Measured memory_bytes: 1400
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        int[] a = new int[3];

        for(int i = 0;i < 3;i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);


        System.out.println(a[2] -  a[0]);


    }
}

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

int main() {
	int64_t N, A, count = 0, sum = 0;
	map <int64_t, int64_t> mp;
	cin >> N;
	mp[0] = 1;
	for (int i = 0; i < N; i++) {
		cin >> A;
		count += A;
		mp[count]++;
	}
	map<int64_t, int64_t>::iterator it;
	for (it = mp.begin(); it != mp.end(); it++) {
		int64_t x = it->second;
		sum += x * (x - 1) / 2;
	}
	cout << sum << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<char>C(N);
  for(int i = 0 ; i < N ; i++){
    cin >> C.at(i);
  }
  for(int i = 0;i < N ; i++){
    if( C.at(i) == 'Y'){
      cout << "Four" <<endl;
      break;
    }
    
    
    if (i == N-1 && C.at(N-1) != 'Y'){
      cout << "Three" <<endl;
    }
    
  }
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#define ll long long 
#define pb push_back
#define INF (ll)1e18
#define IINF (int)1e9 
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
#define MOD 1000000000 + 7
#define F first 
#define S second
#define sp << " " << 
/*rrrohan*/ 
using namespace std; 
 
/*less than or equal to -> l + r + 1*/
 
/*class dsu{
private: 
	vector <int> r,p; 
public: 
	dsu(int n){
		p.resize(n+1);
		r.resize(n+1);  
		for(int i = 0; i < n+1; i++){
			p[i] = i; 
			r[i] = 0; 
		}
	}
	int findset(int i){
		return (p[i] == i) ? i : (p[i] = findset(p[i])); 
	}
	bool issameset(int a, int b){
		return findset(a) == findset(b); 
	}
	void unionset(int i, int j){
		if(!issameset(i,j)){
			int x = findset(i), y = findset(j); 
			if(r[x] > r[y]){
				p[y]  = x; 
			}else{
				p[x] = y; 
				if(r[x] == r[y]){
					r[y]++; 
				}
			}
		}
	}
};
*/ 


int main(){
	int a,b,t; 
	cin >> a >> b >> t; 
	t = t + 0.5; 
	cout << (t/a)*b; 
}

Measured memory_bytes: 256
import numpy as np
import re

mod = 10**9 + 7
letters = "ACGT"

def to_int(s):
    res = 0
    for x in s:
        res <<= 2
        res += letters.index(x)
    return res

def to_str(x, digit):
    res = ""
    for _ in range(digit):
        res += letters[x&3]
        x >>= 2
    return res[::-1]

def is_ok(s):
    ng = [r"AGC", r"ACG", r"GAC", r"A.GC", r"AG.C"]
    for x in ng:
        if re.search(x, s):
            return False
    return True

A = [[0]*64 for _ in range(64)]
for i in range(64):
    s = to_str(i, 3)
    for j in range(4):
        t = s + to_str(j, 1)
        if is_ok(t):
            A[i][to_int(t[1:])] = 1

A = np.array(A, dtype = "object")

def mat_power(A, p, mod):
    res = np.eye(A.shape[0], dtype = "object")
    while p:
        if p & 1:
            res = np.dot(res, A) % mod
        A = np.dot(A, A) % mod
        p >>= 1
    return res

x = [0]*64
x[63] = 1
x = np.array(x)

N = int(input())
print((np.dot(mat_power(A, N, mod), x) % mod).sum() % mod)
# y = np.dot(mat_power(A, N, mod), x) % mod
# for i in range(64):
#   print(to_str(i, 3) + ":", y[i])

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

int main(){
    int n;
    cin >> n;
    string s[n];

    int count_ab = 0;
    size_t x;
    char pre;
    int count_head_o_tail_a = 0;
    int count_head_b_tail_o = 0;
    int count_head_b_tail_a = 0;

    for (int i=0; i<n; i++){
        cin >> s[i];
        x = s[i].length();
        pre = 'o';
        for (int y=0; y<x; y++){
            if(y==x-1){
                if(s[i][0]=='B' && s[i][y]=='A'){
                    count_head_b_tail_a+=1;
                }else if(s[i][0]=='B' && s[i][y]!='A'){
                    count_head_b_tail_o+=1;
                }else if(s[i][0]!='B' && s[i][y]=='A'){
                    count_head_o_tail_a+=1;
                }
                continue;
            }
            if (s[i][y]=='B' && pre=='A'){
                count_ab+=1;
//                cout << "XXX";
            }
            pre = s[i][y];
//            cout << pre << endl;
        }
    }

//    cout << "innner_ab oa bo ba" << endl;
//    cout << count_ab << " " << count_head_o_tail_a << " " << count_head_b_tail_o << " " << count_head_b_tail_a << endl;


    if (count_head_b_tail_a>=1){
        count_ab+=count_head_b_tail_a-1;
//        cout << "+BA " << count_ab << endl;
    
        if (count_head_o_tail_a>=1){
            count_ab+=1;
            count_head_o_tail_a-=1;
        }
//        cout << "+OA " << count_ab << endl;
    
        if (count_head_b_tail_o>=1){
            count_ab+=1;
            count_head_b_tail_o-=1;
        }
//        cout << "+BO " << count_ab << endl;
    }
    count_ab+=min({count_head_b_tail_o, count_head_o_tail_a});
    cout << count_ab << endl;
}


Measured memory_bytes: 768
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int m1, d1; cin>>m1>>d1;
    int m2, d2; cin>>m2>>d2;

    cout << (d2 == 1) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC095B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var X = ReadInt;

            int[] m = new int[N];
            for (int i = 0; i < N; i++)
            {
                int a = ReadInt;
                X -= a;
                m[i] = a;
            }

            int min = m.Min();

            int ans = N + X / min;
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
int l[2001];
int main(){
    cin>>n;
    rep(i,n) cin>>l[i];
    sort(l,l+n);
    int tl,tr;
    ll ans=0;
    rep(i,n)FOR(j,i+1,n){
        tl=j+1;
        if(tl==n) continue;
        tr=lower_bound(l,l+n,l[i]+l[j])-l;
        ans+=max(0,tr-1-tl+1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct P
{
    int x,y;
    bool operator<(const P &a)const{
        //if(y!=a.y) return y>a.y;
        return max(x,-x)>max(a.x,-a.x);

    }

};
vector<int> v;
//bitset<4001000> b;
int i,n,d,m,k,a,b,c,e;
int o[1111];
int l[1111];
int j[1];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s,s1;

//priority_queue<int,vector<int>,greater<int> > q;
//queue<int> q;
string r;
//char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> p;//safe_map;
*/
bool as(P a,P b)
{
    if(a.y!=b.y)
    return a.y>b.y;
    return a.x>b.x;
}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    for(int t=a;t>=1;t--)
    {
        for(int h=t;h>=0;h--)
        if(h==0)
        {
            puts("-1");
            return 0;
        }
        else if(h==o[h])
        {
            s.push(h);
            for(int w=h;w<t;w++)
                o[w]=o[w+1];
            break;
        }
    }
    for(;s.size();s.pop())
        printf("%d\n",s.top());

}




Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int n;
struct guy
{
  int m;
  ll l;
};
guy g[105];
ll dp[105][(1<<16)+5];
ll rec(int x,int y)
{
  if(dp[x][y]>=0) return dp[x][y];
  if(x==n) return 0;
  ll ret=0;
  if((g[x].m & y)==0)
    {
      ret=max(rec(x+1,y),rec(x+1,y|g[x].m)+g[x].l);
    }
  else ret=rec(x+1,y);
  return dp[x][y]=ret;
}

int main(int argc,char const* argv[])
{
  while(1)
    {
      cin >> n;
      if(!n) break;
      for(int i=0;i<n;i++)
	{
	  int p;
	  cin >> p >> g[i].l;
	  g[i].m=0;
	  for(int j=0;j<p;j++)
	    {
	      int s,e;
	      cin >> s >> e;
	      for(int k=s;k<e;k++) g[i].m+=(1<<(k-6));
	    }
	}
      memset(dp,-1,sizeof(dp));
      cout << rec(0,0) << endl;
    }
  return 0;
}
	  



Measured memory_bytes: 56864
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

int main(){
  double a,b;
  cin >> a >> b;
  double a1,a2,b1,b2;
  a1 = a*100/8.0;
  a2 = (a+1)*100/8.0;
  b1 = b*100/10.0;
  b2 = (b+1)*100/10.0;

  for(int answer= 1;answer <= 100000; answer++){
    if((answer >=a1 && answer < a2)&&(answer >=b1 && answer < b2)){
      cout << answer << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main(){
  int N, M; cin >> N >> M;
  int MOD = 1000000007;
  int S[N];
  int T[M];
  int dp[N+1][M+1] = {};
  rep(i, N){
    cin >> S[i];
    dp[i+1][0] = 1;
  }
  rep(i, M){
    cin >> T[i];
    dp[0][i+1] = 1;
  }
  dp[0][0] = 1;
  rep (i, N){
    rep(j, M){
      dp[i+1][j+1] += (dp[i+1][j] + dp[i][j+1])%MOD;
      dp[i+1][j+1] -= dp[i][j];
      dp[i+1][j+1] %= MOD;
      if (S[i] == T[j]){
        dp[i+1][j+1] += dp[i][j];
      }
      dp[i+1][j+1] %= MOD;
    }
  }
  if (dp[N][M] < 0){
    dp[N][M] += MOD;
  }
  cout << dp[N][M] << endl;
}
  

Measured memory_bytes: 15872
S = input()
count1 = 0
count2 = 0
for i in range(0,len(S),2):
  if S[i] == '0':
    count1 += 1
  else:
    count2 += 1
for j in range(1,len(S),2):
  if S[j] == '1':
    count1 += 1
  else:
    count2 += 1
print(min(count1,count2))

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

static const int INF=1e9;

int main(){
    int H,W; cin >> H >> W;
    int h[H][W]={};
    int w[H][W]={};
    char g[H][W];
    for(int i=0;i<H;i++){
        string s; cin >> s;
        for(int j=0;j<W;j++){
            g[i][j]=s[j];
        }
    }
    for(int i=0;i<H;i++){
        int cnt=1;
        for(int j=0;j<W;j++){
            if(g[i][j]=='#') cnt=1;
            else{
                w[i][j]=cnt;
                cnt++;
            }
        }
        for(int j=W-1;j>=1;j--){
            if(g[i][j]=='#'||g[i][j-1]=='#') continue;
            if(w[i][j]>=w[i][j-1]){
                w[i][j-1]=w[i][j];
            }
        }
    }
    /*
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << w[i][j] << " ";
        }
        cout << endl;
    }
    */
    for(int i=0;i<W;i++){
        int cnt=1;
        for(int j=0;j<H;j++){
            if(g[j][i]=='#') cnt=1;
            else{
                h[j][i]=cnt;
                cnt++;
            }
        }
        for(int j=H-1;j>=1;j--){
            if(g[j][i]=='#'||g[j-1][i]=='#') continue;
            if(h[j][i]>=h[j-1][i]){
                h[j-1][i]=h[j][i];
            }
        }
    }
    /*
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << h[i][j] << " ";
        }
        cout << endl;
    }
    */
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ans=max(ans,h[i][j]+w[i][j]-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    ll X, K, D; cin >> X >> K >> D;
    if(abs(X)/D>K){
        cout << abs(X)-D*K << endl;
    }else{
        if((K-abs(X)/D)%2==0) cout << abs(X)%D << endl;
        else cout << D-abs(X)%D << endl;
    }
}

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

int main(){
  int i,j,cnt=0;
  int n;
  string s;
  cin>>n;
  cin>>s;
  int a[n];
  a[0]=0;
  for(i=1;i<n;i++){
    if(s[i]=='E')a[0]++;
  }
  for(i=1;i<n;i++){
    if((s[i-1]=='E' && s[i]=='W') || (s[i-1]=='W' && s[i]=='E'))a[i]=a[i-1];
    else if(s[i-1]=='E' && s[i]=='E')a[i]=a[i-1]-1;
    else a[i]=a[i-1]+1;
  }
  int mi=INT_MAX;
  for(i=0;i<n;i++)mi=min(a[i],mi);
  cout<<mi<<endl;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}



int main(){FIN
    ll n; cin>>n;
    ll ans = 0;
    FOR(i,1,n){
        ll base = i;
        ll sub = i;
        while(base<=n){
            ans += base;
            base += sub;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	ll ans = 0;
	rep(i,0,n){
		ll a;
		cin>>a;
		ans += max(0LL,v[i]-a);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void *a, const void *b)
{
    if (*(intmax_t *)a < *(intmax_t *)b)
        return -1;
    if (*(intmax_t *)a > *(intmax_t *)b)
        return 1;
    return 0;
}

int main(void)
{
    intmax_t N, A[200000];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
    }

    qsort(A, N, sizeof(A[0]), compare);

    for (size_t i = 1; i < N; i++) {
        if (A[i] == A[i - 1]) {
            puts("NO");
            return 0;
        }
    }

    puts("YES");

    return 0;
}


Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
#define per 1000000007
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)<=1){
        if(n<m){
            swap(n,m);
        }
        int a=1;
        for(int i=2;i<=m;++i){
            a=(long long)a*i%per;
        }
        a=(long long)a*(n==m?a*2:(long long)a*n%per)%per;
        cout<<a<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

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

ans = (A*10+B) + C

tmp = (A*10+C) + B
if tmp > ans:
    ans = tmp

tmp = (B*10+A) + C
if tmp > ans:
    ans = tmp

tmp = (B*10+C) + A
if tmp > ans:
    ans = tmp

tmp = (C*10+B) + A
if tmp > ans:
    ans = tmp

tmp = (C*10+A) + B
if tmp > ans:
    ans = tmp

print(ans)


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

vector<int> input(int N) {
  vector<int> res(N);
  for (int i = 0; i < N; i++)cin >> res[i];
  return res;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    h = input(N);
    vector<int> dp(N, 0);
    for(int i = 0; i < min(N, K); i++)dp[i] = abs(h[i] - h[0]);
    for(int i = K; i < N; i++){
        dp[i] = dp[i - K] + abs(h[i] - h[i - K]);
        for(int j = K; j > 0; j--)dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
N,X=(int(x) for x in  input().split())
D=0
L=(int(x) for x in  input().split())
flag=True
for j,i in enumerate(L):
    D+=i
    if D>X:
        flag=False
        break
  
  
if flag:
    print(N+1)
else:
    print(j+1)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  char S[N][N];
  for(int i = 0; i < N; i++){
    scanf(" %s ", S[i]);
  }
  
  int num = 0;
  for(int k = 0; k < N; k++){
    int symmetry = 1;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(S[(i + k) % N][j] != S[(j + k) % N][i]){
          symmetry = 0;
        }
      }
    }
    
    if(symmetry) num += N;
  }
  
  printf("%d\n", num);
  
  return 0;
}

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

int main() {
	int n,a,b;
	unsigned long long x[200001],y[200001];
	for (int i = 0;i < 200001;i++) { x[i] = 0; y[i] = 0; }
	cin >> n;
	for (int i = 0;i < n;i++) cin >> x[i];
	for (int i = 0;i < n;i++) y[i] = x[i];
	sort(x, x + n); //yが元の配列、xが昇順ソート後
	a = (n / 2) - 1; b = n / 2;
	for (int i = 0;i < n;i++)
	{
		if (y[i] <= x[a]) cout << x[b] << endl;
		else cout << x[a] << endl;
	}

	return 0;

}

Measured memory_bytes: 5376
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var H = sc.ReadInt();
        var W = sc.ReadInt();
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var B = new List<int>();
        for (int i = 0; i < N; i++)
        {
            var a = A[i];
            for (int j = 0; j < a; j++)
            {
                B.Add(i + 1);
            }
        }
        var ix = 0;
        var C = new int[H, W];
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                var index = i * W + j;
                C[i, j] = B[index];
            }
        }

        for (int i = 0; i < H; i++)
        {
            var x = new int[W];
            for (int j = 0; j < W; j++)
            {
                x[j] = C[i, j];
            }
            if (i % 2 == 1)
            {
                x = x.Reverse().ToArray();
            }
            var s = string.Join(" ", x);
            Console.WriteLine(s);
        }
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}

int main() {
  LL n, T;
  cin >> n >> T;
  VEC<LL> t(n);
  REP(i, 0, n) cin >> t[i];
  LL last = t[0];
  LL sum = 0;
  REP(i, 1, n) {
    sum += min(T,t[i] - last);
    last = t[i];
    //DUMP(i, last, sum);
  }
  sum += T;
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=5000+5;
const ll oo=1e18+5;
const ll mod=998244353;
 
int n;
int dp[2005][2005];
 
void max_self(int& a,int b){
	if(b>a) a=b;
}
 
void update(int i,int j,int val){
	max_self(dp[i][j],val);
	max_self(dp[j][i],val);
	max_self(dp[i][n],val);
	max_self(dp[n][i],val);
	max_self(dp[j][n],val);
	max_self(dp[n][j],val);
	max_self(dp[n][n],val);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	int n3=n*3;
	vector<int> a(n3);
	for(int& x:a) cin>>x,--x;
	int m=n+1;
	for(int i=0;i<m;++i){
		for(int j=0;j<m;++j) dp[i][j]=-INF;
	}
	update(a[0],a[1],0);
	int add=0;
	for(int i=2;i<n3-1;i+=3){
		int x=a[i],y=a[i+1],z=a[i+2];
		if(x==y&&y==z){
			++add;
			continue;
		}
		vector<tuple<int,int,int>> vec;
		for(int times=0;times<3;++times){
			{
				for(int aa=0;aa<m;++aa){
					int now=dp[aa][n];
					if(y==z){
						max_self(now,dp[aa][y]+1);
					}
					vec.emplace_back(aa,x,now);
				}
			}
			{
				int now=max(dp[n][n],dp[z][z]+1);
				vec.emplace_back(x,y,now);
			}
			swap(x,y);
			swap(y,z);
		}
		for(tuple<int,int,int> x:vec){
			int i,j,val;
			tie(i,j,val)=x;
			update(i,j,val);
		}
	}
	int ans=dp[n][n];
	int l=a[n3-1];
	max_self(ans,dp[l][l]+1);
	ans+=add;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 19428
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N, K;
char S[100100];

int main()
{
	scanf ("%d %d", &N, &K);
	scanf ("%s", S);

	int h = 0;
	for (int i = 0; S[i]; i++){
		if (S[i] == 'L'){
			if (i == 0 || S[i - 1] == 'R');
			else h++;
		}
		else{
			if (S[i + 1] == 'R') h++;
		}
	}

	h += 2 * K;
	if (h >= N) h = N - 1;
	printf ("%d\n", h);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){//up->1,down->2,flat->3
	int n,a[100000],ans[5];
	memset(ans,0,sizeof(ans));
	vector<int> data;
	cin>>n;
	if(n>=2)cin>>a[0]>>a[1];
	if(a[0]>a[1])data.push_back(2);
	else if(a[0]<a[1])data.push_back(1);
	else data.push_back(3);
	for(int i=2;i<n;i++){
		cin>>a[i];
		int state;
		if(a[i]>a[i-1])state=1;
		else if(a[i]<a[i-1])state=2;
		else state=3;
		if(data[data.size()-1]!=state)data.push_back(state);
	}
/*	for(int i=0;i<data.size();i++){
		cout<<data[i]<<" ";
	}cout<<endl;*/
	data.push_back(1000);
	for(int i=0;i<data.size();i++){
		if(data[i]==1){
			if(data[i+1]==2){
				ans[3]++;
			}else{
				if(data[i+2]==1)ans[2]++;
				else if(data[i+2]==2)ans[0]++;
			}
		}else if(data[i]==2){
			if(data[i+1]==1)ans[4]++;
			else{
				if(data[i+2]==1)ans[1]++;
				else if(data[i+2]==2)ans[2]++;
			}
		}
	}
	for(int i=0;i<4;i++){
		cout<<ans[i]<<" ";
	}cout<<ans[4]<<endl;
}


Measured memory_bytes: 2128
n,k=map(int,input().split())
al=[0]+list(map(int,input().split()))

visited=[-1]*(n+1)
visited[1]=0

lstart=0
t=0

now=1
while lstart==0:
    if visited[al[now]]<0:
        visited[al[now]]=visited[now]+1
        now=al[now]
        
    else:
        t=visited[now]-visited[al[now]]+1
        lstart=al[now]

if visited[lstart]>=k:
    print(visited.index(k))
            
else:
    print(visited.index(visited[lstart]+(k-visited[lstart])%t))

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

using namespace std;

#define ll long long

ll gcd(ll a, ll b) { // a,bの最大公約数
	if (a < b) { // a >= bに
		ll t = b;
		b = a;
		a = t;
	}
	if (b == 0) return a;
	if (b == 1) return 1;
	return gcd(a - b, b);
}

ll lcm(ll a, ll b) { // a,bの最小公倍数
	ll g = gcd(a, b);
	return a * b / g;
}

signed main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	a--;
	ll under_b = b - (b / c) - (b / d) + (b / lcm(c, d));
	ll under_a = a - (a / c) - (a / d) + (a / lcm(c, d));
	cout << (under_b - under_a) << endl;
}

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

int n;

void dfs(string s, char mx) {
    if (s.length() == n) {
        cout << s << endl;
    } else {
        for (char c = 'a'; c <= (mx + 1 > 'z' ? 'z' : mx + 1); c++)
            dfs(s + c, c > mx ? mx + 1 : mx);
    }
}

int main() {
    cin >> n;
    dfs("a", 'a');
    return 0;
}


Measured memory_bytes: 1536