akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a;
    cin>>n;
    vector<ll> A,B,C;
    for(int i=0;i<n;i++){
        cin>>a;
        A.push_back(a);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        B.push_back(a);
    }
    for(int i=0;i<n-1;i++){
        cin>>a;
        C.push_back(a);
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=B[A[i]-1];
    }
    for(int i=0;i<n-1;i++){
        if(A[i]+1==A[i+1]) ans+=C[A[i]-1];
    }
    cout<<ans;
    return 0;
}


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

int main() {
    ll A;
    double B;
    cin >> A >> B;
    ll B2 = B*100 + 0.001;
    ll ans = A*B2;
    ans /= 100;
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[300001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i = 0; i < 3*n; i++) cin>>a[i];
	sort(a,a+3*n);
	reverse(a,a+3*n);
	ll ans=0;
	for(int i = 1; i < 2*n; i+=2)
	{
		ans+=a[i];
	}
	cout<<ans<<'\n';
}	


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, 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  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, k;
string s;

int main() {
	cin >> n >> k >> s;
	
	int c = 0, d = 0;
	inc(i, n - 1) { if(s[i] == s[i + 1]) { c++; } else { d++; } }
	
	int ans = c + min(d, 2 * k);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> A(m);
    for (int i = 0; i < m; i++) cin >> A[i];
    int l = 0, r = 0;
    for (int i = 0; i < m; i++) {
        if (A[i] < x) l++;
        if (A[i] > x) r++;
    }
    cout << min(l, r) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
hl = [a[-1] * -1]
a.pop()
# a = a[::-1]

heapq.heapify(hl)
ans = 0

while (a):
    now = a.pop()
    ans += heapq.heappop(hl) * (-1)
    for i in range(2):
        heapq.heappush(hl, now * -1)

print(ans)


Measured memory_bytes: 31560
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii\                               
  ios_base::sync_with_stdio(false);\                                      
  cin.tie(NULL);\
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	ll n,k;cin>>n>>k;
	ll s[n+1];
	s[0] = 0;
	rep(i,1,n+1) s[i] = s[i-1] + i;
	ll ans = 0;
	rep(i,k,n+1){
		ll temp  = mod(s[n] - s[n - i]);
		temp = mod(temp - s[i-1] + 1);
		//cout<<temp<<endl;
		ans = mod(ans + temp);
		//cout<<i<<ans<<endl;
	}
	cout<<mod(ans+1)<<endl;
    
}


Measured memory_bytes: 5180
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
grid=[None]*H
for i in range(H):
    grid[i]=input().split()
for i in range(H):
    for j in range(W):
        if grid[i][j]=='snuke':
            print(chr(j+65)+str(i+1))
            exit()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const LL mb=1e18;
LL k;int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	scanf("%lld",&k);
	if (abs(a-b)>mb) printf("Unfair");
	else  
	if (k%2) printf("%d",b-a);
	else printf("%d",a-b);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


i64 n, a[5];

int main(){
	cin >> n;
	for(int i = 0; i < 5; i++) cin >> a[i];
	
	i64 cnt = 0;
	for(int i = 0; i < 5; i++){
		cnt = max(cnt, n / a[i] + !!(n%a[i]));
	}
	
	cout << cnt + 4 << endl;
	
	return 0;
}

