akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; 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;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){ // xとyに分けてdp

  string s;
  cin>>s;

  int x,y;
  cin>>x>>y;

  vector<int> vx;
  vector<int> vy;

  int fs=0;
  bool xdir=true;
  rep(i,s.length()){
    if(s[i]=='T'){
      if(xdir) vx.emplace_back(fs);
      else vy.emplace_back(fs);
      fs=0;
      xdir=!xdir;
    }
    else{
      fs++;
      if(i==s.length()-1){
        if(xdir) vx.emplace_back(fs);
        else vy.emplace_back(fs);
      }
    }
  }

  bool xdp[vx.size()+1][16001]={};
  bool ydp[vy.size()+1][16001]={};

  xdp[0][8000]=true;
  ydp[0][8000]=true;

  rep(i,vx.size()){
    rep(j,16001){
      if(xdp[i][j]){
        xdp[i+1][j+vx[i]]=true;
        if(i!=0) xdp[i+1][j-vx[i]]=true;
      }
    }
  }

  rep(i,vy.size()){
    rep(j,16001){
      if(ydp[i][j]){
        ydp[i+1][j+vy[i]]=true;
        ydp[i+1][j-vy[i]]=true;
      }
    }
  }

  cout<< ( xdp[vx.size()][x+8000] and ydp[vy.size()][y+8000] ? "Yes" : "No" )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

#define MAX 3

int main() {
	int A, B;

	cin >> A >> B;

	int ans;
	if( B % A == 0 ) {
		ans = A + B;
	}
	else {
		ans = B - A;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i], &b[i])
	}

	sort.Ints(a)
	sort.Ints(b)
	if n%2 == 0 {
		ans := (b[n/2] + b[n/2-1]) - (a[n/2] + a[n/2-1]) + 1
		fmt.Println(ans)
	} else {
		fmt.Println(b[n/2] - a[n/2] + 1)
	}
}


Measured memory_bytes: 8424
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
vector<long> dp(100001, -1); 
long minCost(int i, vector<int> &a) {
  if(i==a.size()-1) return 0;
  if(dp[i]!=-1) return dp[i];
  dp[i] = abs(a[i+1]-a[i]) + minCost(i+1, a);
  if(i+2<a.size()) dp[i] =  min(dp[i],abs(a[i+2]-a[i]) + minCost(i+2, a));
  return dp[i];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //int t;
    //cin >> t;
    //while(t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    cout << minCost(0, a); 
    
    //}
    return 0;
}


Measured memory_bytes: 8572
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

bool eq(const string &s, size_t pos, char c2) {
  return pos < s.length() and (s[pos] == c2 or s[pos] == '?');
}

bool is_greater(const string &s1, const string &s2) {
  if (s1 == "invalid") {
    return true;
  } else if (s2 == "invalid") {
    return false;
  }
  return s1.length() == s2.length()? s1 < s2: s1.length() < s2.length();
}

string compute(string s) {
  if ((isdigit(s[0]) and (s.length() == 1 or s[0] != '0')) or s[0] == '?') {
    for (size_t i = 0; i < s.length(); ++i) {
      if (not (isdigit(s[i]) or s[i] == '?')) {
        break;
      }
      if (i == s.length() - 1) {
        for (size_t j = 0; j < s.length(); ++j) {
          if (s[j] == '?') {
            s[j] = '9';
          }
        }
        return s;
      }
    }
  }
  if ((eq(s, 0, 'R') or eq(s, 0, 'L')) and eq(s, 1, '(') and eq(s, s.length() - 1, ')')) {
    vector<string> sv, cands;
    for (size_t i = 3; i < s.length() - 2; ++i) {
      if (eq(s, i, ',')) {
        string sl = compute(s.substr(2, i - 2));
        string sr = compute(s.substr(i + 1, s.length() - i - 2));
        if (sl != "invalid" and sr != "invalid") {
          if (eq(s, 0, 'L')) {
            cands.push_back(sl);
          }
          if (eq(s, 0, 'R')) {
          cands.push_back(sr);
          }
        }
      }
    }
    if (not cands.empty()) {
      return *max_element(cands.begin(), cands.end(), is_greater);
    }
  }
  return "invalid";
}

