akhauriyash/Code-Regression huggingface dataset:
def solve_m(k, a_m, a_p):
    def syaku(mid):
        """mid以下になる組の数を数える"""
        rm = 0
        cnt = 0
        for lp, num in enumerate(a_p):
            while True:
                if rm >= len(a_m) or num * a_m[rm] > mid :
                    break
                else:
                    rm += 1
            cnt += rm
        return cnt
                
    ok, ng = 1, -10 ** 20
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if syaku(mid) >= k:
            ok = mid
        else:
            ng = mid
    return ok

    
def solve_p(k, a_m, a_p):
    def syaku(mid):
        """mid以下になる組の数を数える"""
        r = len(a_p)
        cnt = 0
        for l, num in enumerate(a_p):
            while True:
                if r == 0 or num * a_p[r - 1] <= mid:
                    break
                else:
                    r -= 1
            cnt += r
            if l <= r - 1:
                cnt -= 1
        r = len(a_m)
        for l, num in enumerate(a_m):
            while True:
                if r == 0 or num * a_m[r - 1] <= mid:
                    break
                else:
                    r -= 1
            cnt += r
            if l <= r - 1:
                cnt -= 1
        return cnt // 2

    a_m = sorted([-num for num in a_m])
    ok, ng = 10 ** 20, -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if syaku(mid) >= k:
            ok = mid
        else:
            ng = mid
    return ok


n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt_p, cnt_m, cnt_0 = 0, 0, 0
tmp_p, tmp_m, tmp_0 = 0, 0, 0
for num in a:
    if num > 0:
        tmp_p += 1
    elif num < 0:
        tmp_m += 1
    else:
        tmp_0 += 1
cnt_p += tmp_p * (tmp_p - 1) // 2 + tmp_m * (tmp_m - 1) // 2
cnt_m += tmp_p * tmp_m
cnt_0 += (tmp_p + tmp_m) * tmp_0 + tmp_0 * (tmp_0 - 1) // 2
# print(cnt_p, cnt_m, cnt_0)

a_m = sorted([a[i] for i in range(n) if a[i] < 0])
a_p = sorted([a[i] for i in range(n) if a[i] > 0])

if k <= cnt_m:
    ans = solve_m(k, a_m, a_p)
elif cnt_m < k <= cnt_m + cnt_0:
    ans = 0
else:
    ans = solve_p(k - cnt_m - cnt_0, a_m, a_p)
      
print(ans)



Measured memory_bytes: 101460
#include <stdio.h>

