akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import static java.util.Comparator.comparing;
import static java.util.Comparator.reverseOrder;

public class Main {

    public static class Restaurant {
        private int num;
        private String name;
        private int point;

        public Restaurant(int num, String name, int point) {
            this.num = num;
            this.name = name;
            this.point = point;
        }

        public int getNum() {
            return num;
        }

        public String getName() {
            return name;
        }

        public int getPoint() {
            return point;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Restaurant> restaurants = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int point = sc.nextInt();
            restaurants.add(new Restaurant(i + 1, name, point));
        }

        restaurants
                .sort(comparing(Restaurant::getName).thenComparing(Restaurant::getPoint, reverseOrder()));
        for (Restaurant r : restaurants) {
            System.out.println(r.getNum());
        }
    }

}


Measured memory_bytes: 27348
from collections import Counter
U = 10 ** 6 + 1

N = int(input())
A = list(map(int, input().split()))

C = Counter(A)
dp = [0] * U

ans = 0
for k in sorted(C.keys()):
    if dp[k]:
        continue
    if C[k] == 1:
        ans += 1
    for i in range(k, U, k):
        dp[i] = 1

print(ans)

Measured memory_bytes: 40144
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, t := intScanner(), intScanner(), intScanner()
	fmt.Println(t / a * b)
}


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

int moveS(int poz, int Q, std::vector<std::pair<char, char>>squareMoves, std::string s)
{
    int len = s.size();
    if(poz < 0)
    {
        return -1;
    }
    if(poz >= len)
    {
        return 1;
    }
    for(int i = 0; i < Q; i++)
    {
        if(squareMoves[i].first != s[poz]) continue;
        if(squareMoves[i].second == 'L')
        {
            poz--;
        }
        else
        {
            poz++;
        }
        if(poz >= len)
        {
            return 1;
        }
        if(poz < 0)
        {
            return -1;
        }
    }

    return 0;
}


int main()
{
    int N, Q;

    std:: cin >> N >> Q;

    std::string s;
    std::cin >> s;

    std::vector<int> count(s.size()+2, 1);
    count[0] = count[s.size()+1] = 0;

    std::vector<std::pair<char, char>>squareMoves;
    for(int i = 0; i < Q; ++i)
    {
        char square, move;
        std:: cin >> square >> move;

        squareMoves.push_back(std::make_pair(square, move));
    }


    int st, dr;
    st = -1;
    dr = N + 1;

    while(st < dr-1)
    {
        int mij = (st+dr)/2;
        //std::cout << moveS(mij, Q, squareMoves, s);
        if(moveS(mij, Q, squareMoves, s) == -1)
        {
            st = mij;
        }
        else
        {
            dr = mij;
        }
    }
    //std::cout << dr;
    int sol1 = dr;

    st = -1;
    dr = N + 1;
    while(st < dr-1)
    {
        int mij = (st+dr)/2;
        if(moveS(mij, Q, squareMoves, s) == 0 || moveS(mij, Q, squareMoves, s) == -1)
        {
            st = mij;
        }
        else
        {
            dr = mij;
        }
    }
    //std::cout << dr;
    int sol2 = dr;

    std::cout << sol2 - sol1;
    return 0; 
}

Measured memory_bytes: 2840
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g $PROGRAM -o $OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

vector<string> split(char d,string s)
{
	stringstream ss(s);
	string t;
	vector<string> words;
	while(getline(ss,t,d))
	{
		words.pb(t);
	}

	return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
	auto start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	double odd = 0, even = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n;++i)
	{
		if(i &1)
			odd++;
		else
			even++;
	}

	double ans = odd / (double)n;
	cout << std::setprecision(10) << std::fixed;

	cout<< ans;

#ifdef LOCAL
	auto end = chrono::high_resolution_clock::now();
	double time_taken =
		chrono::duration_cast<chrono::nanoseconds>(end - start).count();

	time_taken *= 1e-9;

	cerr << "\nTime taken by program is : " << fixed
		 << time_taken << setprecision(9);
	cerr << " sec" << endl;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
bool see[410][410]={};
string g[410];

int d[]={1,0,-1,0,1};

Pl dfs(int i,int j){
  see[i][j]=true;
  Pl p=Pl(0,0);
  if(g[i][j]=='#')p.first++; else p.second++;
  //cout<<i<<' '<<j<<'\n';
  rep(k,4){
    int y=i+d[k],x=j+d[k+1];
    if(y<0||y>=n||x<0||x>=m||see[y][x]||g[y][x]==g[i][j])continue;
    Pl pp=dfs(y,x);
    p.first+=pp.first;
    p.second+=pp.second;
  }
  return p;
}

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

  cin>>n>>m; Int ans=0;
  rep(i,n)cin>>g[i];
  rep(i,n)rep(j,m){
    if(!see[i][j]){
      Pl bw=dfs(i,j);
      ans+=bw.first*bw.second;
    }
  }
  END
}

