akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll t; 
    //cin>>t;
    t=1;
    while(t--){
        ll n; cin>>n;
        ll arr[n][3];
        rep(i,0,n-1){
            rep(j,0,2){
                cin>>arr[i][j];
            }
        }
        ll a,b,c;
        a = arr[0][0];
        b = arr[0][1];
        c = arr[0][2];
        rep(i,1,n-1){
            ll temp1=a,temp2=b,temp3=c;
            a = arr[i][0] + max(temp2,temp3);
            b = arr[i][1] + max(temp1,temp3);
            c = arr[i][2] + max(temp1,temp2);
        }
        ll ans = max(a,max(b,c));
        cout<<ans;
    }
}


Measured memory_bytes: 2560
n,k = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
T = []
for i in range(k+1):
    if i <= n:
        for a in range(i+1):
            L = V[0:a]+V[n-i+a:n]
            L.sort()
            cur = sum(L)
            for b in range(k-i):
                if b < len(L):
                    if L[b] < 0:
                        cur -= L[b]
            if cur > ans:
                ans = cur
    else:
        L = V
        L.sort()
        cur = sum(L)
        for b in range(k-i):
            if b < len(L):
                if L[b] < 0:
                    cur -= L[b]
        if cur > ans:
            ans = cur
print(ans)

Measured memory_bytes: 3064
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{	
	int n;
	cin >> n;
	map<string, int> j;
	V<string> js{ "AC", "WA", "TLE", "RE" };
	j["AC"] = 0;
	j["WA"] = 0;
	j["TLE"] = 0;
	j["RE"] = 0;
	REP(i, n) {
		string s;
		cin >> s;
		j[s]++;
	}

	RBF(ji, js) {
		cout << ji << " x " << j[ji] << endl;
	}


	return 0;
}


Measured memory_bytes: 3660
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val s = sc.next()


    var set = mutableSetOf("AKIHABARA")

    while (true) {
        val next = mutableSetOf<String>()
        next.addAll(set)
        for (x in set) {
            for (j in 0 until x.length) {
                if (x[j] == 'A') next.add(x.removeRange(j..j))
            }
        }
        if(next.size == set.size) break
        set = next
    }

    println(if(set.contains(s)) "YES" else "NO")

}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 33988
import java.math.BigInteger

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map(String::toInt)
    val aSum = aList.sum()
    var dpTable = BigInteger.ONE
    for (a in aList) {
        dpTable = dpTable.or(dpTable.shiftLeft(a))
    }
    for (x in (((aSum + 1) / 2)..aSum)) {
        if (dpTable.testBit(x)) {
            println(x)
            return
        }
    }
}

