akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <functional>
#include <unordered_map>
#define int long long 
#define pi pair<int,int> 
#define endl "\n"
using namespace std ;

const int inf = 1e15 ;
const int size = 3005;
const int mod = 1e9 + 7 ;
int dp[2][size][size] , a[size] , n ;


int32_t main() 
{


     /*#ifndef ONLINE_JUDGE 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
     */
     memset(dp,-1,sizeof(dp));
     cin >> n ;
     for(int i = 1  ; i <= n ; i++ ) cin >> a[i] ;
     for(int i = 1 ;i <= n ; i++ )
     {
         dp[0][i][i] = a[i] ;
         dp[1][i][i] = -a[i] ;
     }

     for(int len = 2 ; len <= n ; len++)
     {
         for(int i = 1 ; i + len-1 <= n ; i++ )
         {
             
              int j = i+len-1;
              dp[0][i][j] = max(a[i]+dp[1][i+1][j],a[j]+dp[1][i][j-1]);
              dp[1][i][j] = min(-a[i]+dp[0][i+1][j],-a[j]+dp[0][i][j-1]);
            
         }
    }
  
    cout<<dp[0][1][n]<<endl;
    return 0 ;
}


Measured memory_bytes: 141816
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228

#define tm tm228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n; 
int a[maxn]; 

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i]; 
    }  
    int lst = 1; 
    int ans = 0; 
    for (int i = 0; i < n; ++i) { 
        if (a[i] <= lst) {  
            lst = max(lst, a[i] + 1); 
            continue; 
        } else {
            if (a[i] % lst == 0) ans += a[i] / lst - 1; 
            else ans += a[i] /= lst; 
            lst = max(lst, 2ll); 
        }                      
    }
    cout << ans; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
} 

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

using namespace std;


     
#define ll long long int
#define ld long double


#define fr first
#define se second



#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))


#define pb push_back
#define mp make_pair

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))

#define easm(a, b) (a + b - 1)/b 


#define PI 3.141592653589793238
#define E  2.718281828459045235


ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}


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

const int N = 1e3 + 10, M = 1e9 + 7;

int n, m, dp[N][N];
char g[N][N];


bool valid(int x, int y){return x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '.';}



int main(){
  //freopen("input.in", "r", stdin);
  //freopen("output.txt", "w", stdout);
  clock_t z = clock();
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++)
    scanf("%s", g[i]);
  dp[0][0] = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(i == 0 && j == 0)continue;
      if(g[i][j] == '#'){dp[i][j] = 0;continue;}
      int w = 0;
      if(i != 0)w += dp[i-1][j]%M;
      if(j != 0)w = (w%M + dp[i][j-1]%M)%M;
      dp[i][j] = w;
    }
  }

  printf("%d\n", dp[n-1][m-1]%M);
  debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -integer overflow
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

Measured memory_bytes: 5248
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

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

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int head[maxn], cnt, n;

struct edge
{
    int v, nxt;
} Edge[maxn];

void init()
{
    for(int i = 0; i <= n; i++) head[i] = -1;
    cnt = 0;
}

void addedge(int u, int v)
{
    Edge[cnt].v = v;
    Edge[cnt].nxt = head[u];
    head[u] = cnt++;
}

ll dp[maxn];
int indeg[maxn];
bool vis[maxn];

void dfs(int id)
{
    if(vis[id]) return;
    vis[id] = true;
    for(int i = head[id]; i != -1; i = Edge[i].nxt)
    {
        int v = Edge[i].v;
        dfs(v);
        dp[id] = max(dp[id], dp[v] + 1);
    }
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int m, u, v;
    scanf("%d%d", &n, &m);
    init();

    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        addedge(u, v);
        indeg[v]++;
    }

    ll answer = 0;
    for(int i = 1; i <= n; i++) if(!vis[i])   dfs(i);
    for(int i = 1; i <= n; i++) answer = max(answer, dp[i]);

    printf("%lld\n", answer);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

using namespace std;

