akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
	int upmax,downmax;
	int pre,now;
	int t,n,i;
	scanf("%d",&t);
	for(;t>0;t--){
		scanf("%d",&n);
		upmax = 0;
		downmax = 0;
		for(i=0;i<n;i++){
			scanf("%d",&now);
			if(i==0){
				pre = now;
				continue;
			}
			if((now>pre)&&(upmax<(now-pre))){
				upmax = now-pre;
			}
			if((now<pre)&&(downmax<(pre-now))){
				downmax = pre-now;
			}
			pre = now;
		}
		printf("%d %d\n",upmax,downmax);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long A,B,N;
    scanf("%llu%llu%llu",&A,&B,&N);
    if(N>=B)
    printf("%llu\n",(A*(B-1))/B);
    else
    printf("%llu\n",(A*N)/B);
    return 0;
}


Measured memory_bytes: 3792
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    xl = [list(map(int,input().split())) for i in range(n)]
    s = [(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
    s.sort(key = lambda x:x[1])
    cnt = 1
    t = s[0][1]
    for i in range(1,n):
        if t <= s[i][0]:
            cnt += 1
            t = s[i][1]
    print(cnt)
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 45352
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int n, m;
    while(cin >> n >> m, n){
        vector< vector<lint> > c(m, vector<lint>(m, LLINF)), t(m, vector<lint>(m, LLINF));
        rep(i, m){
            c[i][i] = 0;
            t[i][i] = 0;
        }

        rep(i, n){
            int a, b;
            lint co, ti;
            cin >> a >> b >> co >> ti;
            chmin(c[--a][--b], co);
            chmin(c[b][a], co);
            chmin(t[a][b], ti);
            chmin(t[b][a], ti);
        }

        rep(k, m){
            rep(i, m){
                rep(j, m){
                    chmin(c[i][j], c[i][k] + c[k][j]);
                    chmin(t[i][j], t[i][k] + t[k][j]);
                }
            }
        }

        int query;
        cin >> query;
        while(query--){
            int p, q, r;
            cin >> p >> q >> r;
            --p;
            --q;
            if(r == 0){
                cout << c[p][q] << endl;
            }else{
                cout << t[p][q] << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3148
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int n,m;
        int result = 0;
        
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		int A[][] = new int[n][m];
		int b[]   = new int[m];
		
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				A[i][j] = scanner.nextInt();
			}
		}
		
		for(int i = 0;i < m;i++){
			b[i] = scanner.nextInt();
		}
		
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				result += A[i][j]*b[j];
			}
			System.out.println(result);
			result = 0;
		}
    	scanner.close();
    }
}

Measured memory_bytes: 40052
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;




  cout << (n>=30?"Yes":"No") << endl;

}

Measured memory_bytes: 3644
n=int(input())
a = list(map(int,input().split()))
ans = [0]*100010
ans[0] = 1
flag = 0
for i in range(n-1):
    if flag == 0:
        if a[i] < a[i+1]:
            flag = 1
        elif a[i] > a[i+1]:
            flag = -1
        else:
            flag = 0
        continue

    if flag == 1 and a[i] <= a[i+1]:
        continue
    if flag == 1 and a[i] > a[i+1]:
        flag = 0
        ans[i] = 1
        continue

    if flag == -1 and a[i] >= a[i+1]:
        continue
    if flag == -1 and a[i] < a[i+1]:
        flag = 0
        ans[i] = 1
        continue

print(ans.count(1))
    
    


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	long long int ans = 0;

	vector<int> a;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push_back(t);
	}

	for(int i=0; i<n; i++){
		if(a[i] > 0 && a[i] % 2 == 0){
			ans += (a[i] - 2) / 2;
			a[i] %= 2;
			a[i] = 2;
		}else{
			ans += a[i] / 2;
			a[i] %= 2;
		}
	}
	/*
	puts("#########");
	for(int i=0; i<n; i++){
		cout << a[i] << endl;
	}
	puts("#########");
	*/
	for(int i=0; i<n-1; i++){
		if(a[i] == 1 && a[i+1] > 0){
			ans++;
			a[i]--;
			a[i+1]--;
		}else if(a[i] == 2){
			ans++;
			a[i] = 0;
		}
	}
	if(a[n-1] == 2){
		ans++;
		a[n-1] = 0;
	}

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 1400
import java.util.*;

