akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }
    vector<int> ascNumberSequence(n);
    for (int i = 0; i < n; ++i)
    {
        ascNumberSequence[i] = i + 1;
    }
    int diffCnt = 0;
    for (int i = 0; i < n; ++i)
    {
        if (p[i] != ascNumberSequence[i])
        {
            ++diffCnt;
        }
    }

    if (diffCnt == 0 || diffCnt == 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007


void solve()
{
 ll n;
 cin>>n;
 ll a[n][n];
 fr(n){
 rep(j,0,n)
 {
  cin>>a[i][j];
 }
}
ll dp[2][1<<n];
fr(2)
{
  rep(j,0,1<<n)
  {
    dp[i][j]=0;
  }
}

dp[0][0]=1;
rep(i,1,n+1)
{
rep(j,0,1<<n)
{
  dp[i%2][j]=0;
  if(__builtin_popcount(j) != i)
    continue;
  rep(k,0,n)
  {
    if(j&1<<k&&a[i-1][k])
    {
      
      dp[i%2][j]+=dp[(i-1)%2][j^1<<k];
      dp[i%2][j]=dp[i%2][j]%mod;
    }
  }
  
}

}

cout<<dp[n%2][(1<<n)-1];
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 36372
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>

#include <sstream>
#include <bitset>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX  2147483647

int main() {
	int N, K;
	cin >> N >> K;
    ++N;

	long long ans = 1;



	for (long long i = K; i < N; ++i) {
        long long buf1 = i * (i - 1) / 2;
        long long buf2 = i * (N - i) + buf1;
        ans = (ans + (buf2 - buf1) + 1) % MOD;
	}

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

Measured memory_bytes: 3576
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		Set<BigInteger> set=new HashSet<BigInteger>();
		int c=0;
		int n=scan.nextInt();
		for(int i=1;i<=n;i++)
		{	
			set.add(scan.nextBigInteger());
		}
		
		ArrayList<BigInteger> bi=new ArrayList<BigInteger>(set);
		
		
		int m=set.size();
		for(int i=0;i<m;i++)
		{
			if(bi.get(i).isProbablePrime(10)==true)
			{
				c++;
			}
		}
		System.out.println(c);
		bi.clear();
		set.clear();

	}

}

Measured memory_bytes: 93092
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	static int counter;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			counter = 0;
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			
			if(a == 0 && b == 0) {
				break;
			}
			if(a < b) {
				int tmp = a;
				a = b;
				b = tmp;
			}
			
			int gcd = ua(a,b);
			
			System.out.println(gcd + " " + counter);
		}
	}
	
	public static int ua(int a, int b) {
		if(b == 0) return a;
		counter++;
		return ua(b,a%b);
	}
}

Measured memory_bytes: 24372
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;

int main(){
    int n, t;  cin>>n>>t;
    int ans = INF;
    for(int i = 0; i < n; i++){
        int a,b; cin>>a>>b;
        if(b<=t){
            ans = min(ans,a);
        }
    }
    if(ans==INF) cout<<"TLE";
    else cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No");
}

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

#define MAXN (100010)
#define ll long long

int n, m;
std::vector<int> vec[MAXN];
int col[MAXN];
bool vis[MAXN];
/*
bool dfs(int u, int c){
	vis[u] = true;
	col[u] = c;
	for(int v : vec[u]){
		if(vis[v]){
			if(col[v] != (c ^ 1)) return false;
			continue;
		}
		if(!dfs(v, !c)) return false;
	}
	return true;
}*/


