akhauriyash/Code-Regression huggingface dataset:
package main

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

var visited []bool
var g [][]bool

func main() {
	nm := nextIntArray()
	n, m := nm[0], nm[1]
	g = make([][]bool, n)
	for i := 0; i < n; i++ {
		g[i] = make([]bool, n)
	}
	edge := make([][]int, m)
	for i := 0; i < m; i++ {
		ab := nextIntArray()
		a, b := ab[0]-1, ab[1]-1
		edge[i] = []int{a, b}
		g[a][b] = true
		g[b][a] = true
	}

	cnt := 0
	for _, v := range edge {
		a, b := v[0], v[1]
		g[a][b] = false
		g[b][a] = false
		visited = make([]bool, n)
		visited[0] = true
		dfs(0)
		all := true
		for _, v := range visited {
			all = all && v
		}
		if !all {
			cnt++
		}
		g[a][b] = true
		g[b][a] = true
	}
	fmt.Println(cnt)
}

func dfs(v int) {
	visited[v] = true

	for nei, flag := range g[v] {
		if flag && !visited[nei] {
			dfs(nei)
		}
	}
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 640
/* author   : mpily :-()
title : Competing.cpp
time :Fri Aug 23 13:20:23 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a; string s;
	cin>>a>>s;
	if(a < 3200)cout<<"red \n";
	else cout<<s<<"\n";
}

Measured memory_bytes: 256
<?php

$rooms     = array_fill(1,10,0);
$floors    = array_fill(1, 3, $rooms);
$buildings = array_fill(1, 4, $floors);

$num = (int)fgets(STDIN);

while (--$num >= 0) {
  fscanf(STDIN, "%d%d%d%d", $b,$f,$r,$v);
  $buildings[$b][$f][$r] += $v;
}

$res = array_fill(1,4,'');
for ($i = 1; $i <= 4; $i++) {
  for ($j = 1; $j <= 3; $j++) {
    $res[$i] .= ' ' . implode(' ', $buildings[$i][$j]) . PHP_EOL;
  }
}

echo implode('####################'.PHP_EOL, $res);

Measured memory_bytes: 15452
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9
#define PI 3.14159265359

using namespace std;
using P = pair<int, int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

  bool ans = true;
  
  int high = 0;

  Rep(i, N) {
    int tmp;
    cin >> tmp;
    if (tmp >= high) {
      high = tmp;
    } else {
      if (tmp < high - 1) {
        ans = false;
        break;
      }
    }
  }

  cout << (ans ? "Yes" : "No") << "\n";
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;

	int ans = 0, cur = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] != cur)ans++;
		else cur++;
	}
	if (ans == a.size())cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

int n, m;

vector<bool> visit(20, false);
vector<vector<bool>> g(20, vector<bool>(20, false));

int dfs(int x) {
	visit[x] = true;

	bool allvisit = true;

	for (int i = 1; i <= n; i++) {
		if (!visit[i]) allvisit = false;
	}

	if (allvisit) return 1;

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		if (g[x][i] == true && visit[i] == false) {
			ans += dfs(i);
			visit[i] = false;
		}
	}
	return ans;
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		g[a][b] = g[b][a] = true;
	}
	cout << dfs(1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <climits>
#include <map>
using namespace std;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n;
vector<vector<pair<int,int>>> G;
vector<int> d;
multimap<int,int> pri_m;
vector<int> colors;

//失败了，怀疑是因为相同的cost的情况覆盖了...
void dijkstra(int s){
    d[s] = 0;
    pri_m.insert(make_pair(0,s));

    while(!pri_m.empty()){
        int cost = pri_m.begin()->first;
        int u = pri_m.begin()->second;
        //pri_m.erase(cost);
        map<int,int>::iterator it=pri_m.find(cost);//删除(c,5)
        pair<map<int,int>::iterator,map<int,int>::iterator> pos=pri_m.equal_range(it->first);//利用一对multimap<string,int>指向第一个出现(c,5)的位置和最后一个出现(c,5)的位置
        while (pos.first!=pos.second)
        {
            if (pos.first->second==u)//当pos指向5时
            {
                pos.first=pri_m.erase(pos.first);//删除后会改变pos迭代器，故赋值给自身，指向删除后的下一个键值对
            }
            else
                ++pos.first;//不进行删除操作则自增

        }
        if(d[u] < cost) continue;
        colors[u] = BLACK;
        for(int i = 0;i<G[u].size();i++){
            int v = G[u][i].first;
            if(colors[v] != BLACK){
                if(d[u]+G[u][i].second < d[v]){
                    d[v] = d[u]+G[u][i].second;
                    pri_m.insert(make_pair(d[v],v));
                }
            }
        }
    }
    for(int i=0;i<n;i++) printf("%d %d\n",i,d[i]);
}

int main(){
    //freopen("data.txt","r",stdin);
    cin >> n;
    G.resize(n);
    d.resize(n,INT_MAX);
    colors.resize(n,WHITE);
    int u,k,v,c;
    for(int i = 0;i<n;i++){
        cin >> u >> k;
        for(int j = 0;j<k;j++){
            cin >> v >> c;
            G[u].push_back(make_pair(v,c));
        }
    }
    dijkstra(0);

    return 0;
}





Measured memory_bytes: 7936
#include <cstdio>

int a, b, c, n, ans = 0;

int main() {
	scanf("%d %d %d %d", &a, &b, &c, &n);
	for (register int i = 0; i <= a; i++) {
		for (register int j = 0; j <= b; j++) {
			for (register int k = 0; k <= c; k++) {
				if (i * 500 + j * 100 + k * 50 > n) break;
				if (i * 500 + j * 100 + k * 50 == n) ans++;
			}
		}
	}
	printf("%d", ans);
        return 0;
}

Measured memory_bytes: 256
import math

n=int(input())
end=math.sqrt(n)
q=2
print(n,":",sep="",end="")
while(True):
    if n%q==0:
        n/=q
        print(" ",q,sep="",end="")
    else:
        q+=1
    if q>end or n==1:
        break
if n>1:
    print(" ",int(n),sep="",end="")
print()


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


int main() {
  int X,N;
  cin>>X>>N;
  vector<int> p(N),P(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  //sort(p.begin(), p.end());
  int ans=X,f,ansub=0;
  for(int i=0;i<N+1;i++){
    f=1;
    for(int j=0;j<N;j++){
      if(ans==p[j])f=0;
    }
    if(f)break;
    if((X-ans)>0){ans+=ansub*2;}
    else {ans-=(ansub*2+1);ansub++;}
  }
  cout<<ans<<endl;
}


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

int main(){
	int N,a=0,b=0;
	string S;
	cin>>N>>S;

	for(int i=0;i<N;i++){
		if(S.at(i)=='#')
			a++;
		else if(S.at(i)=='.'&&a>0){
			b++;
			a--;
		}
	}
	cout<<b<<endl;
}

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

int main() {
  int N,d=0,mm;
  cin >> N >> mm;
  while(mm%2==0){
    mm/=2;
    d++;
  }
  for(int i=1;i<N;i++){
    int m,dd=0;
    cin >> m;
    while(m%2==0){
      m/=2;
      dd++;
    }
    d=min(d,dd);
  }
  cout << d << endl;
}

Measured memory_bytes: 256
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(11, 2), 4)

    def test_2(self):
        self.assertEqual(think(1010101, 10), 7)

    def test_3(self):
        self.assertEqual(think(314159265, 3), 18)


def solve():
    n, k = read()
    result = think(n, k)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, k):
    buf = ''
    while n > 0:
        buf += str(n % k)
        n //= k
    return len(buf)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51692
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll n;
  cin >> n;
  vector<ll> s(n), t(n);

  rep(i, n){
    cin >> s[i];
    t[i] = s[i];
  }
  sort(all(t));

  ll low, high, mid;
  if(n % 2){ //odd
    low = t[n/2];
    high = t[n/2 + 1];
    mid = t[n/2 + 1];
  }else{ // even
    low = t[n/2 - 1];
    high = t[n/2];
    mid = t[n/2];
  }
  // debug(low);
  // debug(high);
  // debug(mid);
  rep(i, n){
    // debug(s[i]);
    if(s[i] < mid){
      cout << high << " ";
    }else{
      cout << low << " ";
    }
  }
}
#endif


Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m,a;
  while(cin>>n>>m>>a,n){
    vector<pair<int,pair<int,int> > >vpi(m);
    for(int i=0;i<m;i++)
      cin>>vpi[i].F>>vpi[i].S.F>>vpi[i].S.S;
    sort(vpi.begin(),vpi.end());
    reverse(vpi.begin(),vpi.end());
    int now=a;
    for(int i=1000;i>=1;i--){
      for(int j=0;j<m;j++){
	if(vpi[j].F==i&&vpi[j].S.F==now){
	  now=vpi[j].S.S;
	}else if(vpi[j].F==i&&vpi[j].S.S==now){
	  now=vpi[j].S.F;
	}
      }
    }
    cout<<now<<endl;
  }

  return 0;
}



Measured memory_bytes: 3028
loop do
  a,b,c = gets.split.map(&:to_i)
  break if a==-1 && b==-1 && c==-1
  if a==-1 || b==-1
    puts "F"
  elsif a+b>=80
    puts "A"
  elsif a+b>=65 && a+b<80
    puts "B"
  elsif a+b>=50 && a+b<65
    puts "C"
  elsif a+b>=30 && a+b<50
    if c>=50
      puts "C"
    else
      puts "D"
    end
  elsif a+b<30
      puts "F"
  end
end


Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
int n,q;
vector<vector<int>>vi(200005);
long long arr[200005] , ans[200005];
void dfs(int node , int parent , long long val){
	ans[node]=val + arr[node];
	for(auto it : vi[node]){
		if(it!=parent){
			dfs(it , node , val+arr[node]);
		}
	}
}
int main() {
	cin>>n>>q;
	for(int i = 0; i < n-1 ; i++){
		int u ,v;cin>>u>>v;
		vi[u].push_back(v);
		vi[v].push_back(u);
	}
	for(int i = 0; i < q ; i++){
		int node , val;
		cin>>node>>val;
		arr[node]+=val;
	}
	dfs(1,-1,0);
	for(int i = 1 ; i<= n ;i++)cout<<ans[i]<<" ";
	return 0;
}


Measured memory_bytes: 28672
#include<fstream>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  int N,M;
  vector<int> vec;
  map<int,bool> exist;
  exist.clear(),vec.clear();
  cin >> N >> M;
  
  for(int j=0;j<N;j++){
    int job;
    cin >> job;
   if(exist[job]){
     foreach(i,vec){
     	if((*i) == job){
	  vec.erase(i);
     	  vec.push_back(job);
     	  break;
     	}
     }
      
    }
    else if(vec.size() < M){
      exist[job] = true;  
      vec.push_back(job);
    }
    else if(vec.size() >= M){      
      exist[*vec.begin()] = false;
      vec.erase(vec.begin());
      vec.push_back(job);
      exist[job] = true;
    }
    else {
    }
  }
 
  for(int i=(int)vec.size()-1;i>=0;i--){
    cout << *(vec.begin()+i) << endl;
  }
  ofstream ofs("out1.txt");
  for(int i=0;i<1000;i++){
    ofs << i << endl;
  }

  return 0;
}

Measured memory_bytes: 5920
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

ll calc_diff(ll x1, ll x2, ll y1, ll y2){
    ll diff = abs(x1 - x2) + abs(y1-y2);
    return diff;
}

signed main() {
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> a(n);
    vector<pair<ll, ll>> c(m);
    vi cp(n);
    rep(i, n){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        a[i] = make_pair(tmp1, tmp2);
    }
    rep(i, m){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        c[i] = make_pair(tmp1, tmp2);
    }

    rep(i, n){
        ll tmp_max_diff = 99999999999999999;
        rep(j, m){
            if(tmp_max_diff > calc_diff(a[i].first, c[j].first, a[i].second, c[j].second)){
                tmp_max_diff = calc_diff(a[i].first, c[j].first, a[i].second, c[j].second);
                cp[i] = j;
            }
            /* printf("%d -> %d = ", i, j);
            cout << calc_diff(a[i].first, c[j].first, a[i].second, c[j].second) << endl; */
        }
    }

    rep(i, n){
        cout << cp[i] + 1 << endl;
    }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
