akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
void test_case() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> G(n + 1);
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> buff(n + 1);
  for (int i = 1; i <= q; ++i) {
    int p, x;
    cin >> p >> x;
    buff[p] += x;
  }
  vector<int> res(n + 1);
  function<void(int, int, int)> dfs = [&](int u, int prv, int p) {
    res[u] = prv + buff[u];
    for (auto v : G[u]) {
      if (v != p) {
        dfs(v, prv + buff[u], u);
      }
    }
  };
  dfs(1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    cout << res[i] << " \n"[i == n];
  }
}
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}

Measured memory_bytes: 33664
w = int(input())
n = int(input())
amida = [i for i in range(1, w + 1)]
for _ in range(n):
    a, b = list(map(int, input().split(',')))
    temp = amida[a - 1]
    amida[a - 1] = amida[b - 1]
    amida[b - 1] = temp
for i in amida:
    print(i)



Measured memory_bytes: 5596
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
using namespace std;


int main() {
    string S;
    cin >> S;

    //
    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }


    //
    int num_c = 0;
    for (int i = 2, len = S.size()-1; i < len; ++i) {
        if(S[i] == 'C') num_c++;
    }
    if(num_c != 1){
        cout << "WA" << endl;
        return 0;
    }


    //
    int num_lower = 0;
    for (int i = 0; i < S.size(); ++i) {
        if('a' <= S[i] && S[i] <= 'z') num_lower++;
    }

    if(num_lower != S.size()-2){
        cout << "WA" << endl;
        return 0;
    }


    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> as;
  ll tmp;
  ll negativeCount = 0;
  ll zeroCount = 0;
  for(int i = 0; i < N; ++i) {
    cin >> tmp;
    if(tmp < 0) {
      negativeCount++;
      tmp = -tmp;
    } else if(tmp == 0) {
      zeroCount++;
    }
    as.push_back(tmp);
  }
  sort(as.begin(), as.end());

  ll sum = accumulate(as.begin(), as.end(), 0LL);
  if(zeroCount == 0 && negativeCount % 2 == 1) {
    sum -= as[0] * 2;
  }
  cout << sum << endl;
  return 0;
}

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

n = int(input())
cnt = 0
ans = []
for i in range(1, n + 1):
    cnt += i
    ans.append(i)
    if cnt >= n:
        if cnt > n:
            ans.remove(cnt - n)
        for j in range(len(ans)):
            print(ans[j])
        exit()


Measured memory_bytes: 3572
N = int(input())
ws = list(map(int, input().split()))
ans = 10**9
for i in range(1, N):
    s1 = sum(ws[:i])
    s2 = sum(ws[i:])
    if abs(s1-s2) < ans:
        ans = abs(s1-s2)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <stdarg.h>
#include <string>
#include <algorithm>
using namespace std;


int main()
{
    int N,X=0;
    int m[110];
    int i,kei=0;
    int min= 1000;
    cin >> N >> X;
    
    for(i=1;i<=N;i++)
    {
        cin >> m[i];
        kei = kei +m[i];
        if(m[i]<=min)
        {
            min =m[i];
        }
        
        
    }
    
    int ans = N+(X-kei)/min;
    cout << ans << endl;
}


Measured memory_bytes: 256
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [N, M] = r.nn()
    const A = r.nnls()

    const lib: Record<number, number> = {}

    for (let i = 0; i < M; i++) {
      const [s, c] = A[i]

      // if (lib[s] !== undefined && lib[s] !== c) return -1
      if (s in lib && lib[s] !== c) return -1
      if (s === 1 && c === 0 && N >= 2) return -1
      lib[s] = c
    }

    if (lib[1] === undefined) {
      lib[1] = N === 1 ? 0 : 1
    }

    let res = ''

    for (let i = 1; i <= N; i++) {
      res += String(lib[i] || 0)
    }

    return res
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map(line => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;

namespace B___Nice_Shopping
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var m = int.Parse (input[2]);
            var arrayA = new int[a];
            var arrayB = new int[b];
            var minA = int.MaxValue;
            var minB = int.MaxValue;
            input = Console.ReadLine ().Split (' ');
            for (var i = 0; i < a; i++)
            {
                arrayA[i] = int.Parse (input[i]);
                minA = Math.Min (minA, arrayA[i]);
            }
            input = Console.ReadLine ().Split (' ');
            for (var i = 0; i < b; i++)
            {
                arrayB[i] = int.Parse (input[i]);
                minB = Math.Min (minB, arrayB[i]);
            }
            var tuple = new Tuple<int, int, int>[m];
            for (var i = 0; i < m; i++)
            {
                input = Console.ReadLine ().Split (' ');
                tuple[i] = Tuple.Create (int.Parse (input[0]), int.Parse (input[1]), int.Parse (input[2]));
            }
            var ans = new List<int> ();
            ans.Add (minA + minB);
            for (var k = 0; k < m; k++)
            {
                ans.Add (arrayA[tuple[k].Item1 - 1] + arrayB[tuple[k].Item2 - 1] - tuple[k].Item3);
            }
            Console.WriteLine (ans.Min ());
        }
    }
}