int gl = 0;
void dfs(int v, int c){
	col[v] = c;
	vis[v] = 1;
	for(int u : vec[v]){
		if(!vis[u]){
			dfs(u, c ^ 1);
		}
		else{
			if(col[u] != (col[v] ^ 1))
			    gl = 1;
		}
	}
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i){
		int u, v;
		scanf("%d%d", &u, &v);
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	ll n1 = 0, n2 = 0, a = 0;
	for(int i = 1; i <= n; ++ i){
		if(!vis[i]){
			if(vec[i].empty()){
			    a ++;
			    continue;
			}/*
			else if(dfs(i, 0)){
				n1 ++;
			}
			else{
				n2 ++;
			}*/
			gl = 0;
			dfs(i, 0);
			if(gl){
				n2 ++;
			}
			else{
				n1 ++;
			}
		}
	}
	ll ans = (2ll) * a * n - a * a + n1 * n1 * 2 + n2 * n2 + n1 * n2 * 2;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 10112
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

//累積和でバーーン！！ってやってみる．
void main()
{
    long n, q;
    scan(n, q);
    auto s = sread();
    long[] com_count = new long[n + 1];
    foreach (i, ref e; com_count)
    {
        if (i < 2)
        {
            continue;
        }
        if (s[i - 2 .. i] == "AC")
        {
            com_count[i] = com_count[i - 1] + 1;
        }
        else
        {
            com_count[i] = com_count[i - 1];
        }
    }
    // writeln(com_count);
    foreach (i; 0 .. q)
    {
        long a,b;
        scan(a,b);
        writeln(com_count[b] - com_count[a]);
    }
}

Measured memory_bytes: 4476
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let v: Vec<i32> = (0..6).map(|_| read()).collect();
    println!("{}", if v[4] - v[0] > v[5] { ":(" } else { "Yay!" });
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
	int a, b, c;

	scanf("%d%d%d", &a, &b, &c);
	if (a < b ){
		if (b<c){
			printf("Yes\n");
	}
		else	printf("No\n");
	}
	else
	printf("No\n");

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i <= N / 4; i++) {
    for (int j = 0; j <= (N - i * 4) / 7; j++) {
      if (i * 4 + j * 7 == N) {
        ans++;
      }
    } 
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
  vector<int> vec1(3), vec2(3), vec3(3);
  for(int i = 0; i < 3; i++)
    cin >> vec1.at(i);
  for(int i = 0; i < 3; i++)
    cin >> vec2.at(i);
  for(int i = 0; i < 3; i++)
    cin >> vec3.at(i);
  
  int N;
  cin >> N;
  
  for(int j = 0; j < N; j++) {
    int b;
    cin >> b;
    for(int i = 0; i < 3; i++) {
      if(b == vec1.at(i))
        vec1.at(i) = 0;
    }
    for(int i = 0; i < 3; i++) {
      if(b == vec2.at(i))
        vec2.at(i) = 0;
    }
    for(int i = 0; i < 3; i++) {
      if(b == vec3.at(i))
        vec3.at(i) = 0;
    }
  }
  
  if(vec1.at(0) == 0 && vec1.at(1) == 0 && vec1.at(2) == 0)
    cout << "Yes" << endl;
  else if(vec2.at(0) == 0 && vec2.at(1) == 0 && vec2.at(2) == 0)
    cout << "Yes" << endl;
  else if(vec3.at(0) == 0 && vec3.at(1) == 0 && vec3.at(2) == 0)
    cout << "Yes" << endl;
  else if(vec1.at(0) == 0 && vec2.at(0) == 0 && vec3.at(0) == 0)
    cout << "Yes" << endl;
  else if(vec1.at(1) == 0 && vec2.at(1) == 0 && vec3.at(1) == 0)
    cout << "Yes" << endl;
  else if(vec1.at(2) == 0 && vec2.at(2) == 0 && vec3.at(2) == 0)
    cout << "Yes" << endl;
  else if(vec1.at(0) == 0 && vec2.at(1) == 0 && vec3.at(2) == 0)
    cout << "Yes" << endl;
  else if(vec1.at(2) == 0 && vec2.at(1) == 0 && vec3.at(0) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <numeric>
#include <vector>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
int main(void){
    int N,L;
    cin >> N >> L;
    int aji = 10000000;
    int result;
    REP(i,N)
    {
        int tabeta = 0,tabetenai = 0;
        REP(j,N)
        {
            tabetenai += L+j;
            if(j!=i) 
            {
                tabeta += L+j;
            }
        }
        if(aji>abs(tabeta-tabetenai))
        {
            aji=abs(tabeta-tabetenai);
            result = tabeta;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<int> c(N);
  rep(i, M)
  {
    cin >> a[i] >> b[i];
    c[a[i]-1]++;
    c[b[i]-1]++;
  }
  rep(i, N)
  {
    cout << c[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc086/tasks/abc086_a */

#include <iostream>

int main(int argc, char *argv[])
{
  // Input
  int a, b;

  std::cin >> a >> b;

  // Output
  if (a*b%2 == 0) {
    std::cout << "Even" << std::endl;
  } else {
    std::cout << "Odd" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

int n;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	double even = n/2;
	double odd = n-even;
	cout << fixed << setprecision(10) << (double)odd/n << endl;
	return 0;
}


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

int main() {
  int A,B,C,D ;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define l long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i]}
using namespace std;

int main(){
    FAST
    int x; cin >> x;
    if(x==1){
        cout << "0" << endl;
    }
    else{
        cout << "1" << endl;
    }
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
const ll inf = 1e18;
const int nax = 2e6 + 7;

using namespace std;
string s;

int main(int argc,char ** argv){
	dhoom;
	long double x;
	cin >> x;
	cout << fixed << setprecision(12) << (x/3)*(x/3)*(x/3) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String input1 = scan.next();
	int a = Integer.parseInt(input1);
	String input2 = scan.next();
	int b = Integer.parseInt(input2);
	String sign = "";
	if (a < b) {
	    System.out.println("a < b");
	} else if (a > b) {
	    System.out.println("a > b");
	} else {
	    System.out.println("a == b");
	}
    }
}

Measured memory_bytes: 26188
import math
  
n = int(input())
x = [ float(s) for s in input().split() ]
y = [ float(s) for s in input().split() ]

p = [ abs(x[i] - y[i]) for i in range(n) ]

p1 = sum(p)
p2 = sum([ d**2 for d in p ]) ** (1/2)
p3 = sum([ d**3 for d in p ]) ** (1/3)
pinf = max(p)

print(p1,p2,p3,pinf,sep='\n')


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int e=0;
  while(a>=b){
    e++;
    b*=2;
  }
  while(b>=c){
    e++;
    c*=2;
  }
  if(d<e){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}



Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
    int k=0;

    cin >> a >> b >> c >> d >> e >> k;

    if(b-a<=k&&c-a<=k&&d-a<=k&&e-a<=k&&c-b<=k&&d-b<=k&&e-b<=k&&d-c<=k&&e-c<=k&&e-d)cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
    d={} 
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d


def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:            
        return -1

def main():
    try:
        l=list(input())
        if l[0]=='R' and l[1]=='R' and l[2]=='R':
            ans=3
            print(ans)
            return
        if (l[0]=='R' and l[1]=='R') or (l[1]=='R' and l[2]=='R'):
            ans=2
            print(ans)
            return
        else:
            ans=0
            for x in range(3):
                if l[x]=='R':
                    ans=1
                    break
            print(ans)
    except: 
        pass
        
M = 998244353
P = 1000000007
Inf=1000000000000000000
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()




Measured memory_bytes: 9420
function Main(input){
  S = input.trim().split('');
  count = 0;
  max_count = 0;
  S.forEach((ch)=>{
    if(ch === 'A' || ch === 'T' || ch === 'G' || ch === 'C'){
      count++;
    }else{
      max_count = count > max_count ? count : max_count;
      count = 0;
    }
  });
  console.log(count > max_count ? count : max_count);
}

Main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
  int n;cin>>n;
  int ans = 0;
  for(int i=0;i<n;i++){
    ans += 800;
    if(i%15 == 14) ans -= 200;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        long x[] = new long[n];
        long y[] = new long[n];

        x[0] = sc.nextInt();
        for(int i=1; i<n; i++) {
            x[i] += x[i-1] + sc.nextInt();
        }

        for(int i=0; i<n; i++) y[i] = sc.nextInt();
        long ans=0;

        for(int i=n-2; 0<=i; i--) {
            y[i] += y[i+1];
            ans=max(ans, y[i]+x[i]);
        }

        if(n==1)ans=x[0]+y[0];

        out.println(ans);
        out.flush();
    }
    
    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 22612
package main

import (
	"fmt"
	"math"
	"sort"
)

var N, K, ans int

func main() {
	fmt.Scan(&N, &K)
	l := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&l[i])
	}
	sort.Ints(l)

	for i := N - 1; N-1-K < i; i-- {
		ans += l[i]
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] > a[j][0]
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> locate(N);
  vector<pair<int, int>> cp(M);
  for (auto &e : locate) {
    int a, b;
    cin >> a >> b;
    e = make_pair(a, b);
  }
  for (auto &e : cp) {
    int a, b;
    cin >> a >> b;
    e = make_pair(a, b);
  }
  
  for (int i = 0; i < N; i++) {
    int dist = 700000000;
    int num;
    for (int j = 0; j < M; j++) {
      int delx = locate[i].first - cp[j].first;
      int dely = locate[i].second - cp[j].second;
      delx = max(delx, -delx);
      dely = max(dely, -dely);
      if (dist > delx + dely) {
        dist = delx + dely;
        num = j + 1;
      }
    }
    cout << num << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	#define mod 1000000007
	#define ll long long int
	#define ar array
	#define mp make_pair
	using namespace std;

	int main()
	{
		ios::sync_with_stdio(false);
		cin.tie(NULL);
		int n;
		cin>>n;
		int a[100001]={0};
		multiset< int,greater<int > >s;
		for(int i = 0 , j; i<n; i++)
		{
			cin>>j;
			a[j]++;
		}
		for(int i =1;i<100001; i++)
			if(a[i])
				s.insert(a[i]);
		sort(a, a+100001, greater<int>());
		int up = 0, down =0;
		for(int i = 0;i <100001;i++)
		{
			if(!a[i]) break;
			up = a[i]/3+a[i]%3;
			while(up>=3)
				up = up/3+ up%3;
			
			a[i]= up;
		}
		sort(a, a+100001, greater<int>());
		int y = count(a,a+100001,2);
		int h = count(a,a+100001,1);
		if(y&1)
			h--;
		cout<<y+h<<endl;
		return 0;
	}

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

const ll M = 1000000007;
int n, m, k;
ll f[1000010], fi[1000010], thr[1000010], ans;

ll pw(ll x, ll k){
	if(k == 1) return x;
	return (k % 2 ? x : 1) * pw(x * x % M, k / 2) % M;
}

ll cm(int n, int r){
	return f[n] * fi[r] % M * fi[n - r] % M;
}

ll cal(int x, int b){
	ll ret = 0, s = 1;
	for(int i = 0; i <= x; i++){
		ret = (ret + thr[m + k - i - b] * cm(n - 1 + i + b, n - 1) % M * s) % M;
		s = (2 * s - cm(i + b, i) + cm(i + b + 1, i + 1) + M) % M;
	}
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	f[0] = fi[0] = thr[0] = 1;
	for(int i = 1; i <= 1000005; i++){
		f[i] = f[i - 1] * i % M;
		fi[i] = pw(f[i], M - 2);
		thr[i] = thr[i - 1] * 3 % M;
	}
	printf("%lld\n", (cal(m + k, 0) - cal(m - 1, k + 1) - cal(k - 1, m + 1) + 2 * M) % M);
}

Measured memory_bytes: 23680
import math
n , st , m = map(int , input().split())
n = abs(n)
t = abs(n)
n = (n-m*st)
tot = n//m
if n>=0:
	print(n)
else:
	rem = t%m
	tot = t//m
	if((st-tot)%2)!=0:
		print(abs(m-rem))
	else:
		print(abs(rem))


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

int dig(long long a){
  int d = 0;
  while(a != 0){
    a /= 10;
    d++;
  }
  return d;
}

int main(){
  long long N;
  int ans = 15;
  cin >> N;
  for (long long i = 1; i*i <= N; i++){
    if(N%i == 0)
      ans = min(ans,max(dig(i),dig(N/i)));
  }
  cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  int list[110];

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

  sort(list,list+N,greater<int>());
  int Alice=0;
  int Bob=0;


  
  for(int i=0; i*2<N;i++){
    Alice += list[i*2];
    if(i*2+1 < N){
    Bob += list[2*i+1];
    }
  }
  
 cout << Alice-Bob << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nn 100008*8
#define lf double
#define mp make_pair
#define ll long long
#define err {puts("No");exit(0);}
int status[nn];int n;
char buf[nn];
int ans[nn];int tot;
void output()
{
	for(int i=0;i<n*2;i++)
	{
		if(ans[i]==0)
		for(int j=i+1;j<n*2;j++)
			if(ans[j]==0)
			{
				ans[i]=ans[j]=++tot;
				i=j;
				break;
			}
	}
	puts("Yes");
	for(int i=0;i<n*2;i++) printf("%d ",ans[i]);
	exit(0);
}
int cmp(vector<int> a,vector<int> b)
{
	return a.size()>b.size();
}
int main()
{
//	freopen("0.txt","r",stdin);
	cin>>n;int o=0;int N=n*2;
	scanf("%s",buf+1);assert(strlen(buf+1)==N-1);
	for(int i=1;i<2*n;i++) status[i]=buf[i]-'0',o+=status[i];
	status[0]=1;
	if(o==2*n-1)
	{
	
		if(n%2==1) err;
		for(int i=0;i<n*2;i+=4)
			ans[i]=ans[i+2]=++tot,ans[i+1]=ans[i+3]=++tot;
		output();
	}
//	if(o%2==0) err;
	vector<vector<int> >gg;
	for(int i=0;i<n*2;i++)
	{
		if(status[i]==0&&status[(i+1)%N]==1)
		{//	cout<<i;
			vector<int> b;b.push_back(i);
			for(int j=(i+1)%N;status[j];j=(j+1)%N) b.push_back(j);
			gg.push_back(b);
		}
	}
	sort(gg.begin(),gg.end(),cmp);
	int d2=0;
	for(int i=0;i<gg.size();i++) 
	{
	//	if(gg[i].size()>2) cout<<gg[i].size();
		d2+=gg[i].size()-2;
	}
	if(d2%2) err;//cout<<gg[0].size()<<" "<<gg[1].size()<<"\n";
	if(d2%4==2)
	{
		if(gg.size()<=1) err
		if(gg[0].size()>2 and gg[1].size()>2) 
		{
			int e1=gg[0].size()-2,e2=gg[1].size()-2;
			ans[gg[0][e1]]=ans[gg[1][e2]]=++tot;
			gg[0].erase(gg[0].begin()+e1);
			gg[1].erase(gg[1].begin()+e2);
			swap(gg[0][e1],gg[1][e2]);
		}
		else err;
	} 
	vector<int> v2;
	for(int i=0;i<gg.size();i++)
	{
		ans[gg[i][0]]=tot+i+1;
		ans[gg[i][gg[i].size()-1]]=tot+(i+1)%(int)(gg.size())+1;
		for(int k=1;k<gg[i].size()-1;k++)
			v2.push_back(gg[i][k]);
	}
	tot+=gg.size();
	for(int i=0;i<v2.size();i+=4)
	{
		ans[v2[i]]=ans[v2[i+2]]=++tot;
		ans[v2[i+1]]=ans[v2[i+3]]=++tot;
	}
	output(); 
}

Measured memory_bytes: 9524
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
char s[15];scanf("%s",s);
int c=0,hoji;

if(s[0]!='A'){printf("WA");return 0;}
for(int i=2;i<=strlen(s)-2;i++){
if(s[i]=='C'){c++;hoji=i;}
}
if(c!=1){printf("WA");return 0;}

for(int i=0;i<=strlen(s)-1;i++){
if((s[i]>='A'&&s[i]<='Z')&&(i!=0)&&(i!=hoji)){printf("WA");return 0;}
}
printf("AC");return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N; cin >> N;
    set<int> s;
    bool ok = true;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;

        // a がすでにあるかどうか (すでにあったらダブりがある)
        if (s.count(a)) ok = false;

        // a を挿入
        s.insert(a);
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 9600
#include<iostream>
int main()
{
	int i;
	int a[10000];		
	int j=1;
	int t;
	for ( int i = 1; i<=10000; ++i )
	{
		std::cin >> t;
		if ( t == 0 )
		{
			break;
		}
		else
			{
				a[i] = t ;
		        ++j;
		}
	}
	for ( int i = 1; i < j; ++i )
	std::cout << "Case " << i << ": " << a[i] << std::endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n;
  cin >> n;
  vector<ll>ar(n);
  ll sum = 0;
  map<ll, int>mp;
  for (int i = 0; i < n; i++){
    cin >> ar[i];
    mp[ar[i]]++;
    sum += ar[i];
  }
  int q;
  cin >> q;
  while (q--){
    ll a, b;
    cin >> a >> b;
    ll d = b - a;
    ll c = mp[a];
    sum += c * d;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << "\n";
  }
  return 0;
}


Measured memory_bytes: 10052
N = gets.to_i
a = gets.chomp.split(" ").map(&:to_i);
sum = 0

a.each do |i|
  sum += i
end
average = (sum.to_f) / N

thumbnail = a[0]
ans = 0

N.times do |i|
  if (average - a[i]).abs < (average - thumbnail).abs
    thumbnail = a[i]
    ans = i 
  end   
end
puts ans

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct SegmentTree {
  vint data;
  vint lazy;
  int sz;
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz *= 2;
    resz(data, 2*sz-1);
    rep(i, sz) data[i+sz-1] = i+1;
    for(int i = sz-2; i >= 0; --i) {
      data[i] = max(data[2*i+1], data[2*i+2]);
    }
    resz(lazy, 2*sz-1, -1);
  }
  void push(int k, int l, int r) {
    if(~lazy[k]) {
      chmax(data[k], lazy[k]);
      if(r-l > 1) {
	chmax(lazy[2*k+1], lazy[k]);
	chmax(lazy[2*k+2], lazy[k]);
      }
      lazy[k] = -1;
    }
  }
  void update(int a, int b, int x, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      chmax(lazy[k], x);
      push(k, l, r);
      return;
    }
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
    data[k] = max(data[2*k+1], data[2*k+2]);
  }
  void update(int a, int b, int x) {
    update(a, b, x, 0, 0, sz);
  }
  int query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return -1;
    if(a <= l && r <= b) return data[k];
    int vl = query(a, b, 2*k+1, l, (l+r)/2);
    int vr = query(a, b, 2*k+2, (l+r)/2, r);
    return max(vl, vr);
  }
  int query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m, q;
  cin >> n >> m >> q;
  vint d(m), a(m), b(m);
  rep(i, m) cin >> d[i] >> a[i] >> b[i], --a[i];
  vint e(q), s(q), t(q);
  rep(i, q) cin >> e[i] >> s[i] >> t[i], --s[i];
  vector<Tapris> vec;
  rep(i, m) vec.emplace_back(d[i], 1, a[i], b[i], i);
  rep(i, q) vec.emplace_back(e[i], 0, s[i], t[i], i);
  sort(all(vec));
  SegmentTree seg(n);
  vector<string> ans(q);
  rep(i, vec.size()) {
    int v, w, x, y, z;
    tie(v, w, x, y, z) = vec[i];
    if(w == 0) {
      if(x+1 >= y) {
	ans[z] = "Yes";
	continue;
      }
      int mr = seg.query(x, x+1);
      int tmp = seg.query(x, mr);
      while(mr != tmp) {
	mr = tmp;
	tmp = seg.query(x, mr);
      }
      ans[z] = (mr >= y ? "Yes" : "No");
      seg.update(x, mr, mr);
    } else {
      seg.update(x, y, y);
    }
  }
  rep(i, ans.size()) cout << ans[i] << endl;

  return 0;
}



Measured memory_bytes: 25060
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long ans = 0;
        for (int i = 1; i < n; i++) {
            ans += ((n + i - 1) / i) - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35620
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n,m;cin>>n>>m;
    vector<vector<LL>> x(n);
    REP(i,n){
        x[i].resize(3);
        cin>>x[i][0]>>x[i][1]>>x[i][2];
    }

    LL result = 0;
    REP(bit,(1<<3)){
        //dump(bit)
        
        vector<LL> v;
        REP(i,n){
            LL tmp = 0;
            REP(j,3){
                if(bit & (1<<j)){
                    tmp += x[i][j];
                }
                else{
                    tmp -= x[i][j];
                }
            }
            v.push_back(tmp);
            //dump(tmp)
        }
        int nth = n-m;
        nth_element(v.begin(), v.begin() + nth, v.end());

        //REP(i,n){
        //    cerr << v[i] << " ";
        //}
        //cerr << endl;
        
        LL sum = 0;
        FOR(i,nth,n){
            sum += v[i];
        }

        result = max(result,sum);


        /*
        priority_queue<LL> pq;

        REP(i,n){
            LL tmp = 0;
            REP(j,3){
                if(bit & (1<<j)){
                    tmp += x[i][j];
                }
                else{
                    tmp -= x[i][j];
                }
            }
            pq.push(tmp);
            //dump(tmp)
        }

        LL sum = 0;
        REP(i,m){
            sum += pq.top();
            pq.pop();
        }

        result = max(result,sum);

        */
    }
    cout << result << endl;

	return;
}

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

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int k, x;
    cin >> k >> x;
    if(x - (k - 1) < -1000000){
        rep(i, -1000000, x + k){
            if(i != -1000000) cout << " ";
            cout << i;
        }
        cout << endl;
    }else if(x + (k - 1) > 1000000){
        rep(i, x - (k - 1), 1000001){
            if(i != x - (k - 1)) cout << " ";
            cout << i;
        }
        cout << endl;
    }else{
        rep(i, x - (k - 1), x + k){
            if(i != x - (k - 1)) cout << " ";
            cout << i;
        }
        cout << endl;
    }

}

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

using namespace std;

int main(void) {
    int n, index_p = 0, index_q = 0;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    do index_p++; while (next_permutation(p.begin(), p.end()));
    do index_q++; while (next_permutation(q.begin(), q.end()));
    cout << abs(index_p - index_q) << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S, T; cin >> S >> T;
  string result = T + S;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back

using namespace std;
int main() {
    IOS;
    int n,k;
    cin>>n>>k;
    vector<int> v;
    for(int y=0;y<n;y++)
    {
        int j;cin>>j;
        v.pb(j);
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int y=2;y<n;y++)
    {
        int idx=1;
        dp[y]=INT_MAX;
        while(y-idx>=0 && idx<=k)
        {
            dp[y]=min(dp[y],dp[y-idx]+abs(v[y]-v[y-idx]));
            idx++;
        }
    }
    cout<<dp[n-1]<<"\n";

    return 0;
}


Measured memory_bytes: 1144
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a > 9)
		{
			System.out.print("-1");
		}
		else if(b > 9)
		{
			System.out.print("-1");
		}
		else
			System.out.print(a*b);
	}
}

Measured memory_bytes: 22996
/*/-----


    Written By:- Sajal Agrawal
          (Have Patience)

/*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define f(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define rf(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define mod 1000000007
#define fi first
#define se second
#define pa pair <ll,ll>
#define mp make_pair
#define c(t) cout<<t<<"\n"
#define pb push_back
#define ln '\n'
#define forstl(i,v) for(auto &i: v)
#define PRI(x) cerr<<#x<<'='<<x<<endl;
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define all(con) con.begin(),con.end()
#define sz(x) ((long long)x.size())
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>

void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

ll dp[100010];
ll find(ll a[],ll i,ll n){

if(i==n-1){
    return 0;
}
if(dp[i]!=-1){
    return dp[i];
}
ll ans=INT_MAX;
if(i<n-1)ans=min(ans,abs(a[i]-a[i+1])+find(a,i+1,n));
if(i<n-2){
    ans=min(ans,abs(a[i]-a[i+2])+find(a,i+2,n));
}
return dp[i]=ans;
}

int main(){

ll n;
cin>>n;
ll a[n];
f(i,0,n+1){
    dp[i]=-1;
}
f(i,0,n){
    cin>>a[i];
}

cout<<find(a,0,n)<<endl;











}





Measured memory_bytes: 6528
S = input()
T = input()

answer = 10**3

for s in range(len(S)):
  if s + len(T) <= len(S):
    count = 0
    for t in range(len(T)):
      if S[s+t] != T[t]:
        count += 1
    answer = min(answer, count)
print(answer)

Measured memory_bytes: 67500
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) A[k] = L[i++];
		else A[k] = R[j++];
	}
}

void mergeSort(int A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main()
{
	int A[MAX], n, i;
	cnt = 0;

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

	mergeSort(A, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;

	cout << cnt << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    string a,b,c;
    cin >> n;
    cin >> a >> b >> c;
    int ans=0;
    for (int i=0;i<n;i++)
    {
        if (a[i]==b[i]&&b[i]==c[i]) ans+=0;
        else if (a[i]==b[i]||b[i]==c[i]||a[i]==c[i]) ans+=1;
        else ans+=2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto &x: a) cin >> x;
  for (auto &x: b) cin >> x;

  reverse(b.begin(), b.end());

  int front = 0;
  int back = n-1;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) continue;
    if (a[i] != b[back] && a[back] != b[i]) {
      swap(b[i], b[back]);
      back--;
      continue;
    }
    else if (a[i] != b[front] && a[front] != b[i]) {
      swap(b[i], b[front]);
      front++;
      continue;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (auto &x: b) cout << x << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>
#include <vector>

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

std::vector<std::vector<int>> Edge;
std::vector<int> In;
std::vector<long double> Expectation;
std::vector<int> ARG;

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

long double compute(int n, int from, int to){
    std::fill(Expectation.begin(), Expectation.end(), 0);
    for(int i = n-2; i >= 0; --i){
        Expectation[i] /= (i == from ? In[i] - 1 : In[i]);
        Expectation[i]++;
        for(int j : Edge[i]) if(!(j == from and i == to)) 
                            Expectation[j] += Expectation[i];
    }
    return Expectation[0];
}


int main(void){
    int n, m; scanf("%d%d", &n, &m);
    Edge.resize(n); In.resize(n);
    REP(i, m){
        int s, t; scanf("%d%d", &s, &t); s--; t--;
        Edge[t].push_back(s); In[s]++;
    }
    Expectation.resize(n+1, 0);
    for(int i = n-2; i >= 0; --i){
        Expectation[i] /= In[i];
        Expectation[i]++;
        for(int j : Edge[i]) Expectation[j] += Expectation[i];
    } Expectation[n] = -1;
    ARG.resize(n-1, n);
    for(int i = n-1; i >= 0; --i){
        for(int j : Edge[i]) if(Expectation[ARG[j]] < Expectation[i]) ARG[j] = i;
    }
    long double res = Expectation[0];

    REP(i, n-1) if(In[i] > 1){
        chmin(res, compute(n, i, ARG[i]));
    }
    printf("%.16Lf\n", res);
    return 0;
}

Measured memory_bytes: 1408
/*                                 ___ _____ 
  ___  _ __ ___   ___  __ _  __ _ / _ \___  |
 / _ \| '_ ` _ \ / _ \/ _` |/ _` | | | | / / 
| (_) | | | | | |  __/ (_| | (_| | |_| |/ /  
 \___/|_| |_| |_|\___|\__, |\__,_|\___//_/   
                      |___/            
*/
// Getting better at it ! ! !
#include <bits/stdc++.h>
#include <string.h>
#define int long long
#define MAX (int)(1e7 + 5)
#define MAX2D (int)(1e3 + 5)
#define itn int
#define inf 5e18
#define MOD (int)(1e9 + 7)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sitr set<int>::iterator
#define mitr map<int, int>::iterator
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define vll vector<unsigned int>
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define fast                       \
    ios_base ::sync_with_stdio(0); \
    cin.tie(NULL);                 \
    cout.tie(NULL)
using namespace std;


void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define see(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define see(x...)
#endif

int f(int n) {
    while(n) {
        if(n%10 != 7) return false;
        n /= 10;
    }
    return true;
}
signed main()
{
    fast;
    int k;
    cin>>k;
    if(k%7 == 0) k /= 7;
    int mod = 0;
    int cnt = 0;
    map<int,int> mp;
    while(1) {
        int g = mod*10 + 1;
        g %= k;
        cnt++;
        if(g == 0) return cout<<cnt, 0;
        if(mp[g]) break;
        mp[g] = 1;
        mod = g;
    }
    cout<<-1;
    return 0; 
}
 
/*
max factors number = 720720 --> 240 factors
max factors number = 1441440 -->288 factors
 
Beautiful program
Please run for me.
I've tried you in BASIC,
FORTRAN and C.
Beautiful program,
You've errors galore.
And each time I run you,
You're swapped out of core.
*/

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

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;






int main(){


        int x,a;
        cin >> x >> a;

        if(x < a) cout << 0 << endl;
        else cout << 10 << endl;

        return 0;




}



Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());

        var d = new int[x + 1];
        d[0] = 0;
        for (int i = 1; i < d.Length; i++)
        {
            d[i] = d[i - 1] + 1;

            var n = 6;
            while (0 <= i - n)
            {
                d[i] = Math.Min(d[i], d[i - n] + 1);
                n *= 6;
            }

            n = 9;
            while (0 <= i - n)
            {
                d[i] = Math.Min(d[i], d[i - n] + 1);
                n *= 9;
            }
        }

        Console.WriteLine(d[x]);
    }
}


Measured memory_bytes: 13204