akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    int a, b;
    double x1, x2;
    cin >> a >> b;
    x1 = (a * 100) / 8.0;
    x2 = (b * 100) / 10.0;
    int f1 = floor(x1 * 0.08);
    int f2 = floor(x1 * 0.10);
    if (f1 == a && f2 == b)
    {
        cout << ceil(x1) << nl;
        return 0;
    }
    int s1 = floor(x2 * 0.08);
    int s2 = floor(x2 * 0.10);
    if (s1 == a && s2 == b)
    {
        cout << ceil(x2) << nl;
        return 0;
    }
    cout << -1 << nl;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int i,t;
    cin >> i >> t;
    cout << (double)i/(double)t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++){
    if((s.size()-i-1) % 2 == 0){
      int x= s.size()-i-1;
      int cnt=0;
      for(int j=0; j<x/2; j++){
        if(s[j] != s[x/2+j]) break;
        else cnt++;
      }
      if(cnt == x/2) {
        cout << cnt*2 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
// 2020-07-23 22:50:58
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int INF = 1e9;
int n, m, p;
vector<vector<pair<int, int> > > G; // to, cost
vector<int> dist, visited, reach;

void dfs(int u) {
  if(visited[u]) return;
  visited[u] = 1;
  for(auto e : G[u]) {
    int v = e.first;
    if(visited[v]) continue;
    dfs(v);
  }
}
void answer() {
  cin >> n >> m >> p;
  G.resize(n);
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].emplace_back(b, p-c);
  }
  reach.resize(n, 0);
  visited.resize(n, 0);
  rep(i, n) {
    visited.assign(n, 0);
    dfs(i);
    if(visited[n-1]) reach[i] = 1;
    else reach[i] = 0;
  }
  dist.resize(n, INF);
  dist[0] = 0;
  rep(i, n) {
    rep(u, n) {
      for(auto e : G[u]) {
        int v, cost;
        tie(v, cost) = e;
        if(!reach[v]) continue;
        if(dist[u] < INF && dist[u] + cost < dist[v]) {
          dist[v] = dist[u] + cost;
          if(i == n-1) {
            cout << -1 << '\n';
            return;
          }
        }
      }
    }
  }
  cout << max(-dist[n-1], 0) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; --i)
#define sz(x) ((int)(x).size())
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define pb push_back

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<double>    vd;
typedef vector<long long> vl;

// template<class T>bool maxc(T &a, const T &b) { if (a<b) { a=b; return 1; } }
// template<class T>bool minc(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

    // 入力
    int n;
    cin >> n;
    int a[n] = {};
    int maxV = 0;
    int cntM = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        maxV = max(maxV, a[i]);
    }

    // 処理
    int maxV2 = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == maxV) {
            cntM++;
            continue;
        }
        maxV2 = max(maxV2, a[i]);
    }

    // 出力
    for (int i = 0; i < n; i++) {
        if (a[i] != maxV) {
            cout << maxV << endl;
        } else if (a[i] == maxV) {
            if (cntM >= 2) {
                cout << maxV << endl;
            } else {
                cout << maxV2 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2432
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
g = [[] for i in range(n)]

for i in range(n-1):
  a,b = na()
  g[a-1].append(b-1)
  g[b-1].append(a-1)

c = na()
c = sorted(c)

print(sum(c)-c[-1])

ans = [0]*n
st = [0]

while st:
  d = st.pop()
  ans[d] = c.pop()
  for v in g[d]:
    if ans[v] == 0:
      st.append(v)

print(' '.join([str(s) for s in ans]))

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

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

    int c = 0, t = n;
    while (t > 0)
    {
        c += t % 10;
        t /= 10;
    }
    if (n % c == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
  ll N; cin >> N;
  string S; cin >> S;

  for (auto c:S) {
    int t = c-'A';
    t = (t + N) % 26;
    cout << (char)(t+'A');
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;

long double dif(int x1,int y1, int x2, int y2){
    return (long double)(sqrt( pow((x1-x2),2) + pow((y1-y2),2) ));
}

int main(){
        _
        sp(10);
        long double res = 0.0;
        int n; cin >> n;
        int X[n+1],Y[n+1];
        for(int i = 0; i<n; i++){
            cin >> X[i] >> Y[i];
        }
        int cnt =0;
        long double tot = 0.0;
        for(int i = 0; i<n; i++){
            for(int j = 0; j<n; j++){
                    if(i==j)continue;
                    res =(dif(X[i],Y[i],X[j],Y[j]))*2/n;
                    tot+=res;
            }

        }
        cout<<tot/2<<endl;

return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <functional>
using namespace std;

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

int main()
{
    int N, P;
    cin>>N>>P;
    string _S;
    cin>>_S;
    vector<long long> S;
    for (char s: _S)
        S.push_back(s-'0');

    //N = 100000;
    //P = 7;
    //S = vector<int>(N, 0);

    vector<long long> T(P);
    long long inv10 = powmod(10, P-2, P);

    function<long long(int, int)> f = [&](int l, int r) -> long long
    {
        if (r-l==1)
            return S[l]%P==0 ? 1 : 0;

        int m = (l+r)/2;

        long long ans = 0;
        long long p10 = 1;
        long long x = 0;
        for (int i=m-1; i>=l; i--)
        {
            x = (x+S[i]*p10)%P;
            T[x]++;
            p10 = p10*10%P;
        }

        x = 0;
        p10 = inv10;
        for (int i=m; i<r; i++)
        {
            x = (x*10+S[i])%P;
            if (10%P==0)
                ans += x==0 ? m-l : 0;
            else
                ans += T[(P-x)*p10%P];
            p10 = p10*inv10%P;
        }

        p10 = 1;
        x = 0;
        for (int i=m-1; i>=l; i--)
        {
            x = (x+S[i]*p10)%P;
            T[x]--;
            p10 = p10*10%P;
        }

        ans += f(l, m) + f(m, r);
        //cout<<l<<" "<<r<<" "<<ans<<endl;
        return ans;
    };

    cout<<f(0, N)<<endl;
}


Measured memory_bytes: 2804
N = int(input())
H = [int(i) for i in input().split()]

for n in reversed(range(1,N)):
    if H[n] >= H [n-1]:
        continue
    elif H[n] == H[n-1]-1:
        H[n-1] -= 1
    else:
        print('No')
        exit()

print('Yes') 


Measured memory_bytes: 14396
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 2147483647
#define dinf 0x3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define ull unsigned long long
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')

#define bl putchar(' ')
#define ed putchar('\n')
#define test cout<<"this:" 

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
const int maxn = 2333;
int n, m, a, b, tmpb, tmpa, flag;
int Map[maxn][maxn];
int col[maxn];
int main()
{
	read(n), read(m), read(a), read(b);
	tmpb = b, tmpa = a;
	begin:
	for (rg int i = 1; i <= n; ++i)
	{
		rg int tot = 0;
		for (rg int j = 1; j <= m; ++j)
		{
			if (col[j] < b) Map[i][j] = 1, ++tot, ++col[j];
			if (tot == a) break; 
		}
		if (tot != a && tot != m - a)
		{
			++flag;
			break;
		}
		if (i == n)
		{
			rg bool isOk = true;
			for (rg int j = 1; j <= m; ++j)
			{
				if (col[j] != b && col[j] != n - b)
				{
					isOk = false;
					++flag;
					break;
				}
			}
			if (isOk) flag = 0;
		}
	}
	if (flag)
	{
		if (flag == 1) b = n - tmpb, a = tmpa;
		if (flag == 2) b = tmpb, a = m - tmpa;
		if (flag == 3) b = n - tmpb, a = m - tmpa;
		if (flag == 4)
		{
			write(-1);
			return 0;
		}
		for (rg int i = 1; i <= n; ++i)
		{
			for (rg int j = 1; j <= m; ++j)
			{
				col[j] = 0;
				Map[i][j] = 0;
			}
		}
		goto begin;
	}
	for (rg int i = 1; i <= n; ++i)
	{
		for (rg int j = 1; j <= m; ++j)
		{
			write(Map[i][j]);
		}
		__endl;
	}
	return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n, w, h, x, y, s, t;
	int i, j;
	while (cin >> n) {
		if (n == 0)break;
		int a[101][101];
		for (i = 0; i < 101; i++) {
			for (j = 0; j < 101; j++) {
				a[i][j] = 0;
			}
		}
		cin >> w >> h;
		for (i = 0; i < n; i++) {
			cin >> x >> y; a[x][y] = 1;
		}
		int dp[101][101];
		for (i = 1; i <= w; i++) {
			for (j = 1; j <= h; j++) {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
			}
		}
		cin >> s >> t;
		int ma = 0;
		for (i = 1; i <= w - s + 1; i++) {
			for (j = 1; j <= h - t + 1; j++) {
				ma = max(ma, dp[i + s - 1][j + t - 1] - dp[i + s - 1][j - 1] - dp[i - 1][j + t - 1] + dp[i - 1][j - 1]);
			}
		}
		cout << ma << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X = list(map(int, readline().split()))

    X.sort()
    if X[0] == 5 and X[1] == 5 and X[2] == 7:
        print('YES')
    else:
        print('NO')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61300
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  
  cin >> N;
  
  vector<int> A(N);
  
  for(int i = 0;i < N;++i){
    cin >> A[i];
  }
  
  int num = 0;
  
  for(int i = 0;i < N;++i){
    if(A[i] % 2 == 0){
      if(A[i] % 3 == 0 || A[i] % 5 == 0){
      }
      else{
        num++;
      }
    }
  }
  
  if(num == 0){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n,m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<tuple<ll,int>> itm;
    REP(i,n)
        cin >> a[i];
    REP(i,m)
    {   
        int b;
        ll c;
        cin >> b >> c;
        itm.emplace_back(c,b);
    }

    sort(ALL(a));
    sort(ALL(itm),greater<tuple<ll,int>>());

    ll vec_idx = 0;
    REP(i,SIZE(itm))
    {
        // cが新しい数字, bが変更できる数
        ll c;
        int b;
        tie(c,b) = itm[i];
        REP(j,b)
        {
            if (a[vec_idx] < c)
            {
                a[vec_idx] = c;
                vec_idx++;
            } 
            else
                break;
        }
    }

    ll ans = 0;
    REP(i,n)
        ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int sosu[1000003];//sosu[i]が0ならiは素数　1は素数扱い
vector<long long int> sosulis;//100万までの素数が小さい順に格納。2から。
int main(){
    for(long long int i=2;i<=1000000;i++){
        if(sosu[i]==0){
            sosulis.push_back(i);
            for(int j=i*2;j<1000003;j+=i){
                sosu[j]=1;
            }
        }
    }
    int X;
    cin>>X;
    while(1){
        if(sosu[X]==0){
            cout<<X<<endl;
            return 0;
        }
        X++;
    }
    return 0;
}


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

const int N = 305;

char s[2 * N][2 * N];
int n, ans = 0, f[N][N];

int find_ans(int u, int v)
{
    int ret = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++)
            ret += (s[u - 1 + i][v - 1 + j] != s[u - 1 + j][v - 1 + i]);
    return ret;
}

int part(int u, int v)
{
    int ret = 0;
    for (int i = 1; i <= n; i++)
        ret -= (s[u][v - 1 + i] != s[u - 1 + i][v]);
    for (int i = 1; i <= n; i++)
        ret += (s[u + n][v + i] != s[u + i][v + n]);
    return ret;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%s", s[i] + 1);
    for (int i = 1; i < 2 * n; i++)
        for (int j = 1; j < 2 * n; j++)
            s[i][j] = s[(i > n ? i - n : i)][(j > n ? j - n : j)];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if (i == 1 || j == 1)
                f[i][j] = find_ans(i, j);
            else
                f[i][j] = f[i - 1][j - 1] + part(i - 1, j - 1);
            ans += (f[i][j] == 0);
        }
    printf("%d", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    vector<ll> a(5);
    cin >> n >> a;
    int bottleneck = 0;
    for(int i = 1; i < 5; i++) {
        if(a[i] < a[bottleneck]) {
            bottleneck = i;
        }
    }
    cout << (n + a[bottleneck] - 1) / a[bottleneck] + 4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct UnionFind{
	vector<int> par,rank,sum;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		sum.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		if(y==(int)par.size()) y--;
//		printf("unite %d,%d,\n",x,y);
		x=find(x),y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			sum[y] += sum[x];
		}else{
			par[y]=x;
			sum[x] += sum[y];
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
};


string s;
int N,M;
int a[100010];

int main(){
	cin>>s;
	N = s.size();
	bool inc = 0;
	if(N%2==0){
		string ns = s.substr(0,N/2) + "a" + s.substr(N/2,N/2);
		s = ns;
		N++;
		inc = 1;
	}
	rep(i,N) a[i+1] = s[i]-'a';

	UnionFind UF(N/2+1);
	rep(i,N/2+1){
		UF.sum[i] += a[i+1]-a[i];
		UF.sum[i] += a[N+1-i]-a[N-i];
	}
	cin>>M;
	int mid = N/2+1;
	rep(i,M){
		int l,r;
		cin>>l>>r;
		if(inc && l>N/2) l++;
		if(inc && r>N/2) r++;
		if(r<=mid){
			UF.unite(l-1,r);
		}else if(l>=mid){
			swap(l,r);
			l = N+1-l;
			r = N+1-r;
			UF.unite(l-1,r);
		}else if(mid-l<=r-mid){
			l = N+2-l;
			if(l>r) continue;
			swap(l,r);
			l = N+1-l;
			r = N+1-r;
			UF.unite(l-1,r);
		}else{
			r = N-r;
			UF.unite(l-1,r);
		}
	}
	bool ok = 1;
	rep(i,N/2+1){
		if(UF.find(i)==i){
			if(UF.sum[i]%26!=0) ok = 0;
		}
	}
	if(ok) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]
for i in range(n):
    dp[i][i] = a[i]

for i in range(n - 2, -1, -1):
    for j in range(i + 1, n):
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])

print(dp[0][n - 1])

Measured memory_bytes: 111836
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()) cout<<"GREATER";
    else if(a.size()<b.size()) cout<<"LESS";
    else{
        int n=a.size();
        rep(i,n){
            if(a[i]>b[i]){
                cout<<"GREATER";
                return 0;
            }else if(a[i]<b[i]){
                cout<<"LESS";
                return 0;
            }
        }
        cout<<"EQUAL";
    }
}

Measured memory_bytes: 3620
package main

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

func get_int(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	as := make([]int, m)
	bs := make([]int, m)
	for i := range as {
		as[i] = get_int(sc)
		bs[i] = get_int(sc)
	}

	cand := make(map[int]bool, 0)
	for i, b := range bs {
		if b == n {
			cand[as[i]] = true
		}
	}
	for i, a := range as {
		if a == 1 && cand[bs[i]] == true {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, a, sum, x, y, z, w, b;
    cin >> A >> B;
    sum = 0;
    for(int i = A; i < B + 1; i++){
    a = i;
    x = i % 10;
    y = ((i - x) % 100) / 10;
    z = ((i - x - y * 10) % 1000) /100;
    w = ((i - x - y * 10 - z * 100) % 10000) / 1000;
    b = (i - x - y * 10 - z * 100 - w * 1000) / 10000;
    if (x == b && y == w){
        sum += 1;
    }
    }
cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200002;
typedef long long ll;
int x[N],S,n,i;
ll p[N],t[N],Ans;
void init(){
    scanf("%d%d",&n,&S);
    for(i=1;i<=n;i++)
        scanf("%d%lld",x+i,p+i);
}
void Query(int l,int r){
    if(S>=x[r]){
        t[l]=S-x[l];
        return;
    }
    if(S<=x[l]){
        t[r]=x[r]-S;
        return;
    }
    if(p[l]>=p[r]){
        p[l]+=p[r];
        Query(l,r-1);
        t[r]=t[l]+x[r]-x[l];
    }
    else{
        p[r]+=p[l];
        Query(l+1,r);
        t[l]=t[r]+x[r]-x[l];
    }
}
void work(){
    Query(1,n);
    for(i=1;i<=n;i++)
        Ans=max(Ans,t[i]);
    printf("%lld",Ans);
}
int main(){
    init();
    work();
    return 0;
}

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

/**
 * JOI and IOI
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int len = line.length() - 1;
			int joi = 0;
			int ioi = 0;

			for (int i = 1; i < len; i++) {
				if (line.charAt(i) == 'O') {
					if (line.charAt(i + 1) == 'I') {
						if (line.charAt(i - 1) == 'J') {
							joi++;
						} else if (line.charAt(i - 1) == 'I') {
							ioi++;
						}
					}
				}
			}
			//
			System.out.println(joi + "\n" + ioi);
		}
	}
}

Measured memory_bytes: 17856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
ll const mod = 1e+9 + 7;

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N){
		cin >> A[i];
	}
	
	ll ans = 0;
	
	rep(i,60){
		ll x = 0;
		rep(j,N){
			if(A[j] >> i & 1){
				x++;
			}
		}
		ll temp = x*(N-x)%mod;
		rep(j,i){
			temp *= 2;
			temp %= mod;
		}
		ans += temp;
		ans %= mod;
	}
	
	cout << ans << endl;
    return 0;
}



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

using namespace std;

int main()
{
    long long int n;

    cin>>n;
    long long int a[n],b[n+1]={0};

    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<b[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 6752
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()
if x[-1] < y[0]:
  print('No War')
else:
  print('War')

Measured memory_bytes: 3060
#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a[i];

  vector<bool> row(h, false);
  vector<bool> col(w, false);
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] == '#') {
        // col 内に1つ以上 # があり縦に . が揃っていないなら . も出力される
        row[i] = true;
        col[j] = true;
      }
    }
  }

  rep(i, h) {
    if (row[i]) {
      rep(j, w) {
        if (col[j]) cout << a[i][j];
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Runtime.CompilerServices;
using System.IO.Pipes;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {

                this.x = x;
                this.y = y;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {
            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine((args[2] * args[1] < args[0] ? "No" : "Yes"));

        }

        public static void Solve()
        {
        }

    }

}

Measured memory_bytes: 28300
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      int x = sc.nextInt();
      int count = 0;
      if(n == 0 && x == 0){
        break;
      }else{
        for(int i=1;i<n+1;i++){
          for(int j=i+1;j<n+1;j++){
            for(int k=j+1;k<n+1;k++){
              int ans = i+j+k;
             // System.out.println(ans);
              if(ans == x){
                count++;
              }
            }
          }
        }
        System.out.println(count);
      }
    }
  }
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> S(N);
	vector<ll> T(M);

	REP(i,N){
	    cin >> S[i];
	}
	REP(i,M){
	    cin >> T[i];
	}

	static ll dp[2003][2003] = {};
	dp[0][0] = 1;
	REP(i,N+1){
	    dp[i][0]=1;
	}

	REP(i,M+1){
	    dp[0][i]=1;
	}

	REP(i,N){
	    REP(j,M){
	        if (S[i] == T[j]){
	        	dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]) % MOD;
	        }else{
	        	dp[i+1][j+1] = (dp[i+1][j]+dp[i][j+1]-dp[i][j]) % MOD;
	        }
	        if (dp[i+1][j+1] < 0) dp[i+1][j+1] += MOD;
	    }
	}


	cout << dp[N][M] % MOD << endl;
	return 0;
}


Measured memory_bytes: 31616
import java.util.Scanner;

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

        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(solve(r, g, b) ? "YES" : "NO");

        sc.close();
    }

    static boolean solve(int r, int g, int b) {
        return (g * 10 + b) % 4 == 0;
    }
}

Measured memory_bytes: 21972
def solve(s, t):
    D1, D2 = {}, {}
    for i in range(len(s)):
        k = s[i]
        v = t[i]
        D1.setdefault(k, set()).add(v)
        D2.setdefault(v, set()).add(k)
        if (len(D1[k]) > 1) or (len(D2[v]) > 1):
            return "No"
    return "Yes"

assert solve("azzel", "apple") == "Yes"
assert solve("chokudai", "redcoder") == "No"
assert solve("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu") == "Yes"
s = raw_input()
t = raw_input()
print solve(s, t)

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
string p[110000], S[110000];
map<string, int> mp;
signed main() {
    cin >> N >> M;
    int ac = 0, pena = 0;
    rep(i, M) {
        cin >> p[i] >> S[i];
        if (mp[p[i]] != -1) {
            if (S[i] == "AC") { ac++, pena += mp[p[i]], mp[p[i]] = -1; }
            else { mp[p[i]]++; }
        }
    }
    cout << ac << " " << pena << endl;
}

Measured memory_bytes: 17536
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
bool intersect(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy){
	long long ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	long long tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	long long tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	long long td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	if(ta*tb<=0LL&&tc*td<=0LL)return true;
	else return false;
}
pair<double,double>getpoint(int ax,int ay,int bx,int by,int cx,int cy ,int dx,int dy){
	double acx=cx-ax;
	double acy=cy-ay;
	double bunbo=(bx-ax)*(dy-cy)-(by-ay)*(dx-cx);
	double r=(acx*(dy-cy)-acy*(dx-cx))/bunbo;
	return make_pair(ax+(bx-ax)*r,ay+(by-ay)*r);
}
double ABS(double a){return a<0.0?-a:a;}
int main(){
	int x1,x2,x3,x4,x5,x6;
	int y1,y2,y3,y4,y5,y6;
	while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2),x1||x2||y1||y2){
		scanf("%d%d%d%d%d%d%d%d",&x3,&y3,&x4,&y4,&x5,&y5,&x6,&y6);
		if(!intersect(x1,y1,x2,y2,x3,y3,x4,y4))printf("kyo\n");
		else if(!intersect(x1,y1,x2,y2,x5,y5,x6,y6))printf("kyo\n");
		else if(!intersect(x5,y5,x6,y6,x3,y3,x4,y4))printf("kyo\n");
		else{
			pair<double,double> p,q,r;
			p=getpoint(x1,y1,x2,y2,x3,y3,x4,y4);
			q=getpoint(x1,y1,x2,y2,x5,y5,x6,y6);
			r=getpoint(x5,y5,x6,y6,x3,y3,x4,y4);
			q=make_pair(q.first-p.first,q.second-p.second);
			r=make_pair(r.first-p.first,r.second-p.second);
			double S=ABS(q.first*r.second-q.second*r.first)/2;
			if(S<0.00001)printf("kyo\n");
			else if(S<100000.0-0.00001)printf("syo-kichi\n");
			else if(S<1000000.0-0.00001)printf("kichi\n");
			else if(S<1900000.0-0.00001)printf("chu-kichi\n");
			else printf("dai-kichi\n");
		}
	}
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, A[100010];
  map<ll, ll> cur;

  void init() {
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", A+i);
    cur[-1] = 3;
  }

  void solve() {
    ll ans = 1;
    rep(i, N) {
      ans = (ans * cur[A[i]-1]) % MOD_1_000_000_007;
      cur[A[i]-1]--;
      cur[A[i]]++;
    }
    printf("%lld\n", ans);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 7296
N = int(input())
x = 0
import math
maxA = int(math.sqrt(N))

for i in range(1,maxA + 1):
  A = i
  for j in range(i,int(N/i) + 1):
    B = j
    if A*B < N and A != B:
      x += 2
    elif A*B < N and A == B:
      x += 1
print(x)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct edge{
   int to, cost;
   edge(int to, int cost):to(to), cost(cost){}
};
vector<edge> G[100010]; 
int d[100010];

void dfs(int now, int pre){
    rep(i, 0, G[now].size()){
        int next = G[now][i].to;
        if(next == pre) continue;
        if(d[next] != -INF) continue;
        d[next] = d[now] + G[now][i].cost;
        dfs(next, now);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m), c(m);
    rep(i, 0, m){
        cin >> l[i] >> r[i] >> c[i];
        l[i]--; r[i]--;
        G[l[i]].push_back(edge{r[i], c[i]});
        G[r[i]].push_back(edge{l[i], -c[i]});
    }
    rep(i, 0, n) d[i] = -INF;
    rep(i, 0, n){
        if(d[i] != -INF) continue;
        d[i] = 0;
        dfs(i, -1);
    }
    bool ans = true;
    // rep(i, 0, n){
    //     cout << i << " " << d[i] << endl;
    // }
    rep(i, 0, m){
        // cout << i << " " << r[i] << " " << l[i] << " " << d[r[i]] << ' ' << d[l[i]] << ' ' << c[i] << endl;
        if(d[r[i]] - d[l[i]] != c[i]){
            ans = false;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 22144
module Main where

import           Data.List
import           Control.Monad

main :: IO ()
main = do
    [h, w] <- (map read . words) <$> getLine :: IO [Int]
    list   <- map (map read . words) <$> (replicateM h) getLine :: IO [[Int]]
    let res1    = (map goRight . enumerate2d) list
    let list2   = (map snd) res1
    let result1 = (concatMap fst) res1
    let res2    = (goRight . map last) list2
    let result2 = fst res2
    let result  = concat [result1, result2]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight []           = ([], [])
goRight [x         ] = ([], [x])
goRight (a : b : xs) = if even (snd a)
    then let res = goRight (b : xs) in mapSnd (a :) res
    else
        let res = goRight (mapSnd (+ 1) b : xs)
        in  ((fst a, fst b) : (fst res), mapSnd (subtract 1) a : (snd res))

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)

mapTuple :: (t1 -> a) -> (t2 -> b) -> (t1, t2) -> (a, b)
mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst :: (t1 -> a) -> (t1, b) -> (a, b)
mapFst = flip mapTuple id

mapSnd :: (t2 -> b) -> (a, t2) -> (a, b)
mapSnd = mapTuple id


Measured memory_bytes: 78460
#include <bits/stdc++.h>
 
using namespace std;
 
const long long mod = 1e9 + 7ll ;
 
long long modpower(long long a , long long b)
{
    if(b == 0)
        return 1ll ;
    long long x = modpower(a , b / 2ll) ;
    x = (x * x) % mod ;
    if(b & 1)
        return (x * a) % mod ;
    return (x % mod) ;
}
 
struct combination
{
    vector<long long>fact , inv ;
    combination(int sz) : fact(sz + 1) , inv(sz + 1)
    {
        fact[0] = 1ll ;
        inv[0] = 1ll ;
        for(long long i = 1 ; i <= sz ; ++i)
            fact[i] = (fact[i-1] * i) % mod ;
        inv[sz] = modpower(fact[sz] , mod - 2ll) ;
		for(long long i = sz-1; i >= 1; --i)
		    inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    long long choose(int n , int k) const
    {
        if(k < 0 || n < k)
            return 0 ;
        return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod) ;
    }
};

int r1 , c1 , r2 , c2 ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>r1>>c1>>r2>>c2 ;
	combination comb(2e6+10) ;
	long long ans = 0ll ;
	for(int i = r1 ; i <= r2 ; ++i)
	{
		ans = (ans + comb.choose(i+c2+1ll , i+1ll)) % mod ;
		ans = (ans - comb.choose(i+c1 , i+1ll) + mod) % mod ;
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
int a[20001],n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n-2;i++)
		for(int j=i+1;j<=n-1;j++)
		{
			int k=j+1;
			while(a[k]<a[i]+a[j]&&k<=n)
			{
				k++;
				ans++;
			}
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = (ll)1e14;

int main() {
    // input
    int n;
    cin >> n;
    vector<int> a(3*n);
    for (int i = 0; i < 3*n; i++) {
        cin >> a[i];
    }
    ll sum;
    // 前半
    priority_queue<int, vector<int>, greater<int>> pq_1;
    sum = 0;
    for (int i = 0; i < n; i++) {
        pq_1.push(a[i]);
        sum += a[i];
    }
    vector<ll> sum_1(n+1);
    sum_1[0] = sum;
    for (int k = 1; k <= n; k++) {
        sum += a[n-1+k];
        pq_1.push(a[n-1+k]);
        sum -= pq_1.top();
        pq_1.pop();
        sum_1[k] = sum;
    }
    // 後半
    priority_queue<int> pq_2;
    sum = 0;
    for (int i = 2*n; i < 3*n; i++) {
        pq_2.push(a[i]);
        sum += a[i];
    }
    vector<ll> sum_2(n+1);
    sum_2[n] = sum;
    for (int k = n-1; k >= 0; k--) {
        sum += a[n+k];
        pq_2.push(a[n+k]);
        sum -= pq_2.top();
        pq_2.pop();
        sum_2[k] = sum;
    }
    ll sum_max = -inf;
    for (int k = 0; k <= n; k++) {
        sum_max = max(sum_max, sum_1[k]-sum_2[k]);
    }
    // output
    cout << sum_max << "\n";
}

Measured memory_bytes: 6892
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int n, m, r;
  unsigned long long d[200][200] = {};
  int r_i[8] = {};

  scanf("%d%d%d", &n, &m, &r);

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(i==j)
        d[i][j] = 0;
      else
        d[i][j] = 200000000;

  for(int i=0;i<r;i++) {
    scanf("%d", r_i+i);
    r_i[i]--;
  }

  for(int i=0;i<m;i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    d[a-1][b-1] = c;
    d[b-1][a-1] = c;
  }

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

  int pn = 1;
  for(int i=0;i<r;i++)
    pn *= i+1;

  long long res = 100000000000000;
  for(int i=0;i<pn;i++) {
    long long hoge = 0;
    for(int j=0;j<r-1;j++) {
      hoge += d[r_i[j]][r_i[j+1]];
    }

    res = min(res, hoge);

    next_permutation(r_i, r_i+r);
  }

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

  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w,ans=0;
	cin>>h>>w;
	vvl vv(h,vl(w,1));
	vvl hh1(h,vl(w,0));
	vvl ww1(h,vl(w,0));
	vvl hh2(h,vl(w,0));
	vvl ww2(h,vl(w,0));
	char c;
	rep(i,h)rep(j,w){
		cin>>c;
		if(c=='#')vv[i][j]=0;
	}
	rep(i,h){
		int cnt=0;
		rep(j,w){
			if(vv[i][j]==0)cnt=0;
			else cnt++;
			hh1[i][j]=cnt;
		}
	}
	rep(i,h){
		int cnt=0;
		rrep(j,w){
			if(vv[i][j]==0)cnt=0;
			else cnt++;
			hh2[i][j]=cnt;
		}
	}
	rep(j,w){
		int cnt=0;
		rep(i,h){
			if(vv[i][j]==0)cnt=0;
			else cnt++;
			ww1[i][j]=cnt;
		}
	}
	rep(j,w){
		int cnt=0;
		rrep(i,h){
			if(vv[i][j]==0)cnt=0;
			else cnt++;
			ww2[i][j]=cnt;
		}
	}
	rep(i,h)rep(j,w){
		chmax(ans,(hh1[i][j]+hh2[i][j]-1)+(ww1[i][j]+ww2[i][j]-1)-1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 156928
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
vector<int> v(100100,inf);
int main(){
    cin>>n;
    vector<int> h(n,0);
    rep(i,n) cin>>h[i];
    v[0]=0;
    rep(i,n-1){
        if(i+2<n){
            v[i+2]=min(v[i+2],v[i]+abs(h[i+2]-h[i]));
            v[i+1]=min(v[i+1],v[i]+abs(h[i+1]-h[i]));
        }
        else if(i+1<n){
            v[i+1]=min(v[i+1],v[i]+abs(h[i+1]-h[i]));
        }
    }
    cout<<v[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024