Measured memory_bytes: 256
//##MohK
//14/03/2020... 2,23.
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a;
    cin>>a;
    if(a==1)cout<<1<<endl;
    else if(a==2)cout<<1<<endl;
    else if(a==3)cout<<1<<endl;
    else if(a==4)cout<<2<<endl;
    else if(a==5)cout<<1<<endl;
    else if(a==6)cout<<2<<endl;
    else if(a==7)cout<<1<<endl;
    else if(a==8)cout<<5<<endl;
    else if(a==9)cout<<2<<endl;
    else if(a==10)cout<<2<<endl;
    else if(a==11)cout<<1<<endl;
    else if(a==12)cout<<5<<endl;
    else if(a==13)cout<<1<<endl;
    else if(a==14)cout<<2<<endl;
    else if(a==15)cout<<1<<endl;
    else if(a==16)cout<<14<<endl;
    else if(a==17)cout<<1<<endl;
    else if(a==18)cout<<5<<endl;
    else if(a==19)cout<<1<<endl;
    else if(a==20)cout<<5<<endl;
    else if(a==21)cout<<2<<endl;
    else if(a==22)cout<<2<<endl;
    else if(a==23)cout<<1<<endl;
    else if(a==24)cout<<15<<endl;
    else if(a==25)cout<<2<<endl;
    else if(a==26)cout<<2<<endl;
    else if(a==27)cout<<5<<endl;
    else if(a==28)cout<<4<<endl;
    else if(a==29)cout<<1<<endl;
    else if(a==30)cout<<4<<endl;
    else if(a==31)cout<<1<<endl;
    else if(a==32)cout<<51<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

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

		final int M = sc.nextInt();
		final int N = sc.nextInt();
		
		int max = 0;
		for(int i = 0; i < M; i++){
			int count = 0;
			
			for(int j = 0; j < N; j++){
				if(sc.nextInt() == 1){
					count++;
				}
			}
			
			max = Math.max(count, max);
		}
		
		System.out.println(max);
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,mx=-1,res,hs=1;
  cin>>n;
  for(int i=2;i<=n;i++){
    cout<<"? "<<1<<" "<<i<<endl;
    cout.flush();
    cin>>res;
    if(res>mx)mx=res,hs=i;
  }
  int ans[100001]={};
  ans[0]=hs;
  for(int i=1;i<=n;i++){
    cout<<"? "<<hs<<" "<<i<<endl;
    cout.flush();
    cin>>res;
    ans[res]=i;
  }
  cout<<"! ";
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcopy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

char s[32];int n;

int main(){
	scanf("%s",s);n=strlen(s);
	int t=0,r=0;
	fore(i,0,n){
		r=max(r,t+s[i]-'0'-1+9*(n-1-i));
		t+=s[i]-'0';
	}
	r=max(r,t);
	printf("%d\n",r);
	return 0;
}

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

using namespace std;

int n, m;
string s[105];
int dp[105][105];
bool can[100][100];

signed main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		cin>>s[i];
		s[i]='!'+s[i];
	}
	for(int i=1; i<=max(m, n); i++)
	{
		dp[0][i]=1000000000;
		dp[i][0]=1000000000;
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(s[i][j]=='.')
			{
				dp[i][j]=min(dp[i-1][j], dp[i][j-1]);
			}
			else
			{
				dp[i][j]=1000000000;
				can[i][j]=1;
				// cout<<i<<" "<<j<<" "<<can[i][j]<<endl;
				for(int k=i; k>=1; k--)
				{
					for(int l=j; l>=1; l--)
					{
						if(k<i||l<j) can[k][l]=false;
						if(s[k][l]=='.') continue;
						if(k<i) can[k][l]|=can[k+1][l];
						if(l<j) can[k][l]|=can[k][l+1];
						if(can[k][l])
						{
							// cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<can[k][l]<<endl;
							dp[i][j]=min(dp[i][j], min(dp[k-1][l], dp[k][l-1])+1);
						}
					}
				}
				if(can[1][1]) dp[i][j]=min(dp[i][j], 1);
			}
			if(i==j&&i==1) dp[i][j]=(s[i][j]=='#');
		}
	}
	cout<<dp[n][m];
}

Measured memory_bytes: 384
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	int cout = 0;
	int x = 1;
	while(x < k) {
		x *= 2;
		cout++;
		if(cout == n) {
			break;
		}
	}
	for(int i = cout + 1; i <= n; i++) {
		x += k;
	}
	System.out.println(x);
}
}

Measured memory_bytes: 23764
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

int main()
{

	ll i, j, k, l, m, flag, N, M, K, H, W, X, P,B,C;
	cin >> N >> H >> W;
	output((N - H + 1)*(N - W + 1));

	return 0;
}





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

using namespace std;

