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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		if(a.equals(b)) {
			System.out.println("H");
		} else {
			System.out.println("D");
		}
		scan.close();

	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod

int f(int x){
    if(x % 4 == 0) return x;
    if(x % 4 == 1) return 1;
    if(x % 4 == 2) return x ^ 1;
    if(x % 4 == 3) return 0;
}

signed main(){

    int A, B; cin >> A >> B;
    cout << (f(A) ^ f(B) ^ A) << endl;

    return 0;
}


Measured memory_bytes: 256
import static java.lang.Math.max;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Locale;
import java.util.Scanner;

public class Main {

	final static int INF = Integer.MAX_VALUE;

	public static void main(String[] args) {
		Locale.setDefault(Locale.ENGLISH);
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		solve(in, System.out);
		in.close();
	}

	protected static void solve(Scanner in, PrintStream out) {
		int n = in.nextInt();
		int w = in.nextInt();
		int[] a = new int[n];
		int[] wt = new int[n];
		for (int j = 0; j < n; j++) {
			wt[j] = in.nextInt();
			a[j] = in.nextInt();
		}
		long ret = solveLine(n, w, a, wt);
		out.printf(Locale.ENGLISH, "%s%n", ret);
	}

	private static long solveLine(int n, int w, int[] v, int[] wt) {
		long[][] dp = new long[n + 1][w + 1];
		for (int i = wt[0]; i <= w; i++) {
			dp[0][i] = v[0];
		}
		for (int i = 1; i < n; i++) {
			for (int j = 1; j <= w; j++) {
				dp[i][j] = j < wt[i] ? dp[i - 1][j] : max(dp[i - 1][j], dp[i - 1][j - wt[i]] + v[i]);
			}
		}
		return dp[n - 1][w];
	}

}

Measured memory_bytes: 126932
import sys
from collections import deque

readline = sys.stdin.readline
N, M = map(int, readline().split())
G = [[] for _ in range(N)]
E = [0] * N
for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    G[a].append(b)
    E[a] += 1
    G[b].append(a)
    E[b] += 1
pre = [[] for _ in range(N-1)]
visited = [-1] * N
L = []
q = deque([0])
visited[0] = 0
while q:
    x = q.popleft()
    for a in G[x]:
        if visited[a] == -1:
            visited[a] = x+1
            q.append(a)
if -1 in visited:
    print('No')
else:
    print('Yes')
    print(*visited[1:], sep='\n')


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