int main() {
  string s;
  cin >> s;
  cout << compute(s) << endl;
  return 0;
}

Measured memory_bytes: 1220
import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	}
}

Measured memory_bytes: 30096
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL dp[321123];

int main() {

    // 1. 入力情報取得.
    int M;
    LL K;
    scanf("%d %lld", &M, &K);

    // 2. 数列作成(K >= 2 の M乗).
    int l = 1 << M; // 数列の長さ.
    // sample_02 で, WA となったので, if文 を 修正.
    // if(K >= l){
    if(K >= l || (M == 1 && K == 1)){
        printf("%d\n", -1);
        return 0;
    }
    
    // 3. 数列作成(K < 2 の M乗).
    // 3-1. K == 0
    // ex.
    // M = 2, K = 0
    // 0 0 -> 1 0 0 1 -> 2 1 0 0 1 2 -> 3 2 1 0 0 1 2 3 とすれば良さそう.
    if(K == 0){
        int base = l - 1, counter = 0;
        dp[base] = K, dp[base + 1] = K;
        for(int i = 0; i < l; i++) if(i != K) counter++, dp[base - counter] = dp[base + 1 + counter] = i;
    }

    // 3-2. K > 0
    // M = 2, K = 1
    // 1 -> 0 1 0 -> 2 0 1 0 2 -> 3 2 0 1 0 2 3 -> 3 2 0 1 0 2 3 1 とすれば良さそう.
    // 
    // M = 2, K = 2
    // 2 -> 0 2 0 -> 1 0 2 0 1 -> 3 1 0 2 0 1 3 -> 3 1 0 2 0 1 3 2 とすれば良さそう.
    // 
    // M = 2, K = 3
    // 3 -> 0 3 0 -> 1 0 3 0 1 -> 2 1 0 3 0 1 2 -> 2 1 0 3 0 1 2 3 とすれば良さそう.
    if(K > 0){
        int base = l - 1, counter = 0;
        dp[base] = K, dp[2 * base + 1] = K;
        for(int i = 0; i < l; i++) if(i != K) counter++, dp[base - counter] = dp[base + counter] = i;
    }
    
    // 3. 後処理.
    for(int i = 0; i < 2 * l; i++) printf("%lld ", dp[i]);
    return 0;

}

Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;
vector< bool > reached;
vector< vs32 > g;

void dfs(P& edge, int u)
{
    reached[u] = true;
    for (auto v : g[u])
    {
        if (reached[v]) continue;
        if (edge == P(u, v) || edge == P(v, u)) continue;
        dfs(edge, v);
    }
}

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

    int n, m;
    cin >> n >> m;
    reached.resize(n);
    g.resize(n);

    vector< P > edge(m);
    rep (i, m)
    {
        int u, v;
        cin >> u >> v;
        --u; --v;
        edge[i] = P(u, v);
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int ans = 0;
    rep (e, m)
    {
        P remove = edge[e];
        rep (i, n) reached[i] = false;
        int cnt = 0;
        rep (i, n)
        {
            if (!reached[i])
            {
                dfs(remove, i);
                ++cnt;
            }
        }
        if (cnt > 1) ++ans;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	ll a = 1, b=1;
	rep(i,n){
		ll x, y;
		cin >> x >> y;
		ll n = max((a-1) / x + 1 , (b-1) / y + 1);
		a = x*n;
		b = y*n;
	}
	cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 3616
n = gets.to_i

@ms = {}
@dp = {}

class Matrix
    attr_reader :row, :col

    def initialize(row, col)
        @row = row
        @col = col
    end
end

[*1..n].each do |i|
    r, c  = gets.split.map(&:to_i)
    @ms[i] = Matrix.new(r, c)
end


def set_value(x, y)
    if x == y
        @dp[[x, y]] = 0
     elsif y - x == 1
        @dp[[x, y]] = @ms[x].row * @ms[x].col * @ms[y].col
    else
        candidate = []
        [*1..(y - x)].each do |k|
            candidate << @ms[x].row * @ms[x + k].row * @ms[y].col + @dp[[x, x + (k - 1)]] + @dp[[x + k, y]]
        end
        @dp[[x, y]] = candidate.min
    end
end


1.upto(n) do |y|
    n.downto(1) do |x|
        unless x > y
            set_value(x, y)
        end
    end
end

p @dp[[1, n]]


Measured memory_bytes: 8920
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	lint a,b,c,k;
	cin>>a>>b>>c>>k;
	lint ans=0;

	if(k <= a){
		cout<<k<<"\n"; return 0;
	}
	ans = a; k -= a;
	k -= b;
	if(k > 0){
		ans -= k;
	}
	cout<<ans<<"\n";

	return 0;	
}



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

using namespace std;

int main(){    
    int N;
    vector<int> d;

    cin >> N;

    for(int i = 0; i < N; i++){
        int l;
        cin >> l;
        d.push_back(l);
    }

    int sum = 0;

    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            sum += d[i]*d[j];
        }
    }

    cout << sum << endl;
    return 0;
}

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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if((0 <= x - r && x + r <= W) && (0 <= y - r && y + r <= H)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    K = int(input())
    A, B = read_values()
    if A % K == 0 or B % K == 0:
        print("OK")
    elif (B // K - A // K) > 0:
        print("OK")
    else:
        print("NG")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9848
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		Arrays.sort(arr);
		System.out.println(arr[n/2] - arr[n/2-1]);
	}

}


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

