akhauriyash/Code-Regression huggingface dataset:
N, D = [int(x) for x in input().split()]
x_list = [[int(x) for x in input().split()] for _ in range(N)]
sq = [n*n for n in range(1000)]
cnt = 0
for i, xi in enumerate(x_list):
    for xj in x_list[i+1:]:
        dist = sum([(y-z)*(y-z) for y, z in zip(xi, xj)])
        cnt += (dist in sq)
print(cnt)


Measured memory_bytes: 38384
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] h = new int[N];

    for (int i = 0; i < N; i++) {
      h[i] = sc.nextInt();
    }

    sc.close();

    Arrays.sort(h);

    int min = 999999999;
    int count = -1;
    int t = K - 1;

    for (int i = 0; i < N - t; i++) {
      int d = h[i+t] - h[i];
      if (d < min) {
        min = d;
        count = i;
      }
    }

    System.out.println(h[count+t] - h[count]);

  }

}

Measured memory_bytes: 48500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,A_d, B;
  int num = 10000;
  int x1, x2, x3, x4, x5, sum;
  
  sum = 0;
  cin >> A >> B;
  while (A <= B){
    A_d = A;
    x1 = A_d / num;
    A_d -= x1 * num;
    num /= 10;
    
    x2 = A_d / num;
    A_d -= x2 * num;
    num /= 10;
    
    x3 = A_d / num;
    A_d -= x3 * num;
    num /= 10;
    
    x4 = A_d / num;
    A_d -= x4 * num;
    num /= 10;
    
    x5 = A_d / num;
    A_d -= x5 * num;
    
    if(x1 == x5 && x2 == x4)sum++;
    
    num = 10000;
    A++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
K, N = list(map(int, input().split()))
lst_A = list(map(int, input().split())) 

def main(K, N, lst_A):

    diff_dis = [lst_A[i+1] - lst_A[i] for i in range(N-1)]
    diff_dis.append(K-lst_A[-1] + lst_A[0])

    sum_diff = sum(diff_dis)
    answer = sum(diff_dis)

    for diff in diff_dis:
        _answer = sum_diff - diff
        answer  = min(answer, _answer)

    return answer

if __name__ == "__main__":

    answer = main(K, N, lst_A)
    print(answer)

Measured memory_bytes: 26444
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;
use std::ascii::AsciiExt;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        s: String,
    }
    let mut ans = "".to_string();
    for (i, c) in s.chars().enumerate() {
        if i == k-1 {
            ans += &c.to_ascii_lowercase().to_string()
        } else {
            ans += &c.to_string()
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define Rep(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) Rep(i,0,n)
#define stop char nyaa;cin>>nyaa;
using ll = long long;
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

using P = pair<int, int>;

void solve() {
	int n; cin >> n;
	vector<vector<P>> v(n);
	rep(i, n) {
		int x; cin >> x;
		rep(j, x) {
			int a, b; cin >> a >> b; a--;
			v[i].push_back({ a,b });
		}
	}
	int ans = 0;
	rep(i, (1 << n)) {
		bool valid = true;
		int tmp = 0;
		rep(j, n) {
			if (i&(1 << j)) {
				tmp++;
				rep(k, v[j].size()) {
					int a = v[j][k].first, b = v[j][k].second;
					if (b) {
						if ((i&(1 << a)) == 0) {
							valid = false;
						}
					}
					else {
						if (i&(1 << a))valid = false;
					}
				}
			}
		}

		if (valid)ans = max(ans, tmp);
	}
	cout << ans << endl;
}


signed main() {
	solve();
	stop
	return 0;
}


Measured memory_bytes: 256
c = []
for i in range(3):
    c.append(list(map(int,input().split())))
ans = "Yes"
for i in range(3):
    for j in range(i+1,3):
        tmp = []
        for h in range(3):
            tmp.append(c[h][i]-c[h][j])
        if len(set(tmp)) != 1:
            ans = "No"
            break

print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace arc087_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = new int[100010];
            int ret = 0;
            for (int i = 0; i < n; i++)
            {
                if (x[i] > 100000) ret++;
                else a[x[i]]++;
            }
            for (int i = 1; i < 100010; i++)
            {
                if (a[i] < i) ret += a[i];
                else ret += a[i] - i;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 32604
N = int(input())
let = [0]*26
S = input()
for a in range(len(S)):
  let[ord(S[a])-ord("a")] += 1
    
for i in range(N-1):
  S = input()
  let_S = [0]*26
  for j in range(len(S)):
    let_S[ord(S[j])-ord("a")] += 1
  for k in range(26):
    if let[k] > let_S[k]:
      let[k] = let_S[k]

ans = ""
for l in range(26):
  ans += chr(ord("a")+l)*let[l]

print(ans)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int MOD = (int)1e9+7;

int main(void) {
	//freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	vl a(n+1);
	rep(i,1,n+1) {
		cin >> a[i];
	}
	vl S(n+1);
	rep(i,1,n+1) {
		S[i] = (S[i-1] + a[i]) % m;
	}
	map<int, int> cnt;
	rep(i,0,n+1) {
		if(cnt.find(S[i]) != cnt.end()) {
			cnt[S[i]]++;
		} else {
			cnt[S[i]] = 1;
		}
	}

	ll ret = 0;
	for(auto it : cnt) {
		int k = it.S;
		ret += (ll)k*(k-1)/2;
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 4736
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0

for i,j in enumerate(b):
    c = min(j, a[i] + a[i+1])
    cnt += c
    a[i+1] -= max(0, c-a[i])
print(cnt)



Measured memory_bytes: 19116
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 文字の数 */
	private static final int N = 26;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[][] s = new char[n][];
			IntStream.range(0, n).forEach(i -> s[i] = scanner.next().toCharArray());
			int[] result = new int[N], temp = new int[N];
			if (n > 0) {
				calcResult(s[0], result, result);
				IntStream.range(1, s.length).forEach(i -> calcResult(s[i], temp, result));
			}
			System.out.println(getResult(result));
		}
	}

	/**
	 * @param s      文字列
	 * @param temp   一時計算結果格納用
	 * @param result 共通計算結果格納用
	 */
	private static void calcResult(char[] s, int[] temp, int[] result) {
		Arrays.fill(temp, 0);
		IntStream.range(0, s.length).forEach(i -> temp[s[i] - 'a']++);
		if (temp != result) {
			// 2回目以降の実行ではtempとresultをマージする
			IntStream.range(0, N).forEach(i -> result[i] = Math.min(temp[i], result[i]));
		}
	}

	/**
	 * @param result 各文字の数
	 * @return 計算結果
	 */
	private static String getResult(int[] result) {
		StringBuilder sb = new StringBuilder();
		IntStream.range(0, N).forEach(i -> IntStream.range(0, result[i]).forEach(j -> sb.append((char) (i + 'a'))));
		return sb.toString();
	}
}


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




int main(){
	
	long long n,w;cin>>n>>w;
	vector<long long> dp(100001,1000000001);
	dp[0]  =0;
	for(int i=0;i<n;i++){
		long long weight,value;
		cin>>weight>>value;
		for(int j=100000;j>=0;j--){
			if(j-value>=0){
				dp[j] = min(dp[j],dp[j-value]+weight);
			}
		}
	}
	long long ans = 1000000001;
	for(int i=0;i<dp.size();i++){
		if(dp[i]<=w)ans = i;
	}
	cout<<ans;
}



Measured memory_bytes: 1024
a = int(input())
List = [input().split() for i in range(a)]
word = input()
sum = 0
slsum = 0
for list in List:
  sum += int(list[1])
#print(sum)

for sleep in List:
  slsum += int(sleep[1])
  if sleep[0] == word:
    break
sum = sum - slsum
print(sum)

Measured memory_bytes: 3064
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

N = i_inpl()
D = []
for i in range(N):
    si, pi = input().split()
    D.append([si, int(pi), i+1])

for r in sorted(D, key=lambda x:(x[0],-x[1])):
    print(r[2])

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

#define printl(s) cout << s << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
using tiil = tuple<int,int,ll>;

const ll modSeed = pow(10,9) + 7;
const int INF = 1'000'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,ans;

int main(){
  ans = 0;
  cin >> N;
  vector<tiil> info(N);
  tiil defo;
  rep(i,N){
    int x,y;
    ll h;
    cin >>x>>y>>h;
    info[i] = make_tuple(x,y,h);
    if(h!=0) defo=info[i];
  }
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      int range = abs(get<0>(defo)-x)+abs(get<1>(defo)-y);
      ll height = get<2>(defo) + range;
      bool flg = true;
      for(int i=0;i<N;i++){
        ll cHeight = max(height-abs(get<0>(info[i])-x)-abs(get<1>(info[i])-y),0LL);
        if(cHeight!=get<2>(info[i])){
          flg = false;
        }
      }
      if(flg){
        cout << x << " " << y << " " << height;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2e5,mod=1e9+7;
long long jc[222222],injc[222222],h,w,n,dp[3333],ans;
pair<long long,long long> a[3333];
long long binpow(long long a,long long t)
{
	long long res=1,p=a;
	for (long long i=t;i;i>>=1)
	{
		if (i&1) res=res*p%mod;
		p=p*p%mod;
	}
	return res;
}
void Init()
{
	jc[0]=1;
	for (long long i=1;i<=maxn;i++) jc[i]=jc[i-1]*i%mod;
	injc[maxn]=binpow(jc[maxn],mod-2);
	for (long long i=maxn-1;i>=0;i--) injc[i]=injc[i+1]*(i+1)%mod;
}
long long C(long long n,long long m)
{
	return (jc[n]*injc[m]%mod)*injc[n-m]%mod;
}
long long go(long long x,long long y,long long xx,long long yy)
{
	return C(xx-x+yy-y,xx-x);
}
int main()
{
	scanf("%lld%lld%lld",&h,&w,&n);
	Init();
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].first,&a[i].second);
	}
	sort(a+1,a+n+1);
	for (long long i=1;i<=n;i++)
	{
		for (long long j=1;j<i;j++)
		{
			if (a[j].first<=a[i].first && a[j].second<=a[i].second) 
			{
				dp[i]=(dp[i]-dp[j]*go(a[j].first,a[j].second,a[i].first,a[i].second))%mod;
			}
		}
		dp[i]=(dp[i]-go(1,1,a[i].first,a[i].second));
	}
	ans=go(1,1,h,w);
	for (long long i=1;i<=n;i++)
	{
		ans=(ans+dp[i]*go(a[i].first,a[i].second,h,w))%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
#define sd(n) scanf("%d",&n)
#define clr(a) memset(a,0,sizeof(a)) 
ll a;int b;
int main(){
	cin>>a;
	cin>>b;
	cout<<a-b+1;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[200050],t[200050];
bool vis[26];
int n;
inline void update(int k,char c1,char c2){
	for(int i=k;i<n;i++)if(t[i]==c1)t[i]=c2;
	else if(t[i]==c2)t[i]=c1;
}
int main(){
	scanf("%s%s",s,t);
	n=strlen(s);
	for(int i=0;i<n;i++){
		if(s[i]!=t[i])if(vis[s[i]-'a']||vis[t[i]-'a']){
			puts("No");
			return 0;
		}else update(i,s[i],t[i]);
		vis[s[i]-'a']=1;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int k, x;
    cin >> k >> x;
    vector<int> ans;
    for (int i = x - k + 1; i <= x + k - 1; i++) {
        if (i >= -1000000 and i <= 1000000) {
            ans.push_back(i);
        }
    }
    for (int x : ans) {
        cout << x << " ";
    }
    cout << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
	map<string, int> m;
	string ar[4]={"AC","WA","TLE","RE"};
	int n;
	cin>>n;
	while (n--)
	{
		string s;
		cin>>s;
		m[s]++;
	}
	for (int i=0;i<4;i++)
	{
		cout<<ar[i]<<" x "<<m[ar[i]]<<"\n";
	}
}

Measured memory_bytes: 3632
import math
a,b,R=map(int,input().split())
C=R*math.pi/180
S=0.5*a*b*math.sin(C)
c=math.sqrt(a**2+b**2-2*a*b*math.cos(C))
L=a+b+c
h=2*S/a
print(S)
print(L)
print(h)



Measured memory_bytes: 5708
def main():
    n = int(input())
    lst = list(map(int, input().split(' ')))
    count = 0
    for i in range(1, n+1):
        if lst[i-1] != i:
            count += 1
    if count <= 2:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
const int jX = W-r;
const int jY = H-r;
if(x<=jX & x>=r & y<=jY & y>=r)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 10000



int main(){
    int n,i;
    string s;
    cin>>s;
    if(s[1]=='R')
        cout<<s[0]<<"B"<<s[2];
    else
        cout<<s[0]<<"R"<<s[2];
    
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n;
  cin >> n;
  VI dams(n);
  forx(i,n) cin >> dams[i];
  ll x = 0;
  forx(i,n) {
    if (i & 1) {
      x -= dams[i];
    } else {
      x += dams[i];
    }
  }
  forx(i,n) {
    cout << x << " ";
    x = 2*dams[i] - x;
  }
  cout << nl;
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 1792
program five_dishes
  implicit none
  integer :: a(5) = 0, i, m, s
  do i = 1, 5
    read(*,*) a(i)
  end do
  s = sum((a+9)/10*10)
  m = s
  do i = 1, 5
    m = min(m,s-(a(i)+9)/10*10+a(i))
  end do
  write(*,'(i0)') m
end program five_dishes

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

vector<ll> dp[10][10010];
ll cnt[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  REP(i, m) cin >> a[i];

  REP(i, m) REP(j, n+1) dp[i][j].assign(10, -1);

  dp[0][0].assign(10, 0);
  REP(i, m) {
    REP(j, n+1) {
      if(i) dp[i][j] = dp[i-1][j];
      if(cnt[a[i]] <= j) {
        auto tmp = dp[i][j-cnt[a[i]]];
        if(tmp[0] == -1) continue;
        tmp[9-a[i]]++;
        ll sum1 = 0, sum2 = 0;
        REP(k, 10) sum1 += dp[i][j][k], sum2 += tmp[k];
        if(sum1 < sum2 || (sum1 == sum2 && dp[i][j] < tmp)) {
          dp[i][j] = tmp;
        }
      }
    }
  }

//  REP(i, n+1) cout << dp[0][i] << endl;

  string ans = "";
  REP(i, 10) ans += string(dp[m-1][n][i], '0'+9-i);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11008
#include <stdio.h>

int main(void){
    long int N;
  	long int Ans;
  
    scanf("%ld",&N);

    if(N % 2 == 0){
      	Ans = N/2-1;
        printf("%ld",Ans);
    }

    else{
      	Ans = (N-1)/2;
        printf("%ld",Ans);
    }
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a,b,c=0;
  cin>>a>>b;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      if(j%10>1&&j/10>1&&i==(j%10)*(j/10))
        c++;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);


int main() {
	int K, X;
	cin >> K >> X;
	if(K*500>=X) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 2 == 0)continue;
        int count = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0)count++;
        }
        if (count == 8)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int main(void){
 int N,M;
 cin >> N >> M;

 const int nmmax=50;
 char A[nmmax][nmmax],B[nmmax][nmmax];


 for(int y=0;y<N;++y){
 for(int x=0;x<N;++x){
 cin >> A[y][x];
 }
 }

 for(int y=0;y<M;++y){
 for(int x=0;x<M;++x){
 cin >> B[y][x];
 }
 }

 bool exist=false;

 for(int ly=0;ly<N;++ly){
 for(int lx=0;lx<N;++lx){
 if(ly+M-1>=N or lx+M-1>=N) continue;

 bool match=true;
 for(int y=0;y<M;++y){
 for(int x=0;x<M;++x){
 if(A[ly+y][lx+x]!=B[y][x]) match=false;
 }
 }
 if(match) exist=true;
 }
 }

 if(exist)
 cout << "Yes" << endl;
 else
 cout << "No" << endl;

 return 0;
 }

Measured memory_bytes: 3612
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let h: usize = s.next().unwrap().parse().unwrap();
	let w: usize = s.next().unwrap().parse().unwrap();
	let k: i32 = s.next().unwrap().parse().unwrap();
	let sy = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let sx = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let gy = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let gx = s.next().unwrap().parse::<usize>().unwrap() - 1;
	let field: Vec<Vec<_>> = s.take(h).map(|s| s.chars().collect()).collect();

	let mut dist = vec![vec![std::i32::MAX; w]; h];
	dist[sy][sx] = 0;
	let mut q = std::collections::VecDeque::new();
	q.push_front((sy as i32, sx as i32));
	while let Some((y, x)) = q.pop_front() {
		const DELTA: [i32; 5] = [0, 1, 0, -1, 0];
		for i in 0..4 {
			for l in 1..=k {
				let ny = y + DELTA[i] * l;
				let nx = x + DELTA[i + 1] * l;
				if 0 <= ny && ny < h as i32 && 0 <= nx && nx < w as i32 {
					let ny = ny as usize;
					let nx = nx as usize;
					if field[ny][nx] != '.' || dist[ny][nx] <= dist[y as usize][x as usize] {
						break;
					}
					if dist[ny][nx] == std::i32::MAX {
						dist[ny][nx] = dist[y as usize][x as usize] + 1;
						q.push_back((ny as i32, nx as i32));
					}
				}
			}
		}
	}
	if dist[gy][gx] == std::i32::MAX {
		println!("-1");
	} else {
		println!("{}", dist[gy][gx]);
	}
}


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

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

static const int INF = 0x3f3f3f3f;

struct edge {
        int to;
        int dis;
        int cost;
};

vector<edge> g[10101];
int dis[10101];
int cost[10101];
int n, m;

void dijkstra(int s) {
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
        fill(dis, dis + n, INF);
        fill(cost, cost + n, INF);
        dis[s] = 0;
        q.push(make_pair(s, 0));
        while (!q.empty()) {
                pair<int, int> p = q.top(); q.pop();
                int v = p.first;
                if (dis[v] < p.second) continue;
                for (auto e : g[v]) {
                        if (dis[e.to] > dis[v] + e.dis) {
                                dis[e.to] = dis[v] + e.dis;
                                q.push(make_pair(e.to, dis[e.to]));
                        }
                }
        }
}

int main() {
        while (cin >> n >> m && n) {
                vector<int> u(m), v(m), d(m), c(m);
                for (int i = 0; i < n; i ++) g[i].clear();
                rep(i, m) {
                        int u, v, d, c;
                        cin >> u >> v >> d >> c;
                        u --, v --;
                        g[u].push_back({v, d, c});
                        g[v].push_back({u, d, c});
                }
                dijkstra(0);
                int ans = 0;
                for (int i = 1; i < n; i ++) {
                        int res = INF;
                        for (auto e : g[i]) {
                                if (dis[e.to] + e.dis == dis[i] && e.cost < res) {
                                        res = e.cost;
                                }
                        }
                        ans += res;;
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 5996
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
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);};

int main() {
  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];
  int c = 0;
  for(int i = 0; i < n - 2; i++) {
    if(p[i] <= p[i + 1] && p[i + 1] <= p[i + 2]) c++;
    else if(p[i + 1] <= p[i] && p[i + 1] >= p[i + 2]) c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    
    int n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];

    ll sum = 0;
    rep(i,n) sum += a[i];

    ll r[n];
    r[0] = sum;
    for (int i=1; i <= n-2; i+=2){
        r[0] -= 2*a[i];
    }

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

    rep(i,n) cout << r[i] << " " ;
    cout << endl;
    

    

}





//              g++ -std=c++1z

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
//	入力の読み込み
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();  //目標金額
		long total = 100L;  //預金金額
		int count = 0;  //何年後か
//	totalがxを超えるまで繰り返す
		while(total < x) {
			total *= 1.01;
			count++;  //何年たったかカウントする
		}
		System.out.print(count);
	}
}


Measured memory_bytes: 27080
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,ans=0;cin>>n>>m;
vector<int> x(m);
for(int i=0;i<m;i++)cin>>x[i];
sort(x.begin(),x.end());
priority_queue<int, vector<int>, greater<int>> que;
for(int i=1;i<m;i++) que.push(x[i]-x[i-1]);
while(m-n>0){
ans+=que.top();
que.pop();
m--;
}
cout<<ans<<endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef int64_t Int;
const double pi = M_PI;

int main()
{
    int a, b;
    char op;

    while (true)
    {
        cin >> a >> op >> b;

        switch (op)
        {
        case '+':
            cout << a + b << endl;
            break;

        case '-':
            cout << a - b << endl;
            break;

        case '*':
            cout << a * b << endl;
            break;

        case '/':
            cout << a / b << endl;
            break;

        default:
            break;
        }

        if (op == '?')
        {
            break;
        }
    }
}



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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 2E5 + 10;

int n;
int a[N];

bool check(int m){
	vector<pii> b;
	for (int i = 1; i < n; ++i)
		if (a[i] <= a[i - 1]){
			if (m == 1)
				return false;

			int t = a[i];
			for (; !b.empty() && b.back() >= pii(t, m); t -= b.back().st == t, b.pop_back());

			if (t == 0)
				return false;
			if (!b.empty() && b.back().st == t)
				++b.back().nd;
			else
				b.emplace_back(t, 2);

			eput(i, b);
		}
	return true;
}

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	int low = 1, high = n;
	while (low < high){
		int mid = low + high >> 1;
		bool res = check(mid);
		eput(mid, res);
		if (res)
			high = mid;
		else
			low = mid + 1;
	}
	printf("%d\n", low);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e7))
