akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
	if(s[i]=='?')
	{
		s[i]='D';
	}
}
cout<<s<<endl;
return 0;
}
// Problem : B - Postdocs
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);


int main() {
	int H, W;
	cin >> H >> W;
	vector<Vi> up(H, Vi(W));
	vector<Vi> down(H, Vi(W));
	vector<Vi> left(H, Vi(W));
	vector<Vi> right(H, Vi(W));

	vector<string> S(H);

	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (S[i][j] == '#') {
				continue;
			}

			if (i == 0) {
				up[i][j] = 1;
			}
			else {
				up[i][j] = up[i - 1][j] + 1;
			}

			if (j == 0) {
				left[i][j] = 1;
			}
			else {
				left[i][j] = left[i][j - 1] + 1;
			}
		}
	}

	int ans = 0;

	for (int i = H - 1; i >= 0; --i) {
		for (int j = W - 1; j >= 0; --j) {
			if (S[i][j] == '#') {
				continue;
			}

			if (i == H - 1) {
				down[i][j] = 1;
			}
			else {
				down[i][j] = down[i + 1][j] + 1;
			}

			if (j == W - 1) {
				right[i][j] = 1;
			}
			else {
				right[i][j] = right[i][j + 1] + 1;
			}

			int num = up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3;
			ans = max(ans, num);
		}
	}


	cout << ans << endl;
}


Measured memory_bytes: 67200
def resolve():
    K, N = map(int, input().split())
    ie_list = list(map(int, input().split()))

    value_list = []
    value_list.append(K - ie_list[-1] + ie_list[0])
    count = 0
    while count != N - 1:
        value_list.append(ie_list[count + 1] - ie_list[count])
        count += 1
    print(K - max(value_list))

resolve()

Measured memory_bytes: 86140
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d; cin>>a>>b>>c>>d;
    int start, end;
    if(a<c) start = c;
    else start = a;
    if(b<d) end = b;
    else end = d;
    int ans = end-start;
    if(end-start<0) ans=0;
    print(ans);
    return 0;
}

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

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

using namespace std;

int main() {
  int n;
  cin>>n;
  REP(i,n){
    vector<int> v;
    string str;
    cin>>str;
    for(char c:str){
      if(c=='['){
        v.push_back(-1);
      }else if(c>='0'&&c<='9'){
        if(v.back()!=-1){
          v.back()*=10;
          v.back()+=c-'0';
        }else{
          v.push_back(c-'0');
        }
      }else{
        for(int j=v.size()-1;j>=0;--j){
          if(v[j]==-1){
            ++j;
            sort(begin(v)+j,end(v));
            int w=v.size()-j;
            int sum=0;
            REP(k,w/2+1){
              sum+=v[k+j]/2+1;
            }
            sum*=2;--sum;
            v.erase(begin(v)+j-1,end(v));
            v.push_back(sum);
            break;
          }
        }
      }
    }
    cout<<(v.front()/2+1)<<endl;
  }
  return 0;
}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    while(true){
        C -= B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
        }

        A -= D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3564
program main
      implicit none
      integer(8) :: a, b, mab, ans

      read *, a, b

      call gcd(a,b,mab)

      ans = a * b
      ans = ans/mab

      print *, ans

      contains

      subroutine gcd(m,n,j)
        implicit none
        integer(8), intent(in) :: m, n
        integer(8), intent(out) :: j
        integer(8) :: l, x, y

        x = m
        y = n
        do 
          l = mod(x,y)
          if ( l == 0 ) exit
          x = y
          y = l
        end do
        j = y

      end subroutine gcd

end program main


Measured memory_bytes: 256
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}

int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0)
		cout<<s[i];
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 512
// Try AtCoder
// author: Leonardone @ NEETSDKASU
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	for i := len(s) - 2; i > 1; i-- {
		if s[:i/2] == s[i/2:i] {
			fmt.Println(i)
			break
		}
	}
}


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