public class Main {

    static int[] dp;

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

        long x = sc.nextLong();
        long k = sc.nextLong();
        long d = sc.nextLong();

        x = Math.abs(x);

        long ret = 0;

        long r = x/d;
        if(k<=r){
            ret = x-d*k;
            System.out.println(ret);
            return;
        }else{
            k-=r;
            x-=d*r;
        }

        if(k%2!=0) ret = -(x - d);
        else ret = x;

        System.out.println(ret);

        sc.close();
    }


}

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

int main(){
  int N, K;
  cin >> N >> K;
  int ans=0;
  for(int i=0; i<N; i++){
    int h;
    cin >> h;
    if(h>=K) ans++;
  }
  cout << ans << endl;
}

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


#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1000000007ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int n, m;
vector<ll> A(101010);
vector<pair<ll, ll>> BC(101010);

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int main() {
    scanf("%d%d", &n, &m);
    rp(i, 0, n){
        scanf("%lld", &A.at(i));
    }
    rp(i, 0, m){
        scanf("%lld%lld", &BC.at(i).second, &BC.at(i).first);
    }
    sort(A.begin(), A.begin() + n);
    sort(BC.rbegin(), BC.rend());

    int pointer = 0;
    rp(i, 0, m){
        rp(j, 0, BC.at(i).second){
            if(A.at(pointer) < BC.at(i).first) A.at(pointer) = BC.at(i).first;
            pointer ++;
            if(pointer == n){
            ll ans = 0;
            rp(i, 0, n) ans += A.at(i);
            printf("%lld\n", ans);
            return 0;
            }
        }
        
    }
    ll ans = 0;
    rp(i, 0, n) ans += A.at(i);
    printf("%lld\n", ans);
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 998244353;

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

  int a,b,h,m;
  cin >> a >> b >> h >> m;

  m += h*60;
  double da = 0.5 * m, db = 6 * m % 360;
  double dif = da - db;
  if(dif < 0)dif *= -1;

  dif *= 2 * M_PI / 360;

  double ret = sqrt(a*a + b*b - 2*a*b*cos(dif));


  cout << setprecision(10) << ret << endl;
}

Measured memory_bytes: 4272
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    PRINT(((N + 1000 - 1) / 1000) * 1000 - N);
    return 0;
}

Measured memory_bytes: 3680
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}


const int N = 1e6 + 100;

pii a[N]; 
int cnt;
int R, C, n;
void insert(int x, int y, int id) {
    if(x == 0) {
        a[++ cnt] = pii(y, id);
    } else if(x == R) {
        a[++ cnt] = pii(2 * C + R - y, id);
    } else if(y == C) {
        a[++ cnt] = pii(C + x, id);
    } else if(y == 0) {
        a[++ cnt] = pii(2 * C + 2 * R - x, id);
    }
}

vector<int> vec;
int main() {
    cin >> R >> C >> n;
    for(int i = 1; i <= n; i ++) {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        if(pii(x1, y1) > pii(x2, y2)) swap(x1, x2), swap(y1, y2);
        if( (x1 == 0 || x1 == R || y1 == 0 || y1 == C ) && 
                (x2 == 0 || x2 == R || y2 == 0 || y2 == C)) {
            insert(x1, y1, i);
            insert(x2, y2, i);
        }
    }
    sort(a + 1, a + cnt + 1);
    for(int i = 1; i <= cnt; i ++) {
        if(vec.empty() || vec[SZ(vec) - 1] != a[i].Y) vec.push_back(a[i].Y);
        else vec.pop_back();
    }
    puts(SZ(vec) ? "NO" : "YES");
}



Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll H, A;
  cin >> H >> A;

  cout << divceil(H, A) << endl;
}

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

int main(int argc, char const* argv[]) {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    int sum = 0;
    std::vector<int> A;
    A.push_back(0);
    for (int i=0; i<N; i++) {
        int Ai;
        std::cin >> Ai;
        A.push_back(Ai);
    }
    A.push_back(0);

    int dist = 0;
    for (int i=1; i<A.size(); i++) {
        dist += std::abs(A[i] - A[i-1]);
    }

    for (int i=1; i<A.size()-1; i++) {
        int res = dist - std::abs(A[i] - A[i-1])
                       - std::abs(A[i+1] - A[i])
                       + std::abs(A[i+1] - A[i-1]);
        std::cout << res << '\n';
    }
    return 0;
}

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