#define pi (2*acos(0))
#define mp make_pair
#define M ((int)(1e9 + 7))
#define xx first
#define yy second
#define NN ((int)(5e5+2))
#define N ((int)(2e5 + 2))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int lu;

typedef tree < int ,  null_type ,  less < int > ,  rb_tree_tag ,  tree_order_statistics_node_update > o_set;

struct info{
    int v, i;
}a[N];

bool cmp(info a, info b)
{
    return a.v<b.v;
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i<n; i++){
        scanf("%d",&a[i].v);
        a[i].i = i;
    }
    sort(a,a+n,cmp);
    int ans = n-1;
    a[0].v = 1;
    for(int i = 1; i<n; i++){
        a[i].v = 1;
        if(a[i-1].i<a[i].i) a[i].v = a[i-1].v+1;
        ans = min(ans,n-a[i].v);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, z, w; scanf("%d%d%d", &n, &z, &w); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	int ans = std::abs(w - a.back());
	if(n > 1) ans = std::max(ans, std::abs(a[n - 1] - a[n - 2]));
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main () {
  int h, w;
  cin >> h >> w;
  vii a(h, vi(w));
  rep (i, h) {
    rep (j, w) {
      cin >> a[i][j];
    }
  }
  vector<pii> idx;
  rep (i, h) {
    if (i % 2 == 0) {
      rep (j, w) {
        idx.push_back(pii(i, j));
      }
    }
    else {
      rrep (j, w) {
        idx.push_back(pii(i, j));
      }
    }
  }
  int cnt = 0;
  vii b;
  rep (k, h * w - 1) {
    int i = idx[k].first, j = idx[k].second;
    int ni = idx[k + 1].first, nj = idx[k + 1].second;
    if (a[i][j] % 2 == 1) {
      a[i][j]--;
      a[ni][nj]++;
      cnt++;
      vi temp = {i + 1, j + 1, ni + 1, nj + 1};
      b.push_back(temp);
    }
  }      
  cout << cnt << endl;
  rep (i, cnt) {
    rep (j, 4) {
      cout << b[i][j];
      if (j != 3) {
        cout << " ";
      }
    }
    cout << endl;
  }
}
            


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

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

Measured memory_bytes: 3584
N,K = list(map(int,input().split()))

if K>((N-1)*(N-2))//2:
    print(-1)

else:
    L = ((N-1)*(N-2))//2 - K
    S = 0
    SL = []
    for i in range(1,N):
        S+=i
        SL.append(S)
    now = N-1
    now2 = 1
    ans = []
    j = 0
    for i in range(L):
        ans.append([now,now+now2])
        if SL[j]==i+1:
            j+=1
            now-=1
            now2=1
        else:
            now2+=1
    
    print(len(ans)+N-1)
    for i in range(2,N+1):
        print(1,i)
    for a in ans:
        print(*a)


Measured memory_bytes: 43504
k['( '],n,a,b,i,m;p(int*x){n=*x-*1[&x];}main(c){for(scanf("%d%d%d%d",&n,&a,&b,&c);i<n;scanf("%d",k+i++));for(qsort(k,n,4,p);~i;a+=b,c+=k[--i])m<c/a?m=c/a:0;a=!printf("%d\n",m);}

Measured memory_bytes: 0
N = int(input())
h = list(map(int, input().split()))

dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]),
                        dp[i-1] + abs(h[i-1] - h[i])
                        )