Measured memory_bytes: 35676
while True:
    n=int(input())
    if n==0:
        break
    
    else:
        score=[]
        for i in range(n):
            score.append(int(input()))
        score.sort()
        score.pop(0)
        score.pop(-1)
        sum=0
        for i in range(n-2):
            sum+=score[i]
        print(int(sum/(n-2)))

Measured memory_bytes: 7500
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<int Modulo = MOD> struct Mint {
	lint val;
	constexpr Mint(lint v = 0) noexcept : val(v % Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		lint a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			lint t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint operator + (const Mint& r) const noexcept { return *this += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return *this -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return *this *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return *this /= r; }
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream &operator << (ostream &os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream &is, Mint<Modulo>& x) noexcept {
		lint tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, lint n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	string s1, s2;
	cin >> s1 >> s2;

	bool vert = (s1[0]!=s2[0]);
	mint ans = vert ? 6 : 3;
	for (int i = vert ? 2 : 1; i < N; i++) {

		if (s1[i] == s2[i]) {
			if (!vert) ans *= 2;
			vert = false;
		}
		else {
			if (vert) ans *= 3;
			else ans *= 2;
			i++;
			vert = true;
		}

	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <array>
#include <iomanip>
#include <unordered_set>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
using namespace std;
int n;
ll dp[3005][3005];
ll arr[3005];


int main(){
    AC
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        dp[i][i] = arr[i];
    }

    for(int i=2; i<=n; i++){
        for(int j=0; j<=n-i; j++){
            int end = j+i-1;
            dp[j][end] = max(arr[end]-dp[j][end-1], arr[j]-dp[j+1][end]);
        }
    }

    cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 49296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

int main() {

	long long A, B;
	char op;
	cin >> A >> op >> B;

	long long ret;
	if (op == '+') ret = A + B;
	if (op == '-') ret = A - B;
	cout << ret << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
      String[] strArr = br.readLine().split("\\s");
      BigInteger n = new BigInteger(strArr[0]);
      BigInteger m = new BigInteger(strArr[1]);
      
      System.out.println(n.modPow(m, new BigInteger("1000000007")));
      
    } catch (IOException e) {
      // TODO 自動生成された catch ブロック
      e.printStackTrace();
    }
    
  }

}



Measured memory_bytes: 24764
class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def hom(n,k)
    cmb(n+k-1, k)
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

# ABC132 Blue and Red Balls 2020/5/13 hom  nHk
# ABC145 2020/5/6
# ABC156 Roaming 2020/5/11 AC
# ABC167 E - Colorful Blocks 2020/5/11 AC

require 'bigdecimal'

n, a, b = gets.to_s.split.map{|t|t.to_i}
v       = gets.to_s.split.map{|t|t.to_i}.sort.reverse

f = Facts.new(100000000000000003)

s = v[0, a].sum
ave_f = s / ( a * 1.0 )
ave_i = ave_f.round

puts '%.10f' % ave_f  

cnt = v.count(v[a-1])
idx = v.index(v[a-1])

if s == v[0] * a 
  cnt = v.count(v[a-1])
  idx = v.index(v[a-1])
  
  start = a - idx
  goal  = [b - idx, cnt].min
  
  ans = 0
  start.upto(goal) do |i|
    ans += f.cmb(cnt, i)
  end
  
  puts ans
else
  puts f.cmb(cnt, a-idx)
end

Measured memory_bytes: 14456
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] in = sc.next().toCharArray();
		int[] a = new int[4];
		for(int i = 0; i < in.length; i++) {
			if(in[i] == 'K') a[0]++;
			if(in[i] == 'U') a[1]++;
			if(in[i] == 'P') a[2]++;
			if(in[i] == 'C') a[3]++;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
		
		
		
		
		
	}
}

