akhauriyash/Code-Regression huggingface dataset:
//g++ -std=c++17 -Wall t.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl '\n'
#define teto(a, b) (a+b-1)/(b)

const int MAX = 400010;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-8;
const ld PI = acosl(-1.0);

// End - Template //

using namespace std;

int main()
{
    int m, k;

    cin >> m >> k;
    int p = 1<<m;

    if(m==1)
    {
        if(k>0)
            cout << -1 << endl;
        else
            cout << "0 0 1 1\n";
    }
    else if(k>=p)
        cout << -1 << endl;
    else
    {
        for(int i=p-1;i>=0;i--)
            if(i!=k)
                cout << i << " ";
        cout << k << " ";
        for(int i=0;i<p;i++)
            if(i!=k)
                cout << i << " ";
        cout << k << endl;
    }

    return 0;
}


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

vector<vector<int> > happiness;

// map<pair<int,int> ,int> memory;

// int dp(int day,int activity){
//     if(day == 0){
//         return happiness[day][activity];
//     }
//     if(memory.count({day,activity})){
//         return memory[{day,activity}];
//     }
//     int max_happiness = 0;
//     for(int i=0;i<3;i++){
//         if(activity!=i){
//             max_happiness = max(max_happiness , happiness[day][activity] +  dp(day-1,i));
//         }
//     }
//     return memory[{day,activity}] = max_happiness;
// }


int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    happiness.resize(n, vector<int>(3,0));
     for(int i=0;i<n;i++){
        for (size_t j = 0; j < 3; j++)cin>>happiness[i][j];
     }

    // cout<< max(dp(n-1,0),max(dp(n-1,1) , dp(n-1,2)));
    
    
    for(int i=1;i<n;i++){
        for(int ac = 0;ac < 3;ac++){
            switch (ac)
            {
            case 0:
                happiness[i][ac] += max(happiness[i-1][1],happiness[i-1][2]);
                break;
            case 1:
                happiness[i][ac] += max(happiness[i-1][0],happiness[i-1][2]);
                break;
            case 2:
                happiness[i][ac] += max(happiness[i-1][1],happiness[i-1][0]);
                break;
            default:
                break;
            }
        }
    }

    cout<<*max_element(happiness[n-1].begin(),happiness[n-1].end());
    return 0;
}

Measured memory_bytes: 5760
N=gets.to_i
F=[]
N.times do
    array=gets.chomp.split(" ").map(&:to_i)
    F.push(array)
end
P=[]
N.times do
    array=gets.chomp.split(" ").map(&:to_i)
    P.push(array)
end
ret= -(10**9)
all=[0, 1].repeated_permutation(10).to_a
all.shift
all.each do |g|
    r=0
    N.times do |n|
        count=0
        10.times do |i|
            count+=1 if F[n][i]==1 && F[n][i]==g[i]
        end
        r+=P[n][count]
    end
    ret=r if ret<r
end
puts ret


Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int X,Y,Z;cin>>X>>Y>>Z;
    cout<<(X*Y)/2<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	int n,p,max;
	int stone[51]={};
	int cup;
	bool flag;
	while(1){
		cin >> n >> p;
		max = p;
		for(int i=0;i<n;i++){
			stone[i]=0;
		}
		cup =0;
		if(n==0&&p==0)break;
		while(1){
			if(p>0){
				p-=1;
				stone[cup]+=1;
				if(cup!=n-1)cup+=1;
				else cup = 0;
			}else{
				flag =0;
				for(int i=0;i<n;i++){
					if(stone[i]!=0&&stone[i]!=max){
						flag =1;
					}
				}
				if(flag==0){
					if(cup==0){
						cout << n-1 << endl;
					}else{
						cout << cup-1 <<endl;
					}
					break;
				}else{
					if(stone[cup]>0){
						p+=stone[cup];
						stone[cup]=0;
						if(cup!=n-1)cup+=1;
						else cup = 0;
					}else{
						if(cup!=n-1)cup+=1;
						else cup = 0;
					}
				}
			}
		}
	}
	return 0;
}

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

