akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
N, M = map(int, input().split())
b = [False] * N
l = [1] * N
b[0] = True
for i in range(M):
    x, y = map(int, input().split())
    if b[x-1] == True:
        b[y-1] = True
    if l[x-1] > 0:
        l[y-1] += 1
        l[x-1] -= 1
    if l[x-1] == 0:
        b[x-1] = False

ans = 0
for i in range(N):
    if b[i] == True and l[i] > 0:
        ans += 1
print(ans)

Measured memory_bytes: 4596
#include <stdio.h>

int main(void) {
    int n, a, b, pass, brank;
    scanf("%d %d %d", &n, &a, &b);
    char s;
    pass = 0; brank = 0;
    getchar();
    for (int i = 0; i < n; i++) {
        scanf("%c", &s);
        
        if (pass < a + b) {
            if (s == 'a') {
                printf("Yes\n");
                pass++;
            } else if (s == 'b' && brank < b) {
                printf("Yes\n");
                pass++;
                brank++;
            } else {
                printf("No\n");
            }
        } else {
            printf("No\n");
        }
    }
    return 0;
}

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

int main()
{
    const int mod = 1000000007;
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long ans = 0;
    bool parallel = true;
    for(int i=0; i<n;){
        if(i==0){
            if(a[i] == b[i]){
                ans = 3;
                parallel = false;
                i++;
            }else{
                ans = 6;
                parallel = true;
                i+=2;
            }
            continue;
        }
        if(a[i] == b[i]){
            if(!parallel) ans = ans*2 %mod;
            parallel = false;
            i++;
        }else{
            if(parallel){
                ans = ans*3%mod;
            }else{
                ans = ans*2%mod;
            }
            parallel = true;
            i+=2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def parth(h,m):
    hmin=min(h)
    hmax=max(h)
    if hmax<=0:
        return m
    else:
        m=m+hmin
        for i in range(len(h)):
            h[i]=h[i]-hmin
#        print(m,h)
        i=0
        while i<len(h):
            h2=[]
            while i<len(h) and h[i]>0:
                h2.append(h[i])
                i=i+1
            if len(h2)>0:
                m=parth(h2,m)                
            i=i+1    
        return m


n=int(input())
h=list(map(int,input().split()))

#n=4
#h=[1,2,2,1]

#n=5
#h=[3,1,2,3,1]

#n=8
#h=[4,23,75,0,23,96,50,100]

m=0
m=parth(h,m)
print(m)
           

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

typedef long long ll;
#define rep(i, n) for (int i = 1; i * i <= (int)(n); i++)

int main() {
    int MAX_N = 10002;
    
    int s[MAX_N];
    for(int i=0;i<MAX_N;++i)s[i]=0;
    
    for(int i=0;i<MAX_N;++i){
        rep(j,i){
            rep(k,i){
                rep(l,i-j*j-k*k-j*k){
                    if(j*j + k*k + l*l + j*k + k*l + l*j == i)++s[i];
                }
            }
        }
    }
    int n; cin>>n;
    for(int i = 1; i<=n; ++i)cout<<s[i]<<endl;
	return 0;
}

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

const int N = 2e5 + 1;

namespace dsu {

int id[N], sz[N];

void clear (int n = N - 1) { iota(id, id + n + 1, 0); fill_n(sz + 1, n, 1); }
int fs (int x) { return x == id[x] ? x : id[x] = fs(id[x]); }
bool ms (int x, int y) { if ((x = fs(x)) == (y = fs(y))) return false; id[y] = x; sz[x] += sz[y]; return true; }

};

struct T { int x, y, id; } a[N];


int main (void) {
  int n;
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i ++) {
    scanf("%d%d", &x, &y);
    a[i] = { x, y, i };
  }
  dsu::clear(n);
  sort(a + 1, a + n + 1, [&](T x, T y){ return x.x > y.x; });
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; j <= n && a[j].y <= a[i].y; j ++);
    for (int k = i; k < j; k ++) dsu::ms(a[i].id, a[k].id);
  }
  sort(a + 1, a + n + 1, [&](T x, T y){ return x.x < y.x; });
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; j <= n && a[j].y >= a[i].y; j ++);
    for (int k = i; k < j; k ++) dsu::ms(a[i].id, a[k].id);
  }
  sort(a + 1, a + n + 1, [&](T x, T y){ return x.y > y.y; });
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; j <= n && a[j].x <= a[i].x; j ++);
    for (int k = i; k < j; k ++) dsu::ms(a[i].id, a[k].id);
  }
  sort(a + 1, a + n + 1, [&](T x, T y){ return x.y < y.y; });
  for (int i = 1, j; i <= n; i = j) {
    for (j = i + 1; j <= n && a[j].x >= a[i].x; j ++);
    for (int k = i; k < j; k ++) dsu::ms(a[i].id, a[k].id);
  }
  for (int i = 1; i <= n; i ++)
    printf("%d\n", dsu::sz[dsu::fs(i)]);
}

