akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int MAX = 10000;

            int[] memo = new int[MAX + 1];
            memo[0] = 1;

            for (int i = 1; i <= MAX; i++)
            {
                memo[i] = memo[i - 1] + i;
            }

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int n = int.Parse(input);

                sb.AppendLine(memo[n].ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    vector<vector<ll>> a(2,vector<ll>(n));
    rep(i,2)rep(j,n) cin>>a[i][j];
    ll mx=0;
    rep(i,n){
        ll sum=a[0][i];
        rep(j,n){
            if(j<i) sum+=a[0][j];
            else sum+=a[1][j];
        }
        mx=max(mx,sum);
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
t = N//2
la, lb = [], []
for _ in range(N):
    A, B = map(int, input().split())
    la.append(A)
    lb.append(B)
la.sort()
lb.sort()
print(lb[t]-la[t]+1 if N%2 else lb[t-1]-la[t]+lb[t]-la[t-1]+1)


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

const int MaxN = 300 + 5;

int N;
int A[MaxN], Cnt[4];
double dp[MaxN][MaxN][MaxN];
bool vis[MaxN][MaxN][MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
}

double dfs(int i, int j, int k) {
  if (i == 0 && j == 0 && k == 0)
    return dp[i][j][k] = 0;
  if (vis[i][j][k] == true) return dp[i][j][k];
  vis[i][j][k] = true;

  if (k != 0)
    dp[i][j][k] += dfs(i, j + 1, k - 1) * k / N;
  if (j != 0)
    dp[i][j][k] += dfs(i + 1, j - 1, k) * j / N;
  if (i != 0)
    dp[i][j][k] += dfs(i - 1, j, k) * i / N;
  dp[i][j][k]++;
  dp[i][j][k] /= 1.0 * (i + j + k) / N;
  return dp[i][j][k];
}

void solve() {
  for (int i = 1; i <= N; ++i)
    Cnt[A[i]]++;
  printf("%.10lf\n", dfs(Cnt[1], Cnt[2], Cnt[3]));
}

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

Measured memory_bytes: 246016
#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

int main() {
    fastIO;
    double n, t, s;
    cin >> n >> t >> s;

    if (n / s <= t) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int n, w, weigth[110], cost[110];
long long dp[110][100010];
int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// srand(time(NULL));
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	// cout << setprecision(10) << fixed;
	// cout<<(clock() + 0.0) / CLOCKS_PER_SEC;
	cin>>n>>w;
	for (int i=1; i<=n; i++){
		cin>>weigth[i]>>cost[i];
	}
	for (int i=0; i<=n; i++){
		for (int j=1; j<=100000; j++){
			dp[i][j] = 1e18;
		}
	}
	for (int i=1; i<=n; i++){
		for (int j=1; j<=100000; j++){
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
			if (j >= cost[i]){
				dp[i][j] = min(dp[i][j], dp[i-1][j-cost[i]] + weigth[i]);
			}
		}
	}
	int ans = 0;
	for (int i=1; i<=100000; i++){
		if (w >= dp[n][i]){
			ans = i;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 80128
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    

main = do
    _ <- getLine
    (a:as) <- readInts
    print $ foldr gcd a as


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

int top,S[101];

void push(int x){
	S[++top] = x;
}

int pop(){
	return S[top--];
}

int main(){
	char str[10];
	int a,b;
	top = 0;
	
	while(scanf("%s",str) != EOF){
		if(str[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(str[0]=='-'){
			a=pop();
			b=pop();
			push(b-a);
		}else if(str[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			push(atoi(str));
		}
	}
	cout<<pop()<<endl;
}

Measured memory_bytes: 1164
import collections
n,m = map(int, raw_input().split())
cities = [map(int,raw_input().split(' ')) + [i] for i in range(m)]
cities.sort(key  = lambda x :x[1] )
h = {}
def fill(s):
	return (max(0,6 - len(str(s))) * '0') + str(s)

cc = collections.Counter()
for p,y,i in cities:
	cc[p] += 1
	h[i] = '{}{}'.format(fill(p),fill(cc[p]))

for i in range(m):
	print h[i]

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

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    int ans = t / a * b;
    cout << ans << '\n';
}


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

Total = sum(W)
sub_Total = 0
for i in range(len(W)):
  pre_sub_Total = sub_Total
  sub_Total = sub_Total + W[i]
  if Total/2 < sub_Total:
    diff1 = abs(Total - 2*sub_Total)
    diff2 = abs(Total - 2*pre_sub_Total)
    break

print(min(diff1, diff2))    

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

using namespace std;

int main(void)
{
  int n,m; cin>>n;
  vector<int> t(n); 
  for(int i=0;i<n;i++){cin>>t[i];}
  cin>>m;
  vector<int> p(m);
  vector<int> x(m);
  for(int i=0;i<m;i++){cin>>p[i]>>x[i];}
  int sum=0;
  int tmp;
  
  for(int i=0;i<m;i++){
    sum=0;
    for(int j=0;j<n;j++){
      if((j+1)==p[i]){tmp=x[i];}
      else{tmp=t[j];}
      sum+=tmp;
    }
    cout<<sum<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	cin>>str;
	int white = 0, blue = 0;
	for(int i =0;i<str.size();i++)
	{
		if(str[i]=='0')
			white++;
		else
			blue++;
	}
	cout<<2 * min(white,blue)<<endl;
	return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int r = sc.nextInt();
		System.out.println(r*r*3);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
  int a2,b2,x,y; cin>>x>>y;
  
  /*
  a+b=x
  2a+4b=y
  det=2
              (4  -1)
  A^(-1)=(1/2)(     )
              (-2  1)
  */
  
  a2 = 4*x-y;
  b2 = -2*x+y;
  //cout<<a<<' '<<b<<endl;
  if(a2>=0&&a2%2==0&&b2>=0&&b2%2==0){cout<<"Yes";}
  else{cout<<"No";}
  
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n,k;
	cin >> n >> k;
	vector<int> l(n);
	for(int i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	reverse(l.begin(),l.end());
	int ans=0;
	for(int i=0; i<k; i++){
		ans+=l[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n > 9 && n < 100)
    cout << 9;
  else if(n > 999 && n < 10000)
    cout << 909;
  else if(n > 99 && n < 1000)
    cout << n-90;
  else if(n == 100000)
    cout << 90909;
  else if(n < 10)
    cout << n;
  else
    cout << n-9090;
}
  

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    sum_a=sum(aa)
    s=0
    ans=10**16
    for a in aa[:-1]:
        s+=a
        cur=abs(sum_a-2*s)
        if cur<ans:ans=cur
    print(ans)
main()

Measured memory_bytes: 23804
s, t, q = list(input()), list(input()), int(input())
ssum, tsum = [0], [0]
for i in range(len(s)):
    if s[i]=="A": ssum.append(ssum[-1]+1)
    else: ssum.append(ssum[-1]+2)
for i in range(len(t)):
    if t[i]=="A": tsum.append(tsum[-1]+1)
    else: tsum.append(tsum[-1]+2)
for i in range(q):
    a,b,c,d = map(int,input().split())
    sa = (ssum[b]-ssum[a-1])-(tsum[d]-tsum[c-1])
    if abs(sa)%3==0:print("YES")
    else: print("NO")

Measured memory_bytes: 65300
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int d = stdin.nextInt();
        
        int div = n / (d * 2 + 1);
        int mod = n % (d * 2 + 1);
        if (mod == 0) {
            System.out.println(div);
        } else {
            System.out.println(div + 1);
        }
    }

}


Measured memory_bytes: 23892
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();
			int n = cin.nextInt();
			int k = cin.nextInt();
			int[] a = cin.ArrayInt(n);
			var dic = new Dictionary<int,int>();
			foreach (var item in a)
			{
				if (dic.ContainsKey(item)) dic[item]++;
				else dic.Add(item, 1);
			}
			var dic1 = dic.OrderByDescending((x) => x.Value);
			int sum = 0;
			int i = 0;
			foreach (var item in dic1)
			{
				sum += item.Value;
				i++;
				if (i >= k) break;
			}
			Console.WriteLine(Math.Max(0, n - sum));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

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

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

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

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

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

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

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

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 36388
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    string sa, sb;
    // for a
    for (int i = 0; i < b; i++) {
        sa += to_string(a);
    }

    // for b
    for (int i = 0; i < a; i++) {
        sb += to_string(b);
    }
    // print the smaller one
    sa < sb ? cout << sa : cout << sb;

    return 0;
}

Measured memory_bytes: 256
/*
Reference : https://www.geeksforgeeks.org/maximum-product-subsequence-size-k/
 
 
*/
#include <bits/stdc++.h> 
using namespace std; 
 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.second>b.second; 
} 
 
/*
Mistakes
 
- while using pairs make sure you comparator datatype it's int by default change it as per the need
- Modify comparator if you want to
*/
#define f first
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll64 int64_t
#define pb push_back
#define pll pair<long long int,long long int>
#define pi pair<int,int>
#define mi map<int,int>
#define ll long long int
#define mll map<long long int,long long int>
#define umi unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long int,long long int>>
#define mod 1000000007
#define fp(i,x,n) for(int i=x;i<n;i++)
#define fn(i,x,n) for(int i=x;i>n;i--)
#define fpm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define asort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysec)
#define asort_vp_first(vect) sort(vect.begin(), vect.end())
#define dsort_vp_first(vect) sort(vect.begin(), vect.end(), sortinrev) 
#define dsort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysecdesc)
#define vi vector<int>
#define vll vector<long long int>
#define c(x) cout<<x<<endl;
#define M 1000000007
using namespace std; 
#define int long long int
 
signed main()
{
    FIO;
    int x;
    cin>>x;
    if(x==1)
    cout<<0<<endl;
    else
    cout<<1<<endl;
   
   
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int i,j;
  int K,N;
  
  double p[200000];
  double S=0,max=0;
  
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++){
    scanf("%lf",&p[i]);
  }

  for(i=0;i<N;i++){
    p[i] = (p[i] + 1)/2;
  }

  for(i=0;i<K;i++){
    S += p[i];
  }
  max = S;
  j=0;
  for(i=K;i<N;i++){
    S -= p[j];
    S += p[i];
    if(S > max) max = S;
    j++;
  }
  printf("%f",max);
  return 0;
}

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

using namespace std;

int main()
{
    int m[10];

    for (int i = 0; i < 10; ++i) cin >> m[i];

    sort(m, m + 10, greater<int>());

    for (int i = 0; i < 3; ++i) cout << m[i] << endl;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <algorithm>
using namespace std;

typedef complex<double> P;
struct L : public vector<P>
{
	L(P a, P b) { push_back(a); push_back(b); }
};


#define EPS			(1e-10)
#define PI			(3.14159265358979323846)
#define INF			1e30

#define X(a)		( (a).real() )
#define Y(a)		( (a).imag() )
#define EQ(a,b)		( -EPS<(a)-(b) && (a)-(b)<EPS )
#define EQV(a,b)	( EQ(X(a),X(b)) && EQ(Y(a),Y(b)) )

#define unit(a)		( (a)/abs(a) )
#define normal(a)	( (a)*P(0,1) )
#define dot(a,b)	( X((a)*conj(b)) )
#define cross(a,b)	( Y(conj(a)*(b)) )

int ccw(P a, P b, P c)
{
	b -= a; c -= a;
	if(cross(b, c) > 0)   return +1;	// counter clockwise
	if(cross(b, c) < 0)   return -1;	// clockwise
	if(dot(b, c) < 0)     return +2;	// c--a--b on line
	if(norm(b) < norm(c)) return -2;	// a--b--c on line
	return 0;
}

bool intersectSS(P a, P b, P c, P d)
{
	return	ccw(a,b,c)*ccw(a,b,d) <= 0 &&
			ccw(c,d,a)*ccw(c,d,b) <= 0;
}

double graph[1000][1000];

void makeGraph(vector<P>& towns, P a, P b)
{
	for(int i=0; i<towns.size(); i++)
	for(int j=i+1; j<towns.size(); j++)
	{
		graph[i][j] = graph[j][i] = graph[i][i] = graph[j][j] = INF;
		if(intersectSS(towns[i], towns[j], a,b)) continue;
		graph[i][j] = graph[j][i] = abs(towns[i] - towns[j]);
	}
}

class State
{
public:
	int n;
	double c;
	State(int n, double c)
		:n(n),c(c)
	{}

	bool operator<(const State& s) const
	{
		return c>s.c;
	}
};

double dijkstra(int N)
{
	priority_queue<State> q;
	q.push(State(0,0));

	bool visited[1000] = {0};

	while(!q.empty()) {
		State s = q.top(); q.pop();
		if(s.n == 1) return s.c;

		if(visited[s.n]) continue;
		visited[s.n] = true;

		for(int i=0; i<N; i++) {
			if(graph[s.n][i] == INF) continue;
			if(visited[i]) continue;

			q.push(State(i,s.c+graph[s.n][i]));
		}
	}
	return INF;
}

void solve(vector<P>& totata, vector<P>& tutete)
{
	double res = INF;
	for(int i=0; i<2; i++) {
		makeGraph(totata, tutete[0], tutete[1]);
		res = min(res, dijkstra(totata.size()) + abs(tutete[0]-tutete[1]));
		swap(totata, tutete);
	}

	if(res == INF) cout << -1 << endl;
	else {
		cout.setf(ios::fixed);
		cout.precision(13);
		cout << res << endl;
	}

}

int main()
{
	int M,N;
	cin >> M >> N;
	vector<P> totata(M), tutete(N);

	for(int i=0; i<M; i++) {
		double a,b;
		cin >> a >> b;
		totata[i] = P(a,b);
	}

	for(int i=0; i<N; i++) {
		double a,b;
		cin >> a >> b;
		tutete[i] = P(a,b);
	}

	solve(totata, tutete);
}

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, m, r;
	cin >> n >> m >> r;
	vector<int> v(r);
	rep(i, r) {
		cin >> v[i];
		v[i]--;
	}
	sort(all(v));
	vector<vector<int>> dis(n, vector<int>(n, inf));
	rep(i, n) dis[i][i] = 0;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		chmin(dis[a][b], c);
		chmin(dis[b][a], c);
	}
	rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
	int ans = inf;
	do {
		int res = 0;
		rep(i, r - 1) res += dis[v[i]][v[i + 1]];
		chmin(ans, res);
	} while (next_permutation(all(v)));
	cout << ans << '\n';
	rep(i, n) {
		rep(j, n) {
			cerr << dis[i][j] << ' ';
		}
		cerr << '\n';
	}
}

Measured memory_bytes: 384
# 解説放送

def main():
    from collections import defaultdict

    n = int(input())

    d = defaultdict(int)
    for x in range(1, n + 1):
        if x % 10 == 0:
            continue

        tail = x % 10
        head = 0
        while x:
            head = x
            x //= 10

        d[head, tail] += 1

    ret = 0
    for (head, tail), cnt in tuple(d.items()):
        # RuntimeError: dictionary changed size during iteration
        # defaultdictの未定義(?)のkeyにアクセスするせいで、REになる
        # d.items()をtuple化して回避
        ret += d[head, tail] * d[tail, head]
        # (head,tail)の出現数を辞書で管理する
        # (head,tail)*(tail,head)の組み合わせがある

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
   int n,l;
   cin>>n>>l;
   vector<string>v(n);
   for(int i=0;i<n;i++){
    cin>>v[i];
   }
   sort(v.begin(),v.end());
   for(int i=0;i<n;i++){
    cout<<v[i];
   }
   cout<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

int main(){

    int A, B, ans;
    cin >> A >> B;

    ans = A - 2 * B;
    if (ans > 0) cout << ans << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	private LinkedList<Boolean> visited;
	private LinkedList<Integer> vertexEnum, preNum, postNum;
	//adjacency list of edges
	public Graph() {
		totalVertex = 0;
		visited = new LinkedList<Boolean>();
		vertexEnum = new LinkedList<Integer>();
		preNum = new LinkedList<Integer>();
		postNum = new LinkedList<Integer>();
	}
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public int nextUnvisited() {
        for(int i = 0; i < visited.size(); i ++)
            if(visited.get(i) == false) return i;
        return -1;
    }
	public void preWalk() {
        visited.clear();
        for(int i = 0; i < totalVertex; i ++) {
        	visited.add(false);
        	preNum.add(0);
        	postNum.add(0);
        }
        vertexEnum.clear();
    }
	public void walk() {
        //method can be "DFS" or "BFS"
        preWalk();
        time = 1;
        int s;
        while((s = nextUnvisited()) != -1) {
        	DFS(s);
        }
    }
	public boolean ifVisited(int v) { return visited.get(v); }
	public void setVisited(int v) { 
        //set vertex v to be visited
        visited.set(v, true); 
        vertexEnum.add(v);
    }
	private int time;
	public void DFS(int v) {
	    preNum.set(v, time);
	    time++;
	    //e.g., preNum.add(v) for preVisit enumeration of the nodes
	    setVisited(v);
	    List<Integer> neighbors = adjList.get(v);
	    for(int i = 0; i < neighbors.size(); i ++) {
	        int v1 = neighbors.get(i);
	        if(ifVisited(v1) == false) DFS(v1); //use recursion!
	    }
	    postNum.set(v, time);
	    time++;
	}
	public void displayEnum() {
        //display enumeration of the vertices
        for(int i = 0; i < totalVertex; i ++) {
            System.out.println((i + 1) + " " + preNum.get(i) + " " + postNum.get(i));
        }
    }
}

public class Main {
	public static void main(String[] args) {
		Graph g = new Graph();
		g.loadAdjList();
		g.walk();
		g.displayEnum();
	}
}


Measured memory_bytes: 28812
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


ll mod = 998244353;
ll root = 3;


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

vector<ll>dft(vector<ll>A,int N,ll Nroot){
	if (N == 1)return A;
	vector<ll>F(N / 2), G(N / 2);
	for (int i = 0; i < N / 2; i++) {
		F[i] = A[2 * i + 0];
		G[i] = A[2 * i + 1];
	}

	ll nxtroot = (Nroot*Nroot) % mod;

	F = dft(F,N/2,nxtroot);
	G = dft(G,N/2,nxtroot);

	ll pow = 1;
	for (int i = 0; i < N; i++) {
		A[i] = (F[i%(N/2)]+ pow*G[i%(N/2)])%mod;
		pow = (pow * Nroot)%mod;
	}
	return A;
}
vector<ll>inv_dft(vector<ll>A,int N,ll Nroot) {
	vector<ll>arranged = dft(A, N,Nroot);
	vector<ll>swapped(N);
	for (int i = 0; i < N; i++)swapped[i] = arranged[(N - i) % N];
	vector<ll>ret(N);
	ll rev = modpow(N,mod-2);
	for (int i = 0; i < N; i++)ret[i] = (rev*swapped[i]) % mod;
	return ret;
}

vector<ll>ntt(vector<ll>A,vector<ll>B){
	//calculate Nth root
	ll P = mod;
	P--;
	int N = 1;
	while (P % 2 == 0) {
		N *= 2;
		P /= 2;
		if (A.size() + B.size() <= N)break;
	}
	ll Nroot = modpow(root,P);
	//

	A.resize(N);
	B.resize(N);

	A = dft(A,N,Nroot);
	B = dft(B,N,Nroot);

	vector<ll>F(N);
	for (int i = 0; i < N; i++) {
		F[i] = (A[i] * B[i]) % mod;
	}
	return inv_dft(F,N,Nroot);
}

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

	int N, M;
	cin >> N >> M;
	vector<ll>A(N), B(M);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < M; i++)cin >> B[i];

	vector<ll>ans = ntt(A, B);
	for (int i = 0; i < N + M - 1; i++)cout << ans[i] << " ";
	puts("");
	return 0;
}

Measured memory_bytes: 77072
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
    
def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct

A, B = map(int, input().split())
G = gcd(A, B)
fct = factorize(G)
ans = 1+len(fct)

print(ans)

Measured memory_bytes: 38640
/*
lakshaygpt28
Lakshay Gupta
*/

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

const double PI = acos(-1);
const long long LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

int main() {
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int x;
    cin >> x;
    cout << (x ^ 1) << "\n";
    return 0;
}


Measured memory_bytes: 3636
n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_input().split() )

def solve(i, m):
  if m == 0:
    return True
  elif i >= n or m > sum(A):
    return False

  res = solve( i+1 , m ) or solve( i+1 , m-A[i] )
  return res

for m in mi:
  if solve( 0 , m ): print "yes"
  else: print "no"

Measured memory_bytes: 6444
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M, K = [int(x) for x in input().strip().split()]

# 友達グループ(候補含む)
par = [i for i in range(N+1)]
rank = [0] * (N+1)

# 友達
friends = [0 for _ in range(N+1)]

# ブロックしている数
blocked = [0 for _ in range(N+1)]

def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]