print(dp[-1])

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

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

Measured memory_bytes: 256
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

ANS=[]
NUM=[]
i=0
while i<N:
    NUM.append(i+1)
    i+=1
#print(NUM)

j=0
for i in itertools.permutations(NUM):
    ANS.append(i)
    if list(i)==P:
        PANS=j+1
    if list(i)==Q:
        QANS=j+1
    j+=1

print(abs(PANS-QANS))

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
	int d;
	cin >> d;
	vector<int> c(26);
	vector<int> last(26, -1);
	vector<vector<int>> s(26, vector<int>(d, 0));
	rep(i, 26)	cin >> c[i];
	rep(j, d) rep(i, 26)	cin >> s[i][j];

	int t = 0;
	vector<ll> score(d, 0);
	rep(i, d) {
		if (i != 0)	score[i] = score[i - 1];
		cin >> t;
		t--;
		score[i] += s[t][i];
		last[t] = i;
		rep(j, 26) {
			score[i] -= (i - last[j])*c[j];
		}
	}
	rep(i, d)	cout << score[i] << endl;

	return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
	for(int i=0;i<5;i++){
		int a;
		cin>>a;
		if(a == 0)cout<<i+1;
		
	}
}


Measured memory_bytes: 3584
k = int(input())
ans1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ite = 9

