akhauriyash/Code-Regression huggingface dataset:
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && arr[left] > arr[largest]) largest = left;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110716
#include<iostream>
#include<string>
#include<queue>

using namespace std;

int main()
{
    priority_queue<int> pq;
    while (true)
    {
        string com;
        cin>>com;
        if(com=="insert")
        {
            int num;
            cin>>num;
            pq.push(num);
        }
        else if(com=="extract")
        {
            int num=pq.top();
            pq.pop();
            cout<<num<<endl;
        }
        else if(com=="end")break;
    }

    return 0;
}



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

ll rec(ll cur){
	if (cur == 1)return 1;
	else return 1LL + 2LL * rec(cur/2LL);
}

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

	ll H;
	cin >> H;
	puts(rec(H));
	
	return 0;
}

Measured memory_bytes: 256
line = input('')
A = line.split(' ')[0]
B = line.split(' ')[1]
C = line.split(' ')[2]

cnt_a = [A,B,C].count(A)
cnt_b = [A,B,C].count(B)
cnt_c = [A,B,C].count(C)

if cnt_a == 3:
  print("No")
elif cnt_a == 2 or cnt_b == 2 or cnt_c == 2:
  print("Yes")
else:
  print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i<n; i++)
int main()
{
	ll a,b,c,d,ans;
	cin >> a >> b >> c >> d;

	ans = a*c;
	if(ans < a*d)
		ans = a*d;
	if(ans < b*c)
		ans = b*c;
	if(ans < b*d)
		ans = b*d;

	cout << ans;

	cin >> ans;
		
	return 0;	
}


