akhauriyash/Code-Regression huggingface dataset:
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    string s;
    cin>>s;
    int n = s.length(),ans=0,i;
    for(i=0;i<n/2;i++)
    {
    	if(s[i]!=s[n-1-i]) ans++;
    }
    cout<<ans;
}

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

ll cal_digit(ll X){
  int cnt=0;
  while(X){
    X /= 10;
    cnt++;
  }
  return cnt;
}

int main(){
  ll N;
  cin >> N;
  
  ll ans = 100000000000;
  
  for(ll i = 1; i*i <=N; i++){
    if(N % i == 0){
      ll now = 0;
      ll b = N / i;
      now = max(cal_digit(i),cal_digit(b) );
      ans = min(ans, now);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		ArrayList<Integer> a = new ArrayList<>(); 
//		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a.add(Integer.parseInt(sc.next()));
		}
		sc.close();
		Collections.sort(a, Comparator.reverseOrder());
		int ans = 0;
		for(i=0;i<n;i++) {
			if(i%2==0)ans+=a.get(i);
			     else ans-=a.get(i);
		}
		System.out.println(ans);
	}
}


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

typedef long long lli;

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

    lli minn = min(a,b);
    lli diff = llabs(a-b);
    if( diff%2 == 0 )cout<<diff/2+minn<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define mod ((ll)1e9+7)
#define N ((ll)2e6+10)
#define pb push_back
#define in insert
#define F first
#define S second
#define MAX_CHARS 256
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x, ll y, ll p) { ll res = 1; while (y) {if (y % 2) res = (res * x % p) % p; x = (x * x) % p; y /= 2; } return res;}
int sv[1000000] = {0};
ll factorialNumInverse[N + 1];
ll naturalNumInverse[N + 1];
ll fact[N + 1];
void InverseofNumber(ll p) {naturalNumInverse[0] = naturalNumInverse[1] = 1; for (ll i = 2; i <= N; i++)naturalNumInverse[i] = naturalNumInverse[p % i] * (mod - mod / i) % mod;}
void InverseofFactorial(ll p) {factorialNumInverse[0] = factorialNumInverse[1] = 1; for (ll i = 2; i <= N; i++)factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % mod;}
void factorial(ll p) {fact[0] = 1; for (ll i = 1; i <= N; i++) {fact[i] = (fact[i - 1] * i) % mod;}}
ll Binomial(ll n, ll R) {ll ans = ((fact[n] * factorialNumInverse[R]) % mod * (factorialNumInverse[n - R]) % mod) % mod; return ans;}
/*TOIENT FUNCTION*/ll phi(ll n) {ll ans = n; for (ll i = 2; i * i <= n; i++) {if (n % i == 0) {while (n % i == 0) n /= i; ans -= ans / i;}} if (n > 1) ans -= ans / n; return ans;}


void fileIO() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {

//    InverseofNumber(mod);
//    InverseofFactorial(mod);
//    factorial(mod);
    speed
    // fileIO();
    ll n; cin >> n;
    ll x = n % 10;
    if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
        cout << "hon";
    else if (x == 0 || x == 1 || x == 6 || x == 8)
        cout << "pon";
    else cout << "bon";


    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 200000
#define DB double
int n,Q,ct;
vector<int> G[MAXN+1];
int dfn[MAXN+2],ot[MAXN+1];
int sum[MAXN+1],id[MAXN+2];
void dfs(int x,int fa){
	dfn[x]=++ct;
	id[ct]=x;
	for(int i=0;i<G[x].size();i++){
		int nxt=G[x][i];
		if(nxt==fa)continue;
		dfs(nxt,x);
	}
	ot[x]=ct;
}
int main()
{
	scanf("%d%d",&n,&Q);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
	}
	dfs(1,0);
	while(Q--){
		int a,b;
		scanf("%d%d",&a,&b);
		sum[dfn[a]]+=b;
		sum[ot[a]+1]-=b;
	}
	for(int i=1;i<=n;i++){
		sum[i]+=sum[i-1];
	}
	for(int i=1;i<=n;i++)
	printf("%d ",sum[dfn[i]]);
}