int main(){

    int a,b,c,d;
    
    scanf("%d %d %d",&a,&b,&c);
    
    d=a+b;
    
    if(d>=c) printf("Yes");
    
    else printf("No");
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
const long long  mod = 1e9+7;
const long long base = 31;
char s[330][330];
long long  n,a,b,hashline[330],hashrow[330],poww[330],ans,map[330][330],tmp[330][330];
int main()
{
	cin>>n;
	poww[0]=1;
	for(long long  i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(long long  j=1;j<=n;j++) map[i][j]=s[i][j]-'a'+1;
		poww[i]=poww[i-1]*base%mod;
	}
	//for(int i=1;i<=n;i++)
	//for(int j=1;j<=n;j++) cout<<map[i][j]<<endl;
	for(long long  a=0;a<=n-1;a++)
	{
		//cout<<a<<endl;
		for(long long  i=1;i<=n;i++)
		{
			for(long long  j=1;j<=n;j++)
			{
				long long k=i+a;
				if(k>n) k-=n;;
				tmp[i][j]=map[k][j];
		//		cout<<tmp[i][j];
			}
		//	cout<<endl;
		}
	//	for(int i=1;i<=n;i++) puts(tmp[i]);
	//	cout<<endl;
		memset(hashrow,0,sizeof(hashrow));
		memset(hashline,0,sizeof(hashline)); 
		for(long long  i=1;i<=n;i++)
		{
			for(long long  j=1;j<=n;j++)
			{
				hashrow[i]=(hashrow[i]*base+tmp[i][j])%mod;
				hashline[i]=(hashline[i]*base+tmp[j][i])%mod;
			}
		//	cout<<hashrow[i]<<" "<<hashline[i]<<endl;
		}
		for(long long  b=0;b<n;b++)
		{
			int flag=0;
			if(b==0) flag=1;
			if(flag==0)
			{
				for(long long  i=1;i<=n;i++)
				{
					hashrow[i]=(long long )((hashrow[i]-tmp[i][b]*poww[n-1])%mod*base%mod+mod+tmp[i][b])%mod;
				}
				long long  tt=hashline[1];
				for(long long  i=2;i<=n;i++)
				{
					hashline[i-1]=hashline[i];
				}
				hashline[n]=tt;
			//	for(int i=1;i<=n;i++) cout<<hashrow[i]<<" "<<hashline[i]<<endl;
			}
			int op=1;
			for(int i=1;i<=n;i++)
			if(hashline[i]!=hashrow[i]) op=0;
			ans+=op; 
		} 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1920
#!/usr/bin/env python3


def solve(n, m, subs):
    is_ac = [False] * n
    num_wa = [0] * n
    total_ac = 0
    total_wa = 0
    for p, s in subs:
        if s == "AC":
            if not is_ac[p]:
                is_ac[p] = True
                total_ac += 1
                total_wa += num_wa[p]
        else:
            if not is_ac[p]:
                num_wa[p] += 1
    return total_ac, total_wa


def main():
    n, m = (int(x) for x in input().split())
    subs = []
    for _ in range(m):
        p0, s = input().split()
        subs.append((int(p0) - 1, s))
    res = solve(n, m, subs)
    print(*res)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

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

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

    int cnt = 0;
    int now = 1;
    for(int i = 0; i < n; i++) {
        if(now == a[i]) {
            now++;
        } else {
            cnt++;
        }
    }

    if(now == 1) {
        cout << -1 << endl;
    } else {
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 4376
#include <iostream>

using namespace std;

int main()
{
    int64_t a=2,b=1,c,n;
    cin>>n;
    if(n==1){
        cout<<"1";
        return 0;
    }
    for(int i=1;i<n;i++){
        c=a+b;
        a=b;
        b=c;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) { cin >> a[i]; }
    if(*min_element(a.begin(), a.end()) > 1) {
        cout << -1 << endl;
        return 0;
    }
    int cur = 1;
    REP(i, N) {
        if(a[i] == cur) {
            cur++;
        }
    }
    cout << N - cur + 1 << endl;
    return 0;
}

Measured memory_bytes: 1792
def main():
    N = int(input())

    paper = []
    for i in range(N):
        paper.append(int(input()))

    # TimSortっていうMergeSortの改良版らしい
    paper.sort()

    preNum = paper[0]
    sameNumCount = 1
    ans = 0
    for num in paper[1:]:
        if preNum == num:
            sameNumCount += 1
        else:
            ans += sameNumCount % 2
            preNum = num
            sameNumCount = 1
    # 一番最後の判定
    if paper[-1] == preNum:
        ans += sameNumCount % 2

    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    double l;
    cin >> l;
    double ans = (l/3)*(l/3)*(l/3);
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3728
S = list(input())
Q = int(input())
Query = [list(input().split()) for i in range(Q)]

from collections import deque

q = deque(S)

r = 0  #反転の有無

for i in range(Q):
    if Query[i][0] == '1':
        r = 1-r
    else:
        if (r + int(Query[i][1])) % 2 == 1:
            q.appendleft(Query[i][2])
        else:
            q.append(Query[i][2])

A = list(q)

if r % 2 == 1:
    A.reverse()

ans = ''
for i in range(len(A)):
    ans += A[i]

print(ans)

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

int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=3005;
int S[MAXN][MAXN],C[MAXN][MAXN];
int n,mod;
void init()
{
	S[0][0]=1;
	for(int i=0;i<MAXN;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
			S[i][j]=(S[i-1][j-1]+1LL*S[i-1][j]*j)%mod;
		}
	}
}
int pow_mod(int a,int b,int md)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1LL*ret*a%md;
		a=1LL*a*a%md;b>>=1;
	}
	return ret;
}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	n=read();mod=read();
	init();int ans=0;
	for(int i=0;i<=n;i++)
	{
		int sum=1LL*pow_mod(2,pow_mod(2,n-i,mod-1),mod)*C[n][i]%mod,num=0;
		for(int k=0;k<=i;k++)ad(num,1LL*pow_mod(pow_mod(2,n-i,mod),k,mod)*S[i+1][k+1]%mod);
		if(i&1)dl(ans,1LL*sum*num%mod);
		else ad(ans,1LL*sum*num%mod);
	}
	pr2(ans);
	return 0;
}