int main() {
    int N;
    cin >> N;
    string str;
    int ans=0;
    for(int i=1; i<N+1; i++){
        str=to_string(i);
        if(str.size()%2==1) ans++;
    }
    cout << ans << endl;
    
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x 
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/11  Problem: N18_e  / Link:   ----- */
/* ------問題------

N 軒のホテルが一直線上に並んでいます。i (1≤i≤N) 番目のホテルは、座標 xi に位置しています。
旅行者である高橋君には、次の 2 つの信念があります。
高橋君の 1 日の移動距離は L を超えない。
高橋君は野宿をしない。すなわち、1 日の終わりには必ずいずれかのホテルにいなければならない。
Q 個のクエリが与えられます。j (1≤j≤Q) 番目のクエリとして、異なる 2 つの整数 aj, bj が与えられます。 
各クエリについて、前述の信念をともに守った上で、高橋君が aj 番目のホテルから bj 番目のホテルに移動するために必要な最小日数を求めてください。 
なお、高橋君が aj 番目のホテルから bj 番目のホテルに移動できることは保証されます。

-----問題ここまで----- */
/* -----解説等-----

ダブリングのコツ
これも半開区間にするとよい
はじっこがめんどくさいので、半開区間
結局移動できるということを利用する
おかづきさんに見てもらって直したけど
もういっかい自分でやった方がよさそう。

----解説ここまで---- */

LL N, L, Q;
LL ans = 0LL;
LL dist[100005][31];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N;
	VL x(N, 0);
	FOR(i, 0, N) {
		cin >> x[i];
	}
	FOR(i, 0, 100005)FOR(j, 0, 31)dist[i][j] = -1;
	cin >> L >> Q;
	FOR(i, 0, N) {
		int id = upper_bound(ALL(x), x[i] + L) - x.begin();
		id--;

		dist[i][0] = i;
		dist[i][1] = id;
	}
	// ->だけつくる 2^(i-1)回の移動
	FOR(i, 1, 30) {
		FOR(j, 0, N) {
			dist[j][i + 1] = dist[dist[j][i]][i];
		}
	}

	FOR(i, 0, Q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a > b)swap(a, b);
		ans = 0;
		int pos = a;

		while (pos < b) {
			FOR(k, 2, 30) {
				if (b<=dist[pos][k]) {
					ans += 1 << (k-2);
					pos = dist[pos][k - 1];
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

typedef long long ll;
const int N = 2e5 + 10;
char s[N];
int cnt[10010];
int n, p;

int main()
{
	scanf("%d%d%s", &n, &p, s + 1);
	if(p == 2 || p == 5) {
		ll res = 0;
		for(int i = 1; i <= n; i++) {
			int v = s[i] - '0';
			if(v % p == 0) res += i;
		}
		
		return 0 * printf("%lld\n", res);
	}
	
	cnt[0] = 1;
	ll j = 1, now = 0, res = 0;
	for(int i = n; i >= 1; i--) {
		int v = s[i] - '0';
		now = (now + j * v) % p;
		res += cnt[now];
		cnt[now]++;
		j = j * 10 % p;
	}
	
	printf("%lld\n", res);
	
	return 0;
}

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

#define BUF_SIZE 1024

struct Node{
    int data;
    Node *prev;
    Node *next;
};

class List{
private:
    Node *start;
    
public:
    List(){
        start = new Node();
        start->data = 0;
        start->prev = start;
        start->next = start;
    };
    ~List(){
        Node *tmp1 = start->next;
        Node *tmp2;
        while(tmp1 != start){
            tmp2 = tmp1->next;
            delete tmp1;
            tmp1 = tmp2;
        }
        delete start;
    };
    void insertx(int x){
        Node *tmp = start->next;
        start->next = new Node();
        start->next->data = x;
        start->next->prev = start;
        start->next->next = tmp;
        tmp->prev = start->next;
    };
    void deletex(int x){
        Node *tmp = start->next;
        while(tmp != start && tmp->data != x){
            tmp = tmp->next;
        }
        if(tmp != start){
            tmp->next->prev = tmp->prev;
            tmp->prev->next = tmp->next;
            delete tmp;
        }
    };
    void deleteFirst(){
        Node *tmp = start->next;
        start->next = start->next->next;
        start->next->prev = start;
        delete tmp;
    };
    void deleteLast(){
        Node *tmp = start->prev;
        start->prev = start->prev->prev;
        start->prev->next = start;
        delete tmp;
    };
    void print(){
        Node *tmp = start->next;
        while(tmp != start){
            printf("%d", tmp->data);
            tmp = tmp->next;
            if(tmp != start)
                printf(" ");
        }
        printf("\n");
    }
};

int main(void){
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf, BUF_SIZE, stdin));
    List list;
    for(int i = 0; i < n; ++i){
        fgets(buf, BUF_SIZE, stdin);
        if(buf[6] == 'F')
            list.deleteFirst();
        else if(buf[6] == 'L')
            list.deleteLast();
        else{
            int x = 0;
            for(int j = 0; buf[j] != '\0'; ++j)
                if(buf[j] >= '0' && buf[j] <= '9')
                    x = 10 * x + (buf[j] - '0');
            if(buf[0] == 'i')
                list.insertx(x);
            else
                list.deletex(x);
        }
    }
    list.print();
    return 0;
}

Measured memory_bytes: 34420
n=int(input())
s=input()
ans=0
for i in range(n-1):
    ls=set(s[0:i+1])
    rs=set(s[i+1:n])
    cnt=0
    for l in ls:
        if l in rs:
            cnt+=1
    ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll a[135];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<ll>v;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout<<v[n/2]-v[n/2-1]<<endl;
    return 0;
    }


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	bool fl = true;
	ll ans = 0;
	while(fl){
		fl = false;
		for(int i=0;i<n;i++){
			if( a[i] >= n){
				ll cnt = a[i]/n;
				ans += cnt;
				a[i]=a[i]%n;
				for(int j=0;j<n;j++){
					if(i!=j)a[j]+=cnt;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(a[i]>=n)fl =true;
		}
	}
	cout<<ans<<endl;
}

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

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            int n = Integer.parseInt(reader.readLine());
            if (n == 0) {
                break;
            }
            long result = Long.MIN_VALUE;
            long partialSum = 0;
            for (int i = 0; i < n; i++) {
                int a = Integer.parseInt(reader.readLine());
                partialSum = Math.max(a, partialSum + a);
                result = Math.max(partialSum, result);
            }
            out.println(result);
        }
    }
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep2(i,a,n) for(int i = (a);i < (n);i++)
#define rep(i,n) rep2(i,0,n)
#define INF (1LL << 60)
#define vec vector

int a[100];
int n;
int memo[100][100];