int main()
{
	int a, b, c;
	
	cin >> a >> b >> c;
	
	if(a < b && b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
		
		return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;

const ll MAX_N=2e5;

ll N,A[MAX_N];

void solve(){
	if (A[0]!=0){
		cout<<-1<<endl;
	}else{
		ll ans=0;
		FOR(i,1,N){
			if (A[i-1]+1<A[i]){
				cout<<-1<<endl;
				return;
			}else if (A[i-1]+1==A[i]){
				ans++;
			}else{
				ans+=A[i];
			}
		}
		cout<<ans<<endl;
	}
}

int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int a[100];

int main(){
	int K,T;
	cin >> K >> T;
	rep(i,T){
		cin >> a[i];
	}
	int m=0;
	rep(i,T){
		m = max(m,a[i]);
	}
	int ans=m-(K-m)-1;
	if(ans<=0){
		cout << 0 << endl;
	}else{
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n, S[10000], q, flag = 1, T[10000], i, count = 0, key, j, Q, N;
    scanf("%d", &n);
    i = 0;
    N = n;
    while ( n-- ) {
        scanf("%d", &S[i]);
        i++;
    }
    scanf("%d ", &q);
    Q = q;
    i = 0;
    while ( q-- ) {
        scanf("%d", &T[i]);
        i++;
    }
    while ( flag == 1) {
        flag = 0;
        for ( j = n - 1; j >= 1; j-- ) {
            if ( S[j] < S[j - 1] ) {
                key = S[j];
                S[j] = S[j - 1];
                S[j - 1] = key;
                flag = 1;
            }
        }
    }
    for ( i = 0; i < Q; i++ ) {
        for ( j = 0; j < N; j++ ) {
            if ( S[j] == T[i]) break;
        }
        if ( j < N ) count++;
    }
    printf("%d\n", count);
}

Measured memory_bytes: 1804
from collections import defaultdict

n = int(input())
s = input()


def solve(s):
    d = defaultdict(int)
    for i in range(2**n):
        blue = red = ""
        for k in range(n):
            if 1 << k & i:
                blue += s[k]
            else:
                red += s[k]
        d[(blue, red)] += 1
    return d


left = solve(s[:n])
right = solve(s[::-1][:n])


ans = 0
for (b, r), v in left.items():
    ans += v * right[(r, b)]

print(ans)

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<pair<int, int>> r, b;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    r.emplace_back(x, y);
  }
  sort(r.rbegin(), r.rend());
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    b.emplace_back(x, y);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    int ymin = 1000, jmin = -1;
    for (int j = 0; j < b.size(); j++) {
      if (r.at(i).first < b.at(j).first && r.at(i).second < b.at(j).second
         && b.at(j).second < ymin) {
        ymin = b.at(j).second;
        jmin = j;
      }
    }
    if (jmin != -1) {
      b.erase(b.begin() + jmin);
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>

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

	unsigned long long times = N / (A + B);
	unsigned long long mod = N % (A + B);

	unsigned long long count = A * times + ((A < mod) ? A : mod);

	std::cout << count << std::endl;

	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define inf (long long) 1e18

typedef long long ll;
typedef long double ld;

const int N = 123456;
const int M = 1234567;
const int P = 400004;
const int A = 256;


int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg1o1
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	

	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	// srand(time(0));

	int n, a, b;
	cin >> n >> a >> b;

	int diff = a - b;

	int x[123456];

	for(int i = 0; i < n; ++i)
		cin >> x[i];

	int l = 1;
	int r = (int) 1e9;

	while(l <= r){

		int mid = (l + r) >> 1;

		ll As = 0;

		for(int i = 0; i < n; ++i){

			ll h = x[i] - mid * 1ll * b;

			if(h > 0)
				As += (h + diff - 1) / diff;
			
		}

		if(As <= mid)
			r = mid - 1;
		else
			l = mid + 1;

	}

	cout << l << endl;

	return 0;					
}


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

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

const long long INF = 1LL << 60;
const long long mod = 1000000007;

ll sum[202020] = {0};

int main(void){
	int n,k;cin >> n >> k;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		sum[i] = sum[i-1] + i;
		//0|0,1|1,2|3,3|6,4|10,5|15,6|21 
	}
	for(int i=k;i<=n;i++){
		ans += (sum[n]-sum[n-i])-sum[i-1] + 1;//sum[0] = 0;
		ans %= mod;
		//cout << ans << endl;
	}
		ans += 1;
	cout << ans << endl;
}


Measured memory_bytes: 5184
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
dist = [[0 for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j in range(10):
        dist[i][j] = C[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
cnt = 0
for i in range(H):
    for j in range(W):
        if A[i][j]>=0:
            cnt += dist[A[i][j]][1]
print(cnt)

Measured memory_bytes: 74044
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
using ulli = unsigned long long int;
#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(args...) do {cerr << #args << " : "; debug(args); } while(0)
#define all(v) ((v).begin()),((v).end())
#define size(x) (int) x.size() 
#define pb emplace_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
void debug () {cerr << endl;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template < typename T, typename ... hello>void debug( T arg, const hello &... rest) {cerr << arg << ' ';debug(rest...);}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    cout<<s.substr(0,3);
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
int main(){
	char s[35];
	gets(s);
	
	char *s1 = strtok(s, " ");
	char *s2 = strtok(NULL, " ");
	char *s3 = strtok(NULL, " ");
	
	int len1 = strlen(s1);
	int len2 = strlen(s2);
	
	if(s1[len1-1] == s2[0] && s2[len2-1] == s3[0]){
		printf("YES\n"); 
	}else{
		printf("NO\n");
	}
	return 0;
} 

Measured memory_bytes: 128
/*
 * Pawan Harendra Mishra
 */

/*
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
*/

/*
 * Windows Powershell
 * Get-Content input.txt | ./a.exe > output.txt
 */

#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define N 101
ll n;
pair<ll, pair<string, ll> > r[N];

bool compare(pair<ll, pair<string, ll> >a,
pair<ll, pair<string, ll> >b) {
    if (a.Y.X != b.Y.X) return a.Y.X < b.Y.X;
    else return a.Y.Y > b.Y.Y;
}

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // //freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif
    
    cin >> n;
    for (ll i=0; i<n; i++) {
        r[i].X = i+1;
        cin >> r[i].Y.X;
        cin >> r[i].Y.Y;
    }
    sort(r, r+n, compare);
    for (ll i=0; i<n; i++) cout << r[i].X << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  vector<int> X(S.size());
  for(int i=0;i<S.size();i++){
    X[i] = S[i];
  }
  int start, end;
  do{
    start = X.size();
    for(int i=0;i<X.size()-1;i++){
      if(X[i]!=X[i+1]){
        X.erase(X.begin() + i, X.begin() + i+2);
        break;
      }
    }
    end = X.size();
  }while(start!=end && end!=0);
  cout << S.size() - X.size() << endl;
  return 0;
}


Measured memory_bytes: 896
from bisect import bisect_left,bisect_right

mod=10**9+7
n,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=list(map(int,input().split()))
arr2=sorted(arr2)
s1=set()
s2=set()
for val in arr1:
  s1.add(val)
for val in arr2:
  s2.add(val)
if len(s1)!=n or len(s2)!=m:
  print(0)
else:
  ans=1  
  for i in range(n*m,0,-1):
    if (i in s1) and (i in s2):
      ans*=1
      ans%=mod
    elif i in s1:
      ans*=(m-bisect_left(arr2,i))
      ans%=mod
    elif i in s2:
      ans*=(n-bisect_left(arr1,i))
      ans%=mod
    else:
      ans*=((n-bisect_left(arr1,i))*(m-bisect_left(arr2,i))-(n*m-i))
      ans%=mod
  print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(iinclude<snt i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct uf {
private:
	vector<int> par, ran;
	vector<int> num;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
		num.resize(n, 1);
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
			num[y] += num[x];
		}
		else {
			par[y] = x;
			num[x] += num[y];
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int cal(int x) {
		return num[x];
	}
};

//oddなら先手の勝ち
bool odt;
bool used[2000][1001][2];
bool ansed[2000][1001][2];

bool dfs(int x, int y, int id) {
	if (used[x][y][id])return ansed[x][y][id];
	used[x][y][id] = true;
	if (x == 2&&y==0)return ansed[x][y][id] = !odt;
	if (y == 2&&x==0)return ansed[x][y][id] = odt;
	bool ret;
	if (id == 0) {
		ret = false;
		if (y >= 2) {
			if (dfs(x + 1, y - 2, 1))ret = true;
		}
		if (x >= 1) {
			if (dfs(x - 1, y, 1))ret = true;
		}
		return ansed[x][y][id] = ret;
	}
	else {
		ret = true;
		if (y >= 2) {
			if (!dfs(x + 1, y - 2, 0))ret = false;
		}
		if (x >= 1) {
			if (!dfs(x - 1, y, 0))ret = false;
		}
		return ansed[x][y][id] = ret;
	}
}

void solve(){
	int n; cin >> n;
	int cnt = 0;
	uf u; u.init(n+1);
	rep(i, n) {
		rep(j, n) {
			char t; cin >> t;
			if (i < j&&t == 'Y') {
				u.unite(i, j);
				cnt++;
			}
		}
	}
	bool ans = true;
	if (n % 4 == 1) {
		if (cnt % 2) {
			ans = true;
		}
		else {
			ans = false;
		}
	}
	else if (n % 4 == 3) {
		if (cnt % 2) {
			ans = false;
		}
		else {
			ans = true;
		}
	}
	else {
		if (n % 4 == 2) {
			if (cnt % 2) {
				odt = true;
			}
			else {
				odt = false;
			}
		}
		else {
			if (cnt % 2)odt = false;
			else odt = true;
		}
		vector<bool> chked(n, false);
		int c[2] = {};
		rep(i, n) {
			int p = u.find(i);
			if (!chked[p]) {
				chked[p] = true;
				c[u.cal(p) % 2]++;
			}
		}
		ans = dfs(c[0], c[1], 0);
	}
	if (ans) {
		cout << "Taro" << endl;
	}
	else {
		cout << "Hanako" << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


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

int main(){
  int t;
  cin>>t;
  vector<int>np(3,0);
  vector<int>dp(3,0);
  vector<int>c(3);
  while(t--){
    for(int i=0;i<3;i++){
      cin>>c[i];
    }
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(i!=j){
          np[j]=max(np[j],dp[i]+c[j]);
        }
      }
    }
    dp=np;

  }
  int dd=max(dp[1],dp[2]);
  cout<< max(dp[0],dd);

}


Measured memory_bytes: 256
use strict;
use utf8;
use warnings;

sub mkcharcountarray{
    my $s = shift @_;
    my @counts = (0) x 26;
    foreach my $ac (split //, $s){
        my $inx = ord($ac) - 97;
        $counts[$inx] += 1;
    }
    \@counts;
}
chomp(my $n = <STDIN>);
chomp(my @lines = <STDIN>);
my @counts = ();
foreach (1..$n){
    push @counts, &mkcharcountarray($lines[$_ - 1]);
}
my @alphabets_count = (0) x 26;
foreach my $i(0..25){
    my $tmin = 51;
    foreach my $j(0..$n-1){
        my $t = $counts[$j][$i];
        if ($t < $tmin){
            $tmin = $t;
        }
    }
    @alphabets_count[$i] = $tmin;
}
my $ans = "";
foreach my $i(0..25){
    my $t = $i + 97;
    my $loop_cnt = $alphabets_count[$i];
    foreach my $j(0..$loop_cnt-1){
        my $ch = chr($t);
        $ans = $ans.$ch;
    }
}
print "$ans\n";


Measured memory_bytes: 768
#[allow(unused_macros)]
macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            let mut next = || { iter.next().unwrap() };
            input_inner!{next, $($r)*}
        };
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! input_inner {
        ($next:expr) => {};
        ($next:expr, ) => {};
     
        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
     
        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };
     
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };
     
        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };
     
        ($next:expr, bytes) => {
            read_value!($next, String).into_bytes()
        };
     
        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };
     
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }

fn main() {
    input! {
            n: usize,
            hats: [i32; n],
        }

    let ans = hats.iter().fold(0, |acc, e| acc ^ e);

    println!("{}", if ans == 0 { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
using System;

class AOJ
{
	public static void Main()
	{
		var input = Console.ReadLine().Trim().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		if(a > b){ Console.WriteLine("a > b"); }
		else if(a < b){ Console.WriteLine("a < b"); }
		else{ Console.WriteLine("a == b"); }
	}
}

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


int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int t;
	t=a;
	a=b;
	b=t;
	t=a;
	a=c;
	c=t;
	cout<<a<<" "<<b<<" "<<c<<endl; 
	return 0;
} 

Measured memory_bytes: 3600
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    let mut tab = vec![vec![0; 10]; 10];
    for i in 1..n + 1 {
        let y = i % 10;
        let mut x = i;
        while x / 10 > 0 {
            x /= 10;
        }
        tab[x][y] += 1;
    }
    let mut ans: usize = 0;
    for i in 1..10 {
        for j in 1..10 {
            ans += tab[i][j] * tab[j][i];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

class Segtree {
public:
	int n;
	vector<int>data;
public:
	Segtree(int _n,int MAX) {
		n = 1;
		while (n < _n) n *= 2;
		for (int i = 0; i < 2 * n - 1; i++) {
			data.push_back(MAX);
		}
	}

	void update(int k, int a) {
		k += n - 1;
		data[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = min(data[k * 2 + 1], data[k * 2 + 2]);
		}
	}

	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return data[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}

	int query(int s, int t) {
		return query(s, t + 1, 0, 0, n);
	}
};

signed main() {
	int n, q;
	cin >> n >> q;
	Segtree seg(n, (1LL << 31) - 1);
	rep(i, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) seg.update(x, y);
		else cout << seg.query(x, y) << endl;
	}

	return 0;
}



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

int main(){
	int i, x, y;
		for(i=1; ; i++){
			cin >> x >> y;
			
			if(x == 0 && y == 0){
				break;
			}
			
			if(x >= y){
				cout << y << " " << x << endl;
			}
			
			else{
				cout << x << " " << y << endl;
			}
			
		}
	return 0;
}

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

int bubblesort(vector<int> &a,int n);

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a.at(i);
    }
    int x=bubblesort(a,n);
    rep(i,n){
        cout<<a.at(i);
        if(i!=n-1){
            cout<<' ';
        }
        else{
            cout<<endl;
        }
    }
    cout<<x<<endl;
    return 0;
}

int bubblesort(vector<int> &a,int n){
    int c=0;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i+1;j--){
            if(a.at(j)<a.at(j-1)){
                int tmp=a.at(j);
                a.at(j)=a.at(j-1);
                a.at(j-1)=tmp;
                c++;
            }
            
        }
    }
    return c;
}
 