#include <algorithm>
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
long long ncr(int n, int r) 
{ 
    long long p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            long long m = gcd(p, k);      
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        }    
    } 
  
    else
        p = 1;   
    return p; 
} 
int main(){
    long long int n, m, p = 0;
    cin >> n >> m;
    if(n >= 2){
        p += ncr(n,2);
    }
    if(m >= 2){
        p += ncr(m,2);
    }
    cout << p;
     
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k,a,b;
	cin>>k>>a>>b;
	bool f=false;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		f=true;
		if(f)
		break;
	}
	if(f)
	cout<<"OK";
	else
	cout<<"NG";
}



Measured memory_bytes: 3652
#include<cstdio>
const int MAXN=50+5;
char map[MAXN][MAXN];int n,m;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",map[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(map[i][j]=='#') printf("%c",'#'); else printf("%d",(map[i-1][j  ]=='#')+(map[i+1][j  ]=='#')+(map[i  ][j-1]=='#')+(map[i  ][j+1]=='#')+(map[i-1][j-1]=='#')+(map[i-1][j+1]=='#')+(map[i+1][j-1]=='#')+(map[i+1][j+1]=='#'));
		printf("\n");
	}
	return 0;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;

    Point(double x = 0, double y = 0) : x(x), y(y) {}

    Point operator + (Point p){ return Point(x+p.x, y+p.y); }
    Point operator - (Point p){ return Point(x-p.x, y-p.y); }
    Point operator * (double a){ return Point(a*x, a*y); }
    Point operator / (double a){ return Point(x/a, y/a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x*x + y*y; }

    bool operator < (const Point &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;

struct Segment{
    Point p1, p2;
};

typedef Segment Line;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}


bool isOrthogonal(Vector a, Vector b){
    return equals(dot(a, b), 0.0);
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
    return isOrthogonal(a1-a2, b1-b2);
}
bool isOrthogonal(Segment s1, Segment s2){
    return equals(dot(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b){
    return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2){
    return isParallel(a1-a2, b1-b2);
}
bool isParallel(Segment s1, Segment s2){
    return equals(cross(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}

int main(){
    int q;
    cin >> q;
    while(q-- > 0){
        double x[8];
        for(int i = 0; i < 8; i++)  cin >> x[i];
        Point a(x[0], x[1]);
        Point b(x[2], x[3]);
        Point c(x[4], x[5]);
        Point d(x[6], x[7]);
        int ans = 0;
        if(isParallel(a,b,c,d)) ans = 2;
        if(isOrthogonal(a,b,c,d))   ans = 1;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
S = input()
N = len(S)
ans =0
for i in range(0, N):
    for j in range(i, N+1):
        tmp = S[i:j]
        if len(tmp)==tmp.count('A')+tmp.count('G')+tmp.count('C')+tmp.count('T'):
            ans = max(ans,len(tmp))
print(ans)

Measured memory_bytes: 3060
import sys

r, g, b = list(map(int, input().split()))
k = int(input())

def check():
    if (r < g < b):
        print("Yes")
    else:
        print("No")
    sys.exit()

m = k
for _ in range(k):
    if (r < g):
        break
    
    g *= 2
    m -= 1

if (m < 1):
    check()

mm = m
for _ in range(m):
    if (g < b):
        break
    
    b *= 2
    mm -= 1

check()


Measured memory_bytes: 9160
S = input()
S = S[::-1]

pattern = ['maerd', 'remaerd', 'esare', 'resare']

pos = 0
possible = True

while pos < len(S):
    no_match = True
    for candidate in pattern:
        if S[pos : pos + len(candidate)] == candidate:
            pos += len(candidate)
            no_match = False
            break

    if no_match:
        possible = False
        break

if possible:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll d[100000];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lld", &d[num - i - 1]);
	ll mini = 2, maxi = 2;
	for (int i = 0; i < num; i++)
	{
		mini = (mini + d[i] - 1) / d[i] * d[i];
		maxi = maxi / d[i] * d[i];
		if (mini > maxi)
		{
			printf("-1\n");
			return 0;
		}
		maxi += d[i] - 1;
	}
	printf("%lld %lld\n", mini, maxi);
}

Measured memory_bytes: 896
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut ret = vec![];
    if n % 2 == 0 {
        for i in 1..(n / 2) {
            ret.push((i, i + 1));
            ret.push((i, n - i));
            ret.push((n - i + 1, i + 1));
            ret.push((n - i + 1, n - i));
        }
        if n > 4 {
            ret.push((n / 2, 1));
            ret.push((n / 2, n));
            ret.push((n / 2 + 1, 1));
            ret.push((n / 2 + 1, n));
        }
    } else {
        for i in 1..((n - 1) / 2) {
            ret.push((i, i + 1));
            ret.push((i, n - i - 1));
            ret.push((n - i, i + 1));
            ret.push((n - i, n - i - 1));
        }
        ret.push(((n - 1) / 2, n));
        ret.push(((n + 1) / 2, n));
        if (n - 1) / 2 != 1 {
            ret.push((1, n));
            ret.push((n - 1, n));
        }
    }
    println!("{}", ret.len());
    for (i, j) in ret {
        println!("{} {}", i, j);
    }
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

using namespace std;

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

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

int main(void) {
  int i,j;
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  if(b==c)cout<<a<<endl;
  if(a==c)cout<<b<<endl;

}


Measured memory_bytes: 764
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

bool check(vector<int>&nums, tuple<int, int, int>tp) {
	int l = get<0>(tp);
	int r = get<1>(tp);
	int s = get<2>(tp);
	return accumulate(nums.begin() + l, nums.begin() + r, 0) == s;
}

int main() {
	int N, X, M; cin >> N >> X >> M;
	vector<tuple<int, int, int>>infos;
	for (int i = 0; i < M; ++i) {
		int l, r, s; cin >> l >> r >> s;
		l--;
		infos.push_back(tuple<int, int, int>{l, r, s});
	}
	int k = 1;
	int ansnum = -1;
	vector<int>ans;
	for (int i = 0; i < N; ++i)k *= (X + 1);
	for (int i = 0; i < k; ++i) {
		int n(i);
		vector<int>nums(N);
		for (int j = 0; j < N; ++j) {
			nums[j] = n % (X + 1);
			n /= (X + 1);
		}
		bool ok = true;
		for (int i = 0; i < M; ++i) {
			if (!check(nums, infos[i])) {
				ok = false;
			}
		}
		if (ok) {
			if (accumulate(nums.begin(), nums.end(), 0) > ansnum) {
				ansnum = accumulate(nums.begin(), nums.end(), 0);
				ans = nums;
			}
		}

	}
	if (ansnum == -1) {
		cout << -1 << endl;
	}
	else {
		for (int i = 0; i < ans.size(); ++i) {
			cout << ans[i];
			if (i == ans.size() - 1)cout << endl;
			else cout << " ";
		}
	}


	return 0;
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) if (scanf("%d", &v)<1);
#define out(v) printf("%d\n", v)

int main() {
  int N; in(N);

  int A[N+2]; // 便宜上、スタートとゴールもAに入れる
  int before = 0;
  int sum = 0;
  A[0] = 0;
  A[N+1] = 0;
  rep(i, N) {
    in(A[i+1]);
    sum += abs(before - A[i+1]);
    before = A[i+1];
  }
  sum += abs(A[N]);

  rep(i, N) {
    out(sum - abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2]));
  }
  return 0;
}


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

static const int N = 100;

int main(){
    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    for(int i=0;i<n;i++) cin >> p[i] >> p[i+1];
    for(int l=1;l<=n;l++) {
        for(int i=0;i<=n-l;i++) {
            int j = i + l;
            if(l==1) m[i][j] = 0;
            else if(l==2) m[i][j] = p[i]*p[i+1]*p[j];
            else {
                m[i][j] = 1000000000;
                for(int k=1;k<l;k++) {
                    m[i][j] = min(m[i][j], m[i][i+k] + m[i+k][j] + p[i]*p[i+k]*p[j]);
                }
            }
        }
    }
    //cout << m[4][6] << endl;
    cout << m[0][n] << endl;
    
    return 0;
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;
int cnt[10][10];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		int a = i % 10;
		int b = a;
		int t = i;
		while (t > 0) {
			b = t % 10;
			t /= 10;
		}
		cnt[a][b]++;
	}
	int res = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			res += cnt[i][j] * cnt[j][i];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();

    double ans = 0.d;
    for (int i = 1; i <= N; i++) {
      int r = log2(K, i);
      ans += 1.d / (1L << r) / N;
    }
    System.out.println(ans);
  }

  private static int log2(int n, int m) {
    int i = 0;
    while (n > m) {
      m *= 2;
      i++;
    }
    return i;
  }
}


Measured memory_bytes: 23764
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll h,w;
ll c[10][10];
ll dist[10][10];

int main() {
    std::cin >> h>>w;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            std::cin >> c[i][j];
        }
    }
    
    Fill(dist,100000);
    
    for (int i = 0; i < 10; i++) {
        dist[i][i]=0;
    }
    for (int abc = 0; abc < 10; abc++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + c[k][j] );
                }
            }
        }
    }
    
    ll res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ll tmp_a;
            std::cin >> tmp_a;
            if(tmp_a==-1)continue;
            if(tmp_a==1)continue;
            res += dist[tmp_a][1];
        }
    }
    std::cout << res << std::endl;
    
    
    
    
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

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

    int x[15][15];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int diff, sum = 0;
            for (int k = 0; k < d; k++) {
                diff = abs(x[i][k] - x[j][k]);
                sum += diff * diff;
            }
            for (int l = 0; l <= sum; l++) {
                if(l * l == sum){
                    cnt++;
                    break;
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
ll qpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cout.tie(0), cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 1;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    // ans = ((ans * (n)) % mod * (n - 1)) % mod;
    // ans = ans * qpow(10, n - 2) % mod;
    ans = (((qpow(10, n) - qpow(9, n) + mod) % mod - qpow(9, n) + mod) % mod + qpow(8, n)) % mod;
    cout << ans % mod << endl;
    return 0;
}


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

int main(){
    int n, m, x, mi;
    cin >> n >> m >> x;
    mi = 1200001;

    //各本のデータの作成
    vector<vector<int>> data(n,vector<int>(m+1));
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            cin >> data.at(i).at(j);
        }
    }

    //ここから判定
    //bit全探索により本の選び方を指定、各場合について条件を満たすか調べる
    //そののち、最小値をとる。
    for(int bit=0; bit<(1<<n); ++bit){
       vector<int> s(n);
       for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                s.at(i) = 1;
            }
       }
    
       vector<int> status(m+1);
       for(int i=0; i<n; i++){
           if(s.at(i)==1){
               for(int j=0; j<m+1; j++){
                   status.at(j) += data.at(i).at(j);
               }
           }
       }

       //判定
       bool frag = true;
       for(int j=0; j<m; j++){
           if(status.at(j+1) >= x){
           }
           else{
               frag = false;
           }
       }

       if(frag){
           mi = min(status.at(0),mi);
       }
    }

    if(mi < 1200001){
         cout << mi << endl;
    }
    else{
        cout << -1 << endl;
    }
}

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

	#define ll long long int
	#define ull unsigned long long int
	#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


	using namespace std;

	const int INF = 1e9 + 7;
	const int N = 1e5+5;

	int main() {

		IO; 
		
		
		int n;
		cin >> n;
		
		vector<int> ar(n);
		for (int i = 0; i <n; ++i) {
			cin >> ar[i];
		}
		
		int low, high;
		high = low = ar[0];
		for (int i = 0; i < n; ++i) {
			low = min(low, ar[i]);
			high = max(high, ar[i]);
		}
		
		ll tot = INF;
		for (int i = low; i <= high; ++i) {
			ll current = 0;
			for (int j = 0; j < n; ++j) {
				current += (ar[j] - i) * (ar[j] - i);
			}
			tot = min(tot, current);
				
		}
		
		cout << tot;
		
	}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  stack<int> s;
  string t;
  while (cin >>t){
    if (t == "+" || t == "-" || t == "*" || t == "/"){
      int b = s.top(); s.pop();
      int a = s.top(); s.pop();
      if (t == "+") s.push(a+b);
      if (t == "-") s.push(a-b);
      if (t == "*") s.push(a*b);
      if (t == "/") s.push(a/b);
    }else{
      s.push(stoi(t));
    }
  }
  cout <<s.top() <<endl;

}


