akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        static long mod = (long)Math.Pow(10, 9) + 7;

        public static void Main(string[] args)
        {
            long[] NAB = Read(Console.ReadLine());
            long N = NAB[0];
            long A = NAB[1];
            long B = NAB[2];

            string[] stringXs = Console.ReadLine().Split(' ');
            long[] ds = new long[N - 1];
            long sumD = int.Parse(stringXs[stringXs.Length-1])- int.Parse(stringXs[0]);


            for (int i = 0; i < N-1; i++)
            {
                ds[i] = long.Parse(stringXs[i + 1]) - long.Parse(stringXs[i]);
            }



            long cost = sumD * A;

            foreach (var item in ds)
            {
                if (item * A > B)
                {
                    cost = cost - item*A + B;
                }
            }

            Console.WriteLine(cost);
            Console.ReadLine();
        }

        private static long[] Read(string input)
        {
            string[] strings = input.Split(' ');
            long num = strings.Length;
            long[] ints = new long[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = long.Parse(strings[i]);
            }

            
            return ints;
        }
    }
}


Measured memory_bytes: 18912
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

#累積和
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    B, A = A, B
    if min(A) == N:
        break

print(*A)


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

using namespace std;

#define N 200005
#define LL long long

int n, a, b, c, i, flag;
char s[3], st[N][3], Sol[N];

