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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n;cin>>n;
    string s;cin>>s;

    int l=0;
    int r=0;

    REP(i,n){
        if(s[i] == '('){
            l++;
        }
        else{
            if(l==0){
                r++;
            }
            else{
                l--;
            }
        }
    }
    REP(i,r){
        s = "("+s;
    }
    REP(i,l){
        s += ")";
    }
    cout<<s<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
import sys
S = input()

odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

for i, j in enumerate(S):
    if i % 2 == 0:
        if not j in odd:
            print('No')
            sys.exit()
    else:
        if not j in even:
            print('No')
            sys.exit()
print('Yes')
        


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

using namespace std;

const int MAX_N = 55;

long long dp[2][MAX_N*MAX_N][MAX_N],ans;

int main()
{
	int n,a,x;
	cin >> n >> a;
	dp[0][0][0]=dp[1][0][0]=1;
	for (int i=1; i<=n; i++)
	{
		cin >> x;
		copy(&dp[1][0][1],&dp[1][n*a][n]+1,
				&dp[0][0][1]);
		for (int k=1; k<=n; k++)	
			for (int s=x; s<=n*a; s++)
				dp[0][s][k]+=dp[1][s-x][k-1];
	
//		copy(&dp[1][0][1],&dp[1][n*a][n]+1,&dp[0][0][1]);
//		transform(&dp[0][x][1],&dp[0][n*a][n]+1,&dp[1][0][0],&dp[0][x][1],plus<>());
		swap(dp[0],dp[1]);
	}
	for (int k=1; k<=n; k++)
		ans+=dp[1][a*k][k];
	cout << ans;
	return 0;
}

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