int main()
{
  int n,i,j,flag,m=0,koukan;

  scanf("%d",&n);

  int A[n];

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  for(i=0;i<n;i++)
    {
      for(j=n-1;j>i;j--)
	{
	  if(A[j]<A[j-1])
	    {
	      koukan=A[j-1];
	      A[j-1]=A[j];
	      A[j]=koukan;
	      m++;
	    }
	}
    }

  for(i=0;i<n-1;i++)printf("%d ",A[i]);
  printf("%d\n%d\n",A[n-1],m);
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  double A,sum;
  string B;
  sum=0;
  for(int i=0;i<N;i++){
    cin>>A>>B;
    if(B=="JPY"){
      sum=sum+A;
    }
    else{
      sum=sum+A*380000.0;
    }
  }
  cout<<sum<<endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ===============================================================================

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << ((k % 2 == 0) ? a - b : b - a) << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;

use itertools::Itertools;

#[fastout]
fn main() {
    input!{
        n: usize, m: usize, q: usize,
        abcd_vec: [[usize; 4]; q],
    }

    let mut ans = 0;

    for com in (1..=m).combinations_with_replacement(n) {
        // dbg!(&com);
        let mut tmp_sum = 0;
        for abcd in abcd_vec.iter() {
            if com[abcd[1]-1] - com[abcd[0]-1] == abcd[2] { tmp_sum += abcd[3] }
        }
        ans = std::cmp::max(ans, tmp_sum);
    }


    println!("{}", ans);
}


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

int main() {
	int time,h,m,s;
	cin>>time;
	
	h = time/3600;
	time-=3600*h;
	m = time/60;
	s=time-60*m;
	
	
	cout<<h<<":"<<m<<":"<<s<<endl;
	
	
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();

int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}

ll run() {
    ll n;
    cin>>n;
    ll a[n+1];
    ll s=0;

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

    sort(a+1,a+n+1);
    ll l=a[n];
    s-=l;
    if(l<s){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

























Measured memory_bytes: 256
program main
	implicit none
	integer(8):: X,Y,A,B,C,N,i,j,t,k,D,E
	read *, X
	
   	if(x==1)then
   	print'(a)',"ACL"
	else if(x==2)then
  	print'(a)',"ACLACL"
	else if(x==3)then
  	print'(a)',"ACLACLACL"
	else if(x==4)then
  	print'(a)',"ACLACLACLACL"
	else if(x==5)then
  	print'(a)',"ACLACLACLACLACL"
    end if
	
end program main

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

int main() {
	int N; cin >> N;
	string s; cin >> s;
	if (N % 2 != 0) { cout << "No" << endl; return 0; }
	
	int n = N / 2;
	string T;
	for (int i = 0; i < n; i++) {
		T += s[i];
	}
	cout << (s == T + T ? "Yes" : "No") << endl;

	return 0;
}

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

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

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

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

ll dp[5010][5010];

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
            res %= mod;
        }
        a = a*a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

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

    ll N;
    string s;
    cin >> N >> s;
    ll M = s.size();

    REP(i, 5010)REP(j, 5010) dp[i][j] = 0;
    dp[0][0]= 1;

    REP(i, N){
    	REP(j, N+1){
    		dp[i+1][j+1] += dp[i][j];
    		dp[i+1][j+1] %= mod;
    		dp[i+1][j+1] += dp[i][j];
    		dp[i+1][j+1] %= mod;
    		ll idx = max(j-1, 0);
    		dp[i+1][idx] += dp[i][j];
    		dp[i+1][idx] %= mod;
    	}
    }

    /*
    REP(i, N+1){
    	REP(j, N+1){
    		cout << dp[i][j] << " ";
    	}
    	cout << endl;
    }
    */

    ll res = dp[N][M];
    ll bo = modinv(powLL(2, M), mod);

    cout << res*bo%mod << endl;

    return 0;
}

Measured memory_bytes: 196352
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>
using namespace std;

#define rep(i,end)          rep2(i,0,(end))
#define rep2(i,beg,end)   for (int i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a = get_n_array(n);
    vi b(n, 0);
    ll cnt = 0;
    for (int i = n; i >= 1; i--) {
        ll s = 0;
        for (int mul = 2; i*mul <= n; mul++) {
            s += b[(i*mul) - 1];
        }
        int x;
        if (s % 2 == 0) {//even
            x = a[i - 1];
        }
        else {//odd
            x = 1 - a[i - 1];
        }
        if (x) {
            b[i - 1] = x;
            cnt++;
        }
    }
    cout << cnt << endl;
    if (cnt > 0) {
        for (int i = 0; i < n; i++) {
            if (b[i]) {
                cout << i + 1 << " ";
            }
        }
        cout << endl;
    }

    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int LINE_MAX = 1024;
    char buf[LINE_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

Measured memory_bytes: 4208
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<math.h>

typedef long long int ll;

using namespace std;

int main(void){

    ll n;
    ll ans = 0;
    ll tmp = 0;
    ll min = 10000000000000;

    cin >> n;


    if(n == 1){
        cout << ans << endl;
    }else{
        for(ll i = 1;i <= sqrt(n);i++){
            if(n % i == 0){
                ll a = i;
                ll b = n/i;
                if(a == 1) tmp = b - 1;
                else tmp = a + b - 2;

                if(min > tmp) min = tmp;
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
    vector<int> data;
	int psum;
    UnionFind(int size){
		data=vi(size,-1);
		psum=size;
	}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
		psum--;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
	int sum(){return psum;}
};
class KRK{//c++11
	public:
	struct edge{
		int from,to,cost;
	};
	vector<edge>G;
	int n;
	KRK(int size){
		n=size;
	}
	void add_edge(int a,int b,int c){
		edge e={a,b,c};
		G.pb(e);
	}
	void init(){
		sort(all(G),[](edge a,edge b){
			return a.cost<b.cost;
		});
	}
	int krk(int st){
		int sum=0;
		UnionFind uf(n);
		int mi=inf,ma=-inf;
		loop(i,st,G.size()){
			edge e=G[i];
			if(!uf.findSet(e.from,e.to)){
				sum+=e.cost;
				uf.unionSet(e.from,e.to);
				mi=min(mi,e.cost);
				ma=max(ma,e.cost);
				if(uf.sum()==1)return ma-mi;
			}
		}
		return inf;
	}
	int f(int m){
		int out=inf;
		rep(i,m){
			out=min(out,krk(i));
		}
		return out;
	}
};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		KRK krk(n);
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			krk.add_edge(a,b,c);
		}
		krk.init();
		int out=krk.f(m);
		if(out==inf)cout<<-1<<endl;
		else cout<<krk.f(m)<<endl;
	}
}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		double w = sc.nextInt();
		double h = sc.nextInt();
		double x = sc.nextInt();
		double y = sc.nextInt();
		if (x + x == w && y + y == h) {
			System.out.println(w /2.0 * h+ " " + 1);
		} else {
			System.out.println(w / 2.0 * h + " " + 0);
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n, m);
	inc(i, m) {
		IN(int, a);
		n -= a;
	}
	OUT(n < 0 ? -1 : n);
}


Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n = 0, a = 0, b = 0;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

        int n = scanner.nextInt();

        Set<String> set= new HashSet<>();

        for(int i=0;i<n;i++){
            set.add(scanner.next());
        }

        System.out.println(set.size());
    }
}