Measured memory_bytes: 28928
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b+c<=a)printf("0\n");
	else printf("%d\n",b+c-a); 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=55,Mo=1e9+7;

int n,C[N][N],f[N][N];

void inc(int &x,int y) {x=x+y>=Mo?x+y-Mo:x+y;}

int main() {
	scanf("%d",&n);
	fo(i,0,n) {
		C[i][0]=1;
		fo(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mo;
	}
	f[1][0]=f[1][1]=n;
	fo(i,1,n-1)
		fo(j,0,i)
			fo(k,max(j,1),n-i) {
				if ((k-j)&1) continue;
				int y=(k-j)/2;// 当前和父亲不一样
				fo(x,0,k) {
					// 目标和父亲不一样
					inc(f[i+k][abs(y-x)],(ll)f[i][j]*C[n-i][k]%Mo*C[k][x]%Mo);
				}
			}
	printf("%d\n",f[n][0]);
	return 0;
}

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



#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int>> vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;




int main(){
    int N;
    cin >> N;
    vi A(N);
    rep(i, N)cin >> A[i];
    rep(i, N)A[i]-=(i+1);
    sort(all(A));
    ll ans = numeric_limits<ll>::max();
    ll lsum = 0;
    ll rsum = 0;
    rep(i, N)rsum+=A[i];
    rep(i, N){
        ll s=0;
        ll b = A[i];
        lsum += A[i]; 
        rsum -=A[i];
        s = -lsum+b*(i+1) + rsum-b*(N-i-1);
        ans = min(s, ans);
    }    
    cout << ans << endl;
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int cnt_a = 0, cnt_b = 0, cnt_c = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'a') cnt_a++;
        else if (S[i] == 'b') cnt_b++;
        else cnt_c++;
    }

    if (abs(cnt_a - cnt_b) <= 1 && abs(cnt_b - cnt_c) <= 1 && abs(cnt_c - cnt_a) <= 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX
#define MAX 100000

using namespace std;
using LL=long long;

int A[3];

int main(){
    int n,a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        A[a%3]++;
    }
    if(!A[1]&&!A[2]) cout<<1<<endl;
    else if(A[1]==A[2]) cout<<A[1]*2+A[0]<<endl;
    else if((A[1]==1&&A[2]==0)||(A[1]==0&&A[2]==1)) cout<<A[0]+1<<endl;
    else if((A[1]==2&&A[2]==0)||(A[1]==0&&A[2]==2)) cout<<A[0]+2<<endl;
    else if((A[1]>=3&&A[2]==0)||(A[1]==0&&A[2]>=3)) cout<<A[0]+3<<endl;
    else if(A[1]>A[2]) cout<<min(A[1]-2,A[2])*2+2+(A[1]-2!=A[2])+A[0]<<endl;
    else cout<<min(A[1],A[2]-2)*2+2+(A[1]!=A[2]-2)+A[0]<<endl;
    return 0;
}



