akhauriyash/Code-Regression huggingface dataset:
s_orig = gets.chomp
t_orig = gets.chomp
 
s = s_orig.codepoints
t = t_orig.codepoints
 
dp = Array.new(s.size+1) { Array.new(t.size+1,0) }
 
0.upto(s.size-1).each do |i|
  dpi = dp[i]
  dpi1 = dp[i+1]
  0.upto(t.size-1).each do |j|
    if s[i] == t[j]
      dpi1[j+1] = dpi[j] + 1
    else
      dpi1[j+1] = dpi1[j] > dpi[j+1] ? dpi1[j] : dpi[j+1]
    end
  end
end
 
ans = ''
y = s.size
x = t.size
 
while y>0
  if dp[y-1][x] == dp[y][x]
    y-=1
  elsif dp[y][x-1] == dp[y][x]
    x-=1
  else
    y-=1
    x-=1
    ans += s_orig[y]
  end
end
 
# dp.each{|l| p l}
 
puts ans.reverse

Measured memory_bytes: 89224
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
int c=sc.nextInt();
int [][]a=new int [r+1][c+1];
int goukei=0;
for(int i=0;i<r;i++) {
	int sum=0;
	for(int o=0;o<c;o++) {
		int n=sc.nextInt();
		a[i][o]+=n;
		sum+=n;
		goukei+=n;
		a[r][o]+=n;
	}
	a[i][c]+=sum;
}
a[r][c]=goukei;
for(int q=0;q<=r;q++) {
	for(int w=0;w<=c;w++) {
		if(w>0) {
			System.out.print(" ");
		}
		System.out.print(a[q][w]);
	}
	System.out.println();
}
sc.close();
  }
}



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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    string s;
    cin >> s ;
    ll ans = 0;
    ll c[s.size()+1];

    for(int i=0;i<=s.size();i++){
        c[i]=0;
    }

    for(int i=0;i<s.size();i++){
        if(s[i]=='<'){
            c[i+1] = c[i]+1;
        }
    }

    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='>'){
            c[i] = max(c[i],c[i+1]+1);
        }
    }

    for(int i=0;i<=s.size();i++){
        ans+=c[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;
 
signed main(){
    int n,k;cin>>n>>k;
    int h[n];
    REP(i,n)cin>>h[i];
    int cost[n];
    REP(i,n)cost[i]=INF;
    cost[0]=0;
    REP(i,n-1)REPS(j,k){
        if(i+j>=n)continue;
        chmin(cost[i+j],cost[i]+abs(h[i]-h[i+j]));
    }
    cout<<cost[n-1];
}

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

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i];
	}
	sort(A,A+N);
	if (A[0] == 0)
	{
		cout << "0" << endl;
		return 0;
	}
	ll ans = A[0];
	rep(i,N-1)
	{
		if (A[i+1] > ll(1e18) / ans)
		{
			cout << "-1" << endl;
			return 0;
		}
		ans *= A[i+1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n,k;
    cin >> n >> k;
    vector<int>A(n);
    
    REP(i,n) cin >> A[i];
    int ans= 1LL<<30;
    REP(i,n-k+1){
        ans= min(ans, min(abs(A[i]) +abs(A[i]-A[i+k-1]), abs(A[i+k-1]) +abs(A[i]-A[i+k-1])));
    }
    
    cout << ans << endl;
}


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

int main() {
	
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
     
      long long n,i,j,k,sum=0,count=0,ans=0,x,y,l,r;
      cin>>n;
      long long a[n],b[1000000]={0};
      for(i=0;i<n;i++)
      {
          cin>>a[i];
          sum=sum^a[i];
      }
      for(i=0;i<n;i++)
      {
          k=sum^a[i];
          cout<<k<<" ";
      }
	return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;

  int cnt = 0;
  for (int i = a * b; i > 0; i--) {
    if ((a % i == 0) && (b % i == 0)) {
      cnt++;
    }
    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;
#define lol long long


int main()
{
	int N;
	string S;
	cin >> N >> S;
	vector<int> R(N + 1);
	if (S[0] == '#') {
		R[0] = 1;
	}
	for (int i = 1; i < N; i++) {
		if (S[i] == '#') {
			R[i] = R[i - 1] + 1;
		}
		else {
			R[i] = R[i - 1];
		}
	}
	R[N] = R[N - 1];
	int ans = min(N - R[N - 1], R[N - 1]);
	for (int i = 0; i < N; i++) {
		ans = min(ans, R[i] + (N - i - 1) - (R[N - 1] - R[i]));
	}

	cout << ans << endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
long long jc(int,int);
int main()
{
	int a,b;cin>>a>>b;
	if(a>0)cout<<"Positive";
    else if(b>=0)cout<<"Zero";
    else if((a&1)^(b&1))cout<<"Positive";
    else cout<<"Negative";
	return 0;
}

long long jc(int x,int y)
{
	if(x==y)return x*y;
	int p=x+1;
	long long r=x;
	for(int i=p;i<=y;i++){
		r=r*i;
	}
	return r;
}


Measured memory_bytes: 256
N = int(input())
m = []
for _ in range(N):
    x, y = map(int, input().split())
    m.append((x, y))
s = set(m)

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

ans = float("inf")
for i in range(N):
    x0, y0 = m[i]
    for j in range(N):
        if i == j:
            continue
        x1, y1 = m[j]
        p = x1 - x0
        q = y1 - y0
        c = 0
        for k in range(N):
            x, y = m[k]
            if (x + p, y + q) not in s:
                c += 1
        ans = min(ans, c)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int h,w; cin >>h >>w;
	vector<string> s(h);
	cinf(h,s);
	for(int i=0;i<h;i++){
		cout << s[i]<< endl;
		cout << s[i]<< endl;
	}
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, L;
    cin >> N >> L;
    int ans = 0;
    for(int i=0; i<N; i++){
        ans += L + i;
    }
    if(L > 0){
        ans -= L;
    }else{
        if(N + L <= 0){
            ans -= N + L -1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef struct node {
    int light[10];
    struct node *next_0;
    struct node *next_1;
    int num;
} Node;

Node *make(int n, int now, int hoge, int *lis) {
    Node *a = (Node *)malloc(sizeof(Node));
    if (now == 0) {
        for (int i=0; i<n; i++) {
            a->light[i] = 0;
        }
    }
    else {
        for (int i=0; i<n; i++) {
            if (i == now-1) a->light[i] = hoge;
            else a->light[i] = lis[i];
        }
    }
    if (now < n) {
        a->next_0 = make(n, now+1, 0, a->light);
        a->next_1 = make(n, now+1, 1, a->light);
    }
    else {
        a->next_0 = a->next_1 = NULL;
    }
    a->num = now;
    return a;
}

int run(Node *start, int *ans, int *p, int **s_buf, int m, int n) {
    if (start == NULL) return;
    if (start->num == n) {
        int count = 0;
        for (int i=0; i<m; i++) {
            int buf = 0;
            for (int j=0; j<s_buf[i][0]; j++) {
                buf += start->light[s_buf[i][j+1]-1];
            }
            if (buf%2 == p[i]) count++;
            else break;
            if (count == m) {
                *(ans) += 1;
            }
        }
    }
    else {
        run(start->next_0, ans, p, s_buf, m, n);
        run(start->next_1, ans, p, s_buf, m, n);
    }
}

void free_node(Node *a) {
    if (a == NULL) return;
    free_node(a->next_0);
    free_node(a->next_1);
    free(a);
}

int main() {
    int n = 0, m = 0;
    scanf("%d %d\n", &n, &m);
    int p[m];
    int s[m][n+1];
    int *s_buf[m];
    for (int i=0; i<m; i++) {
        scanf("%d", &s[i][0]);
        for (int j=0; j<s[i][0]; j++) {
            scanf("%d", &s[i][1+j]);
        }
        s_buf[i] = s[i];
    }
    for (int i=0; i<m; i++) scanf("%d", &p[i]);
    int ans = 0;
    Node *start = make(n, 0, 0, p);
    run(start, &ans, p, s_buf, m, n);
    printf("%d\n", ans);
    free_node(start);
    return 0;
}


Measured memory_bytes: 384
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var a = new int[n];
            for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
            var count = 0;
            for (int i = n - 2; i >= 0; i--)
                for (int j = 0; j <= i; j++)
                    if (a[j] > a[j + 1])
                    {
                        var w = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = w;
                        count++;
                    }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9080
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Turn = True
Alice = 0
Bob = 0
for i in range(0, N):
    if Turn==True:
        Alice = Alice+a[i]
    else:
        Bob = Bob+a[i]
    Turn = not Turn
print("{}".format(Alice-Bob))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) return 0;
    int yk=0,h=0,m=0,ans=0;
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      if(s=="lu") h++;
      else if(s=="ld") h--;
      else if(s=="ru") m++;
      else m--;
      int nans;
      if(h==m){
        if(h==0&&m==0) nans=0;
        else nans=1;
        if(yk!=nans){
          ans++;
          yk=nans;
        }
      }
    }
    cout<<ans<<endl;
  }
}



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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 110;

int n,k,a[N],dp[N][100100],cum[100100],mod=1e9+7;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    dp[n+1][0] = 1;

    for(int i=0;i<=k;i++)
        cum[i] = 1;

    for(int i=n;i>=1;i--)
    {
        for(int j=0;j<=k;j++)
            dp[i][j] = ( ( cum[j] - cum[max(j-a[i]-1,0)] + ( ( j-a[i]-1<0 ) ? cum[0] : 0 ) ) %mod + mod ) %mod;

        cum[0] = dp[i][0];
        for(int j=1;j<=k;j++)
            cum[j] = ( cum[j-1] + dp[i][j] )%mod;
    }

    printf("%d\n",dp[1][k]);
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s,t;

int main()
{
	cin>>s>>t;
	if(s==t.substr(0,s.size())) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,d,x;
cin>>n>>d>>x;
int arr[n];
for(int i=0; i<n; ++i)
cin>>arr[i];
long long int sum(n+x);
for(int i=0; i<n; ++i)
{
int cnt(0);
for(int j=1; j<1000; ++j)
{
if(j*arr[i]+1>d)
break;
++cnt;
}
sum+=cnt;
}
cout<<sum;
}

Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
using namespace std;

struct Matrix2x2{
	int a,b,c,d;
};
Matrix2x2 mult(Matrix2x2 A,Matrix2x2 B){
Matrix2x2 C={0};
	C.a=((A.a*B.a)%1001+(A.b*B.c)%1001)%1001;
	C.b=((A.a*B.b)%1001+(A.b*B.d)%1001)%1001;
	C.c=((A.c*B.a)%1001+(A.d*B.c)%1001)%1001;
	C.d=((A.c*B.b)%1001+(A.d*B.d)%1001)%1001;
	return C;
}

Matrix2x2 expt(Matrix2x2 A, int p){
	if(p==1){
		return A;
	}
	else if(p%2==1){
		Matrix2x2 T=expt(A,p-1);
		return mult(A,T);
	}
	else{
		Matrix2x2 T=expt(A,p/2);
		return mult(T,T);
	}
}
int p[1010];
void init(int nn){
	
	for (int ii=0;ii<nn+1;ii++){
		p[ii]=ii;
	}
}
int root(int a){
	if(p[a]==a) return a;
	else return (	p[a]=root(p[a]));
}
void unite (int a,int b){
	p[root(a)]=root(b);
}
int main() {
int f[1010];
for(int k=0;k<1010;k++){
if(k==0){
	f[k]=1;
}
else if(k==1){
	f[k]=2;
}
else{
Matrix2x2 A={1,1,1,0};
Matrix2x2 G=expt(A,k-1);
f[k-2]=G.a;
}
}
int v,d;
while(cin>>v>>d){
	int j=0;
	init (v);
	for(int i=1; i<=v;i++){
		for(int j=i+1;j<=v;j++){
			if(abs(f[i]-f[j])<d){
				unite(i,j);
			}
		}
	}
for (int r=1;r<=v;r++){
	if(p[r]==r){
		j=j+1;
	}
}
cout<<j<<endl;
}
	return 0;
}

Measured memory_bytes: 1168
def main():
  
  L,R=map(int,input().split())
  x,y=L//2019,R//2019
  
  if y-x>=1:
    print(0)
    
  else:
    i=R
    k=1
    ans=float("inf")
    while(L<i):
      ans=min(ans,i*(i-k)%2019)
      if ans==0:
        print(0)
        break        
      k+=1
      if i-k<L:
        k=1
        i-=1
        
    else:
      print(ans)
      
if __name__=="__main__":
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    vector<long long> A(N),B(N);
    vector<pair<long long,long long>> P(N);
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        P[i] = make_pair(A[i],B[i]);
        //cout << P[i].first << " " << P[i].second << endl;
    }
    sort(P.begin(),P.end());
    for(int i = 0; i < N; i++){
       /* cin >> A[i] >> B[i];
        P[i] = make_pair(A[i],B[i]);*/
        //cout << P[i].first << " " << P[i].second << endl;
    }
    long long Kane = 0;
    int i = 0;
    while(M > 0){
        if(P[i].second == 0) i++;
        M--;
        P[i].second--;
        Kane += P[i].first;
        //cout << P[i].second << endl;
    }
    cout << Kane << endl;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for(int i = 0; i < k; ++i) {
		if(i % 2 == 0) {
			if(a % 2) {
				--a;
			}
			b += a / 2;
			a /= 2;
		} else {
			if(b % 2) {
				--b;
			}
			a += b / 2;
			b /= 2;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

count = 0

while count <= k:
    if a < b and b < c:
        break
    if a >= b:
        count+=1
        b*=2
    elif b >= c:
        count+=1
        c*=2
if a < b and b < c and count <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
def main():
    from bisect import bisect_left
    from bisect import bisect_right
    from sys import stdin
    input=stdin.readline

    n,q=map(int,input().split())
    stx=[list(map(int,input().split())) for _ in [0]*n]
    d=[int(input()) for _ in [0]*q]
    stx=[[s-x,t-x-1,x] for s,t,x in stx]
    stx=[[bisect_left(d,s),bisect_right(d,t),x] for s,t,x in stx]

    #セグ木の要素数（num）および深さ（depth）を計算
    basesize=q
    num,depth=1,1
    while num<basesize:
        num*=2
        depth+=1
    num-=1
    #セグ木を構築
    treesize=num+basesize
    tree=[10**9+1]*treesize
    
    #半開区間[lower,upper)について更新の準備をする関数
    def range_update_pre(lower,upper,new_value):
        q=[[0,1]]  #インデックス、階層
        while q:
            i,f=q.pop()
            #popしたインデックスと階層から、求める下限と上限を算出する
            #幅
            width=pow(2,depth-f)
            #下限と中央と上限
            kagen=(i-pow(2,f-1)+1)*width
            chuo=kagen+width//2
            jogen=kagen+width
            k=2*i+1
            if lower<=kagen and jogen<=upper:
                tree[i]=min(new_value,tree[i])
                continue
            if k<treesize:
                if lower<=kagen and chuo<=upper:tree[k]=min(new_value,tree[k])
                elif lower<=chuo:q.append([k,f+1])
            if k+1<treesize:
                if lower<=chuo and jogen<=upper:tree[k+1]=min(new_value,tree[k+1])
                elif chuo<=upper:q.append([k+1,f+1])

    for s,t,x in stx:
        if s<t:
            range_update_pre(s,t,x)

    for i in range(1,treesize):
        tree[i]=min(tree[i],tree[(i-1)//2])

    ans=[i for i in tree[treesize-basesize:]]
    for i in ans:
        if i==10**9+1:
            print(-1)
        else:
            print(i)
main()

Measured memory_bytes: 121568
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end


N,M=get_i
puts (N-1)*N/2+(M-1)*M/2

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    using pii = pair<ll,ll>;
    vector<pii> P(N+1);
    rep(i,N){
        ll a;
        cin >> a;
        P[i+1].first=a;
        P[i+1].second=i+1;
    }
    sort(All(P));
    reverse(All(P));
    multiset<int> s;
    s.insert(0);
    s.insert(0);
    s.insert(N+1);
    s.insert(N+1);
    
    ll res = 0;

    for(auto x:P){
        int id = x.second;
        auto itr = s.lower_bound(id);
        int R1 = *itr;
        itr++;
        int R2 = *itr;
        itr--;
        itr--;
        int L1 = *itr;
        itr--;
        int L2 = *itr;
        res += x.first*(R2-R1)*(id-L1);
        res += x.first*(R1-id)*(L1-L2);
        s.insert(id);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include<cmath>
#include <cstring>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

const ll MOD = 1000000007LL;

int main() {

  string S;
  cin >> S;

  ll remainder[13];
  memset(remainder, 0, sizeof(remainder));
  remainder[0] = 1;

  ll base = 1;
  for (ll i = S.length() - 1; i >= 0; i--) {
    ll next_remainder[13];
    memset(next_remainder, 0, sizeof(next_remainder));

    if (S[i] == '?') {
      for (ll j = 0; j < 10; j++) {
        for (ll k = 0; k < 13; k++) {
          next_remainder[((base * j) + k) % 13] += remainder[k];
          next_remainder[((base * j) + k) % 13] %= MOD;
        }
      }
    } else {
      ll num = S[i] - '0';
      for (ll k = 0; k < 13; k++) {
        next_remainder[((base * num) + k) % 13] += remainder[k];
        next_remainder[((base * num) + k) % 13] %= MOD;
      }
    }

    memcpy(remainder, next_remainder, sizeof(next_remainder));

    base *= 10;
    base %= 13;
  }

  cout << remainder[5] << endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        var tmp = cin.ArrayInt(N);
        var A = new int[100010];
        for (int i = 1; i <= N; i++) {
            A[i] = tmp[i - 1];
        }

        long original = 0;
        for (int i = 0; i <= N; i++) {
            original += Math.Abs(A[i] - A[i + 1]);
        }

        for (int i = 1; i <= N; i++) {
            long hoge = original - (Math.Abs(A[i] - A[i - 1]) + Math.Abs(A[i + 1] - A[i])) + Math.Abs(A[i + 1] - A[i - 1]);
            Console.WriteLine(hoge);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 25308
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N,C,K;
    cin >> N >> C >> K;
    ll T[N];
    rep(i,N){
        cin >> T[i];
    }
    sort(T,T+N);
    ll out = 0;
    ll start = 0;
    while(start<N){
        ll cnt = 0;
        rep(i,C){
            if(T[start+i]>T[start]+K||start+i==N) break;
            cnt = i;
        }
        start += cnt+1;
        out++;
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m, s, t;
vector<int> g[3 * N];
int D[3 * N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].emplace_back(n + v);
        g[n + u].emplace_back(2 * n + v);
        g[2 * n + u].emplace_back(v);
    }

    cin >> s >> t;
    --s, --t;
    return true;
}

void solve() {
    queue<int> Q;
    Q.push(s);
    
    for (int i = 0; i < 3 * n; ++i)
        D[i] = MOD;

    D[s] = 0;

    while (!Q.empty()) {
        int v = Q.front();
        Q.pop();

        for (auto to : g[v])
            if (D[to] == MOD) {
                D[to] = D[v] + 1;
                Q.push(to);
            }
    }

    if (D[t] == MOD)
        cout << -1 << endl;
    else
        cout << D[t] / 3 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

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

int main() {
  char c;
  cin >> c;
  if (islower(c)) {
    cout << "a" << endl;
  }
  else cout << "A" << endl;
}

Measured memory_bytes: 3620
using System;

class quiz
{
    public int solve(int H, int W, int[][] A)
    {
        int ans = 100000000, West, North, dist;

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                dist = 0;

                for (int k = 0; k < H; k++)
                {
                    for (int l = 0; l < W; l++)
                    {
                        North = i - k < 0 ? k - i : i - k;
                        West = j - l < 0 ? l - j : j - l;
                        dist += A[k][l] * Math.Min(North, West);
                    }
                }

                ans = Math.Min(ans, dist);
            }
        }

        return ans;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();
        
        int[] HW = ex.ParseIntBySpace(Console.ReadLine());
        int[][] A = new int[HW[0]][];

        for (int i = 0; i < HW[0]; i++)
        {
            A[i] = ex.ParseIntBySpace(Console.ReadLine());
        }

        //while (true)
        //{
        Console.WriteLine(ex.solve(HW[0], HW[1], A));
        //}
    }
}


Measured memory_bytes: 20000
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 n;
		if(A <= 9 && B <= 9) {
			n = A * B;
		}else {
			n = -1;
		}
		System.out.println(n);
	}

}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int nax = 2e5 + 100;

vector<int> g[nax];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
	#endif
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	pair<int,int> ans = {0,0};
	for(int A=0;A<=40;A++){
		for(int B=0;B<=40;B++){
			for(int C=0;C<=40;C++){
				for(int D=0;D<=40;D++){
					ll water = a*A*100+b*B*100;
					ll suger = C*c+D*d;
					ll mass = water+suger;
					if(mass > f)continue;
					if(suger*100 > water*e)continue;	
					if(suger*ans.first >= ans.second*mass){
						ans = {mass,suger};
					}
				}
			}
		}
	}
	cout << ans.first << ' ' << ans.second << endl;
}

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

int main() {

	int m1, m2, h1, h2, k;
  	cin>>h1>>m1>>h2>>m2>>k;
  	
  
  	int diff = h2*60 + m2 - h1 * 60 - m1;
  
  	cout<<diff-k<<endl;
  
  	return 0;
      
  
}
  
  
  
      

Measured memory_bytes: 3644
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let a=[ssin(),ssin(),ssin(),ssin()]
  out(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]?'Bad':'Good')
}
main()

Measured memory_bytes: 7372
// Garg's Code
#include <bits/stdc++.h>
using namespace std;
#define set set <ll>
#define ll long long
#define ldb long double;
#define pa pair < ll, ll >
#define map map < ll, ll >
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
#define llong 1e9+7
#define lsmall -1e9+7
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
 int main() 
 
{
   fast();
  
    
  ll n, m;
  cin >> n >> m;
  f(i,m-n+1,m+n)
  {
  	cout << i << " ";
  }
  return 0;   
}

Measured memory_bytes: 256
// C - Snack
#include <stdio.h>
typedef long long ll;

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

int main(void){
    ll a, b;
    scanf("%lld%lld", &a, &b);
    // printf("gcd:%d\n", gcd(a, b));
    printf("%lld\n", a*b/gcd(a, b));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int k, s;
    cin >> k >> s;
    int count = 0;
    int should_break = false;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            int z = s - i - j;
            if (z >= 0 && z <= k) {
                count ++;
            }
        }
    }
    cout << count;

}


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