void Main() {
    long long N, M, K;
    cin >> N >> M >> K;
    vector<long long> A(N, 0LL), B(M, 0LL);
    vector<long long> accA(N, 0LL), accB(M, 0LL);
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
        if (i == 0) {
            accA[i] = A[i];
        }
        else {
            accA[i] = accA[i - 1] + A[i];
        }
    }
    for (long long j = 0; j < M; ++j) {
        cin >> B[j];
        if (j == 0) {
            accB[j] = B[j];
        }
        else {
            accB[j] = accB[j - 1] + B[j];
        }
    }

    auto itA = upper_bound(accA.begin(), accA.end(), K);
    if (itA == accA.begin()) {
        // no choice from A
        auto itB = upper_bound(accB.begin(), accB.end(), K);
        cout << distance(accB.begin(), itB) << endl;
        return;
    }

    long long ans = 0LL;
    for (; itA != accA.begin(); --itA) {
        long long books = distance(accA.begin(), itA);
        auto itB = upper_bound(accB.begin(), accB.end(), K - (*prev(itA)));
        books += distance(accB.begin(), itB);
        ans = max(ans, books);
    }
    {
        // case : itA == accA.begin()
        long long books = 1LL;
        auto itB = upper_bound(accB.begin(), accB.end(), K - A[0]);
        books += distance(accB.begin(), itB);
        ans = max(ans, books);
    }
    auto itB = upper_bound(accB.begin(), accB.end(), K);
    long long books = distance(accB.begin(), itB);
    ans = max(ans, books);

    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9564
N = int(input())
Alist=[]
# Blist=[]
for i in range(0,N):
    Alist.append(int(input()))

Alist.sort()
# print(Alist)

back=N-1

numA=Alist[0]
numB=Alist[back]
ans = abs(numB-numA)
back-=1
# print(ans)

for i in range(1,int(N/2)):
    if i%2 == 0:
        ans+=abs(numA-Alist[i])
        numA=Alist[i]
        ans+=abs(numB-Alist[back])
        numB=Alist[back]
        # print(ans)
    else:
        ans+=abs(numB-Alist[i])
        numB=Alist[i]
        ans+=abs(numA-Alist[back])
        numA=Alist[back]
    back-=1
    # print(ans)

# print("l-")

if N%2 == 1:
    k=int(N/2)
    # print(k)
    if abs(numA-Alist[k]) > abs(numB-Alist[k]):
        ans+=abs(numA-Alist[k])
        numA=Alist[k]
    else:
        ans+=abs(numB-Alist[k])
        numB=Alist[k]
    # print(ans)

# print("a-")
print(ans)


Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
const int maxn=221345;
int n,a[maxn],cnt[maxn];
int main()
{
    scanf("%d",&n);
    long long res=0;
    for (int i=1;i<=n;++i) {
        scanf("%d",&a[i]);
        ++cnt[a[i]];
        res+=cnt[a[i]]-1;
    }
    for (int i=1;i<=n;++i) printf("%lld\n",res-cnt[a[i]]+1);
    return 0;
}


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

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Cake = Tuple!(long, "beauty", long, "tasty", long, "popular");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, m;
    scan(n, m);
    auto cakes = new Cake[](n);
    foreach (ref e; cakes)
    {
        long a, b, c;
        scan(a, b, c);
        e = Cake(a, b, c);
    }
    long max_sum;
    cakes.sort!"a.beauty + a.tasty + a.popular > b.beauty + b.tasty + b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"a.beauty + a.tasty - a.popular > b.beauty + b.tasty - b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"a.beauty - a.tasty + a.popular > b.beauty - b.tasty + b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"a.beauty - a.tasty - a.popular > b.beauty - b.tasty - b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"-a.beauty + a.tasty + a.popular > -b.beauty + b.tasty + b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"-a.beauty + a.tasty - a.popular > -b.beauty + b.tasty - b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"-a.beauty - a.tasty + a.popular > -b.beauty - b.tasty + b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);
    cakes.sort!"-a.beauty - a.tasty - a.popular > -b.beauty - b.tasty - b.popular"();
    max_sum = max(cakes.take(m).tuple_sum, max_sum);

    max_sum.writeln();
}

auto tuple_sum(T)(T tupary)
{
    auto sum = Cake(0, 0, 0);
    foreach (e; tupary)
    {
        sum[0] += e[0];
        sum[1] += e[1];
        sum[2] += e[2];
    }
    // sum.writeln();
    return abs(sum.beauty) + abs(sum.tasty) + abs(sum.popular);
}

Measured memory_bytes: 2428
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>////

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef complex<double> P;/////

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {//交点が存在するかどうか
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P crosspointSS(L a,L b){//交点を求める
  double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
  double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
  return b[0]+(b[1]-b[0])*t1/(t1+t2);
}

P projection(L a,P p){
  double t=dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]);
  return a[0]+t*(a[0]-a[1]);
}

bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