Measured memory_bytes: 17324
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(u==s)
	a--;
	else
	b--;
	cout<<a<<" "<<b;	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int a;
    scanf("%d",&a);
    while(a--){
        int b,c,d;
        scanf("%d%d%d",&b,&c,&d);
        int max=b;
        if(b<c)max=c;
        if(max<d)max=d;
        if(max*max==b*b+c*c+d*d-max*max)printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 1008
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  string S;
  cin>>S;
  for(int i=0;i<3;i++)
    if(S[i]=='9')
      S[i]='1';
 	else	S[i]='9';
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define li long long int
#define mp make_pair
using namespace std;
 int main(){
 int n;
 cin>>n;
 vector<int>a(n+1),b(n);
 li count= 0;
 for(int  i = 0; i <= n; i++){
    cin>>a[i];
 count+=a[i];
 }
 for(int  i = 0; i < n; i++)
    cin>>b[i];
 for(int i = 0; i <= n; i++){
    if(i==0){
        if(a[i]>0){
            if(b[i]>=a[i]){
                b[i]=b[i] - a[i];
                 a[i]=0;
            }
            else {
                a[i] = a[i] - b[i];
                b[i]=0;
            }
           // cout<<2<<" "<<a[i]<<" ";

    }
    }
    else {
        if(b[i - 1] > 0){
                if(a[i] > b[i-1]){
            a[i] = a[i] - b[i -1];
                }
        else{
            a[i]=0;

        }
       // cout<<1<<" "<<a[i]<<" ";
        }
        if(a[i]>0 && i < n){
            if(b[i]>=a[i]){
             b[i]=b[i] - a[i];
                a[i]=0;
            }
            else  {
                a[i] = a[i] - b[i];
                b[i]=0;
            }
          //  cout<<3<<" "<<a[i]<<" ";
        }

    }
 }
 li count1=0;
 for(int  i = 0; i <= n; i++){
        //cout<<a[i]<<" ";
 count1+=a[i];
 }
 cout<<count - count1<<endl;




 }
 /*
3 5 2
4 5
*/


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        string S = RString();
        int N = S.Length;
        long ans = 0;
        int now = 0;
        while (now < N)
        {
            long cnt1 = 0;
            while (now < N && S[now] == '<') { now++; ans += ++cnt1; }
            long cnt2 = 0;
            while (now < N && S[now] == '>') { now++;ans += ++cnt2; }
            ans -= Min(cnt1, cnt2);
        }
        WriteLine(ans);
    }
}