Measured memory_bytes: 7736
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j;
string s[256],t[512];
string::size_type p,q,m,l;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>s[i];
m=0;
for(i=0;i<n;i++){
q=-1;
for(;;){
p=s[i].find('1',q+1);if(p==string::npos)break;
q=s[i].find('0',p+1);if(q==string::npos){if(m<n-p)m=n-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n;i++){
t[i]="";
for(j=0;j<n;j++)t[i]+=s[j][i];
}
for(i=0;i<n;i++){
q=-1;
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<n-p)m=n-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n*2-1;i++){
t[i]="";
for(j=0;j<n;j++){if(i-j>=0&&i-j<n)t[i]+=s[i-j][j];}
}
for(i=0;i<n*2-1;i++){
q=-1;l=t[i].size();
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<l-p)m=l-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n*2-1;i++){
t[i]="";
for(j=0;j<n;j++){if(n-i+j>=0&&n-i+j<n)t[i]+=s[n-i+j][j];}
}
for(i=0;i<n*2-1;i++){
q=-1;l=t[i].size();
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<l-p)m=l-p;break;}
if(m<q-p)m=q-p;
}
}
cout<<m<<endl;
}
return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ld long double
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int cnt[MAXN];
int a[MAXN];
int32_t main(){
	fastio;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	int res=0;
	for(int i=1;i<=n;i++){
		if(cnt[i]){
			res+=(cnt[i]*(cnt[i]-1))/2;
		}
	}
	
	for(int i=1;i<=n;i++){
		int cur = cnt[a[i]]-1;
		cout<<res-cur<<endl;
	}
	
}


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

int main(){
  int n,x,k;
  vector<int> v;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> x;
    v.push_back(x);
  }
  if(n==1) return 0;
  vector<int> dp(n,0);
  for(int i=n-2;i>=0;i--){
    dp[i]=INT_MAX;
    for(int j=i+1;j<=i+k && j<n;j++){
    	dp[i] = min(dp[i],abs(v[i]-v[j]) + dp[j]);
    }
  }
  cout << dp[0] << endl;
  return 0;
}
      


Measured memory_bytes: 1144
package main

import (
    "fmt"
    "sort"
)

func main() {
    // var n int
    // fmt.Scan(&n, &x)
    // nums := make([]int,n);
    // m := make(map[int]int)

    var a,b,c,d,n int
    fmt.Scan(&a,&b,&c,&d)
    fmt.Scan(&n)

    a*=4
    b*=2
    nums := []int{a,b,c}
    sort.Ints(nums)

    c=n*nums[0]
   	d=(n/2)*d

    if n%2==1 {
    	d+=nums[0]
    }

    if c>d {
    	c=d
    }

	fmt.Println(c)
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b, ans =0;
	string  s;
	cin >>a >>b;
	
	
	cout << (a>=13? b: a<=5? 0: b/2) <<"\n";
	return 0;
}


Measured memory_bytes: 256
from collections import deque
X = int(input())
q = deque([""])
N = "357"
ans = 0
while q:
    num = q.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            q.append(next_v)
            if "3" in next_v and "5" in next_v and "7" in next_v:
                ans += 1