Measured memory_bytes: 78728
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

#define NMAX (51)

int N, M;
vector<int> G[NMAX];

bool visited[NMAX] = { false };
int ord[NMAX];
int lowlink[NMAX];
int depth[NMAX];
int dfs_time = 1;
int ans = 0;

void dfs(int node, int src)
{
	int next;

	visited[node] = true;
	ord[node] = dfs_time;
	lowlink[node] = dfs_time;
	dfs_time++;

	if (src == -1) depth[node] = 0;
	else depth[node] = depth[src] + 1;

	rep(i, G[node].size()) {
		next = G[node][i];

		if (!visited[next]) {
			dfs(next, node);
			lowlink[node] = min(lowlink[node], lowlink[next]);
		}
		else if (src != next) {
			lowlink[node] = min(lowlink[node], ord[next]);
		}
	}
}

void bridge()
{
	int peer, parent, des;

	dfs(1, -1);

	repc(i, 1, N) {
		rep(j, G[i].size()) {
			peer = G[i][j];

			if (depth[i] < depth[peer]) {
				parent = i;
				des = peer;
			}
			else {
				parent = peer;
				des = i;
			}

			if (ord[parent] < lowlink[des]) ans++;
		}
	}
}

int main()
{
	int a, b;

	cin >> N >> M;
	rep(i, M) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	bridge();

	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e5 + 5;

bool vis[MAXN];
int tot[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	ll cnt=0,ans=0;
	for(int i=1;i<=m;i++){
		ll p;string s;
		cin>>p>>s;
		if(!vis[p]){
			if(s=="WA"){
				tot[p]++;
			}else{
				cnt++;
				vis[p]=1;
				ans+=tot[p];
			}
		}
	} 
	cout<<cnt<<" "<<ans;
	return 0;
}


Measured memory_bytes: 768
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	LinkedList<Integer> gos;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;
			int s = sc.nextInt();
			int cnt = 1;
			int st = s;
			gos = new LinkedList<Integer>();
			for(int i=2;i<=n;i++) {
				int go = sc.nextInt();
				if( i%2 == 0 ) {
					if( go == st )
						cnt++;
					else {
						if(!gos.isEmpty())
							cnt += gos.removeLast();
						else s = go;
						cnt++;
						st = go;
					}
				}
				else {
					if( go == st )
						cnt++;
					else {
						gos.add(cnt);
						st = go;
						cnt = 1;
					}
				}
			}
			gos.add(cnt);
//			debug(gos);
			int ans = 0;
			int size = gos.size();
			for(int i=0;i<size;i++) {
				int val = gos.removeFirst();
				if( (i+s)%2 == 0 ) ans+=val;
			}
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    char a, b;

    cin >> a >> b;

    if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
        cout << "H";
    } else {
        cout << "D";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a).most_common()