using namespace std;

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

  const long MOD = 1e9+7;

  long N, K; cin>>N>>K;
  vector<int> A(N);
  for (auto& a : A) cin>>a;
  vector<long> tens(N, 0);
  for (int i = 0; i < N; i++) for (int j = 0; j < i; j++) {
    if (A[j] > A[i])
      tens[i]++;
  }
  vector<long> atens(N, 0);
  for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
      if (A[i] > A[j])
        atens[j]++;
  }

  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += tens[i]*K%MOD;
    ans %= MOD;
    ans += atens[i] * (K*(K-1)/2%MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
fun main() {
    val n = readInt()
    val a = readLongs().sortedDescending()

    val score = mutableListOf<Long>()
    score.add(0)
    score.add(a[0])
    for (i in 1 until n) {
        score.add(a[i])
        score.add(a[i])
    }

    println(score.take(n).sum())
}

private fun readInt() = readLine()!!.toInt()
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


int main(void){

    ll n,k,ans;

    cin >> n >> k;

    ans = 0;
    for(ll i=k-1; i<=n; i++){
        ll min_i = (i*(i+1)/2);
        ll max_i = ((i+1)*(2*n-i)/2);
        ans = (ans + (max_i - min_i + 1))%MOD;
        print(i, ":", min_i, max_i, ans); 
    }

    cout << ans << endl;


    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    string s;
    cin >> s;
    li n = sz(s);

    li res = 0;
    li numb = 0;
    rin{
        if (s[i] == 'W') {
            res += numb;
        } else{
            numb++;
        }
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#define maxn 1000005
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

int arr[105];
int brr[105];
int n;

int main(){
	//freopen("Test.txt", "r", stdin);
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; i++){
		scanf("%d", &arr[i]);
	}
	memset(brr, 0, sizeof(brr));
	for(int i = n ; i >= 1 ; i--){
		int k = 0;
		for(int j = 1 ; j <= i ; j++){
			if(arr[j] == j){
				k = j;
			}
		}
		if(k == 0){
			printf("-1\n");
			return 0;
		}
		brr[i] = k;
		for(int j = k ; j < i ; j++){
			arr[j] = arr[j + 1];
		}
	}
	for(int i = 1 ; i <= n ; i++){
		printf("%d\n", brr[i]);
	}
	return 0;
}


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

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2500;
int a[N], b[N];
int dp[2][201][5201];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, res;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if (i == 1) res = x; else{
            int f = __gcd(res, x);
            res /= f;
            res *= x;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-04-04 21:02:26
 * @LastEditTime: 2020-04-04 21:11:58
 * @FilePath: \VSCode\C++\Practice\AC abc161 B.cpp
 */
#include<bits/stdc++.h>
using namespace std;

int n,m;
int a[105];
signed main(){
    scanf("%d%d",&n,&m);
    register int i;

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

    sum=ceil(sum*1.0/(4.0*m));
    int cnt=0;
    for(i=1;i<=n;++i){
        if(a[i]>=sum) ++cnt;
    }
    
    puts(cnt>=m?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 200010

LL a[MX];
LL ans[MX];

int main()
{
    int n;
    scanf("%d",&n);
    LL sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    LL x = a[0];
    LL y = sum-a[0];
    ans[0]=abs(x-y);
    for (int i=1;i<n-1;i++)
    {
        x+=a[i];
        y-=a[i];
        ans[i]=abs(x-y);
    }
    sort(ans,ans+n-1);
    cout<<ans[0]<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int h,w,n,num[10000];
int main() {
    int cnt = 1;
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i = 0;i < n;i ++) {
        scanf("%d",&num[i]);
    }
    for(int i = 0;i < h;i ++) {
        while(!num[cnt - 1]) cnt ++;
        string s = to_string(cnt);
        num[cnt - 1] --;
        for(int j = 1;j < w;j ++) {
            while(!num[cnt - 1]) cnt ++;
            s = i % 2 ? (to_string(cnt) + " " + s) : (s + " " + to_string(cnt));
            num[cnt - 1] --;
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
    int W, H, x, y, r;
    std::cin >> W >> H >> x >> y >> r;
    if ((y+r > H) || (x+r > W) || (y-r < 0) || (x-r < 0)) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

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

  vector<ll> a(n);

  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  ll tmp = 0;
  rep(i, n) {
    tmp += a[i];
    if (tmp * 2 >= sum) {
      ll aa = tmp-(sum-tmp);
      ll bb = (sum-tmp+a[i])-tmp+a[i];
      cout << min(aa, bb) << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){

	string s[3];

	REP(i,3){
		cin>>s[i];
	}

	int turn = 0;
	int now[3]={0,0,0};
	while(1){
		if(now[turn]==s[turn].size()){
			cout<<(char)(turn+'A')<<endl;
			break;
		}
		turn = s[turn].at(now[turn]++)-'a';
	}

	return 0;

}

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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,cons=0,ans=0;
  cin>>N;
  for(int i=0;i<4;i++){
    if(N%10==2){
      ans++;
    }
    N=(int)N/10;
  }
  cout<<ans;

  return 0;
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

//--------------------------------------------

int main(){
  LL n, a, b;

  scanf("%lld %lld %lld",&n, &a, &b);

  if (a <= b && n != 1) {
    printf("%lld\n",(a + (n - 1) * b) - ((n - 1) * a + b) + 1);
  } else if (n == 1 && a == b) {
    printf("1\n");
  } else {
    printf("0\n");
  }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main
{
    private static class Elm {
        final int index;
        final int n;

        public Elm(int index, int n)
        {
            this.index = index;
            this.n = n;
        }
    }

    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Elm> xs = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            xs.add(new Elm(i + 1, scanner.nextInt()));
        }
        xs.sort(Comparator.comparingInt(a -> a.n));
        boolean isFirst = true;
        for (Elm elm : xs) {
            if (isFirst) {
                isFirst = false;
            }
            else {
                System.out.print(" ");
            }
            System.out.print(elm.index);
        }
        System.out.println();
    }
}



Measured memory_bytes: 64692
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), s(n + 1);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) s[i + 1] = s[i] + abs(a[i]);

  ll minus = INFL, minus_cnt = 0;
  rep(i, 0, n) {
    if (a[i] == 0) {
      minus = INFL;
      minus_cnt = 0;
    } else {
      minus = min(minus, abs(a[i]));
      if (a[i] < 0) ++minus_cnt;
    }
  }
  cout << s[n] - (minus_cnt % 2 == 0 ? 0 : minus * 2) << endl;
}

Measured memory_bytes: 4852
#include <iostream>

using namespace std;

int main() {
	int n, a;

	cin >> n;

	a = n % 10;
	
	if (a == 0 or a == 1 or a == 6 or a == 8) {
		cout << "pon";
	}
	else if (a == 3) {
		cout << "bon";
	}
	else {
		cout << "hon";
	}
}

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

int main(){
  int N,M,X,mae=0,usiro=0;
  cin >> N >> M >> X;
  vector<int>vec(M);
  for(int i=0;i<M; i++){
    cin >> vec[i];
    if(vec[i]<X){
      mae++;
    }
    else{
      usiro++;
    }
  }
  cout << min(mae,usiro) << endl;
}



Measured memory_bytes: 3588
import sys
from itertools import combinations_with_replacement as combi
input = sys.stdin.readline
N, M, Q = map(int, input().split())
qs = [tuple(map(int, input().split())) for _ in range(Q)]
res = 0
for c in combi([x for x in range(1, M + 1)], N):
  t = 0
  for l, r, d, s in qs:
    if c[r - 1] - c[l - 1] == d: t += s
  res = max(res, t)
print(res)

Measured memory_bytes: 67796
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007

using namespace std;

class ASecurity {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s;
		in >> s;
		f(i,0,3)
			if(s[i]==s[i+1])
			{
				out << "Bad" << "\n";
				return;
			}
		out << "Good" << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ASecurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String a = sc.next();
        String b = sc.next();

        ArrayList<Integer> arr = new ArrayList<Integer>();

        int la = a.length();
        int lb = b.length();

        for (int i = 0; i < (la-lb+1);i++){
            String c = a.substring(i,i+lb);
            int cu = 0;
            for (int j = 0; j<lb;j++){
                if (c.charAt(j) != b.charAt(j))
                    cu++;
            }
            arr.add(cu);
        }
        System.out.println(Collections.min(arr));
    }
}

Measured memory_bytes: 37260
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    res = 0
    for i in range(n):
        tmp = min(a[i],b[i])
        res += tmp
        a[i] -= max(tmp,0)
        if b[i] > tmp:
            tmp = min(a[i+1],b[i]-tmp)
            res += tmp
            a[i+1] -= max(tmp,0)
    print(res)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 82020
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
const double PI = acos(-1);
double a, b, x;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed), cout.precision(10);
	while (cin >> a >> b >> x)
	{
		double half = a*b / 2 * a, h;
		if (x >= half)
		{
			x = half * 2 - x;
			h = b*x / half;
			cout << atan(h / a) / PI * 180 << endl;
		}
		else
			cout << 90 - atan(a*x / half / b) / PI * 180 << endl;
	}
}
/*
2 2 4

12 21 10

3 1 8
*/

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define plli pair<lli,lli>
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}
/*********************************reused****************************/

int main()
{
    int n,k;
    cin >>n>>k;
    cout<< 2*k-n<<endl;
    return 0;
}



Measured memory_bytes: 256