akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);

	int n; cin >> n; 
	vector<vector<pair<int,int>>> g(n);
	for(int i=0; i<n-1; ++i){
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		w %= 2;
		g[u].push_back(make_pair(v,w));
		g[v].push_back(make_pair(u,w));
	}

	vector<int> dst(n,0);
	vector<bool> visit(n,0);
	stack<int> st;
	visit[0]=1;
	st.push(0);
	while(!st.empty()){
		int z=st.top();
		st.pop();

		for(auto i : g[z]){
			if(!visit[i.first]){
				visit[i.first]=1;
				dst[i.first]=i.second+dst[z];
				st.push(i.first);
			}
		}
	}

	for(int i : dst) cout << i%2 << endl;
}

Measured memory_bytes: 6912
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val a = sc.nextInt
  val b = sc.nextInt
  val c = sc.nextInt
  val d = sc.nextInt
  if((a+b)>(c+d)){
    println("Left")
  }
  else if((a+b)<(c+d)){
    println("Right")
  }
  else{
    println("Balanced")
  }
}

Measured memory_bytes: 27452
while True:
  N = input()
  if not N:
    break
  l = []
  for i in range(N):
    c1, m1, s1, m2, s2, m3, s3, m4, s4 = map(int, raw_input().split())
    l.append(((m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4), c1))
  l = sorted(l)
  print(l[0][1])
  print(l[1][1])
  print(l[-2][1])

Measured memory_bytes: 4724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong();
			long x = in.nextLong();

			out.println(f(x, n-x) + n);
		}

		long f(long s, long l) {
			long ret = 0;

			if (s > l) {
				long t = s;
				s = l;
				l = t;
			}

			if (s == 0) {
				return l;
			}

			if (l % s == 0) {
				ret += (l / s - 1) * 2 * s + f(s, l % s);
			} else {
				ret += (l / s) * 2 * s + f(s, l % s);
			}

			return ret;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

using namespace std;

int main(){
	string  s,t;
	cin>>s>>t;
	int t1=0;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			t1++;
		}
	}
	cout<<t1<<endl;
}



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

int main(void){
  string s;cin>>s;
  bool f=true,g=false;
  if(s.size()<6)f=false;
  for(int i=0;i<10;++i) if(s.find(i+'0')!=-1)g=true;
  if(!g)f=false;
  g=false;
  for(int i='A';i<='Z';++i) if(s.find(i)!=-1)g=true;
  if(!g)f=false;
  g=false;
  for(int i='a';i<='z';++i) if(s.find(i)!=-1)g=true;
  if(!g)f=false;
  cout<<(f?"VALID":"INVALID")<<endl;
  return 0;
}

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