edge = sorted([key, val] for key, val in c if val >= 2)

if len(edge) < 2:
    ans = 0
elif edge[-1][1] >= 4:
    ans = edge[-1][0] ** 2
else:
    ans = edge[-1][0] * edge[-2][0]

print(ans)


Measured memory_bytes: 21540
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#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 << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string x;
int n;
int res;

int npo2(int q, int ileCyfr) {
	if (ileCyfr == 0) {
		return 1;
	} else if (ileCyfr == 1) {
		return q;
	} else if (ileCyfr == 2) {
		return (q * (q - 1)) / 2;
	} else {
		return (q * (q - 1) * (q - 2)) / 6;
	}
}


int fullRes(int ilePozycji, int ileCyfr) {
	int pom = npo2(ilePozycji, ileCyfr);
	while (ileCyfr > 0) {
		pom *= 9;
		--ileCyfr;
	}
	return pom;
}

int compute(int position, int ileCyfr) {
	if (position == n) {
		return ileCyfr == 0;
	}
	if (ileCyfr == 0) {
		return 1;
	}
	// moge tutaj co zrobic.
	bool isZero = (x[position] == '0');
	if (isZero) {
		return compute(position + 1, ileCyfr);
	}
	// moge dac zero i juz potem dowolnie
	int r = fullRes(n - position -1, ileCyfr);
	r += (x[position] - '0' - 1) * fullRes(n - position - 1, ileCyfr - 1);
	r += compute(position + 1, ileCyfr - 1);
	return r;
}

int main() {
	ios_base::sync_with_stdio(false);
	// n;
	// string x;
	cin >> x;
	n = x.size();
	int pom;
	cin >> pom;
	cout << compute(0, pom) << endl;
}

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