class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 27712
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  int b[N];
  int ans[N];
  for (int i = 0; i < N; i++) {
    scanf("%d",&b[i]);
  }

  for (int i = 0; i < N; i++) {
    int flag = 0;
    for (int j = N-1-i; j >= 0; j--) {
      if(b[j] == j+1){
        flag = 1;
        ans[i] = j+1;
        for (int k = j; k < N-1; k++) {
          b[k] = b[k+1];
        }
        break;
      }
    }
    if(flag == 0){
      printf("-1");
      return 0;
    }
  }


  for (int i = N-1; i >= 0; i--) {
    printf("%d\n",ans[i]);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  string S;
  cin >> S;
  ll ans = 0;
  REP(i, 1 << S.size() - 1) {
    ll tmp = S[0] - '0';
    for (int j = 0; j < S.size() - 1; j++) {
      int a = 1 << j;
      int b = a & i;
      if (b != 0) {
        ans += tmp;
        tmp = 0;
        tmp = tmp * 10 + S[j + 1] - '0';
        continue;
      }
      tmp = tmp * 10 + S[j + 1] - '0';
    }
    ans += tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3500
#include<cstdio>
#include<cstring>
#include<vector>
#define int long long
using namespace std;
vector<int>e[30];
int tree[1001000],n,R[200100],vis[200100],ans;
char S[200100];
void modify(int t,int l,int r,int pos){
	if(l==r){
		tree[t]++;
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid)modify(t*2,l,mid,pos);
	else modify(t*2+1,mid+1,r,pos);
	tree[t]=tree[t*2]+tree[t*2+1];
}
int query(int t,int l,int r,int L,int R){
	if(L>r||l>R)return 0;
	if(L<=l&&r<=R)return tree[t];
	int mid=(l+r)/2;
	return query(t*2,l,mid,L,R)+query(t*2+1,mid+1,r,L,R);
}
signed main(){
	scanf("%s",S+1);
	n=strlen(S+1);
	for(int i=1;i<=n;i++)
		e[S[i]-'a'].push_back(i);
	int x=0;
	for(int i=0;i<=25;i++){
		if(e[i].size()&1)x++;
		for(int j=0,k=e[i].size()-1;j<k;j++,k--)
			R[e[i][j]]=e[i][k];
	}
	if(x>1)return puts("-1"),0;
	for(int i=1;i<=n;i++){
		int nxt=R[i];
		if(vis[i])continue;
		if(!nxt)continue;
		ans+=i-1-query(1,1,n,1,i);
		ans+=n-nxt-query(1,1,n,nxt,n);
		modify(1,1,n,i);
		modify(1,1,n,nxt);
		vis[i]=vis[nxt]=1;
	}
	printf("%lld\n",ans);
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int, int>> a, b;
    unordered_map<int, int> af, bf;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i & 1) {
            bf[x]++;
        } else {
            af[x]++;
        }
    }
    for (auto x: af) {
        a.push_back(make_pair(x.second, x.first));
    }
    for (auto x: bf) {
        b.push_back(make_pair(x.second, x.first));
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    int a_first = a[0].first, a_second = a.size() > 1 ? a[1].first : 0;
    int b_first = b[0].first, b_second = b.size() > 1 ? b[1].first : 0;
    if (a[0].second == b[0].second) {
        cout << min(n - a_first - b_second, n - a_second - b_first) << endl;
    } else {
        cout << (n - a_first - b_first) << endl;
    }
}


Measured memory_bytes: 5524
def base_changer(number,base):
    buff=97+abs(base-10)
    dic={};buff2='';buff3=10
    for i in range(97,buff+1):
        dic[buff3]=chr(i)
        buff3+=1   
    while(number>=base):
        mod=int(number%base)
        number=int(number//base)
        if (mod) in dic.keys():
            buff2+=dic[mod]
            continue
        buff2+=str(mod)
    if (number) in dic.keys():
        buff2+=dic[number]
    else:
        buff2+=str(number)

    return buff2[::-1]  
N,K = map(int, input().split())
print(len(base_changer(N,K)))

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

using namespace std;

#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define loop(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e9+7;

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

    int n;

    cin >> n;

    cout << n/3 << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a;
  if(a%1000==0) cout<<0<<endl;
  else 
  {
    c=(a/1000)+1;
    cout<<(1000*c)-a<<endl;
  }
 return 0; 
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int G(int X,int N)
{
	if(X%10==0)
		return 0;
	int res=0;
	int F=X%10;
	int XX=X;
	while(X>9)
		X/=10;
	int L=X;
	if(F==L)
		res++;
	int XXX=10;
	while(true)
	{
		for(int i=0;i<XXX/10;i++)
			if(F*XXX+L+i*10>N)
				return res;
			else	res++;
		XXX*=10;
	}
	return 0;
}
int main()
{
	int N,ans=0;
	cin>>N;
	for(int i=1;i<=N;i++)
		ans+=G(i,N);
	cout<<ans<<endl;
	return 0;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }



  int main(){
    int N;
    cin >> N;
    if(N % 10 == 0){
      print(10);
      return 0;
    }
    int ans = MOD;
    for(int i = 1; i + i <= N; i++){
      int A, B, sum = 0;
      A = i;
      B = N - i;
      while(A > 0){
      sum += A % 10;
      A /= 10;
     }
      while(B > 0){
      sum += B % 10;
      B /= 10;
     }
    ans = min(ans, sum);
  }
  print(ans);
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX_INT 10e9
int main()
{
  	ll i,j,k,n;
  cin>>n;
  int a[n]={0};
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  int m=a[0];
  for(i=1;i<n;i++){
    if(a[i]<m-1){
     cout<<"No"<<endl;
      return 0;
    }
    m=max(m,a[i]);
  }
  cout<<"Yes"<<endl;
    return 0;
    
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

int n, a[10];

bool dfs(int depth, int b, int c) {
    if (depth == 10)
        return true;
    bool ret = false;
    if (a[depth] > b) {
        ret = ret || dfs(depth + 1, a[depth], c);
    }
    if (a[depth] > c) {
        ret = ret || dfs(depth + 1, b, a[depth]);
    }
    return ret;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        if (dfs(0, 0, 0))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


Measured memory_bytes: 3060
from collections import Counter
n = int(input())
A = list(map(int, input().split()))

P = [i+a+1 for i,a in enumerate(A)]
Q = [j-a+1 for j,a in enumerate(A)]

cQ = Counter(Q)
ans = 0
for p in P:
    ans += cQ[p]
print(ans)

Measured memory_bytes: 50652
import Control.Applicative

manhattanDistance :: [Int] -> [Int] -> Double
manhattanDistance x y = realToFrac $ sum $ map abs $ zipWith (-) x y

euclideanDistance :: [Int] -> [Int] -> Double
euclideanDistance x y = sqrt $ realToFrac $ sum $ map (^2) $ zipWith (-) x y

chebyshevDistance :: [Int] -> [Int] -> Double
chebyshevDistance x y = realToFrac $ maximum $ map abs $ zipWith (-) x y

thirdMinkowskiDistance :: [Int] -> [Int] -> Double
thirdMinkowskiDistance x y = (** (1.0/3.0) ) $ realToFrac $ sum $ map ((^3) . abs) $ zipWith (-) x y

main = do{
    n <- getLine;
    x <- map (read::String->Int) . words <$> getLine;
    y <- map (read::String->Int) . words <$> getLine;
    putStrLn $ show $ manhattanDistance x y;
    putStrLn $ show $ euclideanDistance x y;
    putStrLn $ show $ thirdMinkowskiDistance x y;
    putStrLn $ show $ chebyshevDistance x y;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<pair<ll, int> > m(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    m[i].first = a[i] + b[i];
    m[i].second = i;
  }
  sort(m.rbegin(), m.rend());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {  // 高橋のターン
      ans += a[m[i].second];
    } else {
      ans -= b[m[i].second];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(void)
{
    int sum=0,mx=0;
    int n;
    cin >> n;
    while(n--){
        int temp;
        cin >> temp;
        sum+=temp;
        if(mx<temp) mx=temp;
    }
    cout << (mx<sum-mx ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mx 105
int n,W;
int weight[mx],value[mx];

#define ll long long

ll dp[mx][100000+mx];
ll func(int i ,int w)
{
    if(i>=n+1) return 0;
    if(dp[i][w]!=-1) return dp[i][w];

    ll p1 = 0 ,p2 = 0 ;
    if(w+weight[i]<=W)
    {
        p1 = value[i]+func(i+1,w+weight[i]);
    }
    p2=func(i+1,w);

    dp[i][w]=max(p1,p2);
    return dp[i][w];
}
int main()
{
    memset(dp , -1 , sizeof dp);
    scanf("%d %d\n",&n,&W);

    for(int i=1;i<=n;i++) scanf("%d %d",&weight[i],&value[i]);

    ll ans = func(1,0);
    printf("%lld\n",ans);

}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N), B(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N; ++i) {
    scanf("%d", &B[i]);
  }
  vector<int> C(N);
  int ans = 0;
  for (int k = 0; k < 29; ++k) {
    int T = (1 << k);
    for (int i = 0; i < N; ++i) {
      C[i] = B[i] % (2 * T);
    }
    sort(C.begin(), C.end());
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
      int a = A[i] % (2 * T);
      cnt += distance(lower_bound(C.begin(), C.end(), T - a),
                      lower_bound(C.begin(), C.end(), 2 * T - a));
      cnt += distance(lower_bound(C.begin(), C.end(), 3 * T - a),
                      lower_bound(C.begin(), C.end(), 4 * T - a));
    }
    if (cnt & 1) { ans |= (1 << k); }
  }
  printf("%d\n", ans);
  return 0;
}


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll N,K,S;
  cin>>N>>K>>S;
  for(int i=0;i<K;i++)cout<<S<<" ";
  if(S==1) for(int i=K;i<N;i++)cout<<S+1<<" ";
  else for(int i=K;i<N;i++)cout<<S-1<<" ";
  return 0;
}


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

int main()
{

	string sh;
	cin >> sh;
	if (sh[0] == sh[1] || sh[1] == sh[2] || sh[2] == sh[3])
	{
		printf("Bad\n");
	}
	else
	{
		printf("Good\n");
	}
	return 0;
}

Measured memory_bytes: 3588
def eat(a,day):
    count = 0
    i = 0
    while(True):
        if i == 0:
            count = count + 1
        elif i*a +1 <= day:
            count = count + 1
        else:
            break
        i = i + 1
    return count

N = int(input())
dn = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append(int(input()))

eatcounts = 0
for i in range(N):
    eatcounts = eatcounts + eat(A[i],dn[0])

eatcounts = eatcounts + dn[1]
print(eatcounts)


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

#include <iostream>

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;

    int output = 0;
    for (int start = 0; start < S.length(); start++) {
        int max = 0;
        for (int end = start; end < S.length() - start; end++) {
            int tmp = 0;
            if ((end - start + 1) % 2 != 1) continue;
            for (int i = 0; i < (end - start + 1) / 2; i++) {
                if (S[start + i] == S[start + i + (end - start + 1) / 2]) {
                    tmp++;
                } else {
                    tmp = 0;
                    break;
                }
            }
            tmp *= 2;
            // cout << tmp << "::";
            // for (int i = start; i < end; i++) {
            // cout << S[i];
            // }
            // cout << endl;
            if (max < tmp) max = tmp;
        }
        if (output < max) output = max;
    }

    cout << output << endl;
    return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int to; ll cap; int rev;};

const ll MOD = 1000000007;
const double EPS = 1e-9;
const int MAX_V = 202;

vector<edge> G[MAX_V];
vector<int> level(MAX_V, -1);
vector<int> iter(MAX_V, 0);
int N, s, t;

void add_edge(int from, int to, ll cap){
    /*
        ある点vに対する辺の集合はvectorで管理されているので，
        そのvectorの中の何番目の辺に対応しているかを記憶する→rev
    */
    G[from].push_back({to, cap, (int)G[to].size()});
    G[to].push_back({from, 0, (int)G[from].size()-1});
}

void bfs(int s){
    level = vector<int>(MAX_V, -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(edge e : G[v]){
            if(e.cap > 0 && level[e.to] == -1){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(int v, int t, ll f){
    if(v == t) return f;
    rep((int)G[v].size()){
        edge &e = G[v][i]; //eの中身を書き換えたいのでポインタを使用
        if(level[v] < level[e.to] && e.cap > 0){
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll dinic(int s, int t){
    ll max_flow = 0;
    while(true){
        bfs(s);
        if(level[t] < 0) return max_flow;
        ll f;
        while((f = dfs(s, t, LLONG_MAX)) > 0){
            max_flow += f;
        }
    }

    return max_flow;
}


int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    vector<Pll> red(N), blue(N);
    rep(N){
        cin >> red[i].first >> red[i].second;
        add_edge(0, i+1, 1);
    }
    rep(N){
        cin >> blue[i].first >> blue[i].second;
        add_edge(N+1+i, 2*N+1, 1);
    }
    rep(N){
        repp(j, N){
            if(red[i].first < blue[j].first && red[i].second < blue[j].second){
                add_edge(i+1, N+1+j, 1);
            }
        }
    }

    cout << dinic(0, 2*N+1) << endl;
}


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

int main() {
	string s;
	cin >> s;

	int n = s.size();
	int a, b;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			b = i;
			break;
		}
	}

	cout << b - a + 1 << endl;

	return 0;
}

Measured memory_bytes: 644
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, p, m;
ll Plus[int(2e5+5)], Minus[int(2e5+5)];
ll ans = 1;

int main(){
  scanf("%d%d", &N, &K);

  for (int i = 0; i < N; i++){
    ll A; scanf("%lld", &A);
    if (N == K) {
      ans *= A; ans %= MOD;
      continue;
    }
    if (A >= 0) Plus[p] = A, p++;
    else Minus[m] = -1 * A, m++; 
  }

  if (N == K){
    if (ans < 0) ans += MOD;
    printf("%lld\n", ans);
    return 0;
  }

  if (p == 0 && K % 2 != 0){
    sort(Minus, Minus + m);
    for (int i = 0; i < K; i++){
      ans *= Minus[i]; ans %= MOD;
    }
    ans *= -1;
    if (ans < 0) ans += MOD;
    printf("%lld\n", ans);
    return 0;
  }

  sort(Plus, Plus + p, greater<ll>());
  sort(Minus, Minus + m, greater<ll>());

  int now = 0;
  for (int i = K - 1; i >= 1; i-=2){
    if (Minus[now] * Minus[now + 1] == 0) break;
    if (Plus[i] * Plus[i-1] > Minus[now] * Minus[now + 1]) break;
    Plus[i] = Minus[now];
    Plus[i-1] = Minus[now + 1];
    now += 2;
  }

  for (int i = 0; i < K; i++){
    ans *= Plus[i]; ans %= MOD;
  }
  printf("%lld\n", ans);


  return 0;
}


Measured memory_bytes: 6800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  bool memo = true;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      memo = false;
      break;
    }
  }
  int64_t ans = 1;
  if (memo == true) {
    bool memo2 = true;
    for (int i = 0; i < N; i++) { 
      if (A.at(i) <= 1000000000000000000 / ans ) {
        ans *= A.at(i);
      }
      else {
        cout << "-1" << endl;
        memo2 = false;
        break;
      }
    }
    if (memo2 == true) {
      cout << ans << endl;
    }
  }
  else {
    cout << "0" << endl;
  }
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
int main() {
    int N;
    cin>>N;
    vi H(N);
    for (int i = 0; i < N; i++)cin>>H[i];
    for (int i = N-2; i >=0 ; i--){
        if(H[i]-1==H[i+1])H[i]--;
        else if(H[i]-1>H[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		sc.close();
		if(N.charAt(0) == '9' || N.charAt(1) == '9') {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

class UnionFindTree {
   public:
    vector<int> parent;
    vector<int> siz;

    UnionFindTree(int n) {
        siz.resize(n, 1);
        parent.resize(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); int ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        parent[ry] = rx;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    UnionFindTree uft(N + 1);
    vector<int> last(M, -1);
    REP(i, 0, N) {
        int K; cin >> K;
        REP(j, 0, K) {
            int L; cin >> L; L--;
            if (last[L] != -1) {
                uft.unite(i, last[L]);
            }
            last[L] = i;
        }
    }

    if (uft.size(0) == N) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int c[3];
    while (scanf("%d %d %d", &c[0], &c[1], &c[2]) != EOF) {
        int used[11] = {};
        for (int i = 0; i < 3; i++)
            used[c[i]] = 1;
        
        int sum = c[0] + c[1], cnt = 0;
        for (int i = 1; i <= 10; i++)
            if (!used[i] && i + sum <= 20) cnt++;
        
        if (cnt >= 4) puts("YES");
        else puts("NO");
    }

    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int X;
  cin >> X;
  div_t d = div(X, 500);
  div_t e = div(d.rem, 5);
  cout << (d.quot * 1000 + e.quot * 5) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;
const ll Mod = 1e9+7;

struct mat{ll a[3][3];mat(){memset(a,0,sizeof a);}}one,st,trans;
mat mul(mat &x,mat &y)
{
	mat re;
	for(int i=0;i<3;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++)
		(re.a[i][k]+=x.a[i][j]*y.a[j][k]%Mod)%=Mod;
	return re;
}
mat pw(mat x,int k)
{
	mat re=one;
	for(;k;k>>=1,x=mul(x,x)) if(k&1)
		re=mul(re,x);
	return re;
}
int n,m;

int main()
{
	one.a[0][0]=one.a[1][1]=one.a[2][2]=1ll;
	
	st.a[0][0]=1ll;
	trans.a[0][0]=2ll,trans.a[0][1]=2ll,trans.a[0][2]=1ll;
	trans.a[1][0]=1ll; trans.a[1][1]=1ll,trans.a[1][2]=1ll;
	trans.a[2][0]=1ll,trans.a[2][1]=0ll,trans.a[2][2]=1ll;
	scanf("%d%d",&m,&n); int las=0;
	for(int i=1;i<=n;i++)
	{
		int p; scanf("%d",&p);
		mat temp=pw(trans,p-las-1); las=p;
		st=mul(st,temp);
		trans.a[0][0]=1ll,trans.a[1][0]=0ll,trans.a[2][0]=0;
		st=mul(st,trans); 
		trans.a[0][0]=2ll,trans.a[1][0]=1ll,trans.a[2][0]=1ll;
	}
	mat temp=pw(trans,m-las);
	st=mul(st,temp);
	printf("%lld\n",st.a[0][2]);
	
	return 0;
}


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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e5 + 5;

int main()
{
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll l = a + b, r = c + d;
    if (l < r) cout << "Right" << endl;
    else if (l > r) cout << "Left" << endl;
    else cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

bool isHate(std::vector<int> D, int num) {
    int rem = num;
    while (rem > 0) {
        auto result = std::find(D.begin(), D.end(), (rem)%10);
        if (result != D.end()) return true;
        rem /= 10;
    }
    return false;
}

int main() {
    int N, K, temp;
    std::cin >> N >> K;

    std::vector<int> D;
    for (int i=0; i<K; ++i) {
        std::cin >> temp;
        D.push_back(temp);
    }
    
    for (int i=N; i<=99999; ++i) {
        if (!isHate(D, i)) {
            std::cout << i << std::endl;
            break;
        }
    }

    return 0;
}

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

using namespace std;

typedef struct BC {
  int B;
  int C;

  BC(int b_, int c_) {
    B = b_;
    C = c_;
  }

  bool operator<(const BC &other) const {
    return C < other.C;   
  }
  bool operator>(const BC &other) const {
    return C > other.C;   
  }
} bc_t;

int main(void) {
  int N, M; cin >> N >> M;
  vector<int> A;
  vector<bc_t> D;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    A.push_back(a); 
  }

  for (int i = 0; i < M; i++) {
    int b, c; cin >> b >> c;
    D.push_back(BC(b, c));
  }

  sort(D.begin(), D.end(), greater<bc_t>());
  sort(A.begin(), A.end());
  bool fin = false;
  int idx = 0;
  for (int i = 0; i < M && !fin; i++) {
    for (int j = idx; j < min(N, idx + D[i].B); j++) {
      if (D[i].C <= A[j]) {
        fin = true;
        break;
      } else {
        A[j] = D[i].C;
      }
    }
    idx += D[i].B;
    if (idx >= N) {
      break;
    }
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i];
  }

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

Measured memory_bytes: 1784
#include<stdio.h>

int main(void){
	int a,b,c,i,cnt = 0;
	scanf("%d %d %d",&a,&b,&c);
	if(a <= c){
		for( i = a;i <= b; i++){
			if(c % i == 0) {
//				printf("%d\n",i);
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int mcd[500][500];
int main() {
	long long int n,d;
	int a,b,c,tot=0;
	scanf("%d",&a);
	b= a;
	c= a;
	for(int i=1;i<=200;i++) {
		for(int j=1;j<=200;j++) {
			mcd[i][j] = __gcd(i,j);
		}
	}
	for(int i=1;i<=a;i++) {
		for(int j=1;j<=b;j++) {
			for(int k=1;k<=c;k++) {
				tot += mcd[mcd[i][j]][k];
			}
		}
	}
	printf("%d",tot);
}

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

int main() {
  int n; cin>>n; 
  vector<int>a(n);
  vector<int>b(n);
  for(int i=0; i<n;i++){
    int A; cin>>A;
    a[i]=A;
    b[i]=A;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    if(b[i]==a[n-1]) cout<<a[n-2]<<endl;
    else cout<<a[n-1]<<endl;
  }
}

Measured memory_bytes: 3200
n = int(input())
h = list(map(int ,input().split()))
dp = [0 for i in range(n)]
h.reverse()
count = 0
for i in range(n - 1):
    if h[i + 1] >= h[i]:
        count += 1
        dp[i] = count
    else:
        count = 0
        dp[i] = count
print(max(dp))

Measured memory_bytes: 15020