Measured memory_bytes: 69376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
ll fac[maxn], inv[maxn], f[maxn];
ll qpow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
void pre(int n)
{
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		fac[i] = fac[i - 1] * i % mod;
	}
	inv[n] = qpow(fac[n], mod - 2);
	for (int i = n - 1; i >= 0; i--)
	{
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
}
ll C(ll n, ll m)
{
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
	int n;
	cin >> n;
	ll ten = 10, nine = 9;
	for (int i = 2; i <= n; i++)
	{
		f[i] = 2 * ((ten - nine + mod) % mod) % mod;
		ten = ten * 10 % mod;
		nine = nine * 9 % mod;
		f[i] = (f[i] + 8 * f[i - 1] % mod) % mod;
	}
	cout << f[n] % mod << endl;
	return 0;
}

Measured memory_bytes: 11384
#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[200005];
    scanf("%s",s);
    int i=0;//文字数
    while(strncmp(&s[i], "\0", 1)!=0) i++;
    int a=0, z=i-1; 
    while(strncmp(&s[a], "A", 1)!=0) a++;
    while(strncmp(&s[z], "Z", 1)!=0) z--;
    printf("%d", z-a+1);
    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))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

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

    cout << n*n << endl;


    return 0;
}


Measured memory_bytes: 256
import sys

h, w, d = map(int, sys.stdin.readline().split())
a = [[int(x) for x in sys.stdin.readline().split()] for _ in range(h)]
q = int(sys.stdin.readline().rstrip())
lr = zip(*[map(int, sys.stdin.read().split())] * 2) 

def main():
    place = [None] * (h * w + 1)
    for i in range(h):
        for j in range(w):
            place[a[i][j]] = (i, j)
    
    cost = [0] * (h * w + 1)
    cost[0] = None
    for x in range(1, 1+d):
        while x + d <= h * w:
            nex = x + d
            i, j = place[x]
            k, l = place[nex]
            cost[nex] = cost[x] + abs(j - l) + abs(i - k)
            x = nex

    for l, r in lr:
        yield cost[r] - cost[l]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class APassword {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        cout << N * N * N << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    APassword solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
// Problem : A - The Number of Even Pairs
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()
using namespace std;
using namespace __gnu_pbds;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
template<class T>
T abst(T a)
{return a<0?-a:a;}
template<class T> using ordered_set=tree<
T,
null_type,
less_equal<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;cin>>n>>m;
cout<<(n*(n-1)/2+m*(m-1)/2);
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
}


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