int main(void){
    int n;
    
    cin >> n;
    
    vector<int> a(n), d(n+1);
    
    rep(i, n){
        cin >> a.at(i);
    }
    
    rep(i, n){
        d.at(a.at(i)) = i+1;
    }
    
    rep(i, n){
        cout << d.at(i+1);
        if(i != n-1){
            cout << " ";
        } else {
            cout << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1664
N = int(input())
l = input().split(' ')
H = input().split( )

T=int(l[0])
A = int(l[1])
H = [int(x) for x in H]

tem_gap = [abs((T-h*0.006)-A) for h in H]

min = min(tem_gap)
print(tem_gap.index(min) + 1)

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

int main() {
	int H, W;
while(1){
cin>>H>>W;
if(H==0&&W==0) break;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
if((i+j)%2==0){
cout<<"#";

}else{cout<<".";}}cout<<"\n";}cout<<endl;}

// your code goes here
	return 0;
}

Measured memory_bytes: 1156
import Foundation

var line = readLine()!.components(separatedBy: " ").map { Decimal(string: $0)! }
let A = line[0]
let V = line[1]
line = readLine()!.components(separatedBy: " ").map { Decimal(string: $0)! }
let B = line[0]
let W = line[1]
let T = readLine()!.components(separatedBy: " ").map { Decimal(string: $0)! }.first!

if abs(B - A) <= (V - W) * T {
    print("YES")
} else {
    print("NO")
}


Measured memory_bytes: 17848
#include <stdio.h>

// 入力受付用の変数
#define BUF 200002
char str[BUF];

// 入力された値
char S[6];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%s", S);
}

void solve() {
	char c = S[0];
	for (size_t i = 1; i < 4; i++) {
		if (S[i] == c) {
			printf("Bad\n");
			return;
		}

		c = S[i];
	}

	printf("Good\n");
}

