akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int minus = Inf;
    int plus = -Inf;
    int mitr = -1;
    int pitr = -1;
    for(int i = 0;i < N;i++) {
        if(vec.at(i) < 0) {
            if(vec.at(i) < minus) {
                minus = vec.at(i);
                mitr = i;
            }
        }
        else {
            if(vec.at(i) > plus) {
                plus = vec.at(i);
                pitr = i;
            }
        }
    }
    vector<P> ret;
    if(abs(minus) < plus || mitr == -1) {
        for(int i = 0;i < N;i++) {
            vec.at(i) += vec.at(pitr);
            ret.push_back(P(pitr + 1,i + 1));
        }
        for(int i = 0;i < N - 1;i++) {
            ret.push_back(P(i + 1,i + 2));
        }
        cout << ret.size() << endl;
        for(int i = 0;i < ret.size();i++) {
            cout << ret.at(i).first << " " << ret.at(i).second << endl;
        }
    }
    else {
        for(int i = 0;i < N;i++) {
            vec.at(i) += vec.at(mitr);
            ret.push_back(P(mitr + 1,i + 1));
        }
        for(int i = N - 1;i >= 1;i--) {
            ret.push_back(P(i + 1,i));
        }
        cout << ret.size() << endl;
        for(int i = 0;i < ret.size();i++) {
            cout << ret.at(i).first << " " << ret.at(i).second << endl;
        }
    }
}

Measured memory_bytes: 256
from queue import PriorityQueue

[X,Y,Z,K] = list(map(int, input().split()))


A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

ai = 0
bi = 0
ci = 0

vec = []

for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            if (i+1)*(j+1)*(k+1) <= K:
                vec.append(A[i] + B[j] + C[k])
            else:
                break
vec = sorted(vec, reverse=True)
for i in range(K):
    print(vec[i])


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