struct Edge {
    int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
    int k = 1;
    rep(i, g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if(u == p) continue;
        if(k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u, ans[ei], v);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n - 1);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back((Edge){b, i}); 
        g[b].push_back((Edge){a, i});
    }

    dfs(0);
    
    int mx = 0;
    rep(i, n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i, n - 1) {
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 10112
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto H = RD;
	auto W = RD;
	auto A = RD;
	auto B = RD;

	auto ans = new long[][](H, W);
	foreach (y; 0..H)
	{
		if (y < B)
		{
			foreach (x; 0..A)
			{
				ans[y][x] = 1;
			}
		}
		else
		{
			foreach (x; A..W)
			{
				ans[y][x] = 1;
			}
		}
	}

	foreach (y; 0..H)
		ans[y].map!(to!string).join("").writeln;
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 12156
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

using Graph = vector<vector<pair<int,LL>> >;
Graph G;
vector<LL> dis;

// v は現在見ている頂点, p は v の親
void dfs(int v, int p ,LL sum) {
    dis[v] = sum;
    if(G[v].size() == 1 && v != 0)return;
    for (auto nv : G[v]) {
        if (nv.F == p) continue;  // これがツリー探索で一般的な書き方
        dfs(nv.F, v, sum + nv.S);
    }
}


int main() {
    int N;cin >> N;
    G.resize(N);
    rep(i,N-1){
        int a,b;
        LL c;
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    dis.resize(N);
    dis[0] = 0;
    dfs(0,-1,0);

    rep(i,N){
        if(dis[i] % 2 == 0)cout << 0 << endl;
        else cout << 1 << endl;
    }
}

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

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

	vector<int> h(n);

	int mxh = 0;
	string ans = "Yes";

	for(int i=0; i<n; i++){
		cin >> h[i];

		if(h[i]>mxh){
			mxh = h[i];
		}

		if(h[i]<mxh-1){
			ans = "No";
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <string>

int main()
{
  std::string a, b;

  std::cin >> a >> b;

  a.append(b);

  int x;
  
  x = stoi(a, nullptr, 10);

  int ans = sqrt(x);
  
  if (ans * ans == x) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }


  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int ab = 0, b_a = 0, a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') {
        ab++;
      }
    }

    if (s[0] == 'B' && s[s.size() - 1] == 'A') {
      b_a++;
    } else if (s[0] == 'B') {
      b++;
    } else if (s[s.size() - 1] == 'A') {
      a++;
    }
  }

  if (b_a == 0) {
    cout << min(a, b) + ab << endl;
  } else if (a + b > 0) {
    cout << min(a, b) + b_a + ab << endl;
  } else {
    cout << b_a - 1 + ab << endl;
  }
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(10000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    s = input()
    t = input()
    ans = 10**9
    for i in range(len(s)-len(t)+1):
        cnt = 0
        for j in range(len(t)):
            if s[i+j] != t[j]:
                cnt+=1
        ans = min(ans,cnt)
    print(ans)

Measured memory_bytes: 73964
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    int ans = d[n/2] - d[n/2-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    map<long long,int>a;
    for(int i=0;i<N;i++){
        long long aa;
        cin >> aa;
        a[aa]++;
    }
    vector<long long>v;
    for(auto l:a){
        if(l.second>=2){
            if(l.second>=4){
                v.push_back(l.first);
            }
            v.push_back(l.first);
        }
    }
    if(v.size()<2){cout << 0 << endl;}
    else{
        sort(v.begin(),v.end(),greater<long long>());
        cout << v[0]*v[1] << endl;
    }


    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, h[100], maxi = -1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if(h[i] > maxi) maxi = h[i];
	}
	// cout << maxi << endl;
	int ans = 0;
	for (int i = maxi; i >= 1; i--) {
		bool exist = 0;
		for (int j = 0; j < n; j++) {
			if(h[j] == i) {
				exist = 1;
				h[j]--;
			}
			else if(exist && h[j] != i) {
				ans++;
				exist = 0;
			}
		}
		if(exist) ans++;
	}
	cout << ans << endl;

	return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    ll ans = 0;
    for ( ll i = 1; i <= N; i++ ) {
        if ( i % 3 == 0 || i % 5 == 0 ) continue;
        ans += i;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3636
n=int(input())
e=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a].append(b)
  e[b].append(a)
c=list(map(int,input().split()))
c.sort()
print(sum(c[:-1]))

c.reverse()
ans=[0 for i in range(n)]
ans[0]=c[0]
k=1

s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
  s=ns
print(" ".join(map(str,ans)))


Measured memory_bytes: 76780
#include<bits/stdc++.h>
using namespace std;
string a;
bool b;
int main(){
	cin>>a;
	int la=a.length();
	for(int i=0;i<la;i++){
		if(a[i]=='C') b=1;
		if(a[i]=='F'&&b==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int Partition(int *A,int p,int r){
  int j,n1,n2,x,i;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      n1=A[i];
      A[i]=A[j];
      A[j]=n1;
    }
  }
  n2=A[i+1];
  A[i+1]=A[r];
  A[r]=n2;
  return i+1;
}
 
main(){
  int n,i,A[100000],x;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  x=Partition(A,1,n);
  for(i=1;i<=n;i++){
    if(i!=x && i!=n)printf("%d ",A[i]);
    else if (i==x)printf("[%d] ",A[i]);
    else if(i== n) printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}

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

int main()
{
    int n, k, i;
    cin>>n>>k;
    char a[n];

    for(i=0; i<n; i++)
        cin>>a[i];

    for(i=0; i<n; i++)
    {
        if(i== (k-1))
        {
            a[i] = a[i] + 32;

            cout<<a[i];
        }


        else
            cout<<a[i];
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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

  ll K, T;
  cin >> K >> T;
  vector<ll> a;
  rep(i,T){
    ll inp; cin >> inp;
    a.pb(inp);
  }
  sort(rall(a));

  ll ret = 0;
  rep(i,T){
    ret += a[i];
  }
  cout << max((ll)0, a[0]+a[0]-ret-1 ) << endl;;
  
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static int[] ToInt (string[] str)
        {
            int len = str.Length;
            int[] intAry = new int[len];
            for (int i = 0; i < len;i++)
            {
                intAry[i] = int.Parse(str[i]);
            }
            return intAry;
        }
        static void Main(string[] args)
        {
            int[] IntAry = ToInt(Console.ReadLine().Split());
            if(IntAry[0] <= IntAry[1])
            {
                Console.WriteLine("unsafe");
            }else{
                Console.WriteLine("safe");
            }
            
        }
    }
}


Measured memory_bytes: 27480
#include <stdio.h>
int main (){
	int input, digit1, digit2,digit3;
	scanf("%d",&input);
	
	digit3= input%10;
	digit2= (input%100- input%10)/10;
	digit1= input/100;
	
	if (digit1==7||digit2==7||digit3==7){
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1732
#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, K, ans=0; cin >> A >> B >> C >> K;
if(K<=A){ cout << K << "\n"; return 0; }
if(K<=A+B){ cout << A << "\n"; return 0; }
cout << A-(K-(A+B)) << "\n";
}

Measured memory_bytes: 3636
len = int(input())
nums = [int(i) for i in input().split()]

af = 0
for i in nums:
  if i % 2 == 0:
    if (i % 3 == 0) | (i % 5 == 0):
      pass
    else:
      af = 1
      break
if af == 1:
  print('DENIED')
else:
  print('APPROVED')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b;
  cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
  return 0;
}


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

using namespace std;

int n;
map<char, int> mp;

void solve() {
    string s; cin >> s;
    for(int j = 0; j < s.size(); j++) {
        mp[s[j]]++;
    }
    for(int i = 1; i < n; i++) {
        map<char, int> tmp;
        cin >> s;
        for(int j = 0; j < s.size(); j++) {
            tmp[s[j]]++;
        }
        for(char k = 'a'; k <= 'z'; k++) {
            if(mp[k] >= tmp[k]) mp[k] = tmp[k];
        }
    }
    for(char k = 'a'; k <= 'z'; k++) {
        for(int i = 0; i < mp[k]; i++) {
            cout << k ;
        }
    }
    cout << endl;
    
}

int main() {
    cin >> n;
    solve();
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

// https://github.com/akiradeveloper/rust-comp-snippets/ \
// blob/fabb6a9811a955db3546f682679010e61022c472/src/union_find.rs
pub struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            par: (0..n).collect::<Vec<usize>>(),
            rank: vec![1; n],
        }
    }

    pub fn size(&mut self, x: usize) -> usize {
        let y = self.root(x);
        self.rank[y]
    }

    pub fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    pub fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            return x;
        } else {
            let y = self.par[x];
            let z = self.root(y);
            self.par[x] = z;
            return z;
        }
    }

    pub fn merge(&mut self, x: usize, y: usize) -> bool {
        let mut a = self.root(x);
        let mut b = self.root(y);
        if a == b {
            return false;
        }

        if self.rank[a] < self.rank[b] {
            std::mem::swap(&mut a, &mut b);
        }
        assert!(self.rank[a] >= self.rank[b]);

        self.rank[a] += self.rank[b];
        self.par[b] = a;
        return true;
    }
}