int main(){
  int *ip;
  int i,j,n,v,k;
  scanf("%d",&n);
  if(n>=1&&n<=100){
    ip=(int *)malloc(n*sizeof(int));
    for(i=0;i<n;i++){
      scanf("%d",&ip[i]);
      if(ip[i]<0||ip[i]>1000){
	fprintf(stderr,"数値が大きすぎます\n");
	exit(1);
      }
    }
    for(i=0;i<n;i++){
      if(i!=n-1)printf("%d ",ip[i]);
      else printf("%d",ip[i]);
    }
    printf("\n");
    for(i=1;i<n;i++){
      v=ip[i];
      j=i-1;
      while(j>=0&&ip[j]>v)
	{
	  ip[j+1]=ip[j];
	  j--;
	  ip[j+1]=v;
	}
      for(k=0;k<n;k++){
	if(k!=n-1)printf("%d ",ip[k]);
	else printf("%d",ip[k]);
      }
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
typedef pair <int,int> pii;
vector <pii> edges[100005];
int N;
pii ordering[100005];
unordered_set <int> colorIndex[100005];
int color[100005];
unsigned long most = 0;

void dfs(int v, int p){
    int k = 1;
    for (pii e: edges[v]){
        if (e.first != p){
            for (int i=k; i<=most; i++) {
                if (!colorIndex[v].count(i)) {
                    k = i;
                    break;
                }
            }
            colorIndex[v].insert(k);
            colorIndex[e.first].insert(k);
            color[e.second] = k;
            dfs(e.first, v);
        }
    }
}

int main() {
    cin >> N;
    int a, b;
    for (int i=0; i<N-1; i++){
        scanf("%d %d", &a, &b);
        ordering[i].first = a; ordering[i].second = b;
        edges[a].push_back({b,i});
        edges[b].push_back({a,i});
    }
    for (int i=1; i<=N; i++){
        most = max(most, edges[i].size());
    }
    dfs(1, -1);
    cout << most << endl;
    for (int i=0; i<N-1; i++) cout << color[i] << endl;
    return 0;
}

Measured memory_bytes: 24704
s = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    a,b = map(int,[cmd[1],cmd[2]])
    if cmd[0] == 'print':print(s[a:b+1])
    elif cmd[0] == 'reverse':s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':s = s[:a] + cmd[3] + s[b+1:]

Measured memory_bytes: 7600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const int M = 100000;
const int INF = 1e9;
int a[maxN]; 

int s[maxN];
int t[maxN];
vector<pii> p;
vector<pii> q;
int n;
int main()
{
	n = inp();
	for(int i=1;i<=n;i++)
	{
		a[i] = inp();
	}
	int flag = 0;
	for(int i=1;i<=n;i+=2)
	{
		s[a[i]]++;
		t[a[i+1]]++;
	}
 
	for(int i=1;i<=M;i++)
	{
		p.push_back(pii(s[i],i));
		q.push_back(pii(t[i],i));
	}
	sort(p.begin(),p.end());
	reverse(p.begin(),p.end());
	sort(q.begin(),q.end());
	reverse(q.begin(),q.end());
	int k=0,g=0;
	int cnt = 0;
	if(p[0].second == q[0].second)
	{
		cnt = max(p[1].first+q[0].first,p[0].first + q[1].first);
	}
	else
	{
		cnt = p[0].first + q[0].first;
	}
	int ans = n - cnt;
	printf("%d\n",ans);
    return 0;
}

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

signed main(void)
{
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	printf("%lf %d\n",w * h / 2, x + x == w && y + y == h);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==0&&a==b){
        cout<<"No"<<endl;
        return 0;
    }
    if(a*4<b||a*2>b||b%2!=0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

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

ll powmod(ll a, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(a, k / 2, m);
  t = (t * t) % mod;
  if (k % 2 == 1) t = (t * a) % mod;
  return t;
}

int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] != 's') {
    s += "s";
  }
  else if (s[s.size() - 1] == 's') {
    s += "es";
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    long long int n,w;
    cin>>n>>w;
    long long int z[n],v[n];
    long long int s=0;
    for (long long int i = 0; i < n; ++i) {
        cin>>z[i]>>v[i];
        s+=v[i];
    }

    long long int dp[n+1][s+1];

    for (long long int i = 0; i < n+1; ++i) {
        dp[i][0]=0;
    }

    for (long long int i = 0; i < s+1; ++i) {
        dp[0][i]=0;
    }

    for (long long int i = 1; i < n+1; ++i) {
        for (long long int j = 0; j < s+1; ++j) {
            if(j<v[i-1])
                dp[i][j]=dp[i-1][j];
            else if(j==v[i-1])
            {
                if(dp[i-1][j]==0)
                    dp[i][j]= z[i-1];
                else
                {
                    dp[i][j]=min(dp[i-1][j],z[i-1]);
                }
            }
            else
            {
                if(dp[i - 1][j]==0) {
                 if(dp[i-1][j-v[i-1]] == 0)
                     dp[i][j]=0;
                 else
                    dp[i][j] = z[i - 1] + dp[i - 1][j - v[i - 1]];
                }
                    else {
                        if(dp[i-1][j-v[i-1]]==0)
                            dp[i][j]=dp[i-1][j];
                        else
                    dp[i][j] = min(dp[i - 1][j], z[i - 1] + dp[i - 1][j - v[i - 1]]);
                }
            }
        }
    }

    long long int maxa=0;
        for (long long int j = 0; j <s+1 ; ++j) {

            if(dp[n][j]<=w&&dp[n][j]!=0)
            {
                if(j>maxa)
                    maxa=j;
            }
        }
    cout<<maxa;
}


Measured memory_bytes: 79104
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        for (int x = 0; x < n; x++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            if ( a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b ) System.out.println("YES");
            else    System.out.println("NO");
        }

    }
}