int main(){
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<int> cnt(n,0);
    for(int i = 1;i < n;i ++){
        cnt[i] = cnt[i-1];
        if(s[i]=='C'&&s[i-1]=='A') cnt[i] ++;
    }
    for(int i = 0;i < q;i ++){
        int l,r;
        cin >> l >> r;
        l --,r --;
        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n;
	int a[4][3][10];

	for (int i = 0; i < 4; i++)for (int j = 0; j < 3; j++)for (int k = 0; k < 10; k++)
	{
		a[i][j][k] = 0;
	}

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int b, f, r, v;

		scanf("%d %d %d %d", &b, &f, &r, &v);
		a[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				printf(" %d", a[i][j][k]);
			}
			printf("\n");
		}
		if (i < 3)
		{
			for (int j = 0; j < 20; j++)
			{
				printf("#");
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 3176
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }

template <class T>
bool updateMax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

template <class T>
bool updateMin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10


int N, M;
vector<vector<int> > G;
vector<int> deg;

int dp[100010];

int Solve(int v)
{
    if (dp[v] != -1) return dp[v];

    int ans = 0;
    for (auto nv : G[v])
    {
        updateMax(ans, Solve(nv) + 1);
    }
    return dp[v] = ans;
}

int main()
{
    cin >> N >> M;
    G.assign(N, vector<int>());
    deg.assign(N, 0);
    REP(i, M)
    {
        int x, y;
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
        deg[y]++;
    }

    queue<int> que;
    REP(v, N) if (deg[v] == 0) que.push(v);

    // BFS
    while (!que.empty())
    {
        int v = que.front();
        que.pop();
        for (auto nv : G[v])
        {
            --deg[nv];
            if (deg[nv] == 0)
            {
                que.push(nv);
                updateMax(dp[nv], dp[v] + 1);
            }
        }
    }

    int ans = 0;
    REP(v, N) updateMax(ans, dp[v]);
    cout << ans << endl;
    return 0;
}

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

int H, W, N;
int a[10001];
int field[101][101];
int main()
{
	cin >> H >> W >> N;
	REP(i, 0, N) cin >> a[i];

	int i = 0, j = 0;
	int num = 0;
	bool flag = false;
	while (i < H) {
		// →
		if (i%2==0) {
			while (j < W) {
				if (a[num] > 0) {
					field[i][j] = num + 1;
					a[num]--;
					j++;
				}
				else {
					num++;
				}
			}

			i++;
			j--;
		}

		// ←
		else {
			while (j >= 0) {
				if (a[num] > 0) {
					field[i][j] = num + 1;
					a[num]--;
					j--;
				}
				else {
					num++;
				}
			}

			i++;
			j++;
		}
	}
	
	REP(h, 0, H) {
		REP(w, 0, W) {
			cout << field[h][w] << " ";
		}
		cout << endl;
	}
	
	return 0;
}

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

using namespace std;

#define rep(i, a) for(int i = 0; i < a; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define MP(a, b) make_pair(a, b)

int N;
int X;
int D;

int main()
{
  cin >> N >> D >> X;
  while (N--) {
    int a;
    cin >> a;
    X += 1 + (D-1)/a;
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
dx = [0,0,-1,1]
dy = [-1,1,0,0]

def rec(n, x, y):
    global w,h,ans
    global f
    if n >= ans: return
    for i in xrange(4):
        #print x,y
        mx, my = x+dx[i], y+dy[i]
        if not(0 <= mx < w and 0 <= my < h): continue
        if f[my][mx] == 1: continue

        while 1:
            if f[my][mx] == 3:
                #print f
                ans = n
                return

            mx += dx[i]
            my += dy[i]
            if not(0 <= mx < w and 0 <= my < h):
                break
            if f[my][mx] == 1:
                f[my][mx] = 0
                #print mx,my
                rec(n+1, mx-dx[i], my-dy[i])
                f[my][mx] = 1
                break

while 1:
    w,h = map(int, raw_input().split())
    if not(w or h): break
    f = []
    for i in xrange(h):
        f.append(map(int, raw_input().split()))
    for i in xrange(h):
        for j in xrange(w):
            if f[i][j] == 2:
                sx,sy = j,i
                #print f

    ans = 11
    rec(1, sx, sy)
    if (ans>10): ans = -1
    print ans

Measured memory_bytes: 5544
A, B, C, K = map(int, input().split())

if A >= K:
    print(K)
else:
    if (A + B) >= K:
        print(A)
    else:
        if (A + B + C) >= K:
            print(A - (K - (A + B)))
        else:
            print(A - C)

Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x)memset(a,x,sizeof(a))
using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1;return(mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}ll Fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}ll upd(ll x,ll v){x=x+v>=mod?x+v-mod:x+v;return x;}struct node{int next,v,u,w;}p[maxn];int head[maxn],cnt,vis[maxn],n,k,maxx;void add(int u,int v){p[cnt].v=v;p[cnt].next=head[u];head[u]=cnt++;}void dfs(int now,int fa,int step){maxx++;if(step==0)return;for(int i=head[now];~i;i=p[i].next){if(p[i].v==fa)continue;dfs(p[i].v,now,step-1);}}int main(){int i,j,x,y;scanf("%d%d",&n,&k);for(i=0;i<=n;i++)head[i]=-1;for(i=0;i<n-1;i++){scanf("%d%d",&x,&y);add(x,y);add(y,x);}int ans=0;if(k%2){for(i=1;i<=n;i++){for(j=head[i];~j;j=p[j].next){maxx=0;int t=p[j].v;dfs(t,i,k/2);dfs(i,t,k/2);ans=max(maxx,ans);}}}else{for(i=1;i<=n;i++){maxx=0;dfs(i,0,k/2);ans=max(maxx,ans);}}printf("%d\n",n-ans);}


Measured memory_bytes: 3916
import java.util.*;
import java.awt.geom.*;
import java.io.*;
public class Main{

    private void doit(){
        Scanner sc = new Scanner(System.in);
        int count = 0;
        while(sc.hasNext()){
            String input = sc.next();
            if(isP(input)){
	        count++;
            }
	}
        System.out.println(count);
    }

    private boolean isP(String str){
        int len = str.length();
        int mid = len / 2;
        int start = len / 2;
        if(len % 2 == 0) start--;
	int end = len / 2;
        for(int i = 0; i + end < str.length(); i++){
	    if(str.charAt(end + i) != str.charAt(start - i)){
                return false;
            }
    	}
        return true;
    }



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

Measured memory_bytes: 11000
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans[ohara],a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll q;
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k>>q;
    rep(i,q)cin>>a[i];
    ll point=k;
    rep(i,q){
        if(a[i]==1)continue;
        point--;
    }
    ll karipo=0;
    rep(i,q){
        if(a[i]==1)karipo++;
    }
    ll sa;
    sa=-point+1;
    karipo+=sa;
    rep(i,q){
        ans[a[i]-1]++;
    }
    rep(i,n){
        if(ans[i]>=karipo)Cout("Yes");
        else Cout("No");
    }
    return 0;
}

Measured memory_bytes: 5504
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int a[] = new int[N];
		for (int i = 0; i < N; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		int ans = 0, cnt = 0, st = 0;
		for (int i = 0; i < N;) {
			if (cnt == C) {
				ans++; cnt = 0;
			} else if (cnt == 0) {
				st = a[i++] + K;
				cnt++;
			} else {
				if (a[i] <= st) {
					cnt++; i++;
				} else {
					ans++; cnt = 0;
				}
			}
		}
		if (cnt > 0) {
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50356
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100010;
int n,nn,L,R,mid,a[N],b[N],c[N<<1];
int read() {
	int tmp=0, fh=1; char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
	while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
	return tmp*fh;
}
void add(int x) {
	//printf("add %d\n",x);
	for (;x<=n*2+1;x+=(x&(-x))) c[x]++;
}
long long query(int x) {
	long long y=0;
	//printf("query %d ",x);
	for (;x;x-=(x&(-x))) y+=c[x];
	//printf("%lld\n",y);
	return y;
}
bool ok(int x) {
	int tmp=n+1;
	long long cnt=0;
	memset(c,0,sizeof(c));
	for (int i=1;i<=n;i++) {
		add(tmp); if (a[i]<=x) tmp--; else tmp++;
		cnt+=i-query(tmp);
	}
	//printf("%d %lld\n",x,cnt);
	if ((cnt-1)*4>1ll*n*(n+1)) return 1;
	return 0;
}
int main() {
	nn=n=read();
	for (int i=1;i<=n;i++) b[i]=a[i]=read();
	sort(b+1,b+n+1); nn=unique(b+1,b+n+1)-b-1;
	for (int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+nn+1,a[i])-b;
	L=0; R=nn;
	while (L+1<R) {
		mid=(L+R)>>1;
		if (ok(mid)) R=mid; else L=mid;
	}
	printf("%d\n",b[R]);
}

Measured memory_bytes: 1664
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


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

typedef long long ll;
class ATakoyaki {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n,x,t;
        cin >> n >> x >> t;

        int ans = 0;
        while (n > 0){
            ans += t;
            n -= x;
        }
        cout << ans << endl;
	}
};


int main() {
	ATakoyaki solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>

main()
{
int h,n,i,sum;

  scanf("%d %d",&h,&n);
    sum=0;
int a[n];    
  
  for(i=0;i<n;i++)
  {
  scanf("%d",&a[i]);
   sum=sum+a[i];
// printf("%d\n",a[i]);
  }

  if (sum >= h )
  {
  	printf("Yes");
  } else {
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 2400
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 305;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
    int MOD;
    inline void Inc(int &x, int y) {
        x += y; if (x >= MOD) x -= MOD;
    }
    inline void Dec(int &x, int y) {
        x -= y; if (x < 0) x += MOD;
    }
    inline int Add(int x, int y) {
        Inc(x, y); return x;
    }
    inline int Sub(int x, int y) {
        Dec(x, y); return x;
    }
    inline int Mul(int x, int y) {
        return 1LL * x * y % MOD;
    }
}
using namespace ModCalculator;

int n, k;
int C[N][N], dp[N][N], sum[N][N];

void init() {
    read(n); read(k); read(MOD);
    for (int i = 0; i <= n; ++i) {
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = Add(C[i - 1][j], C[i - 1][j - 1]);
        }
    }
}

void solve() {
    for (int j = k; j >= 0; --j) {
        dp[1][j] = 1;
        sum[1][j] = Add(sum[1][j + 1], dp[1][j]);
    }
    for (int i = 2; i <= n + 1; ++i) {
        for (int j = 0; j <= k; ++j) {
            for (int t = 1; t < i; ++t) {
                Inc(dp[i][j], Mul(dp[i - t][j], Mul(C[i - 2][t - 1], sum[t][j + 1])));
            }
        }
        for (int j = k; j >= 0; --j) {
            sum[i][j] = Add(sum[i][j + 1], dp[i][j]);
        }
    }
    printf("%d\n", dp[n + 1][0]);
}

int main() {
    init();
    solve();
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,h,w,k=0,l=0,z=0;
  cin >> h;
  cin >> w;
  int m[h],n[w];
  char a[h][w];
  for(i=0;i<h;i++){
    for (j=0;j<w;j++) {
      cin >> a[i][j];
      m[i]=9999999999;
      n[j]=9999999999;
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++) {
      if(a[i][j]=='#'){
        k=1;
        break;
      }
    }
    if(k==1){
      k=0;
      continue;
    }
    else{
      m[l]=i;
      l++;
    }
  }
  l=0;
  for(i=0;i<w;i++){
    for (j=0;j<h;j++) {
      if(a[j][i]=='#'){
        k=2;
        break;
      }
    }
    if(k==2){
      k=0;
      continue;
    }
    else{
      n[l]=i;
      l++;
    }
  }
  l=0;
  int q=0;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(i==m[l]||j==n[z]){
        if(j==n[z]){
          z++;
        }
        q++;
        continue;
      }
      else{
        cout << a[i][j];
      }
    }
    z=0;
    if(q==w){
      l++;
    }
    else{
      cout << endl;
    }
    q=0;
  }
}


Measured memory_bytes: 256
import Foundation

private func readInt() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!}
}