int main(void) {
	receive_input();

	solve();

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X;

	int K = 1;
	while (K * X % 360 != 0) K++;
	cout << K << endl;
}







Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,m,cnt=1,i;
	ll ans=1ll,r=1ll;
	string s;
	cin >> n;
	cin >> s;
	m = n*2;
	if(s[0]=='W' || s[m-1]=='W'){
		ans = 0ll;
	}
	for(i=1; i<m; ++i){
		if((s[i]=='W')^(r%2)){
			mul_mod(ans,r);
			--r;
		}else{
			++r;
			++cnt;
		}
		if(cnt>n || r<0 || r>n){
			ans = 0ll;
			break;
		}
	}
	if(r){
		ans = 0ll;
	}
	for(i=1; i<=n; ++i){
		mul_mod(ans,i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string S, T;

int main()
{
  std::cin >> S >> T;

  ll ans = 0;

  rep( i, S.size() ) {
    ans += S[i]!=T[i];
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

static int32_t N;
static vector<int32_t> s;
static vector<vector<int32_t>> memo;

static int32_t dp(int32_t index, int32_t sum)
{
	if (memo[index][sum] > -1)
		return memo[index][sum];

	memo[index][sum] = max(dp(index + 1, sum + s[index]), dp(index + 1, sum));
	return memo[index][sum];
}
int main()
{
	cin >> N;
	s.resize(N);

	memo.resize(N + 1);
	for (int32_t i = 0; i < N; i++) {
		cin >> s[i];
		memo[i].resize(10000 + 1);
		std::fill(std::begin(memo[i]), std::end(memo[i]), -1);
	}

	memo[N].resize(10000 + 1);
	for (int32_t sum = 0; sum < 10000 + 1; sum++) {
		memo[N][sum] = sum % 10 == 0 ? 0 : sum;
	}

	cout << dp(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 4224
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt64(scanner)
	s := getNextInt64(scanner)
	fmt.Fprintln(writer, solve(n, s))

	writer.Flush()
}

func solve(n, s int64) int64 {
	if s == n {
		return n + 1
	}

	var b, ans int64

	ans = -1

	for b = 2; (b-1)*(b-1) <= n; b++ {
		sum := f(b, n)
		if sum == s {
			return b
		}
		if n < s {
			continue
		}
		if (n-s)%(b-1) != 0 {
			continue
		}
		sum = f(((n-s)/(b-1))+1, n)
		if sum == s {
			ans = (n-s)/(b-1) + 1
		}
	}
	return int64(ans)
}
func f(b, n int64) int64 {
	var ans int64
	for b <= n {
		ans += n % b
		n /= b
	}
	ans += n
	return ans
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int N,T,C;
	int L, S;
	int data[4];
	int su[4] = { 1000,100,10,1 };
	while (1) {
		C = 0;
		cin >> N;
		if (N == 0) break;
		if (N % 1111 == 0) {
			cout << "NA" << endl;
			continue;
		}

		while (N != 6174) {
			L = S = 0;
			C++;
			data[0] = N / 1000;
			N %= 1000;
			data[1] = N / 100;
			N %= 100;
			data[2] = N / 10;
			N %= 10;
			data[3] = N;

			for (int i = 0; i < 3; i++) {
				for (int j = i + 1; j < 4; j++) {
					if (data[i] < data[j]) {
						T = data[i];
						data[i] = data[j];
						data[j] = T;
					}
				}
			}
			
			for (int i = 0; i < 4; i++) {
				L += data[i] * su[i];
				S += data[3 - i] * su[i];
			}
	
			N = L - S;
		}
		cout << C << endl;
	}
}

Measured memory_bytes: 1160
import kotlin.math.abs
import kotlin.math.pow

fun main(args: Array<String>) {
    val n = 1e6.toInt()
    val x = readLine()!!.toInt()
    for(a in 0..n){
        val bpow5 = (a.toDouble().pow(5.0) - x.toDouble())
        val b = if(bpow5 > 0) bpow5.pow(1.0/5.0)
        else -(-bpow5).pow(1.0/5.0)
        if(abs(b - b.toLong()) < 1e-7){
            println("$a ${b.toLong()}")
            break
        }
    }
}

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

int main() {
    int H ,W;
    while(1){
        cin >> H >> W;
        if( H == 0 && W == 0) break;

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
const int INF=1e9;

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  if(n==2)fin(-1);
  map<int,int> m;
  for(int i=0;i<n;i++)m[v[i]]++;
  vector<int> ans;
  set<int> s;
  for(int i=1;i<=n;i++)s.insert(i);
  while(ans.size()<n){
    if(ans.size()+12>=n){
      int kaka=n-ans.size();
      vector<int> w(kaka);
      for(int i=0;i<kaka;i++){
        w[i]=*s.begin();s.erase(w[i]);
      }
      //cout<<"?";for(int i=0;i<3;i++)cout<<w[i]<<" ";cout<<endl;
      do{
        //cout<<"??";for(int i=0;i<3;i++)cout<<w[i]<<" ";cout<<endl;
        bool f=true;
        int T=-1;
        if(ans.size()>0)T=v[ans[ans.size()-1]-1];
        for(int i=0;i<kaka;i++){
          if(i==0){
            if(T==w[0])f=false;
          }
          else{
            if(v[w[i-1]-1]==w[i])f=false;
          }
        }
        if(f){
          for(int i=0;i<kaka;i++)ans.push_back(w[i]);
          break;
        }
      }while(next_permutation(w.begin(),w.end()));
      break;
    }
    int p=*s.begin();
    /*if(ans.size()==n-1){
      if(p==v[ans[ans.size()-1]-1])fin(-1);
      ans.push_back(p);break;
    }*/
    int t=v[p-1];
    int ho=-1;
    if(ans.size())if(v[ans[ans.size()-1]-1]==p){
      ho=p;s.erase(p);s.insert(INF);
      p=*s.begin();if(p==INF)fin(-1);
      t=v[p-1];
    }
    if(s.count(t)&&m[t]+1==s.size()){
      s.erase(p);
      int q=t;
      ans.push_back(q);
      s.erase(q);
      if(--m[v[q-1]]==0)m.erase(v[q-1]);
      s.insert(p);
    }
    else{
      ans.push_back(p);
      s.erase(p);
      if(--m[t]==0)m.erase(t);
    }
    if(~ho){
      s.erase(INF);s.insert(ho);
    }
  }
  if(ans.size()<n)fin(-1);
  for(int p:ans)cout<<p<<" ";cout<<endl;
}


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

int main (){
  	ll X, Y;
      cin>>X>>Y;
    if(X==1&&Y==1){
        cout<<1000000<<endl;
    }
    else{
        ll Sum=0;
        if(X<=3){
            Sum += (4-X)*100000;
        }
        if(Y<=3){
            Sum += (4-Y)*100000;
        }
        cout<<Sum<<endl;
    }
}

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

using ll = long long;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
    ll n;
    std::cin >> n;
    std::vector<ll> T(n);
    for(int i = 0; i < n; i++){
        std::cin >> T[i];
    }

    // 例外処理
    if(n == 1){
        std::cout << T[0] << std::endl;
        return 0;
    }

    std::sort(T.begin(), T.end());    

    ll g = gcd(T[0], T[1]);
    ll lcm = (T[0] / g) * (T[1] / g) * g;
    for(int i = 2; i < n; i++){
        g = gcd(lcm, T[i]);
        lcm = (lcm / g) * (T[i] / g) * g;
    }

    std::cout << lcm << std::endl;
    return 0;
}


Measured memory_bytes: 256
S = list(input())
K = int(input())

if len(set(S)) == 1:
    print((len(S)*K)//2)
    exit()

def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x

print(n_change(S) + (K-1) * (n_change(2*S) - n_change(S)))

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        string a = Console.ReadLine();
        string b = Console.ReadLine();
        int i = 0;
        for (i = n; i > 0; i--)
        {
            if(a.EndsWith(b.Substring(0, i))) break;
        }
        Console.WriteLine(a.Length + b.Length - i);
    }
}

Measured memory_bytes: 3160
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

vi split(string s, char sep) {
	vi res;
	int a = 0;
	rep (i, s.size()) {
		if (s[i] == sep) {
			res.pb(a);
			a = 0;
		}
		else {
			a = a * 10 + s[i] - '0'; 
		}
	}
	if (s[s.size() - 1] != sep) res.pb(a);
	return res;
}

int main() {
	vector<vi> a;
	for(string s; getline(cin, s); ) a.pb(split(s, ','));
	int n = a.size() / 2;
	int dp[100][100];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = a[0][0];
	REP(i, 1, n) rep(j, i + 1) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]);
	REP(i, n + 1, a.size() - 1) rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
	cout << dp[a.size() - 1][0] << endl;
	
	return 0;
}

Measured memory_bytes: 0
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string n = readln.chomp;

    writeln(n.canFind('9') ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    ll n,k;cin >> n >> k;
    
    ll d = 1;
    int ans = 0;
    while(d <= n){
        d *= k;
        ans++;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
string s, t;
set <int> loc[26];
set <int>::iterator it;

int main() {
    cin >> s >> t;
    for (int i=0; i<s.length(); i++){
        loc[s[i]-'a'].insert(i);
    }
    for (char i : t){
        if (loc[i-'a'].empty()){
            cout << "-1\n";
            return 0;
        }
    }
    ll repeat = 0, idx = -1;
    for (char i : t){
        it = loc[i-'a'].upper_bound(idx);
        if (it == loc[i-'a'].end()){
            repeat++;
            it = loc[i-'a'].begin();
            idx = *it;
        } else {
            idx = *it;
        }
    }
    cout << repeat*s.size()+idx+1LL << endl;
    return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
using namespace std;
int main()
{
	int l,a,b,c,d,x,y;
	scanf("%d",&l);
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	x=0;
	y=0;
	x=a/c;
	y=b/d;
	if(a%c!=0)	x+=1;
	if(b%d!=0)	y+=1;
	if(x>y)	printf("%d\n",l-x);
	else	printf("%d\n",l-y);
	return 0;
}


Measured memory_bytes: 2708
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll k, q;std::cin >> k >> q;
  vll d(k); re(i, k) scanf("%lld", &d[i]);


  re(i, q){
    ll n, x, m;scanf("%lld %lld %lld", &n, &x, &m);
    x%=m;
    ll c = 0, now = 0;

    re(j, k) {
      ll tmp = d[j]%m;
      if(now >= (now+tmp)%m) c++;
      now = (now + tmp)%m;
    }

    c = c * ((n-1)/k);
    c += (now*((n-1)/k))/m;
    now = (now*((n-1)/k))%m;
    if(now+x>=m) c++;
    now = (now+x)%m;

    for(ll j=0;j<((n-1)%k);j++){
      ll tmp = d[j]%m;
      if(now >= (now+tmp)%m) c++;
      now = (now + tmp)%m;
    }
    std::cout << n - 1 - c << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
mo=10**9+7
n=int(input())
from collections import defaultdict
d=defaultdict(int)

for i in range(2,n+1):
    t=int(i**0.5+2)
    for j in range(2,t):
        while i%j==0:
            i//=j
            d[j]+=1
        if i==1:
            break
    if i>1:
        d[i]+=1
ans=1
for i in d.items():
    ans*=i[1]+1
    ans%=mo
print(ans)


Measured memory_bytes: 40304
S = input()
w = int(input())

newS = ""
if len(S) % w == 0:
    for i in range(len(S)//w):
        Si = S[i * w]
        newS += Si
else:
    for i in range(len(S)//w + 1):
        Si = S[i * w]
        newS += Si

print(newS)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int test[213456];
int par[213456];//親
int depth[213456];//木の深さ
//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
signed main() {
	int n, m, a, b, c, ans = 0; cin >> n;
	vector<vector<int> > G(n + 1);
	vector<vector<int> > D(n + 1); init(n);
	for (int h = 1; h < n; h++) {
		cin >> a >> b >> c;
		G[a].push_back(b); G[b].push_back(a);
		D[a].push_back(c); D[b].push_back(c);
		unite(a, b);
	}
	queue<int> que, mae, cnt; test[1] = 1;
	for (int i = 0; i < G[1].size(); i++) {
		que.push(G[1][i]); mae.push(1); cnt.push(D[1][i]);
		//cout << h << ' ' << G[1][i] << ' ' << D[1][i] << endl;
	}
	while (que.size()) {
		for (int i = 0; i < G[que.front()].size(); i++) {
			if (G[que.front()][i] != mae.front()) {
				que.push(G[que.front()][i]); mae.push(que.front()); cnt.push(cnt.front() + D[que.front()][i]);
				//cout << que.front() << ' ' << G[que.front()][i] << endl;
			}
		}
		if (cnt.front() % 2 == 0) { test[que.front()] = 1; }
		else { test[que.front()] = 2; }
		que.pop(); mae.pop(); cnt.pop();
	}
	for (int h = 1; h <= n; h++) {
		cout << test[h] - 1 << endl;
	}
}

Measured memory_bytes: 15616
data class Result(val concentration: Double, val total: Int, val sugar: Int)

fun main(args: Array<String>) {
    val list = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val a = list[0]
    val b = list[1]
    val c = list[2]
    val d = list[3]
    val e = list[4]
    val f = list[5]

    var result = Result(0.0, 0, 0)

    for (aw in 0..(f / (100 * a))) {
        for (bw in 0..(f / (100 * b))) {
            for (cs in 0..(f / c)) {
                for (ds in 0..(f / d)) {
                    val sugar = (cs * c) + (ds * d)
                    val water = (100 * a * aw) + (100 * b * bw)
                    if (water == 0) {
                        continue
                    }
                    if ((water + sugar) > f) {
                        continue
                    }
                    if ((sugar.toDouble() / water.toDouble()) > (e.toDouble() / 100.0)) {
                        continue
                    }
                    val concentration = calc(water, sugar)
                    if (concentration > result.concentration) {
                        result = Result(concentration, water + sugar, sugar)
                    }
                }
            }
        }
    }
    if (result.concentration == 0.0) {
        println("${100 * a} 0")
    } else {
        println("${result.total} ${result.sugar}")
    }
}

// 濃度計算
private fun calc(a: Int, b: Int):Double {
    if (b == 0) {
        return 0.0
    }
    return ((100 * b).toDouble()) / ((a + b).toDouble())
}

Measured memory_bytes: 37932
N = int(input())

a = 1
b = 1
c = 1

for i in range(N):
    a = a * 10 % (10**9+7)
    b = b * 9 % (10**9+7)
    c = c * 8 % (10**9+7)

print((a + c - 2 * b) % (10**9+7))

Measured memory_bytes: 9176
import sys

import math
# S = input()
# N, M = map(int, input().split())
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    R = int(input())

    print(2 * math.pi * R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9152
#include <stdio.h>

int linearSearch(int,int,int*);

int main() {
  int n, q, i, j, count = 0; 
  int s[10001], t;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i = 0;i < q;i++) {
    scanf("%d",&t);
    count += linearSearch(n,t,s);
  }
  printf("%d\n",count);
  
  return 0;
}

int linearSearch(int n,int key,int s[]) {
  int i=0;
  s[n] = key;
  while(s[i] != key) {
    i++;
  }
  if(i != n) return 1;
  else return 0;
}

Measured memory_bytes: 636
#include <stdio.h>

void swap(int *,int *);

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b) swap(&a,&b);
	if(b > c) swap(&b,&c);
	if(a > b) swap(&a,&b);
	printf("%d %d %d\n",a,b,c);
	return 0;
}

void swap(int *x,int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

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

int main() {
  string top;
  cin >> top;
  int res = 700;
  for (int i = 0; i < 3; i++) {
    if (top.at(i) == 'o') {
      res += 100;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
from itertools import product
n = int(input())
if n <= 356:
	print(0)
else:
	ans = 0
	shi_list = ["3", "5", "7"]
	shi_set = {"3", "5", "7"}
	for i in range(3, len(str(n))+1):
		for num in product(shi_list, repeat=i):
			x = int("".join(num))
			if x <= n and set(list(str(x))) & shi_set == shi_set:
				ans += 1
	print(ans)


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

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

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

int N, M, Q;
int a[55], b[55], c[55], d[55];
int A[15], ans = 0;

int Solve(){
  int now = 0;
  for (int i = 0; i < Q; i++){
    if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
  }
  ans = max(now, ans);
  return 0;
}

int DFS(int num, int turn){
  if (turn == N){
    Solve();
    return 0;
  }
  for (int i = num; i <= M; i++){
    A[turn + 1] = i;
    DFS(i, turn + 1);
  }
  return 0;
}

int main(){
  scanf("%d %d %d", &N, &M, &Q);
  for (int i = 0; i < Q; i++){
    scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
  }

  DFS(1, 0);
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 3816
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val matrix = Seq.fill(n, m)(sc.nextInt())
  val vector = Seq.fill(m)(sc.nextInt())

  println(matrix.map(e => multiply(e, vector)).map(e => e.sum).mkString("\n"))

  def multiply(row: Seq[Int], vector: Seq[Int]): Seq[Int] = (0 to row.size - 1).map(i => row(i) * vector(i))
}

Measured memory_bytes: 59420
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');

            int X = int.Parse (str[0]);
            int N = int.Parse (str[1]);

            str = Console.ReadLine ().Split (' ');

            int[] p = new int[100];
            for (int i = 0; i < N; i++)
            {
                p[i] = int.Parse (str[i]);
            }

            int ans = 0;

            for (int i = 0; i <= 101; i++)
            {
                bool flag = true;
                for (int j = 0; j < N; j++)
                {
                    if (p[j] == i)
                    {
                        flag = false;
                        break;
                    }
                }

                if (flag == false) continue;

                if (Math.Abs (i - X) < Math.Abs (ans - X))
                {
                    ans = i;
                }
            }

            Console.WriteLine (ans);

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 27488
#include <stdio.h>

int main()
{
  int inf[5][4][11]={0};
  int n,i,j,k,b,f,r,v;
 
  scanf("%d",&n);
 
  for(n;n>0;n--)
  {
	  scanf("%d %d %d %d",&b,&f,&r,&v);
	  inf[b][f][r]+=v;
  }
 
  for(i=1;i<5;i++)
  {
    for(j=1;j<4;j++)
	{
      for(k=1;k<11;k++)
	  {
		  printf(" %d",inf[i][j][k]);
      }
      
	  printf("\n");
	}

    if(i==4)
	{
		break;
	}
    
	printf("####################\n");
  }
  
  return 0;
}

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

using namespace std;
using lld = long long int;
using ll = pair<lld, lld>;

constexpr auto MAX_N { 100005 };

vector<ll> a(MAX_N);

lld f(lld l, lld r)
{
    return max(r - l + 1, 0LL);
}

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i].first >> a[i].second;
    }

    sort(begin(a) + 1, begin(a) + n + 1, [](ll a, ll b) -> bool
    {
        return a.second == b.second ? a.first > b.first : a.second < b.second;        
    });

    lld max_l = 0, min_r = 1LL << 40, idx_max_l = 1, idx_min_r = 1;
    for (int i = 1; i <= n; ++i)
    {    
        if (max_l < a[i].first)
        {
            max_l = a[i].first;
            idx_max_l = i;
        }

        if (min_r > a[i].second)
        {
            min_r = a[i].second;
            idx_min_r = i;
        }
    }

    lld max_length = 0, idx_max_length = 1;
    for (int i = 1; i <= n; ++i)
    {
        if (idx_max_l == i || idx_min_r == i)
        {
            continue;
        }

        lld length = f(a[i].first, a[i].second);
        if (max_length < length)
        {
            max_length = length;
            idx_max_length = i;
        }
    }

    lld ans = f(a[idx_max_l].first, a[idx_min_r].second) + f(a[idx_max_length].first, a[idx_max_length].second);
    for (int i = 2; i <= n; ++i)
    {
        ans = max(ans, f(a[idx_max_l].first, min(a[idx_max_l].second, a[i].second)) + f(max(a[i - 1].first, a[idx_min_r].first), a[idx_min_r].second));
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    long n,q;
    cin>>n>>q;
    long l,r;
    long i;
    string s;
    cin>>s;
    vector<pair<long,long> > sub(q);
    for(i=0;i<q;i++){
        cin>>l>>r;
        sub[i]=make_pair(l,r);
    }
    long a[100000];
    a[0]=0;
    long flag;
    for(i=0;i<n;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            flag=i;
            if(i==0){
               a[1]=1;
            }
            else{
               a[i]=a[i-1];
               a[i+1]=a[i]+1;
            }
        }
        else {
            if(flag!=i-1)
            a[i]=a[i-1];
        }
    }
    long ans;
    for(i=0;i<q;i++){
        ans=a[sub[i].second-1]-a[sub[i].first-1];
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3456
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var s = Console.ReadLine();
        int n = s.Count(x => char.IsLetter(x));
        var tournament = Node.Parse(s) as Tournament;
        int[] wins = new int[26];
        for (int i = 0; i < n; i++)
        {
            var av = Console.ReadLine().Split();
            var a = av[0][0] - 'a';
            var v = int.Parse(av[1]);
            wins[a] = v;
        }
        foreach (var person in tournament.People())
        {
            var win = wins[person.ID];
            var current = person as Node;
            for (int i = 0; i <= win; i++)
            {
                if (current == null || current.Winner != null) goto end;
                current.Winner = person;
                current = current.Parent;
            }
        }
        if (Node.Fixed(tournament)) 
        {
            Console.WriteLine("Yes");
            return;
        }
        
        end:;
        Console.WriteLine("No");
    }
}

class Node
{
    public Tournament Parent;
    public Person Winner;
    public static bool Fixed(Node node)
    {
        if (node is Person) return true;
        var tournament = node as Tournament;
        return tournament.Winner != null && Fixed(tournament.L) && Fixed(tournament.R);
    }
    public static Node Parse(string s)
    {
        if (!(s[0] == '[')) return new Person() { ID = s[0] - 'a' };
        var depth = 0;
        Node l = null;
        Node r = null;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '[') depth++;
            else if (s[i] == ']') depth--;
            else if (s[i] == '-' && depth == 1)
            {
                l = Parse(s.Substring(1, i - 1));
                r = Parse(s.Substring(i + 1, s.Length - i - 2));
            }
        }
        var res = new Tournament() { L = l, R = r };
        res.L.Parent = res;
        res.R.Parent = res;
        return res;
    }
}

class Tournament : Node
{
    public Node L;
    public Node R;
    public IEnumerable<Person> People()
    {
        IEnumerable<Person> l;
        if (L is Person) l = new[] { L as Person };
        else l = (L as Tournament).People();
        IEnumerable<Person> r;
        if (R is Person) r = new[] { R as Person };
        else r = (R as Tournament).People();
        return l.Concat(r);
    }
}

class Person : Node
{
    public int ID;
}




Measured memory_bytes: 20364
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int p[10000];
int c[500], e[500];
int dp[20000 + 1];

int main()
{	
	int m, n;
	scanf("%d %d", &m, &n);
	for (int i = 0; i < m; i++){
		scanf("%d", &p[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d %d", &c[i], &e[i]);
	}
	
	fill(dp + 1, dp + 20000 + 1, INF);
	for (int i = 0; i < n; i++){
		for (int j = 20000; j >= c[i]; j--){
			dp[j] = min(dp[j], dp[j - c[i]] + e[i]);
		}
	}
	for (int i = 20000; i > 0; i--){
		dp[i - 1] = min(dp[i - 1], dp[i]);
	}
	
	sort(p, p + m);
	reverse(p, p + m);
	
	int maxi = 0;
	int sum = 0;
	for (int i = 0; i < m; i++){
		sum += p[i];
		maxi = max(maxi, sum - dp[i + 1]);
	}
	printf("%d\n", maxi);
	
	return 0;
}

Measured memory_bytes: 1324
#include<iostream>
#include<string>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,a,b,c,d,s;
    char field[200010];
    cin>>n>>a>>b>>c>>d;
    for (int i = 0; i < 200000; ++i) {
        field[i] = '@';
    }
    int two_rocks = 0;
    int can_jump = 0;
    char prev = '@';
    char prevprev = '@';
    for (int i = 1; i < n+1; ++i) {
        cin>>field[i];
        if (field[i] == '#') {
            if (prev == '#') {
                if ((a<i && i<c) || (b<i &&i<d)) two_rocks = 1;
            }
        }
        else {
            if (b<i && i<=d+1) {
                if (prevprev == '.' && prev == '.') {
                    can_jump = 1;
                }
            }
        }
        prevprev = prev;
        prev = field[i];
    }

    if (two_rocks) cout<<"No"<<endl;
    else {
        if (c<d) cout<<"Yes"<<endl;
        else {
            if (can_jump) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }

    return 0;
}


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

/* 
 * g++ -std=c++17 main.cpp -o main
 */
int main() {
  ios::sync_with_stdio(false);
  int n, l;
  cin>>n>>l;
  vector<string> strs(n);
  for(int i = 0; i < n; i++) {
    string s;
    cin>>s;
    strs[i] = s;
  }

  sort(strs.begin(), strs.end());
  string total = "";
  for (auto s : strs)
    total += s;
  cout << total;
  cout << endl;
}


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

int main(void){
	int a, b, c, x;
	int coin[] = { 500, 100, 50 };
	int sum = 0, ans = 0;

	cin >> a >> b >> c >> x;

	for (int i = 0; i <= a; i++){
		for (int j = 0; j <= b; j++){
			for (int k = 0; k <= c; k++){
				sum += coin[0] * i + coin[1] * j + coin[2] * k;
				if (sum == x) ans++;
				sum = 0;
			}
		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))
MOD = 998244353

dp = [[0]*(K+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    x = X[i]
    for j in range(K+1):
        dp[i+1][j] = 2*dp[i][j]
        if j-x>=0:
            dp[i+1][j] += dp[i][j-x]
        dp[i+1][j] %= MOD
print(dp[-1][-1])


Measured memory_bytes: 135364
#include<stdio.h>
#include<string.h>

int main(){
  char str[3];
  scanf("%s",str);
  
  if(strcmp(str,"AAB")==0 || strcmp(str,"ABA")==0 || strcmp(str,"BAB")==0 || strcmp(str,"BBA")==0 || strcmp(str,"ABB")==0 || strcmp(str,"BAA")==0){
    
     
    printf("Yes");
  }else{
    printf("No");
  }}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; int a[50]; cin >> n;
	ll ma = 0; int chk = 0;
	rep(i, n) {
		cin >> a[i];
		if (abs(a[i]) > abs(ma)) {
			ma = a[i]; chk = i;
		}
	}
	int cnt = 0;
	queue<P>out;
	if (ma >= 0) {
		rep(i, n) {
			if (i != chk) {
				cnt++; out.push({ chk + 1,i + 1 });
			}
		}
		rep(i, n - 1) {
			cnt++; out.push({ i + 1,i + 2 });
		}
	}
	else {
		rep(i, n) {
			if (i != chk) {
				cnt++; out.push({ chk + 1,i + 1 });
			}
		}
		per(i, n - 1) {
			cnt++; out.push({ i + 2,i + 1 });
		}
	}
	cout << cnt << endl;
	while(!out.empty()) {
		P nex = out.front(); out.pop();
		cout << nex.first << " " << nex.second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll x,y,z;
    cin>>x>>y>>z;
    ll val,val1;
    val=z/x;
    val1=val*y;
    cout<<val1<<endl;
}


Measured memory_bytes: 3624