Measured memory_bytes: 3048
sx, sy, tx, ty = map(int, input().split())
ans = ("R" * (tx - sx) + "U" * (ty - sy) + "L" * (tx - sx) + "D" * (ty - sy) + 
       "D" + "R" * (tx + 1 - sx) + "U" * (ty + 1 - sy) + "L" + "U" + "L" * (tx + 1 - sx) + "D" * (ty + 1 - sy) + "R")
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    vector<ll>l(N);
    rep(i,N){
        cin>>l[i];
    }

    sort(all(l));
    reverse(all(l));
    ll ans=0;
    rep(i,K){
        ans+=l[i];
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3648
cnt_min=0
cnt_max=0
ans=0
n,m,x=map(int,input().split())
lst=list(map(int,input().split()))

for i in lst:
    if i < x:
        cnt_min+=1
    else:
        cnt_max+=1
print(cnt_max if cnt_min>cnt_max else cnt_min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define Maxn 507
int n,p[Maxn*Maxn];
int f[Maxn][Maxn],g[Maxn][Maxn];
int dx[4],dy[4];
pair<int,int> que[Maxn*Maxn];
bool flag[Maxn][Maxn];
int main()
{
    dx[0]=0,dy[0]=-1;
    dx[1]=0,dy[1]=1;
    dx[2]=-1,dy[2]=0;
    dx[3]=1,dy[3]=0;
    scanf("%d",&n);
    for (int i=1;i<=n*n;i++)
        scanf("%d",&p[i]);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            f[i][j]=min(min(i-1,j-1),min(n-i,n-j));
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            g[i][j]=1;
    int ans=0;
    memset(flag,false,sizeof(flag));
    for (int i=1;i<=n*n;i++)
    {
        int x=(p[i]+n-1)/n;
        int y=p[i]-(x-1)*n;
        ans+=f[x][y];
        g[x][y]=0;
        int lx=0,rx=0;
        que[++rx]=make_pair(x,y);
        flag[x][y]=true;
        while (lx<rx)
        {
            ++lx;
            int nowx=que[lx].first;
            int nowy=que[lx].second;
            flag[nowx][nowy]=false;
            for (int i=0;i<4;i++)
                if (nowx+dx[i]>=1&&nowx+dx[i]<=n&&nowy+dy[i]>=1&&nowy+dy[i]<=n&&f[nowx+dx[i]][nowy+dy[i]]>f[nowx][nowy]+g[nowx][nowy])
                {
                    f[nowx+dx[i]][nowy+dy[i]]=f[nowx][nowy]+g[nowx][nowy];
                    if (!flag[nowx+dx[i]][nowy+dy[i]])
                    {
                        que[++rx]=make_pair(nowx+dx[i],nowy+dy[i]);
                        flag[nowx+dx[i]][nowy+dy[i]]=true;
                    }
                }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 8768
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();

		for(int i = 0; i < n; i++) {
			sb.append(s.charAt(i));
			sb.append(t.charAt(i));
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 35752
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <climits>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <utility>
#include <iostream>
#include <algorithm>
#define mkp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef set<int> seti;
typedef size_t szt;
const int MAXN = 100014;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
int main() {
    string s1, s2;
    int n, i = 0;
    bool prev = 0;
    long long ans = 1;
    cin >> n;
    cin >> s1;
    cin >> s2;
    while (i < n) {
        if (i == 0) {
            if (s1[i] != s2[i]) {
                ans = ans * 6;
                prev = 1;
                i += 2;
            }
            else {
                ans = ans * 3;
                prev = 0;
                i++;
            }
        } else {
            if (s1[i] == s2[i]) {
                if (prev) {
                    ans %= MOD;
                } else {
                    ans = (ans * 2) % MOD;
                }
                prev = 0;
                i++;
            }
            else {
                if (prev) {
                    ans = (ans * 3) % MOD;
                } else {
                    ans = (ans * 2) % MOD;
                }
                prev = 1;
                i += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll f(ll x){
  if(x==1) return 1 ;
  return f(x/2)*2+1 ;
}

int main() {
  ll h;
  cin >>h ;
  
  
  cout << f(h) <<endl ;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void	attack(long long int H, long long int N, long long int *T)
{
  	if (H == 1)
    {
      	H = 0;
      	*T += N;
      	N = 0;
    }
  	else
    {
      	H = H / 2;
      	*T += N;
      	N = N * 2;
      	attack(H, N, T);
    }
}
int	main(void)
{
  	long long int		H;
  	int		num;
  	int		i;
  	long long int		N;
  	long long int		T;
  
  	num = scanf("%lld", &H);
  	if (num != 1)
      	return (0);
  
  	N = 1;
  	T = 0;
  	attack(H, N, &T);
  
  	printf("%lld", T);
  	return (0);
}

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

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

Measured memory_bytes: 3540
N = int(input())
price = list(map(int,input().split()))
money = 1000
stack = 0

state = None
for i in range(1,N):
    if state == None:
        if price[i] < price[i-1]:
            money += price[i-1]*stack
            stack = 0
            state = False
        elif price[i] > price[i-1]:
            stack = money//price[i-1]
            money = money%price[i-1]
            state = True
    elif state == True:
        if price[i] < price[i-1]:
            money += price[i-1]*stack
            stack = 0
            state = False
    elif state == False:
        if price[i] > price[i-1]:
            stack = money//price[i-1]
            money = money%price[i-1]
            state = True

if stack != 0:
    money += price[-1]*stack
    stack = 0

print(money)

Measured memory_bytes: 9244
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

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

///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 1000001;
const int MOD = 1000000007;
const ll INF = LLONG_MAX;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)
#define time() cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///



int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        int n,i,k,j;
        cin>>n;
        vvii v(n,vii(3)),dp(n,vii(3));
        for(i=0; i<n; i++)
            for(j=0; j<3; j++)
                cin>>v[i][j];
        dp[0][0]=v[0][0];
        dp[0][1]=v[0][1];
        dp[0][2]=v[0][2];
        for(i=1; i<n; i++)
            for(j=0; j<3; j++)
                for(k=0; k<3; k++)
                {
                    if(j==k)
                        continue;
                    dp[i][k]=max(dp[i][k],dp[i-1][j]+v[i][k]);
                }
        int ans=*max_element(all(dp[n-1]));
        cout<<ans<<nl;
    }
}

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

typedef long long ll;
const int N = 108, pr[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

int n;
int a[N];

namespace F {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = ::N, M = 2054;

	struct edge {
		int u, v, f;
		edge (int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2;
	int first[N], next[M];
	int dep[N], cur[N], que[N];
	ll flow;

	inline void addedge(int u, int v, int f) {
		e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h, t = 1, i, x, y;
		memset(dep, -1, sizeof dep);
		que[0] = si, dep[si] = 0;
		for (h = 0; h < t; h++) {
			if ((x = que[h]) == ti) return true;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] == -1 && e[i].f)
					que[t++] = y, dep[y] = dep[x] + 1;
		}
		return false;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c; e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	ll Dinic() {
		for (flow = 0; bfs(); flow += dfs(si, INT_MAX))
			memcpy(cur, first, sizeof cur);
		return flow;
	}
}

int main() {
	int i, j; ll s = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) if (scanf("%d", a + i), a[i] > 0) s += a[i];
	for (i = 1; i <= n; ++i)
		if (a[i] > 0) F::addedge(1, i + 2, a[i]);
		else if (a[i] < 0) F::addedge(i + 2, 2, -a[i]);
	for (i = 1; i <= n; ++i)
		for (j = 0; j < 25 && i * pr[j] <= n; ++j)
			F::addedge(i * pr[j] + 2, i + 2, INT_MAX);
	printf("%lld\n", s - F::Dinic());
	return 0;
}

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

int main(void) {
    string S;cin>>S;
    int yen = 700;
    if (S[0] == 'o') yen += 100;
    if (S[1] == 'o') yen += 100;
    if (S[2] == 'o') yen += 100;
    cout << yen << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 50

struct Info{
	Info(int arg_row,int arg_col,int arg_sum_dist){
		row = arg_row;
		col = arg_col;
		sum_dist = arg_sum_dist;
	}
	bool operator<(const struct Info &arg) const{

		return sum_dist > arg.sum_dist; //総距離の昇順(PQ)
	}
	int row,col,sum_dist;
};

int H,W;
int min_dist[NUM][NUM+1];
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
char base_map[NUM][NUM+1];

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;

	}else{

		return false;
	}
}

int main(){

	scanf("%d %d",&H,&W);

	int num_black = 0;

	for(int row = 0; row < H; row++){

		scanf("%s",base_map[row]);
		for(int col = 0; col < W; col++){
			if(base_map[row][col] == '#'){
				num_black++;
			}
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			min_dist[row][col] = BIG_NUM;
		}
	}

	min_dist[0][0] = 1; //★スタートマスの1★

	priority_queue<Info> Q;
	Q.push(Info(0,0,1));

	int next_row,next_col,next_cost;

	while(!Q.empty()){

		if(Q.top().sum_dist > min_dist[Q.top().row][Q.top().col]){

			Q.pop();

		}else if(Q.top().row == H-1 && Q.top().col == W-1){

			printf("%d\n",H*W-num_black-Q.top().sum_dist);
			return 0;

		}else{

			next_cost = Q.top().sum_dist+1;

			for(int i = 0; i < 4; i++){

				next_row = Q.top().row+diff_row[i];
				next_col = Q.top().col+diff_col[i];

				if(rangeCheck(next_row,next_col) == false || base_map[next_row][next_col] == '#')continue;

				if(min_dist[next_row][next_col] > next_cost){

					min_dist[next_row][next_col] = next_cost;
					Q.push(Info(next_row,next_col,next_cost));
				}
			}
			Q.pop();
		}
	}

	printf("-1\n");

	return 0;
}


Measured memory_bytes: 256
import itertools
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0

for i in range(len(l)-2):
  for j in range(i+1,len(l)):
    k = bisect.bisect_left(l, l[i]+l[j])
    if k > j:
      ans += k - j -1

print(ans)

Measured memory_bytes: 9360
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a<=8&&b<=8?"Yay!":":(")<<endl;
	return 0;
}



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




int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;


    cin>>n;
    vector <long long int> v1;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
        if(i==0)
            m=a;
        else
        {
            m^=a;
        }
    }

    for(i=0;i<n;i++)
    {
        a=m^v1[i];
        cout<<a;
        if(i!=(n-1))
            cout<<" ";
    }
    cout<<"\n";

    return 0;


}


Measured memory_bytes: 5364
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,j,n,k,l,r;
    char s[131072];
    scanf("%s",s);
    l=strlen(s);
    r=l;
    for(i=1;i<l;i++){
        if(s[i-1]!=s[i]){r=min(r,max(i,l-i));}
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{

ll n,i,l,r,s1=0,s2=0;
cin>>n;
ll arr[n];
for(i=0;i<n;i++)
    cin>>arr[i];
l=0,r=n-1;
s1=arr[l],s2=arr[r];
while(l<r)
{
    if(s1<=s2)
    {
        l++;
        if(l<r)
            s1=s1+arr[l];
        else
            break;
    }
    else
    {
        r--;
        if(r>l)
            s2=s2+arr[r];
        else
            break;
    }
}
cout<<abs(s1-s2)<<endl;
}



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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N;
    cin >> N;
    VI A(N);
    unordered_map<int, ll> cnt;
    REP(i, N) cin >> A[i];
    REP(i, N) {
    	cnt[A[i]]++;
    }
    ll sum = 0;
    for (auto p : cnt) {
    	sum += p.second * (p.second - 1) / 2LL;
    }
    REP(i, N) {
    	if (cnt[A[i]] < 2) {
    		cout << sum << '\n';
    	} else {
    		cout << sum - cnt[A[i]] + 1 << '\n';
    	}
    }


}

Measured memory_bytes: 8392
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);
	
	long gcd(long a,long b) {
		return a%b==0?b:gcd(b,a%b);
	}
	
	void solve(){
		for(int q:rep(gInt())) {
			long a=gLong(),b=gLong(),c=gLong(),d=gLong();
			if(a<b||b>d) {
				System.out.println("No");
				continue;
			}
			if(b<=c+1) {
				System.out.println("Yes");
				continue;
			}
			long v=gcd(b,d);
			if(v+c<b) {
				System.out.println("No");
				continue;
			}
			if(v>1&&b<=d) {
				System.out.println(a%b>c?"No":"Yes");
				continue;
			}
			System.err.println(v);
			System.err.println(a+" "+b+" "+c+" "+d);
			System.exit(-1);
		}
	}
	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 26960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n, d, x; cin >> n >> d >> x;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        int day = 1;
        int multiple = 1;
        while(day <= d) {
            day += multiple * a;
            sum++;
        }
    }
    cout << sum + x << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pint = pair<int,int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
    int n,k;
    cin>>n>>k;
    vll v(n);
    rep(i,n) cin>>v[i];
    ll ans = -1LL*1e11;
    int mn = min(n, k);

    for(int i=0; i<=mn; i++){
        for(int j=0; j+i<= mn; j++){
            vll a;
            int cnt = k - i - j;
            ll tans=0;
            for(int l = 0; l<i; l++) a.push_back(v[l]);
            for(int l = 0; l< j; l++) a.push_back(v[n-1-l]);
            for(auto at :a) tans += at;
            sort(a.begin(),a.end());
            for(int l = 0; l < cnt&& l<a.size() && a[l]<0; l++) tans -=a[l];
            ans = max(ans, tans);
        }
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
int n,a[100];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 384
n = int(input())
def dfs(string):
    if len(string) == len(str(n)):
        return 1 if all(k in string for k in '753') and int(''.join(string)) <= n else 0

    rec = 0
    s = '753' if len(string) != 0 and string[-1] != '0' else '0753'
    for num in s:
        string.append(num)
        rec += dfs(string)
        string.pop()

    return rec

print(dfs([]))

Measured memory_bytes: 3060
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

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

ans = 'No'
ans = 'Yes' if s[0:n//2] * 2 == s else ans
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;

typedef long long ll;

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int a[2];
   cin >> a[0] >> a[1];
   sort(a, a+2);
   if(a[0] == 1 && a[1] == 2)
       cout << 3;
   else if(a[0] == 1 && a[1] == 3)
       cout << 2 << "\n";
   if(a[0] == 2 && a[1] == 3)
       cout << 1;
   return 0;
} 


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

using namespace std;
int main(){
  int h, w;
  cin >> h >> w;

  char field[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> field[i][j];
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(field[i][j]=='.'){
        int bomb = 0;
        for(int k=i-1;k<i+2;k++){
          for(int l=j-1;l<j+2;l++){
            if(k<0||l<0||k>=h||l>=w)continue;
            if(field[k][l]=='#')bomb++;
          }
        }
        field[i][j]='0'+bomb;
      }
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> field[i][j];
      cout << field[i][j];
    }
    cout << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int M;
  cin >> M;
  
  if(M < 1 || M > 23) {
    cout << "M must be between 1 and 23.";
    return 0;
  }

  cout << 24 * 2 - M << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int n,Tn,w;
int wArray[100000];

int check(long long P){
  int i=0,j;
  for(j=1;j<=Tn;j++){
    int s=0;
    while(s+wArray[i]<=P){
      s+=wArray[i];
      i++;
      if(i==n){
        return n;
      }
    }
  }
  return i;
}

int calc(){
    long long left = 0;
    long long right = 100000 * 10000;
    while(right-left>1){
        long long int mid = (left+right)/2;
        int v = check(mid);
        if(v<n){
            left = mid;
        }else{
            right = mid;
        }
  }
  return right;
}

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

    for (int i=0;i<n;i++){
        scanf("%d", &wArray[i]);
        w += wArray[i];
    }

    long long ans = calc();
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2164
#include <stdio.h>
#include <string.h>

int main()
{
	char a[102],b[102],c[102];
	int A=0,B=0,C=0; //カードの位置
	int turn=1; //1:A,2:B,3:C
	
	fgets(a,102,stdin);
	fgets(b,102,stdin);
	fgets(c,102,stdin);
	
	while(1){
		if(turn==1){
			if(a[A]=='a') turn=1;
			else if(a[A]=='b') turn=2;
			else if(a[A]=='c') turn=3;
			else {
				printf("A\n");
				return 0;
			}
			A+=1;
		}else if(turn==2){
			if(b[B]=='a') turn=1;
			else if(b[B]=='b') turn=2;
			else if(b[B]=='c') turn=3;
			else {
				printf("B\n");
				return 0;
			}
			B+=1;
		}else{
			if(c[C]=='a') turn=1;
			else if(c[C]=='b') turn=2;
			else if(c[C]=='c') turn=3;
			else {
				printf("C\n");
				return 0;
			}
			C+=1;
		}
	}

	return 0;
	
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
vi zyoutai(int bit,int n){
    vi S;
    //cout << bit;
    rep(i,n){
        //cout << (bit & (1 < i));
        if(bit & (1 << i)){
            S.pb(1);
        }
        else{S.pb(0);}
    }
    return S;
}


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

    int n;
    cin >> n;
    vi p(n); //真偽判定
    vi num(n);
    vector<vector<pair<int ,int>>>  x(n); 
    rep(i,n){
        cin >> num[i];
        rep(j,num[i]){
            int tx,ty;
            cin >> tx >> ty;
            x[i].pb( i_i(tx,ty));
        }
    }
    int mx = 0;

    for(int bit = 0;bit < (1<<n);++bit){
        p = zyoutai(bit,n); //正直者と嘘つきを仮定
        int sum = 0; //正直者の数
        bool ok =true;
        rep(i,n){        
            sum += p[i];
            if(p[i]==1){
                rep(j,num[i]){
                    if(p[x[i][j].first-1] != x[i][j].second)ok =false;
                }
            }   
        }    

        if(ok){ 
            //for(auto it : p) cout << it;
            //cout<<endl;
            mx = max(mx,sum);
        }
        
    }
    cout << mx <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){if(a < b) a = b;}
template <class T> inline void chmin(T &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




int main(void){
    int n, k; scanf("%d%d", &n, &k);
    // a のあまりを p とする => bのあまりは k - pである必要 => c の余りは pである
    int p = n / k;
    lli cnt = p; cnt *= p; cnt *= p;
    if(k % 2 == 0){
        int mod_half = (n + (k / 2)) / k;
        lli add = mod_half; add *= mod_half; add *= mod_half;
        cnt += add;
    }
    printf("%lld\n", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main()
{
	string s;
	cin >> s;
	cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;
	return 0;
}

Measured memory_bytes: 256
#atcoder https://atcoder.jp/contests/dp/tasks/dp_b

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))


    dp = [0] * N
    dp[0] = 0

    for i in range(1, N):

        dp[i] = min(
            dp[k] + abs(h[i]-h[k]) for k in range(max(i-K,0), i)
        )

    print(dp[N-1])

main()

Measured memory_bytes: 13976
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll mod=1000000007;

class mll {
public:
	ll val;
    mll(int v){val=(v + mod) % mod;}
    mll operator + (mll m) { return mll((val + m.val + mod) % mod); } 
    mll operator - (mll m) { return mll((val - m.val + mod) % mod); }
    mll operator * (mll m) { return mll((val * m.val + mod) % mod); }
    mll operator / (mll m) { return mll((val * modinv(m.val, mod)) % mod); }
    void operator = (mll m) { val = m.val; }
    explicit operator ll() { return val; }

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

int main(){
    ll N=ii();
    ll K=ii();
    vector<ll> A;
    REP(i,0,N){A.push_back(ii());}
    sort(A.begin(), A.end(), [](int i, int j) -> bool{
        return abs(i) > abs(j);
    });

    ll sign=1;
    ll mmin=-1;
    ll pmin=-1;
    REP(i,0,K){
        sign*=A[i]/abs(A[i]);
        if(A[i]>0){
            pmin=i;
        }else{
            mmin=i;
        }
    }

    ll mmax=-1;
    ll pmax=-1;
    PER(i,A.size()-1,K){
        if(A[i]>0){
            pmax=i;
        }else{
            mmax=i;
        }
    }

    if(sign<0){
        if(pmin>0 && pmax>0 && mmin>0 && mmax>0){
            if(abs(A[mmin]*A[mmax]) < abs(A[pmin]*A[pmax])){
                swap(A[mmin],A[pmax]);
            }else{
                swap(A[pmin],A[mmax]);
            }
            sign=1;
        }else if(pmin>0 && mmax>0){
            swap(A[pmin],A[mmax]);
            sign=1;
        }else if(pmax>0 && mmin>0){
            swap(A[mmin],A[pmax]);
            sign=1;
        }
    }

    mll ret(1);
    if(sign < 0){
        reverse(A.begin(), A.end());
    }
    REP(i,0,K){
        ret=ret*mll(A[i]);
    }
    oie((ll)ret);

    return 0;
}

Measured memory_bytes: 5368