Measured memory_bytes: 12000
<?php
fscanf(STDIN, "%d %d", $H, $W);
$ans = 0;
if ($H === 1 || $W === 1) {
    $ans = 1;
} else {
    $ans =  intdiv($H * $W, 2) + ($H * $W % 2 !== 0);
}
printf("%d", $ans);


Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;

using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}

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


int main() {
	int manji[5][5];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> manji[i][j];
		}
	}
	int a1 = 0, a2 = 0, a3 = 0;
	for (int i = 0; i < 2; i++) {
		
			a1 = abs(manji[i][0] - manji[i + 1][0]);
			a2 = abs(manji[i][1] - manji[i + 1][1]);
			a3 = abs(manji[i][2] - manji[i + 1][2]);
			if (a1 != a2 || a2 != a3) {
				cout << "No" << endl;
				return 0;
		}
	}
	for (int j = 0; j < 2; j++) {

		a1 = abs(manji[0][j] - manji[0][j+1]);
		a2 = abs(manji[1][j] - manji[ 1][j+1]);
		a3 = abs(manji[2][j] - manji[ 2][j+1]);
		if (a1 != a2 || a2 != a3) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
string MrJ(string s) { return s.substr(1) + s.front(); }
string MissC(string s) { return s.back() + s.substr(0, s.size() - 1); }
string MrE(string s) {
	string res;
	if (s.size() % 2) {
		res = s[s.size() / 2];
		res += s.substr(0, s.size() / 2);
		res = s.substr(s.size() / 2 + 1)+res;
	}
	else {
		res = s.substr(s.size() / 2) + s.substr(0, s.size() / 2);
	}
	return res;
}
string MrA(string s) { string res = s; reverse(res.begin(), res.end()); return res; }
string DrP(string s) {
	rep(i, 0, s.size()) {
		if (isdigit(s[i])) {
			if (s[i] == '9')s[i] = '0';
			else s[i]++;
		}
	}
	return s;
}
string MrM(string s) {
	rep(i, 0, s.size()) {
		if (isdigit(s[i])) {
			if (s[i] == '0')s[i] = '9';
			else s[i]--;
		}
	}
	return s;
}
signed main() {
	int n; cin >> n;
	while (n--) {
		string order, king;
		cin >> order >> king;
		rrep(i, 0, order.size()) {
			switch (order[i])
			{
			case 'J':king = MissC(king); break;
			case 'C':king = MrJ(king); break;
			case 'E':king = MrE(king); break;
			case 'A':king = MrA(king); break;
			case 'P':king = MrM(king); break;
			case 'M':king = DrP(king); break;
			default:
				break;
			}
		}

		cout << king << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);


    double a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;

    double dis = abs(max(a, b) - min(a, b));
    if(t * v >= t * w + dis)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 3716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N, K;
	cin >> N >> K;

	vector<int> A;
	inputVector(A, N);

	int minarg = 0;
	rep(i, N) {
		if (A[i] < A[minarg]) minarg = i;
	}

	int ret = 0;
	int pt = minarg;
	while (pt > 0) {
		ret++;
		pt -= K - 1;
	}

	int pt2 = minarg - pt;
	while (pt2 < N - 1) {
		ret++;
		pt2 += K - 1;
	}

	int ret2 = 0;
	pt = minarg;
	while (pt < N - 1) {
		ret2++;
		pt += K - 1;
	}

	pt2 = minarg - (pt - (N - 1));
	while (pt2 > 0) {
		ret2++;
		pt2 -= K - 1;
	}

	cerr << "ret:" << ret << endl;
	cerr << "ret2:" << ret2 << endl;

	cout << min(ret, ret2) << endl;

    return 0;
}


Measured memory_bytes: 1024
import queue

k = int(input())

q = queue.Queue()

for i in range(1,10):
    q.put(i)
    
c = 0
while c<k:
    x = q.get()
    r = x%10
    if r != 0 and r != 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        q.put(10*x+r+1)
        c = c+1
    if r == 0:
        q.put(10*x)
        q.put(10*x+1)
        c = c+1
    if r == 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        c = c+1
    if c == k:
        print(x)
   

Measured memory_bytes: 12536
#include <iostream>
#include <vector>
#include <queue>
using namespace std ;

int main(){
	int n ; cin >> n ;
	priority_queue<int> pq ;
	long long ans = 0 ;
	vector<vector<int>> vec(n,vector<int>(0)) ;
	for(int i=0;i<n;i++){
		int m ; cin >> m ;
		for(int j=0;j<m;j++){
			int a ; cin >> a ;
			vec.at(i).push_back(a) ;
		}
	}
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<vec.at(i).size();j++){
			pq.push(vec.at(i).at(j)) ;
		}
		ans += pq.top() ; pq.pop() ;
	}
	cout << ans << endl ;
}



Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int bit[200003],nn=200003;
int sum(int i){
    int s=0;
    while (i>0){
        s+=bit[i];
        i -= i & -i;
    }
    return s;
}
void add(int i,int x){
    while (i<=nn){
        bit[i]+=x;
        i+= i& -i;
    }
}

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n+1);
    a.at(0)=0;
    rep(i,n){
        ll f;
        cin >> f;
        a.at(i+1)=a.at(i)+f-k;
    }
    vector<ll> b=a;
    sort(all(b));
    map<ll,int> m;
    rep(i,n+1){
        m[b.at(i)]=i+1;
    }
    rep(i,n+1){
        a.at(i)=m[a.at(i)];
    }
    ll ans=0;
    ll u=0;
    rep(i,n+1){
        ans+=sum(a.at(i));
        add(a.at(i),1);
    }   
    cout << ans << endl;
}