print(ans)


Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> m(n, 1e9);
	for (int i = 0; i < n; i++)
	{
		cin >> m[i];
	}

	int ans = 0;

	for (int i = 0; i < n; i++)
	{
		x -= m[i];
		ans++;
	}

	while (x > 0)
	{
		x -= *min_element(m.begin(), m.end());
		if (x < 0)
		{
			break;
		}
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#d=日数, c=満足低下度, s=満足上昇度, t=コンテストの日程 
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
sa = []
for i in s:
  y = [k-l for (k,l) in zip(i, c)]
  sa.append(y)
t_lst = []
res = 0
last = [0 for i in range(26)]
#old = t[dq[j][0] - 1]
#t[dq[0] - 1] = dq[1]
for day in range(d):
  t = sa[day].index(max(sa[day])) + 1
  m = sa[day].index(max(sa[day]))
  res += s[day][m]
  last[m] = day + 1
  t_lst.append(t)
  combined1 = [x * (day + 1 - y) for (x, y) in zip(c, last)]
  res -= sum(combined1)
  #t[dq[j][0] - 1] = old
  print(t)



Measured memory_bytes: 9920
<?php
$score = [];
    while (true) {
        $cnt = trim(fgets(STDIN));
        if ($cnt == 0) {
                break;
        }
        $sumA = 0;
        $sumB = 0;
        for ($i = 0; $i < $cnt; $i++) {
                $score = explode(" ",trim(fgets(STDIN)));
                $scoreA = $score[0];
                $scoreB = $score[1];
                if ($scoreA > $scoreB) {
                    $sumA += $scoreA + $scoreB;
                } elseif ($scoreA < $scoreB) {
                    $sumB += $scoreA + $scoreB;
                } elseif ($scoreA == $scoreB) {
                    $sumA += $scoreA;
                    $sumB += $scoreB;
                }
        }
            echo $sumA . " " . $sumB . "\n";
    }
?>


Measured memory_bytes: 9252
w,h,n=map(int,input().split())
ax=0
ix=w
ay=0
iy=h

for i in range(n):
    x,y,a=map(int,input().split())
    if(a==1):
        ax=max(ax,x)
    elif(a==2):
        ix=min(ix,x)
    elif(a==3):
        ay=max(ay,y)
    else:
        iy=min(iy,y)

if(ax>=ix or ay>=iy):
    print('0')
    exit()

else:
    print((ix-ax)*(iy-ay))

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 100;

int main() {
    ll a, b, q, x;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    for (ll i = 0; i < a; i++) cin >> s[i];
    for (ll i = 0; i < b; i++) cin >> t[i];
    for (ll i = 0; i < q; i++) {
        cin >> x;
        ll d[2][2] = {{inf, inf},
                      {inf, inf}};
        ll r = inf;
        if (lower_bound(s.begin(), s.end(), x) != s.end())
            d[0][0] = (*lower_bound(s.begin(), s.end(), x)) - x;
        if (upper_bound(s.begin(), s.end(), x) != s.begin())
            d[0][1] = (*(upper_bound(s.begin(), s.end(), x) - 1)) - x;
        if (lower_bound(t.begin(), t.end(), x) != t.end())
            d[1][0] = (*lower_bound(t.begin(), t.end(), x)) - x;
        if (upper_bound(t.begin(), t.end(), x) != t.begin())
            d[1][1] = (*(upper_bound(t.begin(), t.end(), x) - 1)) - x;
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                if (d[0][j] != inf && d[1][k] != inf) r = min(r, abs(d[0][j]) + abs(d[0][j] - d[1][k]));
                if (d[1][j] != inf && d[0][k] != inf) r = min(r, abs(d[1][j]) + abs(d[1][j] - d[0][k]));
            }
        }
        cout << r << endl;
    }
}


Measured memory_bytes: 2944
use std::io::{self, BufRead};
use std::cmp::max;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let line = lines.next().unwrap().unwrap();
  let n: usize = line.parse().unwrap();
  let line = lines.next().unwrap().unwrap();
  let xs: Vec<i64> = line.split(' ').map(|x| x.parse().unwrap()).collect();
  let mut memo: Vec<i64> = vec![0; n];
  let mut leftmost: i64 = xs[0];
  for i in 1..n {
    if i == 1 {
      memo[i] = max(xs[0], xs[1]);
    } else if i % 2 == 0 {
      leftmost += xs[i];
      memo[i] = max(memo[i-2] + xs[i], memo[i-1]);
    } else {
      memo[i] = max(leftmost, memo[i-2] + xs[i]);
    }
  }
  println!("{}", memo[n-1]);
}

Measured memory_bytes: 7232
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int res,W,H,tile[20][20];
P start;

int bfs()
{
	int res = 1;
	queue<P> a;
	a.push(start);
	while (!a.empty()) {
		P temp = a.front();
		a.pop();
		if (temp.first + 1 < W && tile[temp.first + 1][temp.second]) {
			tile[temp.first + 1][temp.second] = 0;
			res++;
			a.push(P(temp.first + 1, temp.second));
		}
		if (temp.first - 1 >= 0 && tile[temp.first - 1][temp.second]) {
			tile[temp.first - 1][temp.second] = 0;
			res++;
			a.push(P(temp.first - 1, temp.second));
		}
		if (temp.second + 1 < H && tile[temp.first][temp.second + 1]) {
			tile[temp.first][temp.second + 1] = 0;
			res++;
			a.push(P(temp.first, temp.second + 1));
		}
		if (temp.second - 1 >= 0 && tile[temp.first][temp.second - 1]) {
			tile[temp.first][temp.second - 1] = 0;
			res++;
			a.push(P(temp.first, temp.second - 1));
		}
	}
	return res;
}

int main()
{
	char ch;
	while (cin >> W >> H, W || H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> ch;
				if (ch == '.') {
					tile[j][i] = 1;
				}
				else if (ch == '#') {
					tile[j][i] = 0;
				}
				else {
					tile[j][i] = 0;
					start = P(j,i);
				}
			}
		}
		cout << bfs() << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#  --*-coding:utf-8-*--