Measured memory_bytes: 117980
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int a,b;
    int arr[4];
    rep(i,4)arr[i]=0;

    rep(i,3){
        cin >> a >> b;
        a--;b--;
        arr[a]++;
        arr[b]++;
    }
    int two,one;
    rep(i,4){
        if(arr[i]==0 || arr[i] == 3){ 
            cout << "NO" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
import numpy as np
n=input()
n=int(n)
a=input().split()
b=np.zeros(n)
div=0
num_8=0
for i in range(n):
 a[i]=int(a[i])
 if a[i]<=399 and a[i]>=1:
  b[i]=0
 elif a[i]>=400 and a[i]<=799:
  b[i]=1
 elif a[i]>=800 and a[i]<=1199:
  b[i]=2
 elif a[i]>=1200 and a[i]<=1599:
  b[i]=3
 elif a[i]>=1600 and a[i]<=1999:
  b[i]=4
 elif a[i]>=2000 and a[i]<=2399:
  b[i]=5
 elif a[i]>=2400 and a[i]<=2799:
  b[i]=6
 elif a[i]>=2800 and a[i]<=3199:
  b[i]=7
 else:
  b[i]=8
  num_8=num_8+1
for i in range(8):
 if i in b:
  div=div+1
min=div
max=div+num_8
if min==0:
 min=1
print(min,max)

Measured memory_bytes: 12488
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
al = 0
bb = 0
a.sort{|a,b|b<=>a}.each.with_index do |d, i|
  if(i % 2 == 0)
    al += d
  else
    bb += d
  end
end
p al - bb

Measured memory_bytes: 1788
S = input()

total = 0

for m in range(1 << len(S) - 1):
  acm = ''
  for i, c in enumerate(S):
    acm += c
    if 1 << i & m:
      total += int(acm)
      acm = ''
  if acm:
    total += int(acm)
    
print(total)    
    

Measured memory_bytes: 39920
#include<iostream>
#include<string>
using namespace std;
int main(){
	int as[1234],n;
	string A;getline(cin,A);
	for(int i=0;i<A.size();i++){
        if(A[n]=='\n')break;
        as[n]=A[n];
        if(as[n]/32==2){
            as[n]+=32;
            cout<<(char)as[n];
        }
        else if(as[n]/32==3){
            as[n]-=32;
            cout<<(char)as[n];
        }
        else{
            cout<<A[n];
        }
		n++;
	}
	cout<<endl;
}



Measured memory_bytes: 3176
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int N,M,P,sum,winner;
	
	while(cin>>N>>M>>P){
		if(N==0 && M==0 && P==0){
			break;
		}
		
	    sum=0;
	    winner=0;
		for(int i=1;i<=N;i++){
			int temp=0;
			cin>>temp;
			if(M==i){
				winner=temp;
			}
			sum=sum+temp;
		}
		
		
		if(winner!=0){
			sum=(sum*(100-P))/winner;
			printf("%d\n",sum);
		}
		else{
			printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string A;

int main(){
  cin >> A;
  ll l = A.size();

  map<char, ll> mp;
  REP(i, l) {
    mp[A[i]]++;
  }

  ll ans = l * (l - 1) / 2 + 1;

  char c = 'a';
  REP(i, 26) {
    ans -= mp[c] * (mp[c] - 1) / 2;
    c = char(c + 1);
  }

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



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

int main(){
  string s;
  cin >> s;
  string res = "No";
  if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])){
    res = "Yes";
  }
  cout << res;
}

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair


int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n, k;
	while (cin >> n >> k) {
		vi a(n);
		for (int i = 0; i < n; ++i) cin >> a[i];
		sort(a.begin(), a.end());
		vb memo (k+1, false);
		for (int i = 0; i < k and memo[k] != 1; ++i) {
			for (auto x : a) {
				if(i + x > k) break;
				memo[i + x] = memo[i + x] or not memo[i];
			}
		}
		cout << (memo[k]? "First" : "Second") << '\n';
	}
}




Measured memory_bytes: 256
a, b, k = map(int, input().split())

if a >= k:
  c = a-k
  e = "{0} {1}".format(c, b)
  print(e)
  
elif a < k <= a + b:
  c = b + a - k
  e = "{0} {1}".format(0, c)
  print(e)

else:
  print('0' +' ' +  '0')




Measured memory_bytes: 9152
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let chars: Vec<char> = buf.trim().chars().collect();

    println!("{}", solve(chars));
}

fn solve(mut chars: Vec<char>) -> i64{
    let mut index = 0;
    let mut result:i64 = 0;
    let mut c_counter = 0;
    chars.reverse();
    for char in chars {
        if char == 'B'{
            result += index - c_counter;
            c_counter += 1;
        }
        index += 1;
    }

    result
}