Measured memory_bytes: 16768
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (n < m) {
			int d = n;
			n = m;
			m = d;
		}
		if (Math.abs(n - m) >= 2) {
			System.out.println(0);
			return;
		}
		long ans = 1;
		for (int i = 1; i <= n; ++i) {
			ans = (ans * i) % MODULO;
		}
		for (int i = 1; i <= m; ++i) {
			ans = (ans * i) % MODULO;
		}
		if (n == m) {
			ans = (ans * 2) % MODULO;
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int ans = K * pow(K-1, N-1);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    if (n%2 == 0){
        vector<vector<ll>> dp(n+2,vector<ll>(2,-INF));
        dp[0] = {0,0};
        rep(i,n){
            chmax(dp[i+2][0],dp[i][0]+a[i]);
            chmax(dp[i+2][1],dp[i][1]+a[i]);
            if (i+1 < n) chmax(dp[i+3][1],dp[i][0]+a[i+1]);
        }
        PRINT(max(dp[n+1][1],dp[n][0]));
    }
    else{
        vector<vector<ll>> dp(n+3,vector<ll>(3,-INF));
        dp[0] = {0,0};
        rep(i,n){
            chmax(dp[i+2][0],dp[i][0]+a[i]);
            chmax(dp[i+2][1],dp[i][1]+a[i]);
            chmax(dp[i+2][2],dp[i][2]+a[i]);
            if (i+1 < n){
                chmax(dp[i+3][1],dp[i][0]+a[i+1]);
                chmax(dp[i+3][2],dp[i][1]+a[i+1]);
            }
            if (i+2 < n){
                chmax(dp[i+4][2],dp[i][0]+a[i+2]);
            }
        }
        PRINT(max({dp[n+1][2],dp[n][1],dp[n-1][0]}));
    }
}


Measured memory_bytes: 15856
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;

int main() {
	int N;
	cin >> N;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
S = [sorted(list(input())) for _ in range(N)]

res = ""
strdict = {}
for c in ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]:
    tmp = [0] * N
    for i, s in enumerate(S):
        tmp[i] = s.count(c)
    for t in range(min(tmp)):
        res += c
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int m=0;
  int sum=0;
  int G[13]={1,4,13,40,121,364,1093,3280,9841,29524,88573,265720,797161};
  for(int i=12;i>=0;i--){
    if(N/G[i]>=1){
      m=i;
      break;
    }
  }
  cout << m+1 << endl;
  for(int i=m;i>=0;i--){
    for(int j=G[i];j<=N-1;j++){
    int v=A[j];
    int k=j-G[i];
 while(k>=0 && A[k]>v){
    A[k+G[i]]=A[k];
    k=k-G[i];
    sum++;
    A[k+G[i]]=v;
  }
  }
  if(i>0){
    cout << G[i] << " ";
  }
  else if(i==0){
    cout << G[i] << endl << sum << endl;
  }
 }
 for(int i=0;i<N;i++){
    cout << A[i] << endl;
  }
}  