int main(void) {
  int i,j,k;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int ans=1+n;
    vector<L>l;

    rep(i,n){
      double x,y;
      cin>>x>>y;
      P p(x,y);
      cin>>x>>y;
      P q(x,y);
      l.push_back(L(p,q));

      rep(j,i)if(intersectSS(l[i],l[j])){
	P p=crosspointSS(l[i],l[j]);
	if(abs(10000-p.real()*p.real())>EPS&&
	   abs(10000-p.imag()*p.imag())>EPS){
	  bool h=true;
	  rep(k,j)if(distanceSP(l[k],p)<EPS)h=false;
	  if(h)ans++;
	}
      }

    }

    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3184
import sys
sys.setrecursionlimit(10**5) 

N, M = map(int, input().split())
edge = [[] for i in range(N)]
for i in range(M):
  x, y = map(int, input().split())
  edge[x-1].append(y-1)

dp = [-1] * N
def dist(v):
  if dp[v] != -1: return dp[v]
  
  res = 0
  for to in edge[v]:
    res = max(res, dist(to) + 1)
  
  dp[v] = res
  return res

ans = 0
for i in range(N):
  ans = max(ans, dist(i))

print(ans)

Measured memory_bytes: 59056
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

struct Point {
    int x, y, h;
    bool operator <(const Point &another) { return h < another.h; }
};

int main() {
    int n;
    cin >> n;
    vector<Point> ps(n);
    vector<vector<bool>> is0(101, vector<bool>(101));
    rep(i, n) {
        int x, y, h;
        cin >> x >> y >> h;
        if (h == 0) is0[x][y] = true;
        ps.at(i) = {x, y, h};
    }
    sort(ps.rbegin(), ps.rend());

    const int INF = 1e9 + 1000;
    rep(cx, 101) rep(cy, 101) {
        if (is0[cx][cy]) continue;

        int ch = INF;
        bool ok = true;
        rep(i, n) {
            int x = ps[i].x, y = ps[i].y, h = ps[i].h;
            int nch = h + abs(x - cx) + abs(y - cy);

            if (h == 0) {
                if (nch < ch) {
                    ok = false;
                    break;
                }
            }
            else {
                if (ch == INF) ch = nch;
                else if (ch != nch) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            printf("%d %d %d\n", cx, cy, ch);
        }
    }
}

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

int main() {
  int N; cin >> N;
  int A[200];int ans=100000;
  for(int i = 0; i < N; i++) {
  cin >> A[i];
  }
  for(int i = 1; i < N; i++) {
    int S1=0,S2=0;
    for (int j = 0; j < i; j++)
    {
      S1 += A[j];
    }
    for(int k = i; k < N; k++) {
      S2 += A[k];
    }
     ans = min(ans,abs(S1-S2));
  }
  cout << ans << endl;
  return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String N;
	while (!(N = br.readLine()).equals("0")) {
	    int n = Integer.parseInt(N);
	    int[][] map = new int[21][21];
	    for (int i = 0; i < n; i++) {
		String[] s = br.readLine().split(" ");
		map[Integer.parseInt(s[0])][Integer.parseInt(s[1])] = 1;

	    }
	    int m = Integer.parseInt(br.readLine());
	    int x = 10;
	    int y = 10;
	    int count = 0;
	    for (int i = 0; i < m; i++) {
		if (count != n) {
		    String[] s = br.readLine().split(" ");
		    char c = s[0].charAt(0);
		    int l = Integer.parseInt(s[1]);
		    int dx = 0;
		    int dy = 0;
		    if (c == 'N') {
			dy = 1;
		    } else if (c == 'E') {
			dx = 1;
		    } else if (c == 'S') {
			dy = -1;
		    } else if (c == 'W') {
			dx = -1;
		    }
		    for (int j = 0; j < l; j++) {
			count += map[x][y];
			map[x][y] = 0;
			x += dx;
			y += dy;
		    }
		    count += map[x][y];
		    map[x][y] = 0;
		} else {
		    br.readLine();
		}
	    }
	    if (count == n) {
		System.out.println("Yes");
	    } else {
		System.out.println("No");
	    }
	}
    }
}

Measured memory_bytes: 29308
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	sort(a.begin(), a.end());
	ll ans=0;
	rep(i,0,n) 
	{
		rep(j,i+1,n)
		{
			ll val = a[i]+a[j];
			ll idx = lower_bound(a.begin(), a.end(),val)-a.begin();
			idx--;
			if(idx>=0 && a[idx]<val) ans+=idx-j;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad               (forM_, replicateM)
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe                  (fromJust)
import           Data.Vector.Unboxed         ((!))
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as MV

main :: IO ()
main = do
  [h, w, d] <- readInts <$> BS.getLine
  ass <- replicateM h (readInts <$> BS.getLine)
  q <- readLn
  lrs <- map readInts . BS.lines <$> BS.getContents
  putStr . unlines . map show $ solve h w d ass q lrs

solve :: Int -> Int -> Int -> [[Int]] -> Int -> [[Int]] -> [Int]
solve h w d ass _ lrs = [ds ! (r - 1) - ds ! (l - 1) | [l, r] <- lrs] where
  bs = V.create $ do
    v <- MV.new (h * w)
    forM_ (zip ass [0 .. h - 1]) $ \(as, i) ->
      forM_ (zip as [0 .. w - 1]) $ \(a, j) ->
        MV.write v (a - 1) (i, j)
    return v
  ds = V.create $ do
    v <- MV.replicate (h * w) 0
    forM_ [d .. h * w - 1] $ \i -> do
      let (x, y) = bs ! (i - d)
          (x', y') = bs ! i
      d' <- MV.read v $ i - d
      MV.write v i $ d' + abs (x' - x) + abs (y' - y)
    return v

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readInts :: BS.ByteString -> [Int]
readInts = map readInt . BS.words


Measured memory_bytes: 10876
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long a[105]={0};

    vector<pair<long, long> > xx(n);
    vector<long> flag(n);

    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(xx[i].first));
        xx[i].second=i;
    }
    sort(xx.begin(), xx.end());

    for(i=0; i<n; i++) {
        if(i<n/2) flag[xx[i].second]=1;
        else      flag[xx[i].second]=0;
    }

    long ans[2] = {xx[n/2-1].first, xx[n/2].first};
    for(i=0; i<n; i++) {
        printf("%ld\n", ans[flag[i]]);
    }

    return 0;
}