if (k < 10):
    print(ans1[k - 1])
else:
    while (ite < k):
        ans2 = []
        for num in ans1:
            keta1 = num % 10
            if (keta1 == 0):
                ans2.append(num * 10)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + 1)
                ite += 1
                if (ite == k):
                    break
                # ans2.append(num * 10 + 9)
                # ite += 1
                # if (ite == k):
                #     break
            elif (keta1 == 9):
                # ans2.append(num * 10)
                # ite += 1
                # if (ite == k):
                #     break
                ans2.append(num * 10 + keta1 - 1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1)
                ite += 1
                if (ite == k):
                    break
            else:
                ans2.append(num * 10 + keta1 - 1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1 + 1)
                ite += 1
                if (ite == k):
                    break
        ans1 = ans2[:]
    print(ans2[-1])


Measured memory_bytes: 43248
import math
n = int(input())
a = list(map(int,input().split()))
i = 0
ans = 0
while i < n:
    var = a[i]
    sub = 1
    while i+1 < n:
        if a[i+1] == var:
            i += 1
            sub += 1
        else:
            break
    ans += math.floor(sub//2)
    i += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int r, g;
    cin >> r >> g;
    cout << (2*g - r) <<endl;

}


Measured memory_bytes: 256
import Data.List

main = do
  [k, n] <- map read . words <$> getLine :: IO [Int]
  as <- map read . words <$> getLine :: IO [Int]
  let diffs = calcDiff as
      firstAndLast = (as !! 0) - (as !! (n-1)) + k
  print $ k - (head . reverse . sort $ (firstAndLast:diffs))