int main(void){
    cin >> n;
    rep(i,n)cin >> a[i];
    
    ll ans = 1000;
    
    for(int i = n-1;i >= 0;i--){
        for(int j = i-1;j >= 0;j--){
            if(a[i] > a[j]){
                memo[i][j] = 1;
                break;
            }
        }
    }
    
    for(int i = 0;i < n;i++){
        for(int j = i;j < n;j++){
            if(memo[j][i] == 1){
                ll katta = ans / a[i];
                ans += katta * a[j];
                ans -= katta * a[i];
                i = j;
                //cout << a[j] << " " << a[i] << endl;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k,q; cin>>n>>k>>q;
	vector<int> v(n,0);
	int t;
	For(i,0,q-1){
		cin>>t;
		v[t-1]++;
	}
	For(i,0,n-1){
		if(q-v[i]>=k) cout<<"No\n";
		else cout<<"Yes\n";
	}
	return 0;
}





























Measured memory_bytes: 1408
#include<stdio.h>

int main(){
	int i;
	int n;
	int a[10000];
	
	int min=1000001;
	int max=-1000001;
	long long sum=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		a[i]=0;
		scanf("%d",&a[i]);
		if(a[i] < min) min=a[i];
		if(a[i] > max) max=a[i];
		sum+=a[i];
	}
	
	printf("%d %d %lld\n",min,max,sum);
	
	return 0;
}

Measured memory_bytes: 640
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

vector<pair<int, string>> inputs[2000];

void output(int now, int itr) {
	for (auto x : inputs[now]) {
		REP(q, itr) {
			cout << ".";
		}
		cout << x.second << endl;
		output(x.first, itr + 1);
	}
}

void solve() {
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		string s;
		cin >> s;
		inputs[a].push_back(mp(i + 1, s));
	}
	output(0, 0);
}

#undef int
int main() {
	init();
	solve();
}


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

int bubbleSort(int A[], int N, int count);

int main() {
	int N; //??°????????????
	int A[100]; //??°???
	int count; //???????????????????????°
	count = 0;

	//??\???
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	//?¨????
	count = bubbleSort(A, N, count);

	//??????
	for (int i = 0; i < N; i++) {
		if (i > 0) { cout << " "; }
		cout << A[i];
	}
	cout << endl;
	cout << count << endl;

	return 0;
}

int bubbleSort(int A[], int N, int count) {
	bool flag;
	flag = true;

	while (flag) {
		flag = false;
		for (int j = N - 1; j > 0; j--) {
			if (A[j-1] > A[j]) {
				flag = true;
				int temp = A[j - 1];
				A[j - 1] = A[j];
				A[j] = temp;

				count++;
			}
		}
	}

	return count;
}

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

int main() {
    string N;
    cin >> N;
    for (int i = 0; i < N.size(); i++) {
        if (N.at(i) == '7') {
            cout << "Yes" << endl;
            return(0);
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
	#define ll long long
	#define vi vector<int>
	#define vll vector<ll>
	#define F first
	#define S second
	#define pb push_back
	#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
	#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	using namespace std;
	void solve()
	{
		int n;cin>>n;
		int cnt=0,f=0;
		f(i,0,n-1){
			int u,v;cin>>u>>v;
			if(u==v){
				++cnt;
			}
			else{
				if(cnt>=3)f=1;
				cnt=0;
			}
		}
		if(cnt>=3)f=1;
		if(f)cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	int main()
	{	Fast;
	//	int t;cin>>t;
	//	while(t--)
		solve();
	}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>

using namespace std;

int tizu[52][52];

void check(int i, int j) {
	tizu[i][j] = 0;
	for (int k = -1; k <= 1; k++) {
		for (int l = -1; l <= 1; l++) {
			if (tizu[i+k][j+l] == 1) {
				check(i+k,j+l);
			}
		}
	}
	return;
}

int main() {
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0) {
			break;
		}
		for (int i = 0; i < 52; i++) {
			for (int j = 0; j < 52; j++) {
				tizu[i][j] = 0;
			}
		}
		int counter = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> tizu[i][j];
			}
		}
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (tizu[i][j] == 1) {
					counter++;
					check(i,j);
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1312
#include <stdio.h>

int calcula(int n, int i){
        if(i == 0){
                return 1;
        }
        else{
        return n*calcula(n, --i);
        }
}

int main(){
        int N;
        scanf("%d", &N);
        int resultado = calcula(N, 3);
        printf("%d\n", resultado);
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==5&&a[1]==5&&a[2]==7){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 998244353
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;

int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}

int main()
{
	tint a, b, c, d;
	cin >> a >> b >> c >> d;
	
	vvi dp(c+1, vi(d+1, 0));
	dp[a][b] = 1;
	for(int i = a; i <= c; i++) {
		for(int j = b; j <= d; j++) {
			if(i >= a) {
				dp[i][j] += (j*dp[i-1][j])%MOD;
				dp[i][j] %= MOD;
			}
			if(j >= b) {
				dp[i][j] += (i*dp[i][j-1])%MOD;
				dp[i][j] %= MOD;
			}
			if(i >= a && j >= b) {
				dp[i][j] += MOD - ((i-1)*(j-1)*dp[i-1][j-1])%MOD;
				dp[i][j] %= MOD;
			}
		}
	}
	
	cout << dp[c][d] << endl;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,a; cin>>n>>a;
	n%=500;
	cout << (n<=a ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,l=map(int,input().split())
    T=[int(input()) for _ in range(n)]
    import math,cmath
    pi=math.acos(-1)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=cmath.rect(1,(T[i]+T[j])*pi/l)*(n-(j-i+1))
            ans+=-cmath.rect(1,(T[i]+T[j])*pi/l)*(j-i-1)
    ans/=n*(n-1)*(n-2)/6
    print(ans.real,ans.imag)
resolve()

Measured memory_bytes: 42556
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string ans;
	for (int i = 0; i < (int)s.length(); ++i) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;
	return 0;
}


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

int A[550];

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    for (int i = 0; i < n; i++) {
        cout << "node " << i + 1;
        cout << ": key = " << A[i] << ", ";
        if (i) cout << "parent key = " << A[(i - 1) / 2] << ", ";
        if (A[2 * i + 1]) cout << "left key = " << A[2 * i + 1] << ", ";
        if (A[2 * i + 2]) cout << "right key = " << A[2 * i + 2] << ", ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner

fun main(args:Array<String>){
    val sc=Scanner(System.`in`)

    var n=sc.nextInt()
    var m=sc.nextInt()
    var x=sc.nextInt()
    var y=sc.nextInt()
    var xi=IntArray(n+1)
    var yi=IntArray(m+1)

    for (i in 0 until n){
        xi[i]=sc.nextInt()
    }
    xi[n]=x

    for (l in 0 until m){
        yi[l]=sc.nextInt()
    }
    yi[m]=y

    xi.sort()
    yi.sort()

    println(if (xi[n]>=yi[0]) "War" else "No War")
}

Measured memory_bytes: 34240
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    ll n; cin>>n;
    ll x = 26;
    string ans = "a";
    while (n>x) {
        n-=x;
        x*=26;
        ans += 'a';
    }
    n--;
    int i = ans.size()-1;
    while (n) {
        ans[i] += n % 26;
        n/=26;
        i--;
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> A, rui;

	cin >> N;
	A.resize(N);
	rui.resize(N+1, 0);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		rui[i+1] = rui[i] + A[i];
	}

	llong ret = inf;
	for (int i = 1; i < N; ++i) {
		llong left = rui[i];
		llong right = rui[N] - rui[i];

		llong diff = abs(left - right);
		ret = min(ret, diff);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(N);
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum+=A[i];
    }
    sort(A.rbegin(),A.rend());
    for(int i = 0; i < M; i++) {
        if(A[i]*4*M < sum) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int a[200005]={0};
	int n=s.size();
	int i, j;
	for (i=0; i<n;)
	{
		if (s[i]=='R')
		{
			j=0;
			while (s[i+j]=='R')
			{
				j++;
			}
			int k=i+j;
			while (j)
			{
				if (j%2)
				{
					a[k-1]++;
				}
				else
				{
					a[k]++;
				}
				j--;
			}
			i=k+1;
		}
		else
		{
			i++;
		}
	}
	for (int i=n-1; i>=0;)
	{
		if (s[i]=='L')
		{
			j=0;
			while (s[i-j]=='L')
			{
				j++;
			}
			int k=i-j;
			while (j)
			{
				if (j%2)
				{
					a[k+1]++;
				}
				else
				{
					a[k]++;
				}
				j--;
			}
			i=k-1;
		}
		else
		{
			i--;
		}
	}
	cout << a[0];
	for (i=1; i<n; i++)
	{
		cout << " " << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define el_cucuy ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e6 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, k, w[mxn], c[mxn], dp[mxn], sum = 0;

int main(){
    el_cucuy
    cin >> n >> k;
    for (int i = 1; i <= n; i ++){
        cin >> w[i] >> c[i];
        sum += c[i];
    }for (int i = 1; i <= sum; i ++) dp[i] = inf;
    for (int i = 1; i <= n; i ++){
        for (int j = sum; j >= c[i]; j --){
            dp[j] = min(dp[j], dp[j - c[i]] + w[i]);
        }
    }for (int i = sum; i >= 0; i --){
        if(dp[i] <= k){
            cout << i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 5120
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (str (read-line))
         (s (make-array n :element-type 'bit :initial-element 0))
         (cumul0 (make-array (+ 1 n) :element-type 'uint32 :initial-element 0))
         (cumul1 (make-array (+ 1 n) :element-type 'uint32 :initial-element 0)))
    (dotimes (i n) (setf (aref s i) (if (char= (char str i) #\.) 0 1)))
    (dotimes (i n)
      (setf (aref cumul0 (+ i 1))
            (+ (aref cumul0 i)
               (if (= 0 (aref s i)) 1 0)))
      (setf (aref cumul1 (+ i 1))
            (+ (aref cumul1 i)
               (if (= 1 (aref s i)) 1 0))))
    (println
     (loop for mid to n
           for prefix1 = (aref cumul1 mid)
           for suffix0 = (- (aref cumul0 n) (aref cumul0 mid))
           minimize (+ prefix1 suffix0)))))

#-swank(main)


Measured memory_bytes: 26340
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	long N;
	long count = 0;

	Main(BufferedReader in) throws IOException {
		N = Long.parseLong(in.readLine());
	}

	long count(long a) {
		long mod = N % a;
		long val = N - mod;
		if (mod > 0) {
			return val / a;
		} else {
			return val / a - 1L;
		}
	}

	void calc() {
		for (long a = 1L; a <= N; ++a) {
			count += count(a);
		}
		System.out.println(count);
	}

	void showResult() {
	}
}


Measured memory_bytes: 25700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	lint N, K;
	cin >> N >> K;
	vector<P>ab(N);
	rep(i, N) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab);
	int cnt = 0;
	while (K > 0) {
		K -= ab[cnt].second;
		cnt++;
	}
	cout << ab[cnt-1].first << endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  ll mod=998244353;
  ll n,k;
  cin>>n>>k;
  vector<vector<ll>>lr(k,vector<ll>(2));
  for(ll i=0;i<k;i++)
    cin>>lr[i][0]>>lr[i][1];
  vector<ll>dp(300000);
  vector<ll>sum(300000);
  dp[1]=1;
  sum[1]=1;
  for(ll i=2;i<=n;i++){
    for(ll j=0;j<k;j++){
        ll l=lr[j][0];
        ll r=lr[j][1];
        if(i-l>=0){
          dp[i]+=sum[i-l];
        }
        if(i-r>0){
          dp[i]-=sum[i-r-1];
        }
        dp[i]%=mod;
        if(dp[i]<0)
          dp[i]+=mod;
        sum[i]=sum[i-1]+dp[i];
        sum[i]%=mod;
      }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 8004
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <ctime>
#include <set>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <cmath>

#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define iloop(a,b) for(ll i = a; i < b; ++i)
#define jloop(a,b) for(ll j = a; j < b; ++j)
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)

using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 

char arr[2][60];
void solve()
{
	int n;
	cin >> n;
	iloop(0,2)
	{
		jloop(0,n)
		{
			cin >> arr[i][j];
		}
	}
	//prev = 1 for vertical ans 2 for horizontal
	int prev = -1;
	ll ans = 1;
	iloop(0,n)
	{
		if(arr[0][i] == arr[1][i])
		{
			if(prev == -1)
			{
				ans = ans*3;
			}
			else if(prev == 1)
			{
				ans = ans*2;
			}
			else if(prev == 2)
			{
				ans = ans*1;
			}
			prev = 1;
		}
		else
		{
			if(prev == -1)
			{
				ans = ans*3;
				ans = ans*2;
			}
			else if(prev == 1)	
			{
				ans = ans*2;
			}
			else if(prev == 2)
			{
				ans = ans*3;
			}
			i++;
			prev = 2;
		}
		ans = ans%MOD;
	}
	p(ans)
}
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
} 

Measured memory_bytes: 256
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8");

const inputs = input.split("\n");
const N = Number(inputs[0]);
const arr = inputs[1]
  .trim()
  .split(" ")
  .map(Number);

const main = (N, arr) => {
  let answer = [];
  let ballNum = 0;

  let ai;
  let box = new Array(N).fill(0);
  for (let i = arr.length - 1; i >= 0; i--) {
    // 大きい箱から順番に取り出す
    ai = arr[i];

    let sum = 0,
      j = i + 1;
    while (j + i + 1 <= N) {
      // iを加算していき、Nを超えるまで中のaiを加算し続ける。
      sum += box[j + i];
      j += i + 1;
    }
    // 結果をもとに、箱にたまを入れるかを決定する
    if (sum % 2 == ai) {
      // ボールを入れない
    } else if ((sum + 1) % 2 == ai) {
      // ボールを入れる
      ballNum++;
      answer.push(i + 1);
      box[i]++;
    } else {
      return -1;
    }
  }
  answer = answer.reverse();
  // 回答用の配列に格納
  if (ballNum == 0) {
    return 0;
  } else {
    return `${ballNum}
${answer.join(" ")}`;
  }
};
console.log(main(N, arr));

Measured memory_bytes: 29064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
  int N;
  cin >> N;
  int ans = 0;
  int a, b;
  cin >> a;
  ans += a;
  rep(i, N - 1)
  {
    cin >> b;
    int dif = b - a;
    if (dif > 0)
      ans += dif;
    a = b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;


int main() {
	int e, y; cin >> e >> y;

	if (e == 0) {
		string s; int n;
		if (1868 <= y && y <= 1911)s = "M", n = y - 1867;
		if (1912 <= y && y <= 1925)s = "T", n = y - 1911;
		if (1926 <= y && y <= 1988)s = "S", n = y - 1925;
		if (1989 <= y && y <= 2016)s = "H", n = y - 1988;
		cout << s << n << endl;
	}
	else {
		int n;
		if (e == 1)n = 1867 + y;
		if (e == 2)n = 1911 + y;
		if (e == 3)n = 1925 + y;
		if (e == 4)n = 1988 + y;
		cout << n << endl;
	}
}


Measured memory_bytes: 3156
import Data.List

main :: IO ()
main = do
  [n, m] <- readInts
  xs <- sort <$> readInts
  print $ solve n m xs

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve n m xs
  | n >= m = 0
  | otherwise = solve' n xs

solve' :: Int -> [Int] -> Int
solve' n xs = (xm - x1) - solve'' n ls
  where
    x1 = head xs
    xm = last xs
    ls = zipWith (-) (tail xs) xs

solve'' :: Int -> [Int] ->Int
solve'' n ls = sum $ take (n - 1) $ sortBy (flip compare) ls


Measured memory_bytes: 32764
# A - Pay to Win
import sys
sys.setrecursionlimit(10000)

T = int(input())
a = [list(map(int,input().split())) for _ in range(T)]
memo = {}

# N,A,B,C,D
def solve(N,A,B,C,D):
    if N==0:
        return 0
    if N==1:
        return D
    if N in memo:
        return memo[N]
    ans = min(
        D*N,
        (N-2*(N//2))*D+A+solve(N//2,A,B,C,D),
        (2*((N+1)//2)-N)*D+A+solve((N+1)//2,A,B,C,D),
        (N-3*(N//3))*D+B+solve(N//3,A,B,C,D),
        (3*((N+2)//3)-N)*D+B+solve((N+2)//3,A,B,C,D),
        (N-5*(N//5))*D+C+solve(N//5,A,B,C,D),
        (5*((N+4)//5)-N)*D+C+solve((N+4)//5,A,B,C,D),
    )
    memo[N] = ans
    return ans

for i in range(T):
    memo = {}
    (N,A,B,C,D) = a[i]
    print(solve(N,A,B,C,D))

Measured memory_bytes: 10808
package main

import "fmt"

func main() {
	var H int
	fmt.Scanf("%d", &H)
	h := H
	power := 1
	sum := 0
	for h > 1 {
		if h%2 == 0 {
			h /= 2
		} else {
			h--
			h /= 2
		}
		sum += power
		power *= 2
	}
	if h == 1 {
		sum += power
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;
ll mn1=-9223372036854775808;
int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------


void solve()
{
    string s;
    cin>>s;
    if(s[s.length()-1]=='s')
        s+="es";
    else
        s+="s";
    cout<<s<<endl;
}
int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  string ans="yes";
  for(int i=0;i<s.size()-1;i++){
    for(int j=i+1;j<s.size();j++){
      if(s.at(i)==s.at(j)){
        ans="no";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc079.contest.atcoder.jp/tasks/abc079_d>
問題文============================================================
 魔法少女のjoisinoお姉ちゃんは、この世にあるすべての数字を 1 に変えてやろうと思い立ちました。
 
 1 つの数字を i から j(0≦i,j≦9) に書き変えるには魔力 ci,j が必要です。
 
 今、目の前にある壁は縦方向に H、横方向に W のマス目になっていて、
 1 つ以上のマス目に 0 以上 9 以下の整数が 1 つずつ書かれています。
 
 上から i(1≦i≦H) 番目、左から j(1≦j≦W) 番目のマスの情報として Ai,j が与えられ、
 
 Ai,j≠−1 の場合はマスに Ai,j が書かれている
 Ai,j=−1 の場合はマスに数字が書かれていない
 ことを意味します。
 
 この壁に書かれている数字を最終的に全て 1 に変えるのに必要な魔力の最小量を求めてください。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    ll G[10][10] = {0};
    for(int i = 0; i < 10;i++)for(int j = 0; j < 10;j++) cin >> G[i][j];
    for(int i = 0; i  < 10;i++)for(int j = 0; j < 10;j++) for(int k = 0; k < 10;k++)
        G[j][k] = min(G[j][k],G[j][i] + G[i][k]);
    ll ans = 0;
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            ll A; cin >> A;
            if(A == -1) continue;
            ans += G[A][1];
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())

a = list(map(int, input().split()))

prev = a[0]
result = 0
up_down = None
# print(prev, end=", ")
for v in a[1:]:
    if up_down is None:
        if prev > v:
            up_down = lambda a, b: a >= b
        elif prev < v:
            up_down = lambda a, b: a <= b
        else:
            # print(v, end=", ")
            continue
    if not up_down(prev, v):
        # print("| ",end="")
        up_down = None
        result += 1
    # print(v, end=", ")
    prev = v
# print()
print(result + 1)


Measured memory_bytes: 14224
n=gets.to_i
w=gets.chomp.split.map(&:to_i)
w1=w[0]
w2=w[1,n-1].inject(:+)
ans=(w1-w2).abs
1.upto(n-2) do |i|
  w1 += w[i]
  w2 -= w[i]
  ans=(w1-w2).abs if ans > (w1-w2).abs
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int gcd(int i, int j);

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    int num;
    long long sum=0;
    cin >> num;

    for(int i=1; i<=num; i++){
        for(int j=1; j<=num; j++){
            if(gcd(i,j)==1) sum=sum+num;
            else{
                for(int k=1; k<=num; k++){
                    if(gcd(i,k)==1) sum=sum+1;
                    else if(gcd(j,k)==1) sum=sum+1;
                    else{
                        sum=sum+gcd(gcd(i,j),k);
                    }
                }
            }
        }
    }

    cout << sum;
}

int gcd(int i, int j){
    int Mmax=max(i,j);
    int Mmin=min(i,j);
    while(Mmin!=0){
        Mmax=Mmax%Mmin;
        if(Mmin>Mmax) swap(Mmin,Mmax);
    }
    return Mmax;
}




Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  long long A;
  double B;
  cin >> A >> B;
  //

  long long tmp;
  
    B *= 100;
    tmp = A*B/100;
    cout << tmp << endl;
  

  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
   ll n;
   cin>>n;
   string s;
   while(n>0){
       if(n%26==0)
         s+='z';
       else
        s+=('a' + (n-1)%26);
       n-=1;
       n/=26;
   }
  
   reverse(s.begin(),s.end());
   cout<<s;
}

Measured memory_bytes: 3636
import heapq
import itertools
n, m, r = map(int, input().split())
r = list(map(lambda x:int(x)-1, input().split()))
d = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
  a, b, t = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = t
  d[b][a] = t
for i in range(n):
  d[i][i] = 0

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d  

d = warshall_floyd(d)
ans = float('inf')
for v in itertools.permutations(r):
  tmp = 0
  for i in range(len(v)-1):
    tmp += d[v[i]][v[i+1]]
  ans = min(ans, tmp)

print(ans)


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

long long gcd(long long a, long long b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}

long long lcm(long long a, long long b)
{
    long long g = gcd(a, b);
    return a / g * b;
}

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

    long long ans = 1LL;
    for (int i = 0; i < n; i++)
    {
        long long t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=[]

for i in range(n):
    A.append(int(input()))
    
est=max(A)
B=A[:]
A.remove(est)
er=max(A)
A=B

for i in range(n):
    if A[i] != est:
        print(est)
    else:
        print(er)

Measured memory_bytes: 12588
import scala.io.StdIn.readLine

object Main{
  def solve(n : Int, x : Long): Long ={
    if(n == 0) x
    else{
      val hSize : Long = (1.toLong << (n + 1)) - 3
      val ps : Long = (1.toLong << n) - 1
      if(x == 0) 0
      else if(x == hSize + 2) ps + 1
      else if(x == 2 * hSize + 3) 2 * ps + 1
      else if(x > hSize + 2) ps + 1 + solve(n - 1, x - hSize - 2)
      else solve(n - 1, x - 1)
    }
  }

  def main(args : Array[String]): Unit ={
    val Array(n, x) = readLine().split(' ')
    println(solve(n.toInt, x.toLong))
  }
}


Measured memory_bytes: 25428
s = input().rstrip()
t = input().rstrip()
l_s = len(s)
l_t = len(t)
ans = l_t
for i in range(l_s-l_t+1):
  tmp_ans = l_t
  for j in range(l_t):
    if t[j] == s[i+j]:
      tmp_ans -= 1
  ans = min(ans, tmp_ans)
print(ans)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6+5;
int main()
{
	sync;
	ll l, r, d;
	cin >> l >> r >> d;
	ll ans = 0;
	for(ll i = l; i <= r;i++)
		if(i % d  == 0)
			ans++;
	
	cout<<ans;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    ll sum=0;
    long i;
    for(i=0; i<n; i++) {
        long l, r;
        scanf("%ld%ld", &l, &r);
        sum += (r-l+1);
    }
    printf("%lld\n", sum);
  
    return 0;
}


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

int main() {
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  long long ans;
  
  ans = max(a*c, max(a*d, max(b*c, b*d)));
  cout << ans << endl;
}


Measured memory_bytes: 3624
import System.IO (isEOF)

data Orientation = Horizontal | Vertical deriving Eq
data Direction = North | South | East | West
type Wall = (Int,Int,Orientation)

main = input >>= return . solve >>= output

input :: IO [String]
input = do
    quit <- isEOF
    if quit then return [] else do
        line <- getLine
        fmap (line:) input

output :: [Direction] -> IO ()
output = putStrLn . map toLetter
    where
    toLetter North = 'U'
    toLetter South = 'D'
    toLetter East  = 'R'
    toLetter West  = 'L'

solve :: [String] -> [Direction]
solve ls = ws `seq` trace ws (1,0) East [East]
    where
    ws = walls ls

    trace _  (0,0) _ ds = reverse ds
    trace ws pos   d ds = trace ws npos nd (nd:ds)
        where
        nd = nextDirection ws pos d
        npos = nextPosition pos nd

walls :: [String] -> [Wall]
walls = concat . zipWith bindLine [(y,o)|y<-[0..],o<-[Horizontal,Vertical]]
    where
    bindLine (y,o) cs = bindLine' 0 y o cs

    bindLine' x y o ""       =           []
    bindLine' x y o ('1':cs) = (x,y,o) : bindLine' (x+1) y o cs
    bindLine' x y o (_:cs)   =           bindLine' (x+1) y o cs

wallExists :: [Wall] -> (Int,Int) -> Direction -> Bool
wallExists ws (x,y) North = (x,y-1,Vertical) `elem` ws
wallExists ws (x,y) South = (x,y,Vertical) `elem` ws
wallExists ws (x,y) East  = (x,y,Horizontal) `elem` ws
wallExists ws (x,y) West  = (x-1,y,Horizontal) `elem` ws

turnsOrder :: Direction -> [Direction]
turnsOrder North = [West,North,East,South]
turnsOrder South = [East,South,West,North]
turnsOrder East  = [North,East,South,West]
turnsOrder West  = [South,West,North,East]

nextDirection :: [Wall] -> (Int,Int) -> Direction -> Direction
nextDirection ws (x,y) d = head $ filter (wallExists ws (x,y)) (turnsOrder d)

nextPosition :: (Int,Int) -> Direction -> (Int,Int)
nextPosition (x,y) North = (x,y-1)
nextPosition (x,y) South = (x,y+1)
nextPosition (x,y) East  = (x+1,y)
nextPosition (x,y) West  = (x-1,y)

Measured memory_bytes: 3560
import math

def calc(N):
    gcd = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

    for i in range(1,N + 1):
        for j in range(i,N + 1):
            gcd[i][j] = math.gcd(i,j)
            gcd[j][i] = gcd[i][j]

    ans = 0
    for i in range(1,N + 1):
        for j in range(1,N + 1):
            for k in range(1,N + 1):
                g = gcd[i][j]
                ans += gcd[g][k]
    return ans


N = int(input())

print(calc(N))






Measured memory_bytes: 9484
N, K = map(int, input().split())
D = list(map(str, input().split()))

for i in range(N, 100000):
    j = str(i)
    more = False
    for k in D:
        if j.count(k) > 0:
            more = True
            break
    if not more:
        ans = i
        break

print(ans)

Measured memory_bytes: 3060