Measured memory_bytes: 6912
n,A,B=map(int,input().split())
s=list(input())
cnt=0
cnt_b=0
for i in range(n):
	if s[i]=='a' and cnt<A+B:
		print('Yes')
		cnt+=1
	elif s[i]=='b' and cnt<A+B and cnt_b<B:
		print('Yes')
		cnt_b+=1
		cnt+=1
	else:
		print('No')

Measured memory_bytes: 4712
N, M = gets.split.map(&:to_i)
Bs = readlines.map{|l| l.split.map(&:to_i)}

@p = [*0 .. N]
@r = Array.new(N + 1, 1)

def root(x)
  @p[x] == x ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  return 0 if x == y
  r = @r[x] * @r[y]
  if @r[x] < @r[y]
    @p[x] = y
    @r[y] += @r[x]
  else
    @p[y] = x
    @r[x] += @r[y]
  end
  r
end

puts Bs.reverse.inject([N*(N-1)/2]){|a, (x, y)| a << a.last - (root(x) == root(y) ? 0 : unite(x, y))}.reverse.drop(1).join("\n")

Measured memory_bytes: 22652
#include <iostream>
//#include <cmath>
using namespace std;
using ll=long long;
using ld=long double;

void solve(long long N, long long K){
  N++;

  ll cnt = 0;
  for(ll b=K; b<N; b++){
    if(b>0){
      //cout << b << ","<< (N/b) * (b-K) << endl;;
      cnt += (N/b) * (b-K);
      if(N%b-K > 0) cnt += N%b-K;
    }
  }
  //cout<< "######" << endl;
  //
  // K = 0 のとき、a=0 がカウントされてしまうので、除く。
  if(K==0) cnt -= N-1;
  
  cout << cnt << endl;
}

int main(){	
	long long K;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&K);
	solve(N, K);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int maxn = 20;
const int maxm = maxn * maxn;
const int MX = (1 << 15) + 100;
const int mod = 1e9 + 7;

vector<int> V[maxn];
int t1[maxm] = {}, t2[maxm] = {};

int n, m;
int f[MX] = {};

inline bool check(int S) {
	return (((S & 1) && (S & 2)) || !((S & 1) || (S & 2)));
}

int cnt[MX][maxn] = {};
int Pow2[maxm] = {};