var queries: [(Int, Int, Int, Int)]!
var N: Int!
var M: Int!
var ans: Int = 0

func dfs(_ now: Int, _ i: Int, _ comb: [Int]) {
    guard i < N else { return }
    
    var comb = comb
    for j in (now...M).reversed() {
        comb[i] = j
        var x = 0
        for (a, b, c, d) in queries {
            if comb[b] - comb[a] == c {
                x += d
            }
        }
        ans = max(x, ans)
        dfs(j, i+1, comb)
    }
}

func mainC() {
    let line = readInt()
    N = line[0]
    M = line[1]
    let Q = line[2]
    
    queries = (1...Q).map { _ in
        let q = readInt()
        return (q[0]-1, q[1]-1, q[2], q[3])
    }
    
    dfs(1, 0, [Int](repeating: M, count: N))
    print(ans)
}

mainC()


Measured memory_bytes: 13468
def insert_sort(n:int, s:list):
    print(' '.join(map(str, s)))
    for i in range(1, len(s)):
        j = i - 1
        v = s[i]
        while (j >= 0 and s[j] > v):
            s[j + 1] = s[j]
            j -= 1
            s[j + 1] = v
        print(" ".join(map(str, s)))

insert_sort(int(input()),list(map(int,input().split(' '))))



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