Measured memory_bytes: 3152
n, m, x = list(map(int, input().split()))
_mt = [list(map(int, input().split())) for _ in range(n)]
cs = [r[0] for r in _mt]
anm = [r[1:] for r in _mt]

sumlst = lambda l1, l2: [i1+i2 for i1, i2 in zip(l1, l2)]

mat = [{} for _ in range(n + 1)]
mat[0][0] = (0, [0]*m)
for i in range(n):
    for j in mat[i]:
        w, seq = mat[i][j]
        # Ciを採用しなかった場合
        mat[i + 1][w] = (w, seq)
        # Ciを採用した場合
        mat[i + 1][w + cs[i]] = (w + cs[i], sumlst(seq, anm[i]))

for k in sorted(mat[-1]):
    w, lst = mat[-1][k]
    if all(v >= x for v in lst):
        print(w)
        break
else:
    print(-1)



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

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

    vector<int> res(4);
    rep(i, n) {
        string s;
        cin >> s;

        if (s == "AC") {
            res[0]++;
        } else if (s == "WA") {
            res[1]++;
        } else if (s == "TLE") {
            res[2]++;
        } else {
            res[3]++;
        }
    }

    cout << "AC x "  << res[0] << endl;
    cout << "WA x "  << res[1] << endl;
    cout << "TLE x "  << res[2] << endl;
    cout << "RE x "  << res[3] << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define P=pair<int,int>;