void init() {
	int tot = (1 << n);
	for (int mask = 0; mask < tot; ++mask) {
		for (int i = 1; i <= n; ++i) {
			int sz = V[i].size();
			cnt[mask][i] = 0;
			for (int j = 0; j < sz; ++j) {
				int to = V[i][j];
				if ((1 << (to - 1)) & mask) {
					cnt[mask][i]++;
				}
			}
		}
	}
	Pow2[0] = 1;
	for (int i = 1; i < maxm; ++i) {
		Pow2[i] = 2ll * Pow2[i - 1] % mod;
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> t1[i] >> t2[i];
		V[t1[i]].push_back(t2[i]);
	}
	init();
	int tot = (1 << n);
	for (int mask = 0; mask < tot; ++mask) {
		if (check(mask)) {
			f[mask] = 1; //add no Edges at all
		}
	}
	for (int mask = 0; mask < tot; ++mask) {
		if (check(mask)) {
			for (int sub = (mask - 1) & mask; sub; sub = (sub - 1) & mask) {
				if (check(sub)) {
					int T = mask ^ sub;
					int mul1 = 1, mul2 = 1;
					for (int i = 1; i <= n; ++i) {
						if ((1 << (i - 1)) & sub) {
							mul1 = (1ll * mul1 * (Pow2[cnt[T][i]] - 1) % mod + mod) % mod;
						}
					}
					for (int i = 1; i <= n; ++i) {
						if ((1 << (i - 1)) & T) {
							mul2 = 1ll * mul2 * Pow2[cnt[sub][i]] % mod;
						}
					}
					(f[mask] += 1ll * f[sub] * mul1 % mod * 1ll * mul2 % mod) %= mod;
				}
			}
		}
	}
	cout << (Pow2[m] - f[tot - 1] + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 2944
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
sum = 0
for i in 0..(n-1)
  if a[i] >= b[i]
    sum += b[i]
    a[i] -= b[i]
  else
    if a[i] + a[i+1] < b[i]
      sum += (a[i] + a[i+1])
      a[i] = a[i+1] = 0
    else
      sum += b[i]
      a[i+1] -= (b[i] - a[i])
      a[i] = 0
    end
  end
end
puts sum


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

int s[6], g[6];
bool a[6], b[6];
bool dfs(int l, int r, bool t) {//t==0->??????,t==1->??????
	bool flag = true;
	rep(i, 6)flag &= a[i];
	if (flag)return true;
	flag = true;
	rep(i, 6)flag &= b[i];
	if (flag)return false;
	bool ok;
	if (!t) {
		bool f = false;
		rep(i, 6) {
			if (a[i])continue;
			if (s[i] == l - 1) {
				f = true;
				a[i] = true;
				ok = dfs(s[i], r, 1);
				a[i] = false;
				if (ok)return true;
			}
			if (s[i] == r + 1) {
				f = true;
				a[i] = true;
				ok = dfs(l, s[i], 1);
				a[i] = false;
				if (ok)return true;
			}
		}
		if (!f)return dfs(l, r, 1);
		return false;
	}
	bool f = false;
	rep(i, 6) {
		if (b[i])continue;
		if (g[i] == l - 1) {
			f = true;
			b[i] = true;
			ok = !dfs(g[i], r, 0);
			b[i] = false;
			if(ok)return false;
		}
		if (g[i] == r + 1) {
			f = true;
			b[i] = true;
			ok = !dfs(l, g[i], 0);
			b[i] = false;
			if (ok)return false;
		}
	}
	if(!f)return dfs(l, r, 0);
	return true;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		rep(j, 6)scanf("%d", &s[j]);
		int d = 0;
		for (int j = 1; j <= 13; j++) {
			if (j == 7)continue;
			if (find(s, s + 6, j) == s + 6)g[d++] = j;
		}
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		puts(dfs(7, 7, 0) ? "yes" : "no");
	}
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;
const int N = 51 , mod = 1e9 + 7;

ll tot[N] , p[N];

ll ans(int n , ll x)
{
    if (n == 0)
        return 1;
    if (x == 1)
        return 0;
    if (x == tot[n])
        return p[n];
    if (x <= tot[n]/2)
        return ans(n-1 , x-1);
    if (x == tot[n]/2 + 1)
        return 1 + ans(n-1 , x-2);
    return p[n-1] + 1 + ans(n-1 , x - tot[n-1] - 2);
}

int main()
{
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n , x; cin >> n >> x;
    p[0] = 1 , tot[0] = 1;
    for (int i=1; i<N; i++)
        tot[i] = 2 * tot[i-1] + 3 , p[i] = 2 * p[i-1] + 1;
    cout << ans(n , x);
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        
        int a = s.nextInt();

        if (a% 2 == 1) {
            System.out.println(2*a);
        } else {
            System.out.println(a);
        }
    }
}

Measured memory_bytes: 23892
h, w, a, b = map(int, input().split())
s1 = ["0" if i < a else "1" for i in range(w)]
s2 = ["1" if i < a else "0" for i in range(w)]
for i in range(h):
    if i < b:
        print("".join(s1))
    else:
        print("".join(s2))


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int n,i,neganum,min,j;
  	long result;
  	cin >> n;
  	int m[n];
  	neganum = 0;
  	result = 0;
  	for (i=0;i<n;i++){
    	cin >> m[i];
      	if (m[i]<=0){
        	neganum += 1;
        }
    }
  	if (neganum%2 == 0){
    	for (i=0;i<n;i++){
        	result += abs(m[i]);
        }
    printf("%ld",result);
    return 0;
    }else{
      	min = 100000;
    	for (i=0;i<n;i++){
          	if (abs(m[i])<=min){
            	min = abs(m[i]);
                j = i;
            }
          	m[i] = abs(m[i]);
        }
    	for (i=0;i<n;i++){
          	if (i == j){
            	result -= m[i];
            }else{
            	result += m[i];
            }
        }
    printf("%ld",result);
    return 0;
    }
}