def main():
    N, K, Q = map(int, input().split())
    S = [0]*N

    for _ in range(Q):
        A = int(input())
        S[A-1]+= 1

    T = Q - K + 1

    for s in S:
        print('Yes' if s >= T else 'No')




if __name__ == '__main__':
    main()


Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll smod=998244353;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;




ll kaijou[200000+1];
ll gyakugen[200000+1];
long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%smod,y/2);
    else return x*ruijou(x,y-1)%smod;
}

ll combination(ll n,ll c){
    if(n<c)return 0;
    return ((kaijou[n]*gyakugen[c])%smod)*gyakugen[n-c]%smod;
}
ll mo(ll x){
    ll ans=x%smod;
    if(x>=0)return ans;
    return ans+smod;
}




ll i,j,k;


int main(){
  ll N,M,K;
  cin>>N>>M>>K;
  ll ans=0;
  kaijou[0]=1;
  for(ll i=1;i<=N;i++)kaijou[i]=kaijou[i-1]*i%smod;
  gyakugen[0]=1;
  for(ll i=1;i<=N;i++)gyakugen[i]=gyakugen[i-1]*ruijou(i,smod-2)%smod;

  for(ll k=0;k<=K;k++){
      ans+=(ruijou(M-1,N-k-1)*M)%smod*combination(N-1,k)%smod;
      ans%=smod;
  }
  if(ans>=0)cout<<ans<<endl;
  else cout<<(ans+smod)%smod<<endl;
 
  
  
}


Measured memory_bytes: 6700
import bisect
import math
n = int(input())
a = list(map(int,input().split()))

s = [0]*(n+1)

for i,e in enumerate(a):
    s[i+1] = s[i] + e

def comb(n,m):
    return math.factorial(n)//math.factorial(m)//math.factorial(n-m)

ans = 0
s = sorted(s)

l = 0
r = 0
#print(s)
while l < n+1:
    while r < n+1  and s[l] == s[r]:
        #print(r,s[r])
        r += 1

    if r-l >= 2:
        ans += comb(r-l,2)
    l = r

print(ans)


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

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


Measured memory_bytes: 256
class Dice
    attr_reader :top, :front, :right, :left, :back, :bottom

    def initialize(top, front, right, left, back, bottom)
        @top, @front, @right, @left, @back, @bottom \
            = top, front, right, left, back, bottom
    end

    def south
        @top, @front, @bottom, @back \
            = @back, @top, @front, @bottom
    end

    def north
        @top, @front, @bottom, @back \
            = @front, @bottom, @back, @top
    end

    def east
        @top, @right, @bottom, @left \
            = @left, @top, @right, @bottom
    end

    def west
        @top, @right, @bottom, @left \
            = @right, @bottom, @left, @top
    end
end

dice = Dice.new(*(gets.chomp.split.map(&:to_i)))