#define INF 1000000000
int main(){
	int h,m,s;
	int h1,m1,s1;
	for(int i = 0; i < 3; i++){
		scanf("%d%d%d",&h,&m,&s);
		scanf("%d%d%d",&h1,&m1,&s1);
		int t = h * 3600 + m * 60 + s;
		int t1 = h1 * 3600 + m1 * 60 + s1;
		int time = t1 - t;
		printf("%d %d %d\n",time/3600,(time%3600)/60,time%60);
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#include<climits>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=2001;
int N,K,Q,ff[MAXN],A[MAXN],B[MAXN],tmp[MAXN],Minn,INF=INT_MAX;
void cacl(int l,int r){
    if(l>r||!l) return;
    int len=r-l+1;if(len<K) return;
    int tot=0;for(int i=l;i<=r;i++) B[++tot]=A[i];sort(B+1,B+tot+1);
    for(int i=1;i<=len-K+1;i++) tmp[++tmp[0]]=B[i];return;
}
int main(){
    N=read(),K=read(),Q=read();Minn=INF;for(int i=1;i<=N;i++) A[i]=tmp[i]=read();sort(tmp+1,tmp+N+1);
    int M=unique(tmp+1,tmp+N+1)-tmp-1;for(int i=1;i<=M;i++) ff[i]=tmp[i];for(int i=1;i<=N;i++) A[i]=lower_bound(tmp+1,tmp+M+1,A[i])-tmp;
    for(int i=1;i<=M;i++){
        int l=0;tmp[0]=0;
        for(int j=1;j<=N;j++){
            if(A[j]>=i) if(!l)  l=j;
            if(A[j]<i) {cacl(l,j-1);l=0;}
        }if(A[N]>=i) cacl(l,N);
        if(tmp[0]<Q) continue;sort(tmp+1,tmp+tmp[0]+1);
        Minn=min(Minn,ff[tmp[Q]]-ff[i]);
    }printf("%d\n",Minn);return 0;
}



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

int main(){
  double a,b,t;
  cin >> a >> b >> t;
  int count = 0;
  for(int i=1;i<=20;i++){
    if(a*i > t+0.5){
      break;
    }
    else{
      count += b;
    }
  }
  
  cout << count << endl;
  return 0;
}
    


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

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
typedef pair<int,int> P;
int ans=1e9,n,a[20],b[20],now;
vector<P> v;

signed main(){
  cin>>n;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<(1<<n);i++){
    now=0;
    for(int j=0;j<n;j++)v[j]=P((i>>j)&1?b[j]:a[j],j);
    for(int j=0;j<n;j++)for(int k=0;k<j;k++)now+=(v[k]>v[j]);
    sort(v.begin(),v.end());
    stack<int> sta;
    for(int j=0;j<n;j++){
      int idx=v[j].second;
      if(((i>>idx)+idx-j)&1)sta.push(v[j].first*1000+j);
    }
    if(sta.size()&1)continue;
    while(sta.size()){
      int p=sta.top();sta.pop();
      int q=sta.top();sta.pop();
      if(p-q<1000&&(p-q)&1)now+=p-q;
      else goto OUT;
    }
    chmin(ans,now);OUT:;
  }
  cout<<(ans<1e9?ans:-1)<<endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int a[100100];
int main()
{
	int n,k;
	while(1)
	{
	cin >> n >> k;
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++)cin >> a[i];
	int ans=-INF;
	int base=0;
	for(int i=0;i<k;i++)base+=a[i];
	ans=base;
	for(int i=k;i<n;i++)
	{
		base-=a[i-k];
		base+=a[i];
		ans=max(ans,base);
	}
	cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1552
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  LL x;
  cin >> x;
  LL ans = 0;
  ans += x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
from sys import stdin
import bisect

def main():
    input = stdin.readline
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    d = [0] * (m + 1)
    for i in range(m):
        d[i + 1] = d[i] + b[i]
    cnt = 0
    for i in range(n + 1):
        if c[i] > k:
            break
        e = bisect.bisect_right(d, k - c[i])
        if e > m and cnt < i + m:
            cnt = i + m
        if e <= m and cnt < i + e - 1:
            cnt = i + e - 1
    print(cnt)
main()

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

int a[3][3];

int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
		a[i][1] -= a[i][0]; a[i][2] -= a[i][0]; a[i][0] = 0;
	}
	for (int i = 0; i < 3; i++) {
		if (!(a[0][i] == a[1][i] && a[1][i] == a[2][i])) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
def manhattan_distance(p, q) -> int:
    return abs(p[0] - q[0]) + abs(p[1] - q[1])


N, M = map(int, input().split())
students = [tuple(map(int, input().split())) for _ in range(N)]
checkpoints = [tuple(map(int, input().split())) for _ in range(M)]

for student in students:
    p = min([(manhattan_distance(student, checkpoint), idx) for idx, checkpoint in enumerate(checkpoints, start=1)])
    print(p[1])


Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }

const int N = 500;

void solve() {
  string str;
  cin >> str;
  fore(ch, str)if (ch == '9') {
    cout << "Yes" << ln;
    return;
  }
  cout << "No" << ln;
}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



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

using namespace std;

int main(){
  string S;
  cin>>S;
  int len=(int)S.length();
  int i=len-1;
  int j=0;
  int count = 0;
  while(i!=(-1)){
    if(S[i] != S[j]){
      count++;
    }
    j++;
    i--;
  }
  count=count/2;
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
 
    	Scanner sc = new Scanner(System.in);
 
    	double a = sc.nextDouble();
    	double b = sc.nextDouble();
    	double x = sc.nextDouble();
 
   		double ans = 0.0;
 
  		if (a*a*b / 2.0 <= x){
    		ans = Math.toDegrees(Math.atan((2*(a*a*b-x))/(a*a*a)));
    	} else {
    		ans = Math.toDegrees(Math.atan(a*b*b/(2*x)));
    	}
 
    	System.out.println(ans);
    }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    ll ans = 0;
    vector<int> A(N);
    vector<int> cnt(N + 1);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        cnt[A[i]]++;
        if (cnt[A[i]] == 2)
            ans++;
        else if (cnt[A[i]] > 2)
            ans += cnt[A[i]] - 1;
    }

    for (int i = 0; i < N; ++i) {
        ll tmp = ans;
        if (cnt[A[i]] == 2)
            tmp--;
        else if(cnt[A[i]] > 2)
            tmp -= cnt[A[i]] - 1;
        cout << tmp << '\n';
    }

    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
int main() {
	int m[10];
	for (int i = 0; i < 10; ++i) {
		std::cin >> m[i];
	}
	for (int i = 0; i < 10; ++i) {
		for (int j = 0; j < 10; ++j) {
			int a;
			if (m[i] < m[j]) {
				a = m[i];
				m[i] = m[j];
				m[j] = a;
			}
		}
	}
		std::cout << m[9] << std::endl;
		std::cout << m[8] << std::endl;
		std::cout << m[7] << std::endl;
		return 0;
	}

Measured memory_bytes: 1160
N = int(input())
A = [int(_) for _ in input().split()]

import itertools

ts = list(itertools.accumulate(A))

cs = {0: 1}
for t in ts:
    cs[t] = cs.get(t, 0) + 1

r = 0
for c in cs:
    n = cs[c]
    r += n * (n - 1) // 2

print(r)



Measured memory_bytes: 41108
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 100000000



h, w = LI()
ans = INF
for i, j in ((h, w), (w, h)):
# iをまず分割する(h, w)
    for k in range(1, i):
        for l, m in (j, k), (k, j):
            part = [j * (i - k), l // 2 * m, (l - l // 2) * m]
            ans = min(ans, max(part) - min(part))



print(ans)






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

using namespace std;

typedef long long int ll;

ll mod = 1000000007;
//---------------------------------------------------------------------------------------------------
ll f[1100001], rf[1100001];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    for (int i = 1; i < 1100001; i++) {
        f[i] = (f[i - 1] * i) % mod;
    }
    for (int i = 0; i < 1100001; i++) {
        rf[i] = inv(f[i]);
    }
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

int main() {
    init();
    int x, y; cin >> x >> y;
    if (!((2*x - y) >= 0 && (2*x - y) % 3 ==0)) {
        cout << 0 << endl;
        return 0;
    }

    if (!((2*y - x) >= 0 && (2*y - x) % 3 ==0)) {
        cout << 0 << endl;
        return 0;
    }
    ll a = (2*y - x) / 3;
    ll b = (2*x - y) / 3;

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

    if ( b < a ) {
        swap(a, b);
    }
    ll ans = 0;
    for (int i = 1; i <= a; i++) {
        ans += (C(b+1, i) * C(a - 1, i - 1)) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17408
import sys

x, y = [int(x) for x in sys.stdin.readline().split()]

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

def inn(x):
	xin = ''
	if x in a:
		xin = 'a'
	elif x in b:
		xin = 'b'
	else:
		xin = 'c'
	return xin

if inn(x) == inn(y):
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<atcoder/dsu>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  int n,q;
  cin >> n >> q;
  atcoder::dsu d(n);
  for(int i=0;i<q;i++){
    ll t,u,v;
    cin >> t >> u >> v;
    if(t==0){
      d.merge(u,v);
    }else{
      if(d.same(u,v)) cout <<1<<"\n";
      else cout <<0<<"\n";
    }
  }
}


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

int main(){
    int n,k;
    std::vector<long> x;
    std::cin >> n >> k ;
    long tmp;
    for (int i=0; i<n; i++){
        std::cin >> tmp;
        x.push_back(tmp);
    }
    std::sort(x.begin(),x.end(), std::greater<long>());
    long result;
    if (k<n){
        result = std::accumulate(x.begin()+k, x.end(), long(0));
    }else{
        result = 0;
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
//#define int long long

using namespace std;


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int fl = 0;
    while (a > 0 && c > 0) {
        if (fl) {
            a -= d;
        }
        else {
            c -= b;
        }
        fl = (fl + 1) % 2;
    }
    if (fl == 1) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl;
#endif
using namespace std;
typedef long long int lli;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> v(n+1);
	for(int i=1; i<=n; ++i) cin >> v[i];
	int cnt = 0;
	for(int i=1; i<=n; ++i){
		if((i&1) && (v[i]&1)) cnt++;	
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3636
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    ll n;
    cin>>n;
    cout<<(n*(n+1))/2-n<<endl;
    return 0;
}


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

int main(){
	ll n;
	scanf("%lld",&n);
	if(n < 2 || n % 2 == 1) printf("0\n");
	else{
		ll cnt = 0;
		cnt += n / 10;
		n /= 10;
		while(n){
			cnt += n / 5;
			n /= 5;
		}
		cout << cnt << endl; 
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        char tar ='+';
        int a =0;

        for(char x: n.toCharArray()){
            if(x == tar){
                a++;
            }
        }

        if(a == 0){
            System.out.println("-4");
        }else if(a == 1){
            System.out.println("-2");
        }else if(a == 2){
            System.out.println("0");
        }else if(a == 3){
            System.out.println("2");
        }else{
            System.out.println("4");
        }

    }
}


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

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

int main() {
int a,b,c;
cin>>a>>b>>c;
if(a==b)cout<<c<<endl;
else if(b==c)cout<<a<<endl;
else cout<<b<<endl;


    return 0;
}

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

int main (){
    //条件x+y+z==Sをみたすx,y,zを抽出する
    int x,y,z,ans=0,s,k;
    cin >> k >> s;
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            // x,yが決まればzが定まる
            if(0<=(s-x-y) && (s-x-y)<=k){
                ans++;
            }
            }
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			// solveB();
			// solveC();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numA = nextInt();
		int numB = nextInt();

		out.println((numA + numB) % 24);
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    ll ans=0,x;cin>>x;
    ans+=2*(x/11);
    x%=11;
    if(x>0){x-=6;ans++;}
    if(x>0){x-=5;ans++;}
    if(x>0){x-=6;ans++;}
    if(x>0){x-=5;ans++;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
str_cnt = {'M' : 0, 'A' : 0, 'R' : 0, 'C' : 0, 'H' : 0}
for i in range(N):
    s = input()
    if s[0] in 'MARCH':
        str_cnt[s[0]] += 1
import itertools
ans = 0
for i in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3):
    ans += str_cnt[i[0]] * str_cnt[i[1]] * str_cnt[i[2]]
print(ans)

Measured memory_bytes: 3064
H,W = map(int,input().split())
A=[""]*H
for i in range (H):
	A[i]=input()

V=[0]*H
X=[0]*W
for i in range (H):
	for j in range (W):
		if A[i][j]=="#":
			V[i]=1
			X[j]=1

for i in range (H):
	if V[i]==1:
		for j in range (W):
			if X[j]==1:
				print(A[i][j],end="")
		print()

Measured memory_bytes: 4468
# https://atcoder.jp/contests/abc151/tasks/abc151_d

from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]


def bfs(sx, sy):
    result = 0
    count = [[-1] * w for i in range(h)]
    count[sx][sy] = 0
    d = deque()
    d.append((sx, sy))
    while d:
        x, y = d.popleft()
        result = count[x][y]
        for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            tx, ty = x + i, y + j
            if (
                not (0 <= tx < h)
                or not (0 <= ty < w)
                or maze[tx][ty] == "#"
                or count[tx][ty] != -1
            ):
                continue
            else:
                count[tx][ty] = count[x][y] + 1
                d.append((tx, ty))
    return result


ans = 0
for i in range(w):
    for j in range(h):
        if maze[j][i] == ".":
            ans = max(ans, bfs(j, i))
print(ans)


Measured memory_bytes: 3444
using System;

class B
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int p = h[0], i = 1; i <= 10; i++, p *= h[0]) Console.WriteLine(p * h[2] - h[1] * (p - 1) / (h[0] - 1));
	}
}


Measured memory_bytes: 11092
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>


#ifdef MY_LOCAL
namespace sandbox {
#endif

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;

	vector<vector<int>> passages(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		passages[a].push_back(b);
		passages[b].push_back(a);
	}

	vector<int> signposts(n, -2);
	queue<int> q;
	signposts[0] = -1;
	q.push(0);
	while (!q.empty())
	{
		int this_room = q.front();
		q.pop();
		for (auto next_room : passages[this_room])
		{
			if (signposts[next_room] == -2)
			{
				q.push(next_room);
				signposts[next_room] = this_room;
			}
		}
	}

	for (auto this_signpost : signposts)
	{
		if (this_signpost == -2)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int j = 1; j < n; j++)
	{
		cout << signposts[j] + 1 << endl;
	}

	return 0;
}

#ifdef MY_LOCAL
}
#endif