Measured memory_bytes: 640
isEvenString :: String -> Int -> Bool
isEvenString s n
  | even n && half ++ half == s = True
  | otherwise = False
  where half = takeHalf s n
 
takeHalf :: String -> Int -> String
takeHalf s n = take (div n 2) s
 
solve :: String -> Int -> Int
solve (x:xs) n
  | isEvenString xs n' = n'
  | otherwise = solve xs n'
  where n' = n - 1
 
main  :: IO ()
main = do
  s <- getLine
  print $ solve (reverse s) (length s)

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


int dp[100010][3];
int main(){
    int n;
    cin >> n;
    int a[100010][3];
    for(int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
        }
    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
    return 0;
}



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

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    bool k1 = true;
    for (int i = 0; i < N / 2; i++)
    {
        if (S[i] != S[N - 1 - i])
        {
            k1 = false;
            break;
        }
    }
    if (k1 == false)
    {
        cout << "No" << endl;
        return 0;
    }
    else
    {
        for (int i = 0; i < N / 4; i++)
        {
            if (S[i] != S[N / 2 - 1 - i])
            {
                k1 = false;
                cout << "No" << endl;
                return 0;
            }
        }
        if (k1 == true)
        {
            for (int i = 0; i < N / 4; i++)
            {
                //       cout << "i=" << i << endl;
                if (S[(N + 3) / 2 - 1 + i] != S[N - i - 1])
                {
                    cout << S[(N + 3) / 2 - 1] << S[N - i - 1] << endl;
                    k1 = false;
                    //         cout << "No" << endl;
                    return 0;
                }
            }
            cout << "Yes" << endl;
        }
    }
}

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