calcDiff :: [Int] -> [Int]
calcDiff [] = []
calcDiff (x1:[]) = []
calcDiff (x1:x2:xs) = (x2-x1) : calcDiff (x2:xs)


Measured memory_bytes: 111996
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  int N, M;
  cin >> N;
  LL dist[50][50];
  REP(i, N) {
    REP(j, N) {
      dist[i][j] = 1LL << 60;
    }
    dist[i][i] = 0;
  }
  REP(i, N-1) {
    int A, B;
    cin >> A >> B;
    --A; --B;
    dist[A][B] = 1LL << i;
    dist[B][A] = 1LL << i;
  }
  REP(k, N) {
    REP(i, N) {
      REP(j, N) {
        LL ndist = dist[k][i] + dist[k][j];
        if(ndist < dist[i][j]) {
          dist[i][j] = ndist;
          dist[j][i] = ndist;
        }
      }
    }
  }
  cin >> M;
  vector<LL> routes(M);
  REP(i, M) {
    int U, V;
    cin >> U >> V;
    --U; --V;
    routes[i] = dist[U][V];
  }
  int lmax = 1 << M;
  LL ret = 0;
  REP(i, lmax) {
    int ti = i;
    LL mask = 0;
    REP(j, M) {
      if((ti>>j)&1) {
        mask |= routes[j];
      }
    }
    LL used = __builtin_popcountll(mask);
    if(__builtin_parity(i) == 0) {
      ret += 1LL << (N - 1 - used);
    } else {
      ret -= 1LL << (N - 1 - used);
    }
  }
  cout << ret << endl;
}

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