Measured memory_bytes: 10088
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

typedef long long ll;
using namespace std;

//AからBまでのCで割れる個数の計算
ll count(ll A, ll B,ll C){

    ll _min, _max, result;
    _min = A % C;

    if(A % C != 0)
        _min = A + (C - _min);
    else
        _min = A;

    _max = B % C;
    _max = B - _max;

    result = ((_max - _min) / C) + 1;

    return result;
}

int main(void){
    ll A, B, C, D, E, F, G, r, x, result;
    scanf("%lld%lld%lld%lld", &A, &B, &C, &D);

    E = count(A, B, C);
    F = count(A, B, D);


    if(C < D){
        int tmp = C;
        C = D;
        D = tmp;
    }

    x = C * D;

    r = C % D;
    while(r != 0){
        C = D;
        D = r;
        r = C % D;
    }

    r = x / D;

    G = count(A, B, r);
    result = ((B - A) + 1) - (E + F - G);

    cout << result << endl;

}

Measured memory_bytes: 256
import sys
from itertools import combinations


def main():
    input = sys.stdin.readline
    antena_list = [int(input()) for _ in range(5)]
    k = int(input())
    max_length = max([j - i for i, j in combinations(antena_list, 2)])
    print(":(" if max_length > k else "Yay!")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
N,*T = map(int,input().split())
L = [int(input()) for i in range(N)]
ans = 3000

