akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

ll p[51] = {1};
ll a[51] = {1};

ll calc(int lv, ll x){
    if(x == 0) return 0;
    if(x == a[lv]) return p[lv];
    if(x >= (a[lv] + 1) / 2) return p[lv] - calc(lv - 1, a[lv] - x - 1);
    return calc(lv - 1, x - 1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    for(int i = 0; i < 50; ++i){
        p[i + 1] = 2 * p[i] + 1;
        a[i + 1] = 2 * a[i] + 3;
    }

    int n;
    ll x;
    cin >> n >> x;

    cout << calc(n, x) << "\n";
}


Measured memory_bytes: 256
ans=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(ans[n-1])

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

int main() {
  int n;
  scanf("%d", &n);

  set<string> st;
  char s[16], last;
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    if (st.count(s)) {
      printf("No\n");
      return 0;
    }
    st.insert(s);
    if (i > 0 && s[0] != last) {
      printf("No\n");
      return 0;
    }
    last = s[strlen(s) - 1];
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

#define maxn 100000+5

using namespace std;

int a[maxn];
int n,mx,pos,ans,pp;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(mx<a[i]) pp=i,mx=a[i];
	}
	ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		if(abs(a[i]*2-mx)<ans && i!=pp){
			ans=abs(a[i]*2-mx);
			pos=i;
		}
	}
	printf("%d %d",mx,a[pos]);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
inline int read(){int x=0,f=1;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;}
const int maxn = 3e5 + 50;

int n , A[maxn];