int main(){

int N,M;
  cin>>N>>M;
  
vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
  
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
  
double sum=0.000;
for(int j=0; j<N; j++)
{sum=sum+vec.at(j);}
  
  double summ=sum/(4*M);
  
 if(vec.at(M-1)>=summ){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while(true){
    C-=B;
    if(C<=0){cout << "Yes" << endl; return 0;}
    A-=D;
    if(A<=0){cout << "No" << endl; return 0;}
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122


int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    rep(i, 1, 101) {
        if (a % i == 0 && b % i == 0) {
            v.push_back(i);
        }
    }

    sort(all(v));
    reverse(all(v));
    cout << v[k - 1] << endl;
    return 0;
}


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

int main(){
	long long N,K;
	cin >> N >> K;
	K++;
	long long loop;
	map<long long,long long> isFirst;
	vector<long long> A(N);
	for(loop=0;loop<N;loop++){
		cin >> A[loop];
	}
	long long now=1,nowtime=1;
	while(isFirst.count(now)==0){
		isFirst[now]=nowtime;
		now=A[now-1];
		nowtime++;
	}
	long long now2=now;
	vector<long long> Loops(nowtime-isFirst[now]);
	for(loop=0;loop<nowtime-isFirst[now];loop++){
		Loops[loop] = now2;
		now2 = A[now2-1];
	}
	K-=(isFirst[now]-1);
	if(K<=0){
		K+=(isFirst[now]-1);
		now=1;
		for(loop=1;loop<K;loop++){
			now=A[now-1];
		}
		cout << now << endl;
	}else{
		K=K%(nowtime-isFirst[now]);
		if(K){
			cout << Loops[K-1] << endl;
		}else{
			cout << Loops[nowtime-isFirst[now]-1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 17548
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n;
    cin >> n;
    if(n%2)cout << n*2 << endl;
    else cout << n << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(a) int((a).size())
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int n;
    cin>>n;
    vector<int>A(n);
    for (auto &e: A) scanf("%d", &e);
    FI(i,0,n-1) A[i] -= i;
    sort(A.begin(), A.end());
    int t = A[n/2];
    LL ans = 0;
    for (auto e: A) ans += abs(t-e);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < ll  int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;

        void solve()
        {
            ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,x,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1,w;
            cin>>n>>m;
            n+=m;
            if(n%2) cout<<"IMPOSSIBLE";
            else cout<<n/2;


        }



        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


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

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}


int shoujun(int a[],int size){
	int i,j;
	for(i=0;i<size-1;i++){
		for(j=i+1;j<size;j++){
			if(a[j] < a[i]){
				return 1;
			}
		}
	}
	return 0;
}


int main(){
	
	int a;
	int b[50];
	int i,j,temp,count =0;
	
	cin  >> a;
	syc(a,2,50);
	
	for(i=0;i<a;i++){
		cin >> b[i];
	}

	if(shoujun(b,a)==0){
			cout << "YES" << endl;
			return 0;
	}
	
	for(i=0;i<a-1;i++){
		for(j=i+1;j<a;j++){
			if(b[j]<b[i]){
				temp=b[i];
				b[i]=b[j];
				b[j]=temp;
				if(shoujun(b,a)==0){
					cout << "YES" << endl;
					return 0;
				}else{
				 temp=b[i];
				 b[i]=b[j];
				 b[j]=temp;	
				}
				
			}
		}
	}
	
	cout << "NO" << endl;
	return 0;	
}


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

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

    int idx = 1;
    rep(i, n) {
        int a;
        cin >> a;
        if (a == idx) idx++;
    }

    if (idx == 1)
        cout << -1 << endl;
    else
        cout << n - (idx - 1) << endl;
    return 0;
}


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

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  int ans = 0;
  double diff = 1ll << 60;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    diff = min(diff, abs(a - (t - h * 0.006)));
    if (abs(a - (t - h * 0.006)) == diff) {
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
	n = int(input())
	dictionary = {}

	for _ in range(n):
		order, code = input().split()
		if order == 'insert':
			dictionary[code] = 1
		elif order == 'find':
			if code in dictionary:
				print('yes')
			else:
				print('no')
		else:
			raise Exception('InputError')

if __name__ == '__main__':
	main()

Measured memory_bytes: 37364
#include <stdio.h>

int main(void){
	int card[52]={0};
	char mark[4]={'S','H','C','D'};
	char c;
	int b;
	int n;
	int i,j;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf(" %c %d",&c,&b);
		for(j=0;j<4;j++){
			if(c == mark[j]) card[j*13+b-1]=1;
		}
	}
	
	for(i=0;i<52;i++){		
		if(card[i] == 0)printf("%c %d\n",mark[i/13],i%13 + 1);
	}
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

long long int getpow(long long int q)
{
	// cout << q << endl;
	if(q == 0) return 1;
	else if(q == 1) return 3;
	else {
		long long int tmp = getpow(q / 2);
		if(q % 2 == 0) return (tmp * tmp) % mod;
		else return ((tmp * tmp) * 3) % mod;
	}
}

int main()
{
	string s;
	cin >> s;
	long long int hatenanum = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == '?') hatenanum++;
	}
	long long int bcnum = 0;
	long long int cnum = 0;
	long long int ans = 0;
	long long int tmp = getpow(mod - 2);
	long long int nowh = hatenanum;
	for(int i = s.length()- 1; i >= 0; i--){
		if(s[i] == 'A'){
			ans += bcnum;
			ans %= mod;
		} else if(s[i] == 'B'){
			bcnum += cnum;
			bcnum %= mod;
		} else if(s[i] == 'C'){
			cnum += getpow(hatenanum);
			cnum %= mod;
		} else {
			nowh--;
			ans += (bcnum * tmp) % mod;
			ans %= mod;
			bcnum += (cnum * tmp) % mod;
			bcnum %= mod;
			cnum += getpow(hatenanum - 1);
			cnum %= mod;
		}
		// cout << ans << " " << hatenanum << " " << bcnum << " " << cnum << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <limits>

#define ll long long

using namespace std;

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

	int n; cin >> n;

	vector<ll> v(n), su(n);

	for (int i = 0; i < n; i++) {
		cin >> v[i];
		su[i] = v[i];
		if (i > 0) su[i] += su[i - 1];
	}

	ll t[4], ans = numeric_limits<ll>::max();

	for (int i = 1; i < n - 1; i++) {
		// [0, i], [i+1, n]
		ll v1 = su[i] / 2, v2 = su[i] + (su[n - 1] - su[i]) / 2;
		auto iter1 = upper_bound(su.begin(), su.begin() + i, v1);
		auto iter2 = upper_bound(su.begin() + i + 1, su.end() - 1, v2);

		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				t[0] = *iter1;
				t[1] = su[i] - t[0];
				t[2] = *iter2 - su[i];
				t[3] = su[n - 1] - *iter2;
				sort(t, t + 4);
				ans = min(ans, t[3] - t[0]);
				iter2--;
			}
			if (iter1 == su.begin()) break;
			iter1--;
			iter2++;
			iter2++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3328
#include<stdio.h>
long int GetGCD(long int temp1,long int temp2);
int main()
{
long int num1,num2,gcd,lcm,x;
scanf("%ld%ld",&num1,&num2);
gcd=GetGCD(num1,num2);
lcm=(num1*num2)/gcd;
printf("%ld\n",lcm);

}
long int GetGCD(long int temp1,long int temp2)
{
 if(temp2!=0) 
{
 GetGCD(temp2,temp1%temp2);
 
}
 else 
{
 return(temp1);
 
}

}




Measured memory_bytes: 128
void main()
{
    long n = rdElem;

    long[] factor = new long[n+1];
    foreach (i; 2 .. n+1)
    {
        long num = i;
        for (long j = 2; j * j <= n; ++j)
        {
            while (num % j == 0)
            {
                num /= j;
                ++factor[j];
            }
        }
        if (num > 1) ++factor[num];
    }

    long[] list = [2, 4, 14, 24, 74];
    long[long] cnt;
    foreach (x; list) cnt[x] = 0;
    foreach (x; factor)
    {
        foreach (y; list)
        {
            if (x >= y) ++cnt[y];
        }
    }

    long result;
    result += cnt[74];
    result += cnt[24] * (cnt[2] - 1);
    result += cnt[14] * (cnt[4] - 1);
    result += ((cnt[4] * (cnt[4] - 1)) >> 1) * (cnt[2] - 2);

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

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

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int X, A;
	cin >> X >> A;
	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Objects;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int x = sc.nextInt();
			String id = "ai1333";
			for(int i=0;i<x/100;i++) {
				id += "3";
			}
			System.out.println(id);
			
			
	
		}
	}
}





Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t
ll ans = -1;

pair<string, ll> dfs(string S, ll cnt){
    if(S.size() == 1){
        return {S, cnt};
    }
    int n1 = S[0]-48;
    int n2 = S[1]-48;

    if(n1+n2 >= 10){
        S[0] = (n1+n2)/10+48;
        S[1] = (n1+n2)%10+48;
        return dfs(S, cnt+1);
    }
    else{
        S[0] = (n1+n2)+48;
        S.erase(S.begin()+1);
        return dfs(S, cnt+1);
    }
    //return res;
}



int main(){
    //テーブルを二つ、０は９と同じ
    ll M; cin >> M;
    vector<vector<pair<string, ll>>> T1(11, vector<pair<string, ll>>(11)); //何になるかと何回変換するか
    for(int i = 1; i <= 9; i++){
        string S; 
        for(int j = 0; j <= 9; j++){
            if(j == 0){
                T1[i][0] = {"", 0};
                continue;
            }
            S += i+48;
            auto p = dfs(S, 0);
            T1[i][j] = dfs(S, 0);
        }
    }
    vector<pair<string, ll>> T2(101);
    for(int i = 0; i < 100; i++){
        string S = to_string(i);
        T2[i] = dfs(S, 0);
    }

    vector<ll> D(M), C(M);

    for(int i = 0; i < M; i++){
        cin >> D[i] >> C[i];
    }
    vector<string> V(M);
    ll ans = 0;

    for(int i = 0; i < M; i++){
        ll d = D[i], c = C[i];
        if(d == 0){
            V[i] = "0";
            ans += c-1;
            continue;
        }
        ll ds = 0;
        ds += (c/9)*(d+9);
        pair<string, ll> p = T1[d][c%9];
        if(c%9 == 0) {
            p.first = T1[d][9].first;
            ds -= (d+9);
            ds += T1[d][9].second;
        }
        ds += p.second;
        ans += ds;
        V[i] = p.first;
    } 


    string T = V[0];
    for(int i = 1; i < M; i++){
        string U = T; U += V[i];
        auto p = T2[stoll(U)];
        T = p.first;
        ans += p.second;

    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
N, M = map(int, input().split())
nums = map(int, input().split())

import heapq

pq = [-1 * x for x in nums]
heapq.heapify(pq)
for _ in range(M):
    x = -heapq.heappop(pq)
    heapq.heappush(pq, -(x//2))

print(-sum(pq))


Measured memory_bytes: 72344
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
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 sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := 0.
	for i := 0; i < n; i++ {
		ans += 1 / fScan()
	}
	fmt.Println(1 / ans)
}


Measured memory_bytes: 1736
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
const int inf=0x3f3f3f3f;
char s[55];
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n-8;i++)printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 128
import java.util.*

fun main(omkar: Array<String>) {
    val jin = Scanner(System.`in`)
    val n = jin.nextInt()
    val m = jin.nextLong()
    val choice2 = LongArray(n + 1)
    choice2[0] = 1L
    for (j in 1..n) {
        choice2[j] = (((2 * j) - 1).toLong() * choice2[j - 1]) % m
    }
    val choice3 = LongArray(n + 1)
    choice3[0] = 1L
    for (j in 1..n) {
        choice3[j] = ((((3 * j) - 1) * ((3 * j) - 2)).toLong() * choice3[j - 1]) % m
    }
    val choose = Array((3 * n) + 1) { LongArray(it + 1) }
    choose[0][0] = 1L
    for (j in 1..3 * n) {
        choose[j][0] = 1L
        choose[j][j] = 1L
        for (k in 1 until j) {
            choose[j][k] = (choose[j - 1][k] + choose[j - 1][k - 1]) % m
        }
    }
    var answer = 0L
    for (b in 0..n) {
        for (c in 0..n - b) {
            var addend = choose[3 * n][2 * b] * choose[(3 * n) - (2 * b)][3 * c]
            addend %= m
            addend *= choice2[b]
            addend %= m
            addend *= choice3[c]
            addend %= m
            answer += addend
            answer %= m
        }
    }
    println(answer)
}

Measured memory_bytes: 190352
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n;
int main() 
{
	FAST
	cin>>n;
	if(__builtin_popcount(n)==1) {
		return cout<<"No\n", 0;
	}
	cout<<"Yes\n";
	for(ll i=2;i+1<=n;i+=2) {
		cout<<1<<' '<<i<<'\n';
		cout<<i<<' '<<i+1<<'\n';
		cout<<1<<' '<<(i+1)+n<<'\n';
		cout<<(i+1)+n<<' '<<i+n<<'\n';
	}
	if((n&1)==0) {
		bool f=0;
		for(ll i=2;i<n;++i) if((n^i) < n) {
			ll other = (n^i)^1;
			assert((i&1) ^ (other&1));
			if(i&1) { // i odd, other even
				cout<<i+n<<' '<<n<<'\n';
				cout<<other<<' '<<n+n<<'\n';
			} else { // i even, other odd
				cout<<i<<' '<<n<<'\n';
				cout<<other+n<<' '<<n+n<<'\n';
			}
			f=1;
			break;
		}
		assert(f);
	}
	cout<<3<<' '<<1+n<<'\n';
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

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


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

int main(){
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

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

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> ms(m);
  std::vector<int> trans = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  std::vector<int> nums(9, 0); // 2, 3, 4, 5, 6, 7
  for (int i = 0; i < m; i++) {
    std::cin >> ms[i];
    nums[trans[ms[i]]] = std::max(ms[i], nums[trans[ms[i]]]);
  }
  sort(ms.begin(), ms.end(), std::greater<int>());
  std::vector<int> table(n + 1, -1);
  table[0] = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = -1;
    for (int j = 1; j < 9; j++) {
      if (nums[j] == 0)
        continue;
      if (i - j >= 0) {
        tmp = std::max(tmp, table[i - j] + 1);
      }
    }
    table[i] = tmp;
  }
  std::string ans = "";
  int cur = n;
  for (int i = 0; i < table[n]; i++) {
    for (auto m : ms) {
      if (cur - trans[m] >= 0 && table[cur - trans[m]] == table[cur] - 1) {
        cur -= trans[m];
        ans += std::to_string(m);
        break;
      }
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <iostream>
#include <algorithm>
#include <vector>
//#include <limits>
#include <math.h>
//#include <queue>
//#include <tuple>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string>
//#include "string.h"
// #include <unordered_map>
#include <map>
#include <unordered_set>
//#include <array>
#include <set>
#include <limits>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2224

using namespace std;

using ll = long long;

#include <vector>

struct UnionFind {
    vector<size_t> parent;
    vector<size_t> rank;
    size_t findParent(size_t x) {
        if (parent[x] == x) {
            return x;
        } else {
            parent[x] = findParent(parent[x]);
            return parent[x];
        }
    }
    explicit UnionFind(size_t size) {
        parent.resize(size);
        rank.resize(size);
        for (size_t i = 0; i < size; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }
    virtual ~UnionFind() {}
    void unite(size_t x, size_t y) {
        size_t px = findParent(x);
        size_t py = findParent(y);
        if (px == py) {
            return;
        }
        if (rank[px] < rank[py]) {
            parent[px] = py;
        } else if (rank[px] > rank[py]) {
            parent[py] = px;
        } else { // rank[px] == rank[py]
            parent[py] = px;
            rank[px]++;
        }
    }
    bool isSame(size_t x, size_t y) {
        return findParent(x) == findParent(y);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    struct Pl {
        int x;
        int y;
        Pl(int x, int y) : x(x), y(y) {}
        double dist(const Pl& rhs) const {
            return sqrt(pow((double)(x - rhs.x), 2.0) + pow((double)(y - rhs.y), 2.0));
        }
    };
    vector<Pl> piles;
    piles.reserve(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        piles.emplace_back(x, y);
    }
    struct Fc {
        int a;
        int b;
        double len;
        Fc(int a, int b, double len) : a(a), b(b), len(len) {}
        static bool compareLen(const Fc& lhs, const Fc& rhs) {
            return lhs.len > rhs.len;
        }
    };
    vector<Fc> fences;
    fences.reserve(M);
    double totalLen = 0.0;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        double len = piles[a].dist(piles[b]);
        fences.emplace_back(a, b, len);
        totalLen += len;
    }
    sort(fences.begin(), fences.end(), Fc::compareLen);
    UnionFind uf(N);
    double lenSum = 0.0;
    for (Fc fc : fences) {
        if (!uf.isSame(fc.a, fc.b)) {
            uf.unite(fc.a, fc.b);
            lenSum += fc.len;
        }
    }
    printf("%.10lf\n", totalLen - lenSum);
    return 0;
}



Measured memory_bytes: 3664
#lang racket

(define (fizzbuzz i)
  (or  (zero? (remainder i 15))
       (zero? (remainder i 5))
       (zero? (remainder i 3))))

(let ([N (read)])
  (define (iter i)
    (if (> i N)
        0
        (+ (if (fizzbuzz i) 0 i) (iter (+ i 1)))))
  (display (iter 1)))


Measured memory_bytes: 147048
from collections import deque
def bfs(tx,ty,kx,ky,d):
    dict = {}
    
    que = deque([(tx,ty,kx,ky,0)])
    while len(que):
        tx,ty,kx,ky,t = que.popleft()
        try:
            if dict[(tx,ty,kx,ky)] <= t:
                continue
        except KeyError:
            dict[(tx,ty,kx,ky)] = t
        
        if tx == kx and ty == ky:
            return t
        t += 1
        if 100 < t:
            break
        que.append((tx if d[ty][tx + 1] else tx + 1,ty,kx if d[ky][kx - 1] else kx - 1,ky,t))
        que.append((tx,ty if d[ty + 1][tx] else ty + 1,kx,ky if d[ky - 1][kx] else ky - 1,t))
        que.append((tx if d[ty][tx - 1] else tx - 1,ty,kx if d[ky][kx + 1] else kx + 1,ky,t))
        que.append((tx,ty if d[ty - 1][tx] else ty - 1,kx,ky if d[ky + 1][kx] else ky + 1,t))
    return 'NA'

import sys
f = sys.stdin

while True:
    x, y = map(int, f.readline().split())
    if x == y == 0:
        break
    tx, ty = map(int, f.readline().split())
    kx, ky = map(int, f.readline().split())
    depart = [[1] * (x + 2)] + [[1] + list(map(int, f.readline().split())) + [1] for i in range(y)] + [[1] * (x + 2)]
    print(bfs(tx,ty,kx,ky,depart))   

Measured memory_bytes: 42944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const bool INF = false;

typedef pair<int,int> P;


int main(){
    int n,keta,first;
    map<P,int> mp;
    cin >> n;
    rrep(i,n){
        int val = i;
        while(val/10>0){
            ++keta;
            val/=10;
        }
        first=i%10;
        // printf("n:%d: (%d,%d)\n",i,val,first);
        ++mp[make_pair(val,first)];
    }
    ll ans=0;
    // for(auto m:mp){
    //     printf("(%d,%d):%d\n",m.first.first,m.first.second,m.second);
    // }
    for(auto m:mp){
        for(auto mm:mp){
            if(m.first.first==mm.first.second &&m.first.second==mm.first.first){
                ans+=m.second*mm.second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
  long long n, a, b;
  scanf("%lld %lld %lld", &n, &a, &b);

  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }

  if (b == 0) {
    cout << n << endl;
    return 0;
  }


  long long base_b_count = a;

  long long r = n / (a + b);
  long long idx = n % (a + b);

  long long b_count = 0;
  b_count = min(a, idx);

  cout << (base_b_count * r) + b_count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     ll X;
     cin >> X;
     ll A = 100;
     ll counter = 0;
     while(A < X){
          A += A/100;
          counter++;
     }
     cout << counter << endl;
     return 0;
}

Measured memory_bytes: 3644
S=input()
a=len(S)

n=0
for i in range(a):
    if i%2==0:
        if S[i]=="R" or S[i]=="U" or S[i]=="D":
            n+=0
        else:
            n+=1
    else:
        if S[i]=="L" or S[i]=="U" or S[i]=="D":
            n+=0
        else:
            n+=1


if n==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def d_robot_arms(N, Pos):
    # 参考: http://drken1215.hatenablog.com/entry/2018/09/30/002900

    pos = []
    # すべての座標でパリティが一致しなければ、条件を満たす腕を選べない
    parity = (abs(Pos[0][0]) + abs(Pos[0][1])) % 2
    for x, y in Pos:
        parity_current = (abs(x) + abs(y)) % 2
        if parity != parity_current:
            return -1
        pos.append([x - y, x + y])
        # u=x-y, v=x+y とすると、 点(u, v)は
        # 原点周りに45度回転させる座標変換によって点(x, y)から移される点

    # log2(10**9)=29.90 なので、2**30以下の2の冪乗を適当に選べば
    # xy平面上の x+y が奇数である任意の座標に到達できる
    arms = [1 << k for k in range(30, -1, -1)]
    if parity % 2 == 0:
        arms.append(1)  # x+yが偶数である座標に到達するときに必要

    # 腕の数, 長さのリストを最初に格納する(任意の入力に対して固定)
    ans_tmp = [str(len(arms)), ' '.join(list(map(str, arms)))]

    for pos_u, pos_v in pos:
        # u, v座標はそれぞれ独立に見て構わない
        usum, vsum = 0, 0
        tmp = ''
        for arm_len in arms:
            if usum <= pos_u:
                udir = 'positive'
                usum += arm_len
            else:
                udir = 'negative'
                usum -= arm_len

            if vsum <= pos_v:
                vdir = 'positive'
                vsum += arm_len
            else:
                vdir = 'negative'
                vsum -= arm_len

            # uv平面で軸と平行にどちら向きに移動するかと
            # xy平面での移動モード(UDLR)との対応
            if udir == 'positive' and vdir == 'positive':
                tmp += 'R'
            elif udir == 'positive' and vdir == 'negative':
                tmp += 'D'
            elif udir == 'negative' and vdir == 'negative':
                tmp += 'L'
            else:
                tmp += 'U'
        ans_tmp.append(''.join(tmp))
    ans = '\n'.join(ans_tmp)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(d_robot_arms(N, Pos))

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] board = new int[3][3];
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                board[i][j] = scanner.nextInt();
            }
        }
        int n = scanner.nextInt();
        for (int i = 0; i < n; ++i) {
            int current = scanner.nextInt();
            for (int k = 0; k < 3; ++k) {
                for (int m = 0; m < 3; ++m) {
                    if (current == board[k][m]) {
                        board[k][m] = 0;
                    }
                }
            }
        }
        for (int i = 0; i < 3; ++i) {
            if (board[i][0] == 0 && board[i][1] == 0 && board[i][2] == 0) {
                System.out.println("Yes");
                return;
            }
        }
        for (int i = 0; i < 3; ++i) {
            if (board[0][i] == 0 && board[1][i] == 0 && board[2][i] == 0) {
                System.out.println("Yes");
                return;
            }
        }
        if (board[0][0] == 0 && board[1][1] == 0 && board[2][2] == 0) {
            System.out.println("Yes");
            return;
        }
        if (board[0][2] == 0 && board[1][1] == 0 && board[2][0] == 0) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

void trace(int A[], int N)
{
  int i;
  for(i = 0; i < N; i++)
  {
    if(i > 0){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionsort(int A[],int N)
{
  int i,j,v;
  for(i = 1; i < N; i++)
  {
    v = A[i];
    j = i - 1;
    while(j >= 0 && v < A[j])
    {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A,N);
  }
}

int main(void)
{
  int N,i,j;
  int A[100];
  
  scanf("%d",&N);
  
  for(i = 0; i < N; i++)
  {
    scanf("%d",&A[i]);
  }
  
  trace(A,N);
  insertionsort(A,N);

  return 0;
}

Measured memory_bytes: 604
# -*- coding:utf-8 -*-
A, B = map(int, input().split())

if B == 1:
    print(0)
    exit(0)

if B < A:
    print(1)
    exit(0)

remain = B - A
count = remain // (A-1)
mod = remain % (A-1)
if not mod == 0:
    count += 1
count += 1
print(count)


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

const int N = 2e5+5;
int n, a[N];

ll c(ll mid) {
    ll under = 0, over = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= mid) under += mid-a[i];
        else over += a[i]-mid;
    }
    return over + under;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(a,a+n);
    int mid = a[n/2];
    cout << c(mid) << '\n';
}



Measured memory_bytes: 1024
#include <stdio.h>

#define N 100001

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[N];

int main(){
  int n, i, j, buf;
  int id, degree, depth[N];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = N;
    T[i].right = N;
    depth[i] = 0;
  }
  
  for(i = 0; i < n; i++){
    scanf("%d%d", &id, &degree);
    
    if(degree == 1){
      scanf("%d",&T[id].left);
      buf = T[id].left;
      T[buf].parent = id;
    }
    else if(degree > 1){
      scanf("%d",&T[id].left);
      buf = T[id].left;
      for(j = 1; j < degree; j++){
	scanf("%d", &T[buf].right);
	T[buf].parent = id;
	buf = T[buf].right;
      }
      T[buf].parent = id;
    }
  }
  
  for(i = 0; i < n; i++){
    buf = T[i].parent;
      while(1){
	if(buf == -1) break;
	else {
	  buf = T[buf].parent;
	  depth[i]++;
	}
      }
    printf("node %d: parent = %d, depth = %d,", i, T[i].parent, depth[i]);
    
    if(T[i].parent == -1){
      if(T[i].left == N) printf(" root, []\n");
      else{
      printf(" root, [%d", T[i].left);
      buf = T[i].left;
      while(T[buf].right != N){
	printf(", %d", T[buf].right);
	buf = T[buf].right;
      }
      printf("]\n");
      }
    }
    else if(T[i].left == N)
      printf(" leaf, []\n");
    else{
      printf(" internal node, [%d", T[i].left);
      buf = T[i].left;
      while(T[buf].right != N){
	printf(", %d", T[buf].right);
	buf = T[buf].right;
      }
      printf("]\n");
    }
  }
  return 0;
}

Measured memory_bytes: 2172
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int x, y, z;
  scanf("%d%d%d", &x, &y, &z);
  int ans = 1;
  x -= y+2*z;
  ans += x/(y+z);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s;
    cin >> t;

    int slen = s.length();
    s = '#' + s + s;
    int nxt[s.length()][26];
    for (int i = 0; i < 26; i++) {
        nxt[s.length()-1][i] = -1;
    }
    for (int i = s.length() - 2; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            nxt[i][j] = nxt[i+1][j];
        }
        nxt[i][s[i+1]-'a'] = i + 1;
    }

    long long ans = 0;
    for (int i = 0; i < t.length(); i++) {
        int c = nxt[ans%slen][t[i]-'a'];
        if (c == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans += c - (ans % slen);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 20972
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

char s;
int cnt[26];

int main(){

  while(cin >> s){
    s = tolower(s);
    if(s >= 'a' && s <= 'z')
      cnt[(int)(s - 'a')]++;
  }

  for (int i = 0; i < 26; i++) {
    cout << (char)(i + 'a') << " : " << cnt[i] << endl;
  }
}

Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vi h(n);
	rep(i, n) cin >> h[i];

	vi dp(n);
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; i++) {
		dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
	}
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
ARGF.each_line do |line|
  a, b, c, d, e, f = line.split.map(&:to_f)

  if a == 0
    y = c / b
    x = (f - e * y) / d
  elsif b == 0
    x = c / a
    y = (f - d * x) / e
  elsif d == 0
    y = f / e
    x = (c - b * y) / a
  elsif e == 0
    x = f / d
    y = (c - a * x) / b
  end

  unless x || y
    y = ((c / a) - (f / d)) / ((b / a) - (e / d))
    x = (c - b * y) / a
  end

  puts "#{'%1.3f' % x.round(3)} #{'%1.3f' % y.round(3)}"
end

Measured memory_bytes: 8872
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    string t;
    cin >> t;
    int n = 0;
    int s = 0;
    int e = 0;
    int w = 0;
    REP(i,t.size()){
        if(t[i] == 'N'){
            n++;
        }
        else if(t[i] == 'W'){
            w++;
        }
        else if(t[i] == 'S'){
            s++;
        }
        else{
            e++;
        }
    }
    bool ans = true;
    if(n != 0 && s == 0 || n == 0 && s != 0){
        ans = false;
    }
    if(e != 0 && w == 0 || e == 0 && w != 0){
        ans = false;
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
n=int(input())
ans=0
v=[[0 for i in range(9)] for j in range(9)]
for i in range(1,n+1):
  s=str(i)
  a,b=int(s[0]),i%10
  if a*b!=0:
    v[a-1][b-1]+=1

for i in range(9):
  for j in range(9):
    x=v[i][j]
    y=v[j][i]
    ans+=x*y



print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, M, X, Y, x, y;
    cin >> N >> M >> X >> Y;
    int xmax = X, ymin = Y;
    REP(i, N) {
        cin >> x;
        amax(xmax, x);
    }
    REP(i, M) {
        cin >> y;
        amin(ymin, y);
    }
    if (xmax < ymin) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
}


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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<ll, ll>

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
#endif

    ll n, m; in >> n >> m;
    ll r = 0;

    ll t1 = min(n, m/2);
    n -= t1;
    m -= t1*2;
    r += t1;

    r += m/4;

    out << r << endl;

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  int zero = 0;
  int ichi = 0;
  
  for(int i = 0;i < s.size();i ++){
    if(s[i] == '0')zero ++;
    else ichi ++;
  }
  
  cout << min(zero,ichi) * 2 << endl;
}

Measured memory_bytes: 3752