using namespace std;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
    int n,k;cin>>n>>k;
    string s;cin>>s;
    if(s.at(k-1) == 'A') s.at(k-1) = 'a';
    if(s.at(k-1) == 'B') s.at(k-1) = 'b';
    if(s.at(k-1) == 'C') s.at(k-1) = 'c';
    cout<<s<<endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll a, v, t, b, w, diff_d, diff_v;
    double diff;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;

    if(a >= b) {
        diff_d = a - b;
    } else {
        diff_d = b - a;
    }

    if(w >= v) {
        cout << "NO" << endl;
        exit(0);
    } else {
        diff_v = v - w;
        diff = (double)diff_d / diff_v;
        if(diff <= t) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < 1000; ++i) {
		ostringstream os;
		os << setfill('0') << setw(3) << i;
		string str = os.str();
		int pos = 0;
		for (int j = 0; j < n; ++j) {
			if (str[pos] == s[j]) pos++;
			if (pos == 3) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main()
{
  int ans = 0;
  string a;
  cin >> a;

  for (int i = 0; i < 3; i++)
  {
    if (a[i] == '1')
    {
      ans++;
    }
  }
  printf("%d", ans);
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int y;
    y = a + b;

    if(y % 2 == 0) {
        cout << y/2;
    }
    else {
        cout << y/2 + 1;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define A 0
#define B 1
#define C 2
#define D 3
using namespace std;
string s;

int makeHash(int a[]) {
	stack<int> st;
	for(int i=s.size()-1;i>=0;i--) {
		if('a'<=s[i] and s[i]<='d') {
				if(s[i]=='a') st.push(a[A]);
				else if(s[i]=='b') st.push(a[B]);
				else if(s[i]=='c') st.push(a[C]);
				else if(s[i]=='d') st.push(a[D]);
			}
			else if(s[i]=='+') {
				int x = st.top();
				st.pop();
				int y = st.top();
				st.pop();
				st.push(x | y);
			}
			else if(s[i]=='*') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x & y);
			}
			else if(s[i]=='^') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x ^ y);
			}
		}
	return st.top();

}
int main() {
	string p;
	while(cin >> s) {
		if(s==".") break;
		cin >> p;
		vector<int> a(4);
		for(int i=0;i<4;i++) {
			a[i] = p[i] - '0';
		}
		stack<int> st;
		for(int i=s.size()-1;i>=0;i--) {
			if('a'<=s[i] and s[i]<='d') {
				if(s[i]=='a') st.push(a[A]);
				else if(s[i]=='b') st.push(a[B]);
				else if(s[i]=='c') st.push(a[C]);
				else if(s[i]=='d') st.push(a[D]);
			}
			else if(s[i]=='+') {
				int x = st.top();
				st.pop();
				int y = st.top();
				st.pop();
				st.push(x | y);
			}
			else if(s[i]=='*') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x & y);
			}
			else if(s[i]=='^') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x ^ y);
			}
		}
		int value = st.top();
		int cnt = 0;
		int tmp[4];
		for(int i=0;i<=9;i++) {
			for(int j=0;j<=9;j++) {
				for(int k=0;k<=9;k++) {
					for(int l=0;l<=9;l++) {
						tmp[0] = i;
						tmp[1] = j;
						tmp[2] = k;
						tmp[3] = l;
						if(makeHash(tmp) == value) cnt++;
					}
				}
			}
		}
		cout << value << " " << cnt << endl;
	}
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
void s3()
{
    int n;
    cin>>n;
    vector<int> a(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int res=0;
    int minIt=n+1;
    for(int i=0;i<n;i++){
        if(a[i]<minIt){
            res++;
            minIt=a[i];
        }
    }
    cout<<res<<endl;
}
void s4()
{

}
int main()
{
    //s1();
    //s2();
    s3();
    //s4();
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <string>
using namespace std; map<string,int>RB;int main() {string T;while ((cin>>T)!=NULL) {for (int i=T.length()-1;i>=0;i--) if (T[i]<='Z') T[i]+=32;RB[T]++;}
map<string,int>::iterator it=RB.begin(),ot=it++;for (;it!=RB.end();it++) if ((it->second)>(ot->second)) ot=it;cout<<ot->first<<" ";it=RB.begin();ot=it++;for (;it!=RB.end();it++) if ((it->first).length()>(ot->first).length()) ot=it;cout<<ot->first<<endl;return 0;}

Measured memory_bytes: 1196
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a;
    cin >> a;
    bool ok = true;
    REP(i, 0, 26) {
        char b = 'a' + i;
        if (a == b) {
            ok = false;
        }
    }
    yesno(ok, "A", "a");
}


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

int h, w;
string s[2010];
int h_cnt[2010][2010];
int w_cnt[2010][2010];

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

    for(int i = 0; i < h; i++) {
        cin >> s[i];
    }

    // 照らされるマスの個数をカウント
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j] == '#') {
                w_cnt[i][j] = 0;
            }
            else if(j == 0 || s[i][j-1] == '#') {
                int dot_cnt = 0;
                for(int jj = j; jj < w; jj++) {
                    if(s[i][jj] == '#')
                        break;
                    dot_cnt++;
                }
                w_cnt[i][j] = dot_cnt;
            }
            else {
                w_cnt[i][j] = w_cnt[i][j-1];
            }
        }
    }

    for(int j = 0; j < w; j++) {
        for(int i = 0; i < h; i++) {
            if(s[i][j] == '#') {
                h_cnt[i][j] = 0;
            }
            else if(i == 0 || s[i-1][j] == '#') {
                int dot_cnt = 0;
                for(int ii = i; ii < h; ii++) {
                    if(s[ii][j] == '#')
                        break;
                    dot_cnt++;
                }
                h_cnt[i][j] = dot_cnt;
            }
            else {
                h_cnt[i][j] = h_cnt[i-1][j];
            }
        }
    }

    int ans = -1;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            ans = max(ans, h_cnt[i][j] + w_cnt[i][j] - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35840
n=int(input())
a=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1])
print(dp[n-1])