Measured memory_bytes: 4352
#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>;
bool check_bingo(vector<vector<P>> &A) {
    rep(i, 3) {
        bool tate_ok = true, yoko_ok = true;
        rep(j, 3) {
            if(!A.at(i).at(j).second) tate_ok = false;
            if(!A.at(j).at(i).second) yoko_ok = false;
        }
        if (tate_ok || yoko_ok) return true;
    }
    if (A.at(0).at(0).second && A.at(1).at(1).second && A.at(2).at(2).second) return true;
    if (A.at(0).at(2).second && A.at(1).at(1).second && A.at(2).at(0).second) return true;
    return false;
}
int main (void) {
    vector<vector<P>> A(3, vector<P>(3));
    rep(i, 3) {
        rep(j, 3) {
            cin >> A.at(i).at(j).first;
            A.at(i).at(j).second = 0;
        }
    }
    int N;
    cin >> N;
    rep(i, N) {
        int b;
        cin >> b;
        rep(j, 3) {
            rep(k, 3) {
                if(b == A.at(j).at(k).first) A.at(j).at(k).second = 1;
            }
        }
    }
    
    
    cout << (check_bingo(A) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n;
  string sa,sd;
  int fa,fd;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> sa >> sd;
    fa = 0;
    fd = 0;
    for(int j=0;j<sa.length();j++){
      if(sa[j] == 'm')
	{
	  if( 2 <= sa[j-1]-'0' && sa[j-1]-'0' <= 9)
	    {
	      fa += 1000*(sa[j-1]-'0');
		continue;
	    }
	  fa += 1000;
	} 
      if(sa[j] == 'c')
	{
	  if( 2 <= sa[j-1]-'0' && sa[j-1]-'0' <= 9)
	    {
	      fa += 100*(sa[j-1]-'0');
		continue;
	    }
	  fa += 100;
	} 
      if(sa[j] == 'x')
	{
	  if( 2 <= sa[j-1]-'0' && sa[j-1]-'0' <= 9)
	    {
	      fa += 10*(sa[j-1]-'0');
		continue;
	    }
	  fa += 10;
	} 
      if(sa[j] == 'i')
	{
	  if( 2 <= sa[j-1]-'0' && sa[j-1]-'0' <= 9)
	    {
	      fa += 1*(sa[j-1]-'0');
		continue;
	    }
	  fa += 1;
	} 
    }
 for(int j=0;j<sd.length();j++){
      if(sd[j] == 'm')
	{
	  if( 2 <= sd[j-1]-'0' && sd[j-1]-'0' <= 9)
	    {
	      fd += 1000*(sd[j-1]-'0');
		continue;
	    }
	  fd += 1000;
	} 
      if(sd[j] == 'c')
	{
	  if( 2 <= sd[j-1]-'0' && sd[j-1]-'0' <= 9)
	    {
	      fd += 100*(sd[j-1]-'0');
		continue;
	    }
	  fd += 100;
	} 
      if(sd[j] == 'x')
	{
	  if( 2 <= sd[j-1]-'0' && sd[j-1]-'0' <= 9)
	    {
	      fd += 10*(sd[j-1]-'0');
		continue;
	    }
	  fd += 10;
	} 
      if(sd[j] == 'i')
	{
	  if( 2 <= sd[j-1]-'0' && sd[j-1]-'0' <= 9)
	    {
	      fd += 1*(sd[j-1]-'0');
		continue;
	    }
	  fd += 1;
	} 
    }
 int ff = fa+fd;    
 char ch[20000];
 sprintf(ch,"%d",ff);
 string s;
 string ans;
 s.append(ch);
 for(int i=0;i<s.length();i++){
   if(s[i]-'0' == 0){
continue;
   }
   else if(2 <= s[i]-'0' && s[i]-'0' <= 9){
     cout << s[i];
   }
   if(s.length() == 4){
     if(i == 0)cout << 'm';
     else if(i == 1)cout << 'c';
     else if(i == 2)cout << 'x';
     else if(i == 3)cout <<'i';
   }
   else if(s.length() == 3){
     if(i == 0)cout << 'c';
     else if(i == 1)cout << 'x';
     else if(i == 2)cout <<'i';
   }
 else if(s.length() == 2){
     if(i == 0)cout << 'x';
     else if(i == 1)cout <<'i';
   }
 else if(s.length() == 1){
    cout <<'i';
   }
 }cout << endl; 
  }
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> l(N + 1), b(N);
  for (int i = 0; i <= N; i++) {
    cin >> l[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    int x = min(l[i], b[i]);
    ans += x;
    if (b[i] - x > 0){
      int y = min(b[i] - x, l[i+1]);
      ans += y;
      l[i+1] -= y;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    int sum = 0;
    for (int i = 0; i < 3; i++){
        if (s[i] == '1'){
            sum++;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int main()
{
	ll a, b;
	string sa, sb;
	cin >> a >> b >> sa >> sb;
	ll g = gcd(a, b);
	string za, zb;
	for (int i = 0; i < sa.size(); i += a / g)za.push_back(sa[i]);
	for (int i = 0; i < sb.size(); i += b / g)zb.push_back(sb[i]);
	if (za != zb)printf("-1\n");
	else printf("%lld\n", a*b / g);
}

Measured memory_bytes: 512
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	var n int
	fmt.Scan(&n)

	bp := big.NewInt(1)
	for i := 1; i <= n; i++ {
		bi := big.NewInt(int64(i))
		bp = bp.Mul(bp, bi)
	}
	bn := big.NewInt(int64(math.Pow(10, 9)) + 7)
	res := bp.Mod(bp, bn)
	fmt.Println(res)
}


Measured memory_bytes: 7680
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	biga := big.NewInt(int64(a))
	bigb := big.NewInt(int64(b))

	gcd := new(big.Int).GCD(nil, nil, biga, bigb)
	prod := new(big.Int).Mul(biga, bigb)
	ans := new(big.Int).Quo(prod, gcd)

	fmt.Println(ans.String())
}


Measured memory_bytes: 640
// C - 4-adjacent
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

bool solve(int N, vi &A){
	int c2 = 0, c4 = 0;
	rp(i, 0, N){
		if(A[i]%4 == 0) c4++;
		else if(A[i]%2 == 0) c2++;
	}
	return N/2 <= c4 + c2/2;
}

int main(){
	int N; cin>>N;
	vi A(N); rp(i, 0, N) cin>>A[i];
	cout<< (solve(N, A)? "Yes":"No") <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
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; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    string s;
    cin >> s;
    for range(i,s.size()){
        if (i%2==0){
            cout <<s[i];
        }
    }cout << endl;
}

Measured memory_bytes: 512
//MST
#if 0

#endif // 0
#include<iostream>
#include<vector>
#include<algorithm>
#define MAX 10010
using namespace std;
vector<int> s;
int root(int x)
{
    if(s[x]==x)return x;
    return root(s[x]);
}

int main()
{
    int cost[MAX],src[MAX],dst[MAX];
    pair<int,int> pos[MAX];
    int n,sum=0;
    cin>>n;
    s.resize(n);
    for(int i=0;i<n;i++)
    {
        s[i]=i;
    }
    int m=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            int a;
            cin>>a;
            if(a>=0&&j>i)
            {
                cost[m]=a;
                src[m]=i;
                dst[m]=j;
                pos[m].first=cost[m];
                pos[m].second=m;
                m++;
            }
        }
    }
    sort(pos,pos+m);
    int c=0;
    for(int i=0;i<m;i++)
    {
        int d=pos[i].second;
        if(root(src[d])!=root(dst[d]))
        {
            sum+=cost[d];
            s[root(src[d])]=root(dst[d]);
            c++;
        }
        if(c>=n-1)
            break;
    }

    cout<<sum<<endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef pair <ll, ll> dll;
typedef vector <ii> vii;
typedef vector <vi> graph;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
	string s;
    cin >> s;
    int n = s.size();
    stack <char> pila;
    int cont = 0;
    for (int i = 0; i < n; ++i)
    {
    	if (pila.empty() || s[i] == pila.top()) {
    		pila.push(s[i]);
    	} else {
    		pila.pop();
    		cont += 2;
    	}
    }
    cout << cont << "\n";
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int f = -1;
  rep(i, n-1){
    if(a.at(i) + a.at(i+1) >= l) f = i+1;
  }
  if(f != -1){
    cout << "Possible" << endl;
    rep2(i, 1, f) cout << i << endl;
    rrep2(i, f, n) cout << i << endl;
  }else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 3764
h, w = map(int, input().split())
a = [list(input().split()) for _ in range(h)]
for i in a:
  i.insert(0, '#')
  i.append('#')
a.insert(0, ['#']*(w+2))
a.append(['#']*(w+2))
for i in a:
  print(''.join(i))

Measured memory_bytes: 9148
n = int(input())						# 5
A = list( map(int, input().split()) )	# 1 2 3 4 5 ...

count=0
j=0
for i in range(n-1):
	if A[i]==A[i+1]:
		j += 1
	else:
		count += (j+1)//2
		j=0

count += (j+1)//2

print(count)


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}
	box := make([]int, N)
	count := 0
	for i := N - 1; i >= 0; i-- {
		for j := i; j < N; j += (i + 1) {
			box[i] ^= box[j]
		}
		box[i] ^= a[i]
		if box[i] == 1 {
			count++
		}
	}
	fmt.Fprint(out, count, "\n")
	for i := 0; i < N; i++ {
		if box[i] == 1 {
			fmt.Fprint(out, (i + 1))
			if i != N-1 {
				fmt.Fprint(out, " ")
			}
		}
	}
	// 1 0 0
	// i=1, 1 = (b[1]+b[2]+b[3])%2
	// i=2, 0 = (b[2])%2
	// i=3, 0 = (b[3])%2
	// x x x x x x
	//   x   x   x
	//     x     x
	//       x
	//         x
	//           x
}

func solve(N int, a []int, used []int, s2, x1, x2, depth int) bool {
	// fmt.Fprint(out, used, depth, x1, x2, "\n")
	if depth == N {
		// fmt.Fprint(out, "atta\n")
		return x1^x2^a[0] == 0 && x2^a[0]^s2 == 0
	}
	for i := 0; i < N; i++ {
		if used[i] > 0 {
			continue
		}
		if depth >= 2 && x1^x2^a[i] != 0 {
			continue
		}
		used[i] = 1
		if depth == 1 {
			s2 = a[i]
		}
		if solve(N, a, used, s2, x2, a[i], depth+1) {
			return true
		}
		used[i] = 0
	}
	return false
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 6144
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

string N; //　10 進法で高々 100 桁
int K;

ll dp[100][4][2];
ll solve(int n, int nokori, int pitari){
	if(nokori < 0) return 0LL;
	if(n == N.size()){
		if(nokori == 0) return 1LL;
		else return 0LL;
	}
	if(dp[n][nokori][pitari] != -1) return dp[n][nokori][pitari];
	ll ret = 0LL;
	if(pitari == 1 && N[n]-'0' == 0) ret += solve(n+1, nokori, 1);
	else ret += solve(n+1, nokori, 0);
	for(int i=1; i<10; i++){
		if(pitari == 1 && N[n]-'0' < i) continue;
		if(pitari == 1 && N[n]-'0' == i) ret += solve(n+1, nokori-1, 1);
		else ret += solve(n+1, nokori-1, 0);
	}
	return dp[n][nokori][pitari] = ret;
}

// 0 でない数字が K 個
signed main(){
	cin >> N >> K;
	memset(dp, -1, sizeof(dp));
	cout << solve(0, K, 1) << endl;
}

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

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;

	int ans = -1;
	int nth = 0;

	for (int i = min(a, b); i > 0; i--) {
		if (a % i == 0 && b % i == 0) {
			k--;
			if (k == 0) {
				ans = i;
				break;
			}
		}

	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    string a,b;
    int ca = 0,cb = 0;
    cin >> a >> b;

    rep(i, a.size() + b.size()){
        if(i % 2 == 0){
            cout << a[ca];
            ca++;
        }
        else{
            cout << b[cb];
            cb++;
        }
    }
    cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MON 1000000007
#define INF (1<<29)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

class Edge{
public:
  int from, to, rev;
  Int cost, lim;
  Edge(int from, int to, Int cost, int lim = -1, Int rev = -1):
    from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
  int n;
  int m;
  vector<vector<Edge>> edge;
  Graph(int n = 0):n(n),m(0){
    edge = vector<vector<Edge>>(n);
  }
  void add_edge(int from, int to, int cost = 1, int lim = -1)
  {
    if(lim == -1){
      edge[from].push_back(Edge(from, to, cost));
      return;
    }
    edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
    edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
  }
};

Graph g;

vector<int> dep(108000);

void dfs(int x, int last = -1){
  if(last == -1){
    dep[x] = 0;
  }
  for(auto e:g.edge[x]){
    if(e.to == last)continue;
    dep[e.to] = dep[x] + e.cost;
    dfs(e.to, x);
  }
}
int n, s, t, w;
int main(){
  cin >> n;
  g = Graph(n);
  for(int i = 0;i < n-1;i++){
    cin >> s >> t >> w;
    g.add_edge(s, t, w);
    g.add_edge(t, s, w);
  }
  
  int l = 0;
  dfs(l);
  for(int i = 0;i < n;i++)
    if(dep[l] < dep[i])swap(l,i);
  dfs(l);
  cout << *max_element(dep.begin(), dep.end()) << endl;
  return 0;
}


Measured memory_bytes: 18072
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N);
  vi a(N); in(a);
  map<int,int> m;
  each(x , a){
    if(m[x] == 1) die("NO");
    m[x]++;
  }
  out("YES");
}

Measured memory_bytes: 10368
N = int(input())
A = list(map(int, input().split())) 

manzoku = 1
hakai = 0

for i in range(N):
  if A[i] == manzoku:
    manzoku += 1
  else:
    hakai += 1

if hakai == N: 
  print(-1)
else:
  print(hakai)

Measured memory_bytes: 32328
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[200000][3];
int main()
{
	int num;
	scanf("%d", &num);
	ll now = 0;
	for (int i = 0; i < 200000; i++)dp[i][0] = dp[i][1] = dp[i][2] = -1000000000000000000LL;
	int zt;
	scanf("%d", &zt);
	dp[0][0] = zt;
	for (int i = 1; i < num; i++)
	{
		char za;
		int zb;
		scanf(" %c%d", &za, &zb);
		if (za == '+')
		{
			dp[i][0] = max(dp[i][0], dp[i - 1][0] + zb);
			dp[i][1] = max(dp[i][1], dp[i - 1][1] - zb);
			dp[i][2] = max(dp[i][2], dp[i - 1][2] + zb);
			dp[i][0] = max(dp[i][0], dp[i - 1][1] - zb);
			//dp[i][0] = max(dp[i][0], dp[i - 1][2] + zb);
			dp[i][1] = max(dp[i][1], dp[i - 1][2] + zb);
		}
		else
		{
			dp[i][0] = max(dp[i][0], dp[i - 1][0] - zb);
			dp[i][1] = max(dp[i][1], dp[i - 1][1] + zb);
			dp[i][2] = max(dp[i][2], dp[i - 1][2] - zb);
			dp[i][1] = max(dp[i][1], dp[i - 1][0] - zb);
			dp[i][2] = max(dp[i][2], dp[i - 1][1] + zb);
			//dp[i][2] = max(dp[i][2], dp[i - 1][0] - zb);
			dp[i][0] = max(dp[i][0], dp[i - 1][1] + zb);
			//dp[i][0] = max(dp[i][0], dp[i - 1][2] - zb);
			dp[i][1] = max(dp[i][1], dp[i - 1][2] - zb);
		}
	}
	printf("%lld\n", max(dp[num - 1][0], max(dp[num - 1][1], dp[num - 1][2])));
}

Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int dp[100100];

int main()
{
    int n; cin >> n;
    for(int i = 0; i < 100100; i++){
        dp[i] = inf;
    }
    dp[0] = 0;
    for(int i = 0; i <= n; i++){
        for(int six = 1; i + six <= n; six *= 6){
            dp[i+six] = min(dp[i+six],dp[i]+1);
        }
        for(int nine = 1; i + nine <= n; nine *= 9){
            dp[i+nine] = min(dp[i+nine],dp[i]+1);
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");

typedef long long ll;
typedef long double ld;

void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int flag = 0;
    while(a >= 0 && c >= 0){
        c -= b;
        if(c <= 0){
            flag = 1;
            break;
        }
        a -= d;
        if(a <= 0){
            flag = 0;
            break;
        }
    }
    cout << (flag == 0 ? "No\n" : "Yes\n");
    return;
}
 
int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

# 個数制限なしナップサック問題
W,N = map(int,readline().split())

dp = [INF for j in range(W+1)]
dp[0] = 0

for i in range(N):
    w,v = map(int,readline().split())
    # dp[j] = 重さj以下でつくれる最大の価値
    for j in range(W+1):
        dp[j] = min(dp[j],dp[max(j-w,0)] + v)

print(dp[W])


Measured memory_bytes: 74880
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>



using namespace std;

int main(void) {

	int a[200010] = {};
	unsigned long long int visited[200010];
	int n;
	unsigned long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		visited[i] = -1;
	}
	int b = 1;
	visited[1] = 0;
	for (unsigned long long int i = 1; i <= k; i++){
		b = a[b];
		if (visited[b] != -1) {
			k -= i;
			k %= (i - visited[b]); 
			
			while (k--) {
				b = a[b];
			}
			break;
		}
		visited[b] = i;
		
	}



	cout << b << endl;

	return 0;
}

Measured memory_bytes: 5960
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,q;
	vector<long long> S(n);
	long long T;
	cin >> n;
	int roop;
	for(roop=0;roop<n;roop++){
		cin >> S[roop];
	}
	int roop2,count=0;
	sort(S.begin(),S.end());
	S.erase(unique(S.begin(),S.end()),S.end());
	n=(int)S.size();
	cin >> q;
	for(roop=0;roop<q;roop++){
		cin >> T;
		for(roop2=0;roop2<n;roop2++){
			if(S[roop2]!=T){
				continue;
			}else{
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 35372
s = input()
ans = []
for i in range(len(s)):
    if s[i] == "A":
        j = i
        break
for i in range(len(s)):
    if s[len(s)-i-1] == "Z":
        k = len(s)-i-1
        break
ans = k-j+1
print(ans)

Measured memory_bytes: 3516
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const a = arg[1].split(" ").map(n=>parseInt(n));
    
    const mapArray = [...Array(100000)].fill(0);
    
    for(let val of a) {
        mapArray[val]++;
        if(val > 0)     mapArray[val-1]++;
        if(val < 99999) mapArray[~~val+1]++;
    }
    
    console.log(Math.max(...mapArray));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 30460
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n;
    cin>>n;
    vector <ll> a(n+1);
    rep(i,n+1)
    cin>>a[i];
    vector <ll> suf(n+2);
    for (int i=n;i>=0;i--)
        suf[i]=suf[i+1]+a[i];
    ll was=1;
    ll ans=0;
    for (int i=0;i<n+1;i++)
    {
        //cout<<i<<" "<<was<<" "<<suf[i+1]<<'\n';
        if (a[i]>was)
        {
         //   cout<<i<<" "<<was<<'\n';
            cout<<-1;
            return 0;
        }
        else
        {
            ll wass=was;
            if (suf[i+1]>=(was-a[i])*2)
            {
                ans+=was;
                was=2*(was-a[i]);
               // cout<<i<<" "<<was<<'\n';
            }
            else
            {
                ans+=was;
                was=suf[i+1];
            }
            //was=max(was,wass-a[i]);
        }
    }
    cout<<ans;



}

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

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

    while(1){
        C = C - B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }
        A = A - D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

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

const int INF=100100100;
const int di[]={-1,0,1,0};
const int dj[]={0,-1,0,1};


int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h){
        cin >> s[i];
    }
    int ans=0;
    rep(si,h)rep(sj,w){
        if(s[si][sj]=='#') continue;
        vector<vector<int>> dist(h,vector<int>(w,INF));
        queue<P> q;
        auto update=[&](int i,int j,int x){
            if(dist[i][j]!=INF) return; //もう来ている頂点
            dist[i][j]=x;
            q.push(P(i,j));
        };
        update(si,sj,0); //始点
        while(!q.empty()){
            int i=q.front().first;
            int j=q.front().second; q.pop();
            rep(dir,4){ 
                int ni=i+di[dir],nj=j+dj[dir]; //近接点の調査
                if(ni<0||ni>=h||nj<0||nj>=w) continue;
                if(s[ni][nj]=='#') continue;
                update(ni,nj,dist[i][j]+1);
            }
        }
        rep(i,h)rep(j,w){
            if(dist[i][j]==INF) continue;
            ans=max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
a = 0 < int(S[:2]) < 13
b = 0 < int(S[2:]) < 13

if a and b:
    print("AMBIGUOUS")
if a and not b:
    print("MMYY")
if not a and b:
    print("YYMM")
if not a and not b:
    print("NA")


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

using namespace std;

#define all(v)   v.begin(), v.end()
#define sz(x)    (int) (x.size())
#define Unique(x) x.erase(unique(all(x)), x.end())
#define endl "\n"
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE
#define MOD 1000000007
#define EPS 1e-7


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


int main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("test cases\\in.txt", "r", stdin);
    //freopen("test cases\\in.txt", "w", stdout);
    int n, m; cin>>n>>m;
    string s; cin>>s;
    ll cnt = 0;
    if(m == 2 || m == 5){
        for(int i = 0; i<n; i++){
            if((s[i] - '0') % m == 0) cnt += i + 1;
        }
        cout<<cnt;
        return 0;
    }
    int po10 = 1, suff =0;
    vector<int> mp(m);
    mp[suff]++;

    for(int i = n-1; ~i; i--){
        int dig = s[i] - '0';
        suff = (suff + dig * po10%m)%m;
        po10 = (po10 * 10)% m;
        cnt += mp[suff];
        mp[suff]++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 720
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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 getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make(AA, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	sort.Sort(aa)

	cm := Com{}
	cm.init(n)

	var mx, mn int64

	for i := 0; i < n; i++ {
		mn += (aa[i] * cm.calc(n-i-1, k-1)) % cm.mod
		mn %= cm.mod
	}
	for i := 0; i < n; i++ {
		mx += (aa[n-1-i] * cm.calc(n-1-i, k-1)) % cm.mod
		mx %= cm.mod
	}
	fmt.Fprintln(writer, ((mx-mn)%cm.mod+cm.mod)%cm.mod)
}

type AA []int64

func (a AA) Len() int           { return len(a) }
func (a AA) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a AA) Less(i, j int) bool { return a[i] < a[j] }

// Com ...
type Com struct {
	facs, invs []int64
	mod        int64
}

func (cm *Com) init(n int) {
	cm.facs = make([]int64, n+1)
	cm.invs = make([]int64, n+1)

	cm.facs[0] = 1
	cm.mod = int64(1e9 + 7)
	for i := 1; i <= n; i++ {
		cm.facs[i] = (cm.facs[i-1] * int64(i)) % cm.mod
	}
	cm.invs[n] = cm.inv(cm.facs[n])
	for i := n - 1; i >= 0; i-- {
		cm.invs[i] = cm.invs[i+1] * int64(i+1) % cm.mod
	}
}

func (cm *Com) inv(n int64) int64 {
	var ii [32]int64
	ii[0] = n
	for i := 1; i < 31; i++ {
		ii[i] = (ii[i-1] * ii[i-1]) % cm.mod
	}
	var ans int64
	ans = 1
	m := cm.mod - 2
	for i := 30; i >= 0; i-- {
		for m >= 1<<uint(i) {
			ans = (ans * ii[i]) % cm.mod
			m -= 1 << uint(i)
		}
	}

	return ans
}

func (cm *Com) calc(n, k int) int64 {
	if n < k {
		return 0
	}
	ans := cm.facs[n] * cm.invs[k]
	ans %= cm.mod
	ans = ans * cm.invs[n-k]
	ans %= cm.mod
	return ans
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // Initialize
          	var intN = cin.ReadInt;
          	var intY = cin.ReadInt;
          	var ansI = -1 ;
          	var ansJ = -1 ;
            var ansK = -1 ;
            // Process
			for(int i = 0 ; i <= intN ; i ++ )
            {
            	for(int j = 0 ; i + j <= intN ; j ++)
                {
                	int k = intN - i - j ;
                  	if(10000*i + 5000*j + 1000*k == intY)
                    {
                    	ansI = i ;
                      	ansJ = j ;
                      	ansK = k ;
                    }
                }
            }
           	// Output
        	WriteLine($"{ansI} {ansJ} {ansK}");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 27912