def isSame(x, y):
    return find(x) == find(y)

def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 

    if rank[x] >= rank[y]:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
    else:
        par[x] = y

for m in range(M):
    a, b = [int(x) for x in input().strip().split()]
    union(a, b)
    friends[a] += 1
    friends[b] += 1

for k in range(K):
    c, d = [int(x) for x in input().strip().split()]
    if isSame(c, d):
        blocked[c] += 1
        blocked[d] += 1


for n in range(1, N+1):
    find(n)

cnt = Counter(par)
print(*[cnt[par[n]] - friends[n] - blocked[n] - 1 for n in range(1, N+1)])

Measured memory_bytes: 19016
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  ll N;
  cin >> N;
  cout << ((N-1)*N)/2 << endl;
}

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

public class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        int x, y, z;
        int ans = 0;
        try{
        	String[] list = br.readLine().split(" ");
        	x = Integer.parseInt(list[0]);
        	y = Integer.parseInt(list[1]);
        	z = Integer.parseInt(list[2]);
        	
        	for (int i = x; i <= y; i++)
        	{
        		if (z % i == 0)
        			ans += 1;
        	}
        	
        }
        catch(IOException e){
        	e.printStackTrace();
        }
        System.out.println(ans);
	}

}

Measured memory_bytes: 24376
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