int main() {
  int n, k, result;
  cin >> n >> k;
  result = 1;
  
  for (int i = 0; i < n; i++) {
    if (result <= k) {
      result *= 2;
    }
    else {
      result += k;
    }
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
# cf16-exhibition-final-openA - 1D Matching
def calc(x, y, total):
    if y:
        total = (total * y) % MOD
        y -= 1
    else:
        x += 1
    return x, y, total


def main():
    global MOD
    # sort A, B and the lines between A, B shouldn't cross
    # cross <-> not min distance
    N, *AB = map(int, open(0))
    C = sorted([(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]])
    MOD = 10 ** 9 + 7
    ans, a, b = 1, 0, 0
    for i, t in C:
        if t:  # laptop
            a, b, ans = calc(a, b, ans)
        else:  # power sources
            b, a, ans = calc(b, a, ans)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 28536
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    
    string s;
    cin >> s;
    if (s == "ARC") cout << "ABC";
    else cout << "ARC";
    
    
}





Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[List[int]]"):
    es = [
        (A[i][j], i, j)
        for i in range(N)
        for j in range(i)
    ]
    es.sort(reverse=True)
    ans = 0
    for d, i, j in es:
        for k in range(N):
            if k == i or k == j:
                continue
            nd = A[i][k] + A[k][j]
            if nd < d:
                print(-1)
                return
            if nd == d:
                break
        else:
            ans += d
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(N)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48348
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans;
    if (a+b <= 2*c) {
        ans = a*x + b*y;
    } else {
        int m = min(x,y);
        ans = 2*c*m;
        x -= m;
        y -= m;
        ans += min(a*x, 2*c*x);
        ans += min(b*y, 2*c*y);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  vector<int> N(4), cor{1, 4, 7, 9};
  rep(i, 4)
    cin >> N[i];
  sort(N.begin(), N.end());
  if (N == cor)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 384
n=int(input())
x=[i for i in range(n+3)]
x[0]=0
x[1]=1
i=2
while i<=n+1:
    j=2*i
    if x[i]==i:
        
        while j<=n+1:
            if x[j]==j:x[j]=i
            j+=i
    i+=1
def f(k):
    if k==1:
        return 1

    z=[]
    p=x[k]
    m=1
    ans=1
    while k>=2:
        k=k//p
        if p==x[k]:
            m+=1
        else:
            z.append(m)
            m=1
            p=x[k]

    for i in range(len(z)):
        ans*=z[i]+1
    return ans
s=0
for i in range(1,n+1):
    s+=i*f(i)
print(s)


Measured memory_bytes: 225380
import itertools
import math
from collections import defaultdict

def input_ints():
    return list(map(int, input().split()))

def solve():
    n, = input_ints()
    a = input_ints()
    ans = 1
    for x in a:
        ans = (ans * x)
        ans = min(10 ** 18 + 1, ans)
    if ans > 10 ** 18:
        ans = -1
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 22416
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int h;
	int max = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> h;

		if (max <= h) {
			ans++;
			max = h;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
typedef long long LL;
int main()
{ 
    int n;
    LL k;
    cin>>n>>k;
    LL a[n];
    LL f[n];
    for(int i=0;i<n;i++){cin>>a[i];}
    for(int i=0;i<n;i++){cin>>f[i];}
    sort(a,a+n);
    reverse(a,a+n);
    sort(f,f+n);
    LL ans_min=0;
    LL ans_max=1000000000000;
    //二分探査
    int flag=0;
    while(ans_max!=ans_min&&flag<2){
        LL m=(ans_max+ans_min)/2;
        if(ans_min==m){flag++;}
        LL s=0;
        for(int i=0;i<n;i++){
            LL x;
            x=m/f[i];
            if(x<a[i]){s=s+a[i]-x;}
        }
        if(k<s){ans_min=m;}
        else{ans_max=m;}
    }
    cout<<ans_max<<endl;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
 
ll n;
ll Main() {
    cin >> n;
    ll ans = 0;
    
    if(n>=30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3640
import math
from functools import reduce
import itertools



def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k = int(input())
a = list(itertools.combinations_with_replacement(range(1,k+1), 3))

#print(a)
ans = 0
for i in a:
    #print(i)
    if len(set(i)) == 1:
        num = 1
    elif len(set(i)) == 2:
        num = 3 
    else:
        num = 6
    ans += gcd_list(i)*num

print(ans)

Measured memory_bytes: 105952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

const int maxn = 2e5 + 10;
int fmin[20][maxn] , fmax[20][maxn];
int a[maxn] , LOG[maxn];
bool ok[maxn];

int n , k;

int ask_min(int l , int r){
	int t = LOG[r - l + 1];
	return min(fmin[t][l] , fmin[t][r - (1 << t) + 1]);
}

int ask_max(int l , int r){
	int t = LOG[r - l + 1];
	return max(fmax[t][l] , fmax[t][r - (1 << t) + 1]);
}

int main(){
	ios::sync_with_stdio(0);
	cin >> n >> k;
	for(int i = 1 ; i <= n ; ++ i){
		cin >> a[i];
		fmin[0][i] = fmax[0][i] = a[i];
	}
	for(int i = 1 ; (1 << i) <= n ; ++ i)
		for(int j = 1 ; j + (1 << i) - 1 <= n ; ++ j){
			fmin[i][j] = min(fmin[i - 1][j] , fmin[i - 1][j + (1 << (i - 1))]);
			fmax[i][j] = max(fmax[i - 1][j] , fmax[i - 1][j + (1 << (i - 1))]);
		}
	int L = 1 , R = 1;
	while(L <= n){
		if(R < L) R = L;
		while(R < n && a[R + 1] > a[R])
			R ++;
		ok[L] = ((R - L + 1) >= k);
		L ++;
	}
	LOG[1] = 0;
	for(int i = 2 ; i <= n ; ++ i)
		LOG[i] = LOG[i >> 1] + 1;
	int ans = 0 , cnt = 0;
	if(ok[1])
		cnt ++;
	else
		ans = 1; 
	for(int i = 1 ; i <= n - k ; ++ i){
		if(ok[i + 1])
			cnt ++;
		else if(a[i] == ask_min(i , i + k - 1) && a[i + k] == ask_max(i + 1 , i + k))
			continue;
		else
			ans ++;
	}
	cout << ans + (cnt > 0) << endl;
	return 0;
}

Measured memory_bytes: 33024
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    IN(ll, Q);
    ll S = 0;
    vi dp(1e5 + 1);
    FOR(a, A)
    {
        ++dp[a];
        S += a;
    }
    REP(i, Q)
    {
        IN(ll, B);
        IN(ll, C);
        dp[C] += dp[B];
        S += dp[B] * (C - B);
        dp[B] = 0;
        OUT(S);
    }
}

Measured memory_bytes: 4840
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char mat[102][102];

int main()
{
	int n, i, k, u, v;

	n = in();
	for (i = 0; i < n; i++) {
		u = in()-1;
		k = in();
		while (k--) {
			v = in()-1;
			mat[u][v] = 1;
		}
	}
	for (u = 0; u < n; u++) {
		pc('0'+mat[u][0]);
		for (v = 1; v < n; v++) pc(' '), pc('0'+mat[u][v]);
		pc('\n');
	}
	return 0;
}



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

int main(){
  int X,Y;
  cin >> X >> Y;
  if(Y%2 != 0){
    cout << "No";
    return 0;
  }
  int a = (X*4 - Y)/2;
  int b = X-a;
  if(a>=0 && b>=0) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
int main()
{
	lld n,ans=0,x;
	vlld v;
	cin>>n;
	rep(i,1,n+1) cin>>x,v.pb(x);
	sort(all(v));
	cout<<v[n-1]-v[0];
	return 0;
}

Measured memory_bytes: 256
while (n=gets.to_i)!=0
  mat=Array.new(n+1){Array.new(n+1,0)}
  n.times.with_index do |id|
    mat[id]=gets.split.map(&:to_i)
    mat[id][n]=mat[id].inject(:+)
    (n+1).times.with_index do |id2|
      mat[n][id2]+=mat[id][id2]
    end
  end
  mat.each do |line|
    line.map!{|ss|ss=format("%5d",ss)}
  end
  mat.each do |line|
    puts line.join
  end
end

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

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long a, b;
    scan(a, b);
    auto cd = common_divisers(a, b);
    long cnt;
    foreach (i; iota(cd.length))
    {
        bool disjoint = true;
        foreach (j; iota(1, i))
        {
            disjoint = disjoint && (cd[i] % cd[j]);
        }
        if (disjoint)
            cnt++;
    }
    cnt.writeln();
}

auto divisers(long t)
{
    auto ret = new long[](0);
    long iter = 1;
    while (iter ^^ 2 <= t)
    {
        if (t % iter == 0)
        {
            ret ~= iter;
            ret ~= t / iter;
        }

        iter++;
    }
    ret.sort();
    ret.length -= ret.uniq.copy(ret).length;
    return ret;
}

auto common_divisers(long a, long b)
{
    auto a_divs = a.divisers();
    auto b_divs = b.divisers();
    auto common_set = new long[](0);
    long a_iter, b_iter;
    while (a_iter < a_divs.length && b_iter < b_divs.length)
    {
        if (a_divs[a_iter] == b_divs[b_iter])
        {
            common_set ~= a_divs[a_iter];
            a_iter++, b_iter++;
        }
        else if (a_divs[a_iter] < b_divs[b_iter])
            a_iter++;
        else
            b_iter++;
    }
    return common_set;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 508
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	let sum = 0;
  	for(let i = 0; i<tmp.length; i++){
      sum += parseInt(tmp[i]);
    }
  	//console.log(sum);
  	let left = 0;
  	let arr =[];
  	for(let i = 0; i<tmp.length; i++){
      left += parseInt(tmp[i]);
      let right = sum - left;
      let sa = Math.abs(left-right);
      arr.push(sa);
    }
  	console.log(Math.min.apply(null, arr));

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(void) {
    string s, p;
    bool flag = false;
    getline(cin, s);
    getline(cin, p);
    s += s;
    for (int i = 0; i < s.size() - p.size(); i++) {
        if (s.substr(i, p.size()) == p) {
            flag = true;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1184
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	string s;
	cin >> a >> b >> s;
	rep(i,s.size()){
		if(i < a || a < i){
			if(s[i] == '-'){
				cout << "No" << endl;
				return 0;
			}
		}
		else{
			if(s[i] != '-'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3616