akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
const int dx[] = { -1,0,1,0 };
const int dy[] = { 0,-1,0,1 };
const int ddx[] = { 0,1,1,  0,2, 1,-1,-2, 2, 2, -2,-2,1,-1,1,-1,2,2,-2,-2 };
const int ddy[] = { 2,1,-1,-2,0, 1, 1, 0,2, -2,  2,-2,2,2, -2,-2, 1,-1,1,-1 };


int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}

	vector<vector<int>> D(H, vector<int>(W, 1e9));//回数
	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > q;
	q.push(make_pair(0, make_pair(ch, cw)));
	D[ch][cw] = 0;

	while (!q.empty()) {
		int x = q.top().second.first;
		int y = q.top().second.second;
		int z = q.top().first;
		q.pop();
		if (D[x][y] < z) continue;
		if (x == dh && y == dw) continue;
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y];
					pair<int, pair<int, int>> p = make_pair(D[x1][y1], make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
		//範囲内かつ0を24セット
		for (int l = 0; l < 20; ++l) {
			int x1 = x + ddx[l];
			int y1 = y + ddy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y] + 1;
					pair<int, pair<int, int>> p = make_pair(D[x1][y1], make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
	}
	if (1e9 == D[dh][dw]) {
		cout << -1 << endl;
	}
	else {
		cout << D[dh][dw] << endl;
	}
	return 0;
}