Measured memory_bytes: 6940
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
n = int(input())
l = make_divisors(n)
ans = 0
for i in l:
    if (i - 1) != 0 and n // (i - 1) == n % (i - 1):
        ans += i - 1
print(ans)

Measured memory_bytes: 3352
s = input()
if int(s[:2]) == 0 or int(s[:2]) >= 13:
    if int(s[2:]) == 0 or int(s[2:]) >= 13:
        print('NA')
    else:
        print('YYMM')
else:
    if int(s[2:]) == 0 or int(s[2:]) >= 13:
        print('MMYY')
    else:
        print('AMBIGUOUS')



Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int x;
  cin>>x;
  if(x<1200){
    cout<<"ABC"<<endl;
  }else{
    cout<<"ARC"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string s;
cin>>s;
s+='00000';
s+='aaaaa';
s+='adoooo';
if(s.at(0)=='A'&&s.at(1)=='C'||s.at(1)=='A'&&s.at(2)=='C'||s.at(2)=='A'&&s.at(3)=='C'||s.at(3)=='A'&&s.at(4)=='C'){
cout << "Yes" << endl;}
else{
cout << "No" << endl;}}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <list>
#include <numeric>
#include <math.h>
#include <cstdlib>
#include <queue>
#include <iterator>
#include <limits>
#include <string>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <stack>
#include <memory>
#include <deque>
#include <string_view>
#include <random>
#include <chrono>
#include <cstring>

using namespace std;

static int my_speed_up = []() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
using ll = long long; using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using vvv = vector<vector<vector<T>>>;
template<class T> using vvvv = vector<vector<vector<vector<T>>>>;
#define for_b(i, b) for (int i = 0; i < ll(b); ++i)
#define for_ab(i, a, b) for (int i = a; i < ll(b); ++i)
#define what_is(x) cout << #x << " = " << x << endl;
#define what_are(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl;
#define pad(x) for_b(i, x) cout << "  ";
#define show_1d(___x) cout << #___x << " = "; for (auto& ___num : ___x) cout << ___num << ", "; cout << endl;
#define show_2d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto ___num : ___row) cout << ___num << ", "; cout << endl; }
#define show_3d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto& ___row2 : ___row) { for (auto ___num : ___row2) cout << ___num << ", "; cout << endl; }cout << endl; }


int main()
{
    string s;
    cin >> s;
    
    int res = 0;
    int cur = 0;
    
    for (auto ch : s)
    {
        if (ch == 'S')
            cur = 0;
        else
        {
            ++cur;
            res = max(res, cur);
        }
    }
    cout << res << endl;
        
    return 0;
}


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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

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

  vector<ll> p(n);
  for (ll i = 0; i < n; ++i) {
    cin >> p[i];
  }

  ll ans = 1;
  ll v = p[0];
  for (ll i = 1; i < n; ++i) {
    if (v >= p[i]) ++ans;
    if (p[i] < v) {
      v = p[i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int ans = 0;
  vector<int> b(n,0);
  for(int i = n; i > 0; --i){
    int sum = 0;
    for(int num = i*2; num <= n; num += i){
      if(b[num-1]==1) ++sum;
    }
    if(sum%2!=a[i-1]){
      b[i-1] = 1;
      ++ans;
    }
  }
  cout << ans << endl;
  if(ans>0){
    rep(i,n) if(b[i]==1) cout << i+1 << " ";
    cout << endl;
  }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main (void) {
  int a, b, c;
  cin >> a >> b >> c;
  if (a * b * c == 5 * 7 * 5)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256