Measured memory_bytes: 18048
from scipy.sparse.csgraph import floyd_warshall
import itertools

n,m,r=[int(x) for x in input().split()]
rlist=[int(x)-1 for x in input().split()]
abc=[[int(x) for x in input().split()] for _ in range(m)]

adj=[[float("inf")]*n for _ in range(n)]

for item in abc:
  if item[2]<adj[item[0]-1][item[1]-1]: adj[item[0]-1][item[1]-1]=item[2]
  if item[2]<adj[item[1]-1][item[0]-1]: adj[item[1]-1][item[0]-1]=item[2] 

d=floyd_warshall(adj)

res=float("inf")

for route in itertools.permutations(rlist):
  tmp=sum([d[route[i]][route[i+1]] for i in range(len(route)-1)])
  if tmp<res: res=tmp

print(int(res))  

Measured memory_bytes: 18532
import sys
sys.setrecursionlimit(10 ** 6)
n , m = map(int,input().split())
coins = list(map(int,input().split()))
coins.sort(reverse=True)
dp = [[float("inf")]*(n + 1) for _ in range(m + 1)]
def solve(i , value):
    if dp[i][value] != float("inf"):
        return dp[i][value]
    if i == m - 1 or value == 0:
        ret_val = value
    elif coins[i] > value:
        ret_val = solve(i + 1,value)
    else:
        ret_val = min(solve(i + 1,value) , solve(i,value - coins[i]) + 1)
    dp[i][value] = ret_val
    return ret_val

solve(0 , n)
print(dp[0][n])


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



bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int fib(int n)
{
    if (n <= 1)
        return n;
    return fib(n-1) + fib(n-2);
}





int main()

{

int n,k,count=0;
cin>>n>>k;
int ar[n];
for(int i=0;i<n;i++)
{
    cin>>ar[i];
}
for(int i=0;i<n;i++)
{
    if(ar[i]>=k)
    {
        count++;
    }
}
cout<<count<<endl;


}



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

#define ll 					long long
#define db					double
#define ull 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define vl					vector<ll>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const ll infll = 1e18+5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 1005;
int n, val[MAXN], vk;

int main() {
	gi(n); gi(vk);
	int mn = inf;
	for (int i=1; i<=n; i++) {
		int x; gi(x);
		mn = min(mn,x);
		vk -= x;
	}
	printf ("%d\n", n + (vk/mn));
	return 0;
}

Measured memory_bytes: 256
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;

int main(){
	int n;
	char s[101000];
	char ans[101000];
	int x = 0;

	cin >> n;
	scanf("%s", s);

	for(int i=0;i<n;i++)
		while(666){
			if(s[i]==s[i+1]){
				ans[x] = s[i];
			}else{
				ans[x++] = s[i];
				break;
			}
			if(ans[x] == s[i+1]){
				i++;
			}else{
				x++;
				break;
			}
		}
	cout <<x<< endl;
}


Measured memory_bytes: 384
totalPrograms, totalChannels = STDIN.gets.split(" ").map{|x| x.to_i }
program_times = []
totalPrograms.times {
    start, stop, channel = STDIN.gets.split( " " ).map{|x| x.to_f}
    start -= 0.5
    channel -= 1
    program_times << ['S', start, channel]
    program_times << ['E', stop, channel]
}

program_times.sort! {|t1, t2| t1[1] - t2[1]}

maxRecording = 0
recording = 0
recordingChannels = Array.new(30,0)
program_times.each { |t|
    if( t[0] == 'S' )
        recording += 1 if recordingChannels[ t[2] ] == 0
        recordingChannels[ t[2] ] += 1
    elsif( t[0] == 'E' )
        recordingChannels[ t[2] ] -= 1
        recording -= 1 if recordingChannels[ t[2] ] == 0
    end
    maxRecording = recording if recording > maxRecording
}
puts maxRecording


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

int main()
{
	ll n, res = 0; cin >> n;
	if (n % 2)	cout << 0;
	else
	{
		for (ll i = 10; i <= n; i *= 5){
			res += n / i;
		}
		cout << res;
	}
	return 0;
}

Measured memory_bytes: 256
#include <set> 
#include <cstdio>
#include <iostream>
#define N 100010
using namespace std;
set<int> v[N];
pair<int,int> Q[N];
int n,head,tail,fa[N];
int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
int main()
{
	scanf("%d",&n);
	for (int i=1,x,y;i<=n*2-2;i++) 
	{
		scanf("%d%d",&x,&y);
		if (!v[x].count(y)) v[x].insert(y),v[y].insert(x); else Q[tail++]=make_pair(x,y);
	} 
	for (int i=1;i<=n;i++) fa[i]=i;
	while (head<tail)
	{
		int x=find(Q[head].first),y=find(Q[head++].second);
		if (v[x].size()<v[y].size()) swap(x,y);
		for (set<int>::iterator it=v[y].begin();it!=v[y].end();it++) if (*it!=x)
		{
			int l=x,r=*it;
			v[r].erase(y);
			if (!v[l].count(r)) v[l].insert(r),v[r].insert(l); else Q[tail++]=make_pair(l,r);
		}
		v[x].erase(y),fa[y]=x;
	}
	if (tail==n-1) printf("YES"); else printf("NO");
}