Measured memory_bytes: 20568
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int INF=(int)1e9;
const int MOD=(int)1e9+7;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main(){
 lint N,A[100020];
 cin>>N;
 for(lint t=0;t<N;t++)cin>>A[t];
 sort(A,A+N,greater<lint>());

 lint cont=0,x=0,y=0;
 for(lint t=0;t<N;t++){
   if(cont==0){
     if(A[t]==A[t+1]&&t+1<N){
       if(A[t+1]==A[t+2]&&A[t+2]==A[t+3]&&t+3<N){
         x=A[t];
         cout<<x*x<<endl;
         return 0;
       }else{
         x=A[t];
         t++;
         cont++;
       }
     }
   }else{
     if(A[t]==A[t+1]&&t+1<N){
       y=A[t];
       cout<<x*y<<endl;
       return 0;
     }
   }
 }

 cout<<x*y<<endl;
 return 0;
}


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

int main()
{
    char a[3],aa[3],aaa[3];
    int i;
    for(i=0; i<3; i++)
    {
        scanf("%c",&a[i]);
    }
    getchar();
    for(i=0; i<3; i++)
    {
        scanf("%c",&aa[i]);
    }
    getchar();
    for(i=0; i<3; i++)
    {
        scanf("%c",&aaa[i]);
    }

    printf("%c%c%c",a[0],aa[1],aaa[2]);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

//solution classes here

public class Main {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static long mod = (long)1e9+7;
    static long MOD = 998244353;
    //static ArrayList<Integer> list[] = new ArrayList[(int)1e6+1];
    //static int color[] = new int[(int)1e6+1];
    //static int visit[] = new int[(int)1e5+1];
    //static Deque<Integer> q = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {
        int n = sc.nextInt();
        long a[] = new long[n+1];
        long dp[][] = new long[n+1][2];
        for(int i=1;i<=n;i++) {
            a[i]=sc.nextLong();
        }
        // Here dp[i][0] means excluding ith element and taking floor(i/2) total elements
        // Here dp[i][1] means including ith element and taking floor(i/2) total elements
        dp[2][0] = a[1];
        dp[2][1] = a[2];
        for(int i=3;i<=n;i++) {
            if(i%2==1) {
                dp[i][0] = Math.max(a[i-2]+dp[i-3][0],Math.max(a[i-1]+dp[i-2][0],a[i-1]+Math.max(dp[i-3][1],dp[i-3][0])));
                dp[i][1] = a[i]+Math.max(dp[i-3][0],Math.max(dp[i-3][1],Math.max(dp[i-2][0],dp[i-2][1])));
            }
            else {
                dp[i][1] = a[i]+Math.max(dp[i-2][0],Math.max(dp[i-2][1],dp[i-1][0]));
                dp[i][0] = a[i-1]+dp[i-2][0];
            }
        }

        out.println(Math.max(dp[n][0],dp[n][1]));


        out.flush();
        out.close();
    }
    //solution functions here

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */

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

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

const int N = 50 + 5;

int n, m, q;
int a[N], b[N], c[N], d[N], t[N];
int ans;

void dfs(int pos, int lb) {
    if (pos == n) {
        int cur = 0;
        for (int i = 0; i < q; ++i) {
            if (t[b[i]] - t[a[i]] == c[i]) cur += d[i];
        }
        ans = max(ans, cur);
    } else {
        for (int i = lb; i <= m; ++i) {
            t[pos] = i;
            dfs(pos + 1, i);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    dfs(0, 1);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3604