int main (void)
{
	scanf("%d%d%d%d",&n,&a,&b,&c);
	if ((LL)a+b+c!=2) {
		flag=0;
		for (i=1; i<=n; i++) {
			scanf("%s",s);
			if (s[0]=='A'&&s[1]=='B') {
				if (a>b) a--,b++,Sol[i]='B';
				else a++,b--,Sol[i]='A';
				if (a<0||b<0) flag=1;
			}
			else if (s[0]=='A'&&s[1]=='C') {
				if (a>c) a--,c++,Sol[i]='C';
				else a++,c--,Sol[i]='A';
				if (a<0||c<0) flag=1;
			}
			else {
				if (b>c) b--,c++,Sol[i]='C';
				else b++,c--,Sol[i]='B';
				if (b<0||c<0) flag=1;
			}
		}
		if (flag) puts("No");
		else {
			puts("Yes");
			for (i=1; i<=n; i++) printf("%c\n",Sol[i]);
		}
	}
	else {
	//	assert(0);
	    flag=0;
		for (i=1; i<=n; i++) scanf("%s",st[i]);
		for (i=1; i<=n; i++) {
			if (st[i][0]=='A'&&st[i][1]=='B') {
				if (!a) a++,b--,Sol[i]='A';
				else if (!b) a--,b++,Sol[i]='B';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='C') a++,b--,Sol[i]='A';
					else if (st[i+1][0]=='B'&&st[i+1][1]=='C') b++,a--,Sol[i]='B';
					else a++,b--,Sol[i]='A';
				}
				if (a<0||b<0) flag=1;
			}
			else if (st[i][0]=='A'&&st[i][1]=='C') {
				if (!a) a++,c--,Sol[i]='A';
				else if (!c) a--,c++,Sol[i]='C';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='B') a++,c--,Sol[i]='A';
					else if (st[i+1][0]=='B'&&st[i+1][1]=='C') c++,a--,Sol[i]='C';
					else a++,c--,Sol[i]='A';
				}
				if (a<0||c<0) flag=1;
			}
			else {
				if (!b) b++,c--,Sol[i]='B';
				else if (!c) b--,c++,Sol[i]='C';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='C') c++,b--,Sol[i]='C';
					else if (st[i+1][0]=='A'&&st[i+1][1]=='B') b++,c--,Sol[i]='B';
					else b++,c--,Sol[i]='B';
				}
				if (b<0||c<0) flag=1;
			}
		}
		if (flag) puts("No");
		else {
			puts("Yes");
		    for (i=1; i<=n; i++) printf("%c\n",Sol[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 4240
import math
l=[]
for i in range(5):
    l.append(int(input()))

res = 0
x   = 10
for i in range(5):
    res = res + math.ceil(l[i]/10)
    if l[i] % 10 != 0:
        x = min(x,l[i] % 10)
    
res = res * 10 - 10 + x

print(res)



Measured memory_bytes: 3060
while True:
    try:
        n, k, q = map(int, input().split())
        lst = []
        temp = k-q
        for i in range(n):
            lst.append(temp)
        for i in range(q):
            lst[int(input())-1] += 1
        for i in range(n):
            if lst[i] > 0:
                print('Yes')
            else:
                print('No')
    except:
        break

Measured memory_bytes: 6608
from collections import deque
s = input()
s = deque(s)
q = int(input())
reverse = False
for i in range(q):
    query = input()
    if len(query) == 1:
        reverse = not reverse
    else:
        if not reverse:
            if query[2] == '1':
                s.appendleft(query[4])
            else:
                s.append(query[4])
        else:
            if query[2] == '2':
                s.appendleft(query[4])
            else:
                s.append(query[4])
s ="".join(list(s))
if reverse:
    s = s[::-1]
print(s)

Measured memory_bytes: 8436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
#include <stack>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

//const int MOD = 1e9 + 7;

template <class T>
T GCD(T a, T b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

template <class T>
T LCM(T a, T b)
{
    return (a * b) / GCD(a, b);
}

template <class T>
T max_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(vec.size() - 1);
}
template <class T>
T min_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(0);
}

void ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    char s1[(n - 1) / 2];
    char s2[(n - 1) / 2];
    for (int i = 0; i < (n - 1) / 2; i++){
        s1[i] = s.at(i);
        s2[i] = s.at((n + 1) / 2 + i);
    }
    //char s2[(n - 1) / 2];
    bool flag = true;
    for (int i = 0; i < n; i++){
        if (s.at(i) != s.at(n - 1 - i)){
            flag = false;
        }
    }
    if (flag){
        for (int i = 0; i < (n - 1) / 2; i++){
            if (s1[i] != s1[(n-1)/2 -1 -i]){
                flag = false;
            }
            if (s2[i] != s2[(n-1)/2 -1 -i]){
                flag = false;
            }
        }
    }
    ans(flag);
}

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

int main(){
int n,k;
  cin>>n>>k;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  for(int i=1;i<n;i++){
  for(int j=i-1;j>=max(i-k,0);j--){
  	dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
  }
  }
  cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define hell 2000000000000000000
using namespace std;

long long a,b,c,d,n;
long long mncost1=hell,mncost2=hell;
long long mncost(long double sum,long long cost,long long need){
	if (sum>need+0.0)
		return hell;
	if (sum==need+0.0)
		return cost;
	long long cost1,cost2,cost3,cost4;
	cost1=mncost(sum+0.25,cost+a,need);
	cost2=mncost(sum+0.5,cost+b,need);
	cost3=mncost(sum+1,cost+c,need);
	cost4=mncost(sum+2,cost+d,need);
	return min(cost1,min(cost2,min(cost3,cost4)));
}
int main() {
	
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
	mncost1=mncost(0.0,0,1);
	mncost2=mncost(0.0,0,2);
	long long ans=n/2*mncost2;
	if (n&1)
		ans+=mncost1;
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    bool ans = false;
    for (char ch: s) {
        if (ch == '7') {
            ans = true;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}



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

int main(){
 int a,b,c;
  cin>>a>>b;
  vector<int> n(a);
 c=1000000000;
  for(int i=0;i<a;i++){
 cin>>n[i];
    }
  sort(n.begin(),n.end());
  for(int i=0;i<a-b+1;i++){
c=min(c,abs(n[i]-n[i+b-1]));
//cout<<n[i]<<endl;
  }
  cout<<c<<endl;

}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int n, y;;
int main(){
    cin >> n >> y;
    for(int i=n;i>=0;i--){
        for(int j=n-i;j>=0;j--){
            int k=n-(i+j);
            if((i*10000)+(j*5000)+(1000*k) == y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int count = 0;
  for (int i=100; 0<i;i--){
    if (a%i == 0 && b%i == 0) count += 1;
    if (count == k){
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var D = new Dictionary<string, int>();
        int N = cin.nextint;
        for (int i = 0; i < N; i++)
        {
            var s = ReadLine();
            if (!D.ContainsKey(s))
            {
                D[s] = 0;
            }
            D[s]++;
        }
        int M = cin.nextint;
        for (int i = 0; i < M; i++)
        {
            var s = ReadLine();
            if (D.ContainsKey(s))
            {
                D[s]--;
            }
        }
        int ans = 0;
        foreach (var item in D)
        {
            ans = Math.Max(ans, item.Value);
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13152
flag = true
while line = gets
  if flag
    flag = false
  else puts
  end
  line.chomp!
  nums = line.rjust(5,"0").split("").map(&:to_i);
  nums.each do |n|
    if n<5
      print "*"
    else print " "
    end
  end
  puts
  nums.each do |n|
    if n>=5
      print "*"
    else print " "
    end
  end
  puts
  puts "====="
  a = nums.map{|n| n%5}
  1.upto(5) do |i|
    a.each_with_index do |x,j|
      if i<=x
        print "*"
      else
        print " "
        a[j]=5
      end
    end
    puts
  end
end

Measured memory_bytes: 2456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;

struct Mark{
	int col,ti; Mark(){}
	Mark(int col,int ti): col(col),ti(ti){}
	bool operator > (const Mark &B) const {return ti > B.ti;}
}last[11][maxn],Ans[maxn];

int n,m,q;

vector <int> v[maxn];

inline Mark max(const Mark &x,const Mark &y) {return x > y ? x : y;}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n >> m;
	while (m--)
	{
		int x,y; scanf("%d%d",&x,&y);
		v[x].push_back(y); v[y].push_back(x);
	}
	cin >> q;
	for (int i = 1; i <= q; i++)
	{
		int x,d,c;
		scanf("%d%d%d",&x,&d,&c);
		Mark now = Mark(c,i);
		Ans[x] = max(Ans[x],now);
		last[d][x] = max(last[d][x],now);
	}
	for (int j = 10; j; j--)
		for (int i = 1; i <= n; i++)
		{
			if (!last[j][i].ti) continue;
			for (int k = 0; k < v[i].size(); k++)
			{
				int to = v[i][k];
				Ans[to] = max(Ans[to],last[j][i]);
				last[j - 1][to] = max(last[j - 1][to],last[j][i]);
			}
		}
	for (int i = 1; i <= n; i++) printf("%d\n",Ans[i].col);
	return 0;
}

Measured memory_bytes: 15864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        ll temp=a;
        a=b;
        b=temp;
    }
    ll r=a%b;
    while(r>0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll> xs(n);
    for(ll i=0;i<n;i++){
        cin>>xs[i];
    }
    if(n==1){
        cout<<abs(x-xs[0]);
        return 0;
    }
    xs.push_back(x);
    sort(xs.begin(),xs.end());
    vector<ll> xdiff(n);
    for(ll i=0;i<n;i++){
        xdiff[i]=xs[i+1]-xs[i];
    }
    ll r=gcd(xdiff[0],xdiff[1]);
    for(int i=2;i<n;i++){
        r=gcd(r,xdiff[i]);
    }
    cout<<r<<endl;
    return 0;
}

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

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

using namespace std;

template <int Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  int a;

  constexpr modint(int x = 0) noexcept : a(x % Modulus){
      if(a < 0) a += Modulus;
  }
  constexpr int &value() noexcept { return a; }
  constexpr const int &value() const noexcept { return a; }

  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs;}
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs;}
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs;}
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs;}
  //increment, decrement
  constexpr modint &operator++() noexcept {a++; if(a >= Modulus) a -= Modulus; return *this;}
  constexpr modint &operator--() noexcept {a--; if(a < 0) a += Modulus; return *this;}

  //calc inverse
  constexpr modint operator~() noexcept {return modint(1) / *this;}

  //interpret -1 as (modulus - 1)
  constexpr modint operator-() noexcept{ return modint(-a);}
  
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = (int) (1LL * a * rhs.a % Modulus);
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int exp = Modulus - 2;
    while (exp) {
      if (exp & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }

  //judge equal or not equal
  constexpr bool operator ==(const modint& rhs){return this->a == rhs.a;}
  constexpr bool operator !=(const modint& rhs){return this->a != rhs.a;}

  modint pow(int64_t n) const {
    modint ret(1), mul(a);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend constexpr ostream& operator << (ostream &os, const modint& x) noexcept {
    return os << x.a;
  }
  
};

const int MAX = 510000;
const int MOD = 1000000007;

using mint = modint<MOD>;

mint fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * mint(i);
        inv[i] = mint(MOD) - inv[MOD%i] * mint(MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}

// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k]);
}

int main(void){
    int N; cin >> N;
    mint A[N];
    rep(i, N){
        int a; cin >> a;
        A[i] = mint(a);
    }
    vector<mint> sum(N+1, 0);
    rep(i, N) sum[i+1] = sum[i] + A[i];
    mint ans(0);
    rep(i, N) ans += (sum[N] - sum[i+1])*A[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll num=1, ans=0, cnt=0, sum=0;

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

  ll S, W;
  cin >> S >> W;
  if(S<=W) cout << "unsafe" << newl;
  else cout << "safe" << newl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
ll dp[100005][13];

int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  ll sum2 = 0;
  ll x[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  for(int i = 1; i < n-1; i+=2){
    sum2 += 2*a[i];
  }
  //cout << sum << endl;
  //cout << sum2 << endl;
  x[0] = sum - sum2;
  for(int i = 1; i < n; i++) x[i] = 2*a[i-1] - x[i-1];
  for(int i = 0; i < n; i++) cout << x[i] << " ";
  cout << endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
string s[10000];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> s[i];
	
	int ans = 0;
	int a = 0, b = 0, ba = 0;
	rep(i, n) {
		rep(j, s[i].length() - 1) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
				ans++;
			}
		}
		if (s[i][0] != 'B' && s[i][s[i].length() - 1] == 'A') a++;
		if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') ba++;
		if (s[i][0] == 'B' && s[i][s[i].length() - 1] != 'A') b++;
	}
	
	if (ba > 0) {
		if (a > 0 && b > 0) {
			a--; b--;
			ans += ba + 1;
		}
		else if (a > 0) {
			a--;
			ans += ba;
		}
		else if (b > 0) {
			b--;
			ans += ba;
		}
		else {
			ans += max(0, ba - 1);
		}
	}
	
	cout << ans + min(a, b) << endl;
	return 0;
}

Measured memory_bytes: 768
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

bool can(vector<ll> D) {
    int N = D.size();
    vector<ll> imos(N + 1);
    imos[0] = 1; imos[1] = -1;

    for(int i=0; i+1<N; i++) {
        if(imos[i] > 0) {
            int x = D[i] / 10;
            // fprintf(stderr, "i = %d, x = %d\n", i, x);
            if(x > 0) {
                int l = i + 1, r = min(N, i + x + 1);
                imos[l]++; imos[r]--;
            }
        }
        imos[i+1] += imos[i];
    }
    return imos[N-1] > 0;
}

int main() {
    int N; cin >> N;
    vector<ll> D(N);
    for(int i=0; i<N; i++) cin >> D[i];

    bool ok = true;
    ok &= can(D);
    reverse(D.begin(), D.end());
    ok &= can(D);
    cout << (ok ? "yes" : "no") << endl;
    return 0;
}



Measured memory_bytes: 10000
import math
N = input()
A = list(map(int, input().split()))

f,e,d = 0,0,0

for a in A:
    x = a % 4
    if(x==0):
        f = f+1
    elif(x==2):
        e = e+1
    else:
        d = d+1
if(e>0):
    d = d+1
if(f >= d-1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> n;
  ll a1 = 1, b1 = 1, a2, b2;

  FOR(i, 0, n) {
	cin >> a2 >> b2;

	if (a1 < a2) a1 = a2;
	if (b1 < b2) b1 = b2;
	tmp = (a1 + a2 - 1) / a2;
	m = max(tmp, (b1 + b2 - 1) / b2);
	a1 = a2*m;
	b1 = b2*m;
  }
  cout << a1 + b1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

   int a, b, c, x;

   scanf("%d %d %d\n", &a, &b, &c);

      if (a > b){
         x = a;
         a = b;
         b = x;
      } if (b > c){
         x = b;
         b = c;
         c = x;
      } if (a > b){
         x = a;
         a = b;
         b = x;
      }

   printf("%d %d %d\n", a, b, c);

   return 0;
}

   


Measured memory_bytes: 2120
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
else:
    import math
    h_odds = math.ceil(h / 2)
    h_evens = h // 2
    w_odds = math.ceil(w / 2)
    w_evens = w // 2
    print(h_odds * w_odds + h_evens * w_evens)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int nmax=200005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
// modintを使うときはllをmintに
ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    COMinit();
    map<ll,ll> mp;
    for(ll i=2;i*i<=m;i++){
        while(m%i==0){
            mp[i]++;
            m/=i;
        }
    }
    if(m!=1){
        mp[m]++;
    }
    ll ans=1;
    for(auto x:mp){
        (ans*=com(n-1+x.second,n-1))%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int maxn=100000+10;
long long k,dp[maxn],vis[maxn],ans,cnt=0;
void dfs(long long len,long long now,long long Len)
{
	if(len==Len)
	{
		cnt++;
		if(cnt==k)
		{
			ans=now;
		}
		now/=10;
		return ;
	}
	long long w=now%10;
	for(long long i=w-1;i<=w+1;i++)
	{
		if(i<0||i>9)continue;
		dfs(len+1,now*10+i,Len);
	}
}
int main()
{
	cin>>k;
	for(long long len=1;len<=10;len++)
	{
		for(long long i=1;i<=9;i++)
		{
			dfs(1,i,len);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map(&:to_i)
including_one_minus = nums.select { |num| num < 0 }.size.odd? ? true : false
absolute_nums = nums.map { |num| num.abs }.sort
ans = absolute_nums.sum
ans -= absolute_nums.first * 2 if including_one_minus
puts ans


Measured memory_bytes: 23924
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  if((a * b) % 2 == 0)cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & -x)

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    cin.tie(0);
    cout.tie(0);
    //freopen("a.in", "r", stdin);


    int n, k;
    cin >> n >> k;
    vector<int> v(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];

    vector<int> dp(n + 1, 1000000000);
    dp[1] = 0;
    for(int i = 2; i <= n; i ++)
        for(int j = i - 1; j >= max(i - k, 1); j --)
            dp[i] = min(dp[i], dp[j] + abs(v[i] - v[j]));
    cout << dp[n];

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
       int n,x,T; cin >> n >> x >> T;
       int ans = (n + x - 1) / x;
       cout << ans * T << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long double A,B;
    cin>>A;
    cin>>B;
    if(A>B)
        cout<<"GREATER"<<endl;
    else if(A<B)
        cout<<"LESS"<<endl;
    else
        cout<<"EQUAL"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int main(){
    char ch[1001];
    
    while(1){
        scanf("%s", ch);
        if (ch[0] == '0')break;

        int num = 0, len = strlen(ch);
        for(int i = 0; i < len; i++){
            num += (ch[i] - '0');
        }

        printf("%d\n", num);
        
    }
    return 0;

}


Measured memory_bytes: 2724
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[100000],i,cnt=1;
    cin >> n;
    for(i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    for(i=1;i<n;i++) if(a[i-1]!=a[i])cnt++;
    cout << cnt - (n-cnt)%2;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << (X - Z) / (Y + Z) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
#define u_b upper_bound
#define l_b lower_bound

int N;
int s[200200];
vector<int> x;
map<int, int> y;
int A[200200];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        s[i + 1] = s[i] + A[i];
        x.push_back(s[i + 1]);
    }
    sort(x.begin(), x.end());
    int ans = 0;
    rep(i, N) {
        int xc = u_b(x.begin(), x.end(), s[i]) - l_b(x.begin(), x.end(), s[i]);
        ans = ans + xc - y[s[i]];
        ++y[s[i + 1]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17392
#include <iostream>
using namespace std;
 
int main()
{
    int n,a = 100000;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        a *= 1.05;
        if(a%1000)
        {
           a += 1000-a%1000;
         }
        
    }
    cout << a<< endl;
     return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  char first[1000];
  cin >> first;
  int len;
  len = strlen(first);
  vector<char> str(len);
  int i,j,k;
  for(i = 0;i < len;++i){
    str.at(i) = first[i];
  }
  int ordern; cin >> ordern;
  int a,b;
  string order;
  for(i = 0;i < ordern;++i){
    cin >> order;
    if(order == "print"){
      cin >> a >> b;
      for(j = a;j <= b;++j){
        cout << str.at(j);
      }
      cout << "\n";
    }else if(order == "reverse"){
      cin >> a >> b;
      reverse(str.begin()+a,str.begin()+b+1);
    }else{
      cin >> a >> b;
      string str1;  cin >> str1;
      k = 0;
      for(j = a;j <= b;++j){
        str.at(j) = str1.at(k);
        ++k;
      }
    }
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m, vector<int>(0));
  while(true) {
    int x;
    cin >> x;
    if(cin.eof()) break;
    for(int i=0; i<x; i++) {
      int y;
      cin >> y;
      v[y-1].push_back(334);
    }
  }
  int count = 0;
  for(int i=0; i<m; i++) if(v[i].size() == n) count++;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

using pci = pair<char, int>;
vector<pci> runlength(string s) {
  vector<pci> ret;
  int cnt = 1;
  int n = sz(s);
  rep3(i, 1, n) {
    if (s[i] == s[i - 1]) ++cnt;
    else { ret.eb(s[i - 1], cnt); cnt = 1; }
  }
  ret.eb(s[n - 1], cnt);
  return ret;
}

void solve() {
  string s;
  cin >> s;
  auto v = runlength(s);
  cout << sz(v) - 1 << endl;
}


Measured memory_bytes: 1608
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var a = Console.ReadLine();

            if(char.IsUpper(Convert.ToChar(a)))
            {
                Console.WriteLine('A');

            }
            else
            {
                Console.WriteLine('a');
            }
        }
    }

}

Measured memory_bytes: 25924
from operator import itemgetter


n = int(input())
info = [list(map(int, input().split())) for i in range(n)]

li = []
for i in range(n):
    x, l = info[i]
    li.append((x - l, x + l))
li = sorted(li, key = itemgetter(1))

r_max = - 10**18
ans = 0
for i in range(n):
    l, r = li[i]
    if r_max <= l:
        ans += 1
        r_max = r
print(ans)

Measured memory_bytes: 72536
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	ll H;
	int N;
	
	ll asum = 0;
	int tmp;
	cin >> H >> N;

	REP(i, N) {
		cin >> tmp;
		asum += tmp;
	}
	if (H > asum) cout << "No" << endl;
	else cout << "Yes" << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << "\n";

	return 0; 
}


Measured memory_bytes: 256
def main():
    N = int(input())
    for n in range(1, 3501):
        for h in range(1, 3501):
            denom = 4*n*h - N*n - N*h
            if denom == 0:
                continue
            w = (N*h*n) / denom
            if w == int(w) and w > 0:
                print(int(n), int(h), int(w))
                return
    
if __name__ == "__main__":
    main()


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

int main() {
    ll a, b, ans;
    cin >> a >> b;
    
    ans = a + b;

    if(ans < 24){
        cout << ans << endl;
    }
    else if(ans >= 24){
        ans -= 24;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
def qSort(array):
    left = []
    right = []

    if len(array) <= 1:
        return array

    ref = array[0]
    array = array[1:]
    for a in array:
        if a < ref:
            left.append(a)
        else:
            right.append(a)

    return qSort(left) + [ref] + qSort(right)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C_minus = []
C_plus = []
cnt = 0
if sum(A) < sum(B):
    print("-1")

else:
    for i, a in enumerate(A):
        tmp = A[i] - B[i]
        if tmp > 0:
            C_plus.append(tmp)
        elif tmp < 0:
            C_minus.append(tmp)

    C_plus = list(reversed(qSort(C_plus)))
    C_minus = qSort(C_minus)

    if len(C_minus) == 0:
        print(len(C_minus))
    else:
        start = 0
        judge = 0
        for c_m in C_minus:
            judge = c_m
            for i in range(start, len(C_plus)):
                judge += C_plus[i]
                if judge > 0:
                    start = i
                    C_plus[i] = judge
                    break

        print(len(C_minus)+start+1)


Measured memory_bytes: 20420
num = int(input())
b = list(map(int, input().split()))
a = []
for i in range(len(b) + 1):
    if i == 0:
        a.append(b[i])
    elif i == len(b):
        a.append(b[len(b)-1])
    else:
        a.append(min(b[i], b[i-1]))
print(sum(a))


Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
  int st,upm=0,dum=0,i,j,df,dn,d;
  scanf("%d",&st);
  for(i=0;i<st;i++){
    scanf("%d",&d);
    scanf("%d",&df);
    upm=0;
    dum=0;
      for(j=1;j<d;j++){
	scanf("%d",&dn);
	if(df>dn){
	  if(df-dn>dum){
	    dum=df-dn;
	  }
	}else if(dn>df){
	  if(dn-df>upm){
	    upm=dn-df;
	  }
	}
	df=dn;
      }
    printf("%d %d\n",upm,dum);
  }
  return 0;
}

    

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
	char a[100001][2],b[100001][2],c[2];
	int n,m,i,j,f;
	while(scanf("%d",&n),n){
		for(i=0;i<n;i++){
			scanf("%s %s",a[i],b[i]);
		}
		scanf("%d",&m);
		for(i=0;i<m;i++){
			scanf("%s",c);
			f=1;
			for(j=0;j<n;j++){
				if(a[j][0]==c[0]){
					f=0;
					printf("%c",b[j][0]);
				}
			}
			if(f){
				printf("%c",c[0]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
from itertools import product
from collections import Counter
 
n, c = map(int, input().split())
color_costs = [map(int, input().split()) for _ in range(c)]
matrix = [list(map(int, input().split())) for _ in range(n)]
 
colord = {(i, j):cost 
               for i, row in enumerate(color_costs)
               for j, cost in enumerate(row)}
 
color_counts = []
for n in range(3):
  counter = Counter(c-1 for i, row in enumerate(matrix) 
                                       for j, c in enumerate(row) 
                                       if (i+j)%3==n)
  color_counts.append(counter)
 
cc = [[(color, sum(colord[cellcolor, color]*n for cellcolor, n in color_count.items()))
                                                                    for color in range(c)]
                                                                    for color_count in color_counts]
 
dd = [sorted(xs, key=lambda x:x[1])[:3] for xs in cc]
ee = (a[1]+b[1]+c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3)
print(min(ee))

Measured memory_bytes: 6132
A, B, M = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

min_p = min(a) + min(b)

for i in range(M):
    x, y, c = [int(i) for i in input().split()]
    min_p = min(min_p, a[x-1]+b[y-1]-c)
    
print(min_p)


Measured memory_bytes: 17968
N = int(input())
a = list(map(int,input().split()))
ans = [0] * 8
over3200 = 0
rates = [1,400,800,1200,1600,2000,2400,2800,3200]
for i in range(N):
    if a[i] >= rates[8]:
        over3200 += 1
        continue
    for j in range(7,-1,-1):
        if a[i] >= rates[j]:
            ans[j] = 1
            break

min = 0
max = 0

if sum(ans) > 0:
    min = sum(ans)
else:
    min = 1

max = sum(ans) + over3200

print(min, max)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define G() Cr = getchar()
int Xr, Fr; char Cr;
inline int rd() {
	Xr =0 , Fr = 1, G();
	while(Cr < '0' || Cr > '9') {if(Cr == '-') Fr = -1; G();}
	while(Cr >='0' && Cr <= '9') Xr = (Xr<<1) + (Xr<<3) + (Cr&15), G();
	return Xr * Fr;
}
#define MAX_N 2005
#define LL long long
int n;
LL ans;
LL dp[MAX_N][MAX_N];
struct node {
	int pos;
	LL va;
}e[MAX_N];
bool comp(node x,node y) {
	return x.va < y.va;
}
int main() {
	n = rd();
	for(int i = 1; i <= n; i++) e[i].va = rd(), e[i].pos = i;
	sort(e+1,e+1+n,comp);
	for(int i = 1; i <= n; i++) {
		LL ma = e[i].va, t = e[i].pos;
		for(int l = 1, r = l + i - 1; r <= n; l++, r++)
			dp[l][r] = max(dp[l][r-1] + ma * abs(t - r), dp[l+1][r] + ma * abs(t - l));
	}
	cout<<dp[1][n]<<endl;
}

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


long double PI=3.141592653589793;

int main() {
  long double ans,a,b,h,m;
  
  cin >>a>>b>>h>>m;
  h=h*(1.0/12.0)*360.0+(m*0.5);
  m=m*(1.0/60.0)*360.0;

  long double rad=abs(h-m);
  if(rad>180) rad=180-(rad-180);
  if(rad==180){
    cout <<a+b<<endl;
  }else if(rad==90){
    ans=a*a+b*b;
    ans=pow(ans,0.5);
    cout <<ans<<endl;
  }else{
    rad*=(PI/ 180.0);
    ans=a*a+b*b-(2.0*a*b*cosl(rad));
    cout << fixed << setprecision(20) << pow(ans,0.5)<< endl;
  }
}


Measured memory_bytes: 4172
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

#define MAX 26

int main(void)
{
	string s,p;
	string tmp;
	int i,j,k;
	bool flg = false;

	getline(cin, s);
	getline(cin, p);

	for (i=0; i<s.size(); i++) {
		if (s[i] == p[0]) {
			k=i;
			for (j=0; j<p.size(); j++) {
				if (s[k] != p[j]) {
					break;
				}
				if ((k+1 >= s.size())) {
					k = 0;
				}
				else {
					k++;
				}
			}
			if (j == (p.size())) {
				flg = true;
				break;
			}
		}
	}
	if (flg == true) {
		cout << "Yes" <<endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}




Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>
#include <map>
 
using namespace std;
 
#define pb push_back;
 
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
 
int main(){
	int n;
	cin>>n;
	vi a(n);
	int minim = 1e6 + 1;
	int min_idx;
	int maxim = -(1e6 + 1);
	int max_idx;
 
	for(int i = 0; i < n; i++){
		cin>>a[i];
		if (a[i] > maxim){
			maxim = a[i];
			max_idx = i;
		}
		if (a[i] < minim){
			minim = a[i];
			min_idx = i;
		}
	}
 
	if (a[min_idx] >= 0){
		cout<<n - 1<<endl;
		for(int i = 1; i <= n -1; i++){
			cout<<i<<" "<<i + 1<<endl;
		}
		return 0;
	}
	if (a[max_idx] <= 0){
		cout<<n - 1<<endl;
		for(int i = n ; i >= 2; i--){
			cout<<i<<" "<<i - 1<<endl;
		}
		return 0;
	}
	if (a[max_idx] >= -a[min_idx]){
		cout<<2*n - 1<<endl;
		for(int i = 1 ; i <= n; i++){
			cout<<max_idx + 1<<" "<<i<<endl;
		}
		for(int i = 1; i <= n -1; i++){
			cout<<i<<" "<<i + 1<<endl;
		}
		return 0;
	}
	if (a[max_idx] < -a[min_idx]){
		cout<<2*n - 1<<endl;
		for(int i = 1 ; i <= n; i++){
			cout<<min_idx + 1<<" "<<i<<endl;
		}
		for(int i = n ; i >= 2; i--){
			cout<<i<<" "<<i - 1<<endl;
		}
		return 0;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

string s;
int a,b,i,j,l;
set<char>q;
cin>>s;
for(i=0;i<s.size();i++)
{
  q.insert(s[i]);
}
if(s.size()==q.size())
cout<<"yes\n";
else cout<<"no\n";
}

Measured memory_bytes: 256
#include<stdio.h>  

int main(void){  
  int n,x,stack[11],i;  
  while(scanf("%d",&n),n){ 
    
    for(i=0;n>0;i++){
      x=n%8;
      stack[i]=(x==4)?5:(x<4)?x:x+2;  
      n=n/8;  
    }
    for(;i>0;i--)printf("%d",stack[i-1]);
    printf("\n");
  }  
  return 0;
}  

Measured memory_bytes: 0
#include <stdio.h>

#define max 100

int main()
{
    int N, str[max], i, flag=0, num=0;
    
    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", &str[i]);
    }
    
    for (i=0; i<N; i++) {
        if(str[i]%2==0){
            num++;
            if(str[i]%3==0||str[i]%5==0)
                flag++;
        }
    }
    
    if(flag==num)
        printf("APPROVED");
    else
        printf("DENIED");
    
    return 0;
}


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

int main() {
  string n;
  cin>>n;
  bool ans=false;
  for(int i=0;i<n.size();i++){
    if(n[i]=='9'){
      ans=true;
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    m,d = LI()
    r = 0
    for i in range(d+1):
        d1 = i//10
        d2 = i%10
        if d1 < 2 or d2 < 2:
            continue
        if m >= d1*d2:
            r += 1

    return r


print(main())





Measured memory_bytes: 6716