akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) {
    cout << a - 1 << endl;
  } else {
    cout << a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, c = map(int, input().split())
    if c * a <= b:
        print(c)
    else:
        print(b // a)



if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    string s;
    bool flag=true;

    cin>>s;

    FOR(i,0,s.size()-1){
        if(i%2==0){
            if(s[i]=='L'){
                flag=false;
            }
        }else{
            if(s[i]=='R'){
                flag=false;
            }
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var nt = Reads();
            var N = nt[0];
            var T = nt[1];
            var t = Reads();
            long ans = 0;
            for (int i = 0; i <N-1; i++)
            {
                if (t[i + 1] - t[i] < T) ans += (t[i + 1] - t[i]);
                else ans += T;
            }
            ans += T;
            Console.WriteLine(ans);

            
           
         
            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 32416
fun main(args: Array<String>) {
    var (N, W) = pairIntLong()
    val WV = Array(4) { mutableListOf<Long>() }
    var baseW = 0 //WV[0].first.toLong()
    repeat(N) {
        val wv = pairIntLong()
        if (baseW == 0) baseW = wv.first
        WV[wv.first - baseW].add(wv.second)
    }
    WV.forEach {
        it.sortDescending()
        it.add(0, 0)
    }
    var ans = 0L
    for (n0 in WV[0].indices)
    for (n1 in WV[1].indices)
    for (n2 in WV[2].indices)
    for (n3 in WV[3].indices) {
        val w0 = (baseW + 0L) * n0
        val w1 = (baseW + 1L) * n1
        val w2 = (baseW + 2L) * n2
        val w3 = (baseW + 3L) * n3
        if (w0 + w1 + w2 + w3 > W) continue
        val v0 = WV[0].subList(0, n0 + 1).sum()
        val v1 = WV[1].subList(0, n1 + 1).sum()
        val v2 = WV[2].subList(0, n2 + 1).sum()
        val v3 = WV[3].subList(0, n3 + 1).sum()
        ans = Math.max(ans, v0 + v1 + v2 + v3)
    }
    println(ans)
}
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 48548
/*
A - AtCoder Beginner Contest 999
abc111
*/
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
#define MOD 1000000007LL
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n, x, sum, minl = INF;
    vector<int> m(10101);

    cin >> n >> x;
    REP(i, n) {
        cin >> m[i];
        sum += m[i];
        minl = min(m[i], minl);
    }
    cout << n + (x - sum) / minl << endl;

    return 0;
}

Measured memory_bytes: 3188
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S, T := nextLine(), nextLine()
	var ans int
	for i := 0; i < len(S); i++ {
		if S[i] != T[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

using namespace std;

const int N = 200000 + 7;
const int INF = 1000000000 + 7;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ll,ll> pll;

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

  ll a[N];
  ll sum = 0;
  ll odd = 0;
  for(int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    sum += a[i];
    if(i % 2 == 1) odd += a[i];
  }

  sum /= 2;
  ll cur = sum - odd;

  for(int i = 0; i < n; ++i) {
    ll temp = a[i] - cur;
    a[i] = 2 * cur;
    cur = temp;
  }

  for(int i = 0; i < n; ++i) {
    if(i > 0) printf(" ");
    printf("%lld", a[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s; cin >> s;
  rep(i,3) cout << s[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import heapq as hp

# import heapq
# import sys
#
# h = []
#
# for com in sys.stdin.readlines():
#     if com[0] == "i":
#         heapq.heappush(h, -int(com[7:]))
#     elif com[1] == "x":
#         print(-heapq.heappop(h))

if __name__ == '__main__':
    _input = sys.stdin.readlines()
    # command_list = list(map(lambda x: x.split(), _input))

    allowed_commands = ('insert', 'extract', 'end')
    heap_array = []
    for each in _input:
        # command, content = each[0], each[-1]
        # if command not in allowed_commands:
        #     raise SystemExit('Illegal command!')
        if each.startswith('in'):
            hp.heappush(heap_array, -1 * int(each[7:]))
        elif each.startswith('ex'):
            print(-1 * hp.heappop(heap_array))

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

const ll INF = 1e18;

int main(int argc, char const *argv[])
{
	// rep(i, n) rep(j, h) rep(k, ...)

	int h, n; cin >> h >> n;
	vector<int> a(n), b(n); rep(i, n) cin >> a[i] >> b[i];

	// dp[i][j] := i番目までの魔法を使って、
	// モンスターの大量をj減らすときに使う魔力の最小値
	vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, INF));

	dp[0][0] = 0;
	rep(i, n) rep(j, h + 1) {
		// unused
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		// used
		dp[i + 1][min(j + a[i], h)]
			= min(dp[i + 1][min(j + a[i], h)], dp[i + 1][j] + b[i]);
	}

	cout << dp[n][h] << endl;
	return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

struct Job {
  ll reward;
  ll day;
  bool used;
};

int main(int argc, char* argv[]) {
  ll n, m;
  cin >> n >> m;
  map<ll, vector<ll>> jobs;
  rep(i, 0, n) {
    ll d, c;
    cin >> d >> c;
    jobs[d].push_back(c);
  }

  priority_queue<ll> q;
  ll ans = 0;

  auto first = begin(jobs);
  auto last = end(jobs);
  rep(i, 1, m + 1) {
    if ((*first).first <= i && first != last) {
      for (ll val : (*first).second) q.push(val);
      first++;
    }

    if (q.empty()) continue;
    ans += q.top();
    q.pop();
  }

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

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 10880
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
 
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi w=in;
	sort(all(w));
	rep(i,n){
		if(in[i]==w[n-1])cout<<w[n-2]<<endl;
		else cout<<w[n-1]<<endl;
	}
}












Measured memory_bytes: 4736
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem065b(n, a))
}

fun problem065b(n: Int, a: List<Int>): Int {
    var current = 1
    var count = 0
    val set = hashSetOf<Int>()
    while (current != 2) {
        current = a[current - 1]
        if (set.contains(current)) return -1
        set.add(current)
        count++
    }
    return count
}

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


struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main(){

int N,M;
cin>>N>>M;

ll x[N];
ll y[N];
ll z[N];


rep(i,N){
    cin>>x[i]>>y[i]>>z[i];

}
ll max = 0;
rep(j,8){
    ll sorezore[N]={};
    rep(i,N){
        if(j%2==0){
            sorezore[i]-=z[i];
        }
        else{
            sorezore[i]+=z[i];
        }
        int jj=j/2;

        if(jj%2==0){
            sorezore[i]-=y[i];

        }
        else{
            sorezore[i]+=y[i];
        }
        int jjj=jj/2;
        if(jjj%2==0){
            sorezore[i]-=x[i];
        }
        else{
            sorezore[i]+=x[i];
        }
    
    }
        sort(sorezore,sorezore+N);
        long long int ans=0;
        for(int i=0;i<M;i++){
            ans+=sorezore[N-1-i];
        }
        if(ans>max){
            max = ans;
        }

}

cout<<max<<"\n";


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define H 250

int parent(int);
int left(int);
int right(int);

int main(){
  int i, k, A[H];

  scanf("%d",&k);
  for(i = 1; i <= k; i++)
    scanf("%d",&A[i]);
  for(i = 1; i <= k; i++){
    printf("node %d: key = %d, ",i, A[i]);
    if(parent(i) > 0) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= k) printf("left key = %d, ",A[left(i)]);
    if(right(i) <= k) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

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

class Program
{
    void Calc()
    {
        var sc = new Scanner();
        string b = sc.Next();
        char[] a = b.ToCharArray();
        string c = sc.Next();
        char[] d = c.ToCharArray();
        string e = sc.Next();
        char[] f = e.ToCharArray();
        if (a[a.Length-1] == d[0] &&d[d.Length-1]==f[0])
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }

    static void Main()
    {
        new Program().Calc();
    }

    class Scanner
    {
        string[] s = new string[0];
        int i = 0;
        char[] cs = new char[] { ' ' };

        public string Next()
        {
            if (i < s.Length) return s[i++];
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }
        public int NextInt() { return int.Parse(Next()); }
        public long NextLong() { return long.Parse(Next()); }
        public double NextDouble() { return double.Parse(Next()); }
    }
}

Measured memory_bytes: 13140
# coding: utf-8

n, m = list(map(int, input().split()))
hs = list(map(int, input().split()))
hs = [-1] + hs
es = [list(map(int, input().split())) for _ in range(m)]

# "同じ展望台の組を結ぶ道が複数あることもある。"
ed = {}
for a, b in es:
    if a not in ed:
        ed[a] = set([b])
    else:
        ed[a].add(b)
    if b not in ed:
        ed[b] = set([a])
    else:
        ed[b].add(a)

#print(ed)
cnt = 0
for s in range(1, n+1):
    #print ('start point %s:' % s)
    if s not in ed:
        #print('=> isolate')
        cnt += 1
    else:
        mx = max(hs[e] for e in ed[s])
        pred = hs[s] > mx
        #print ('h = %s, mx = %s' % (hs[s], mx))
        if pred:
            #print('xx')
            cnt += 1

print(cnt)


Measured memory_bytes: 57096
n = int(input())
h = list(reversed(list(map(int,input().split()))))
ans = "Yes"
for i in range(n-1):
    if h[i]+2 <= h[i+1]:
        ans = "No"
        break
    elif h[i]+1 == h[i+1]:
        h[i+1] -= 1
print(ans)

Measured memory_bytes: 15020
#include <stdio.h>
#define S_MAX 100<<20

char str[2][S_MAX];

int main(){
  int n,i;

  while(1){
    scanf("%d",&n);
    if(n==0) break;
    scanf("%s",str[0]);


    for(i=0; i<n; i++){
      int cnt=1,idx1=1,idx2=0;
      char ch = str[i&1][0];

      while(1){
	if(ch == str[i&1][idx1])
	  cnt++;
	else{
	  sprintf(&str[~i&1][idx2],"%d%c",cnt,ch);
	  
	  while(str[~i&1][++idx2])
	    ;

	  if(str[i&1][idx1] == '\0')
	    break;

	  ch = str[i&1][idx1];
	  cnt = 1;
	}
	idx1++;
      }
    }
    printf("%s\n",str[n&1]);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc127_a(vector<vector<string>> v) {

    int a = atoi(v[0][0].c_str());
    int b = atoi(v[0][1].c_str());
    

    if(a>=13){
        
        cout << b<<endl;
    }else if(a>=6){
        
        cout << b/2<<endl;
    }else{
        cout <<0 <<endl;
    }
    


}

int main() {

    vector<vector < string>> vec_arr_result;
    //    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata();

    abc127_a(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  rep(i,N) cin >> red[i].first >> red[i].second;
  rep(i,N) cin >> blue[i].first >> blue[i].second;
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());
  int ans = 0;

  rep(i, blue.size()) {
    int pair_index = -1; int max_value = -1;
    rep(j, red.size()) {
      if(red[j].first < blue[i].first && red[j].second < blue[i].second) {
        if(max_value < red[j].second) {
          max_value = red[j].second;
          pair_index = j;
        }
      }
    }
    if(pair_index != -1) {
      //printf("Pair: (%d, %d) (%d, %d)\n", red[pair_index].first, red[pair_index].second, blue[i].first, blue[i].second);
      red.erase(red.begin()+pair_index);
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long f[500005],g[500005]; 
int main()
{
	string s;
	cin>>s;
	long long l=s.size();
	long long sum=0;
	if(s[0]=='<')  f[0]=1;
	for(int i=1;i<l;++i)
	{
	   if(s[i]=='<'&&s[i-1]=='<') f[i]=f[i-1]+1;
	   else if(s[i]=='<') f[i]=1;
	   else f[i]=0;
    } 
    for(int i=l-1;i>=0;--i)
    {
    	if(s[i]=='>'&&s[i+1]=='>') g[i]=g[i+1]+1;
    	else if(s[i]=='>') g[i]=1;
    	else g[i]=0;
	}
	for(int i=0;i<=l;++i)
		sum+=max(f[i-1],g[i]);
	cout<<sum<<endl;
}

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

int main() {
    const long long mod = 1000000007;
    long long n; cin >> n;
    long long rtn = 1;
    for (int i = 1; i <= n; i++) {
       rtn *= i; rtn %= mod;
    }
    cout << rtn << endl;
}


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

int main(){
    int N,M;cin>>N>>M;
    vector<pair<int,int> > v(M);
    int res=0;
    bool ok=true;
    vector<int> b(N,-1);
    for(int i=0;i<M;i++){
        cin>>v[i].first>>v[i].second;v[i].first--;
        if(b[v[i].first]!=-1 && b[v[i].first]!=v[i].second ){
            ok=false;
        }
        if(v[i].first!=N-1 && v[i].second==0)ok=false;
        b[v[i].first]=v[i].second;
    }
    for (int i=0;i<N;i++){
        if(b[i]!=-1){
        res+=b[i]*pow(10,N-i-1);
        }
    }
    if(res<pow(10,N-1)){
        if(N!=1) res+=pow(10,N-1);
    }
    if(ok==true){
    cout<<res<<endl;
    }
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	static	double EPS=1e-5;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			Point p1=new Point(in.nextDouble(), in.nextDouble()); 
			Point p2=new Point(in.nextDouble(), in.nextDouble()); 
			if(p1.x==0&&p1.y==0&&p2.x==0&&p2.y==0)
				return;
			Point p3=new Point(in.nextDouble(), in.nextDouble()); 
			Point p4=new Point(in.nextDouble(), in.nextDouble()); 
			Point p5=new Point(in.nextDouble(), in.nextDouble()); 
			Point p6=new Point(in.nextDouble(), in.nextDouble());
			boolean judge=true;
			if(!lineCross(p1, p2, p3, p4))
				judge=false;
			if(!lineCross(p3, p4, p5, p6))
				judge=false;
			if(!lineCross(p5, p6, p1, p2))
				judge=false;

			if(judge)
			{
				double a1=slanting(p1, p2);
				double a2=slanting(p3, p4);
				double x1=(a1*p1.x-p1.y-a2*p3.x+p3.y)/(a1-a2);
				if(a1==-1.123)
					x1=p1.x;
				else if(a2==-1.123)
					x1=p3.x;
				double y1=(p2.y-p1.y)/(p2.x-p1.x)*(x1-p1.x)+p1.y;
				if(a1==-1.123)
					y1=(p4.y-p3.y)/(p4.x-p3.x)*(x1-p3.x)+p3.y;

				a1=slanting(p3, p4);
				a2=slanting(p5, p6);
				double x2=(a1*p3.x-p3.y-a2*p5.x+p5.y)/(a1-a2);
				if(a1==-1.123)
					x2=p3.x;
				else if(a2==-1.123)
					x2=p5.x;
				double y2=(p4.y-p3.y)/(p4.x-p3.x)*(x2-p3.x)+p3.y;
				if(a1==-1.123)
					y2=(p5.y-p6.y)/(p5.x-p6.x)*(x2-p5.x)+p5.y;

				a1=slanting(p5, p6);
				a2=slanting(p1, p2);
				double x3=(a1*p5.x-p5.y-a2*p1.x+p1.y)/(a1-a2);
				if(a1==-1.123)
					x3=p5.x;
				else if(a2==-1.123)
					x3=p1.x;
				double y3=(p6.y-p5.y)/(p6.x-p5.x)*(x3-p5.x)+p5.y;
				if(a1==-1.123)
					y3=(p2.y-p1.y)/(p2.x-p1.x)*(x3-p1.x)+p1.y;

				double a=x2-x1;
				double b=y2-y1;
				double c=x3-x1;
				double d=y3-y1;
				double S=Math.abs(a*d-b*c)/2;
				if(S<EPS)
					System.out.println("kyo");
				else if(S<100000)
					System.out.println("syo-kichi");
				else if(S<1000000)
					System.out.println("kichi");
				else if(S<1900000)
					System.out.println("chu-kichi");
				else 
					System.out.println("dai-kichi");			
			}
			else
				System.out.println("kyo");
		}
	}

	static boolean lineCross(Point p1,Point p2,Point p3,Point p4)
	{
		double jc1=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x);
		double jd1=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x);
		double jc2=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x);
		double jd2=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x);
		return jc1*jd1<=0 && jc2*jd2<=0;
	}

	static double slanting(Point p1,Point p2)
	{
		if(Math.abs(p1.x-p2.x)<EPS)
			return -1.123;
		else
			return (p1.y-p2.y)/(p1.x-p2.x);
	}
}
class Point
{
	double x;
	double y;
	Point(double x,double y)
	{
		this.x=x;
		this.y=y;
	}
}

Measured memory_bytes: 23188
import java.util.Scanner;

public class Main {

    static int k;
    static int[] T = new int[100000];
    static int n;

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        for(int i = 0; i < n; i++){
            T[i] = sc.nextInt();
        }
        long ans = solve();
        System.out.println(ans);
    }

    public static long solve(){
        long left = 0;
        long right = 100000 * 10000;
        long mid;
        while(right - left > 1){
            mid = (right + left) / 2;
            int v = check(mid);
            if(v >= n){
                right = mid;
            }else{
                left = mid;
            }
        }
        return right;
    }
    public static int check(long P){
        int i = 0;
        for(int j = 0; j < k; j++){
            long s = 0;
            while(s + T[i] <= P){
                s += T[i];
                i++;
                if(i == n){
                    return n;
                }
            }
        }
        return i;
    }
}



Measured memory_bytes: 71360
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct Timer{
    chrono::high_resolution_clock::time_point st;

    Timer() { reset(); }

    void reset(){
        st = chrono::high_resolution_clock::now();
    }

    chrono::milliseconds::rep elapsed(){
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    }
};

struct RNG{
    mt19937 mt;

    RNG() : mt(chrono::steady_clock::now().time_since_epoch().count()){}

    int operator()(int a, int b){
        uniform_int_distribution<int> dist(a, b - 1);
        return dist(mt);
    }

    int operator()(int b){
        return (*this)(0, b);
    }
};

constexpr int D = 365;
vector<int> c(26);
vector<vector<int>> s(D, vector<int>(26));
Timer TimeKeeper;
RNG rng;
constexpr ll inf = 1e+15;

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

    int kyomu;
    cin >> kyomu;
    for(int i = 0; i < 26; ++i) cin >> c[i];
    vector<int> maxe(D, -1);
    vector<int> cur(D, 0);
    for(int i = 0; i < D; ++i){
        for(int j = 0; j < 26; ++j){
            cin >> s[i][j];
            if(chmax(maxe[i], s[i][j])) cur[i] = j;
        }
    }

    ll BestScore = 0;
    auto calc_score = [&](vector<int>& v) -> ll {
        ll res = 0;
        vector<int> pre(26, -1);
        for(int i = 0; i < D; ++i){
            res += s[i][v[i]];
            pre[v[i]] = i;
            for(int j = 0; j < 26; ++j){
                res -= c[j] * (i - pre[j]);
            }
        }
        return res;
    };
    BestScore = calc_score(cur);

    int Day = 0;
    while(TimeKeeper.elapsed() < 1970){
        ll NxtScore = -inf;
        int ProblemType = -1;
        vector<int> nxt = cur;
        for(int i = 0; i < 26; ++i){
            if(i == cur[Day])   continue;
            nxt[Day] = i;
            if(chmax(NxtScore, calc_score(nxt)))    ProblemType = i;
        }
        if(chmax(BestScore, NxtScore)){
            cur[Day] = ProblemType;
        }
        if(++Day == D)  Day = 0;
    }

    for(int i = 0; i < D; ++i)  cout << cur[i] + 1 << '\n';
}

Measured memory_bytes: 3724
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int count=0;
  x=x/50;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(10*i+2*j+k==x) count++;
      }
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n, y;
  cin >> n >> y;
  y/=1000;
  bool ans=false;
  for(int i=0;y-n-4*i>=0;i++){
    if((y-n-4*i)%9==0){
      int x = (y-n-4*i)/9;
      if(x>=0 && i>=0 && n-x-i >=0){
        ans = true;
        cout << x << ' ' << i << ' ' << n-x-i << endl;
        break;
      }
    }
  }
  if(!ans)cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
n = input()
num = [int(i) for i in input().split()]
count = 0
end=False
while(True):
	div = []
	for i in num:
		if(i % 2 == 0):
			div.append(i/2)
		else:
			print(count)
			end = True
			break
	if(end == True):
		break
	num = div
	count = count + 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
string s;
bool contains(char ch){
	for (int i = 0; i < s.size(); ++i)
		if(s[i] == ch)
			return true;
	return false;
}
bool allCh(string s, char ch){
	for (int i = 0; i < s.size(); ++i)
		if(s[i] != ch)
			return false;
	return true;
}
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin>>s;
	int min_moves = INT_MAX;
	for (char ch = 'a'; ch <= 'z' ; ++ch)
	{
		if(contains(ch)){
			int moves = 0;
			string s_temp = s;
			while(allCh(s_temp, ch) == false){
				moves++;
				string t;
				for(int j = 0; j <= s_temp.size() - 2; j++){
					if(s_temp[j+1] == ch)
						t.push_back(ch);
					else if(s_temp[j] == ch)
						t.push_back(ch);
					else
						t.push_back(s_temp[j]);
				}
				// cout<<s_temp<<endl;
				s_temp = t;
			}
			min_moves = min(min_moves, moves);
		}
	}
	cout<<min_moves<<endl;
	return 0;
}

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

int main()
{
    int x,y;
    while(cin>>x>>y)
    {
        if(x==0 && y==0) break;

        if(x>y)
            swap(x,y);
        cout<<x<<" "<<y<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3080
using System;

class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] mHeights = new int[n];
            for (int i = 0; i < n; i++)
            {
                mHeights[i] = int.Parse(input[i]);
            }
           
            int count = 1;
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if (mHeights[j] > mHeights[i])
                    {
                        break;
                    }

                    if (j == i - 1) count++;
                }
            }
            Console.WriteLine(count);
        }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n,m,k; cin >> n >> m >> k;
  vector<int> a(n),b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  vector<ll> c(m+1);
  rep(i,m) c[i+1] = c[i]+b[i];
  int ans = 0;
  int sum = 0;
  rep(i,n){
    if(sum > k) break;
    int s = k-sum;
    int d = upper_bound(c.begin(),c.end(),s)-c.begin();
    d--;
    ans = max(ans,i+d);
    sum += a[i];
  }
  if(sum <= k){
    int s = k-sum;
    int d = upper_bound(c.begin(),c.end(),s)-c.begin();
    d--;
    ans = max(ans,n+d);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    int a[n+1];
    set<int>s;
    map<int,int>m;

    for(int i=0;i<n;i++){
        cin>>a[i+1];
        s.insert(a[i+1]);
        m[a[i+1]]=i+1;
    }
    int ans[n*n+1];
    for(int i=1;i<=n*n;i++)
        ans[i]=-1;
    bool flag=true;
    for(auto c:m)
    {
        int i=c.second;
        ans[a[i]]=i;
        int have_to=i-1;
        for(int j=1;j<=a[i]-1 && have_to>=1;j++)
        {
            if(ans[j]==-1 && !s.count(j))
            {
                ans[j]=i;
                have_to--;
            }
        }
        if(have_to!=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(auto c:m)
    {
        int i=c.second;
        int have_to=n-i;
        for(int j=a[i]+1;j<=n*n && have_to>=1;j++)
        {
            if(ans[j]==-1)
            {
                ans[j]=i;
                have_to--;
            }
        }
        if(have_to!=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<=n*n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 5612
def sumitrust2019_d():
    n = int(input())
    s = input()

    ans = 0

    for i in range(1000):
        # 確認するpinの数字の組み合わせと桁の初期化
        # pin = list(str(i).zfill(3))
        current_digit = 0
        pin = f'{i:0>3}'
        search_num = pin[current_digit]

        for num in s:
            # 見つけると桁を右に一つずらす
            # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。
            # if num == pin[current_digit]:
            if num == pin[current_digit]:
                current_digit += 1

                # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
                if current_digit == 3:
                    ans += 1
                    break
                # 見つけ終わるまではチェックする数字を置き換え。
                elif current_digit < 3:
                    search_num = pin[current_digit]

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d()

Measured memory_bytes: 9212
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}

void add_mod(ll& a, ll b){
    a += b;
    a %= MOD;
}

int main(void){
	ll a,b,c,ans,m;
	int k;
	cin >> a >> b >> c;
	m = max(a,max(b,c));
	cin >> k;
	cout << (a + b + c - m + (m<<k)) << endl;
	return 0;
}


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

int main()
{
	int A, B;

	cin >> A >> B;

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  string s, t;
  cin >> s >> t;
  set<char> se;
  map<char, vector<int>> mp;
  rep(i, s.size()){
    se.insert(s.at(i));
    mp[s.at(i)].push_back(i);
  }
  int S = se.size();
  rep(i, t.size()){
    se.insert(t.at(i));
    int k = se.size();
    if(k > S){
      cout << -1 <<endl;
      return 0;
    }
  }
  ll k = s.size();
  ll cnt = 0, pos = -1;
  for(int i = 0; i < t.size(); i++){
    auto itr = upper_bound(all(mp[t.at(i)]), pos);
    if(itr - mp[t.at(i)].begin() >= mp[t.at(i)].size()){
      cnt++;
      pos = mp[t.at(i)][0];
    }else{
      pos = *itr;
    }
  }
  cout << cnt * k + pos + 1 <<endl;
}

Measured memory_bytes: 4260
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const int INF = 1001001001;

int main() {
    while(true) {
        int n,m;
        cin >> n >> m;
        if(n==0 && m == 0) break;
        vector<int>c(m),x(n);
        rep(i,m) cin >> c[i];
        rep(i,n) cin >> x[i];
        vector<vector<int>>dp(n+1,vector<int>(256,INF));
        dp[0][128] = 0;
        for(int i = 0;i<n;i++) {
            for(int j = 0;j<=255;j++) {
                for(int k = 0;k<m;k++) {
                    int d = c[k] + j;
                    if(d<0) d = 0;
                    if(d > 255) d=255;
                    chmin(dp[i+1][d], dp[i][j]+(d-x[i])*(d-x[i]));
                }
            }
        }
        int ans = INF;
        for(int i = 0;i<=255;i++) {
            chmin(ans,dp[n][i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	if(k>n*(n-1)/2-(n-1))
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<n*(n-1)/2-k<<endl;
		for(int i=2;i<=n;i++)
		{
			cout<<1<<" "<<i<<endl;
		}
		int res=n-1;
		for(int i=2;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				if(res==n*(n-1)/2-k)
				  return 0;
				else
				{
					cout<<i<<" "<<j<<endl;
					res++;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std ; 
const int N = 3e7 + 1e5 ; 
long long pt[N] , dd[N] , mark[N] , x , y , a , b , c , st1 , st2 , st3 , ans = 0 ;
bool cmp(int i , int j){
	return pt[i] > pt[j] ||pt[i]==pt[j]&&i<j;
}
int main(){
	cin>>x>>y>>a>>b>>c;
	for(int i = 1 ; i <= a + b + c ; i ++){
		cin>>pt[i] ;
		dd[i] = i ;
		if(i <= a) {
			mark[i] = 1 ;
		}else if(i <= a + b ){
			mark[i] = 2 ;
		}else{
			mark[i] = 3 ;
		}
	}
	sort(dd + 1 , dd + a + b + c + 1 , cmp) ;
	long long n = a + b + c ;
	for(int i = 1 ; i <= n ; i ++){
		if(mark[dd[i]] == 1 && st1 < x){
			st1 ++ ;
			ans += pt[dd[i]] ;
		}else if(mark[dd[i]] == 2 && st2 < y){
			st2 ++ ;
			ans += pt[dd[i]] ;
		}else if(mark[dd[i]] == 3){
			st3 ++ ;
			ans += pt[dd[i]] ;
		}
		if(st1 + st2 + st3 == x + y) break ;
	}
	cout<<ans<<endl ;
	return 0 ;
} 

Measured memory_bytes: 10684
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Solve
{
  List<int>[] G;
  int[] color;
  int[] us;//拡大可能距離
  StringBuilder sb;//解答
  
  public static void Main()
  {
    new Solve().Run();
  }
  
  void Run()
  {
    sb = new StringBuilder();
    Calc();
    Console.Write(sb.ToString());
  }
  
  void Calc()
  {
    string[] str = Console.ReadLine().Split(' ');
    int N = int.Parse(str[0]);
    int M = int.Parse(str[1]);
    G = new List<int>[N];//隣接リスト
    for(int i = 0; i < N; i++) G[i] = new List<int>();
    for(int i = 0; i < M; i++)//隣接リストの作成
    {
      str = Console.ReadLine().Split(' ');
      int a = int.Parse(str[0]) - 1;//頂点番号は1減らして受け取る
      int b = int.Parse(str[1]) - 1;
      G[a].Add(b);
      G[b].Add(a);
    }
      
    int Q = int.Parse(Console.ReadLine());
    int[] V = new int[Q];//各クエリを受け取る
    int[] D = new int[Q];
    int[] C = new int[Q];
    for(int i = 0; i < Q; i++)
    {
      str = Console.ReadLine().Split(' ');
      V[i] = int.Parse(str[0])-1;
      D[i] = int.Parse(str[1]);
      C[i] = int.Parse(str[2]);
    }
      
    color = new int[N];
    us = new int[N];
    for(int i = 0; i < N; i++) us[i] = -1;//初期化
    
    for(int i = Q-1; i >= 0; i--)//クエリを逆順に処理
    {
      if(us[V[i]] < D[i])//拡大可能距離を増やせるならば
      {
        dfs(V[i],D[i],C[i]);//深さ優先探索を繰り返す
      }
    }
    
    for(int i = 0; i < N; i++) sb.Append(color[i]+"\n");//出力メモ
  }
    
  void dfs(int v,int d,int c)//深さ優先探索
  {
    us[v] = d;//拡大可能距離
    if(color[v] == 0) color[v] = c;//塗っていない時だけ上書き
    if(d != 0)//周りも塗れる可能性がある時
    {
      for(int i = 0; i < G[v].Count; i++)//隣接頂点の確認
      {
        int t = G[v][i];
        if(us[t] < d-1) dfs(t,d-1,c);
      }
    }
  }
}


Measured memory_bytes: 30360
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,list(_in[0])))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    arr = [B,C,D]
    N = len(arr)
    for bit in range(1<<N):
        # bit = 0: '-', 1: '+'
        sum_ = A
        for i,x in enumerate(arr):
            if bit&(1<<i):
                sum_ += x
            else:
                sum_ -= x
        if sum_ == 7:
            str_ = str(A)
            for i,x in enumerate(arr):
                if bit&(1<<i):
                    str_ += '+'+str(x)
                else:
                    str_ += '-'+str(x)
            str_ += '=7'
            break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(str_)


Measured memory_bytes: 38384