int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> v(n+1);
    vector<ll> vis(n+1,0);
    for(ll i=0;i<m;i++){
        ll x,y;
        cin>>x>>y;
        v[x].push_back(y);v[y].push_back(x);
    }
    ll ans=1;
    for(ll i=1;i<=n;i++){
        if(!vis[i]){
            queue<ll> q;
            ll cnt=0;
            for(ll j=0;j<(ll)v[i].size();j++){
                if(!vis[v[i][j]])   cnt++,q.push(v[i][j]),vis[v[i][j]]=1;
            }
            while(!q.empty()){
                ll t=q.front();
                // vis[t]=1;
                for(ll j=0;j<(ll)v[t].size();j++){
                    if(!vis[v[t][j]])   cnt++,q.push(v[t][j]),vis[v[t][j]]=1;
                }
                q.pop();
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N = 100100 , L = 17;
int n ;
ll dp[N] ;
map < pair < int , int > , int > mp ;
vector < int > adj[N];
void dfs(int u,int par, ll sum )
{
     sum += mp[{u,par}];
     dp[u] = sum ;
    for(auto v:adj[u])
        if( v!=par )
        {
            dfs(v,u,sum);

        }

}


int main()
{
    scanf("%d",&n);
    for(int i=1; i<n; i++) // n-1 edges
    {
        int a , b , c ;
        scanf("%d%d%d",&a,&b,&c);
        adj[a].push_back(b);
        adj[b].push_back(a);
        mp[{a,b}] = c;
        mp[{b,a}] = c;
    }
    int Q , k ;
   scanf("%d%d",&Q,&k);
   dfs(k,0,0LL);
   int x, y ;

   while ( Q-- ){
    scanf("%d%d",&x,&y);
    printf("%lld\n",dp[x]+dp[y]);
   }
    return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

const int MAX = 2005;
const int INFTY = 1e9+7;

vector<int> adj[MAX]; // 重み付き有向グラフの隣接リスト表現
bool visited[MAX];
int d[MAX];

void bfs(int s) {
  queue<int> q;
  for (int i = 0; i < MAX; i++) {
    d[i] = INFTY;
    visited[i] = false;;
  }

  d[s] = 0;
  q.push(s);

  while (!q.empty()) {
    int u = q.front(); q.pop();
    if (visited[u]) continue;
    visited[u] = true;
    for (int v: adj[u]) {
      if (visited[v]) continue;
      if (d[v] > d[u]+1) {
        d[v] = d[u]+1;
        q.push(v);
      }
    }
  }
};

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

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

  int n;
  cin >> n;
  int x, y;
  cin >> x >> y;
  x--; y--;

  rep(i, 0, n-1) {
    adj[i].pb(i+1);
    adj[i+1].pb(i);
  }

  adj[x].pb(y);
  adj[y].pb(x);

  map<PI, int> mp;

  rep(i, 0, n) {
    bfs(i);
    rep (j, 0, n) {
      if (j == i) continue;
      int a = i;
      int b = j;
      if (a > b) swap(a, b);
      mp[make_pair(a, b)] = d[j];
    }
  }

  vi ans(n, 0);
  for (auto ele: mp) {
    ans[ele.second]++;
  }

  rep(i, 1, n) {
    cout << ans[i] << endl;
  }


  return 0;
};


Measured memory_bytes: 125440
s = []
n, k = map(int, input().split())
for i in range(n):
    s.append(0)
for i in range(k):
    m = int(input())
    na = list(map(int, input().split()))
    for j in na:
        s[j - 1] = 1
         
print(s.count(0))
        
    

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector A(n,0);rep(i,n) cin>>A[i];
  vector<P> v;
  sort(ALL(A));
  ll maximum=A[n-1],mimimum=A[0];
  for(ll pos=1;pos<n-1;pos++) {
    if(A[pos]>=0) {
      v.emplace_back(P(mimimum,A[pos]));
      mimimum-=A[pos];
    }
    else {
      v.emplace_back(P(maximum,A[pos]));
      maximum-=A[pos];
    }
  }
  v.emplace_back(maximum,mimimum);
  print(maximum-mimimum);
  for(P p:v) cout<<p.first<<' '<<p.second<<endl;
  return 0;
}

Measured memory_bytes: 4336
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

int N;

int main(){
    cin>>N;
    int A[N],a;
    rep(i,N){
        cin>>a;
        a--;
        A[a]=i+1;
    }
    rep(i,N)out(A[i]);
    
    
}


Measured memory_bytes: 1152
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 最後に開かれた日付
    # 開催するコンテスト
    T = [ i%26+1 for i in range(D) ]

    def scoring():
        last = [0]*26
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            last[T[i]-1] = i+1
            for j in range(26):
                score -= C[j] * (i+1 - last[j])
        return score

    max_score = scoring()
    # print(max_score)
    ans = T.copy()
    # a = 0
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # if a % 10000 == 0:
        #     print(a, *T, score, max_score)
        # a += 1
        end = get_now()
    print(*ans, sep='\n')

main()


Measured memory_bytes: 9908
s = list(input())
# print(s)
d = {}
for i in range(len(s)):
    d[s[i]] = d.get(s[i], 0)+1
# print(d)
ans = 0
if 'N' in d:
    ans += 1
if 'S' in d:
    ans -= 1
if 'E' in d:
    ans += 100
if 'W' in d:
    ans -= 100
if ans == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <complex>
#include <cstdlib>

using namespace std;

const int N = 20000;

vector<bool> p;

void init(){
    p.assign(N, true); p[0] = p[1] = false;
    for(int i=2; i<N; ++i)if(p[i]){
        for(int j=i<<1; j<N; j+=i)p[j] = false;
    }
}

bool solve(int m, int n){ //http://en.wikipedia.org/wiki/Gaussian_integer
    complex<int> g(abs(m), abs(n));
    return (g.real() == 0 && g.imag() % 4 == 3 && p[g.imag()]) ||
           (g.imag() == 0 && g.real() % 4 == 3 && p[g.real()]) ||
           norm(g) == 2 || (norm(g) % 4 == 1 && p[norm(g)]);
}

int main(){
    init();
    int T;
    cin >> T;
    while(T--){
        int m, n;
        cin >> m >> n;
        cout << (solve(m, n)? 'P': 'C') << '\n';
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<char,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);;
    for(ll i=0;i<N;i++){
        cin>>A[i+1]
    ;}
    vector<ll> rain(N+1,0);
    ll sum=0;
    for(ll i=0;i<N;i++){
        sum+=A[i+1]
    ;}
    for(ll i=1;i<N;i+=2){
        sum-=A[i]*2
    ;}
    rain[N]=sum;
    for(ll i=N-1;i>=0;i--){
        rain[i]=2*A[i]-rain[i+1]
    ;}  
    for(ll i=0;i<N;i++){
        cout<<rain[i+1]<<" "
    ;}cout<<endl;
return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>

int main(){
  int k;
  int a[33] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  scanf("%d", &k);

  printf("%d\n", a[k]);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,c,k,a[N],ans;
int main(){
	scanf("%d%d%d",&n,&c,&k);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1,j=1;i<=n;i++,i=j){
		while (j-i<c&&j<=n&&a[j]<=a[i]+k)j++;
		ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
void main() {
    string s = readln.chomp;
    writeln(2 * min(s.count('0'), s.count('1')));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 508
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = input()[4:]
    print("2018"+s)
    return

#B
def B():
    n = I()
    d = IR(n)
    d = list(set(d))
    print(len(d))
    return

#C
def C():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
const int Kmax=1e7;
int sum[Kmax];
int R[Kmax];
 
int main()
{
    int n;
    cin>>n;
    cin>>s;
    int Max=0;
        for(int j=1;j<n;j++){
         sum[j]=sum[j-1];
         if(s[j-1]=='E'){
            sum[j]++;
			
         }
         }
        for(int k=n;k>0;k--){
        R[k-1]=R[k];
        if(s[k]=='W'){
        R[k-1]++;
        }
         sum[k-1]=sum[k-1]+R[k-1];
		
         Max=max(Max,sum[k-1]);
        }
        cout<<n-1-Max<<endl;
    return 0;
}

Measured memory_bytes: 3964
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc160_a.cpp"

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e9+7;
int main()
{
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll>> d(n, vector<ll>(n));
    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] = INF;
        }
    }
    for(int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if(c > l) continue;
        d[a][b] = c;
        d[b][a] = c;
    }
    for(int k = 0; k < n; k++)
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    vector<vector<int>> x(n, vector<int>(n));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(d[i][j] <= l) x[i][j] = 1;
            else x[i][j] = INF;
        }
    }
    for(int k = 0; k < n; k++)
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                x[i][j] = min(x[i][j], x[i][k] + x[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    while(q--)
    {
        int s, t;
        cin >> s >> t;
        s--; t--;
        if(x[s][t] == INF) cout << -1 << endl;
        else cout << x[s][t]-1 << endl;
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  mii mp;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    if (tmp < 3200)
      mp[tmp / 400]++;
    else
      mp[8]++;
  }
  if (n == mp[8]) {
    cout << 1 << " " << mp[8] << "\n";
    return;
  }
  int kazu = size(mp) - 1;
  cout << kazu << " " << kazu + mp[8] << "\n";
}

int main(void) { solve(); }

Measured memory_bytes: 3632
from fractions import gcd
from functools import reduce


def lcm_base(x,y):
    return (x*y)//gcd(x,y)


def lcm(A):
    return reduce(lcm_base,A,1)


n,m=map(int,input().split())
A=list(map(int,input().split()))
num=lcm(A)
semi=num//2

ans=0
if any([True for i in range(n) if semi%A[i]==0]):
    print(0)
elif semi<=m:
    ans +=1
    m -=semi
    ans +=m//num
    print(ans)
else:print(0)

Measured memory_bytes: 89580
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, d;
int dd[10][10];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> d;
  REP(i, n) {
    REP(j, d) {
      cin >> dd[i][j];
    }
  }

  int ans = 0;
  for(int i=0; i < n; i++) {
    for(int j=i + 1; j < n; j++) {
      int sum = 0;
      REP(k, d) {
        sum += abs(dd[i][k] - dd[j][k]) * abs(dd[i][k] - dd[j][k]);
      }
      double sq = sqrt(sum);
      if(ceil(sq) == floor(sq)) ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: ??‏/??‏/????
 *      Author: Israa
 */

#include<bits/stdc++.h>
using namespace std;


int n, k, sum, arr[1005];

int main() {
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k;
    for(int i=0; i<n; i++) {
    	cin>>arr[i];
    }
    
    sort(arr, arr+n);
    
    for(int i=0; i<k; i++) {
    	sum += arr[i];
    }
    
    cout<<sum;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long int lli;
#define tc int t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>



int main() {
	fastio;
    string s;
    cin>>s;
    int p1=0,p2=s.length()/2-1,fl=0;
    while(p1<p2)
    {
        if(s[p1]!=s[p2])
            break;
        p1++,p2--;
    }
    if(p1<p2)
        fl=1;
    p1=s.length()/2+1,p2=s.length()-1;
    while(p1<p2)
    {
        if(s[p1]!=s[p2])
            break;
        p1++,p2--;
    }
    if(p1<p2)
        fl=1;
    p1=0,p2=s.length()-1;
    while(p1<p2)
    {
        if(s[p1]!=s[p2])
            break;
        p1++,p2--;
    }
    if(p1<p2)
        fl=1;
    if(fl)
        cout<<"No\n";
    else
            cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#define LL long long

using namespace std;

const int N = 1e5 + 5;

int n, m, v, p;
int d[N];

bool cmp(int a, int b) {
    return a > b;
}

bool check(int mid) {
    if (mid <= p) return 1;
    if (d[mid] + m < d[p]) return 0;
    if (v < p && d[mid] + m >= d[p]) return 1;
    LL ans = (LL)m * p;
    for (int i = n, j = v - p; i > mid && j; i--, j--) {
        ans += m;
    }
    LL ned = (LL)m * v - ans;
    int cd;
    for (int i = p; i < mid; ++i) {
        int x = min(m, max(0, d[mid] + m - d[i]));
        if (x > ned) x = ned;
        ned -= x;
        if (i == p) {
            cd = d[p] + x;
        }
    }
    return cd <= m + d[mid] && ned <= 0;
}

int main() {
    scanf("%d%d%d%d", &n, &m, &v, &p);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &d[i]);
    }
    sort(d + 1, d + n + 1, cmp);
    int l = 1, r = n + 1;
    while (l + 1 < r) {
        int mid = (l + r) >> 1;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    printf("%d\n", l);
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        Stack<Character> stack = new Stack<>();
        for(Character c : input.toCharArray()){
            if(c != 'B')
                stack.push(c);
            else{
                if(!stack.empty())
                    stack.pop();
            }
        }
        StringBuilder result = new StringBuilder("");
        while(!stack.empty()){
            result.append(stack.pop());
        }
        result.reverse();
        System.out.println(result.toString());
    }
}


Measured memory_bytes: 21844
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n; ll A[MAXN],o[MAXN];
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n) cin>>A[i];
	ll x=0;
	FOR(i,0,n) if(i&1) x-=A[i]; else x+=A[i]; 
	A[0]-=x/2;A[n-1]-=x/2;
	cout<<x<<' ';
	FOR(i,1,n) {
		cout<<A[i-1]*2<<' ';
		A[i]-=A[i-1]; A[i-1]=0;
	}
	return 0;
}


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

int main() {
  int a;
  cin >> a;
  int b = a/1000;
  int c = a%1000/100;
  int d = a%1000%100/10;
  int e = a%1000%100%10;
  if (b == c && c == d ){
    cout << "Yes" << endl;
  }
  else if (c == d && d == e ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n,m  = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
P = 10**9+7

def s(n,i):
	return i * (n-(i-1))

def xx(x,n):
	t = 0
	for i in range(n-1):
		t = (t + s(n-1,i+1) * (x[i+1]-x[i])) % P
	return t

R = (xx(x,n) * xx(y,m)) % P 
print(R)


Measured memory_bytes: 18576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,T,k = 0;
    bool can = false;
    cin >> n >> T;
    int c[n],t[n];
    rep(j, n){
        cin >> c[k] >> t[k];
        if (t[k] <= T) {
            can = true;
            ++k;
        }
    }
    if (!can) {
        cout << "TLE" << endl;
        return 0;
    }
    qsort(c, k, sizeof(int), asc);
    cout << c[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

int main()
{
	int A, B;
	std::cin >> A >> B;

	if (B % A == 0)
		std::cout << (A+B) << "\n";
	else
		std::cout << (B-A) << "\n";

	return 0;
}


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

int main()
{
    int k, sum;
    cin >> k >> sum;

    int ans = 0;

    for(int x = 0;x <= k; x++){
        if(sum-x>2*k){
            continue;
        }
        if(sum-x<0){
            break;
        }
        if(sum-x<=k){
            ans += sum - x +1;
        }else{
            ans += 2*k - sum + x + 1;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int A[2000];
int n;

int solve(int i, int m) {
    if (m == 0) {
        return 1;
    } else if (i >= n) {
        return 0;
    } else {
        return solve(i + 1, m - A[i]) || solve(i + 1, m);
    }
}

int main(void) {
    int q, i, ans, m;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &m);
        ans = solve(0, m);
        if (ans) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
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); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;} 
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<> a(n);
    cin >> a;
    sort(all(a));
    ll ans = accumulate(a.begin(), a.begin() + k, 0);
    cout << ans << endl;
}

Measured memory_bytes: 3612
#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 ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
    ll n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    if(p == 2 || p == 5)
    {
        ll sum = 0;
        REP(i,0,n){
            if((s[i] - '0') % p == 0){
                sum += i+1;
            }
        }
        cout<<sum<<endl;
        return 0;
    }
    
    map<ll,ll> um;
    
    ll dp[n+1] = {0};
    um[0]++;
    ll sum = 0;
    ll pt = 1;

    REPI(i,0,n){
        dp[i] = (dp[i+1] + pt*(s[i] - '0')) % p;
        pt = (pt * 10) % p;
        sum += um[dp[i]];
        um[dp[i]]++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   string s;
   cin>>s;
   if(s[s.size()-1]=='s') {cout<<s<<"es"<<endl;return 0;}
   s+='s';
   cout<<s;
   cout<<endl;
}



  

Measured memory_bytes: 3684
n = int(input())
line_a = list(map(int,input().split()))
total = sum(line_a)
q = int(input())
numbers = [0 for i in range(10**5+1)]
for i in line_a:
  numbers[i] += 1

for i in range(q):
  b,c = map(int, input().split())
  d = c - b
  stock = numbers[b]
  numbers[c] += numbers[b]
  numbers[b] = 0
  total += stock*d
  print(total)


Measured memory_bytes: 21124
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
const ll MOD = 1e9 + 7;
const ll INF = 1e10;

int main() {
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(n - 1));
    rep(i,n)rep(j,n - 1) {
        cin >> a[i][n - j - 2];
        a[i][n - j - 2] --;
    }

    vector<P> q;
    
    auto check = [&](int i) {
        if (a[i].size() == 0) return;
        int j = a[i].back();
        if (a[j].back() == i) {
            if (i > j) swap(i,j);
            q.push_back(P(i,j));
        }
    };

    rep(i,n) check(i);

    int day = 0;
    while (q.size()) {
        day ++;
        sort(q.begin(),q.end());
        q.erase(unique(q.begin(),q.end()),q.end());
        vector<P> prevQ;
        swap(prevQ,q);
        for (P p: prevQ) {
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (P p: prevQ) {
            int i = p.first,j = p.second;
            check(i);
            check(j);
        }
    }

    rep(i,n) {
        if (a[i].size() != 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.valueOf(br.readLine());
        
        double pi = 3.14159265358979;
        
        String square = String.format("%.06f", r * r * pi);
        String round = String.format("%.06f", 2 * pi * r);
        
        System.out.println(square + " " + round);
    }
}


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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int H, W, D;
    cin >> H >> W >> D;

    vector< vector<int>> A(H, vector<int>(W, 0));
    vector< pair<int, int>> index(H*W);

    REP(h, H) {
        REP(w, W) {
            cin >> A[h][w];
            A[h][w]--;

            index[A[h][w]] = make_pair(h, w);
        }
    }

    vector< vector< ll >> cost(D, vector<ll>(H*W/D+100, 0LL));
    REP(d, D) {
        int i = 1;

        while(d + i * D < H * W) {
            pair<int, int> p = index[d + (i-1) * D];
            pair<int, int> q = index[d + (i) * D];

            cost[d][i] = cost[d][i-1] + abs(p.first - q.first) + abs(p.second - q.second);

            i++;
        }
    }

    int Q;
    cin >> Q;
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        l--; r--;

        cout << cost[r%D][r/D] - cost[l%D][l/D] << endl;
    }

    return 0;
}

Measured memory_bytes: 75392
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N;
  sc.scan(N);

  int[] A = new int[N];
  int[] B = new int[N];
  long[] sum = new long[N];
  foreach (i; 0 .. N) {
    sc.scan(A[i], B[i]);
    sum[i] += A[i] + B[i];
  }

  sort(sum);
  reverse(sum);
  long res = 0;

  foreach (i; 0 .. N) {
    if (i % 2 == 1)
      res -= sum[i];

    res += A[i];
  }

  writeln(res);
}


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

n = int(input())
h = list(map(int, input().split()))
f_inf = float("inf")
dp = [f_inf] *(10**5 +10)

def chmin(a,b):
    if a<b:
        return a
    else:
        return b

def rec(i):
    if dp[i] < f_inf: #更新されてたらそのまま返す
        return dp[i]

    if i == 0 :
        return 0
    
    res = f_inf

    res = chmin(res, rec(i-1) + abs(h[i]-h[i-1]))
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i]-h[i-2]))
    dp[i] = res

    return res
print(rec(n-1))


Measured memory_bytes: 93956
import sys
sys.setrecursionlimit(2000000000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
dic={}
c=[0]
for i in range(n):
    t=int(input())
    if c[-1]!=t:
        c.append(t)
g=[[i+1] for i in range(len(c)-1)]
g.append([])
for i in range(len(c)):
    if c[i] in dic:
        g[dic[c[i]]].append(i)
        dic[c[i]]=i
    else:
        dic[c[i]]=i
ans_table=[0 for i in range(len(c))]
ans_table[-1]=1
for i in range(len(c)-1):
    i=len(c)-2-i
    for to in g[i]:
        ans_table[i]+=ans_table[to]
print(ans_table[0]%(10**9+7))

Measured memory_bytes: 795428
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	long long mi=0,n,ans=0;
	cin >> n;
	vector<long long> vec(n,0);
	for(int i=0;i<n;i++){
		cin >> vec[i];
		if(vec[i]<0)mi++;
		vec[i]=abs(vec[i]);
		ans+=vec[i];
	}
	sort(vec.begin(),vec.end());
	if(mi%2==1)ans-=2*vec[0];
	cout << ans;
}

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int a = cin.nextInt();
        int b = cin.nextInt();
        int ans = 0;
        for (int i = 1; i <= b - a; i++)
        {
            ans += i;
        }
        Console.WriteLine(ans - b);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

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

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
using namespace std;
char s[10];
int ci1,ci2;
int main()
{
	scanf("%s",s+1);
	for(int i=1;i<=3;i++)
	{
		if(s[i]=='A')
		{
			ci1++;
		} 
		if(s[i]=='B')
		{
			ci2++;
		}
	}
	if(ci1&&ci2)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
x,y=gets.split.map &:to_i
if(x==2)
    puts y==2?:Yes: :No
elsif(a.include?(x))
    puts a.include?(y)?:Yes: :No
else
    puts b.include?(y)?:Yes: :No
end

Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
    int d,n,c;
    scanf("%d %d",&d,&n);
     if(n==100)
     {
         n++;
     }
    if(d==0)
    {
        c=n;
    }
    else if(d==1)
    {
        c=n*100;
    }
    else
    {
        c=n*100*100;
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <utility>

using namespace std;

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define printi(x) printf("%d ", x)
#define printiln(x) printf("%d\n", x)
#define printiarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1])
#define scani(x) scanf("%d", &x)
#define scaniarray(a,n) for(int i=0; i<n; i++){scanf("%d", &a[i]);}
#define scans(str) scanf("%s",str)
#define scanc(ch) scanf("%c", &ch)

int main() {
    stack<int> S1;
    stack<pair<int,int> > S2;
    char x;
    int sum=0, subsum=0;
    for(int i=0; scanc(x) != EOF; i++) {
        int j;
        if(x == '\\') {
            S1.push(i);
        }
        else if(x == '/' && S1.size() > 0) {
            j = S1.top(); S1.pop();
            int a = i-j;
            sum += a;
            while(S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second; S2.pop();
            }
       
        	S2.push(make_pair(j,a));
        }
    }
    
    int ans[S2.size()];
    int i=S2.size()-1;
	int size = i+1;
    while(S2.size() > 0) {
    	ans[i--] = S2.top().second;
        S2.pop();
    }
    printiln(sum);
	if(size > 0){
		printi(size);
		printiarray(ans,size);
	} else {
		printiln(size);
	}
    
    
    return 0;
}


Measured memory_bytes: 2836
#include <stdio.h>

int main(void){
	int a[3];
	int i,j;
	int temp;
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	
	for(i=0;i<3;++i){
		for(j=i+1;j<3;++j){
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}  
		}
	}
	
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, k; cin >> n >> k;
    int G = 0;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        G = __gcd(a[i], G);
    }

    bool res = false;
    for(int i = 0; i < n; i++) {
        if(a[i] - k >= 0 && (a[i] - k) % G == 0)res = true;
    }
    cout << (res ? "POSSIBLE" : "IMPOSSIBLE" ) << endl;

}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int const F[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    int K;
    cin >> K;
    cout << F[K-1] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

int a[12];

void dfs(int bit,int mx)
{   
    if(bit == n)
    {   
        for(int i = 0; i < n; i++) 
        {
            putchar('a'+a[i]);
        }
        putchar('\n');
        return;
    }
    for(int i = 0; i <= mx+1; i++)
    {   
        a[bit] = i;
        dfs(bit+1,max(mx,i));
    }
}

signed main()
{
    cin>>n;
    a[0] = 0;
    dfs(1,0);
    return 0;
}

Measured memory_bytes: 1536