akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, x, y;
  double ans;
  cin>>a>>b>>x>>y;
  ans = (double)a*b/2;
  printf("%.6lf ",ans);
  if(x*2 == a && y*2 == b)
      cout<<"1";
  else
      cout<<"0";

  system("pause");
  return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  int p[8]= {0};
  int q = 0;
  for(int i = 0; i< N; i++){
  if(a.at(i)<400){
    p[0]++;
  }
  else if(a.at(i)<800){
    p[1]++;
  }
  else if(a.at(i)<1200){
    p[2]++;
  }
  else if(a.at(i)<1600){
    p[3]++;
  }
  else if(a.at(i)<2000){
    p[4]++;
  }
  else if(a.at(i)<2400){
    p[5]++;
  }
  else if(a.at(i)<2800){
    p[6]++;
  }
  else if(a.at(i)<3200){
    p[7]++;
  }
  else{
    q++;
  }
}
int ans = 0;
for(int i = 0; i<8;i++){
  if(p[i]!=0){
    ans++;
  }
}
if(ans==0){
  if(q>0){
  cout << 1 << " " << q << endl;
}
else{
  cout << 0 <<" "<< 0 << endl;
}
}
else{
  cout << ans<< " " << ans+q << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N, 0);
    rep(i, N) cin >> a[i];

    rep(j, N) {
        cout << a[j];
        if (j != N-1) cout << " ";
        else cout << "\n";
    }
    reps(i, 1, N) {
        ll key = a[i];
        // a[0:i-1]の適切な場所に挿入
        ll j = i-1;
        while (a[j]>key) {
            a[j+1] = a[j];
            j--;
            if (j < 0) break;
        }
        // a[j]<=keyとなったとき
        a[j+1] = key;

        rep(j, N) {
            cout << a[j];
            if (j != N-1) cout << " ";
            else cout << "\n";
        }
    }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region UnionFind
struct UnionFind
{
    vector<int> d;
    // d[x] is the index of the parent of x
    // d[x] is -size if x is a root

    UnionFind(int n) : d(vector<int>(n, -1)) {}
    int root(int x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (d[x] > d[y])
            swap(x, y); // x always bigger tree

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x) { return -d[root(x)]; }
};
#pragma endregion

struct sphere
{
    double x, y, z, r;
    sphere(double xx = 0, double yy = 0, double zz = 0, double rr = 0) : x(xx), y(yy), z(zz), r(rr) {}
    double dist(sphere &other)
    {
        double dx = x - other.x, dy = y - other.y, dz = z - other.z;
        return sqrt(dx * dx + dy * dy + dz * dz) - r - other.r;
    }
    bool intersect(sphere &other)
    {
        return dist(other) < 0;
    }
};

struct edge
{
    int s, t;
    double d;
    edge(int ss, int tt, double dd) : s(ss), t(tt), d(dd) {}
    bool operator>(const edge &r) const { return d > r.d; }
};