int main() {
	long int i, n, t, a, h[1000], suti, min = 9999999, mina = 0;

	scanf("%ld", &n);
	scanf("%ld %ld", &t, &a);

	for (i = 0; i < n; i++) {
		scanf("%ld", &h[i]);
		suti = abs(a * 1000 - (t * 1000 - h[i] * 6));
		if (suti < min) {
			min = suti;
			mina = i + 1;
		}
	}

	printf("%ld\n", mina);

	return 0;
}

Measured memory_bytes: 128
/*A - Addition and Subtraction Easy*/
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	long long num1;
	long long num2;
	string signo;

	cin >> num1 >> signo >> num2;

	if(signo == "+")
		cout << num1 + num2;
	else
		cout << num1 - num2;

	return 0;
}

Measured memory_bytes: 256
H,W=map(int, input().split())
s=[]
for _ in range(H):
    s.append(list(input()))
x = []
y = []
for i in range(len(s)):
    if set(s[i])=={"."}: #残すのはset(i)==2
        x.append(i)
for i in range(len(s[0])):
    y_check = []
    for j in range(len(s)):
        y_check.append(s[j][i])
    if set(y_check)=={"."}:
        y.append(i)
for i in x[::-1]:
    del s[i]
for j in range(len(s)):
    for i in y[::-1]:
        del s[j][i]