const int MAX_N = 1e5+1;
 
ll par[MAX_N]; // 親
ll size_list[MAX_N]; // iを親とするグループのサイズ
ll depth[MAX_N]; // 木の深さ
 
 
// n要素の初期化
void init(ll n){
	REP(i,n){
		par[i] = i;
		depth[i] = 0;
	}
}
 
// 木の根を求める
ll find(ll x){
	if (par[x]==x){
		return x;
	}
	else{
		return par[x] = find(par[x]);
	}
}
 
// xとyの属する集合を併合
void unit(ll x, ll y){
	x = find(x);
	y = find(y);
	if (x==y) return;
 
	if (depth[x]<depth[y]){ // xよりyが深いなら
		size_list[y] += size_list[par[x]];
		par[x] = y; // xの親はy
	}
	else{
		size_list[x] += size_list[par[y]];
		par[y] = x;
		if (depth[x]==depth[y]) depth[x]++;
	}
}
 
// xとyが同じ集合に属するか否か
bool same(ll x, ll y){
	return find(x) ==find(y);
}
 
// xのグループの大きさ
ll size(ll x){
	return size_list[par[x]];
}

 
int main() {
	// 入力
	ll N,M;
	cin >> N>>M;
	ll X[M],Y[M],Z[M];
	REP(i,M){
		ll x,y,z;cin>>x>>y>>z;x--;y--;
		X[i] = x;Y[i] = y;Z[i] = z;
	}
 
	// 解法
	init(N); // Union-Find木を初期化
	REP(i,M){
		unit(X[i],Y[i]);
	}
	// REP(i,N){
	// 	printf("%lld: %lld, %lld\n", i, par[i], depth[i]);
	// }
	set<ll> se;
	REP(i,N) se.insert(find(i));
	printf("%lld\n", se.size());
	// printf("%lld\n", 1);
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int bp(int pow, int n){
    int d = 1;
    while(n)
    {
        if(n%2==1)d=(d*pow)%mod;
        pow=(pow*pow)%mod;
        n/=2;
    }
    return d;
}
void solve(){
    int k, a, b;
    cin>>k>>a>>b;
    int cnt = 1;
    while (k*cnt<min(a, b))cnt++;
    if(cnt*k>=min(a, b)&&cnt*k<=max(a, b))cout<<"OK\n";
    else cout<<"NG\n";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
ll a[6][6];
ll used[6][6];
bool checks(vector<ll> &t)
{
        for(ll i=1;i<=4;i++) for(ll j=1;j<=4;j++) used[i][j]=a[i][j];
        ll cur = t[0];
        ll pos=0;
        while(pos < 3LL) {
                ll nxt = t[pos+1LL];
                if(used[nxt][cur]) {
                        used[nxt][cur]=0;
                        used[cur][nxt]=0;
                        cur = nxt;
                        pos++;
                }else return false;
        }
        return true;
}
int main()
{
        for(ll i=1;i<=3;i++) {
                ll u,v;
                cin >> u >> v;
                a[u][v]=1;
                a[v][u]=1;
        }
        vector<ll> v;
        for(ll i=1;i<=4;i++) v.pb(i);
        do{
                if(checks(v)){
                        cout << "YES\n"; return 0;
                }
        }while(next_permutation(v.begin(), v.end()));
        cout << "NO\n"; return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;
class modint_t {
public:
    modint_t() = default;
    modint_t(int64_t value):value(value % MOD){}

    bool operator<(const modint_t rhs) const { return value < rhs.value; }
    bool operator<=(const modint_t rhs) const { return value <= rhs.value; }
    bool operator>(const modint_t rhs) const { return value > rhs.value; }
    bool operator>=(const modint_t rhs) const { return value >= rhs.value; }

    modint_t operator+(const modint_t rhs) const { return modint_t(value + rhs.value); }
    modint_t operator+=(const modint_t rhs) { return value = (value + rhs.value) % MOD; }
    modint_t operator-(const modint_t rhs) const { return modint_t(MOD + value - rhs.value); }
    modint_t operator-=(const modint_t rhs) { return value = (MOD + value - rhs.value) % MOD; }

    modint_t operator*(const modint_t rhs) const { return modint_t(value * rhs.value); }
    modint_t operator*=(const modint_t rhs) { return value = value * rhs.value % MOD; }
    modint_t operator/(const modint_t rhs) const { return *this * rhs.invert(); }
    modint_t operator/=(const modint_t rhs) { return *this *= rhs.invert(); }

    modint_t square() const { return *this * *this; }
    modint_t power(int64_t y) const
    {
        if(y == 0) return 1;
        else if(y == 1) return *this;
        else if(y % 2 == 0) return this->power(y/2).square();
        else return *this * this->power(y-1);
    }

    modint_t invert() const
    {
        return power(MOD-2);
    }

    operator int64_t() const
    {
        return value;
    }
private:
    static const int MOD = 1000000007;
    int64_t value = 0;
};

struct combination {
    vector<modint_t> fact, ifact;
    combination(int n)
        : fact(n + 1)
        , ifact(n + 1)
    {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * modint_t(i);
        ifact[n] = fact[n].invert();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * modint_t(i);
    }
    modint_t operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

void solution()
{
    int k;
    string s;
    cin >> k >> s;
    const int n = s.size();

    modint_t answer;
    combination comb(n+k);
    for(int i = 0; i <= k; ++i){
        answer += modint_t(25).power(i) * comb(i+n-1,n-1) * modint_t(26).power(k-i);
    }
    cout << answer << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 35584
#include<stdio.h>
int gcd(int a, int b)
{
	int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int gl[100005], gr[100005];
	gl[0] = a[0];
	for (i = 1; i < n; i++)
		gl[i] = gcd(gl[i - 1], a[i]);
	gr[n - 1] = a[n - 1];
	for (i = n - 2; i >= 0; i--)
		gr[i] = gcd(gr[i + 1], a[i]);
	int max = gr[1];
	for (i = 1; i < n - 1; i++)
		if (max < gcd(gl[i - 1], gr[i + 1]))
			max = gcd(gl[i - 1], gr[i + 1]);
	if (max < gl[n - 2])
		max = gl[n - 2];
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <map>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <array>

using namespace std;

int main()
{
    string str;
    cin >> str;
    bool n=false, s=false, w=false, e=false;
    for(auto c : str) {
        if(c=='N') n = true;
        else if (c=='S') s = true;
        else if(c=='W') w = true;
        else e = true;
    }
    if((n&&s) || (!n&&!s)) {
        if((w&&e) || (!w&&!e)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
a, b, c = gets.to_s.split.map{|t|t.to_i}

o_num = 0
o_num += 1 if a.odd?
o_num += 1 if b.odd?
o_num += 1 if c.odd?

ans = 0
if o_num == 1
  
  ans += 1
  a += 1 if a.even?
  b += 1 if b.even?
  c += 1 if c.even?
  
elsif o_num == 2
  
  ans += 1
  a += 1 if a.odd?
  b += 1 if b.odd?
  c += 1 if c.odd?

end

x = [a, b, c].sort
m = x.max

ans += ( m - x[0] ) / 2
ans += ( m - x[1] ) / 2

puts ans

Measured memory_bytes: 14276
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    hs <- VU.fromList <$> getIntList
    dp <- VUM.replicate n 0
    VUM.write dp 0 0
    VUM.write dp 1 $ abs ((hs VU.! 1) - (hs VU.! 0))
    forM_ [2..n-1] $ \i -> do
        a <- VUM.read dp (i - 1)
        b <- VUM.read dp (i - 2)
        let da = abs $ (hs VU.! (i - 1)) - (hs VU.! i)
        let db = abs $ (hs VU.! (i - 2)) - (hs VU.! i)
        VUM.write dp i $ min (a + da) (b + db)
    ans <- VUM.read dp (n - 1)
    print ans

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	string s;
	cin>>s;

	if(s=="AAA" || s=="BBB")cout<<"No"<<endl;
	else cout<<"Yes"<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    long long N, A, B, ans;    cin >> N >> A >> B;
    if(A>B) cout << 0;
    else if(A==B)    cout << 1;
    else{
        if(N==1)    cout << 0;
        else if(N==2)   cout << 1;
        else{
            ans = B*(N-1)+A - A*(N-1) -B + 1;
            cout << ans;
        }
    }
}

Measured memory_bytes: 3584
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    bool ans=true;
    rep(i,N-1) if(A[i]==A[i+1]) ans=false;
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n, m, k;
  cin >> n >> m >> k;
  vector<FiniteField> factorials(n * m + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n * m; i++) {
    factorials[i] = factorials[i - 1] * i;
  }

  FiniteField ans = 0;
  FiniteField x_base = 0, y_base = 0;
  for (int dx = 1; dx <= m - 1; dx++) {
    x_base += FiniteField(n) * n * (m - dx) * dx;
  }
  for (int dy = 1; dy <= n - 1; dy++) {
    y_base += FiniteField(m) * m * (n - dy) * dy;
  }
  ans = x_base + y_base;
  // cout << ans.Value() << endl;

  ans *= factorials[n * m - 2];
  ans /= factorials[k - 2];
  ans /= factorials[n * m - k];
  cout << ans.Value() << endl;
}


Measured memory_bytes: 1792
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s1: Vec<char> = input::<String>().chars().collect();
    let s2: Vec<char> = input::<String>().chars().collect();
    let s3: Vec<char> = input::<String>().chars().collect();
    println!(
        "{}{}{}",
        s1[0].to_uppercase().collect::<String>(),
        s2[0].to_uppercase().collect::<String>(),
        s3[0].to_uppercase().collect::<String>()
    );
}


Measured memory_bytes: 4352
N, M, L = list(map(int, input().split()))
NMtable = [[] for i in range(N)]
MLtable = [[] for i in range(M)]

for i in range(N):
    nums = list(map(int, input().split()))
    NMtable[i] = nums

for i in range(M):
    nums = list(map(int, input().split()))
    MLtable[i] = nums
    
for n in range(N):
    for l in range(L):
        total = 0
        for m in range(M):
             total += NMtable[n][m] * MLtable[m][l]
        if l > 0: print(" ", end="")
        print(f"{total}", end="")
    print()




Measured memory_bytes: 6512
import java.util.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      if(N<10){
        System.out.println(N);
        return;
    }
    Deque<Long> lll = new ArrayDeque<Long>();
    
    for(int i=1; i < 10; i++){
      lll.add(Long.valueOf(i));
    }
     
    Integer cnt = 9;
    while(cnt < N){
      Long prev = lll.poll();
      Long now = Long.valueOf(0);
      if((prev%10)!=0){
        now = 10*prev + (prev%10) -1;
        lll.add(now);
        cnt++;
      }
      if(cnt==N){
        System.out.println(now);
        return;
      }
      now = 10*prev + (prev%10);
      lll.add(now);
      cnt++;
	  if(cnt==N){
        System.out.println(now);
        return;
      }
      if((prev%10)!=9){
		now = 10*prev + (prev%10) + 1;
        lll.add(now);
        cnt++;
      }
      if(cnt==N){
        System.out.println(now);
        return;
      }
    }
  }
}

Measured memory_bytes: 27732
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n = 0, s = 0, w = 0, e = 0;
    string str;
    cin >> str;
    for(int i = 0; i < str.length(); i++){
        switch ((str.at(i))) {
            case 'N':
                n++;
                break;
            case 'S':
                s++;
                break;
            case 'W':
                w++;
                break;
            case 'E':
                e++;
                break;
            default:
                break;
        }
    }
    string ans = "No";
    if(((n > 0 && s > 0) || (n == 0 && s == 0)) && ((w > 0 && e > 0) || (w == 0 && e == 0)))
        ans = "Yes";
    cout << ans;
}

Measured memory_bytes: 256