int main(){
  ll t1, t2; cin >> t1 >> t2;
  ll a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2;
  ll suma = a1 * t1 + a2 * t2, sumb = b1 * t1 + b2 * t2;
  if(suma == sumb){
    cout << "infinity\n";
    return 0;
  }
  if((a1 > b1 && suma > sumb) || (a1 < b1 && suma < sumb)){
    cout << 0 << endl;
    return 0;
  }
  if(suma < sumb){
    swap(a1, b1);
    swap(a2, b2);
    swap(suma, sumb);
  }
  ll sa = suma - sumb;
  ll hani = (b1 - a1) * t1;
  ll ans = 1 + (hani / sa) * 2;
  if(hani % sa == 0){
    ans--;
  }
  /*cout << a1 << " " << a2 << " " << b1 << " " << b2 << endl;
  cout << suma << " " << sumb << endl;
  cout << hani << " "<< sa << endl;*/
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,l,r,cnt,dp[100005][2],hed[100005][2];
string st;
char c;
int main()
{
	cin>>st;st=" "+st;
	for (c='a';c<='z';c++)
	{
		dp[1][0]=1<<25;
		hed[1][0]=-1;
		dp[1][1]=(st[1]!=c);
		hed[1][1]=1;
		for (i=2;i<st.length();i++)
		{
			dp[i][0]=dp[i-1][1]+1-(c==st[i]);
			hed[i][0]=hed[i-1][1];
			dp[i][1]=dp[i-1][0]-(c==st[i]);
			hed[i][1]=hed[i-1][0];
			if (dp[i][0]<1)
			{
				cout<<hed[i][0]<<' '<<i<<endl;
				return 0;
			}
			if (dp[i][1]<1)
			{
				cout<<hed[i][1]<<' '<<i<<endl;
				return 0;
			}
			if (dp[i][1]>(c!=st[i]))
			{
				dp[i][1]=(c!=st[i]);
				hed[i][1]=i;
			}
		}
	}
	cout<<"-1 -1\n";
	return 0;
}

Measured memory_bytes: 2044
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let mut tok = line.split_whitespace();
    let mut s: i64 = tok.next().unwrap().parse().unwrap();
    let mut w: i64 = tok.next().unwrap().parse().unwrap();
    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2092
from heapq import heapify,heappush,heappop

N,M = map(int,input().split())
a = list(map(int,input().split()))
a = [(-x, x) for x in a]

heapify(a)

for m in range(M):
  max_ = heappop(a)
  a_ = max_[1]//2
  heappush(a,(-a_,a_))

ans=0
for a_ in a:
  ans+=a_[1]
print(ans)

Measured memory_bytes: 17352
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {

    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    map<int, int> table;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        table[A] ++;
    }
    for(auto& a : table) {
        if ( a.second > 1 ) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

const int maxn = 200010;
int n, a[maxn];
map<long long, int> mp;

int main() {
    scanf("%d", &n);
    long long cur = 0, ans = 0;
    mp[0]++;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]), cur += a[i];
        ans += mp[cur]++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 13568