Measured memory_bytes: 16180
/**
 *    author:   K.R.Surrya  
 *    created:  10/05/2020 17:36:28
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}

void solve() { 
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    long long ret=0;
   if(k<a) {
      ret+=k;
      k=0;
   } else if(k>=a && k<b) {
       ret+=a;
       k-=a;
       k-=min(k,b);
   } else if(k>=b) {
      ret+=a;
      k-=(a+b);
      ret-=min(c,k);
   }
   cout << ret << '\n';
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


Measured memory_bytes: 3640
s1 = []   #/????????????????????§??????????????????
s2 = []   #??????????°´??????????????¢??????[????????????\???????????????????°´??????????????¢???]?????¢??§????????§??????????????????
su = 0   #?????¢???

st = list(input())   #??\?????????????????????????´????????????????

for i in range(len(st)):   #???????????????????????????????????£????????¢????¨????
    if st[i] == '\\':
        s1.append(i)
    elif st[i] == '/' and len(s1) != 0:
        left = s1.pop()
        su += i - left
        area = 0
        while len(s2) != 0 and left < s2[-1][0]:
            area += s2.pop()[1]
        s2.append([left,area + i -left])

print(su)
print(' '.join([str(len(s2))] + [str(i[1]) for i in s2]))

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

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

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1e9 + 7;
using m64 = modint<MOD>;

m64 modpow(m64 x, i64 n) {
    m64 res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1; 
    }
    return res;
}

int main() {
    i32 n, k;
    cin >> n >> k;
    vector<i32> mul(k+1);
    for (i32 i = 1; i <= k; i++) {
        for (i32 x = 1; x <= (i32) sqrt(i); x++) {
            if (i % x != 0) continue;
            mul[x]++;
            if (i / x != x) mul[i / x]++;
        }
    }

    vector<m64> cnt(k+1);
    m64 ans = 0;
    for (i32 i = k; i > 0; i--) {
        cnt[i] = modpow(mul[i], n);
        for (i32 x = i + i; x <= k; x += i) cnt[i] -= cnt[x];
        ans += cnt[i] * i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 4844
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
s = ns()

ans = 0

for a in range(10):
    for b in range(10):
        now = 1
        ss = set()
        for i in range(n):
            if now == 1 and s[i] == str(a):
                now = 2
            elif now == 2 and s[i] == str(b):
                now = 3
            elif now == 3:
                ss.add(s[i])
        ans += len(ss)

print(ans)

Measured memory_bytes: 9252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int count = 1;
        while (num != 0) {
            System.out.println("Case " + count + ": " + num);
            num = sc.nextInt();
            count++;
        }

    }

}


Measured memory_bytes: 41216
#include <iostream>

using namespace std;

int sum_dig(int a){
	int s = 0;
	for(int i = a; i > 0; i /= 10){
		s += i%10;
	}
	return s;
}

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

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

    for(int a = n-2, b = 2; b <= n/2; a--, b++){
    	if(b == 2){
    		m = sum_dig(a)+sum_dig(b);
    		continue;
    	}
    	int t = sum_dig(a)+sum_dig(b);
    	if(t < m)
    		m = t;
    }

    cout<<m<<endl;

    return 0;
}

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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            if (ab.Any(n => n > 9)) { Console.WriteLine(-1); return; }
            Console.WriteLine(ab[0] * ab[1]);
        }
    }
}

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

ll dp[100001][13];
const int MOD = 1e9+7;
int main()
{
	string s;
	cin >> s;
	dp[0][0] = 1;

	int n = s.size();

	for(int i = 0;i<n;i++)
	{
		if(s[i]=='?')
		{
			for(int j = 0;j<10;j++)
			{
				for(int k = 0;k<13;k++)
				{
					int x = (k*10+j)%13;
					(dp[i+1][x] += dp[i][k])%=MOD;
				}
			}
		}
		else
		{
			int k = s[i] - '0';
			for(int j = 0;j<13;j++)
			{
				int x  = (j*10 + k)%13;
				(dp[i+1][x] += dp[i][j])%=MOD;
			}
		}
	}
	cout<<dp[n][5]<<endl;

}

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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int m=0,k=0,u=0;

     for(int i=0;i<n;i++)
    {
        if(arr[i]>m)
        {
            m=arr[i];
            k=i;
        }
    }
         for(int i=0;i<n;i++)
    {
        if(arr[i]>u&&i!=k)
        {
            u=arr[i];
        }
    }

for(int i=0;i<n;i++)
    {
        if(i!=k)
        {
          cout<<m<<endl;
        }
        else
        {
            cout<<u<<endl;
        }
    }

}


Measured memory_bytes: 2432
class Dice():
    def __init__(self, dice_labels):
        self.top = dice_labels[0]
        self.south = dice_labels[1]
        self.east = dice_labels[2]
        self.west = dice_labels[3]
        self.north = dice_labels[4]
        self.bottom = dice_labels[5]

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.top, self.east, self.west, self.bottom = (self.west, self.top, self.bottom, self.east)

    def __roll_to_west(self):
        self.top, self.east, self.west, self.bottom = (self.east, self.bottom, self.top, self.west)

    def __roll_to_south(self):
        self.top, self.south, self.north, self.bottom = (self.north, self.top, self.bottom, self.south)

    def __roll_to_north(self):
        self.top, self.south, self.north, self.bottom = (self.south, self.bottom, self.top, self.north)

    def __turn_right(self):
        self.south, self.east, self.west, self.north = (self.east, self.north, self.south, self.west)

    def __turn_left(self):
        self.south, self.east, self.west, self.north = (self.west, self.south, self.north, self.east)

dice_labels = input().split(' ')
num_question = int(input())
dice = Dice(dice_labels)

for i in range(0, num_question):
    target_top_label, target_for_label = tuple(input().split(' '))
    for j in range(0, 2):
        for k in range(0, 4):
            if dice.top != target_top_label:
                dice.roll('N')
        dice.turn('R')

    for j in range(0, 4):
        if dice.south != target_for_label:
            dice.turn('R')

    print(dice.east)


Measured memory_bytes: 5604
#include<stdio.h>
int main(){
	int a,b,d,r;
	double f;

	scanf("%d %d",&a,&b);
	
	d=a/b; 
	r=a%b;
		printf("%d %d\n",d,r);
	f=(double)a/b;
	printf("%f\n",f);
		
return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <stdlib.h>

int main(void){
    long long int n, x, i, j, temp, ans=0;
    scanf("%lld %lld", &n, &x);
    long long int a[n];
    for(int i=0; i<n; i++) {
         scanf("%lld", &a[i]);
    }
    for(i=0; i<n; i++){
        for(j=n-1; j>i; j--){
            if(a[j] < a[j-1]){
                temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
        }
    }
    for(i=0; i<n; i++){
        if(x-a[i]>=0){
            x -= a[i];
            ans++;
        }else break;
        if(i==n-1 && x>0) ans--;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

using tup = tuple<int,int,int>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int L;
  cin >> L;
  int N = 20;
  vector<tup> edge;
  for(int i=1; i<20; i++){
    edge.emplace_back(i,i+1,0);
  }
  int sum = 1;
  int cnt = 0;
  while(sum < L){
    if(sum+(1LL<<cnt) <= L){
      sum += (1LL<<cnt);
      edge.emplace_back(20-(cnt+1),20-cnt,(1LL<<cnt));
    }else{
      int now = L-sum;
      int now2 = sum;
      for(int bit=20; bit>=0; bit--){
        if(now & (1LL<<bit)){
          edge.emplace_back(1,20-bit,now2);
          now2 += (1LL<<bit);
        }
      }
      break;
    }
    cnt++;
  }
  cout << N << " " << edge.size() << "\n";
  for(int i=0; i<edge.size(); i++){
    int a,b,c;
    tie(a,b,c) = edge[i];
    cout << a << " " << b << " " << c << "\n";
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
    int N;
    int input;
    
    vector<int> A;
    double ans = 0;

    cin >> N;

    for (int i = 0; i<N; i++){
        cin >> input;
        A.push_back(input);
    }

    for(auto& variable : A){
        ans  = ans + 1.0/variable;
    }
    cout << 1/ans << endl;

    return 0;
}

Measured memory_bytes: 256
X,N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []
  
int_list = [i for i in range(102)]
forbidden_list = sorted(list(set(int_list) - set(p)))
num_X = int_list.index(X)
c = 10000000
 
if X in forbidden_list:
  print(X)
else:
  for i in range(len(forbidden_list) - 1):
    a = abs(X - forbidden_list[i])
    b = abs(X - forbidden_list[i + 1])
    if a == b:
      print(forbidden_list[i])
      break
    elif c > a:
      c = a
    elif c <= a and b >= a:
      print(forbidden_list[i - 1])
      break
    elif b < a:
      print(forbidden_list[i])
      break
  else:
    if a < b:
      print(forbidden_list[i])
    else:
      print(forbidden_list[i + 1])

Measured memory_bytes: 9252
using System;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = decimal.Parse(input[0]);
            var b = decimal.Parse(input[1]);

            int d = (int)a / (int)b;
            int r = (int)a % (int)b;
            var f = a / b;

            Console.WriteLine($"{d} {r} {f}");
        }
    }
}



Measured memory_bytes: 18048
fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val hn = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    val graph = mutableMapOf<Int, MutableList<Int>>()
    repeat(m) {
        readLine()!!.split(" ").map(String::toInt).let {
            graph.getOrPut(it[0] - 1, { mutableListOf() }).add(it[1] - 1)
            graph.getOrPut(it[1] - 1, { mutableListOf() }).add(it[0] - 1)
        }
    }


    var count = 0
    for (i in 0 until n) {

        val list = graph[i]
        if (list.isNullOrEmpty()) {
            count++
            continue
        }

        if (hn[i] > list.map { hn[it] }.max()!!){
            count++
        }
    }

    println(count)

}





Measured memory_bytes: 77540
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[5005],dp[20][5005];
int ans;
void solve(int l,int r, int pos)
{
	if(l==r)
	{
		int tmp=0;
		for(int i=max(0,k-a[l]);i<k;i++)
		{
			tmp|=dp[pos][i];
		}
		ans+=1-tmp;
		return;
	}
	else
	{
		int mid=(l+r)/2;
		for(int i=0;i<k;i++)
		{
			dp[pos+1][i]=dp[pos][i];
		}
		for(int i=l;i<=mid;i++)
		{
			for(int j=k-1;j>=a[i];j--)
			{
				dp[pos+1][j]|=dp[pos+1][j-a[i]];
			}
		}
		solve(mid+1,r,pos+1);
		for(int i=0;i<k;i++)
		{
			dp[pos+1][i]=dp[pos][i];
		}
		for(int i=mid+1;i<=r;i++)
		{
			for(int j=k-1;j>=a[i];j--)
			{
				dp[pos+1][j]|=dp[pos+1][j-a[i]];
			}
		}
		solve(l,mid,pos+1);
	}
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	dp[1][0]=1;
	solve(1,n,1);
	cout<<ans;
	return 0;
}

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

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

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

  vector<int> L(N + 1), R(N + 1);
  for (int i = 0; i < N; i++) L[i + 1] = gcd(L[i], A[i]);
  for (int i = N - 1; i >= 0; i--) R[i] = gcd(R[i + 1], A[i]);

  int ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, gcd(L[i], R[i + 1]));

  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++)
    cin >> p.at(i);
  int count = 0;
  for(int i = 0; i < n; i++)
    if(p.at(i) != i+1)
      count++;
  if(count <= 2 )
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a, b, c, d, e, f, sum1, sum2, sum3, sum, p;
int main() {
	while (true) {
		sum = 0;
		cin >> a >> b >> c >> d >> e >> f;
		if (a + b + c + d + e + f == 0) { break; }
		sum1 = a + d;
		sum2 = b + e;
		sum3 = c + f;
		p = 0;
		p = min(sum1, sum2);
		p = min(p, sum3);
		for (int i = max(0, p - 10); i <= p; i++) {
			sum = max(sum, i + (sum1-i) / 3 + (sum2-i) / 3 + (sum3-i) / 3);
		}
		cout << sum << endl;
	}
}

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

int n;
long long city[110000];
long long hero[110000];
long long sum = 0;
long long tmp;

// Ci <= min(Ai + Ai+1, Bi)
int main() {
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        cin >> city[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> hero[i];
    }
    for (int i = 0; i <= n; ++i) {
        if (i == 0) {
            tmp = min(city[i], hero[i]);
            city[i] -= tmp;
            sum += tmp;
            hero[i] -= tmp;
        }
        if (i == n) {
            tmp = min(city[i], hero[i-1]);
            city[i] -= tmp;
            sum += tmp;
            break;
        }
        tmp = min(city[i], hero[i-1]);
        sum += tmp;
        city[i] -= tmp;
        tmp = min(city[i], hero[i]);
        sum += tmp;
        hero[i] -= tmp;
    }
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 5168
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long llINF = 1e18;
#pragma endregion


int main () {
    int n, m; cin >> n >> m;
    vint s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i];

    bool check = false;
    int checkM = 0;

    if (n == 1) {
        for (int i = 0; i < 10; i++) {
            string temp = to_string(i);
            checkM = 0;
            for (int j = 0; j < m; j++) {
                int keta = s[j] - 1;
                if (temp[keta] == (c[j] + '0')) checkM++;
            }
            if (checkM == m) {
                cout << i << endl;
                return 0;
            }
        }
    } else if (n == 2) {
        for (int i = 10; i < 100; i++) {
            string temp = to_string(i);
            checkM = 0;
            for (int j = 0; j < m; j++) {
                int keta = s[j] - 1;
                if (temp[keta] == (c[j] + '0')) checkM++;
            }
            if (checkM == m) {
                cout << i << endl;
                return 0;
            }
        }
    } else if (n == 3){
        for (int i = 100; i < 1000; i++) {
            string temp = to_string(i);
            checkM = 0;
            for (int j = 0; j < m; j++) {
                int keta = s[j] - 1;
                if (temp[keta] == (c[j] + '0')) checkM++;
            }
            if (checkM == m) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  string c = "CODEFESTIVAL2016";
  int cnt=0;
  REP(i,16){
    if(s[i]!=c[i])cnt++;
  }
  P(cnt);
  return 0;
}


Measured memory_bytes: 256
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1e6 + 5;
const int INF = 1e15;

int n;
vector<pair<int, int> > adj[N];
int dist[N];

void dijkartas(int s) { 
    for(int i = 0; i < N; i++)
        dist[i] = INF;
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; 
    
    pq.push({0, s}); 
    dist[s] = 0; 
    while(!pq.empty()) { 
        int v = pq.top().second; 
        pq.pop();
         
        for(auto p : adj[v]) { 
            int u = p.first; 
            int w = p.second; 
            if (dist[u] > dist[v] + w) { 
                dist[u] = dist[v] + w; 
                pq.push({dist[u], u}); 
            } 
        } 
    }  
} 
  
signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1; 
    // cin >> t; 
    while (t--) {
        cin >> n;
        for(int i = 1; i <= n; i++) {
            adj[(i % n)].push_back({(i + 1) % n, 1});
            adj[(i % n)].push_back({(10 * i) % n, 0});
        }
        
        dijkartas(1);
        cout << dist[0] + 1 << '\n';
    }
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 37500
#include <algorithm>
#include <cstdio>
#include <functional>
#include <fstream>
#include <iostream>
#include <set>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

typedef struct
{
  int f;
  int h;
  int v;
} T;

T S[2001][2001];

void debug(int w, int h)
{
  int x, y;
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      cout << S[y][x].f;
    }
    cout << endl;
  }
  cout << endl;
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      cout << S[y][x].h;
    }
    cout << endl;
  }
  cout << endl;
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      cout << S[y][x].v;
    }
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("file.1", "r", stdin);

  int w, h;
  cin >> h >> w;
  int x, y;
  for (y = 0; y < h; y++) {
    string s;
    cin >> s;
    for (x = 0; x < w; x++) {
      if (s[x] == '#')
        S[y][x].f = 1;
    }
  }
  for (y = 0; y < h; y++) {
    int cnt = 1;
    for (x = 0; x < w; x++) {
      if (S[y][x].f) {
        S[y][x].h = 0;
        cnt = 1;
      } else {
        S[y][x].h = cnt;
        cnt++;
      }
    }
    cnt = 0;
    for (x = w - 1; 0 <= x; x--) {
      if (S[y][x].f == 0) {
        if (cnt == 0)
          cnt = S[y][x].h;
        else
          S[y][x].h = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  for (x = 0; x < w; x++) {
    int cnt = 1;
    for (y = 0; y < h; y++) {
      if (S[y][x].f) {
        S[y][x].v = 0;
        cnt = 1;
      } else {
        S[y][x].v = cnt;
        cnt++;
      }
    }
    cnt = 0;
    for (y = h - 1; 0 <= y; y--) {
      if (S[y][x].f == 0) {
        if (cnt == 0)
          cnt = S[y][x].v;
        else
          S[y][x].v = cnt;
      } else {
        cnt = 0;
      }
    }
  }
  // debug(w, h);
  int ans = 0;
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      int num = 0;
      if (S[y][x].f == 0) {
        num = S[y][x].h + S[y][x].v - 1;
        ans = max(ans, num);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 47232
# coding: utf-8
# Your code here!

class dice(object):
    def __init__(self, arr):
        self.top = arr[0]
        self.side_s = arr[1]
        self.side_e = arr[2]
        self.side_w = arr[3]
        self.side_n = arr[4]
        self.bottom = arr[5]
    def roll(self, s):
        if s=='S':
            tmp = self.bottom
            self.bottom = self.side_s
            self.side_s = self.top
            self.top = self.side_n
            self.side_n = tmp
        elif s=='E':
            tmp = self.bottom
            self.bottom = self.side_e
            self.side_e = self.top
            self.top = self.side_w
            self.side_w = tmp
        elif s=='W':
            tmp = self.bottom
            self.bottom = self.side_w
            self.side_w = self.top
            self.top = self.side_e
            self.side_e = tmp
        elif s=='N':
            tmp = self.bottom
            self.bottom = self.side_n
            self.side_n = self.top
            self.top = self.side_s
            self.side_s = tmp
    

s = input().split()
# s = '1 2 4 8 16 32'.split()

dice = dice(s)
arr = input()
for a in arr:
    dice.roll(a)
# print(type(dice))
print(dice.top)



Measured memory_bytes: 5576
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(1) {
		c -= b;
		if(c <= 0) return cout << "Yes\n", 0;
		a -= d;
		if(a <= 0) return cout << "No\n", 0;
	}
	return 0;
}

Measured memory_bytes: 3636
from sys import stdin, stdout
input = stdin.readline
#print = stdout.write

N = int(input())
A = [[int(i) for i in input().split()] for _ in range(N)]
sumA = sum(sum(A, [])) // 2
correct = True

def isCorrect():
    for u in range(N):
        for v in range(u + 1, N):
            for k in range(N):
                if A[u][k] and A[v][k]:
                    #print(u,v,k,A[u][k],A[v][k],A[u][v])
                    if A[u][k] + A[k][v] < A[u][v]:
                        return False
    return True


if not isCorrect(): print(str(-1))
else:
    for u in range(N):
        for v in range(u + 1, N):
            for k in range(N):
                if A[u][k] and A[k][v]:
                    if A[u][k] + A[k][v] == A[u][v]:
                        sumA -= A[u][v]
                        break
    print(str(sumA))


Measured memory_bytes: 133896
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll n,m,x;
  cin>>n>>m>>x;
  vi c(n);
  vvi a(n,vi(m));
  rep(i,n){
    cin>>c[i];
    rep(j,m) cin>>a[i][j];
  }
  ll ans=inf;
  rep(tmp,1<<n){
    bitset<12> s=tmp;
    vi b(m,0);
    ll cost=0;
    rep(i,n){
      if(s.test(i)){
        cost+=c[i];
        rep(j,m) b[j]+=a[i][j];
      }
    }
    //out(cost);
    bool f=true;
    rep(j,m){
      if(b[j]<x) f=false;
    }
    if(f) chmin(ans,cost);
  }
  if(ans==inf){
    out(-1); return;
  }
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3672
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: u64 = itr.next().unwrap().parse().unwrap();
    let mut p: u64 = itr.next().unwrap().parse().unwrap();

    if n == 1 {
        println!("{}", p);
        return;
    }
    let mut ans: u64 = 1;
    let mut i: u64 = 2;
    while i * i <= p {
        let mut cnt: u64 = 0;
        while p % i == 0 {
            cnt += 1;
            p /= i;
        }
        ans *= i.pow((cnt / n) as u32);
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BinaryHeap;

fn main() {
    input!{
        n: usize,
        v: [i32; n],
    }

    let mut heap = BinaryHeap::new();
    for i in v.iter() {
        heap.push(i);
    }
    let mut prev = heap.pop().unwrap();
    while let Some(i) = heap.pop() {
        if i == prev {
            println!("NO");
            return;
        }
        prev = i;
    }
    println!("YES");
}


Measured memory_bytes: 10492
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a[5]={0,1,0,0,0},n,m,i,x,y,j,b[5]={0},f=0;
    cin>>n>>m;
    if(n==1&&m==0)
    {
        cout<<0<<endl;
    }
    else if(n>1&&m==0)
    {
        for(j=1;j<=n;j++)
        {
            cout<<a[j];
        }
        cout<<endl;
    }
    else
    {
        for(i=1;i<=m;i++)
        {
            cin>>x>>y;
            if(b[x]==0)
            {
                a[x]=y;
            }
            else
            {
                if(y!=a[x])
                {
                    f++;
                }
            }
            b[x]++;    
        }   
        if(f>0)
        {
            cout<<-1<<endl;
        }
        else if(a[1]==0&&n>1)
        {
            cout<<-1<<endl;
        }
        else
        {
            for(j=1;j<=n;j++)
            {
                cout<<a[j];
            }
            cout<<endl;
        }
    }   
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;
ll N, H, W, tmp;
string s, t;
int main(void)
{
    cin >> N >> H >> W;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        int A, B;
        cin >> A >> B;
        if (H <= A && W <= B)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    //137
    int A,B,C;
    cin >> A >> B >> C;
    if(A-B >=C){
        cout << "0" << endl;
    }
    else if(A-B <C){
        cout << C-(A-B) << endl;
    }
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3632
N = int(input())
As = list(map(bool, map(int, input().split())))
As.insert(0, False)
Ans = [False for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    p = i * 2
    s = False
    while p <= N:
        s ^= Ans[p]
        p += i
    Ans[i] = s ^ As[i]
M = sum(Ans)
print(M)
if M > 0:
    c = True
    for i in range(1, N + 1):
        if Ans[i]:
            if c:
                c = False
            else:
                print(" ", end="")
            print(i, end="")
    print("")

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    string s, t;
    cin >> s >> t;
    vector<ll> next[26];
    REP(i, s.size()){
    	next[s[i]-'a'].push_back(i);
    }

    ll now = -1;
    ll kai = 0;
    REP(i, t.size()){
    	auto start = next[t[i]-'a'].begin();
    	auto itr = lower_bound(next[t[i]-'a'].begin(), next[t[i]-'a'].end(), now+1);
    	if(itr == next[t[i]-'a'].end()){
    		kai++;
    		auto itr2 = lower_bound(next[t[i]-'a'].begin(), next[t[i]-'a'].end(), 0);
    		if(itr2 == next[t[i]-'a'].end()){
    			cout << -1 << endl;
    			return 0;
    		}
    		now = next[t[i]-'a'][itr2 - start];
    	}else{
    		now = next[t[i]-'a'][itr - start];
    	}
    }

    cout << kai * (ll)s.size() + now + 1 << endl;
    return 0;
}

Measured memory_bytes: 1736
def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    P = [0 for _ in range(M)]
    X = [0 for _ in range(M)]
    for i in range(M):
        P[i],X[i] = map(int, input().split())
    
    Tsum = sum(T)
    for i in range(M):
        print(Tsum - T[P[i]-1] + X[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
n = int(input())
ans = 0
for i in range(1,10):
  if i <= n:
    ans += 1
  else:
    break
if n > 99:
  for i in range(100,1000):
    if i <= n:
      ans += 1
    else:
      break
if n > 9999:
  for i in range(10000,100000):
    if i <= n:
      ans += 1
    else:
      break
print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;
typedef long long ll;
const ll MD = 1e9+7.1;

int n;
char s[2000030];

ll expr(char **begin);

ll numb(char **begin) {
    ll r = 0;
    while (isdigit(**begin)) {
        r *= 10;
        r += **begin - '0';
        *begin += 1;
    }
    return r;
}

ll term(char **begin) {
    if (**begin == 'S') {
        *begin += 2;
        ll r = expr(begin)%MD;
        *begin += 1;
        return (r*r)%MD;
    } else {
        return numb(begin);
    }
}

bool ist(char c) {
    return (isdigit(c) || c == 'S') ;
}
ll expr(char **begin) {
    ll r = term(begin);
    while (true) {
        if (**begin == '>' && *(*begin + 1) == '>' && ist(*(*begin + 2))) {
            *begin += 2;
            r >>= min(60LL, term(begin));
        } else {
            break;
        }
    }
    return r;
}

int main() {
    while (true) {
        string ss;
        getline(cin, ss);
        if (ss[0] == '#') break;
        n = 0;
        for (char c: ss) {
            if (c != ' ') {
                s[n] = c;
                n++;
            }
        }
        s[n] = '@';
        char *beg = s;
        ll ans = expr(&beg);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2972
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define REP(i,a,b) for(int i = (int)(a); (i) < (b); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int h,w;
	string s;
	vector<string> img;
	cin >> h >> w;
	string padding(w+2, '#');

	img.push_back(padding);
	rep(i,h){
		cin >> s;
		img.push_back("#" + s + "#");
	}
	img.push_back(padding);

	rep(j,img.size()) cout << img[j] << endl;
	return 0;
}


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (K <= A){
    cout << K << endl;
  }
  else if (K <= A+B){
    cout << A << endl;
  }
  else {
    cout << 2*A+B-K << endl;
  }
}


Measured memory_bytes: 3652
let bin_search x ary =
  let rec doit l r =
    if l >= r then false
    else begin
      let m = (l + r) / 2 in
      if x = ary.(m) then true
      else if x < ary.(m) then doit l m
      else doit (m + 1) r
    end
  in
  doit 0 (Array.length ary)

let () =
  let read_seq () = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
  let _ = read_int () in
  let s = Array.of_list (read_seq ()) in
  let _ = read_int () in
  let t = read_seq () in
  Printf.printf "%d\n" (List.fold_left (fun acc e -> acc + (if bin_search e s then 1 else 0)) 0 t)

Measured memory_bytes: 16240
import java.io.*;
import java.util.*;
 
public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;
 
  private static PrintWriter _err = new PrintWriter(System.err);
 
  private void solve(Scanner sc, PrintWriter out) {
    int a = sc.nextInt();
    String op = sc.next();
    int b = sc.nextInt();
    if (op.equals("+")) {
      out.println((a + b));
    } else {
      out.println((a - b));
    }
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();
 
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();
 
    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 21844
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var AL=Arr.shift();
var hash={};
for(var i=0;i<AL;i++){
   var arr=Arr[i].split(" ");
   var a=arr[0];
   if(!hash.hasOwnProperty(a))hash[a]=0;
   hash[a]+=arr[1]-0;
}
var X=[];
for(var i in hash)X.push(i);
X.sort();
var Max=0;
for(var i=0;i<X.length;i++)if(Max<=X[i].length)Max=X[i].length;
var Y=[];
for(var i=1;i<=Max;i++){
   var F=X.filter(function(v){return v.length==i;});
   Y=Y.concat(F);
}
for(var i=0;i<Y.length;i++)console.log(Y[i]+" "+hash[Y[i]]);

Measured memory_bytes: 10960
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll; const int INF=1e9;
typedef pair<int,int> P;

int main() {
  int n; cin>>n;
  int m=1<<n;
  int a[m], b[m], c[m], d[m];
  fill(b,b+m,0); for(int i=0;i<m;i++) c[i]=i; fill(d,d+m,-1);
  for(int i=0;i<m;i++) cin>>a[i];

  for(int i=0;i<m;i++) {
    for(int j=0;j<n;j++) {
      if (i & (1<<j)) continue;
      int id=i|(1<<j);
      P us[4]={{a[i],c[i]}, {b[i],d[i]}, {a[id],c[id]}, {b[id],d[id]}};
      sort(us,us+4);
      a[id]=us[3].first; c[id]=us[3].second;
      if (us[3].second != us[2].second) b[id]=us[2].first, d[id]=us[2].second;
      else b[id]=us[1].first, d[id]=us[1].second;
      //if (a[i] > a[id]) b[id]=a[id], a[id]=a[i];
      //else if (a[i] > b[id]) b[id]=a[i];
    }
  }
  //for(int i=0;i<m;i++) cout<<a[i]<<" "; cout<<endl;
  //for(int i=0;i<m;i++) cout<<b[i]<<" "; cout<<endl;

  ll an=0;
  for(int i=1;i<m;i++) {
    an=max(an, (ll)(a[i]+b[i]));
    cout<<an<<endl;
  }
}

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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> ii;
#define ll long long

#define sz(a) int((a).size())
#define len(a) int((a).length())
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define newl '\n'


int main(){
  int n,k; cin >> n >> k;

  vector<int> v(n);

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


  int dp[n]; 
  memset(dp,0x3f,sizeof(dp));

  dp[0]=0;
  for(int i=1;i<n;++i){
    for(int j=1;j<=k;++j){
      if(i-j<0) continue;
      dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
    }
  }
  cout << dp[n-1] << newl;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
list_N = [input() for _ in range(n)]
list_N = list(set(list_N))
cnt = [0 for _ in range(5)]

for i in range(len(list_N)):
    l = list(list_N[i])
    if l[0] in "M":
        cnt[0] += 1
    elif l[0] in "A":
        cnt[1] += 1
    elif l[0] in "R":
        cnt[2] += 1
    elif l[0] in "C":
        cnt[3] += 1
    elif l[0] in "H":
        cnt[4] += 1

ans = 0
l  = []
if cnt.count(0) == 2:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0]*l[1]*l[2]
if cnt.count(0) == 1:
    for num in cnt:
        if num != 0:
            l.append(num)
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[2] * l[3]
    ans += l[2] * l[1] * l[3]
if cnt.count(0) == 0:
    l = cnt
    ans += l[0] * l[1] * l[2]
    ans += l[0] * l[1] * l[3]
    ans += l[0] * l[1] * l[4]
    ans += l[0] * l[2] * l[3]
    ans += l[0] * l[2] * l[4]
    ans += l[0] * l[3] * l[4]
    ans += l[1] * l[2] * l[3]
    ans += l[1] * l[2] * l[4]
    ans += l[1] * l[3] * l[4]
    ans += l[2] * l[3] * l[4]

if cnt.count(0) > 2:
    print(0)
else:
    print(ans)

Measured memory_bytes: 15940
#include <iostream>
#include <cstdlib>
#include <cmath>
 
using namespace std;
 
int get_three_num(string str, int index);
int calc_sub(int num);
 
int main(void)
{
  string str;
  int closest_num;
  int current_num;
  
  cin >> str;
  
  closest_num = get_three_num(str, 0);
  for(int i = 1; i < str.length() - 2; i++){
    current_num = get_three_num(str, i);
    
    if(calc_sub(closest_num) > calc_sub(current_num)){
      closest_num = current_num;
    }
  }
  
  cout << abs(closest_num - 753);
  
  return 0;
}
 
int get_three_num(string str, int index)
{
  int num = 0;
  
  for(int i = index; i < index + 3; i++){
    num += (str[i] - '0') * pow(10, 2 - (i - index));
  }
  
  return (int)num;
}
 
int calc_sub(int num)
{
  return abs(753 - num);
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    ll n, k;
    cin >> n >> k;

    vector<ll> v(n);

    rep(i, n) cin >> v[i];

    sort(ALL(v), greater<ll>());

    ll ans = 0;

    for (int i = k; i < n; i++)
        ans += v[i];

    OP(ans);

    return 0;
}

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

int main(){
    double r, ans;
    cin >> r;
    ans = r * 2.0 * 3.141592653589;
    cout << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 3784