Measured memory_bytes: 25472
#include<bits/stdc++.h> 
using namespace std; 
#define x first
#define y second
#define forn(i, n) for(int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;


int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S,T;
	cin>>S>>T;
	int n = S.size();
	int ans =1;
	forn(i,n){
		if(S[i]!=T[i]){
			ans = 0;
			break;
		}
	}
	if(ans){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
 	
	return 0;	
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string l;cin>>l;
  int n=l.length();
  vector<vector<int>> dp(2,vector<int>(n+5,0));
  dp[0][0]=2;
  dp[1][0]=1;
  rep1(i,n-1){
    if(l[i]=='1'){
      dp[0][i]=dp[0][i-1]*2;
      dp[0][i]%=MOD;
      dp[1][i]=dp[1][i-1]*3+dp[0][i-1];
      dp[1][i]%=MOD;
    }
    else{
      dp[0][i]=dp[0][i-1];
      dp[1][i]=dp[1][i-1]*3;
      dp[1][i]%=MOD;
    }
  }
  cout<<(dp[0][n-1]+dp[1][n-1])%MOD<<"\n";
  return 0;
}


Measured memory_bytes: 2816
S = input()

ls = ["WB", "BW"]

cnt = 0
if S[0] == "W":
  i = 0
else:
  i = 1

for j in range(len(S)-1):
  if i == 0 and S[j:j+2] == "WB":
    cnt += 1
    i = 1
  if i == 1 and S[j:j+2] == "BW":
    cnt += 1
    i = 0
    
print(cnt)

Measured memory_bytes: 9136
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
ans = [[0]*w for i in range(h)]
i = 0
j = 0
flag = 0
cnt = 0
for p in range(n):
    color = p+1
    numberofcolor = a[p]
    while numberofcolor >0:

        if j > w-1:
            flag = 1- flag
            j = w-1
            i +=1
            continue
        if j <0:
            flag = 1-flag
            j = 0
            i+=1
            continue
        if i > h-1:break
        numberofcolor -= 1
        ans[i][j] = color
        if flag == 0:j +=1
        else:j-=1
            
for i in range(h):
    print(*ans[i])
        

Measured memory_bytes: 41968
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;

long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD) https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a 3-4参照
}