int main( int argc , char * argv[] ){
	n = read();
	for(int i = 1 ; i <= n * 3 ; ++ i) A[i] = read();
	sort( A + 1 , A + 3 * n + 1 );
	long long ans = 0;
	for(int step = 1 , a = 1 , b = 3 * n - 1 , c = 3 * n ; step <= n ; ++ step , ++ a , b -= 2 , c -= 2)
		ans += A[b];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		sC();
	}

	void sC() {
		String s = sc.next();
		int zero = 0, one = 0;
		char c[] = s.toCharArray();
		for(int i = 0; i < c.length; i++) {
			if(c[i] == '0') zero++;
			else one++;
		}
		if(one > zero) {
			System.out.println(zero * 2);
		}
		else System.out.println(one * 2);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

int main(){
vector<string> c(3);

for(int j = 0; j <3;j++){
cin>>c.at(j);
}
cout<<c.at(0).at(0)<<c.at(1).at(1)<<c.at(2).at(2)<<endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int A, B, C, week, amari,i , day = 0;
    cin >> A >> B >> C;
    week = C/(7*A + B);
    amari = C%(7*A + B);
    for(i=0;i<7;i++){
        if(amari<=A*i){
            break;
        }
    }
    day = week*7 + i;
    cout << day << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include<cstdio>

#define MAXN 100000
int N,M,Ans,cnt[MAXN+5],red[MAXN+5];

int main(){
    scanf("%d%d",&N,&M);
    for(int i=1;i<=N;i++)
        cnt[i]=1;
    red[1]=1;
    for(int i=1;i<=M;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        red[v]|=red[u],cnt[v]++;
        if(--cnt[u]==0)
            red[u]=0;
    }
    for(int i=1;i<=N;i++)
        Ans+=red[i];
    printf("%d",Ans);
}


Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <iostream>
bool x = true,y = true ,z = true ,w = true;
using namespace std;
int main(){
	char s[10000];
	scanf("%s",s);
	
	int l,c=-1;
	l = strlen(s);
	for(int i = 2; i<l-1;i++)
	{
		if(s[i]=='C')
			c++;
	}
	for(int i = 1;i<l ;i++){
		if(s[i]<'a'){
			if(s[i]=='C')
				continue;
			else {
				x = false;
				break;
			}
		}
	}
	//cout<<c;
	if(s[1]<'a'){
		w = false;
		//cout<<"NO w";
	}
	if(c>0||c<0){
		y = false;
		//cout<<"NO C";
	}
	if(s[0]!='A'){
		z = false;
		//cout<<"NO A";
	}
	if(x&&y&&z&&w)
		printf("AC\n");
	else 
		printf("WA\n");
	return 0;



}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
vector<int> Tree[101010];
map<pair<int, int>, int> mp;
int a[101010], b[101010], c[101010];

int main(){
    cin >> n;
    REP(i, n - 1){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        Tree[a[i]].emplace_back(b[i]);
        Tree[b[i]].emplace_back(a[i]);
        mp[make_pair(a[i], b[i])] = mp[make_pair(b[i], a[i])] = i;
    }
    REP(i, n)c[i] = -1;
    queue<pair<int, int>> q;
    q.push(make_pair(0, -1));
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        set<int> st;
        if(p.second != -1)st.insert(c[mp[make_pair(p.first, p.second)]]);
        int col = 0;
        for(auto to : Tree[p.first]){
            if(c[mp[make_pair(p.first, to)]] != -1)continue;
            while(st.count(col))col++;
            c[mp[make_pair(p.first, to)]] = col;
            st.insert(col);
            q.push(make_pair(to, p.first));
        }
    }
    int ans = 0;
    REP(i, n - 1)ans = max(ans, c[i]);
    cout << ans + 1 << endl;
    REP(i, n - 1){
        cout << c[i] + 1 << endl;
    }
}

Measured memory_bytes: 19840
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define inf (1ll<<60)
#define mod 1000000007
#define eps 1e-18
inline ll read()
{
    ll tmp=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0';
    return tmp*f;
}
using namespace std;
ll cnt[256];
char s[20];
int main()
{
	int i,j,k,n=read();
	for(i=1;i<=n;i++){
		scanf("%s",s);
		if(s[0]=='A'||s[0]=='R'||s[0]=='M'||s[0]=='C'||s[0]=='H')++cnt[(int)s[0]];
	}
	ll ans=0;
	for(i=0;i<256;i++)
		for(j=i+1;j<256;j++)
			for(k=j+1;k<256;k++)
				ans+=cnt[i]*cnt[j]*cnt[k];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
  string s,p;
  cin >> s >> p;
  s=s+s;
  if(s.find(p)!=-1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int num[100];
void change(int k,int now,int n){
	if(num[now]%k>num[now+1]%k)swap(num[now],num[now+1]);
	if(now!=n)change(k,now+1,n);
}
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>num[i];
    for(int i=1;i<=m;i++)change(i,0,n-2);
    for(int i=0;i<n;i++)cout<<num[i]<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <sstream>
#include <string>

using namespace std;
int gcd(int a, int b){
	if(b == 0){
		return a;
	}
	return gcd(b,a%b);
}

int main(){
	int a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	return 0;
}

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

using namespace std;

typedef long double ld;

//#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()

const int maxn = 3001;

ld dp[maxn][maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    dp[0][0] = 1.0;
    for (int i = 1; i <= n; i++) {
        ld x;
        cin >> x;
        for (int j = 1; j <= i; j++) {
            dp[j][i - j] += dp[j - 1][i - j] * x;
            dp[i - j][j] += dp[i - j][j - 1] * (1.0 - x);
        }
    }
    ld ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i <= n - i) continue;
        ans += dp[i][n - i];
    }
    cout << fixed << setprecision(10) << ans << "\n";

    return 0;
}


Measured memory_bytes: 139648
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Int (Int64)

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ solve n m

solve :: Int64 -> Int64 -> Int64
solve 1 1 = 1
solve n 1 = n - 2
solve 1 m = m - 2
solve n m = n * m - 2 * (n + m) + 4


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <cmath>

#include <atcoder/dsu>
#include <cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

using namespace std;
typedef long long ll;

using namespace atcoder;

int main()
{
    ll n, q;
    ll ans = 0;
    ll cnt = 0;
    scanf("%lld %lld", &n, &q);
    dsu d(n);
    for (ll i = 0; i < q; i++) {
        ll t, u, v;
        scanf("%lld %lld %lld", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4052
n,k,q = map(int, input().split())

lista = []
for i in range(n):
    lista.append(k-q)
#print(lista)
for i in range(q):
    num = int(input())-1
    lista[num] = lista[num] +1
    #print(lista)
#print(lista)
for i in range(n):
    if lista[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 7848
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,z,w; cin >> n >> z >> w;
    vector<int>v(n);
    for(auto & e : v) cin >> e;
    if(n == 1) cout << abs(v.front() - w) << endl;
    else cout << max(abs(v.back() - w),abs(v[n-1] - v[n-2])) << endl;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) > (b) ? (b) : (a))

int asc(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int
main(int argc, char *argv[])
{
  char s[5];
  scanf("%s", s);

  int c[10000] = {};
  
  for(int i = 0; i < 4; i++){
    c[s[i]]++;
  }
  int cnt = 0;
  for(int i = 'A'; i <= 'Z'; i++){
    if(c[i] > 0) cnt++;
  }

  if(cnt == 2) printf("Yes\n");
  else printf("No\n");

  return 0;
}
	  


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c[3][3] = {{}};
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    int A = c[0][0] + c[1][1] + c[2][2];
    int B = c[0][1] + c[1][2] + c[2][0];
    int C = c[0][2] + c[1][0] + c[2][1];
    if (A == B && B == C) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

class Program
{

    public static void Main( )
    {
        int N = int.Parse( Console.ReadLine( ) );
        string input = " " + Console.ReadLine( );   // すべて1オリジンにする
        var count = "RGB".ToDictionary( c => c, c => new int[ N + 1 ] );
        for ( int i = 1; i < N + 1; i++ )
        {
            char c = input[ i ];
            count[ 'R' ][ i ] = count[ 'R' ][ i - 1 ];
            count[ 'G' ][ i ] = count[ 'G' ][ i - 1 ];
            count[ 'B' ][ i ] = count[ 'B' ][ i - 1 ];
            count[ c ][ i ] += 1;
        }

        long ans = 0;
        for ( int i = 1; i < N + 1; i++ )  
        {
            char left = input[ i ];
            for ( int j = i + 1; j <= N - 1; j++ )
            {
                char mid = input[ j ];
                if ( left == mid ) continue;

                char right = GetRemainning( left, mid );
                ans += ( count[ right ][ N ] - count[ right ][ j ] );

                if ( j + ( j - i ) <= N )
                {
                    if ( input[ j + ( j - i ) ] == right ) ans--;
                }
            }
        }
        Console.WriteLine( ans );

    }

    static char GetRemainning( char a, char b )
    {
        var candidates = "RGB";
        return candidates.Where( c => c != a && c != b ).ToArray( )[ 0 ];
    }


}

Measured memory_bytes: 46564
#include <bits/stdc++.h>
using namespace std;
  
int main() {
int a[3];
int n; cin >> n;
for(int i=0; i<n; i++) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a+3);
if(a[1] * a[1] + a[0] * a[0] == a[2] * a[2]) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>
#include<string>
#include<iostream>

using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(void){


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

long gcdmin = 10000000000;

gcdmin = euclidean_gcd(a[0],a[1]);

for (int i=2; i<n;i++){
    gcdmin = euclidean_gcd(gcdmin,a[i]);
}

cout << gcdmin << endl;


return 0;
}


Measured memory_bytes: 1024
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
void solve()
{
	int n;
	cin>>n;
	int arr[n];
	forn(i,n)cin>>arr[i];
	int x=1,ans=0;
	set<int> s;
	forn(i,n)
	{
		if(x==arr[i])
		{
			x++;
			s.insert(arr[i]);
		}
		else ans++;
	}
	x=1;
	if(!s.size())cout<<-1;
	else cout<<ans<<endl;

}
 
int main()
{
 
    FastIO;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 10368
#include <iostream>
#include <limits>
#include <cmath>

using namespace std;

int main() {
	int A, B,ans = numeric_limits<int>::min();

	cin >> A >> B;

	ans = max(ans, A + B);
	ans = max(ans, A - B);
	ans = max(ans, A * B);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
   ll a, b, c, k; cin >> a >> b >> c >> k;
   if(k<=a+b) cout << min(k, a) << endl;
   else{
       cout << a-(k-a-b) << endl;
   }
}

Measured memory_bytes: 3596
N,K = map(int,input().split())

# 頂点対の最大値は、グラフがスター型の時で、(N-1)*(N-2)//2
# Kがそれより大きい場合は構築不可。
if K > (N-1)*(N-2)//2:
  print(-1)
  exit()

G = []
# スター型のグラフを作る。
# 頂点1～N-1と頂点Nの間に枝を張る。
# 頂点1～N-1の最短距離は2となり、その頂点対の数は(N-1)*(N-2)//2。
for i in range(1,N):
  G.append([i,N])

# 最短距離が2であるような頂点対がちょうどK個になるまで、
# 頂点1～N-1の間に枝を張る。

count = 0
u = 1
v = 2
while (count < (N-1)*(N-2)//2 - K):
  G.append([u,v])
  v += 1
  if (v == N):
    u += 1
    v = u + 1
  count += 1

print(len(G))
for g in G:
  print(*g)
    

Measured memory_bytes: 43504
h, w, k = map(int, input().split(' '))
c = [input() for x in range(h)]
cnt = 0

for maskR in range(2**h):
    for maskC in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (((maskR >> i) &1) == 0
                    and ((maskC >> j) &1) == 0 and c[i][j] == '#'):
                    black += 1
        if black == k:
            cnt += 1
print(cnt)

Measured memory_bytes: 9032
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>



int main() {
    char s[3];
    int i,d=0;
    scanf("%s",s);
    for(i=0;i<strlen(s);i++)
    {
        if(s[i]=='1')
            d++;
    }
    printf("%d",d);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll
#define P pair<int,int>

#define MAX 100005
int a[MAX];

// 利益の最大値 first  配列の場所 second
vector<P> max_dif;

signed main(){
  int n,t; cin>>n>>t;
  for(int i=0; i<n; i++) cin>>a[i];
  
  max_dif.push_back(mk(-1,-1));
  int minl=INF;
  for(int i=0; i<n; i++){
    minl=min(minl,a[i]);
    int d=a[i]-minl;
    if(d==max_dif[0].first) max_dif.push_back(mk(d,i));
    else if(d>max_dif[0].first){
      max_dif.clear();
      max_dif.push_back(mk(d,i));
    }
  }
  
  cout<<max_dif.size()<<en;
}



Measured memory_bytes: 2168
#include <stdio.h>

int main(void)
{
	int r, c, i, j;
	int a[101][101] = { 0 };

	scanf("%d %d", &r, &c);

	for (i = 0; i < r; i++)
		for (j = 0; j < c; j++)
			scanf("%d", &a[i][j]);

	for (i = 0; i < r; i++)
		for (j = 0; j < c; j++)
			a[i][c] += a[i][j];

	for (j = 0; j <= c; j++)
		for (i = 0; i < r; i++)
			a[r][j] += a[i][j];

	for (i = 0; i <= r; i++) 
		for (j = 0; j <= c; j++) 
			printf("%d%s", a[i][j], j == c?"\n" : " ");

	return 0;
}

Measured memory_bytes: 648
listA = []
import itertools
listB = [0] * 9
for i in range(3):
    listA.append(input().split())
listA = list(itertools.chain.from_iterable(listA))
N = int(input())
for i in range(N):
    B = input()
    if B in listA:
        listB[listA.index(B)] = 1
for i in range(3):
    if listB[i*3] == 1 and listB[i*3+1] == 1 and listB[i*3+2] == 1:
        print("Yes")
        exit()
for i in range(3):
    if listB[i] == 1 and listB[i+3] == 1 and listB[i+6] == 1:
        print("Yes")
        exit()
if listB[0] == 1 and listB[4] == 1 and listB[8] == 1:
    print("Yes")
    exit()
if listB[2] == 1 and listB[4] == 1 and listB[6] == 1:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/math/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}; std::cin >> N;
  vector<ui> A(N);
  rep(0, A.size()) cin >> A[i];

  auto ans = boost::accumulate(
    A,
    A[0],
    [](auto ans, auto res){
      return boost::math::gcd(ans, res);
    });

  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)

int main(){
    int n;  cin >> n;
    int a[n];   rep(i, n)cin >> a[i];
    int va = 1;
    rep(i, n)
        if(a[i] % 2 == 0)
            va *= 2;
    cout << pow(3, n) - va << endl;
}


Measured memory_bytes: 256
from sys import exit, stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
S = [list(stdin.readline().rstrip()) for _ in range(H)]
cnt = 0
for l in S:
    cnt += l.count('#')
if cnt == H + W - 1:
    print('Possible')
else:
    print('Impossible')

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, K, D;
    cin >> X >> K >> D;

    ll x = abs(X) / D;
    ll t = std::min(K, x);
    K -= t;
    X = abs(X) - D * t;

    ll ans = X;
    if (K % 2 == 1) {
        ans = std::min(abs(X + D), abs(X - D));
    }

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> adj[100100];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans = 0;
    rep(i, n) {
        bool good = true;
        for (int t : adj[i]) {
            if (h[t] >= h[i]) {
                good = false;
                break;
            }
        }
        if (good) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8732
object Main extends App {
  import java.util.Scanner

  val scan = new Scanner(System.in)
  val h, w = scan.nextInt
  var s = Vector(): Vector[Array[Char]]
  for (i <- 0 to h - 1) {
    s :+= scan.next.trim().toCharArray
  }
  var dw = Array.ofDim[Int](h, w)
  var dh = Array.ofDim[Int](w, h)
  for ( i <- 0 to (h - 1) ) {
    var count = 0
    for ( j <- 0 to (w - 1) ) {
      if (s(i)(j) == '#') {
        dw(i)(j) = 0
      }
      else if (j == 0 || s(i)(j - 1) == '#') {
        def loop1(i: Int, k: Int, w: Int, count: Int): Int = {
          if (k > w - 1 || s(i)(k) != '.') {
            return count
          }
          else {
            return loop1(i, (k + 1), w, (count + 1))
          }
        }
        count = loop1(i, j, w, 0)
        dw(i)(j) = count
      }
      else {
        dw(i)(j) = count
      }
    }
  }
  for ( j <- 0 to (w - 1) ) {
    var count = 0
    for ( i <- 0 to (h - 1) ) {
      if (s(i)(j) == '#') {
        dh(j)(i) = 0
      }
      else if (i == 0 || s(i - 1)(j) == '#') {
        def loop2(k: Int, j: Int, h: Int, count: Int): Int = {
          if (k > h - 1 || s(k)(j) != '.') {
            return count
          }
          else {
            return loop2((k + 1), j, h, (count + 1))
          }
        }
        count = loop2(i, j, h, 0)
        dh(j)(i) = count
      }
      else {
        dh(j)(i) = count
      }
    }
  }
  var max = 0
  for (i <- 0 to (h - 1)) {
    for (j <- 0 to (w - 1)) {
      var sum = dw(i)(j) + dh(j)(i)
      if (max < sum) {
        max = sum
      }
    }
  }
  println(max - 1)
}


Measured memory_bytes: 99636
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int A = inputVal<int>();
	const int B = inputVal<int>();
	const int C = inputVal<int>();
	outputVal(std::max(C-(A-B),0));
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

n=int(input())
visitedlist=[-1 for  i in range(n)]
kilist=[[] for i in range(n)]
anslist=[0 for i in range(n)]
searchedlist=[-1 for i in range(n)]
for i in range(n-1):
        a,b,c=map(int,input().split())
        kilist[a-1].append((b,c))
        kilist[b-1].append((a,c))
def search(i):
        searchedlist[i-1]=1
        visitedlist[i-1]=1
        flag=0
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag+=1
                anslist[j[0]-1]=anslist[i-1]+j[1]
        else:
            pass

        if flag>0:    
            for k in kilist[i-1]:
                if searchedlist[k[0]-1]==-1:
                    search(k[0])
search(2)
for i in anslist:
    print(i%2)


Measured memory_bytes: 86552
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    string s;cin >> s;
    int flag = 0;
    int count;cin >> count;
    for(int i=0;i<count;i++){
        int t;cin >> t;
        if(t==1){
            flag = 1-flag;
        }else if(t==2){
            int f;cin >> f;
            string k;cin >> k;
            if(f==1){
                if(flag){s+=k;continue;}
                s.insert(0,k); 
            }else if(f==2){
                if(flag){s.insert(0,k);continue;}
                s+=k;
            }
        }
    }
    if(flag){
        for(auto itr = s.rbegin();itr!=s.rend();++itr){
            cout << *itr;
        }
        cout << endl;
        return 0;
    }
    cout << s << endl;
}

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

int main() {
    int n; cin >> n; 
    vector<int> v(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] > c[i]) ans += v[i] - c[i];
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//:)
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort (a,a+3);
  cout<<a[2]-a[0];
  return 0;
}

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

int main(){
    int a,m=0,t=0;
    cin>>a;
    int n[a];
    for(int i=0;i<a;i++) cin>>n[i];
    for(int i=0;i<a;i++){
        if(m<n[i]) m=n[i];
    }
    for(int i=0;i<a;i++) t+=n[i];
    cout<<t-m/2<<endl;
}


Measured memory_bytes: 256
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define endl                        '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],adj1[100010],vis(100010,0),dis(100010,0),par(100010,0);
int myrandom (int i) { return std::rand()%i;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    string s;
    cin>>s;
    string cur,prev;
    int i=0,cnt=0;
    while(i<(int)s.length())
    {
        cur.pb(s[i]);
        if(cur!=prev)
        {
            prev=cur;
            cur.clear();
            cnt++;
        }
        i++;
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    vector<int> vec(N);
    rep(i, N) vec[i] = A[i] - B[i];
    sort(rALL(vec));
    if(vec[N - 1] >= 0) {
        cout << 0 << endl;
        return 0;
    }
    int left = 0, right = N - 1;
    int ans = 0;
    while (vec[left] > 0 && vec[right] < 0) {
        int diff = max(0, vec[left] + vec[right]);
        vec[right] = vec[left] - diff + vec[right];
        vec[left] = diff;
        if (vec[left] <= 0) {
            left += 1;
            ans += 1;
        }
        if (vec[right] >= 0) {
            right -= 1;
            ans += 1;
        }
    }
    rep(i, N) if (vec[i] < 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

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

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

	if(a < b) cout << "a < b" << endl;
	if(a > b) cout << "a > b" << endl;
	if(a == b) cout << "a == b" << endl;

	return 0;
}

Measured memory_bytes: 3068
import math
#import sympy
n=int(input())
a=math.factorial(n)
#print(a)
#a=32400

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
ps=prime_factors(a)
sy={}
for i in ps:
    if i not in sy:
        sy[i]=1
    else:
        sy[i]+=1
#aaaaaaaaaaa
#sy=sympy.factorint(a)
count75=0
count25=0
count15=0
count5=0
count3=0
for k in sy.values():
    #print(k)
    if k+1>=75:
        count75+=1
    if k+1>=25:
        count25+=1
    if k+1>=15:
        count15+=1
    if k+1>=5:
        count5+=1
    if k+1>=3:
        count3+=1

#print(count75)
#print(count25*(count3-1))
#print(count15*(count5-1))
#print((count5*(count5-1)*(count3-2))/2)
print(int(count75+count25*(count3-1)+count15*(count5-1)+(count5*(count5-1)*(count3-2))/2))


Measured memory_bytes: 3064
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: ans,i
    character(3):: s
    read*, s
    ans=0
    do i=1,3
        if (s(i:i) == '1') ans=ans+1
    end do
    print'(i0)', ans
end program main

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
char str[400005];
int a[400005],b[400005],d[400005][2];
int n,m,ans;
bool vis[400005];
vector<int>V[400005];
queue<int>Q;
int main()
{
	scanf("%d%d",&n,&m);
    scanf("%s",str+1);
    for (int i=1;i<=n;i++) a[i]=(str[i]=='A');
    for (int i=1,x,y;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        V[x].push_back(y);
        V[y].push_back(x);
        d[x][a[y]]++;
        d[y][a[x]]++;
    }
    for (int i=1;i<=n;i++)
    	if (!d[i][0] || !d[i][1]) Q.push(i);
    while (!Q.empty())
    {
        int u=Q.front();Q.pop();
        if (vis[u]) continue;
        vis[u]=true;
        ans++;
        for (int i=0;i<V[u].size();i++)
        {
            int v=V[u][i];
            d[v][a[u]]--;
            if (!d[v][a[u]]) Q.push(v);
        }
    }
    if (ans<n) printf("Yes\n"); else printf("No\n");
    return 0;
}


Measured memory_bytes: 20352
import sys

def main():
    N,L = map(int, input().split())
    apples = [L+i-1 for i in range(1,N+1)]
    mmin = sys.maxsize
    allsum = sum(apples)
    ans = 0
    for i in range(N):
        tmpsum = sum(apples[:i])
        if i != N-1:
            tmpsum += sum(apples[i+1:])
        tmp = abs(allsum-tmpsum)
        if tmp < mmin:
            mmin = tmp
            ans = tmpsum
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    string s; cin >> s;
    ll k; cin >> k;
    char show = '1';
    for (int i = 0; i < (int)s.size(); i++) {
        if (i >= k) {
            break;
        }
        if (s[i] != '1') {
            show = s[i];
            break;
        }
    }

    cout << show << endl;
}


Measured memory_bytes: 256
//2017-10-8
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (200000+5)

map<int, int> ms;

int main(){
	int n, m, rt;

	scanf("%d", &n);
	For(i, 1, n){
		scanf("%d", &rt);
		if(ms.count(rt)) ++ms[rt];
		else ms[rt] = 1;
	}
	
	scanf("%d", &m);
	For(i, 1, m){
		scanf("%d", &rt);
		if(!ms.count(rt)){puts("NO"); return 0;}
		if(!ms[rt]){puts("NO"); return 0;}
		--ms[rt];
	}
	
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

typedef long long ll;

const int sz = 2e5 + 1;

int n, k;
int pref[sz], a[sz];

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

	for (int i = 0; i < k; i++) {
		memset(pref, 0, sizeof(pref));

		for (int j = 0; j < n; j++) {
			int left = max(j - a[j], 0);
			int right = min(j + a[j] + 1, n);
			pref[left]++;
			pref[right]--;
		}
		bool all = 1;
		a[0] = pref[0];
		if (a[0] != n)
			all = 0;
		for (int i = 1; i < n; i++) {
			pref[i] += pref[i - 1];
			a[i] = pref[i];
			if (a[i] != n)
				all = 0;
		}
		if (all)
			break;
	}

	for (int i = 0; i < n; i++)
		cout << a[i] << ' ';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int a, b; cin >> a >> b;
    if(a>8 || b>8) cout << ":(";
    else cout << "Yay!";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
	int N;
  	cin>>N;
  	if(N%1000 == 0)
    {
      cout<<0;
      return;
	}
  	int ans = 1000 - N%1000;
  	cout<< ans;
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


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

using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	int n = (int)a.size();
	int m = (int)b.size();
	int nm = min(n, m);
	string ans = "";
	for (int i = 0; i < nm; i++) {
		ans += a[i];
		ans += b[i];	
	}
	if (n - nm > 0) {
		ans += a[n - 1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define MAX 100005
#define int long long

signed main()
{
  int N, M;
  int data[MAX], E[MAX] = {0};
  int A, B, C, sum = 0, ans = 0;
  
  cin >> N >> M;
  Rep(i,M) {
    cin >> data[i]; data[i]--;
  }
  Rep(i,M - 1) {
    E[min(data[i], data[i + 1])]++;
    E[max(data[i], data[i + 1])]--;
  }
  Rep(i,N - 1) {
    cin >> A >> B >> C;
    sum += E[i];
    ans += min(A * sum, C + B * sum);
  }

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

Measured memory_bytes: 4660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int []a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		boolean ok=a[0]==0;
		for(int i=1;i<n;i++)
			if(a[i]-a[i-1]>1)
				ok=false;
		if(!ok)
		{
			System.out.println(-1);
			return;
		}
		long ans=0;
		for(int i=1;i<n;i++)
			if(a[i]>a[i-1])
				ans++;
			else
				ans+=a[i];
		pw.println(ans);
		
	
		
		
		
		pw.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		public Scanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
	
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 45284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int a, b; cin >> a >> b;
    int ans = 0;
    if(a >= 13) ans = b;
    else if(a >= 6) ans = b / 2;
    else ans = 0;
    COUT(ans);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  string s; cin >> s;
  vector<char> ans;
  for(char c:s) {
    if(c=='B') {
      if(ans.empty()==false) ans.pop_back();
    } else {
      ans.push_back(c);
    }
  }
  for(auto c:ans) cout << c;
  cout << endl;
}


Measured memory_bytes: 256