for x in range(4**N):
    l = [0]*4
    t = [0]*4
    n = 4
    i = 0

    for i in range(N):
        l[x%n] += L[i]
        t[x%n] += 1
        x//=n

    if 0 in l[:3]:
        continue
    cost = 0
    for i in range(3):
        cost += (t[i]-1)*10
        cost += abs(l[i]-T[i])
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n;cin>>n;
	string s;cin>>s;
	ll a[n];For(i,0,n) if(s[i]=='E') a[i]=1; else a[i]=0;
	ll count[n][2];
	memset(count,0,sizeof(count));
	count[0][0] = a[0];
	For(i,1,n) count[i][0]=count[i-1][0]+a[i];
	count[n-1][1] = a[n-1];
	Fod(i,n-1,0) count[i][1]=count[i+1][1]+a[i];

	ll ans=1e18;
	For(i,0,n){
		ll x = (i-(count[i][0]-a[i]))+count[i][1]-a[i];
		ans = min(ans,x);
	}
	cout<<ans<<endl;










	
}

Measured memory_bytes: 7700
from bisect import bisect_left

N, K = map(int, input().split())
xs = list(map(int, input().split()))

num1 = bisect_left(xs, 0)
num2 = N - num1

d1s = [0] + [-x for x in xs[:num1]][::-1]
d2s = [0] + xs[num1:]