int main()
{
    /*A
    int n,m;
    cin>>n>>m;
    int count;
    count = (n*(n-1)/2+m*(m-1)/2);
    cout<<count<<endl;
    */

    /*B
    string s;
    cin>>s;
    int n = s.size();
    bool flag = true;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            flag = false;
        }
    }
    
    for(int i=0;i<(n-1)/2;i++)
    {
        if(s[i]!=s[(n-1)/2-(i+1)])
        {
            flag = false;
        }
    }
    for(int i=(n+3)/2;i<n;i++)
    {
        if(s[i]!=s[n-(i+1)])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    int l;
    cin>>l;
    double a;
    a = (double) l/3;

    cout<<setprecision(12)<<a*a*a<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> dishes(M);
  for(int i=0;i<N;i++){
    int K;
    cin>>K;
    for(int j=0;j<K;j++){
      int dish;
      cin>>dish;
      dish--;
      dishes.at(dish)++;
    }
  }
  int ans = 0;
  for(int i=0;i<M;i++){
    if(dishes.at(i)==N){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	int in[40];
	int count = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", in + i);
	}
	for(int i = 0; i < n - 2; i++){
		if(in[i] < in[i + 1]){
			if(in[i + 1] < in[i + 2])count++;
		}else{
			if(in[i + 1] > in[i + 2])count++;
		}
	}
	printf("%d\n", count);
	return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    int a;
    int b;
    int area;
    int length;

    scanf("%d", &a);
    scanf("%d", &b);

    area = a * b;
    length = 2 * a + 2 * b;

    printf("%d %d\n", area, length);

    return 0;
}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, h, m;
  cin >> a >> b >> h >> m;
 
  double c = ((h / 12.0 + m / 60.0 / 12.0 - m / 60.0) * 2 * M_PI);
  cout << fixed << setprecision(20);
  cout << sqrt(a * a + b * b - 2 * a * b * cos(c)) << endl;

  return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int AB = A * B;
  
  if (AB % 2 == 0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  return 0;

}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

    int n;
    cin >> n;

    vector<int> h(n + 1);
    rep(i, n){
        cin >> h[i];
    }

    int dp[100010];
    fill(dp, dp + n, IINF);
    dp[0] = 0;

    rep(i, n - 1){
        chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(int n){
  int ret = 0;
  while(n != 0 && n % 2 == 0){
    if(ret == 2) break;
    ret++;
    n /= 2;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  vector<int> m(3, 0);
  rep(i, n){
    int in;
    cin >> in;
    int co = fc(in);
    m.at(co)++;
  }
  if(m.at(0) > m.at(2)+1){
    cout << "No" << endl;
  }else{
    if(m.at(0) == m.at(2) + 1 && m.at(1) != 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import itertools
h, w, k = map(int, input().split())
bw = []
for i in range(h):
    bw.append(input())
h_list = [i+1 for i in range(h)]
w_list = [i+1 for i in range(w)]

cnt = 0
for m in range(1, h+1):
    for n in range(1, w+1):
        for H in itertools.combinations(h_list, m):
            for B in itertools.combinations(w_list, n):
                a = []
                for hh in H:
                    for bb in B:
                        a += bw[hh-1][bb-1]
                if a.count('#') == k:
                    cnt += 1

print(cnt)

Measured memory_bytes: 9132
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using LL = unsigned long long;
LL gcd(LL a, LL b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
LL lcm(LL a, LL b) {
	LL g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}
int main() {
	int a, b;
	cin >> a >> b;
	a += b;
	cout << a % 24;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
	int flag[1000] = { 0 };
	int N, K; scanf("%d %d", &N, &K);
	while (K--) {
		int d; scanf("%d", &d);
		while (d--) {
			int a; scanf("%d", &a);
			flag[a] = 1;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		cnt += !flag[i];
	}
	printf("%d", cnt);
}

Measured memory_bytes: 3196
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=0
for i in range(n-1,1,-1):
    for j in range(i-1,0,-1):
        t=bisect.bisect_right(a,a[i]-a[j])
        #print(a[i],a[j],a[i]-a[j],t,j-t)
        if j-t>0:
            ans+=j-t
print(ans)
        

Measured memory_bytes: 9276
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        char[] c = br.readLine().toCharArray();

        for(int i=0 ; i<c.length ; i++) c[i] = 'x';

        pw.println(c);
        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 21332
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

MOD = 10 ** 9 + 7

n, k = map(int, input().split())

L = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)

def perm(n, r):
    ret = 1
    for i in range(r):
        ret = (ret * n) % MOD
        n -= 1
        #print(ret, n, r)
    return ret

def func(s, p):
    if len(L[s]) == 1:
        return 1
    ret = perm(k-2, len(L[s])-1)
    for x in L[s]:
        if x == p:
            continue
        ret = (ret * func(x, s)) % MOD
    return ret

ans = perm(k, len(L[0]) + 1)
#print(ans)

for x in L[0]:
    ans = (ans * func(x, 0)) % MOD

print(ans)

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

int main()
{
  int x;
  int h,m,s;

  cin >> x;

  h = x/(60*60);
  m = (x%(60*60))/60;
  s = (x%(60*60))%60;

  cout << h <<":"<< m << ":" << s << endl;

  return 0;
} 

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  int k,s;
  cin >> k >> s;
  int cnt=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if( i+j > s  || ( s - (i+j) ) > k) continue;
      cnt++;
    }
  }
        
  cout << cnt << endl;
        
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	int a;
	cin>>a;
	if(a%2)cout<<a/2+1<<endl;
	else cout<<a/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		char[] c1 = s.toCharArray();
		Arrays.sort(c1);
		
		char[] c2 = t.toCharArray();
		Arrays.sort(c2);
		
		int n = Math.min(c1.length, c2.length);
		String ans = "Yes";
		for (int i = 0; i < n; i++) {
			if (c1[i] > c2[c2.length - 1 - i]) {
				ans = "No";
				break;
			}
			
			if (c1[i] == c2[c2.length - 1 - i]) {
				if (i == n - 1 && c1.length >= c2.length) {
					ans = "No";
				}
				continue;
			}
			if (c1[i] < c2[c2.length - 1 - i]) break;
		}
		
		
		
		System.out.println(ans);
		
	}
}

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

#define X first
#define Y second
#define ll long long
#define MP make_pair
#define PB push_back

using namespace std;

ll niz[100005],n;
ll dp[100005];

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

	cin>>n;
	for(int i=0; i<n; i++){
		cin>>niz[i];
	}
	dp[1]=abs(niz[1]-niz[0]);
	for(int i=2; i<n; i++){
		dp[i]=min(dp[i-2]+abs(niz[i]-niz[i-2]),dp[i-1]+abs(niz[i]-niz[i-1]));
	}
	cout<<dp[n-1];
	
	return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> H >> W;

    vector<vector<char>> arr(H,vector<char>(W));
    vector<vector<char>> brr(W,vector<char>(H));
    vector<bool> Hrr(200);
    vector<bool> Wrr(200);
    char ccc;
    for (int i = 0; i < H; i++) rep(j,W) 
    {
        cin >> ccc;
        arr.at(i).at(j) = ccc;
        brr.at(j).at(i) = ccc;
    }

    rep(i,H)
    {
        if(count(all(arr[i]),'#')==0)Hrr[i]=true;
    }
    rep(i,W)if(count(all(brr[i]),'#')==0)Wrr[i]=true;

    rep(i,H)
    {
        if(Hrr[i])continue;
    rep(j,W)
    {
        if(Wrr[j])continue;
        cout << arr[i][j];
    }
    cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
w = int(raw_input())
n = int(raw_input())
a = []
for i in range(n):
    a.append(map(int, raw_input().split(',')))
r = range(1, w + 1)
for i in a:
    tmp = r[i[0] - 1]
    r[i[0] - 1] = r[i[1] - 1]
    r[i[1] - 1] = tmp
for i in r:
    print i

Measured memory_bytes: 5068
import java.util.Scanner;
import java.util.Stack;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while(n-->0) {
			String s1 = in.next();
			String s2 = in.next();
			if(s1.length()>80||s2.length()>80) {
				System.out.println("overflow");
				continue;
			}
			StringBuffer s = new StringBuffer(s1);
			s1 = s.reverse().toString();
			s = new StringBuffer(s2);
			s2 = s.reverse().toString();
			Stack<Integer> stack = new Stack<>();
			int a=0,b=0;    //每一位上的数字
			int flag=0;    //标记进位
			if(s1.length()<s2.length()) {
				String t = s1;
				s1 = s2;
				s2 = t;
			}
			for(int i=0;i<s1.length();i++) {
				switch(s1.charAt(i)) {
				case '0' : a = 0; break;
				case '1' : a = 1; break;
				case '2' : a = 2; break;
				case '3' : a = 3; break;
				case '4' : a = 4; break;
				case '5' : a = 5; break;
				case '6' : a = 6; break;
				case '7' : a = 7; break;
				case '8' : a = 8; break;
				case '9' : a = 9; break;
				}
				if(s2.length()<=i)
					b=0;
				else {
					switch(s2.charAt(i)) {
					case '0' : b = 0; break;
					case '1' : b = 1; break;
					case '2' : b = 2; break;
					case '3' : b = 3; break;
					case '4' : b = 4; break;
					case '5' : b = 5; break;
					case '6' : b = 6; break;
					case '7' : b = 7; break;
					case '8' : b = 8; break;
					case '9' : b = 9; break;
					}
				}
				if(a+b+flag>9) {
					stack.add(a+b+flag-10);
					flag=1;
				}
				else {
					stack.add(a+b+flag);
					flag = 0;
				}
			}
			if(flag==1)
				stack.add(flag);
			if(stack.size()>80)
				System.out.println("overflow");
			else {
				while(!stack.isEmpty()) {
					int c = stack.pop();
					System.out.print(c);
				}
				System.out.println();
			}
		}
		in.close();
	}
}


Measured memory_bytes: 25876
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(void){
    int a,b;
    char op;
    cin >> a >> op >> b;
    
    while(op != '?'){
        if(op == '+'){
            cout << a+b << endl;
        }
        else if(op == '-'){
            cout << a-b << endl;
        }
        else if(op == '*'){
            cout << a*b << endl;
        }
        else if(op == '/'){
            cout << a/b << endl;
        }
        cin >> a >> op >> b;
    }
}


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	string s ;
	cin>>s ;
	int pref[n], suff[n] ;
	pref[0] = (s[0] == 'W') ;
	for(int i = 1 ; i < n ; ++i)
		pref[i] = pref[i-1] + (s[i] == 'W') ;
	suff[n-1] = (s[n-1] == 'E') ;
	for(int i = n-2 ; i >= 0 ; --i)
		suff[i] = suff[i+1] + (s[i] == 'E') ;
	int ans = 1e9 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i == 0)
			ans = min(ans, suff[i+1]) ;
		else if(i == n-1)
			ans = min(ans , pref[i-1]) ;
		else
			ans = min(ans, pref[i-1] + suff[i+1]) ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 2964
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;
const int _N = 2e5 + 100;

int n,m;
ll k;
string s;

struct BIT{
	int data[_N];
	int n;
	void init(int n){
		this->n = n;
		REP(i, n+1)data[i] = 0;
	}
	void add(int i, int x){
		i++;
		while(i<=n){
			data[i] += x;
			i += i&-i;
		}
	}
	int sum(int i){
		i++;
		int s = 0;
		while(i>=1){
			s += data[i];
			i -= i&-i;
		}
		return s;
	}
};

BIT letters[26];

int main() {
	cin >> s;
	n = s.size();

	ll ans = 1;

	REP(i, 26) letters[i].init(n);
	REP(i, n) letters[s[i]%26].add(i, 1);

	FOR(i, 1, n){
		ans += i-letters[s[i]%26].sum(i-1);
	}

	cout << ans;
	cout << endl;
}


Measured memory_bytes: 20868
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int n, m;
	int a[1000];
	cin >> n;
	//a = (int *)malloc(sizeof(int) * n);
	
	for (int i = 0;i < n;i++){ 
		cin >> m;
		a[i] = m;
	}
	
	for (int i = n-1;i > 0; i--){
		cout << a[i] << " ";
	}
	cout << a[0];
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{
		int N = nextInt();

		dfs(0,N,new char[N]);
	}

	public static void dfs(int n,int N ,char[] ans ){
		if(n==N){
			StringBuffer sb = new StringBuffer();
			sb.append(ans);
			System.out.println(sb.toString());
			return;
		}
		if(n==0){
			ans[n]=(char)('a');
			dfs(n+1,N,ans);
		}else{
			int max=0;
			for(int i=0;i<n;i++){
				max=Math.max(max, ans[i]-'a');
			}
			for(int i=0;i<=max+1;i++){
				ans[n]=(char)('a'+i);
				dfs(n+1,N,ans);
			}
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 41656
A, B, C = map(int, input().split())
maximam = max(A, B, C)
count = (maximam-A)//2 + ( maximam-B)//2 + (maximam-C)//2
A +=((maximam-A)//2*2)
B +=((maximam-B)//2*2)
C +=((maximam-C)//2*2)
if A==B and B == C:
  print(count)
elif (A==B and A==maximam) or (C==B and C==maximam) or (A==C and C==maximam):
  print(count+2)
else:
  print(count+1)

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

int a,b;

int main(){
	scanf("%d%d",&a,&b);
	if(a<=0&&0<=b)puts("Zero");
	else if(a>0)puts("Positive");
	else puts(((b-a)&1)?"Positive":"Negative");
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct TwoSat {
	int N;
	vector<vi> gr;
	vi values; // 0 = false, 1 = true

	TwoSat(int n = 0) : N(n), gr(2*n) {}

	int add_var() { // (optional)
		gr.emplace_back();
		gr.emplace_back();
		return N++;
	}

	void either(int f, int j) {
		f = max(2*f, -1-2*f);
		j = max(2*j, -1-2*j);
		gr[f^1].push_back(j);
		gr[j^1].push_back(f);
	}
	void set_value(int x) { either(x, x); }

	void at_most_one(const vi& li) { // (optional)
		if (sz(li) <= 1) return;
		int cur = ~li[0];
		rep(i,2,sz(li)) {
			int next = add_var();
			either(cur, ~li[i]);
			either(cur, next);
			either(~li[i], next);
			cur = ~next;
		}
		either(cur, ~li[1]);
	}

	vi val, comp, z; int time = 0;
	int dfs(int i) {
		int low = val[i] = ++time, x; z.push_back(i);
		trav(e, gr[i]) if (!comp[e])
			low = min(low, val[e] ?: dfs(e));
		++time;
		if (low == val[i]) do {
			x = z.back(); z.pop_back();
			comp[x] = time;
			if (values[x>>1] == -1)
				values[x>>1] = !(x&1);
		} while (x != i);
		return val[i] = low;
	}

	bool solve() {
		values.assign(N, -1);
		val.assign(2*N, 0); comp = val;
		rep(i,0,2*N) if (!comp[i]) dfs(i);
		rep(i,0,N) if (comp[2*i] == comp[2*i+1]) return 0;
		return 1;
	}
};

const int MAXN = 1.1e4;
int N;
pair<int, int> pts[MAXN*2];

bool isGood(int D) {
	TwoSat ts(N * 3);
	const int Pref = N, Suff = 2 * N;
	for (int i = 0; i < N; i++) {
		ts.either(~pts[i].second, i+Pref);
		if (i > 0 && pts[i].first / D == pts[i-1].first / D) {
			ts.either(~pts[i].second, ~(i-1+Pref));
			ts.either(~(i-1+Pref), i+Pref);
		}
	}
	for (int i = N-1; i >= 0; i--) {
		ts.either(~pts[i].second, i+Suff);
		if (i+1 < N && pts[i].first / D == pts[i+1].first / D) {
			ts.either(~pts[i].second, ~(i+1+Suff));
			ts.either(~(i+1+Suff), i+Suff);
		}
	}
	for (int i = 0, j = 0; i < N; i++) {
		while (j < N && pts[j].first - pts[i].first < D) {
			j++;
		}
		if (j > i && pts[j-1].first / D > pts[i].first / D) {
			ts.either(~(i+Suff), ~(j-1+Pref));
		}
	}
	return ts.solve();
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> pts[2*i].first >> pts[2*i+1].first;
		pts[2*i].second = i;
		pts[2*i+1].second = ~i;
	}
	N *= 2;
	sort(pts, pts + N);

	int mi = 0;
	int ma = int(1e9);
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (isGood(md)) {
			mi = md;
		} else {
			ma = md;
		}
	}
	cout << mi << '\n';

	return 0;
}


Measured memory_bytes: 11180
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define int long long
#define pb push_back
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


const int MAX_n = 100000;
int n,a[3*MAX_n];


int ans;



signed main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);


    scanf("%lld", &n);
    for(int i = 0;i < 3* n;i++){
        scanf("%lld", &a[i]);
    }


    SORTR(a,3* n);

    for(int i = 0;i < n;i++){
        ans += a[2*i+1];
    }

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

    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int msb_(int x) { return 31 - __builtin_clz(x); }
int64_t msb(int64_t x) {
  int64_t y = x>>32;
  if(y == 0) return msb_((int)x);
  return msb_((int)y) + 32;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  int64_t a1, a2; std::cin >> a1 >> a2;
  int64_t sum = 0;
  for(int i = 2; i < N; ++i) {
    int64_t a; std::cin >> a; sum ^= a;
  }
  int64_t tmp = a1^a2^sum;
  if(tmp == 0) fin(0);
  if(tmp&1) fin(-1);
  int64_t an = a1+a2 - sum;
  if(an < 0) fin(-1);
  an /= 2;
  if(an&sum) fin(-1);
  if(an > a1) fin(-1);
  int64_t dif = a1-an;
  int64_t mask = ((int64_t)1<<msb(dif)+1)-1;
  sum &= mask;
  while(sum > dif) {
    int64_t ms = (int64_t)1<<msb(dif);
    dif -= ms;
    sum -= ms;
    int64_t mask = ((int64_t)1<<msb(dif)+1)-1;
    sum &= mask;
  }
  dif -= sum;
  if(dif == a1) fin(-1);
  fin(dif);
  return 0;
}


Measured memory_bytes: 3628
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
l = [(item[0]+item[1], item[0]-item[1]) for item in xy]
l.sort()
v0 = l[-1][0]-l[0][0]
l.sort(key=lambda x: x[1])
v1 = l[-1][1]-l[0][1]
ans = max(v0,v1)
print(ans)

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

using namespace std;

#define MAX_M 20
#define MAX_N 50000

#define INF 100000000

int n, m;

vector<int> c(MAX_M, 0);
vector<int> dp(MAX_N + 1, INF);

int coin_c(int k)
{
	dp[0] = 0;

	for(int i = 1; i <= k; ++i)
	{
		for(int j = 0; j < m; ++j)
		{
			if(i - c[j] >= 0)
			{
				if(dp[i] > dp[i - c[j]] + 1)
				{
					dp[i] = dp[i - c[j]] + 1;
				}
			}
		}
	}

	return dp[n];
}

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

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

	cout << coin_c(n) << endl;

	return 0;
}

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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

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};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

ll f2(int n, int p, string s){
	ll ans=0;
	reverse(all(s));
	rep(i,n){
		if((s[i]-'0')%p==0) ans += (n-i);
	}
	return ans;
}

ll f5(int n, int p, string s){
	ll ans=0;
	reverse(all(s));
	rep(i,n){
		if((s[i]-'0')%p==0) ans += (n-i);
	}
	return ans;
}

ll fp(int n, int p, string s){
	ll ans=0;
	reverse(all(s));
	vector<int> res(n,0);
	rep(i,n){
		res[i] = (s[i]-'0') % p;
	}
	ll ten=10;
	repi(i,1,n){
		res[i] = (res[i]*ten + res[i-1]) % p;
		ten = ten*10 % p;
	}
	map<int, ll>mp;
	rep(i,n){
		mp[res[i]] += 1;
	}

	// rep(i,n){
	// 	int num=res[i];
	// 	ll cnt=mp[num];
	// 	// if(num==0) ans += cnt;
	// 	// else ans += mp[p-num];

	// 	// mp[num] -= 1;
	// }
	mp[0]++;
	rep(i,p) ans += mp[i] * (mp[i]-1)/2;
	return ans;
}

int main()
{
	int n,p;
	string s;
	cin>>n>>p>>s;
	ll ans;
	if(p==2) ans = f2(n,p,s);
	else if(p==5) ans = f5(n,p,s);
	else ans = fp(n,p,s);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2052
n,q = map(int,raw_input().split())
s = raw_input()
dp = [0]*n
for i in xrange(1,n):
  dp[i] = dp[i-1]
  if s[i] == 'C' and s[i-1] == 'A':
    dp[i] += 1
for i in xrange(q):
  l,r = map(int,raw_input().split())
  print dp[r-1] - dp[l-1]

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

using namespace std;

int main(void) {
	int H,W;
	while (cin >> H >> W, H||W) {
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (i == 0||j == 0||i == H-1||j == W-1) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
a = list(input())
b = list(input())
c = list(input())
nex = 'a'
while True: 
    if nex == 'a':
        if len(a) == 0:
            print('A')
            break
        nex = a.pop(0)
    elif nex == 'b':
        if len(b) == 0:
            print('B')
            break
        nex = b.pop(0)
    else:
        if len(c) == 0:
            print('C')
            break
        nex = c.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1; 
    while(t--){
	    int n;
	    cin>>n;
	    vector<int> a(n);
	    for(auto &it : a) cin>>it;
	    int q;
	    cin>>q;
	    int b,c;
	    //ll sum=accumulate(a.begin(),a.end(),0);
	    ll sum=0;
	    for(auto i : a)
		    sum=(ll)sum+i;
	    unordered_map<int,int>mp;
	    for(auto i:a)
		    mp[i]++;
            for(int i=0;i<(int)q;i++){
		    cin>>b>>c;
		    //replace(a.begin(),a.end(),b,c);
		    if(mp.count(b)){
		    sum=(sum-(ll)mp[b]*b+(ll)mp[b]*c);
		   // sum-=1LL*mp[b]*b;
		   // sum+=1LL*mp[b]*c;
		    mp[c]+=mp[b];
		    mp[b]-=mp[b];

		   
		    }
                    cout<<(ll)sum<<endl;
		   //for(auto j : a)
		     //  cout<<j<<" ";
		  //  cout<<<<endl;
	    }

    
    }
    return 0;
} 


Measured memory_bytes: 7256
from itertools import combinations_with_replacement
from collections import defaultdict
N = int(input())

def calc(x: int, y: int, z: int) -> int:
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

f = defaultdict(int)
for x,y,z in combinations_with_replacement(range(1, 100), 3):
    l = len(set([x,y,z]))
    num = calc(x,y,z)
    if l == 1:
        f[num] += 1
    elif l == 2:
        f[num] += 3
    else:
        f[num] += 6

for i in range(1, N+1):
    print(f.get(i, 0))

Measured memory_bytes: 11756
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

int main(void)
{
    std::string n;

    std::cin >> n;

    auto func = [&](){ 
        auto count = 0;
        for (auto i=1; i<n.size(); ++i) {
            if (n.at(i-1) == n.at(i)) {
                count++;
                if (count >= 2) return "Yes";
            } else {
                count = 0;
            }
        }
        return "No";
    };

    std::cout << func() << std::endl;

    return 0;
}

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

void bubbleSort(int numbers[], int array_size)
{
  int i, j, temp;

  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (numbers[j-1] > numbers[j]) {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}

int main(){
  int a,b;
  cin>>a>>b;
  int A[3];
  A[0]=a+b;
  A[1]=a-b;
  A[2]=a*b;
  bubbleSort(A,3);
  cout<<A[2];
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	int a[100];
	int flag;
	int k;

	scanf("%d", &n);
	for(k = 0; k < n; k++){
		scanf("%d", &a[k]);
	}

	flag = 0;
	for (k = 0; k < n; k++) {
		if(a[k] % 2 == 0){
			if(((a[k] % 3 != 0)&&(a[k] % 5 != 0))){ flag = 1; break; }
		}
	}

	if (flag == 0) {
		puts("APPROVED");
	} else {
		puts("DENIED");
	}

	return 0;
}


Measured memory_bytes: 128
using System;
class Program
{
	static void Main(string[] args)
	{
	    int number = int.Parse(Console.ReadLine());
	    string[] order = Console.ReadLine().Split();
	    string[] value = Console.ReadLine().Split();
	    string[] addValue = Console.ReadLine().Split();
	    
	    int result = 0;
	    for (int i = 0; i < number; i++)
	    {
	        int foodNumber = int.Parse(order[i]);
	        result += int.Parse(value[foodNumber - 1]);
	        if (0 < i && foodNumber == int.Parse(order[i - 1]) + 1) 
	        {
	            result += int.Parse(addValue[foodNumber - 2]);
	        }
	    }
	    
	    Console.WriteLine(result);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    for(int i = 0;i< S.size();i++)cout << char((S[i]-'A'+N)%26+'A');
    cout <<endl;

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static char left(String s){
        return s.charAt(0);
    }

   public static char right(String s) {
        return s.charAt(s.length() - 1);
   }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a,b,c;
        a = sc.next();
        b = sc.next();
        c = sc.next();
        boolean ans = (left(b) == right(a)) && (right(b) == left(c));
        if (ans) {
            System.out.println("YES");
        } else{
            System.out.println("NO");
        }

        return;
    }
}




Measured memory_bytes: 23764
#include<stdio.h>

int main(void)
{
    long long n,m;
    long long S,L;
    long long i,k,j;
    scanf("%lld%lld",&n,&m);
    k=m-n-n;
    if(k>0)
    {
        m=m-n-n;
        m=m/4;
        S=n+m;
    }
    else if(k<0)
    {
        S=m/2;
    }
    printf("%lld",S);
    return 0;
}

Measured memory_bytes: 760