Measured memory_bytes: 3628
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  static int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),c=CH(),p=0,m=0,z=0,A[200000];
  long K=0,count=0,l=-2e18,r=-l,mid,x;while(c>47&&c<58){K=K*10+c-48,c=CH();}
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if((K>1l*m*p)&&(2*K<2l*m*p+1l*z*(N-1)))return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;x=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=x;if(count>=K){r=mid-1l;continue;}
      rep(i,p){while(i<plus&&(1l*A[i]*A[plus]>mid)){plus--;}if(i==plus){break;}count+=1l*plus-i;}if(count>=K){r=mid-1l;continue;}
      rep(i,m){while(i<minus&&(1l*A[m+p-1-i]*A[m+p-1-minus]>mid)){minus--;}if(i==minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
inline int read(){
	#define gc getchar
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
	#undef gc
}
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
inline int add(const int&a,const int&b){return a+b>=mod?a+b-mod:a+b;}
inline int dec(const int&a,const int&b){return a>=b?a-b:a-b+mod;}
inline int mul(const int&a,const int&b){return (ll)a*b%mod;}
inline void Add(int&a,const int&b){a=a+b>=mod?a+b-mod:a+b;}
inline void Dec(int&a,const int&b){a=a>=b?a-b:a-b+mod;}
inline void Mul(int&a,const int&b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,a=mul(a,a))if(p&1)Mul(ret,a);return ret;}
int main(){
	int a=read(),b=read(),c=read();
	cout<<max(0,c+b-a);
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const aList = input[1].split(' ').map(x => parseInt(x, 10));

    const gcd = function(a, b) {
        if ( ! b) {
            return a;
        }
    
        return gcd(b, a % b);
    };

    const lList = [0];
    const rList = [0];
    var newL = 0;
    var newR = 0;
    for (var i = 0; i < N; i++) {
        newL = gcd(newL, aList[i]);
        lList.push(newL);
        newR = gcd(newR, aList[N - i - 1]);
        rList.unshift(newR);
    }

    var max = 0;
    for (var i = 0; i < N; i++) {
        var result = gcd(lList[i], rList[i + 1]);
        max = Math.max(max, result);
    }

    console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Console.Write(n + ":");

            if (n < 2) Console.Write(" " + n);

            while (n % 2 == 0)
            {
                n /= 2;
                Console.Write(" " + 2);
            }

            for (int i = 3; i <= n; i += 2)
            {
                while (n % i == 0)
                {
                    n /= i;
                    Console.Write(" " + i);
                }
            }

            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9224
const main = (input) => {
    input = input.split('\n');
    const a = Number(input[0]);
    const s = input[1];

    if (a >= 3200) {
        console.log(s);
    } else {
        console.log('red');
    }
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(a == b) {
    	cout << "YES";
    }
    else if(a < b) {
    	a += v * t;
    	b += w * t;
    	if(a >= b) cout << "YES";
    	else cout << "NO";
    }
    else {
    	a -= v * t;
    	b -= w * t;
    	if(a <= b) cout << "YES";
    	else cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

    static double[] getLine(double x1, double y1, double x2, double y2){
	double[] ans = new double[3];
	double mid_x = (x1 + x2) / 2;
	double mid_y = (y1 + y2) / 2;
	ans[0] = y1 - y2;
	ans[1] = x1 - x2;
	ans[2] = - mid_y * (y1 - y2) - mid_x * (x1 - x2);
	return ans;
    }
    
    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	double[] co = new double[6];
	for(int i = 0; i < n; i++){
	    for(int j = 0; j < co.length; j++){
		co[j] = stdin.nextDouble();
	    }
	    double[] l1 = getLine(co[0], co[1], co[2], co[3]);
	    double[] l2 = getLine(co[0], co[1], co[4], co[5]);
	    
	    double x = (l1[0] * l2[2] - l1[2] * l2[0]) / (l1[1] * l2[0] - l1[0] * l2[1]);
	    double y;
	    if(l1[0] != 0){
		y = (l1[1] * x + l1[2]) / -l1[0];
	    } else {
		y = (l2[1] * x + l2[2]) / -l2[0];
	    }	    
	    double r = Math.sqrt(Math.pow(x - co[0], 2) + Math.pow(y - co[1] , 2));
	    System.out.printf("%.3f %.3f %.3f\n", x, y, r);
	}
    }
    
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
using namespace std;

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

    string S[210000];
    rep(i, N) cin >> S[i];

    set<string> st;
    rep(i, N) {
      st.insert(S[i]); // 値を追加．すでに格納されている場合無視される．
    }

    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 25680
#include<iostream>
int main()
{
	long int i = 0;
	long int N;
	long int a[10000];
	long int min = 0, max = 0, sum = 0;
		std::cin >> N;
	for ( i = 0; i < N; ++i )
	{
		std::cin >> a[i];
		min = a[0];
		max = a[0];
	}
	for ( i = 0; i < N; ++i )
	{
		sum += a[i];
		if ( a[i] <= min )
		{
			min = a[i];
		}
		if ( a[i] >= max )
		{
			max = a[i];
		}
	}
	std::cout << min << " " << max << " " << sum << std::endl;
	return 0;
}


Measured memory_bytes: 3148
# coding: utf-8
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
B = [[A[i][j] for i in range(H)] for j in range(W)]
check_H = sorted([i for i in range(H) if '#' not in A[i]], reverse=True)
check_W = sorted([i for i in range(W) if '#' not in B[i]], reverse=True)
for i in check_H:
    A = A[:i] + A[i + 1:]
for i in check_W:
    for j in range(len(A)):
        A[j] = A[j][:i] + A[j][i + 1:]
for a in A:
    print(''.join(a))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	bool b=0;
	string s, t;
	cin>>s>>t;
	rep(i, s.size()){
		if(s[i]!=t[i])
			b=1;
	}
	if(b==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll l,r,d;
    cin>>l>>r>>d;
    ll val=r/d;
    ll val1=(l/d);
    if(l%d) val1+=1;
    ll ans=val-val1+1;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3608
sw, li = [int(i) for i in input().split(" ")]
sw_lists = []
sw_arr = [1 for _ in range(sw)]
ans = 0

for i in range(li):
    sw_list = []
    sw_list = [int(j) - 1 for j in input().split(" ")][1:]
    sw_lists.append(sw_list)

sw_mod = [int(i) for i in input().split(" ")]

for i in range(2 ** sw):
    ena_sw = [0 for _ in range(sw)]
    ena_nums = []

    for j in (range(sw)):
        if (i >> j) & 1:
            ena_sw[j] = 1
    
    for j in sw_lists:
        ena_num = []
        for k in j:
            ena_num.append(ena_sw[k])
        ena_nums.append(ena_num)
    
    for ena_num,mod in zip(ena_nums, sw_mod):
        if (sum(ena_num) % 2) != mod:
            break
    else:
        ans += 1
print(ans)

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

int findDigitSum(int i) {
  int sum = 0;
  while (0 < i) {
    sum += i % 10;
    i /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int answer = 100000000;
  for (int A = 1; A <= N / 2; A++) {
    int B = N - A;
    int sum = findDigitSum(A) + findDigitSum(B);
    answer = min(sum, answer);
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#ゴーレム判定関数
#pos=位置
#s=文字列
def survive(pos,s,spell,move,N):
    for i in range(0,len(spell)):
        if(s[pos]==spell[i]):
            pos+=move[i]
        #ゴーレムが消えたか判定
        if(pos<0):
            return -1
        elif(pos>N-1):
            return 1
    return 0

N,Q=map(int,input().split())
s=str(input())
tmp1=""
tmp2=""
tmp=0
#AとかBとかそういう奴らがどのくらい動くのかをカウント
spell=[]
move=[]
for time in range(0,Q):
    tmp1,tmp2=map(str,input().split())
    spell.append(tmp1)
    if(tmp2=="L"):
        move.append(-1)
    elif(tmp2=="R"):
        move.append(1)
left_result=-1
right_result=N
#右にoutしていくやつのうちもっとも左のやつを探す
left=0
right=N-1
mid=0
judge=False
#何も右から出ていかないパターン
if(survive(N-1,s,spell,move,N)!=1):
    right_result=N
#全て右から出ていくパターン
elif(survive(0,s,spell,move,N)==1):
    right_result=0
else:
    while ((right+left)//2)!=mid:
        mid=(right+left)//2
        judge=survive(mid,s,spell,move,N)
        if(judge==1):
            right=mid
        else:
            left=mid
    right_result=right

#左にoutしていくやつのうちもっとも右のやつを探す
left=0
right=N-1
mid=0
judge=False
#何も左から出ていかないパターン
if(survive(0,s,spell,move,N)!=-1):
    left_result=-1
#全て左から出ていくパターン
elif(survive(N-1,s,spell,move,N)==-1):
    left_result=N-1
else:
    while ((right+left)//2)!=mid:
        mid=(right+left)//2
        judge=survive(mid,s,spell,move,N)
        if(judge==-1):
            left=mid
        else:
            right=mid
    left_result=left

ans=right_result-left_result-1
print(ans)

Measured memory_bytes: 6788
import java.util.*;

class Main {
	public static void main(String[] args){
		List<String> list = new LinkedList<String>();

		String[] mark = {"S", "H", "C", "D"};

		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				list.add(mark[i] + " " + (j + 1));
			}
		}

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());
		
		for(int i = 0; i < n; i++){
			list.remove(sc.nextLine());
		}

		for(String str : list){
			System.out.println(str);
		}
		
	}
}

Measured memory_bytes: 17300
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main()
{
  int x1,x2,x3,x4,x5;
  in x1>>x2>>x3>>x4>>x5;
  int ans=0;
  if(x1==0)ans=1;
  if(x2==0)ans=2;
  if(x3==0)ans=3;
  if(x4==0)ans=4;
  if(x5==0)ans=5;

  cout<< ans <<endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define M 3010
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x) ; i <= (y); i ++) 
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	} while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	} return x * f;
}
char s[M]; int sum[M];
int r[M];
int f[M][M];
int main() {
	int n = read(), m = read();
	scanf("%s", s + 1);
	rep(i, 1, n) sum[i] = sum[i - 1] + (s[i] == '1');
	rep(i, 1, n) r[i] = i;
	rep(i, 1, m) {
		int x = read(), y = read();
		r[x] = max(r[x], y);
	} rep(i, 1, n) r[i] = max(r[i - 1], r[i]);
	f[0][0] = 1;
	rep(i, 1, n) {
		rep(j, 0, sum[r[i - 1]]) if(f[i - 1][j]) {
			if(sum[r[i]] > j) (f[i][j + 1] += f[i - 1][j]) %= MOD;
			if(sum[r[i]] - j < r[i] - i + 1) (f[i][j] += f[i - 1][j]) %= MOD;
		}
	} cout << f[n][sum[n]];
	return 0;
}

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

using namespace std;

int N, a[209];
long long ans = 0;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=2 * N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + 2 * N + 1);
for (int i=2 * N - 1; i>=1; i-=2)
    ans += a[i];
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"sort"
	"strconv"
	"strings"
)