int main()
{
    int n;
    while (cin >> n, n)
    {
        vector<sphere> p(n);
        UnionFind uft(n);
        rep(i, n) cin >> p[i].x >> p[i].y >> p[i].z >> p[i].r;
        priority_queue<edge, vector<edge>, greater<edge>> q;
        rep(i, n) rep(j, n)
        {
            if (p[i].intersect(p[j]))
            {
                uft.unite(i, j);
            }
            else
            {
                q.push(edge(i, j, p[i].dist(p[j])));
            }
        }

        long double ans = 0;
        while (q.size())
        {
            edge e = q.top();
            q.pop();
            if (uft.unite(e.s, e.t))
            {
                ans += e.d;
            }
        }

        cout << fixed << setprecision(3) << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3484
"""
双対セグ木
アクセスは0-indexed, 内部のツリーは 1-indexed
つまりすべての和は tree[0]
関数は閉区間
作用素は右から作用とする

引数：
    N: 処理する区間の長さ
    compose: 作用素を合成させる関数 (max, min, __add__,ラムダ式,関数定義など)
    UNIT: 恒等作用素
    funcval(x,f) = f(x)
"""

class segment_tree:
    def __init__(self, N, compose, funcval, UNIT=None):
        self.compose = compose
        self.UNIT = UNIT
        self.funcval = funcval

        self.h = (N-1).bit_length() #木の高さ
        self.N0 = 1<<self.h #木の横幅 >= N
        self.laz = [self.UNIT]*(2*self.N0) #作用素の木
        self.val = None #値の配列

    #初期値の配列を作る
    def build(self,initial):
        self.val = initial[:]

    #laz[k] を子に伝える、
    def propagate(self,k):
        if self.laz[k] == self.UNIT: return;
        if self.N0 <= k:
            self.val[k-self.N0] = self.funcval(self.val[k-self.N0], self.laz[k])
            self.laz[k] = self.UNIT
        else:
            self.laz[(k<<1)  ] = self.compose(self.laz[(k<<1)  ],self.laz[k]);
            self.laz[(k<<1)+1] = self.compose(self.laz[(k<<1)+1],self.laz[k]);
            self.laz[k] = self.UNIT;
    
    # laz[k]およびその上に位置する作用素をすべて伝播
    def thrust(self,k):
        for i in range(self.h,-1,-1): self.propagate(k>>i)

    # 区間[l,r]に関数 f を作用
    def update(self, L,R,f):
        L += self.N0; R += self.N0+1
        """まず伝播させる（オペレータが可換なら必要ない）"""
        self.thrust(L)
        self.thrust(R-1)
        #登りながら関数 f を合成
        while L < R:
            if R & 1:
                R -= 1
                self.laz[R] = self.compose(self.laz[R],f)
            if L & 1:
                self.laz[L] = self.compose(self.laz[L],f)
                L += 1
            L >>= 1; R >>= 1
    
    # values[k] を取得。
    def point_get(self, k):
        res = self.val[k]
        k += self.N0
        while k:
            res = self.funcval(res, self.laz[k])
            k //= 2
        return res
    
    # values[k] = x 代入する
    def point_set(self, k): 
        self.thrust(k)
        values[k] = x



###########################################################################
#日経2020予選D

###########################################################################

# coding: utf-8
# Your code here!
 
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n,m = [int(i) for i in readline().split()]
lrc = [tuple(int(i) for i in readline().split()) for _ in range(m)]
lrc.sort()

compose = lambda f,g: min(f,g)
funcval = lambda x,f: min(x,f)
UNIT = INF = 10**18

seg = segment_tree(n, compose, funcval, UNIT)
seg.build([0]+[INF]*(n-1))

for l,r,c in lrc:
    l -= 1
    r -= 1
    v = seg.point_get(l)
    seg.update(l+1,r,v+c)

ans = seg.point_get(n-1)

if ans != INF:
    print(ans)
else:
    print(-1)





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

long c[22], M;
struct Mat {
	vector<long> a;
	int s;
	Mat(int s) :s(s), a(s*s) {}
	const Mat &operator=(long x) {
		for (int i = 0; i < s; i++)
			for (int j = 0; j < s; j++)
				(*this)(i, j) = i == j ? x : 0;
		return *this;
	}
	long &operator()(int i, int j) {
		return a[i*s + j];
	}
	const long &operator()(int i, int j) const {
		return a[i*s + j];
	}
	const Mat &operator()(const Mat &m, const Mat &n) {
		for (int i = 0; i < s; i++)
			for (int j = 0; j < s; j++)
				for (int k = 0; k < s; k++)
					((*this)(i, k) += m(i, j)*n(j, k)) %= M;
		return *this;
	}
	const Mat &operator*=(const Mat &m) {
		Mat t(s);
		return *this = t(*this, m);
	}
};
int main() {
	long L, a, b;
	cin >> L >> a >> b >> M;
	for (long i = 0, j = 1; i < 18; i++, j *= 10) {
		c[i] = min(L, (j - a + b - 1) / b);
		if (c[i] < 0) c[i] = 0;
		if (i&&a + b * c[i] >= j * 10)
			c[i] = c[i - 1];
	}
	c[18] = L;
	long t = 1, S = 0;
	for (int e = 0; e < 18; e++) {
		(t *= 10) %= M;
		Mat A(3), B(3);
		A = 1;
		A(0, 1) = 1;
		A(1, 2) = b;
		A(0, 0) = t;
		B = 1;
		[](auto &x, auto &y, long k) {
			for (;;) {
				if (k & 1) y *= x;
				k >>= 1;
				if (!k) break;
				x *= x;
			}
		}(A, B, c[e + 1] - c[e]);
		S = (S*B(0, 0) + a * B(0, 1) + B(0, 2)) % M;
		(a += B(1, 2)) %= M;
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

l = 0
r = sum(a)

d = 2 * 10 ** 9 + 1

for i in range(n - 1):
    l += a[i]
    r -= a[i]
    d = min(d, abs(l - r))

print(d)


Measured memory_bytes: 24828
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx;
	int dy = ty - sy;
	for (int i=0; i<dx; i++) cout << 'R';
	for (int i=0; i<dy; i++) cout << 'U';
	for (int i=0; i<dx; i++) cout << 'L';
	for (int i=0; i<dy; i++) cout << 'D';
	cout << 'D';
	for (int i=0; i<=dx; i++) cout << 'R';
	for (int i=0; i<=dy; i++) cout << 'U';
	cout << 'L';
	cout << 'U';
	for (int i=0; i<=dx; i++) cout << 'L';
	for (int i=0; i<=dy; i++) cout << 'D';
	cout << 'R';
}

Measured memory_bytes: 256
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, T = map(int, input().split())
time = [0] * (T + 2)
for _ in range(N):
    l, r = map(int, input().split())
    time[l] += 1
    time[r] -= 1

print(max(accumulate(time)))


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

int main() {
	int n,count=0, mini= 1000000;
  	string s;
  	cin >> n >> s;
  	for(int i = 1; i < n; i++) {
    	if(s[i] == 'E')
          	count++;
    }
  	if(mini > count)
      	mini = count;
  	for(int i = 1; i < n; i++) {
    	if(s[i] == 'E')
          	count--;
      	if(s[i-1] == 'W')
			count++;
		if(mini > count)
			mini = count;
    }
  	cout << mini << endl;
}


Measured memory_bytes: 900
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

cnt = [0]*(2*10**5)#何回出たか
cnt2 = [0]*(2*10**5)#何回目に出てきたか
t = []
nxt = 0
loop = 0

for i in range(2*10**5):
    cnt[nxt] += 1
    if cnt[nxt] >= 2:
        loop = i - cnt2[nxt]
        modC = cnt2[nxt]
        break
    cnt2[nxt] = i
    t.append(nxt)
    nxt = a[nxt]

modK = (k-modC)%loop

if k < modC:
    print(t[k] + 1)
else:
    print(t[modC + modK] + 1)

Measured memory_bytes: 32292
#
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    d = list(map(int, input().split()))
    d.sort()
    m1 = d[n//2 - 1]
    m2 = d[n//2]
    # print('{} {}'.format(m1, m2))
    if m1 == m2:
        print(0)
    else:
        ans = m2 - m1
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 52684
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#N, M = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

xorA = 0
for a in A:
    xorA ^= a

answer = []
for a in A:
    answer.append(xorA ^ a)
    
print(*answer)

Measured memory_bytes: 107004
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a_sum(n+1, 0);
    vector<ll> b_sum(m+1, 0);
    rep(i, n) {
        ll a;
        cin >> a;
        a_sum[i + 1] = a_sum[i] + a;
    }
    rep(i, m) {
        ll b;
        cin >> b;
        b_sum[i + 1] = b_sum[i] + b;
    }

    ll ans = 0;
    for (ll i = 0; i <= n; i++) {
        if (a_sum[i] > k) break;
        ll t = k - a_sum[i];
        ll left = 0;
        ll right = m + 1;
        while ((right - left) > 1) {
            ll middle = (left + right) / 2;
            if (b_sum[middle] > t) {
                right = middle;
            }
            else {
                left = middle;
            }
        }
        ans = max(ans, i + left);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int b[10001];
  b[0]=0;
  for(int i=1; i<10001; i++) {
    b[i]=b[i-1]+i;
  }
  int n;
  while(cin >> n && n) {
    vector<int> a;
    int sum=0;
    for(int i=0; i<n; i++) {
      int x;
      cin >> x;
      a.push_back(x);
      sum+=x;
    }
    bool ck=false;
    for(int i=1; i<10001; i++) {
      if(sum<b[i]) break;
      if(sum==b[i]) ck=true;
    }
    if(!ck) {
      cout << "-1" << endl;
      continue;
    }
    int cnt=0;
    while(1) {
      ck=true;
      for(int i=0; i<a.size(); i++) {
	if(a[i]!=i+1) {
	  ck=false;
	}
	a[i]--;
      }
      if(ck) break;
      a.push_back(a.size());
      a.erase(remove(a.begin(), a.end(),0),a.end());
      cnt++;
      if(cnt>10000) break;
    }
    if(ck) cout << cnt << endl;
    else cout << "-1" << endl;
  }
  return 0;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << '\n'

signed main ( ) {

    long n;
    read n;

    long ans = 0x3f3f3f3f3f3f3f3fLL;

    for ( long i = 1; i * i <= n; i++ ) {
        if ( n % i == 0 ) {
            ans = min ( ans, i+(n/i)-2 );
        }
    }

    echo ans fin;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n; cin >> n;
    ll rem = 0;
    rep (i, n.size()) {
        rem = (rem + (int)(n[i] - '0')) % 9;
    }
    cout << (rem == 0 ? "Yes\n" : "No\n");
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const ll MOD = 998244353;

bool cmp(vi& a, vi& b) {
	if (a.size() > b.size()) return 0;
	if (a.size() < b.size()) return 1;
	int n = a.size();
	rep(i, n) {
		if (a[n-1-i]==b[n-1-i]) continue;
		if (a[n-1-i] > b[n-1-i]) return 0;
		else return 1;
	}
	return 0;
}

vi gcd(vi a, vi b) {
	if (cmp(a, b)) {
		swap(a, b);
	}

	bool zero = true;
	for (auto x : b) {
		if (x != 0) zero = false;
	}
	if (zero) return a;

	int d = a.size() - b.size();
	vi res = a;
	rep(i, b.size()) {
		res[i + d] ^= b[i];
	}

	while (res.size() && res.back() == 0) {
		res.pop_back();
	}
	return gcd(res, b);
}

vi get(string s) {
	reverse(ALL(s));
	vi res;
	for (char c : s) {
		res.pb(c - '0');
	}
	return res;
}

int main() {
	int N; cin >> N;
	string sx; cin >> sx;
	vi x = get(sx);
	vi g;

	rep(i, N) {
		string s; cin >> s;
		vi vec = get(s);
		g = gcd(g, vec);
	}

	int dg = g.size(), dx = x.size();

	if (dg > dx) {
		puts("1");
		return 0;
	}

	ll ans = 0;
	for (int i = dx-1; i >= dg-1; --i) {
		ans = ans * 2 + x[i];
		ans %= MOD;
	}

	vi xx(dx);

	for (int i = dx-1; i >= dg-1; --i) {
		if (xx[i] != x[i]) {
			for (int j = 0; j < dg; ++j) {
				xx[i-j] ^= g[dg-1-j];
			}
		}
	}

	bool ok = true;

	for (int j = dg-1; j >= 0; --j) {
		if (x[j] == xx[j]) {
			continue;
		} else if (x[j] > xx[j]) {
			ok = true;
			break;
		} else {
			ok = false;
			break;
		}
	}

	if (ok) { ans = (ans + 1) % MOD; }

	cout << ans << endl;

	return 0;
}

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

int main() {
	int N;
    double ans = 0;
	cin >> N;
	vector<double> data(N);
	rep(i,N){
		cin >> data.at(i);
	}
    sort(data.begin(),data.end());
    rep(i,N-1){//235
        ans = ((double)data.at(i) + (double)data.at(i+1))/2.0000;
        data.at(i+1) = ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
  li, ri = map(int, input().split())
  l.append(li)
  r.append(ri)
maxl = -10**5-1
minr = 10**5+1
for i in range(m):
  maxl = max(maxl, l[i])
  minr = min(minr, r[i])
print(max(minr - maxl + 1, 0))

Measured memory_bytes: 11016
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    string n; cin >> n;
    if(n[n.length()-1]=='2'||n[n.length()-1]=='4'||n[n.length()-1]=='5'||n[n.length()-1]=='7'||n[n.length()-1]=='9') {
        cout << "hon" << endl;
    } else if (n[n.length()-1]=='0'||n[n.length()-1]=='1'||n[n.length()-1]=='6'||n[n.length()-1]=='8') {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
def main():
    N, K, *xn = map(int, open(0).read().split())
    ans = int(1e9 + 7)
    for xl, xr in zip(xn, xn[K - 1:]):
        t = xr - xl + min(abs(xl), abs(xr))
        ans = t if t < ans else ans
    print(ans)
    return


main()


Measured memory_bytes: 14052
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

static const int MAX=200000;

int main(){
    vector<int> R(MAX);
    int n;
    cin >> n;
    for(int i=0;i<n;i++) cin >> R.at(i);
    int maxv=-2000000000;
    int minv=R.at(0);
    for(int i=1;i<n;i++){
        maxv=max(maxv,R.at(i)-minv);
        minv=min(minv,R.at(i));
    }
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3436
n = int(input())
t, a = map(int, input().split())
h = [int(_) for _ in input().split()]

nearest = 100000000
ans = 0

for idx, i in enumerate(h):
    temp = t - i * 0.006
    temp = abs(a-temp)
    if nearest > temp:
        nearest = temp
        ans = idx + 1

print(ans)

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, X; cin >> N >> X;
	int cur = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (cur <= X);
		int L; cin >> L;
		cur += L;
	}
	ans += (cur <= X);
	cout << ans << endl;

	return 0;
}

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

int main(){
  int N;
  int x_ = 0;
  int y_ = 0;
  int diff;
  int diff_t = 0;
  cin >> N;
  int t[N], x[N], y[N];
  for(int i=0;i<N;i++) cin >> t[i] >> x[i] >> y[i];
  for(int i=0;i<N;i++){
	diff_t = t[i] - diff_t;
    diff = abs(x_-x[i]) + abs(y_-y[i]);
    if(diff<=diff_t){
	  if((diff_t-diff)%2!=0){
	    cout << "No" << endl;
		return 0;
	  }
	}else{
	  cout << "No" << endl;
	  return 0;
	}
	diff_t = t[i]; //これするの完全に忘れてた
    x_ = x[i];
	y_ = y[i];
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
//                        Bismillahir Rahmanir Rahim
//ALGO:
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define MX 1000010
#define mod  998244353
#define dout if(debug) cout
#define FR(i, n) for(int i=0; i<n; i++)
#define FOR(i, n) for(int i=1; i<=n; i++)
const double Pi=acos(-1);
using namespace std;
int debug=01;
void solve(){
    ll n, k;
    cin>>n>>k;
    ll x[k], y[k], cnt[n+1]={0};
    for(ll i=0; i<k; i++)cin>>x[i]>>y[i];
    cnt[1]=1;
    ll sum=0;
    for(ll i=2; i<=n; i++){
        for(ll j=0; j<k; j++){
            if(i-x[j]>0)sum=(sum+cnt[i-x[j]])%mod;
            if(i-y[j]-1>0)sum=(sum-cnt[i-y[j]-1]+mod)%mod;
        }
        cnt[i]=sum;
    }
    cout<<cnt[n];
}
int main() {
    Fast
    int tst=1;
    //cin>>tst;
    for(int T=1; T<=tst; T++){
        //cout<<"Case "<<T<<": ";
        solve();
    }
}


Measured memory_bytes: 5168
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

modS = [0]
for i in A:
    modS.append((modS[-1] + i) % MOD)

ans = 0
for i in range(1, N + 1):
    count = modS[-1] - modS[i]
    if count < 0:
        count = MOD + count
    ans = (ans + (A[i - 1] * count % MOD)) % MOD

print(ans)

Measured memory_bytes: 107136
import heapq
class Graph():
    def __init__(self,vertex_num,node_num,naive_input,start_zero=True,direction=False):
        self.vertex_num=vertex_num
        self.node_num=node_num
        #nodeには入力時のインデックスも含む
        #[接続ノード , インッデクス]のarray
        node=[{} for _ in range(vertex_num)]
        for i in range(node_num):
            u,v,w=naive_input[i]
            if not start_zero:
                u-=1
                v-=1
            node[u][v]={"weight":w,"index":i}
            #node[v][u]={"weight":w,"index":i}
            if not direction:
                node[v][u]={"weight":w,"index":i}
                #node[u][v]["reverse"]={"weight":w,"index":i}
        self.node=node
        #それぞれの頂点の辺の数
        self.node_num_arr=list(map(lambda x:len(x),node))

    def djikstra(self,s=0):
        distance=[float("inf") for _ in range(self.vertex_num)]
        distance[s]=0
        #visitedにしたけど正確には訪問済みではなく最短距離確定済みが適切
        #いい名前教えて
        #visited_vertex=[False for _ in range(self.vertex_num)]
        #visited_vertex[s]=True
        visited_vertex={s}
        before_vertex=[float("inf") for _ in range(self.vertex_num)]
        node_index_arr=[float("inf") for _ in range(self.vertex_num)]
        while len(visited_vertex)<self.vertex_num:
            #will_visit_node=cal_will_visit_node(self.node,visited_vertex)
            will_visit_node=set()
            for now_node_num in visited_vertex:
                for next_node_num in self.node[now_node_num].keys():
                    if next_node_num in visited_vertex:
                        continue
                    will_visit_node.add(next_node_num)
                    next_node=self.node[now_node_num][next_node_num]
                    cal_d=distance[now_node_num]+next_node["weight"]
                    if cal_d<distance[next_node_num]:
                        distance[next_node_num]=cal_d
                        before_vertex[next_node_num]=now_node_num
                        node_index_arr[next_node_num]=next_node["index"]
                    #distance_vertex[distance[next_node_num]]=next_node_num
                    #heapq.heappush(min_distance_heap,distance[next_node_num])
            #add_vertex=distance_vertex[min_distance_heap[0]]
            add_vertex=[float("inf"),float("inf")]
            for i in will_visit_node:
                if distance[i]<add_vertex[1]:
                    add_vertex[0]=i
                    add_vertex[1]=distance[i]
            visited_vertex.add(add_vertex[0])
        return node_index_arr
        





n,m=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(m)]
G=Graph(n,m,a,start_zero=False)  
ans=[True for _ in range(m)]
for i in range(n):
    tmp=G.djikstra(i)
    for j in tmp:
        if j!=float("inf"):
            ans[j]=False

print(sum(ans))

            


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;

  vector<P> p;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    p.emplace_back(x, y);
  }

  ll is_odd = (p[0].first + p[0].second) % 2;
  is_odd += 2;
  is_odd %= 2;
  for (const auto& it : p) {
    ll tmp = (it.first + it.second) % 2;
    tmp += 2;
    tmp %= 2;

    if (is_odd != tmp) {
      cout << -1 << endl;
      return 0;
    }
  }

  vll arms;
  ll tmp = 1;
  rep(i, 34) {
    arms.push_back(tmp);
    tmp <<= 1;
  }
  reverse(all(arms));

  if (is_odd) {
    cout << arms.size() << endl;
  } else {
    cout << arms.size() + 1 << endl;
    cout << 1 << " ";
  }

  for (auto arm : arms) {
    cout << arm << " ";
  }
  cout << endl;

  for (auto it : p) {
    if (!is_odd) {
      it.first--;
      cout << "R";
    }
    ll x = it.first;
    ll y = it.second;

    for (auto arm : arms) {
      if (abs(x) > abs(y)) {
        // 左右優先
        if (x > 0) {
          cout << "R";
          x -= arm;
        } else {
          cout << "L";
          x += arm;
        }
      } else {
        // 上下優先
        if (y > 0) {
          cout << "U";
          y -= arm;
        } else {
          cout << "D";
          y += arm;
        }
      }
    }
    cout << endl;
    // cout << x << " " << y << endl;
  }

  return 0;
}


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

int n, k;
long long A[200200];

int main(){
	scanf("%d%d", &n, &k);
	rep(i, n) scanf("%lld", &A[i]);
	sort(A, A+n);
	long long sum = 0LL;
	rep(i, n-k) sum += A[i];
	cout << sum << endl;
	return 0;
}

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

int min(int a,int b){
  return a<b?a:b;
}

typedef struct RMQ{
  int *a;
  int size;
} segTree;

segTree* newRMQ(const int n){
  int k=1;
  while(k<n) k*=2;
  segTree *s=(segTree *)malloc(sizeof(segTree));
  s->a=(int *)calloc(2*k,sizeof(int));
  s->size=k;
  for(int i=1;i<2*k;i++) s->a[i]=2147483647;
  return s;
}

void update(segTree *s,int x,int v){
  int *a=s->a;
  x+=s->size;
  a[x]=v;
  x/=2;
  while(x>=1){
    a[x]=min(a[2*x],a[2*x+1]);
    x/=2;
  }
}

int find(segTree *s,int l,int r){
  int res=2147483647;
  for(l+=s->size,r+=s->size;l<r;l>>=1,r>>=1){
    if(l&1) res=min(res,s->a[l++]);
    if(r&1) res=min(res,s->a[--r]);
  }
  return res;
}

typedef long long int int64;

void run(void){
  int n,x;
  scanf("%d%d",&n,&x);
  int *a=(int *)calloc(n,sizeof(int));
  int i,j;
  for(i=0;i<n;i++) scanf("%d",a+i);
  segTree *s=newRMQ(2*n);
  for(i=0;i<n;i++){
    update(s,i,a[i]);
    update(s,i+n,a[i]);
  }
  int64 ans=1000000000LL*n;
  for(i=0;i<n;i++){
    int64 sum=(int64)x*i;
    for(j=0;j<n;j++){
      sum+=find(s,j+n-i,j+n+1);
    }
    if(ans>sum) ans=sum;
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
A,B = map(int,input().split())
a = [] # 回文数の個数を入れるリストの作成
for i in range(A,B+1):
  if str(i) == str(i)[::-1]: #回文数を発見した場合
    a.append(1) #リストaに1を追加する
  else: #iが回文数でない場合
    pass # 何もしない
  
print(sum(a)) #リスト内の1をすべて足す
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    string n; cin>>n;
    ll t = 0;
    for(int i=0; i<n.length(); ++i){
        t = t + (n[i]-'0');
        t = t %9;
    }
    if(t%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



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

#define ll long long
int main() {

  int N;
  cin >> N;
  int A[N], B[N], C[N];
  
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    A[i];
  }
  sort(A, A+N);
  for (ll i = 0; i < N; i++) {
    cin >> B[i];
  }
  sort(B, B+N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    C[i];
  }
  sort(C, C+N);
  
  
  ll ans = 0;
  // Bからきめる
  for (ll i = 0; i < N; i++) {
    ll a, c;
    // Aのきめかた
    a = lower_bound(A, A+N, B[i]) - A;
    
    // Cのきめかた
    c = N - (upper_bound(C, C+N, B[i]) - C);
    
    ans += a * c;
    
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4760
A, B, C, X, Y = map(int, input().split())

separate = A * X + B * Y
middle = X * 2 * C + B * (Y - X) if min(X, Y) == X else Y * 2 * C + A * (X - Y)
whole = max(X, Y) * 2 * C

print(min(separate, middle, whole))

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

int main() {
  string S, T;
  cin>>S>>T;
  bool ans=false;
  rep(i, S.size()) {
    if (S==T) {
      ans = true;
      break;
    }
    S=S.back()+S.substr(0,S.size()-1);
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		WriteLine(I[0] * I[1] % 2 == 0 ? "Even" : "Odd");
	}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long  LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef priority_queue<ppr,Vppr,greater<ppr> > PpprQ;
const int SIZE=5+1e+5;
const LL INF=1LL<<60;
const ld eps=1e-6;
const LL p=7+1e+9;
PpprQ qu;
PQ legi;
LL least[SIZE];
LL N,M,K,D,SS,a[11],b[11],c[11];
LL nums[SIZE];
bool checked[101][101][101];
bool isAble[101][101][101];
bool tekitou(int now,int s,int e){
	if(s==e) return a[now]==nums[s];
	if(checked[now][s][e]) return isAble[now][s][e];
	checked[now][s][e]=true;
	FOR(i,s,e)
	 if(tekitou(b[now],s,i)&&tekitou(c[now],i+1,e)) return isAble[now][s][e]=true;
	return isAble[now][s][e]=false;
}
int main(){
	cin >> N;
	REP(i,N)
		cin >> nums[i];
	cin >> M;
	FOR(i,1,M+1)
		cin >> a[i] >> b[i] >> c[i];
	if(tekitou(1,0,N-1)) cout <<"Yes" << endl;
	else cout <<"No" << endl;
	return 0;
}

Measured memory_bytes: 1372
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		if((long)A*B< N || N<(long)A+B-1){
			sb.append(-1);
		}
		else{
			int n = 0;
			for(int i=1;i<=A;i++){
				while(n + B + (A-i) > N)	B--;
				
				for(int j=n+B;j>n;j--){
					sb.append(j+" ");
				}
				n+=B;
			}
			
			sb.deleteCharAt(sb.length()-1);
		}
		System.out.println(sb);
	}
}


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

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

    bool prime[100010];
    rep(i, 100005)  prime[i] = true;
    prime[0] = false;
    prime[1] = false;
    rep(i, 100005) {
        if (prime[i]) {
            for (int j=2*i; j<=100005; j+=i) prime[j] = false;
        }
    }

    for (int x=X; x<=100005; x++) {
        if (prime[x]) {
            cout << x << endl;
            break;
        }
    }


    return 0;    
}



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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	double sum = 0;
	for(int i  =0; i<n; i++){
		cin>>a[i];
		sum+=a[i];
		}
	long long int dsum = 0;	
	int x = floor(sum/n);
	long long int psum = 0;
	int s = ceil(sum/n);
	for(int i  = 0; i<n; i++){
		dsum += (a[i]-x)*(a[i]-x);
		psum += (a[i]-s)*(a[i]-s);
		
		}	
	cout<<min(psum,dsum);	
		
	
	
	return 0;
	}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<ll> A(N); rep(i, N) cin >> A[i];

    vector<ll> sum(N+1);
    rep(i, N) sum[i+1] = sum[i] + A[i];

    ll ans = INFLL;
    for (int b2=1; b2<N-2; b2++) {
        int b1 = -1;
        {
            int ok = 0, ng = b2 - 1;
            while (abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                ll s1 = sum[mid+1], s2 = sum[b2+1] - sum[mid+1];
                (s1 <= s2 ? ok : ng ) = mid;
            }
            ll s1 = sum[ok+1], s2 = sum[b2+1] - sum[ok+1];
            ll ss1 = sum[ng+1], ss2 = sum[b2+1] - sum[ng+1];

            b1 = (abs(s2-s1) < abs(ss2-ss1) ? ok : ng);
        }

        int b3 = -1;
        {
            int ok = b2+1, ng = N - 1;
            while (abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                ll s1 = sum[mid+1] - sum[b2+1], s2 = sum[N] - sum[mid+1];
                (s1 <= s2 ? ok : ng ) = mid;
            }
            ll s1 = sum[ok+1] - sum[b2+1], s2 = sum[N] - sum[ok+1];
            ll ss1 = sum[ng+1] - sum[b2+1], ss2 = sum[N] - sum[ng+1];

            b3 = (abs(s2-s1) < abs(ss2-ss1) ? ok : ng);
        }

        ll s1 = sum[b1+1] - sum[0];
        ll s2 = sum[b2+1] - sum[b1+1];
        ll s3 = sum[b3+1] - sum[b2+1];
        ll s4 = sum[N] - sum[b3+1];


        // if (ans > max({s1, s2, s3, s4}) - min({s1, s2, s3, s4})) {
        //  cerr << "b1, b2, b3 = " << b1 << " " << b2 << " " << b3 << endl;
        //  cerr << "s1, s2, s3, s4 = " << s1 << " " << s2 << " " << s3 << " " << s4 << endl;
        // }
        ans = min(ans, max({s1, s2, s3, s4}) - min({s1, s2, s3, s4}));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int MOD = (int)1e9 + 7;
int add(int x, int y)
{
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}

const int N = 302;
int n, m;
vector<pii> a[N];
int dp[N][N][N];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d%d", &n, &m);
    while(m--)
    {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        a[r].push_back(mp(l, x));
    }

    dp[0][0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int x = 0; x < i; x++)
            for (int y = 0; y < i; y++)
            {
                dp[i][x][y] = add(dp[i][x][y], dp[i - 1][x][y]);
                if (i > 1)
                {
                    dp[i][i - 1][y] = add(dp[i][i - 1][y], dp[x][i - 1][y]);
                    dp[i][y][i - 1] = add(dp[i][y][i - 1], dp[x][y][i - 1]);
                }

                dp[x][i][y] = add(dp[x][i][y], dp[x][i - 1][y]);
                if (i > 1)
                {
                    dp[i - 1][i][y] = add(dp[i - 1][i][y], dp[i - 1][x][y]);
                    dp[y][i][i - 1] = add(dp[y][i][i - 1], dp[y][x][i - 1]);
                }

                dp[x][y][i] = add(dp[x][y][i], dp[x][y][i - 1]);
                if (i > 1)
                {
                    dp[i - 1][y][i] = add(dp[i - 1][y][i], dp[i - 1][y][x]);
                    dp[y][i - 1][i] = add(dp[y][i - 1][i], dp[y][i - 1][x]);
                }
            }

        for (int x = 0; x < i; x++)
            for (int y = 0; y < i; y++)
            {
                bool ok = true;
                for (pii q : a[i])
                {
                    int cnt = 1;
                    cnt += (x >= q.first);
                    cnt += (y >= q.first);
                    ok &= cnt == q.second;
                }
                if (!ok)
                    dp[i][x][y] = dp[x][i][y] = dp[x][y][i] = 0;
            }
    }

    int ans = 0;
    for (int x = 0; x < n; x++)
        for (int y = 0; y < n; y++)
        {
            ans = add(ans, dp[n][x][y]);
            ans = add(ans, dp[x][n][y]);
            ans = add(ans, dp[x][y][n]);
        }
    printf("%d\n", ans);

    return 0;
}

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

using namespace std;

class St{
public:
  int td, sc, pn, ac;

  St() {}
  St(int _td, int _sc, int _pn, int _ac): td(_td), sc(_sc), pn(_pn), ac(_ac) {}

  void print(){
    cout << td << " " << ac << " " << sc << endl;
  }
};

int t, r, p;

bool comp(const St& s1, const St& s2)
{
  if(s1.ac == s2.ac){
    if(s1.sc == s2.sc) return s1.td < s2.td;
    return s1.sc < s2.sc;
  }

  return s1.ac > s2.ac;
}

int main()
{
  string str;
  vector<St> vec;
  int td, pd, tm;
  bool a[51][11];
  int sv[51][11];

  while(cin>>t>>r>>p && t+r+p){
    for(int i = 0; i < t; ++i) vec.push_back(St(i+1, 0, 0, 0));
    fill(&a[0][0], &a[51][0], false);
    fill(&sv[0][0], &sv[51][0], 0);

    while(p--){
      cin >> td >> pd >> tm >> str;
      if(a[td][pd]) continue;

      if(str == "CORRECT"){
	a[td][pd] = true;
	++vec[td-1].ac;
	vec[td-1].sc += (tm+1200*sv[td][pd]);
      } else {
	++sv[td][pd];
	++vec[td-1].pn;
      }
    }
    sort(vec.begin(), vec.end(), comp);

    for(int i = 0; i < vec.size(); ++i)
      vec[i].print();

    vec.clear();
  }

  return 0;
}

Measured memory_bytes: 928
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int N;
    cin >> N;
    vector<int> A(N+2);
    A[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
    }
    A[N + 1] = 0;
    ll sum = 0;
    for (int i = 1; i <= N + 1;i++)
    {
        sum += abs(A[i] - A[i-1]);
    }
    for (int i = 1; i <= N; i++)
    {
        cout << sum + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) << endl;
    }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    ll n; std::cin >> n;
    vl cnt(n+1, 1);
    srep(i, 2, n+1) {
        for (int j = i; j <= n; j+=i) {
            cnt[j]++;
        }
    }

    ll ans = 0;
    rrep(k, n) {
        ans += cnt[k] * k;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 81332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int gcd(int a,int b){
    return (b?gcd(b,a%b):a);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    map<int,int> a;
    for(int i=0;i<n;i++){
        int d;cin >> d;
        a[d]++;
    }
    int m;cin >> m;
    for(int i=0;i<m;i++){
        int t;cin >> t;
        if(a[t]<1){
            cout << "NO" << endl;
            return 0;
        }
        a[t]--;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll test;
  cin >> test;
  ll ans=0;
  while(test--)
    {
      ll a,b;
      cin >> a >> b;
      ans+=(b-a+1);
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 

    fast;

    ll n;
    cin>>n;

    string s[n];
    ll t[n];
    ll ans=0;
    map<string,ll> m;

    for(ll i=0;i<n;i++)
    {
    	cin>>s[i]>>t[i];
    	m[s[i]]=i;
    }
    
    string c;
    cin>>c;
    ll id=m[c];

    for(ll i=id+1;i<n;i++)
    	ans+=t[i];
    cout<<ans<<endl;
  }

Measured memory_bytes: 256
S = input()
T = input()
buf =[]
for i in range(len(S)-len(T)+1):
    A=S[i:(i+len(T))]
    same = 0
    for j in range(len(T)):
        if A[j]==T[j]:
            same+=1
    buf.append(same)
print(len(T)-max(buf))

Measured memory_bytes: 9120
package main

import "fmt"

func main() {
	// Code for B - ss
	var S string
	fmt.Scanf("%s", &S)

	n := len(S)
	for i := n - 2; 0 < i; i -= 2 {
		if S[0:i/2] == S[i/2:i] {
			fmt.Println(i)
			break
		}
	}
}


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

int main()
{
    int n, ans = 0;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        mp[i + 1] = a;
        if (mp[a] == i + 1)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// 多重vectorを可変引数テンプレートで http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//

#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
    cin >> s;
    for(i64 i = 0; i < s.length(); ++i) cout << 'x';
    cout << endl;
}

Measured memory_bytes: 256