for i in s:
    for j in i:
        print(j,end="")
    print("")

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int sum=0;
	for(int i=0;i<s.size();++i)
	{
		if(t[i]!=s[i]) ++sum;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REP2(a,b) for(lo j=(a);j<(b);j++)
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++
#define INF 2000000000
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 
//UVa
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
 
 
lo cel(lo x,lo y){
	if(x%y<=1)return x/y;
	else return x/y +1;
}
 void solve(){
 	lo x,y;
 	lo a,b;
 	cin>>x>>y>>a>>b;
 	if(b==1 and x+1==a){
 		cout<<'1';
 	}
 	else cout<<"0";
 }
 
int main(){
	
	
 
	lo n;
	//cin>>n;
	//while(n--)
		solve();
	
	return 0;
}

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

using namespace std;

string str;
int cnt[13];
vector<int> res;
bool f;
void dfs(int v,int a,int m){
	if(f)return;
	if(a==1 && m==4)f=true;
	if(v==10)return;
	if(cnt[v]==0)dfs(v+1,a,m);
	else{
		if(cnt[v]>=2 && a==0){
			cnt[v]-=2;
			dfs(v,a+1,m);
			cnt[v]+=2;
		}
		if(cnt[v]>=3 && m<=3){
			cnt[v]-=3;
			dfs(v,a,m+1);
			cnt[v]+=3;
		}
		if(cnt[v]>=1 && cnt[v+1]>=1 && cnt[v+2]>=1 && m<=3){
			cnt[v]-=1;
			cnt[v+1]-=1;
			cnt[v+2]-=1;
			dfs(v,a,m+1);
			cnt[v]+=1;
			cnt[v+1]+=1;
			cnt[v+2]+=1;
		}
	}
}

int main(void){
	while(cin >> str){
		res.clear();
		for(int i=1;i<=9;i++){
			memset(cnt,0,sizeof(cnt));
			for(int j=0;j<str.size();j++)cnt[str[j]-'0']++;
			if(cnt[i]==4)continue;
			f=false;
			cnt[i]++;
			dfs(1,0,0);
			cnt[i]--;
			if(f)res.push_back(i);
		}
		if(res.size()==0)puts("0");
		else{
			for(int i=0;i<res.size();i++)printf("%d%c",res[i],i==res.size()-1?'\n':' ');
		}
	}
	return 0;
}

Measured memory_bytes: 1200
using System;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var nums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var count = ToInt32(ReadLine());
        Array.Sort(nums);
        for(var i = 0; i < count; i++)
        {
            nums[2] *= 2;
        }
        WriteLine(nums[0] + nums[1] + nums[2]);
    }
}



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

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

double min(double x, double y){
    if(x<y)return x;
    return y;
}
char s[200001];
int main(void){
    scanf("%s", &s);
    int count = 0;
    int mem = 0;
    int recount = 0;
    ll ans = 0;
    for(int i = 0;s[i] != '\0';i++){
        if(s[i] == 'A'){
            count++;
            mem = 0;
            count += recount;
            recount = 0;
        }else if(s[i] == 'B'){
            mem = count;
            count = 0;
            mem += recount;
            if(s[i + 1] != 'C')recount = 0;
        }else{
            count = 0;
            ans += mem;
            recount = mem;
            mem = 0;
        }
        //printf("%d %d %d %d\n", count, mem, recount, ans);
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
  int A, B, C; cin >> A >> B >> C;
  if (A + B + C > 21) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
l = 0
T = []
while l < N:
    ch = S[l]
    r = l+1
    while r < N:
        if S[r] == ch:
            r += 1
        else:
            break
    T.append(ch)
    l = r

print(N-max(1, len(T)-2*K))


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  vector<vector<char> > v(n,vector<char>(m));
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      cin>>v[i][j];
    }
  }
  vector<vector<long long> > v1(n,vector<long long>(m));
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          v1[i][j]=0;
      }
  }
  int k=m-1;
  while(v[n-1][k]=='.')
  {
      v1[n-1][k]=1;
      if(k==0)
        break;
      k--;
  }
  k=n-1;
  while(v[k][m-1]=='.')
  {
      v1[k][m-1]=1;
      if(k==0)
        break;
      k--;
  }
  for(int i=n-2;i>=0;i--)
  {
    for(int j=m-2;j>=0;j--)
    {
        if(v[i][j]=='*')
            continue;
      if(v[i][j+1]=='.')
      {
        v1[i][j]+=v1[i][j+1];
        v1[i][j]%=1000000007;
      }
      if(v[i+1][j]=='.')
      {
        v1[i][j]+=v1[i+1][j];
        v1[i][j]%=1000000007;
      }
      v1[i][j]%=1000000007;
    }
  }
  cout<<v1[0][0]%1000000007<<endl;
  return 0;
}