opary = gets.chomp.split(//)
opary.each do |op|
    case op
    when "S"
        dice.south
    when "N"
        dice.north
    when "E"
        dice.east
    when "W"
        dice.west
    end
end

puts dice.top

Measured memory_bytes: 6112
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long
typedef std::pair<int,int> pii;
inline bool up(int&x,const int y){return x<y?x=y,1:0;}
inline bool down(int&x,const int y){return x>y?x=y,1:0;}

int main(){
	std::ios::sync_with_stdio(0);
	int n; std::cin>>n;
	rep(i,1,n) std::cout<<"ACL";
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> y(n);
	rep(i, n) cin >> y.at(i);
	vector<int> u = y;
	sort(u.begin(), u.end());
	reverse(u.begin(), u.end());
	int max_1 = u.at(0);
	int max_2 = u.at(1);
	for (int i : y) {
		if (max_1 == i) cout << max_2 << endl;
		else cout << max_1 << endl;
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVVll = vector<VVll>;
using VVVld = vector<VVld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


VVll multiply(VVll &a, VVll &b) {
  int p = a.size();
  int q = b.size();
  int r = b[0].size();
  VVll res(p, Vll(r));
  rep(i, p) rep(j, r) rep(k, q) (res[i][j] += a[i][k] * b[k][j]) %= MOD;
  return res;
}


int main() {
  ll N, K; cin >> N >> K;
  VVll a(N, Vll(N));
  rep(i, N) rep(j, N) cin >> a[i][j];
  
  VVVll p;
  const int m = 60;
  p.push_back(a);

  rep(i, m) p.push_back(multiply(p[i], p[i]));

  VVll q(N, Vll(N));
  rep(i, N) q[i][i]++;

  rep(i, m) if (K>>i&1) q = multiply(q, p[i]);

  int ans = 0;
  rep(i, N) rep(j, N) (ans += q[i][j]) %= MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
struct Graph{
    struct edge{int to;ll cost;};
    int siz;
    bool dir;
    vector<vector<edge>> G;
    Graph(bool dir):dir(dir){}
    Graph(int siz,bool dir):siz(siz),dir(dir){
        G.resize(siz+1);
    }
    void resize(int nsiz){
        siz=nsiz;
        G.resize(siz+1);
    }
    void add_edge(int u,int v){
        assert(0<=u&&u<siz);assert(0<=v&&v<siz);
        G[u].push_back({v,0});
        if(!dir)G[v].push_back({u,0});
    }
    void add_edge(int u,int v,ll cost){
        assert(0<=u&&u<siz);assert(0<=v&&v<siz);
        G[u].push_back({v,cost});
        if(!dir)G[v].push_back({u,cost});
    }
    vector<edge>& operator[](const int& idx){
        assert(0<=idx&&idx<siz);
        return G[idx];
    } 
};
vector<ll> dijkstra(int s,Graph G){
    int n=G.siz;
    assert(0<=s&&s<n);
    vector<ll> d(n,LINF);
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.push(P(0,s));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(d[e.to]<=d[v]+e.cost)continue;
            d[e.to]=d[v]+e.cost;
            q.push(P(d[e.to],e.to));
        }
    }
    return d;
}
int main(){
    int n,m,r;cin>>n>>m>>r;
    Graph G(n,true);
    while(m--){
        int u,v,c;cin>>u>>v>>c;
        G.add_edge(u,v,c);
    }
    vector<ll> d=dijkstra(r,G);
    for(int i=0;i<n;i++){
        if(d[i]==LINF){
            cout<<"INF"<<endl;
        }else{
            cout<<d[i]<<endl;
        }
    }
}



Measured memory_bytes: 30820
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
    cin >> n >> k;
    long long ans = 0;
    if(k % 2 == 0) {
        long long ecnt = n/k;
        ans += pow(ecnt, 3);
        long long evcnt = 0;
        for(int i = 1; i <= n; ++i) {
            if(i % k == k/2) evcnt++;
        }
        ans += pow(evcnt, 3);
    }else {
        long long ocnt = n/k;
        ans += pow(ocnt, 3);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = input().split()
A = [int(i) for i in A]
A.sort(reverse=True)
total = sum(A)
flag = True

for i in range(M):
    if A[i] < total/(4*M):
        print('No')
        flag = False
        break

if(flag):
    print('Yes')

Measured memory_bytes: 9172
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        ArrayList<Integer> numbers = new ArrayList<>();

        for(int i = 0; i <3; i++){
            boolean inserted = false;
            int temp = input.nextInt();
            for(int x = 0; x < numbers.size(); x++){
                if(temp < numbers.get(x)){
                    numbers.add(x, temp);
                    inserted = true;
                    break;
                }
            }
            if(!inserted)numbers.add(temp);
        }
        for(int j = 0; j < 3 - 1; j ++){
            System.out.print(numbers.get(j) + " ");
        }
        System.out.print(numbers.get(2)+"\n");
    }}


Measured memory_bytes: 26128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<pair<ll, ll>> a(n); // pair of <value, id>
  rep(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1; // 1-indexed
  }
  sort(all(a));
  reverse(all(a));
  // For Debug
  // rep(i, n) {
  //   cout << a[i].first << " " << a[i].second << endl;
  // }

  vector<vector<ll>> dp(n+1, vector<ll>(n+1)); // dp[x][y] .. max score when selecting x as (i-pi) and y as (pi-i).
  rep(x, n) rep(y, n) {
    ll now = x + y;
    if (now >= n) { continue; }
    ll px = x+1; // 1, 2, ...
    ll py = n-y; // n, n-1, ...
    chmax(dp[x+1][y], dp[x][y] + a[now].first * (a[now].second - px));
    chmax(dp[x][y+1], dp[x][y] + a[now].first * (py - a[now].second));
  }

  ll ans = 0;
  rep(i, n+1) {
    chmax(ans, dp[i][n-i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 34624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int num[100005];
int num2[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]),num2[i]=num[i];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(num[i]==i)
        {
            swap(num[i],num[i+1]);
            sum++;
        }
    }
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        if(num2[i]==i)
        {
            swap(num2[i],num2[i-1]);
            ans++;
        }
    }
    printf("%d\n",min(sum,ans));
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    long long x,ans;
    cin >> x;
    if(x%11==0){
        ans = x/11*2;
    }else if(x%11<7){
        ans = x/11*2 + 1;
    }else{
        ans = x/11*2 + 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ps(x, y) fixed<<setprecision(y)<<x
// double ans = 1.012345668992
//cout<<ps(ans , 6)
// ans = 1.012345 // 6 decimal places
using namespace std;
int main(){
  int n ;
  cin>>n;
  double ans = 2*3.14*n;
  cout<<ps(ans , 2)<<"\n";
  return 0;
}

Measured memory_bytes: 3784
#include  <bits/stdc++.h>
using namespace std;
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define M 1000000007

/*const ll N=10^5+1;
std::vector<ll> deg(N);
std::vector<vector<ll> >g(N);
vector<bool> visited(N);
vector<ll> comp;

void dfs(ll i){

    //comp.push_back(i);
   // cout<<" visited: "<<i<<" ";
    visited[i]=true;
   for(int j=0;j<g[i].size();j++)
    if(!visited[g[i][j]])
    dfs(g[i][j]);
}
*/

int main() {
    
    ll d,t,s;cin>>d>>t>>s;
    if(t*s>=d)
            cout<<"Yes";
    else
        cout<<"No";
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, ans=0, tmp=0, DP[200001];
vector<ll> A, C[200001];

signed main(){
    cin >> N;
    DP[0]=1;
    for(int i=1;i<=N;i++) {
        ll a;
        cin >> a;
        DP[i] = DP[i-1];
        A.push_back(a);
        if(i==1) C[a].push_back(i);
        if(i>1) {
            if(A[i-2]!=A[i-1]) {
                if(C[a].size()>0) {
                    if(C[a].back()<i-1) DP[i] += DP[C[a].back()];
                }                
                C[a].push_back(i);
            }
        }
        DP[i] %= 1000000007;
        //cout << i << " " << DP[i] << endl;
    }
    cout << DP[N] << endl;
    return 0;
}

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


int main() {
    string s;
    getline(cin, s);
    int a = 0, b = 0, k = 1;
    bool ok = 0;
    char op;
    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == ' ') continue;
        if (s[i] == '+' || s[i] == '-'){
            op = s[i];
            ok = 1;
            k = 1;
            continue;
        }
        if (ok) a += int(s[i] - 48) * k;
        else b += (int(s[i]) - 48) * k;
        k *= 10;
    }
    if (op == '+') cout << a + b;
    else cout << a - b;
    return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    vector<ll> ans;
    for (int i = 0; i < x; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < y; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < z; ++i) {
        cin >> c[i];
    }

    vector<ll> ab;
    for (int i = 0; i < x; ++i) {
        for (int j = 0; j < y; ++j) {
            ab.push_back(a[i] + b[j]);
        }
    }

    sort(all(ab));
    reverse(all(ab));
    sort(all(c));
    reverse(all(c));

    for (int i = 0; i < min(sz(ab), k); i++) {
        for (int j = 0; j < z; ++j) {
            ans.push_back(ab[i] + c[j]);
        }
    }
    sort(all(ans));
    reverse(all(ans));

    for (int i = 0; i < k; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43240
#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++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m;
string s,t,ans;

int main() {
  cin >> n;
  if(n%10==3) ans="bon";
  else if(n%10==0||n%10==1||n%10==6||n%10==8) ans="pon";
  else ans="hon";
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c[15],h[15];
   // map<int,char>h;
    int i,s,k,n;
    while(cin>>c)
    {
        k=0;
        for(i=0;i<strlen(c);i++)
        {
            if(c[i]=='0')
            {
                h[k++]='0';
            }
            else if(c[i]=='1')
            {
                h[k++]='1';
            }
            else if(c[i]=='B')
            {
                if(k!=0)
                {
                   k=k-1;
                }
                else continue;

            }
            //cout<<h[k];

        }
        for(i=0;i<k;i++)cout<<h[i];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b1 = []
b2 = []
for i in range(n):
    if i % 2 == 0:
        b2.append(a[i])
    else:
        b1.append(a[i])
ans =[]
if n % 2 == 0:
    ans = b1[-1:-n - 1:-1] + b2
else:
    ans = b2[-1:-n - 1:-1] + b1

for i in ans:
    print(i, end=' ')

Measured memory_bytes: 26176
import std.stdio, std.conv, std.string;

void main() {
	int N, K;
	N = readln().chomp().to!(int);
	K = readln().chomp().to!(int);
	int res = 1;
	foreach(int i; 0..N) {
		if(res + K < res*2) {
			res += K;
		}
		else {
			res *= 2;
		}
	}
	writeln(res);
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
sum = 0

a.each{|i|
    sum += b[i-1]
    if a[i-1]+1 == a[i]
      sum += c[a[i-1]-1]
    end
}

puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(15) << std::fixed;
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    precise
    int t=1;
    //cin>>t;
    while(t--)
    {
        int a,b,h,m;
        cin>>a>>b>>h>>m;
        int tm=h*60+m;
        double ang1=tm/2.0;
        double ang2=m*6.0;
        double ang3=abs(ang2-ang1);
        ang3=min(ang3,360.0-ang3);
        double ans=1.0*b*b+1.0*a*a-2.0*b*a*cos(ang3*PI/180.0);
        ans=sqrt(ans);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4248
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val D = rd.readIntArray()

    if (N==1) {
        println(min(D[0], 24-D[0]))
        return
    }
    if (N>=24) {
        println(0)
        return
    }

    val A = IntArray(24){0}
    A[0] = 1
    D.sort()
    var left = D[0] < 24-D[0]
    for (i in 0 until N) {
        if (left) A[(24-D[i])%24] += 1
        else A[D[i]] += 1
        left = !left
    }

    var ans = 0
    if (A.none { it > 1 }) {
        val dist = (A.joinToString("") )
                .split('1').map{it.length}.drop(1).min()!! + 1
        ans = max(ans, dist)
    }

    println(ans)
}


//val rd = debug.Reader("etc", "cf17-final", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 40288
A, B, C, K = [int(v) for v in input().split()]

s = 0
while K:
    if A and K:
        if K >= A:
            K -= A
            s += A
            A -= A
        else:
            s += K
            K -= K
    if B and K:
        if K >= B:
            K -= B
        else:
            K -= K
    
    if C and K:
        if K >= C:
            K -= C
            s -= C
            C -= C
        else:
            s -= K
            K -= K

        
print(s)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  int ans = 0;
  for(int i = 0; i < N;) {
    while (A[i] == A[i+1] && i < N-1) {
      i++;
    }
    if (A[i] < A[i+1]) {
      while (A[i] <= A[i+1] && i < N-1) {
        i++;
      }
      i++;
      ans++;
    }
    else if (A[i] > A[i+1]) {
      while (A[i] >= A[i+1] && i < N-1) {
        i++;
      }
      i++;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    int ans = 0;
    for (int i = 0; i < 1000 * 1000; ++i) {        
        ans = max(ans, (ai/2) * 2 + ao * 1 + (aj/2)*2 + (al/2)*2 + i*3);
        if (!ai || !aj || !al) {
            break;
        }   
        --ai; 
        --aj;
        --al;
    }   
    cout << ans << endl;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> k;
	x = 0;
	rep(i, n){
		cin >> y;
		x += min(y, k-y) * 2;
	}
	cout << x << endl;
}

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

int main(){
    int INF = 10000000000;//10^10
    int N, K;
    cin>>N>>K;

    int h[100010];
    for(int i = 0; i < N; i++){
        int temp;
        cin>>temp;
        h[i] = temp;
    }

    int dp[100010];
    for(int i = 0; i < N; i++){
        dp[i] = INF;
    }

    dp[0] = 0;
    dp[1] = 0;
    for(int i = 1; i < K;i++){
        if(i + 1 > N) break;
        int temp = INF;
        for(int j = 0; j < i; j++){
            temp = min(temp, dp[i-j] + abs(h[i] - h[i-j-1]));
        }
        dp[i+1] = temp;
    }
    for(int i = K; i < N; i++){
        int temp = INF;
        for(int j = 0; j < K; j++){
            temp = min(temp, dp[i-j] + abs(h[i] - h[i-j-1]));
        }
        dp[i+1] = temp;
    }

    cout<<dp[N]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>S;
    N = S.size();
    cout<<((N%2 == 1)^(S[0] != S[N-1]) ? "Second" : "First")<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)
#define MOD (1000000007)

/////////////////////////////////////////////////////////

void Main(){
  int N; cin >> N;
  vector<int> s(N);
  rep(i, 0, N) cin >> s[i];
  int sum = 0;
  int min = INF;
  bool ten = true;
  rep(i, 0, N){
    if(s[i] % 10 != 0){
      ten = false;
      if(s[i] < min) min = s[i];
    }
    sum += s[i];
  }
  if(ten) cout << 0 << endl;
  else if(sum % 10 == 0) cout << sum - min << endl;
  else cout << sum << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include<stdio.h>

void era_transform(int year, int month, int day);

int main(void)
{
 int year, month, day;
 while(scanf("%d %d %d", &year, &month, &day) != EOF) {
 era_transform(year, month, day);
 }
 return 0;
}

void era_transform(int year, int month, int day)
{
 int date_number = year * 10000 + month * 100 + day;
 int meiji_number = 1868 * 10000 + 9 * 100 + 8;
 int taisho_number = 1912 * 10000 + 7 * 100 + 30;
 int showa_number = 1926 * 10000 + 12 * 100 + 25;
 int heisei_number = 1989 * 10000 + 1 * 100 + 8;
 if (date_number < meiji_number) {
      printf("pre-meiji\n");
 } else if (date_number < taisho_number) {
      printf("meiji %d %d %d\n", year - 1867, month, day);
 } else if (date_number < showa_number) {
      printf("taisho %d %d %d\n", year - 1911, month, day);
 } else if (date_number < heisei_number) {
      printf("showa %d %d %d\n", year - 1925, month, day);
 } else {
      printf("heisei %d %d %d\n", year - 1988, month, day);
 }
}

Measured memory_bytes: 1036
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
# Bubble Sort: python3
#  2018.12.05 yonezawa

import sys
input = sys.stdin.readline


def bubbleSort(l):
    cnt = 0    
    flg = True
    while True:
        flg = False
        for i in range(len(l)-1):
            if l[i] > l[i + 1]:
                (l[i],l[i+1]) = (l[i+1],l[i])
                cnt += 1
                flg = True
        if flg == False:
            break
    return l,cnt

def main():
    n = int(input())
    l = list(map(int,input().split()))
    (ans,cnt) = bubbleSort(l)
    print (*ans)
    print (cnt)
if __name__ == '__main__':
    main()



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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
template<long long Mod = mod>
constexpr long long MOD(long long in) {
    return in % Mod;
}

constexpr ll v = 1000000000;

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

    std::cin >> s;

    ll x = (v - s % v) % v;
    ll y = (s + x) / v;

    std::cout << "0 0 1000000000 1 " << x << " " << y << std::endl;

    return 0;
}


Measured memory_bytes: 256
#Beginner COnetst 145 /2019/11/16
#Probrem A
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def calc(x,y):
    if (x*2-y)%3 != 0 or (y*2-x)%3 != 0: return 0
    m = (x*2-y)//3
    n = (y*2-x)//3
    if m < 0 or n < 0:return 0
    #return combinations_count(m+n,m)
    return cmb(m+n,m,mod)

DEBUG = 0

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


X,Y = list(map(int, input().split()))

if DEBUG:print(X,Y)

print(calc(X,Y))


Measured memory_bytes: 124352
/**
 * author:    Ziel
 * created:   23.04.2020 20:19:46
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
    int n;
    cin >> n;
    vector<double> h(n + 1), t(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
        t[i] = 1.0 - h[i];
    }
    vector<vector<array<double, 2>>> dp(n + 1, vector<array<double, 2>>(n + 1));
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j > 0)
                dp[i][j][0] = h[i] * 1.0 * double(dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]);
            dp[i][j][1] = t[i] * 1.0 * double(dp[i - 1][j][0] + dp[i - 1][j][1]);
        }
    }
    double ans = 0;
    for (int i = (n + 1) / 2; i <= n; i++) {
        ans += dp[n][i][0] + dp[n][i][1];
    }
    cout << fixed << setprecision(9) << ans;
    
	return 0;
}

/*
	Raise your standard.
*/


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

int main(){
    int h,n; cin>>h>>n;
    vector<int> a(n);
    bool defeat = false;
    rep(0,i,n){
        cin>>a.at(i);
        h -= a.at(i);
        if(h<=0){
            defeat = true;
            break;
        }
    }

    if(defeat)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

pair<ll,ll> dp[300030];

int main(){
  int n;
  cin>>n;
  int m=pow(2,n);
  ll A[m+1]={};
  for(int i=0;i<m;i++){
      cin>>A[i];
  }

  for(int i=1;i<m;i++) dp[i]=make_pair(i,0);
  dp[0]=make_pair(0,m);

  for(int i=1;i<m;i++){
      set<int> se;
      for(int j=18;j>=0;j--){
          if((1<<j)&i){
              int z=i^(1<<j);
              se.insert(dp[z].first);
              se.insert(dp[z].second);
          }
      }
      se.insert(0);
      se.insert(i);
      
      int ma1=0,ma2=0;
      int mat1=0,mat2=0;
      for(auto s:se){
          if(ma1<A[s]){
              ma2=ma1;
              mat2=mat1;
              ma1=A[s];
              mat1=s;
          }else if(ma2<A[s]){
              ma2=A[s];
              mat2=s;
          }
      }
      dp[i]=make_pair(mat1,mat2);
  }

  ll ans[m+1]={};
  for(int i=1;i<m;i++){
      ans[i]=A[dp[i].first]+A[dp[i].second];
      ans[i]=max(ans[i],ans[i-1]);
      cout<<ans[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <functional>
#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 int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

typedef pair <ll,ll> P;

bool pairCompareF(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}

bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main()
{
    ll N, K;
    ll X, Y;
    cin >> N >> K >> X >> Y;
    ll count = 0;
    rep(i, N)
    {
        if (i < K) {
            count += X;
        } else {
            count += Y;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  if(S.at(K-1)=='A'){
    S.at(K-1)='a';
  }
  else if(S.at(K-1)=='B'){
    S.at(K-1)='b';
  }
  else{
    S.at(K-1)='c';
  }
  cout << S << endl;
}

Measured memory_bytes: 256