Measured memory_bytes: 3088
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func CreateList(n int, input string) []int {
	list := make([]int, n)
	elements := strings.Split(input, " ")
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(elements[i])
	}
	return list
}

func Swap(list *[]int, lhs int, rhs int) {
	(*list)[lhs], (*list)[rhs] = (*list)[rhs], (*list)[lhs]
}

func SwapRange(list *[]int, begin int , end int, t int) {
	// fmt.Printf("%d %d %d\n", begin, mid, end)
	for k := 0; k < end - begin; k++ {
		Swap(list, begin + k, t + k)
	}
}

func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)
	lines, _ := ReadLongLines(1)
	list := CreateList(n, lines[0])

	// query
	var q int
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)
	for _, v := range lines {
		args := strings.Split(v, " ")
		begin, _ := strconv.Atoi(args[0])
		end, _ := strconv.Atoi(args[1])
		t, _ := strconv.Atoi(args[2])
		SwapRange(&list, begin, end, t)
	}

	for i := 0; i < len(list); i++ {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}


Measured memory_bytes: 1320
// slight modification similar logic errichto's code

#include <bits/stdc++.h>

using namespace std;


const int INF = 1e9 + 5;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n; 
    cin >> n ; 
    vector<int> h(n);

    for(int & x: h){
        cin >> x ; 
    }

    vector<int> dp(n , INF);

    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j : {i+1,i+2}){
            if (j < n){
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    cout << dp[n-1] << "\n";
    
    
 
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    int A,B;
    string S;
    bool F=true;
int main(){
    cin>>A;
    cout<<((((A%1000)%111==0)||((A/10)%111==0))?"Yes":"No")<<endl;
    return 0;

}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
t = ns()
q = ni()

sa = [0]
sb = [0]
ta = [0]
tb = [0]

for si in s:
    if si == "A":
        sa.append(sa[-1] + 1)
        sb.append(sb[-1])
        
    else:
        sa.append(sa[-1])
        sb.append(sb[-1] + 1)
        
for ti in t:
    if ti == "A":
        ta.append(ta[-1] + 1)
        tb.append(tb[-1])
        
    else:
        ta.append(ta[-1])
        tb.append(tb[-1] + 1)
        
for _ in range(q):
    a,b,c,d = li()
    
    sanum = sa[b] - sa[a-1]
    sbnum = sb[b] - sb[a-1]
    
    tanum = ta[d] - ta[c-1]
    tbnum = tb[d] - tb[c-1]
    
    sanum += 2*sbnum
    tanum += 2*tbnum
    
    if sanum%3 == tanum%3:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 13712
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

int main()
{
	S a,b;
	cin>>a>>b;
	cout<<b+a<<endl;
}

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

int main(){
int h,w;
cin >> h >> w;

//(x,y)=(j,i);
vector<vector <char>> f(w,vector<char>(h));

rep(i,h)
{   rep(j,w)
    {   //(x,y)=(j,i);
        cin >> f[j][i];
    }
}

string ans="Yes";
int xvec[]={1,0, 0,-1};
int yvec[]={0,1,-1, 0};
rep(i,h)
{
    rep(j,w)
    {
      if(f[j][i]=='#')
       {bool can=false;
        rep(k,4)
            {int nx=j+xvec[k];int ny=i+yvec[k];
         
             if(nx<0 || ny<0 || w<=nx || h <= ny)
             {continue;}
             else if(f[nx][ny]=='#')
             {can=true;}
             
            }
         if(!can)
         {ans="No";break;}
       }
    }
}



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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100;

int N;
int A[2][MAX_N], S[2][MAX_N+1];
int dp[2][MAX_N];

int main()
{
  scanf( "%d", &N );
  rep( i, 2 ) rep( j, N )
    scanf( "%d", &A[i][j] ), S[i][j+1] = S[i][j]+A[i][j];
  
  int ans = 0;
  rep( i, N )
    ans = std::max( ans, S[0][i+1]+S[1][N]-S[1][i] );

  printf( "%d\n", ans );

  return 0;
}

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

int main()
{
    string str;
    int a,b,c,d;
    cin >> str;

    a = str[0] - '0';
    b = str[1] - '0';
    c = str[2] - '0';
    d = str[3] - '0';

    if(a + b + c + d == 7)
    {
        cout << a << "+" << b << "+" << c << "+" << d << "=7"<< endl;
    }
    else if(a + b + c - d == 7)
    {
        cout << a << "+" << b << "+" << c << "-" << d << "=7"<< endl;
    }
    else if(a + b - c + d == 7)
    {
        cout << a << "+" << b << "-" << c << "+" << d << "=7"<< endl;
    }
    else if(a + b - c - d == 7)
    { 
        cout << a << "+" << b << "-" << c << "-" << d << "=7"<< endl;
    }
    else if(a - b + c + d == 7)
    {
        cout << a << "-" << b << "+" << c << "+" << d << "=7"<< endl;
    }
    else if(a - b + c - d == 7)
    {
        cout << a << "-" << b << "+" << c << "-" << d << "=7"<< endl;
    }
    else if(a - b - c + d == 7)
    {
        cout << a << "-" << b << "-" << c << "+" << d << "=7"<< endl;
    }
    else if(a - b - c - d == 7)
    {
        cout << a << "-" << b << "-" << c << "-" << d << "=7"<< endl;
    }
    else
    {
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int x,y,b;
	bool k;
	cin>>x>>y;
	b=y-2*x;
	if(b%2)
    {
        k=0;
    }
    else
    {
        b/=2;
        if(b>x||b<0)
        {
            k=0;
        }
        else
        {
            k=1;
        }
    }
    if(k)cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}


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

string s;

void solve(){
    cin >> s;
    int ans=0,cnt=1;
    for(int i=0;i<3;++i) {
        if(s[i] != 'R')
            continue;
        for(int j=i+1;j<3&&s[j]=='R';++j) {
            cnt++;
        }
        ans=max(ans,cnt);
        cnt=1;
    }
    cout << ans << "\n";

}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 3656