fn main() {
    input! {
        S: String,
    }

    // 偶数回動かすことになるので、2回後の変化に着目する

    // まず、それがゴールとなるマスかどうかを判定する O(N)

    // グループの情報をUnion Find木で表現する
    // 2回後に行くノードと同じグループにまとめる (O(N * a(n)))

    // それぞれのマスに対して、
    // ゴールとなるマスでないなら → 0
    // ゴールとなるマスならば → nodes()
    // UnionFind木をまとめる時に、そのノード数の情報も持っておくと良さそう

    let N = S.len();
    let mut isGoal = Vec::new();
    isGoal.resize(N, false);

    for i in 0..N {
        if i != N - 1 && &S[i..i + 1] == "R" && &S[i + 1..i + 2] == "L" {
            isGoal[i] = true;
        } else if i != 0 && &S[i..i + 1] == "L" && &S[i - 1..i] == "R" {
            isGoal[i] = true;
        }
    }


    let mut union_find = UnionFind::new(N);

    // まとめていく
    for i in 0..N {
        if isGoal[i] {
            continue;
        }

        // 問題文の制約から、境界をはみ出すことは無い
        let mut next = i;
        if &S[i..i + 1] == "R" {
            next = i + 1;
        }
        if &S[i..i + 1] == "L" {
            next = i - 1;
        }

        // 同じ処理をしているので、関数化も視野
        let mut next_next = next;
        if &S[next..next + 1] == "R" {
            next_next = next + 1;
        }
        if &S[next..next + 1] == "L" {
            next_next = next - 1;
        }

        // i と next_nextをマージ
        union_find.merge(i, next_next);
    }

    for i in 0..N {
        let size = if isGoal[i] { union_find.size(i) } else { 0 };
        println!("{}", size);
    }

}


Measured memory_bytes: 3900
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#define mp make_pair
#define pb push_back

using namespace std;

int main() 
{
	string a,b,c;
	cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] ;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int n;
ll ans;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
		{
            int a=gcd(i,j),b;
            for(int k=1;k<=n;k++)
                b=gcd(a,k),ans+=b;
        }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint counts[100011];

void solveSingleCase(int caseNo)
{
    memset(counts, 0, sizeof counts);
    int N;
    lint K;
    cin >> N >> K;
    FOR(i, 0, N) {
        int a, b;
        cin >> a >> b;
        counts[a] += b;
    }

    FOR(i, 1, 100001)
        if (counts[i] >= K) {
            cout << i << endl;
            return;
        } else {
            K -= counts[i];
        }
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 1024