Measured memory_bytes: 12064
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
  long W,H,x,y;
  cin>>W>>H>>x>>y;
 
  double val = (float)(W*H)/2.;
  int flag = (x*2 == W && y*2 == H)?1:0;
  cout<<val<<" "<<flag<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n;i>0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
namespace mp = boost::multiprecision;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;


int main() {
	int n;
	cin >> n;
	VI a(n), b(n), c(n);
	REP(i, n)cin >> a[i] >> b[i] >> c[i];

	VVI dp(100010, VI(3, 0));
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];

	FOR(i, 1, n) {
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i]);
	}
	cout << max({ dp[n - 1][0],dp[n - 1][1], dp[n - 1][2] }) << endl;
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int n, t, ans;
	while (cin >> n)
	{
		cin >> t;
		ans = n - t;
		if (ans < 0)
			cout << '0'<<endl;
		else cout << ans << endl;;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	int n, a, v, maxa, maxv;

	cin >> n >> maxa >> maxv;

	for (int i=0; i<n-1; i++)
	{
		cin >> a >> v;

		if(v == maxv){
			if(a < maxa){
				maxa = a;
				maxv = v;
			}
		}
		else if(v > maxv){
				maxa = a;
				maxv = v;
		}
	}

	cout << maxa << ' ' << maxv << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int A,B;
    cin >> A >>B;
    if((A+B)%3 == 0 || A%3 == 0 || B%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 888
N = int(input())
num = 2
idx = 1
nums = [1]
while True:
  if num**idx > N:
    if idx == 2 or N in range(1, 5):
      break
    else:
      num += 1
      idx = 0
      continue
  else:
    nums.append(num**idx)
    idx += 1
nums.sort(key=lambda x:-x)
print(nums[0])


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

            label:
            while (true) {
                String[] sArr = br.readLine().split(" ");
                int a = Integer.parseInt(sArr[0]);
                int b = Integer.parseInt(sArr[2]);
                String op = sArr[1];

                int res;

                switch (op) {
                    case "+":
                        res = a + b;
                        break;
                    case "-":
                        res = a - b;
                        break;
                    case "*":
                        res = a * b;
                        break;
                    case "/":
                        res = a / b;
                        break;
                    case "?":
                        break label;
                    default:
                        throw new RuntimeException();
                }

                System.out.println(res);
            }

        }
    }
}



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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n, k;
    cin >> n >> k;

    ll r, q, p;
    cin >> r >> q >> p;

    string s;
    cin >> s;

    string ss;

    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (i - k >= 0) {
            if (s[i] == 'r') {
                if (ss[i - k] == 'p') {
                    ss += 'o';
                } else {
                    ss += 'p';
                    cnt += p;
                }

            } else if (s[i] == 's') {
                if (ss[i - k] == 'r') {
                    ss += 'o';
                } else {
                    ss += 'r';
                    cnt += r;
                }
            } else if (s[i] == 'p') {
                if (ss[i - k] == 's') {
                    ss += 'o';
                } else {
                    ss += 's';
                    cnt += q;
                }
            }

        } else {
            if (s[i] == 'r') {
                ss += 'p';
                cnt += p;
            } else if (s[i] == 's') {
                ss += 'r';
                cnt += r;
            } else if (s[i] == 'p') {
                ss += 's';
                cnt += q;
            }
        }
    }

    cout << cnt << endl;
}

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

int main(void)
{
	string a, b;
	cin >> a >> b;

	for (int i = 0; i < a.length(); i++) {
		if (b[i] == NULL) {
			cout << a[i];
			break;
		}

		cout << a[i] << b[i];

	}
	return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef vector < int > vi;
typedef pair<int,int> pi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(i,a,b) for(ll i=a;i<b;i++)
//add below to remove endl in input just before getline()
//cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int d,n,c=0;
	cin>>d>>n;
	for(int i=0;;i++){
		if(i%100!=0){
			c++;
			if(c==n){cout<<i;break;}
			}
		}
		if(d==1)cout<<"00";
		else if(d==2)cout<<"0000";

	
return 0;}


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