ans = float('inf')
for i in range(max(0, K - num2), min(num1, K) + 1):
    d1, d2 = d1s[i], d2s[K - i]
    ans = min(ans, d1 + d2 + min(d1, d2))

print(ans)


Measured memory_bytes: 14484
#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>
#include <algorithm>

typedef long long ll;
int mat[750][3072 * 4] __attribute((aligned(32)));; 
ll dp0[3008];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx512vl"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd() - 1;
        int c = rd() - 1;
        int v = rd();
        mat[r / 4][(c + (r & 3)) * 4 + (r & 3)] = v;
    }
    int rlim = (rr + 3) / 4;
    int clim = cc + 3;

    for (int y = 0; y < rlim; y++) {
        __m256i work0 = _mm256_setzero_si256();
        __m256i work1 = _mm256_setzero_si256();
        __m256i work2 = _mm256_setzero_si256();
        __m256i work3 = _mm256_setzero_si256();

        __m256i prev0 = _mm256_setzero_si256();
        __m128i *p = (__m128i *)&mat[y];
        ll *q = dp0;

        for (int x = 0; x < clim; x++) {
            prev0 = _mm256_mask_set1_epi64(prev0, 1, q[3]);
            work0 = _mm256_max_epi64(work0, prev0);

            __m128i v0 = _mm_load_si128(p);
            __m256i v1 = _mm256_cvtepi32_epi64(v0);

            __m256i tmp2 = _mm256_add_epi64(work2, v1);
                   work3 = _mm256_max_epi64(work3, tmp2);

            __m256i tmp1 = _mm256_add_epi64(work1, v1);
                   work2 = _mm256_max_epi64(work2, tmp1);

            __m256i tmp0 = _mm256_add_epi64(work0, v1);
                   work1 = _mm256_max_epi64(work1, tmp0);

            __m256i max32 = _mm256_max_epi64(work3, work2);
            __m256i max10 = _mm256_max_epi64(work1, work0);
            __m256i max3210 = _mm256_max_epi64(max32, max10);

            prev0 = _mm256_alignr_epi64(max3210, max3210, 7);
            
            _mm256_mask_store_epi64(q, 1, prev0);
            
            ++p;
            ++q;
        }
    }
    std::printf("%lld\n", dp0[clim - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 40132
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b;
  cin >> a >> b;

  int ans = -1;
  rep(i,11000){
    int ai = (i*0.08), bi = (i*0.10);
    if (a==ai&&b==bi) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = list(map(int, input()))

def solve(N):
    dp = (0, 1) # n円の場合とn+1円の場合
    for n in N:
        a = min(dp[0] + n, dp[1] + 10 - n)
        b = min(dp[0] + n + 1, dp[1] + 10 - (n+1))
        dp = (a, b)
    return dp[0]

print(solve(N))


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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int main(){
  int r,d,x; cin >> r >> d >> x;
  REP(i,10){
    x = r * x - d;
    cout << x << "\n";
  }
}

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

f = True
cnt = 0
while(f):
	for i in range(N):
		if A[i]%2 == 0:
			A[i] = A[i]//2
		else:
			f = False
			break
	if f:
		cnt += 1

print(cnt)
			

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        int sum=1;
        for(int i=0;i<n;i++)
        {
            int t;
            cin>>t;
            if(t%2==0)
                sum*=2;
        }
        cout<<(int)pow(3,n)-sum<<endl;
    }
    return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  if(k%2){
    long long ans=0;
    for(int i=1;i<=n;i++){
      if(i%k==0){
        ans++;
      }
    }
    cout<<ans*ans*ans<<endl;
  }else{
    long long ans=0,ans2=0;
    for(int i=1;i<=n;i++){
      if(i%k==k/2){
        ans++;
      }
      if(i%k==0){
        ans2++;
      }
    }
    cout<<ans*ans*ans+ans2*ans2*ans2<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string S;
	cin >> S;
	cout << S[0] << S.size()-2 << S[S.size() - 1] << endl;
	return 0;
}


Measured memory_bytes: 256