func mapf(f interface{}, list interface{}) interface{} {
	fv, listv := reflect.ValueOf(f), reflect.ValueOf(list)

	if fv.Kind() != reflect.Func || listv.Kind() != reflect.Slice {
		return nil
	}

	len := listv.Len()
	ret := reflect.MakeSlice(reflect.SliceOf(fv.Type().Out(0)), len, listv.Cap())

	for i := 0; i < len; i++ {
		v := fv.Call([]reflect.Value{listv.Index(i)})
		ret.Index(i).Set(v[0])
	}

	return ret.Interface()
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	arr, _ := mapf(strconv.Atoi, strings.Split(scanner.Text(), " ")).([]int)
	sort.Ints(arr)

	fmt.Println(strings.Trim(fmt.Sprint(arr), "[]"))
}



Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
long long n,v[123456],c;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
        c+=v[i];
        c-=i+1;
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3880
import sys
from itertools import permutations

input = sys.stdin.readline


def main():
    N, C = map(int, input().split())
    D = [None] * C
    for i in range(C):
        D[i] = tuple(map(int, input().split()))
    A = [None] * N
    for i in range(N):
        A[i] = tuple(map(int, input().split()))

    R = [[0] * C for _ in range(3)]
    for i in range(N):
        for j in range(N):
            R[(i + j + 2) % 3][A[i][j] - 1] += 1

    cost = [[0] * C for _ in range(3)]
    for r in range(3):
        for Y in range(C):
            tmp = 0
            for X, num in enumerate(R[r]):
                tmp += D[X][Y] * num
            cost[r][Y] = tmp

    ans = float("inf")
    for c0, c1, c2 in permutations(range(C), r=3):
        ans = min(ans, cost[0][c0] + cost[1][c1] + cost[2][c2])

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int N;
  cin >> N;
  int X = N;
  int sumX = X % 10;
  while (X / 10 > 0) {
    X /= 10;
    sumX += X % 10;
  }
  
  if (N % sumX == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
int a[200010];
ll cnt[2][200010];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        if (i - a[i] >= 0) cnt[0][i-a[i]]++;
        if (i + a[i] < n) cnt[1][i + a[i]]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += cnt[0][i] * cnt[1][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7540
#include <bits/stdc++.h>
#define maxn 3000
using namespace std;

int n;
double p[maxn];
double dp[maxn][maxn];

int main() {
	scanf("%d",&n);
	for( int i = 1 ; i <= n ; i++ )
		scanf("%lf",&p[i]);
	dp[0][0] = 1;
	for( int i = 1 ; i <= n ; i++ )
		for( int j = 0 ; j <= i ; j++ ) {
			if(j)
				dp[i][j] = dp[i-1][j-1] * p[i];
			dp[i][j] += dp[i-1][j] * (1-p[i]);
		}
	double ans = 0;
	for( int i = n/2+1 ; i <= n ; i++ )
		ans += dp[n][i];
	printf("%.10lf\n",ans);
	return 0;
}


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

int main(){
  int h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      string s;
      cin>>s;
      if(s=="snuke"){
        char ans=j+65;
        cout<<ans<<i+1<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string n;
int a,i;
int main()
{
    cin>>n;
    a=n.length();
   for(i=0;i<a;i++)
   {
       if(n[i]==',')
       cout<<" ";
       else
       cout<<n[i];
   }cout<<"\n";
    return 0;
}

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

using namespace std;
#define ll long long

#define N 100005
ll in[N];
void solve() {
    ll ret = 0;
    int n;scanf("%d",&n);
    for(int i=0;i<n;++i) {
        scanf("%lld",&in[i]);
        ret ^=in[i];
    }
    for(int i=0;i<n;++i) {
        ll tmp = in[i]&ret;
        in[i] -= tmp;
    }
    sort(in,in+n,greater<ll>());
    int pos = 0;
    for(int i=60;i>=0;--i) {
        int ind = -1;ll tmp = -1e18;
        for(int j=pos;j<n;++j) {
            if(in[j]&(1LL<<i)   && tmp<in[j]) {
                swap(in[pos],in[j]);
                tmp = in[j];
                break;
            }
        }
        if(tmp==-1e18) {
            int cc = 0;
            for(int j = 0;j<pos;++j) {
                if(in[j]&(1LL<<i)) {
                    ++cc;
                }
            }
            if(cc&1) {
                ret += (1LL<<i)*2;
            }
            continue;
        }
        ll org = in[pos];
        in[ind] = 0;
        ret += (1LL<<i)*2;
        for(int j=0;j<n;++j) {
            if(in[j]&(1LL<<i) && j!=pos) {
                in[j]^= org;
            }
        }
        ++pos;
    }
    printf("%lld\n",ret);
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int ke(long long int n){
  int c=1;
  while(1){
    if(n/10==0)return c;
    n/=10;
    c++;
  }
}
      
int main(){
  long long int n;
  int mi=11;
  cin >> n;
  for(long long int i=1;i*i<=n;i++){
    if(n%i==0){
      mi=min(mi,ke(n/i));
      // cout << i << endl;
    }
  }
  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

counts = []

class Node:
    def __init__(self):
        self.edge = []
        self.count = 0

def dfs(tree,node,p_node,p_count):
    count = tree[node].count + p_count
    counts[node] = count
    for x in tree[node].edge:
        if x == p_node:
            continue
        dfs(tree,x,node,count)

N,Q = inm()

tree = []
for _ in range(N):
    tree.append(Node())

#node = Node()
#tree = [node]*N

for _ in range(N-1):
    a,b = inm()
    tree[a-1].edge.append(b-1)
    tree[b-1].edge.append(a-1)

for _ in range(Q):
    p,x = inm()
    tree[p-1].count += x

for _ in range(N):
    counts.append(0)

#for i in range(N):
#    print(tree[i].edge)
#    print(tree[i].count)


dfs(tree,0,-1,0)

counts_str = [str(n) for n in counts]
s = " ".join(counts_str)
print(s)


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long


using namespace std;
const ll maxn=2e5+100,inf=1e18,LOG=23,mod=1e9+7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
#define int ll
#define pii pair <int, int>

int n, a[maxn], tin[maxn], tout[maxn], sz[maxn], b[maxn];
vector <int> color[maxn], edge[maxn];
vector <int> adds;
set <pii> st;

bool cmp(int i, int j)
{
	return tin[i] < tin[j];
}

void dfs(int v, int pred = -1)
{
	sz[v] = 1;
	tin[v] = ++timer;
	for(auto to : edge[v])
	{
		if(to == pred) continue;
		dfs(to, v);
		sz[v] += sz[to];
	}
	tout[v] = ++timer;
}

main()
{
	IOS
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
		color[a[i]].pb(i);
	}
	edge[0].pb(1);
	edge[1].pb(0);
	forn(1, i, n)
	{
		color[i].pb(0);
	}
	forn(1, i, n - 1)
	{
		int l, r;
		cin >> l >> r;
		edge[l].pb(r);
		edge[r].pb(l);
	}
	dfs(0);
	forn(1, i, n)
	{
		adds.clear();
		sort(all(color[i]), cmp);
		for(auto j : color[i])
		{
			for(auto to : edge[j])
			{
				if(tin[to] >= tin[j])
				{
					adds.pb(to);
					b[to] = sz[to];
				}
			}
		}
		sort(all(adds), cmp);
		int uk = 0;
		st.clear();
		for(auto j : color[i])
		{
			while(uk < adds.size() && tin[adds[uk]] <= tin[j])
			{
				st.insert({tout[adds[uk]], adds[uk]});
				uk++;
			}
			auto it = st.upper_bound(mp(tout[j], 0ll));
			if(it != st.end())
			{
				b[it->s] -= sz[j];
			}
		}
		int ans = n*(n+1)/2;
		for(auto j : adds)
		{
			ans -= b[j] * (b[j] + 1) / 2;
		}
		cout << ans << " ";
	}
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define nl "\n"
#define ump unordered_map<ll , ll>

void doit(){
	ll n,tox=0,i,j;
	cin >> n;
	vector< ll >v(n);
	for(i = 0; i < n; i++){
		cin>>v[i];
		tox^=v[i];
	}
	rep(i,0,n){
		cout << (tox^v[i]) <<" ";
	}
	
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	// cin >> t;
	for(ll i = 1; i <= t; i++){
		doit();
	}
}


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

int main() {
    int D; //365
    cin >> D;

    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }

    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }

    int t[D] = {};
    srand(time(NULL));
    rep(i, 0, D) {
        t[i] = rand() % 26;
    }

    ll mx_score = -1;
    int cnt = 100000;
    while (cnt--) {
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            //増加分
            score[i] += s[i][t[i]];

            last_day[t[i]] = i;

            //減少分
            int decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
using namespace std;
using ll = long long;
int main(){
	ll a,b,c,x,y,ans;
	cin >> a >> b >> c >> x >> y;
	if((a+b)>=2*c){
		if(x>=y){
			ans = min(y*2*c+(x-y)*a,x*2*c);
		}
		else{
			ans = min(x*2*c+(y-x)*b,y*2*c);
		}
		cout << ans << endl;
	}
	else{
		cout << a*x+b*y << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> 
struct ModInt {
    using u64 = std::uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    bool operator==(const ModInt &p) const {return a == p.a;}
    bool operator!=(const ModInt &p) const {return a != p.a;}

    ModInt pow(long long N) const {
        ModInt ret(1), mul(a);
        while(N > 0) {
            if(N & 1) ret *= mul;
            mul *= mul;
            N >>= 1;
        }
        return ret;
    }
};

using mint = ModInt<MOD>;

mint dp[401][401];
mint S[401][401];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,C; cin >> N >> C;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    rep(i,400) S[0][i+1] = 1;
    rep(i,400) {
        rep(j,401) {
            S[i+1][j] = S[i][j]*j;
        }
    }
    rep(j,400) {
        rep(i,401) S[i][j+1] += S[i][j];
    }
    dp[0][0] = 1;
    rep(i,N) {
        rep(j,C+1) {
            rep(k,j+1) {
                dp[i+1][j] += dp[i][k]*(S[j-k][B[i]]-S[j-k][A[i]-1]);
            }
        }
    }

    cout << dp[N][C].a << ln;
}

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


int mx[128];
vector<int> adjList[128];
pair<int,int> edges[128];

void dfs(int u,int p,int l){
	int kids = 0;
	for(auto v: adjList[u]) if(v != p){
		kids += 1;
		dfs(v,u,l+1);
	}
	mx[l] = max(mx[l],kids);
}


int main(){
	int N;cin>>N;
	for(int i=0;i<N-1;i++){
		int u,v;cin>>u>>v;
		u--;v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
		edges[i] = make_pair(u,v);
	}
	
	long long blevel = N+1,bleafs = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=N;j++) mx[j] = 0;
		dfs(i,-1,0);
		int cl = 1;
		for(int j=0;j<=N;j++) if(mx[j] != 0) cl = j + 2;
		if(cl < blevel){
			blevel = cl;
			long long total = 1;
			for(int j=0;j<N && mx[j] != 0;j++) total *= mx[j];
			bleafs = total;
		}else if(cl == blevel){
			long long total = 1;
			for(int j=0;j<N && mx[j] != 0;j++) total *= mx[j];
			bleafs = min(bleafs,total);
		}
	}

	for(int i=0;i<N-1;i++){
		int x = edges[i].first,y = edges[i].second;
		for(int j=0;j<=N;j++) mx[j] = 0;
		dfs(x,y,0);
		dfs(y,x,0);
		int cl = 1;
		for(int j=0;j<=N;j++) if(mx[j] != 0) cl = j + 2;
		if(cl < blevel){
			blevel = cl;
			long long total = 2;
			for(int j=0;j<N && mx[j] != 0;j++) total *= mx[j];
			bleafs = total;
		}else if(cl == blevel){
			long long total = 2;
			for(int j=0;j<N && mx[j] != 0;j++) total *= mx[j];
			bleafs = min(bleafs,total);
		}
	}
	
	cout<<blevel<<" "<<bleafs<<endl;
	return 0;
}

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

int main()
{
    int numPoint;
    int numDim;

    cin >> numPoint >> numDim;

    vector<vector<int>> point(numPoint + 1, vector<int>(numDim + 1, 0));

    for (int i = 1; i <= numPoint; i++)
    {
        for (int j = 1; j <= numDim; j++)
        {
            cin >> point[i][j];
        }
    }

    int ans = 0;

    //ここから距離を計算。
    for (int i = 1; i <= numPoint; i++)
    {
        for (int j = i + 1; j <= numPoint; j++)
        {
            //点iと点jの距離を計算する
            float distance;
            float temp0 = 0;
            for (int k = 1; k <= numDim; k++)
            {
                float temp = point.at(i).at(k) - point.at(j).at(k);
                temp0 = temp0 + (temp * temp);
            }

            distance = sqrt(temp0);

            int distanceInteger = distance;

            float distanceFloat = distanceInteger;

            if(distance - distanceFloat == 0)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import product


def check(N, p, X):
    for i in range(N):
        if p[i] == 0:
            continue
        for j in range(N):
            if X[i][j] is not None and X[i][j] != p[j]:
                return False
    return True


def main():
    N = int(input())
    X = [[None] * N for _ in range(N)]
    for i in range(N):
        A = int(input())
        for j in range(A):
            x, y = map(int, input().split())
            X[i][x-1] = y
    ans = 0
    for p in product([0, 1], repeat=N):
        if check(N, p, X):
            ans = max(ans, sum(p))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44764
#include<stdio.h>
int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    while (a > 0 && c > 0)
    {
        c = c - b;
        if (c > 0)
        {
            a = a - d;
        }

    }
    if (c <= 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }


    return 0;
}

Measured memory_bytes: 1612
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
const int N = 1e3 + 10;
char s[N];
ll K, a[N];
const ll d[] = {1, 9, 81, 729};

ll C(ll x, ll k) {
    if (k == 1) return x;
    else if (k == 2) return x * (x - 1) / 2;
    else return x * (x - 1) * (x - 2) / 6;
}

ll solve(ll now, ll k, bool f) {
    if (now < k) return 0;
    if (!k) return 1;
    if (f) return C(now, k) * d[k];
    ll ret = solve(now - 1, k, a[now] ? 1 : f);
    if (a[now])
        ret += solve(now - 1, k - 1, f) + solve(now - 1, k - 1, 1) * (a[now] - 1);
    return ret;
}

int main() {
    scanf("%s", s + 1);
    ll n = strlen(s + 1);
    rep(i, 1, n) a[i] = s[i] - '0';
    reverse(a + 1, a + n + 1);
    cin >> K;
    printf("%lld\n", solve(n, K, 0));
    return 0;
}


Measured memory_bytes: 256
// abc137_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    map<string, ll> mp;
    vector<string> S(N);
    REP(i, N){
        cin >> S[i];
        sort(ALL(S[i]));
        mp[S[i]]++;
    }

    ll ans = 0;
    REP(i, N){
        ans += mp[S[i]] - 1;
    }

    print(ans / 2);

    return 0;
}


Measured memory_bytes: 16640
sum_ = [0]

N,M = input().split()
N,M = int(N),int(M)
m_ = []
for i in range(M):
    m_.append(int(input()))
#m = sorted(m)

m = [1 for i in range(N+1)]
for i in m_:
    m[i] = 0
for i in range(1,N+1):
    if(i==1):
        if(m[i]==1):
            sum_.append(1)
        else:
            sum_.append(0)
    elif(i==2):
        if(m[i]==1):
            sum_.append(1+sum_[1])
        else:
            sum_.append(sum_[1])
    
    else:
        sum_.append((m[i-1]*sum_[i-1]+m[i-2]*sum_[i-2])*m[i])
print(sum_[N]%1000000007)

Measured memory_bytes: 460904
#include<bits/stdc++.h>
#define LL long long


using namespace std;
const int maxn=1e5+5;
int gcd(int a , int b)
{
        return a%b==0? b:gcd(b,a%b);
}
inline LL quickread()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
int main()
{
    char s[200000+5];
    cin>>s;
    int len=strlen(s);
    int sum=0;
    for(int i=0;i<len;i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H1;
    int M1;
    int H2;
    int M2;
    int K;

    cin >> H1 >> M1 >> H2 >> M2 >> K;


    int wakeUpTime = H1 * 60 + M1;
    int sleepTime = H2 * 60 + M2;;

    int studyTime = sleepTime - wakeUpTime - K;

    printf("%d\n",studyTime);

	return 0;
}

Measured memory_bytes: 3764
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
typedef long long ll;
typedef long double ld;
 

 
ll MOD=1e9 + 7;
ll OO=1e17;
const int N=5e5 + 10,M=10 + 1;
ll arr[N];
int ans[N];


int n,m,k,T,cnt,SU;
ll a,b,c,d;
ll l,r,mid;
int val;



ll Power(ll n,ll m,ll p){
	n%=p;
	ll cnt = 1;
	while(m){
		if(m&1)
			cnt = (cnt*n)%p;
		
		n = (n * n)%MOD;
		m>>=1;
	}
	
	return cnt;
}


ll inv(ll n,ll p){
	return Power(n,p-2,p);
}



ll Gun(){
	arr[0] = 1;
	for(int i=1;i<N;++i){
		arr[i] = arr[i-1]*i;
		arr[i] %= MOD;
	}
}

ll mul(ll x,ll y){
	return x * y % MOD;
}

ll nPr(int n,int r){
	ll p = arr[n];
	ll x = arr[n-r];
	
	x = inv(x,MOD);
	p = mul(x,p);
	return p;
}


ll nCr(int n,int r){
	
	ll p = arr[n];
	ll x = mul(arr[n-r],arr[r]);
	x = inv(x,MOD);
	p = mul(x,p);
	return p;
}

ll valid(ll n){
	if(n%2 == 0 || n%5 == 0)
		return -1;
	
	ll val = 7;
	int len = 1;
	while(val%n){
		val *= 10;
		val += 7;
		val %= n;
		++len;
	}
	
	return len;
}


int main(){

	cin>>n;
	
	cout<<valid(n)<<endl;
	
}




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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int A[n];
    for(int i = 0; i < n; i++){
        A[i] = k - q;
    }
    for(int i = 0; i < q; i++){
        int ans;
        cin >> ans;
        A[ans - 1] += 1;
    }
    for(int i = 0; i < n; i++){
        if(A[i] <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int N;
int main(){
    cin >> N;
    for(int i=1;i <= 9; i++){
        if(N<=111*i && N > 111*(i-1) ){
            N = 111*i;
            break;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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 (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;

  vector<ll> v(n);
  vector<ll> c(n);

  rep(i,n) cin>>v[i];
  rep(i,n) cin>>c[i];

  ll ans=0;

  rep(i,n){
    if(v[i]-c[i]>0) ans+=v[i]-c[i];
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)

n=int(input())
A=list(map(int,input().split()))
L=[0]*(n+1)
R=[0]*(n+1)
for i in range(n):
    L[i+1]=gcd(L[i],A[i])
for i in reversed(range(n)):
    R[i]=gcd(R[i+1],A[i])
ans=0
for i in range(n):
    ans=max(ans,gcd(L[i],R[i+1]))
print(ans)

Measured memory_bytes: 59632
S = input()

l = len(S)
MOD = 10**9+7
dp = [[0 for i in range(13)] for j in range(l+1)]
dp[0][0] = 1
for i in range(l):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k] % MOD
    else:
        for k in range(13):
            dp[i+1][(k*10+int(S[i]))%13] += dp[i][k] % MOD

print(dp[-1][5] % MOD)

Measured memory_bytes: 66012
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> cmp;
	int size;
	UnionFind(int n) :size(n) {
		par.resize(size);
		rank.resize(size);
		cmp.resize(size);
		for (int i = 0; i < size; i++) {
			par[i] = i;
			rank[i] = 0;
			cmp[i] = 1;
		}
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			cmp[y] += cmp[x];
		}
		else {
			par[y] = x;
			cmp[x] += cmp[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		x = find(x);
		y = find(y);
		return x == y;
	}
};
map<int, int> cnt[200000];
int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind u1(N), u2(N);
	for (int i = 0; i < K; i++) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		u1.unite(p, q);
	}
	for (int i = 0; i < L; i++) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		u2.unite(r, s);
	}
	for (int i = 0; i < N; i++) {
		int x = u1.find(i);
		int y = u2.find(i);
		cnt[x][y]++;
	}

	for (int i = 0; i < N; i++) {
		int x = u1.find(i);
		int y = u2.find(i);
		cout << cnt[x][y] << " ";
	}
	cout << endl;
 }


Measured memory_bytes: 23168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

#define MAX (40 * 40 * 10)
bool flag[MAX + 1] = { false };
int X[10][10];

int main()
{
	int N, D, d, ans = 0;

	for (int i = 1; i * i <= MAX; i++) flag[i * i] = true;

	cin >> N >> D;
	rep(i, N) rep(j, D) cin >> X[i][j];

	repc(i, 0, N - 2) {
		repc(j, i + 1, N - 1) {
			d = 0;
			rep(k, D) d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			if (flag[d]) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    
    int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;
    for(int i = 0; i < 10; i++){
            cin>>s1>>s2>>s3>>s4>>s5>>s6>>s7>>s8>>s9>>s10;
}
cout<<s1+s2+s3+s4+s5+s6+s7+s8+s9+s10<<endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll d, g; cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    rep(i, d){
        cin >> p[i] >> c[i]; 
    }

    ll ans = INF;
    for(ll i = 0; i < (1<<d); i++){
        //cout << "{ ";

        ll highest_question = -1;
        ll current_ans = 0;
        ll current_score = 0;
        for(ll j = 0; j < d; j++){
            if(i & (1<<j)){
                //cout << j << " ";
                current_ans += p[j];
                current_score += p[j] * (100*(j+1)) + c[j];
            }else{
                highest_question = j;
            }
        }

        //cout << "} " << endl;
        if(current_score >= g){
            ans = min(ans, current_ans);
        }else{
            if(highest_question != -1){
                ll q = 100 * (highest_question + 1);
                ll need_q = ((g-current_score) + (q-1)) / q;
                if(need_q <= p[highest_question]){
                    ans = min(ans, current_ans + need_q);
                }
            }
        }
        //cout << current_score << endl;
        //cout << highest_question << endl;
    }
    cout << ans << endl;


}

Measured memory_bytes: 3612