int main(){
  int n;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  b[0] = 0;
  b[1] = abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
  	b[i] = min(b[i-2]+abs(a[i-2]-a[i]),b[i-1]+abs(a[i-1]-a[i]));
  }
  cout<<b[n-1];
}

Measured memory_bytes: 1024
n=int(input())
h=list(map(int,input().split()))

dp=[10**9]*(n+1)


dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i>1:
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

Measured memory_bytes: 52208
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A, B;
  cin >> A >> B;

  if(A + B < 10) cout << A + B << endl;
  else cout << "error" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back



int N;
int A[200005],B[200005];
pair<int,int> AB[200005];
int ans=0;
int mod=1000000007;
int use=0;
signed main(){
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld %lld",&A[i],&B[i]);
        AB[i]=mp(B[i],A[i]);
        use=max(use,B[i]);
    }
    sort(AB,AB+N,greater< pair<int,int> >());
    rep(i,N){
        use=min(use,AB[i].first)-AB[i].second;
        if(use<0){printf("No\n");return 0;}
    }
    printf("Yes\n");return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		else a=a*a%MOD;
		b>>=1;
	}
	return res;
}
*/


ll digitSum(ll n,ll b){
	ll ret=0;
	while(n){
		ret+=n%b;
		n/=b;
	}
	return ret;
}

int main()
{
	//IOS;
	ll n,s;
	cin>>n>>s;

	if(n==s){
		cout<<n+1<<'\n';
		return 0;
	}

	for(int i=2;i<320000;i++){
		if(digitSum(n,i)==s){
			cout<<i<<'\n';
			return 0;
		}
	}

	ll meow=n-s;
	if(meow<0){
		cout<<-1;
		return 0;
	}

	for(int i=320000;i>=1;i--){
		if(meow%i) continue;
		ll b=meow/i+1;
		if(n%b+n/b%b+n/b/b==s){
			cout<<b<<'\n';
			return 0;
		} 
	}
	cout<<-1;

	return 0;
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i += 1)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX_N 100000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<ll> A;
ll N,M;

bool judge(ll x){
    ll res = 0;
    Rep(i,N){
        res += A.end()-lower_bound(All(A),x-A[i]);
    }
    if(res >= M)return true;
    else return false;
}

int main(){
    cin >> N >> M;
    vector<ll> Sum(N+1,0);
    Rep(i,N){
        ll a;
        cin >> a;
        A.push_back(a);
    }
    sort(All(A));
    Rep(i,N){
        Sum[i+1] = Sum[i] + A[i];
    }
    sort(All(A));
    ll l = 0;
    ll r = 250000;
    while(r-l > 1){
        ll m = (l+r)/2;
        if(judge(m)){
            l = m;
        }else{
            r = m;
        }
    }
    //cout << l << endl;
    ll count = 0;
    ll ans = 0;
    Rep(i,N){
        ll j = lower_bound(All(A),l+1-A[i])-A.begin();
        ans += Sum[N]-Sum[j] + (N-j)*A[i];
        count += (N-j);
        //cout << i << sp << j << sp << ans << endl; 
    }
    ans += (M-count)*l;
    cout << ans << endl;
    //cin >> N;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > A(N);
	vector<int> D(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
		D[i] = A[i].first;
		A[i].second = i;
	}
	vector<vector<pair<int, int> > > g(N);
	int INF = 1000000000;
	vector<int> res(M, INF);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}
	sort(A.begin(), A.end());
	string col(N, '.');
	for (int i = 0; i < N; i++) {
		int val = A[i].first;
		int idx = A[i].second;
		if (col[idx] != '.') continue;
		bool ok = false;
		for (const pair<int, int> &p : g[idx]) {
			if (col[p.first] != '.') {
				col[idx] = (col[p.first] == 'B' ? 'W' : 'B');
				res[p.second] = val;
				ok = true;
				break;
			}
		}
		if (!ok) {
			queue<int> qu;
			qu.push(idx);
			col[idx] = 'B';
			while (qu.size() > 0) {
				int a = qu.front();
				qu.pop();
				for (const pair<int, int> &p : g[a]) {
					if (col[p.first] == '.') {
						if (D[p.first] == val) {
							col[p.first] = (col[a] == 'B' ? 'W' : 'B');
							res[p.second] = val;
							ok = true;
							qu.push(p.first);
						}
					}
				}
			}
		}
		if (!ok) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << col << endl;
	for (int i = 0; i < M; i++) {
		cout << res[i] << endl;
	}
}