struct Sieve {
    int n;
    vector<ll> f, primes;
    Sieve(ll n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(ll x) { return f[x] == x;}
    vector<pair<ll, int>> factor(ll x) {
        vector<pair<ll, int>> res;
        for (int p : primes) {
            int y = 0;
            while (x%p == 0) x /= p, ++y;
            if (y != 0) res.emplace_back(p, y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

int main() {
    ll n;
    cin >> n;
    Sieve s(1000005);
    auto fs = s.factor(n);
    int ans = 0;
    for (auto p : fs) {
        int x = p.second;
        int b = 1;
        while (b <= x) {
            x -= b;
            ++b;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12112
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	double a_d,b_d;
	scanf("%d %d",&a,&b);
	a_d = static_cast<double>(a);
	b_d = static_cast<double>(b);
	printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


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

int main() {
  long n,x,aokipt=0,ans=0;
  cin >> n >> x;
  vector<long> b(n),l(n),u(n);
  priority_queue<long> q;
  for(long i=0;i<n;i++) {
    cin >> b[i] >> l[i] >> u[i];
    aokipt+=b[i]*l[i];
    q.push(b[i]*l[i]+(x-b[i])*u[i]);
  }
  while(aokipt>=q.top()) {
    ans+=x,aokipt-=q.top();
    q.pop();
  }
  long aaa=99999999999999;
  if(aokipt==0) aaa=0;
  set<long> s;
  long rty=-99999999999999;
  while(q.size()!=0) {
    if(rty==-99999999999999) rty=q.top();
    s.insert(q.top());
  	q.pop();
  }
  for(long i=0;i<n;i++) {
    if(s.count(b[i]*l[i]+(x-b[i])*u[i])) {
      if(b[i]*l[i]>=aokipt) {
        aaa=min(aaa,(aokipt+l[i]-1)/l[i]);
      } else {
        aaa=min(aaa,b[i]+(aokipt-b[i]*l[i]+u[i]-1)/u[i]);
      }
    } else {
      if(b[i]*l[i]>=aokipt-rty+b[i]*l[i]+(x-b[i])*u[i]) {
        aaa=min(aaa,(aokipt-rty+b[i]*l[i]+(x-b[i])*u[i]+l[i]-1)/l[i]);
      } else {
        aaa=min(aaa,b[i]+(aokipt-rty+b[i]*l[i]+(x-b[i])*u[i]-b[i]*l[i]+u[i]-1)/u[i]);
      }
    }
  }
  ans+=aaa;
  cout << ans << endl;
}

Measured memory_bytes: 10804
use proconio::{fastout, input};

use proconio::marker::Usize1;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        h: [u64; n],
    }
    let mut g = vec![true; n];
    for _ in 0..m {
        input! { a: Usize1, b: Usize1 }
        if h[a] <= h[b] {
            g[a] = false;
        }
        if h[b] <= h[a] {
            g[b] = false;
        }
    }
    let ans = g.iter().filter(|&&x| x).count();
    println!("{}", ans);
}


Measured memory_bytes: 5100
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC169F
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = RInt;
            var S = RInt;
            var A = RInts;

            int mod = 998244353;

            long[,] dp = new long[N + 1, S + 1];
            dp[0, 0] = 1;
            for (int i = 1; i <= N; i++)
            {
                for (int j = 0; j <= S; j++)
                {
                    dp[i, j] = 2 * dp[i - 1, j];
                    dp[i, j] %= mod;
                    if (j - A[i - 1] >= 0) dp[i, j] += dp[i - 1, j - A[i - 1]];
                    dp[i, j] %= mod;
                }
            }

            Draw2D(dp);

            long ans = dp[N, S];
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

int main() {
  long long H,W,N,u;
  cin>>H>>W>>N;
  int c[H][W];
  u=0;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<H;i++){
    if(i%2==0){
    for(int j=0;j<W;j++){
      if(a[u]>0){
        c[i][j]=u+1;
        a[u]--;
      }
      else{
        u++;
        j--;
        continue;
      }
    }
    }
    else{
         for(int j=W-1;j>=0;j--){
      if(a[u]>0){
        c[i][j]=u+1;
        a[u]--;
      }
      else{
        u++;
        j++;
        continue;
      }
    }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<c[i][j];
      if(j<W-1){
        cout<<" ";
      }
      else{
        cout<<endl;
      }
    }
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll a[n],ans=0,k;
    for (i=0;i<n;i++)
    {
        cin>>a[i];
        k=a[i];
        while (k%2==0)
        {
            ans++;
            k>>=1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i=0; i<n; i++){
            x[i] = stdIn.nextInt();
            y[i] = stdIn.nextInt();
        }

        int[] seed = new int[n];
        for(int i=0; i<n; i++){
            seed[i] = i;
        }
        Permutation p = new Permutation(seed);

        double sum = 0.0;
        do{
            int[] perm = p.getPerm();
            for(int i=1; i<perm.length; i++){
                sum += Math.sqrt((x[perm[i]] - x[perm[i-1]]) * (x[perm[i]] - x[perm[i-1]]) + (y[perm[i]] - y[perm[i-1]]) * (y[perm[i]] - y[perm[i-1]]));
            }
        }while(p.next());

        int fact = factorial(n);

        System.out.println(sum / factorial(n));
    }

    static int factorial(int n){
        if(n == 0){
            return 1;
        }
        return n * factorial(n - 1);
    }
}

class Permutation{
    int[] seed;
    int[] perm;

    public Permutation(int [] seed){
        this.seed = seed;
        this.perm = seed;
    }

    public int[] getPerm(){
        return this.perm;
    }

    public boolean next(){
        for(int i=perm.length-1; i>0; i--){
            if(perm[i] > perm[i-1]){
                changePerm(i);
                return true;
            }
        }

        return false;
    }

    private void changePerm(int index){
        int targetIndex = index;
        int min = Integer.MAX_VALUE;
        for(int i=index; i<perm.length; i++){
            if(min > perm[i] && perm[index-1] < perm[i]){
                min = perm[i];
                targetIndex = i;
            }
        }

        int temp = perm[index - 1];
        perm[index - 1] = perm[targetIndex];
        perm[targetIndex] = temp;

        for(int i=index; i<perm.length; i++){
            int x = perm[i];
            int j = i;
            while(j>index && perm[j-1] > x){
                perm[j] = perm[j-1];
                j--;
            }
            perm[j] = x;
        }
    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n;
char s[maxn];
int main() {
	scanf(" %s",s+1);
	n = strlen(s+1);
	long long ans = 0;
	for(int i=1,j=1;i<=n-2;) {
		if(s[i]!='A') j = i+1;
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
			//printf("i =%d j = %d\n",i,j);
			s[i+1] = s[j];
			s[i+2] = s[j+1];
			s[j] = 'B';
			s[j+1] = 'C';
			ans += i-j+1;
			j = j+2;
		}
		i = i+1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int MR=1e6+10;

int f(int x,int b){
	int ans=0;
	while(x){
		ans+=x%b;
		x/=b;
	}
	return ans;
}

int main(){
	int N;
	cin>>N;
	int ans=N;
	for(int M=0;M<=N;M++){
		ans=min(ans,f(M,6)+f(N-M,9));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int N,T;
  cin >> N >> T;
  int c[N];
  int t[N];
  for(int i=0;i<N;i++){
    cin >> c[i] >> t[i];
  }
  vector<pair<int,int> > tc(N);
  for(int i=0;i<N;i++){
    tc[i] = make_pair(t[i],c[i]);
  }
  int ans = 1000;
  sort(tc.begin(),tc.end());
  if(tc[0].first > T){
    cout << "TLE" << endl;
  }else{
    for(int i=0;i<N;i++){
      if(tc[i].first<=T){
        ans = min(tc[i].second,ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

//int AtCoderABC058B( int argc, char *argv[] )
int main( int argc, char *argv[] )
{
int i;
char O[ 60 ];
char E[ 60 ];

	cin >> O;
	cin >> E;

	i = 0;
	while( true )
	{
		if( O[ i ] == '\0' ) break;

		cout << O[ i ];
		if( E[ i ] == '\0' ) break;

		cout << E[ i ];

		i++;
	}

	cout << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
void solve () {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = s;
    stack<char> st;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] == ')') {
            if (st.empty()) {
                ans = '(' + ans;
            } else {
                st.pop();
            }
        } else {
            st.push(')');
        }
    }
    cout << ans;
    for (int i = 0; i < (int) st.size(); i++) {
        cout << ')';
    }

}

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


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vector<ll> sum;
void pre_process(vector<ll> &a, vector<ll> &s) {  //累積和のvector
    ll n = (ll)a.size();
    s.assign(n + 1, 0);
    for (ll i = 0; i < n; i++) {
        s[i + 1] = (s[i] + a[i]) % mod;
        s[i + 1] %= mod;
    }
}
ll query(ll i, ll j, vector<ll> &s) {  //区間[i,j]の和
    return (s[j] - s[i]);
}

struct UnionFind {
    vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(
        int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);       // xの根をrx
        int ry = root(y);       // yの根をry
        if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] =
            ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }

    vector<ll> num(n);
    rep(i, n) { num[uf.root(i)]++; }
    sort(num.begin(), num.end(), greater<ll>());

    cout << num[0] << "\n";

    return 0;
}

Measured memory_bytes: 11708
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	string s;
	ll K;
	cin >> s >> K;
	if(s.size() == 1) {
		cout << s << endl;
		return 0;
	}

	int idx = 0;
	rep(i, 0, s.size()) {
		if(s[i] != '1') break;
		idx++;
	}

	if(idx >= K) {
		cout << 1 << endl;
		return 0;
	}
	
	cout << s[idx] << endl;
}


Measured memory_bytes: 256
package main
import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

func main(){
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for scanner.Scan(){
		input := scanner.Text()
		if input=="-"{
			break
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i:=0; i<m; i++{
			scanner.Scan()
			h, _ := strconv.Atoi(scanner.Text())
			input = input[h:]+input[:h]
		}
		fmt.Println(input)
	}
}


Measured memory_bytes: 1084
X = int(input())

r = 0

if X < 600:
    r = 8
elif X < 800:
    r = 7
elif X < 1000:
    r = 6
elif X < 1200:
    r = 5
elif X < 1400:
    r = 4
elif X < 1600:
    r = 3
elif X < 1800:
    r = 2
else:
    r = 1

print(r)

Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll a, b, m;
    cin >> a >> b >> m;
    ll x[a], y[b];
    map<p, ll> I{};
    for(ll i = 0; i < a; i++)
        cin >> x[i];
    for(ll i = 0; i < b; i++)
        cin >> y[i];
    ll ans = 1e+9;
    for(ll i = 0; i < m; i++){
        ll c, d, e;
        cin >> c >> d >> e;
        ans = min(ans, x[c-1]+y[d-1]-e);
    }
    sort(x, x+a);
    sort(y, y+b);
    ans = min(ans, x[0]+y[0]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 5e3+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin>>n>>k;
	vector<int> vec(n);
	for(auto &x: vec) cin>>x;
	SORT(vec);
	ll res = 0;
	for(int i = 0; i < k; i++) res += vec[i];
	cout<<res;
}

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

int main(){
	string a, b;
	string ans="EQUAL";
	cin >> a >> b;
	if(a.size()>b.size()) ans="GREATER";
	if(a.size()<b.size()) ans="LESS";
	if(a.size()==b.size()){
		for(int i=0; i<a.size(); i++){
			if(a.at(i)>b.at(i)){
				ans="GREATER";
				break;
			}
			if(a.at(i)<b.at(i)){
				ans="LESS";
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3552
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main(void) {
  int r, g, b;
  cin >> r >> g >> b;
  int v = r*100 + g*10 + b;
  puts(v%4 == 0 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string>
#define mod 1000000007
using ll = long long;
using namespace std; 

int main(){
    int h,w,k; cin >> h >> w >> k;
    vector<string> H(h);
    vector<string> W(w);
    map<int,int> C;
    int how=0;
    for (int i=0;i<h;i++){
        C[i]=0;
    }
    for (int i=0;i<h;i++){
        string a; cin >> a;
        H[i]=a;
        for (int j=0;j<a.size();j++){
            if (a[j]=='#'){
                W[j]+=a[j];
                how++;
            }
            else W[j]+='.';
        }
    }
    int ans=0;
    int check=0;
    for (int i=0;i<(1<<h+w);i++){
        for (int j=0;j<h;j++){
            if (i&(1<<j)){
                C[j]=1;
                string r=H[j];
                for (int k=0;k<w;k++){
                    if(r[k]=='#') {
                        check++;
                    }
                }
            }
        }
        for (int j=h;j<h+w;j++){
            if (i&(1<<j)){
                string r=W[j-h];
                for (int k=0;k<h;k++){
                    if (C[k]==0 && r[k]=='#') check++;
                }
            }
        }
        if (how-check==k){
            ans++;
        }
        check=0;
        for (int i=0;i<h;i++){
            C[i]=0;
        }
    }
    cout << ans << "\n";
}




Measured memory_bytes: 3616
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        mut K: usize,
        A: [usize; N],
    }

    let mut dist = vec![std::usize::MAX; N + 1]; // 街1 からの距離
    dist[1] = 0;

    let mut step = 0;
    let mut l1 = 0; // 1 -> 閉路開始点までの距離
    let mut l2 = 0; // 閉路長

    let mut node = 1;
    for _ in 0..N {
        step += 1;
        node = A[node - 1];
        if dist[node] < std::usize::MAX {
            l1 = dist[node];
            l2 = step - dist[node];
            break;
        }
        dist[node] = step;
    }

    let ans = if K < l1 {
        dist.iter().position(|&x| x == K).unwrap()
    } else {
        let a = (K - l1) % l2 + l1;
        dist.iter().position(|&x| x == a).unwrap()
    };
    println!("{}", ans);
}


Measured memory_bytes: 6372
#include <iostream>
using namespace std;
 
int main(){
  int n,k,x = 1;
  cin >> n >> k;
  for (int i = 0; i < n;i++){
    if (x < k){
      x *= 2;
    }else{
      x += k;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int x,y,r,tmp;

  scanf("%d%d",&x,&y);

  if(x<y) {
    tmp=x;
    x=y;
    y=tmp;
  }

  r = x%y;

  while(r!=0) {
    x = y;
    y = r;
    r = x%y;
  }

  printf("%d\n",y);

  return 0;

}



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int X[1002], Y[1002], R[1002];
vector<pair<int,double>> e[1002];
double dist[1002];

double distance(int a, int b) {
    return max(0.,sqrt((double)(X[a]-X[b])*(X[a]-X[b])+(double)(Y[a]-Y[b])*(Y[a]-Y[b]))-R[a]-R[b]);
}

int main(void) {
    int i, j, N, XS, YS, XT, YT;
    cin >> XS >> YS >> XT >> YT;
    cin >> N;
    REP (i,N) cin >> X[i] >> Y[i] >> R[i];
    X[N] = XS; Y[N] = YS;
    X[N+1] = XT; Y[N+1] = YT;
    REP (i,N+2) REP (j,N+2) {
        e[i].emplace_back(j,distance(i,j));
    }
    priority_queue<pair<double,int>> q;
    REP (i,N+2) dist[i] = 1e14;
    dist[N] = 0;
    q.push(make_pair(0,N));
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        int u = p.second;
        for (auto x: e[u]) {
            int v = x.first;
            double d = x.second;
            if (dist[u] + d < dist[v]) {
                dist[v] = dist[u] + d;
                q.push(make_pair(-dist[v],v));
            }
        }
    }
    cout << fixed << setprecision(12);
    cout << dist[N+1] << endl;
    return 0;
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int32_t main()
{
	IOS;
	string s, t;
	cin >> s >> t;
	s = '#' + s;
	t = '#' + t;
	int n = s.length(), m = t.length();
	vector<vector<int>> dp;
	auto solve = [&]() {
		dp.assign(n + 1, vi(m + 1, 0));
		rep(i, 1, n)
		{
			rep(j, 1, m)
			{
				if (s[i] == t[j])
					dp[i][j] = dp[i - 1][j - 1] + 1;
				else
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	};
	solve();
	int nowi = n - 1, nowj = m - 1;
	int rem = dp[n - 1][m - 1];
	string ans = "";
	while (rem > 0)
	{
		if (s[nowi] == t[nowj])
		{
			ans += s[nowi];
			nowi--, nowj--;
			rem--;
		}
		else if (dp[nowi - 1][nowj] > dp[nowi][nowj - 1])
		{
			nowi--;
		}
		else
		{
			nowj--;
		}
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 70784
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 998244353
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N];
	f(i, N)a[i] = 0;
	long long dp[5000];
	long long dp2[5000];
	int l[5000];
	int r[5000];
	f(i, 5000){
		dp[i] = 0;
		dp2[i] = 0;
	}
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%s",a);
	n = strlen(a);
	l[0] = 0;
	r[0] = 0;
	f(i, n){
		if (a[i] == '0'){
			r[i + 1] = r[i];
			l[i + 1] = max(r[i + 1] - i - 1, 0);
		}
		else if (a[i] == '1'){
			r[i + 1] = r[i] + 1;
			l[i + 1] = max(r[i+1] - i-1, 0);
		}
		else{
			r[i + 1] = r[i] + 2;
			l[i + 1] = max(r[i+1] - i-1, 0);
		}
	}
	f(i, n){
		r[i + n + 1] = r[i + n];
		l[i + n + 1] = max(0, r[i + n + 1] + i + 1 - n);
	}
	dp[0] = 1;
	f(i, 2 * n){
		for (int j = l[i]; j <= r[i]; j++){
			if (l[i + 1] <= j&&j <= r[i + 1])dp2[j] = (dp[j] + dp2[j]) % MOD;
			if (l[i + 1] <= (j + 1) && (j + 1) <= r[i + 1])dp2[j + 1] = (dp[j] + dp2[j + 1]) % MOD;
		}
		f(j, 5000){
			dp[j] = dp2[j];
			dp2[j] = 0;
		}
	}

	printf("%lld\n", dp[r[2*n]]);


	return 0;
}

Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))

left = max(A)

right = 0
dif_min = 10**10
mid = (max(A)/2)

for i in range(n):
    if A[i] == left:
        continue
    dif = abs(A[i] - mid)
    if dif <= dif_min:
        dif_min = dif
        right = A[i]

print(str(left) + ' ' + str(right))

Measured memory_bytes: 14428
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int ans = n;
    REP(i,n/2){
        if (s[i] != s[i+1] || s[n-1-i] != s[n-2-i]){
            ans = min(ans, n-1-i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
int table[1100000];
int val[1001];
int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(a+b==0)return 0;
		for(int i=0;i<a;i++){
			scanf("%d",val+i);
		}
		val[a]=0;
		for(int i=0;i<=a;i++){
			for(int j=0;j<=a;j++){
				table[i*(a+1)+j]=val[i]+val[j];
			}
		}
		std::sort(table,table+(a+1)*(a+1));
		int point=0;
		for(int i=0;i<=a;i++){
			for(int j=0;j<=a;j++){
				if(val[i]+val[j]<=b)point=max(point,val[i]+val[j]+table[upper_bound(table,table+(a+1)*(a+1),b-val[i]-val[j])-table-1]);
			}
		}
		printf("%d\n",point);
	}
}

Measured memory_bytes: 4680
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll a[MAXN];
set<ll> cnt;
map<ll,int> xy;

int main() {
	int n; ni(n);
	for (int i = 0; i < n; i++) {
		nl(a[i]);
		cnt.insert(a[i]);
		if (xy.find(a[i]) == xy.end())
			xy[a[i]] = 0;
		xy[a[i]]++;
	}
	if (cnt.size() > 3) return !printf("No\n");
	vl tmp;
	for (set<ll>::iterator it = cnt.begin(); it != cnt.end(); it = next(it))
		tmp.pb(*it);
	sort(tmp.begin(), tmp.end());
	if (tmp.size() == 1 && tmp[0] == 0) return !printf("Yes\n");
	if (tmp.size() == 2 && tmp[0] == 0 && xy[tmp[0]] * 2 == xy[tmp[1]]) return !printf("Yes\n");
	if (tmp.size() == 3 && xy[tmp[0]] == xy[tmp[1]] && xy[tmp[2]] == xy[tmp[0]]) {
		if ((tmp[0] ^ tmp[1]) == tmp[2])
			return !printf("Yes\n");
	}
	printf("No\n");
    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 ll n,a[1001],b[1001],cnt=0,m,t=1;
 const ll N=1e9+7;
int main()
{
    cin>>n;
    memset(a,0,sizeof(0));
    for(int i=1;i<=n;i++)
        {
            m=i;
            int j=2;
            while( j<=m)
            {
                if(m % j == 0) {a[j]++; m/=j;}
                else j++;
            }
        }
    for(int i=1;i<=n;i++) {
        t*=(a[i]+1);
        t%=N;

    }
    cout<<t;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,x,m[1000],i,a,b,cnt,s;
	cin>>n>>x;
	a=0;
	cnt=0;
	s=1001;
	for(i=0;i<n;i++){
		cin>>m[i];
		a=a+m[i];
		cnt=cnt+1;
		if(s>m[i]) s=m[i];
	}
	//cout<<"a"<<a<<endl;
	//cout<<"s"<<s<<endl;
	b=x-a;
	//cout<<"b"<<b<<endl;
	while(1){
		if(b<s) break;
		b=b-s;
		cnt=cnt+1;
	//	cout<<cnt<<endl;
	}
	cout<<cnt<<endl;
	return 0;
}


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

#define LL long long

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF=9999999;
const int MAXN=100000;

int N;
int a[100001],vis[100002];
int ans;

int main(){
	N=read();
	for(int i=1;i<=N;i++)
		a[i]=read(),vis[a[i]]++;
	for(int i=1;i<=100000;i++){
		ans=max(ans,vis[i]+vis[i-1]+vis[i+1]);
	}
	printf("%d\n",ans);
	return 0;
}
//1 1 2 3 4 5 9

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

vector<ll> enum_div(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;
}

//実行部
void Main()
{
  ll a, b; cin >> a >> b;
  ll d = b - a;
  ll n = 0;
  for(ll i = d;i >= 0;i--)
  {
    n += i;
  }
  fin(abs(b - n))
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

ll digit(ll a) {
	ll sum = 0;
	while (a > 9) {
		sum += a % 10;
		a = (a - a % 10) / 10;
	}
	return sum + a;
}

int main(void) {
	ll n, ans = 100000;
	cin >> n;
	for (ll i = 1;i <= n / 2;i++) {
		ans = min(digit(i) + digit(n - i), ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
lst = [-999 for i in range(N+1)]
for i in range(M):
    idx, val = map(int, input().split())
    if lst[idx] == -999:
        lst[idx] = val
    elif lst[idx] != val:
        print(-1)
        exit(0)
res = ""

if N==1 and lst[1]== -999:
    print(0)
    exit(0)
if N==1 and lst[1]== 0:
    print(0)
    exit(0)
if lst[1] == 0:
    print(-1)
    exit(0)
if lst[1] == -999:
    lst[1] = 1
for i in range(1,N+1):
    if lst[i] == -999:
        res += "0"
    else:
        res += str(lst[i])
print(res)

Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
char dice[7][8]={
		"TOP",
		"SOUTH",
		"EAST",
		"WEST",
		"NORTH",
		"BOTTOM",
};
void north(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"TOP"))strcpy(dice[i],"NORTH");
		else if(!strcmp(dice[i],"NORTH"))strcpy(dice[i],"BOTTOM");
		else if(!strcmp(dice[i],"BOTTOM"))strcpy(dice[i],"SOUTH");
		else if(!strcmp(dice[i],"SOUTH"))strcpy(dice[i],"TOP");
	}
}
void east(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"TOP"))strcpy(dice[i],"EAST");
		else if(!strcmp(dice[i],"EAST"))strcpy(dice[i],"BOTTOM");
		else if(!strcmp(dice[i],"BOTTOM"))strcpy(dice[i],"WEST");
		else if(!strcmp(dice[i],"WEST"))strcpy(dice[i],"TOP");
	}
}
void south(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"TOP"))strcpy(dice[i],"SOUTH");
		else if(!strcmp(dice[i],"SOUTH"))strcpy(dice[i],"BOTTOM");
		else if(!strcmp(dice[i],"BOTTOM"))strcpy(dice[i],"NORTH");
		else if(!strcmp(dice[i],"NORTH"))strcpy(dice[i],"TOP");
	}
}
void west(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"TOP"))strcpy(dice[i],"WEST");
		else if(!strcmp(dice[i],"WEST"))strcpy(dice[i],"BOTTOM");
		else if(!strcmp(dice[i],"BOTTOM"))strcpy(dice[i],"EAST");
		else if(!strcmp(dice[i],"EAST"))strcpy(dice[i],"TOP");
	}
}
void left(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"EAST"))strcpy(dice[i],"NORTH");
		else if(!strcmp(dice[i],"NORTH"))strcpy(dice[i],"WEST");
		else if(!strcmp(dice[i],"WEST"))strcpy(dice[i],"SOUTH");
		else if(!strcmp(dice[i],"SOUTH"))strcpy(dice[i],"EAST");
	}
}
void right(){
	int i;
	for(i=0;i<6;i++){
		if(!strcmp(dice[i],"WEST"))strcpy(dice[i],"NORTH");
		else if(!strcmp(dice[i],"NORTH"))strcpy(dice[i],"EAST");
		else if(!strcmp(dice[i],"EAST"))strcpy(dice[i],"SOUTH");
		else if(!strcmp(dice[i],"SOUTH"))strcpy(dice[i],"WEST");
	}
}
int main(){
	int i,n,j,sum;
	char str[10];
	while(1){
		scanf("%d",&n);
		if(!n)break;
		strcpy(dice[0],"TOP");
		strcpy(dice[1],"SOUTH");
		strcpy(dice[2],"EAST");
		strcpy(dice[3],"WEST");
		strcpy(dice[4],"NORTH");
		strcpy(dice[5],"BOTTOM");
		sum=1;
		for(j=0;j<6;j++){
		}
		for(i=0;i<n;i++){
			scanf("%s",str);
			if(!strcmp(str,"North"))
				north();
			else if(!strcmp(str,"East"))
				east();
			else if(!strcmp(str,"South"))
				south();
			else if(!strcmp(str,"West"))
				west();
			else if(!strcmp(str,"Left"))
				left();
			else if(!strcmp(str,"Right"))
				right();
			for(j=0;j<6;j++){
				if(!strcmp(dice[j],"TOP")){
					sum+=j+1;
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
int f(int a){
	if(a==0)
		return 0;
	return 1+2*f(a/2);
}
int32_t main() 
{ 
	int h,n;
	cin>>h>>n;
	int a[n],b[n];
	for(int i=0;i<n;++i)
		cin>>a[i]>>b[i];
	int c[h+1];
	for(int i=0;i<=h;++i)
		c[i]=LLONG_MAX;
	c[0]=0;
	for(int i=0;i<n;++i){
		for(int j=1;j<=h;++j){
			if(j<a[i])
				c[j]=min(c[j],b[i]);
			else
				c[j]=min(c[j],c[j-a[i]]+b[i]);
		}
	}
	cout<<c[h];
} 


Measured memory_bytes: 384
//Tsundoku

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m,k;cin>>n>>m>>k;
    deque<int>t(n),b(m);
    rep(i,0,n)cin>>t[i];
    rep(i,0,m)cin>>b[i];
    reverse(range(t));
    int s=accumulate(range(t),0LL),ans=0;
    t.pb(0);
    while(true){
        bool flag=false;
        while(s>k){
            if(t.front()==0)flag=true;
            if(flag==true&&t.front()!=0)break;
            s-=t.front();
            t.pop_front();
        }
        if(flag==true&&t.front()!=0)break;
        ans=max(ans,(int)t.size()-1);
        if(b.size()<1)break;
        t.pb(b.front());
        s+=b.front();
        b.pop_front();
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 6968
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;

typedef long long ll;
#define PII pair<ll,ll>
const int maxn=1e6+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-10;
using namespace std;
int main()
{
	int n,i,a[maxn]={0},vis[4]={0};
	char s[maxn];
	scanf("%d",&n);
	scanf("%s",s+1);
	for(i=1;i<=n;i++)a[i]=s[i]-'0'-1,vis[a[i]]=1;
	if(vis[2])
	{
		if(vis[1])
		{
			for(i=1;i<=n;i++)a[i]=a[i]%2;
		}
		else for(i=1;i<=n;i++)if(a[i]==2)a[i]=1;
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
		if(((n-1)&i)==i)ans=(ans+a[i+1])%2;
	}
	if(ans)
	{
		if(vis[1])puts("1");
		else puts("2");
	}
	else puts("0");
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int d[510][510];

signed main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    int p = 1e9 - 1;
    int m = -1e9;
    rep(i, 0, H){
        rep(j, 0, W){
            if(i % h == 0 && j % w == 0) d[i][j] = p;
            if(i % h == h - 1 && j % w == w - 1) d[i][j] = m;
        }
    }
    rep(i, 0, H){
        rep(j, 0, W){
            if(j != 0) cout << " ";
            cout << d[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 4864
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int testcase_ends() {
  size_t m;
  size_t nmin, nmax;
  scanf("%zu %zu %zu", &m, &nmin, &nmax);

  if (m == 0 && nmin == 0 && nmax == 0) return 1;

  std::vector<int> P(m);
  for (auto& pi: P) scanf("%d", &pi);

  std::sort(P.rbegin(), P.rend());
  size_t res = 0;
  int gap = 0;
  for (size_t i = m; i--;) {
    if (i > nmax) continue;
    if (i < nmin) break;
    if (gap < P[i-1]-P[i]) {
      gap = P[i-1]-P[i];
      res = i;
    }
  }
  printf("%zu\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2616
# 2019-11-19 10:28:31(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    a, b = map(int, sys.stdin.readline().split())
    print(max(0, a - b * 2))

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    
    int max_=0;
    int min_=MOD;
    vector<int> A(N,0);

    for(int i=0; i<N; i++){
        int a;
        cin >> a;

        max_=max(max_, a);
        min_=min(min_, a);
        A[a]++;
    }

    //cout << N << ' ' << max_ << ' ' << min_ << endl;
    if(max_-min_>1){
        cout << "No" << endl;
        return 0;
    }else if(max_-min_==0 && min_==N-1){
        cout << "Yes" << endl;
        return 0;
    }

    if(max_-N+A[max_]>0 && A[max_]/(max_-N+A[max_])>=2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define ll long int

ll ans = 0;

const int N = pow(10,5)/2 + 5;
ll x[N] = {},y[N] = {};

int main(){
    ll n,t,tmax = -1;
    cin >> n >> t;
    vector<pair <ll,ll> > v;
    for(int i = 0; i < n; ++i){
        ll a,b;
        cin >> a >> b;
        if(b <= t)
            v.push_back(make_pair(a,b));
    }

    if(v.size() == 0){
        cout << "TLE" << endl;
        return 0;
    }

    sort(v.begin(),v.end());

    cout << v[0].first << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
const int MN=100000;
vector<int> a[MN];
int ans[MN];
stack<int> st;
int main(){
	cin>>N;
	rep(i,N) ans[i]=-1;
	rep(i,N){
		int x;
		cin>>x;
		x--;
		a[x].pb(i);
	}
	rep(i,N) reverse(all(a[i]));
	rep(i,2*N){
		if(i<N) for(int x:a[i]) st.push(x);
		if(!st.empty() && ans[i%N]==-1){
			ans[i%N]=st.top();
			st.pop();
		}
	}
	rep(i,N) cout<<ans[i]+1<<endl;
}

Measured memory_bytes: 7848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
     
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            String[] arr = str.split(" ");
            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            int c = Integer.parseInt(arr[2]);
            int temp;
             
            if (a > b) {
                temp = a;
                a = b;
                b = temp;
            }
             
            if (b > c) {
                temp = b;
                b = c;
                c = temp;
            }
             
            if (a > b) {
                temp = a;
                a = b;
                b = temp;
            }
             
            System.out.println(a + " " + b + " " + c);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

Measured memory_bytes: 24328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=55;
ll dp[INF][INF*INF]; 
int main(){
    int n,a;
    cin>>n>>a;
    int x;
    dp[0][0]=1;
    for(int i=0; i<n; i++){
        cin>>x;
        for(int j=i; j>=0; j--){
            for(int k=0; k<=INF*j; k++){   
                dp[j+1][k+x]+=dp[j][k];
            }
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        ans+=dp[i][i*a];
    }
    cout<<ans<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 1024
X,N = map(int,input().split())

min = 100

if N !=0:
  Plist = list(map(int,input().split()))
  anslist = [i for i in range(201)]
  anslist.append(-1)
  #anslist.remove(0)
  Plist = sorted(Plist)
  for i in range(N):
    anslist.remove(Plist[i])
    temp =100
  for i in range(len(anslist)):
    if min >abs(anslist[i]-X) :
      min = abs(anslist[i]-X)
      temp = anslist[i]
  print (temp)
else :
  print (X)

Measured memory_bytes: 9064