Measured memory_bytes: 18432
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    N, M = [int(x) for x in input().split()]
    isAC = [False] * (N+1)
    cntWA = [0] * (N+1)
    cntAC = 0
    cntPN = 0
    for i in range(M):
        p, s = input().split()
        p = int(p)
        if not isAC[p]:
            if s == "AC":
                isAC[p] = True
                cntAC += 1
            else:
                cntWA[p] += 1
    for i in range(1, N+1):
        if isAC[i]:
            cntPN += cntWA[i]

    return " ".join([str(cntAC), str(cntPN)])


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 14804
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var H int
	fmt.Scan(&H)
	sum := 1
	kotai := 1
	for {
		H = H / 2
		if H == 0 {
			break
		}
		kotai *= 2
		sum += kotai
	}

	fmt.Fprintln(wtr, sum)
	_ = wtr.Flush()
}


Measured memory_bytes: 1844
A, B, M = map(int, input().split())
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mlenzi=100000
mzouko=100000
mPrice = 200000
for i in range(A):
  if lenzi[i]<mlenzi:
    for j in range(B):
      if zouko[j]<mzouko:
        if lenzi[i]+zouko[j]<mPrice:
          mPrice=lenzi[i]+zouko[j]
        mzouko=zouko[j]
    mlenzi=lenzi[i]
for i in range(M):
  x, y, c = map(int, input().split())
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)

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

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

  vector<int> t_s;
  for (int i=0; i<n; i++) {
    int t;
    cin >> t;
    t_s.push_back(t);
  }

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

  int i=0, ans=0;
  while (i<n) {
    i = min(i+c, (int)(upper_bound(t_s.begin(), t_s.end(), t_s[i] + k) - t_s.begin()));
    ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ll n;
	cin >> n;
	if(n == 2){
		cout << "2";
		return 0;
	}
	if(n == 1){
		cout << "0";
		return 0;
	}
	ll x = 1, y = 2, z = 1;
	for(int i = 1; i <= n; ++i){
		x = (x * 10) % mod;
		y = (y * 9) % mod;
		z = (z * 8) % mod;
	}

	ll ans = (x - y + z + mod) % mod;
 	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
using System;
public class Hello{
    public static void Calc(string str)
    {
        
    }
    
    public static string target;
    
    public static void Main(){
        target=" "+Console.ReadLine()+" ";
        string str;
        int correct=0;
        int ans=0;
        
        while(true)
        {
            str=" "+Console.ReadLine()+" ";
            //Console.WriteLine(str);
            if(str==" END_OF_TEXT ")break;
            for(int i=0;i<str.Length;i++)
            {
                if(target[correct]==str[i]||
                   (char)((int)target[correct]^0x20)==str[i])correct++;
                else if(str[i]==' ')correct=1;
                else correct=0;
                
                if(correct==target.Length)
                {
                    ans++;
                    //Console.Write(i+" ");
                    correct=1;
                }
            }
            correct=0;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 15812
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int f(ll x, ll y) {
  int a, b;
  a = b = 0;
  while (x > 0) {
    x /= 10;
    a++;
  }
  while (y > 0) {
    y /= 10;
    b++;
  }
  return max(a, b);
}

int main() {
  ll n;
  cin >> n;
  int mi = 50;
  for (ll i = 1; i <= n/i; i++) {
    if (n%i == 0) mi = min(mi, f(i, n/i));
  }
  dump(mi);
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<ll> B;
    ll sum = 0, minuscnt = 0;
    for(int i = 0; i < N;i++){
        ll A; cin >> A;
        if(A >= 0){
            B.push_back(A);
            sum += A;
        }
        else{
            B.push_back(-A);
            sum -= A;
            minuscnt++;
        }
    }
    if(minuscnt % 2 == 0) cout << sum << endl;
    else{
        sort(B.begin(), B.end());
        sum -= 2 * B[0];
        cout << sum << endl;
    }
}

Measured memory_bytes: 1528
from fractions import gcd

def lcm(*args):
    ans = 1
    for x in args:
        ans = ans * x // gcd(ans, x)
    return ans

n, m = map(int, input().split())
a = [int(x) for x in input().split()]

def log(x):
    ans = 0
    while x % 2 == 0:
        ans += 1
        x //= 2
    return ans

def solve(a):
    tmp = None
    for ta in a:
        if tmp is None:
            tmp = log(ta)
        else:
            if tmp == log(ta):
                continue
            else:
                print(0)
                return
    l = lcm(*a)
    print(m // (l//2) - m // l)

solve(a)

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

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

    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        int cnt = 0;
        for (char c = 'a'; c <= 'z'; ++c)
        {
            bool left = false, right = false;
            for (int j = 0; j < i; j++)
                if (s[j] == c)
                    left = true;

            for (int j = i; j < n; j++)
                if (s[j] == c)
                    right = true;

            if (left && right)
                cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256