akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

ll n;
map < ll , int > dp;

ll solve(ll health){
	if(health == 1)
		return 1;
	ll ret = dp[health];
	if(ret) return ret;
	dp[health] = 1;
	return ret = 2*solve(health/2) + 1;
}


int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	
	scanf("%lld" , &n);
	//memset(dp , -1 , sizeof dp);
	printf("%lld\n", solve(n));
	
	
    return 0;
}




Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
char s[200005];
int n,a[2];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	ll res=0;
	int sum=0;
	int sum2=0;
	For(i,1,n)
		if (s[i]=='1'){
			res+=(sum2+sum%2)/2;
			++a[sum%2]; ++sum;
			res+=(sum+1)/2;
		}
		else{
			++sum2;
			res+=max(a[0],a[1]);
			a[0]=a[1]=max(a[0],a[1]);
		}
	cout<<res<<endl;
}

Measured memory_bytes: 3960
#include <cstdio>

inline int readin(){
	int x=0,c;
	bool f=0;
	for (;(c=getchar())<'0'||c>'9';f|=c=='-');
	for (;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-48;
	return f?-x:x;
}

int main(){
	int x1=readin(),y1=readin(),x2=readin(),y2=readin();
	printf("%d %d %d %d",x2+y1-y2,y2-x1+x2,x1+y1-y2,y1-x1+x2);
}

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

int main() {
  char A,B,C;
  std::cin>>A>>B>>C;
  if(A!='7' && B!='7' && C!='7'){
        std::cout <<"No"<<endl;
  }
  else{
    std::cout<< "Yes"<<endl;
  }
}
    
  

    
  


Measured memory_bytes: 3596
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

struct state {
	int n1[3];
	int n2[3];
	int n3;

	inline int count_total() const {
		return n1[0] + n1[1] + n1[2] + 2 * (n2[0] + n2[1] + n2[2]) + 3 * n3;
	}

	bool operator<(const state & S) const {
		return count_total() < S.count_total();
	}
};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	string S;
	cin >> N >> S;
	cat mod = 998244353;
	map<state, cat> dp;
	dp[{{0, 0, 0}, {0, 0, 0}, 0}] = 1;
	auto it = begin(dp);
	while(true) {
		int pos = it->ff.count_total();
		it->ss %= mod;
		if(pos == 3*N) break;
		int v = (S[pos] == 'R') ? 0 : ((S[pos] == 'B') ? 1 : 2);
		// add as 1
		if(it->ff.n1[0] + it->ff.n1[1] + it->ff.n1[2] == 0) {
			state s = it->ff;
			s.n1[v]++;
			assert(s.count_total()-pos == 1);
			if(it->ff.n2[v] == 0) dp[s] += it->ss;
		}
		else if(it->ff.n1[v] > 0) {
			state s = it->ff;
			s.n1[v]++;
			assert(s.count_total()-pos == 1);
			dp[s] += it->ss;
		}
		// add as 3
		if(it->ff.n2[v] > 0) {
			state s = it->ff;
			s.n2[v]--;
			s.n3++;
			assert(s.count_total()-pos == 1);
			dp[s] += it->ss * it->ff.n2[v] % mod;
		}
		else
		// add as 2 with sth else
		for(int k = 0; k < 3; k++) if(k != v && it->ff.n1[k] > 0) {
			state s = it->ff;
			s.n1[k]--;
			s.n2[3-v-k]++;
			dp[s] += it->ss * it->ff.n1[k] % mod;
		}
		it++;
	}
	cat fac = 1;
	for(int i = 2; i <= N; i++) fac = fac * i % mod;
	cout << dp[{{0, 0, 0}, {0, 0, 0}, N}] * fac % mod << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 23956
/*    
 *  eat_code    
 *  IIIT Allahabad
 */
#include <bits/stdc++.h>
//#include "pretty_print.h"
using namespace std;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define CONTAINS(a, x) (a.find(x) != a.end())
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define nl cout << endl
#define F first
#define S second

#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define CASET int ___T, case_n = 1; scanf("%d", &___T); while (___T-- > 0) 

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef vector<vi> vvi;

ll INF = 1E9;
ll M = 1E9 + 7;

inline ll power (ll a,ll p){
    ll res = 1, x = a;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x ); p >>= 1;
    }
    return res;
}

int main() {
    boost;
    if(fopen("input.txt", "r")){
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    }
    int n;
    cin >> n;
    bool ok = false;
    int prev = -1, cnt = 0;
    while(1){
        int curr = n % 10;
        if(prev == curr){
            cnt++;
            if(cnt >= 3)
                ok = true;
        }else cnt = 1;
        n /= 10;
        if(n == 0)break;
        prev = curr;
    }
    if(ok)cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}
//  Train Insane or Remain the same
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
#define lc 2 * x // if tree index id 0 based
#define lr 2 * x + 1
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e6 + 6;
int main()
{
    ll n, ans = 0;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n - 2; i++)
    {
        ll k = i + 2;
        for (int j = i + 1; j < n; j++)
        {
            while (k < n && a[i] + a[j] > a[k])
                k++;
            if (k > j)
                ans += k - j - 1;
            //c(ans)
        }
    }
    c(ans)
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b, _, k := nextInt4()

	if a >= k {
		puts(k)
	} else if a+b >= k {
		puts(a)
	} else {
		puts(a - (k - a - b))
	}
}


Measured memory_bytes: 1764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
seen = [False]*n
def dfs(v):
    seen[v] = True
    stack = [v]
    while stack:
        v = stack.pop()
        for nv in G[v]:
            if seen[nv]:
                continue
            seen[nv] = True
            stack.append(nv)
ans = 0
for i in range(n):
    if not seen[i]:
        ans += 1
        dfs(i)
ans -= 1
print(ans)

Measured memory_bytes: 80856
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 3e4 + 11;
const int inf = 1e9;
int head[N], to[N], nex[N], size = 1;
int dl[N], fr[N];
int n, S = 3000, T = 3001;
LL dis[N], wei[N], cst[N], ans;
bool mark[N];
void add(int x, int y, int z, int k){
	to[++size] = y; nex[size] = head[x]; head[x] = size; cst[size] = k; wei[size] = z;
	to[++size] = x; nex[size] = head[y]; head[y] = size; cst[size] = -k; wei[size] = 0;
}
void spfa(){
	int hd = 0, tl = 1;
	dl[1] = S;
	for(int i = 1;i <= T; i++)dis[i] = -1e18;
	dis[S] = 0; mark[S] = 1;
	while(hd < tl){
		int u = dl[++hd];
		for(int i = head[u];i;i = nex[i]){
			if(wei[i] <= 0)continue;
			int v = to[i];
			if(dis[v] < dis[u] + cst[i]){
				dis[v] = dis[u] + cst[i];
				fr[v] = i;
				if(!mark[v])dl[++tl] = v, mark[v] = 1;
			}
		}
		mark[u] = 0;
	}
}
void MCMF(){
	while(1){
		spfa();
		LL ma = dis[T]; 
		if(ma == -1e18)return ;
		LL flow = 1e9;		
//		printf("ma=%lld ans=%lld\n", ma, ans);
		for(int u = T;u != S;u = to[fr[u]^1])flow = min(flow, wei[fr[u]]);
		ans += flow * ma;
		for(int u = T;u != S;u = to[fr[u]^1])wei[fr[u]] -= flow, wei[fr[u]^1] += flow;
	}
}
int main(){
	cin>>n;
	int x, y, w;
	for(int i = 1;i <= n; i++){
		scanf("%d%d%d", &x, &y, &w);
		add(S, i, w, 0);
		add(i, 2 * n + 1, inf, x + y);
		add(i, 2 * n + 2, inf, x - y);
		add(i, 2 * n + 3, inf, -x + y);
		add(i, 2 * n + 4, inf, -x - y);
	}
	for(int i = 1;i <= n; i++){
		scanf("%d%d%d", &x, &y, &w);
		add(i + n, T, w, 0);
		add(2 * n + 1, i + n, inf, -x - y);
		add(2 * n + 2, i + n, inf, -x + y);
		add(2 * n + 3, i + n, inf, x - y);
		add(2 * n + 4, i + n, inf, x + y);
	}
	MCMF();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits.h>

using namespace std;

int main()
{
	int n;
	int cx,cy;
	long ch;
	

	cin >> n;

	int *x = new int[n];
	int *y = new int[n];
	long *h = new long[n];

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

	bool find;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			cx = i;
			cy = j;
			int delta_x;
			int delta_y;
			int delta_h;
			find = false;
			ch = LONG_MAX;

			int k;
			for (k = 0; k < n; k++) {
				if (ch != -1) {
					delta_x = abs(x[k] - i);
					delta_y = abs(y[k] - j);
					long temp_ch = h[k] + delta_x + delta_y;
					if (temp_ch <= ch) {
						ch = temp_ch;
					} else if (h[k] == 0) {
						continue;
					} else {
						break;
					}
				}
			}
			for (k = 0; k < n; k++) {
				if (ch != -1) {
					delta_x = abs(x[k] - i);
					delta_y = abs(y[k] - j);
					long temp_ch = h[k] + delta_x + delta_y;
					if (temp_ch <= ch) {
						ch = temp_ch;
					}
					else if (h[k] == 0) {
						continue;
					}
					else {
						break;
					}
				}
			}
			if (k == n && ch < LONG_MAX) {
				find = true;
				break;
			}
		}
		if (find) {
			break;
		}
	}
	cout << cx << " " << cy << " " << ch << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    string s; cin >> s;
    rep(i, 0, 5) {
        cout << s[i];
    }
    cout << ' ';
    rep(i, 6, 13) {
        cout << s[i];
    }
    cout << ' ';
    rep(i, 14, 19) {
        cout << s[i];
    }
}


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

void countingSort(int *a,int *b,int n,int k){
  int i,j;
  int c[10001];
  for(i=0;i<=k;i++)c[i]=0;
  for(j=1;j<=n;j++)c[a[j]]++;
  for(i=1;i<=k;i++)c[i]=c[i]+c[i-1];
  for(j=n;j>=1;j--){
    b[c[a[j]]]=a[j];
    c[a[j]]--;
  }
}

int main(){
  int i,n,max=0;
  int *ar1,*ar2,*a,*b;
  
  scanf("%d",&n);
  ar1=(int *)malloc(n*sizeof(int)+1);
  ar2=(int *)malloc(n*sizeof(int)+1);
  a=ar1;
  b=ar2;

  for(i=1;i<n+1;i++){
    scanf("%d",a+i);
    if(*(a+i)>max)max=*(a+i);
  }
  countingSort(a,b,n,max);

  for(i=1;i<n;i++)printf("%d ",*(b+i));
  printf("%d\n",*(b+i));
  free(ar1);
  free(ar2);
  return 0;
}

Measured memory_bytes: 16056
n, t = map(int, input().split())
a = [int(x) for x in input().split()]

minimum = a[0]
count = 0
profit = 0
for i in range(1, n):
  if a[i] < minimum:
    minimum = a[i]
    continue
  
  k = a[i]-minimum
  if profit < k:
    profit = k
    count = 1
  elif profit == k:
    count += 1

print(count)

Measured memory_bytes: 14252
#define RUN
#ifdef RUN
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MAX 211111

int N;
int A[MAX];
int C[MAX];
int COMB[MAX];
int COMB_1[MAX];
int AC;

int calc(int k) {
    int a = A[k];
    int ans = AC;
    ans -= COMB[a];
    ans += COMB_1[a];
    return ans;
}

signed main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int z;
        cin >> z;
        A[i] = z;
        C[z] = C[z] + 1;
    }
    for (int i = 1; i <= N; ++i) {
        int c = C[i];
        COMB[i] = c * (c - 1) / 2;
        COMB_1[i] = ((c >= 2) ? ((c - 1) * (c - 2) / 2) : 0);
    }
    for (int i = 1; i <= N; ++i) {
        AC += COMB[i];
    }
    for (int k = 1; k <= N; ++k) {
        int ans = calc(k);
        cout << ans << endl;
    }
    return 0;
}
#endif


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=2e5+10;
int a[N],n,vis[N],pos[N];
ll k;
void solve()
{
    cin>>n>>k;
    rep(i,1,n) cin>>a[i];
    int now=1,id=1;
    while(id<=k&&vis[now]==0){
        vis[now]=1;
        now=a[now];
        k--;
    }
    if(k==0) {
        printf("%d\n",now);
        return ;
    }
    int fa=a[now],len=1;
    while(fa!=now) fa=a[fa],len++;

    int num=0;
    pos[num]=now,fa=a[now];
    while(fa!=now){
        pos[++num]=fa;
        fa=a[fa];
    }
    printf("%d\n",pos[k%len]);

}
int main()
{
	solve();

}


Measured memory_bytes: 5624
import scala.io.StdIn
import scala.util.control.Breaks

object Main {

  def main(args: Array[String]): Unit = {
    val firstLine = StdIn.readLine().split(" ")
    val pnum = firstLine(0).toInt
    val quantum = firstLine(1).toInt
    val myq = new MyQueue
    var totaltime = 0

    // ?????\???????????????
    for (i <- 1 to pnum) {
      val mateArray = StdIn.readLine().split(" ")
      val materi = MyCase(mateArray(0), mateArray(1).toInt)
      myq.enqueue(materi)
    }

    var flag = true
    while (flag) {
      val entity = myq.dequeue()
      if (entity.time <= quantum) {
        totaltime += entity.time
        println(entity.pName + " " + totaltime)
      } else {
        totaltime += quantum
        val newEntity = MyCase(entity.pName, entity.time - quantum)
        myq.enqueue(newEntity)
      }
      if (myq.isEmpty) flag = false
    }
  }
}

class MyQueue {
  val myQueue = new Array[MyCase](10000000)
  var head = 0
  var tail = 0

  def isEmpty(): Boolean = head == tail

  def enqueue(value: MyCase): Unit = {
    myQueue(tail) = value
    if (tail + 1 == myQueue.length) tail = 0 else tail += 1
  }

  def dequeue(): MyCase = {
    val result = myQueue(head)
    if (head + 1 == myQueue.length) head = 0 else head += 1
    result
  }
}

case class MyCase(pName: String, time: Int)

Measured memory_bytes: 125960
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int a[1<<18];
P dp[1<<18];
int main(){
    int n;cin>>n;
    for(int i=0;i<(1<<n);i++){
        cin>>a[i];
        dp[i].first=a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<n);j++){
            if(j&(1<<i)){//集合jにiが含まれる
                int fr=j^(1<<i);//iが含まれてないとき
                vector<ll> v;
                v.push_back(dp[fr].first);
                v.push_back(dp[fr].second);
                v.push_back(dp[j].first);
                v.push_back(dp[j].second);
                sort(all(v));
                reverse(all(v));
                dp[j].first=v[0];
                dp[j].second=v[1];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<(1<<n);i++){
        ans=max(ans,dp[i].first+dp[i].second);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 8192
#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>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
  int n,d;
  cin >> n >> d;
  
  vv x(n, v (d));
  
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> x[i][j];
    }
  }
  
  int ans = 0;
  
  for(int i=0; i<n; i++){
    for(int k=i+1; k<n; k++){
      int dist = 0;
      
      for(int j=0; j<d; j++){
        dist += (x[i][j]-x[k][j])*(x[i][j]-x[k][j]);
      }
      if(sqrt(dist)==(int)sqrt(dist))
        ans ++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
# maze = [list(map(int, input().split())) for i in range(H)]
maze = []
s_init_cnt = 0
for i in range(H):
    gyo = list(input())
    s_init_cnt += gyo.count('.')
    maze.append(gyo)

#print(maze)
#print(s_init_cnt)

direction = [(-1, 0), (0, -1), (1, 0), (0, 1)]
reached = [[-1] * W for i in range(H)]
reached[0][0] = 1
from collections import deque


def bfs():
    d = deque([[0, 0]])
    while len(d) > 0:
        px, py = d.popleft()
        for dx, dy in direction:
            tx = px + dx
            ty = py + dy
            if tx >= H or ty >= W or tx < 0 or ty < 0:
                continue
            if reached[tx][ty] != -1 or maze[tx][ty] == '#':
                continue
            else:
                reached[tx][ty] = reached[px][py] + 1
                d.append([tx, ty])
bfs()
ans = reached[H-1][W-1]
if ans == -1:
    print(ans)
else:
    ans = s_init_cnt - ans
    print(ans)


Measured memory_bytes: 9468
n=int(input())
l=list(map(int, input().split()))
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if len(set([l[i],l[j],l[k]]))==3 and l[i]+l[j]>l[k]:
                ans+=1
print(ans)

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class Key, class T> struct radix_heap {
  static_assert(is_integral<Key>::value, "");
  array<vector<pair<Key, T>>, sizeof(Key) * 8 + 1> v;
  Key last = 0;
  size_t sz = 0, ptr = 0;
  static int lg(Key a) { return a ? __lg(a) : -1; }
  void emplace(Key key, T val) {
    assert(key >= last);
    v[lg(key ^ last) + 1].emplace_back(key, val);
    ++sz;
  }
  void pull() {
    if (ptr < v[0].size()) return;
    v[0].clear(), ptr = 0;
    int i = 1;
    while (v[i].empty()) ++i;
    last = min_element(begin(v[i]), end(v[i]), [](auto a, auto b) {
      return a.first < b.first;
    })->first;
    for (auto e : v[i]) v[lg(e.first ^ last) + 1].push_back(e);
    v[i].clear();
  }
  pair<Key, T> top() { return pull(), v[0][ptr]; }
  void pop() { pull(), --sz, ++ptr; }
  bool empty() const { return sz == 0; }
};

template <class T> struct graph {
  struct edge {
    int from, to;
    T w;
  };
  const int n;
  vector<edge> edges;
  vector<int> head;
  graph(int _n = 0) : n(_n), head(n + 1) {}
  void add(int from, int to, T w = 1) {
    edges.push_back({from, to, w}), ++head[from];
  }
  void build() {
    partial_sum(begin(head), end(head), begin(head));
    for (auto&& e : vector<edge>(edges)) edges[--head[e.from]] = e;
  }
  template <class F> void for_each_edge(int from, F f) const {
    for (int i = head[from]; i < head[from + 1]; ++i) f(edges[i]);
  }
};

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; };

template <class T> vector<T> dijkstra(const graph<T>& g, int s) {
  vector<T> d(g.n, inf<T>);
  radix_heap<T, int> rh;
  rh.emplace(d[s] = 0, s);
  while (not rh.empty()) {
    T dv;
    int v;
    tie(dv, v) = rh.top(), rh.pop();
    if (dv != d[v]) continue;
    g.for_each_edge(v, [&](auto&& e) {
      if (chmin(d[e.to], dv + e.w)) rh.emplace(d[e.to], e.to);
    });
  }
  return d;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  int lim = 50 * (n - 1) + 1;
  graph<long long> g(n * lim);
  auto $ = [&](int v, int x) {
    return v * lim + x;
  };
  while (m--) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    for (int x = a; x < lim; ++x) {
      g.add($(u, x), $(v, x - a), b);
      g.add($(v, x), $(u, x - a), b);
    }
  }
  for (int v = 0; v < n; ++v) {
    int c, d;
    cin >> c >> d;
    for (int x = 0; x < lim; ++x) {
      g.add($(v, x), $(v, min(x + c, lim - 1)), d);
    }
  }
  g.build();
  auto d = dijkstra(g, $(0, min(s, lim - 1)));
  for (int v = 1; v < n; ++v) {
    auto res = inf<long long>;
    for (int x = 0; x < lim; ++x) {
      chmin(res, d[$(v, x)]);
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 22236
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int main(){
	int n;
	int a[1010][1010];
	int ptr[1010]={};
	scanf("%d",&n);
	rep(i,1,n+1)rep(j,0,n-1){
		scanf("%d",&a[i][j]);
	}
	int ans=0;
	while(1){
		ans++;
		int flag[1010]={};
		int temp=0,temp2=n;
		rep(i,1,n+1){
			if(ptr[i]<n-1){
				if(!flag[i]){
					int t=a[i][ptr[i]];
					if(a[t][ptr[t]]==i&&!flag[t]){
						temp=flag[i]=flag[t]=1;
						ptr[i]++;
						ptr[t]++;
					}
				}
			}else temp2--;
		}
		if(!temp2){
			printf("%d",ans-1);
			return 0;
		}
		if(!temp){
			puts("-1");
			return 0;
		}
	}
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"

using namespace std;
const long long INF = 1LL << 60;

void chmin(int &a,int b){
    if(a>b)a=b;
    return;
}

void chmax(int &a,int b){
    if(a<b)a=b;
    return;
}

int a[100010][3];
int dp[100010][3];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<3;i++){
       ans=max(dp[n][i],ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 10000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
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() {
	int A, B;
	cin >> A >> B;
	
	int cnt = 1;
	int ans = 0;
	A--;
	while (true)
	{
		if (cnt >=B)break;
		cnt += A;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {

	int n, d, x;
	cin >> n >> d >> x;
	int ans = x;
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;


		++ans;
		for (int i = 1; true; i++)
		{
			if (a * i + 1 <= d) ++ans;
			else break;


		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
S = int(input())

YYMM = 0
MMYY = 0

if S % 100 >= 1 and S % 100 <= 12:
    YYMM = 1

if S // 100 >= 1 and S // 100 <= 12:
    MMYY = 1

if YYMM == 0 and MMYY == 0:
    print('NA')
elif YYMM == 0 and MMYY == 1:
    print('MMYY')
elif YYMM == 1 and MMYY == 0:
    print('YYMM')
else:
    print('AMBIGUOUS')


Measured memory_bytes: 61528
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left
def main():
    n=int(input())
    L=[int(_) for _ in input().split()]
    L.sort()
    ans=0
    for a in range(n-2):
        for b in range(a+1,n-1):
            ans+=bisect_left(L,L[a]+L[b])-b-1
    print(ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 100001;

/******* c++14 don't include *******/

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }

/*******                      *******/

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    
    
    double res = (double)(h*w/2.0);
    
    int res_2 = (x*2==w && y*2==h)? 1:0;
    
    printf("%9f %d\n", res, res_2);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  string b[4];
  b[0]="AC";
  b[1]="WA";
  b[2]="TLE";
  b[3]="RE";
  ll c[4];
  fill(c,c+4,0);
  string a;
  for(ll i=0;i<n;i++){
    cin>>a;
    if(a=="AC"){c[0]++;}
    if(a=="WA"){c[1]++;}
    if(a=="TLE"){c[2]++;}
    if(a=="RE"){c[3]++;}
  }
  for(ll i=0;i<4;i++){
    cout <<b[i] <<" "<<"x"<<" "<< c[i]<<endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
#define ll long long
#define vll vector<ll>
#define ot cout 
#define nl endl
#define fr(a,b) for(auto i=a;i<b;i++)
#define in cin 
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI 3.14159265
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
ll i,j;
ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    ll n;
    cin >> n;
    ll mx=0;
    for(i=1;(i*i)<=n;i++){
        if((i*i)<=n){
            mx=max(mx,(i*i));
        }
    }
    cout << mx << endl;

   
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int s,w; cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}



Measured memory_bytes: 3624
from math import atan2, pi

N, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))

for i, (x, y) in enumerate(XY):
    D = sorted(atan2(X - x, Y - y) for j, (X, Y) in enumerate(XY) if j != i)
    D.append(D[0] + 2 * pi)

    ans = 0
    for a, b in zip(D, D[1:]):
        if b - a >= pi:
            ans = (b - a) - pi
            break

    print(ans / (2 * pi))

Measured memory_bytes: 3444
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();

		int N = sc.nextInt();
		int cnt = 0;
		for (int i = 1; i <= N; i++) {
			int input = sc.nextInt();
			if (input != i) {
				cnt++;
			}
		}

		if (cnt == 2 || cnt == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

typedef long long ll;
bool check(int n){
    while(n){
        int cnt = n % 10;
        if(cnt == 7) return true;
        n /= 10;
    }
    return false;
}
int main(){
    //freopen("in.txt","r",stdin);
    int n;
    cin>>n;
    if(check(n)) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t=0,c=0,k=0;
  cin >>n;
  c=n;
  while(c!=0){
    t=c%10;
    c/=10;
    k+=t;
  }
  if(n%k==0){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}
    
  

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = -1;
		for (int i = 0; i <= 1250; i++) {
			if (8*i/100 ==  A && i/10 == B) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace  std;
#define int long long
#define inf 10000000000000

struct player
{
	int h, p;
};

int n;
player a[5001];
int dp[5001][5001];
bool comp(player p1, player p2)
{
	return min(p1.h, p2.h - p1.p) > min(p2.h, p1.h - p2.p);
}

void read()
{
	cin>>n;
	for(int i = 1; i<=n; i++)
	{
		cin>>a[i].h>>a[i].p;
	}
}

void solve()
{
	sort(a + 1, a + n + 1, comp);

	for(int i=0;i<=n;i++) for(int j = 0; j<=n; j++)dp[i][j] = inf;

	int ans = 1;
	dp[1][1] = a[1].p;

	for(int i = 2; i<=n; i++)
	{
		for(int j = 1;j <= i; j++)
		{
			if(dp[i - 1][j - 1] <= a[i].h)
			{
				ans = max(ans, j);
				dp[i][j] = dp[i - 1][j - 1] + a[i].p;
			}			
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
		}
	}
	cout<<ans<<'\n';
}
signed main()
{
	read();
	solve();
}


Measured memory_bytes: 195712
#include <stdio.h>
#include <math.h>

int main(void)
{
  int i, n, m, p[200000], ac[200000], re = 0, wa[200000] = {0}, mi = 0;
  char s[200000][5]; 
  
  scanf("%d %d", &n, &m);
  
  for( i = 0; i < m; i++ ){
      scanf("%d %s", &p[i], s[i]);
      ac[i] = 0;
      //printf("%s\n", s[i]);
  }
  
  for( i = 0; i < m; i++ ){
      if( ac[p[i]] != 1 ){
          if( s[i][0] == 'A' ){
              ac[p[i]] = 1;
              re++;
              mi += wa[p[i]];
          } else {
              wa[p[i]] += 1;
          }
        
      } 
  }
  
  printf("%d %d\n", re, mi);
  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<cctype>
#include<string>
#include<iomanip>

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


using namespace std;

  int surface[6];

  void turn_n(){                                 //n??????????????¢???????????¨???

    int temp = surface[0];
    surface[0] = surface[1];
    surface[1] = surface[5];
    surface[5] = surface[4];
    surface[4] = temp;
  }
  void turn_e(){                                 //e??????????????¢???????????¨???
    int temp = surface[0];
    surface[0] = surface[3];
    surface[3] = surface[5];
    surface[5] = surface[2];
    surface[2] = temp;
  }
  void turn_s(){                                 //s??????????????¢???????????¨???
    rep(i,0,3) turn_n();
  }
  void turn_w(){                                 //w??????????????¢???????????¨???
    rep(i,0,3) turn_e();
  }

  void top_print(){                                 //????????????????????£???????????¨???
    cout << surface[0] << endl;
  }

void turn(char c){
   if(c=='E') turn_e();
   else  if(c=='W') turn_w();
   else  if(c=='S') turn_s();
   else  if(c=='N') turn_n();
}


int main(){

///////////////////////////////////////////
//2?????????????????¢?????°?????\???
//////////////////////////////////////////
  rep(i,0,6){
    cin >> surface[i];                         //1????????????????????????????????\???
  }

  int second[6];

  rep(i,0,6){
    cin >> second[i];                         //2?????????????????????????????\???
  }



  bool ans = 0;                                   //????????¨??????????????°?????????

  char SWS[10]={"SSSSWSSSS"};
  rep(i,0,10){
      if(surface[1]==second[1]) break;           //1????????¨2???????????????????????????????????¨????????????????????????
      turn(SWS[i]);                              //??????????????????????????¨????????°????????£????????????????\???????????????¢???????????????????????????
    }

    Rep(j,0,4){
      if(surface[0] == second[0]){
          if(surface[2]==second[2] && surface[3]==second[3] && surface[4]==second[4] && surface[5]==second[5])
              ans = 1;                                            //????????¢?????°?????????????????????????????¢?????°??¨?????´?????????true
            }
            turn('W');                             //?\???????????????¢
          }

/////////////////////////////////////
//Yes or No?????¨???
////////////////////////////////////
  if (ans == 1){
      cout << "Yes" <<endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pp printf("Case %d: \n",t)
const unsigned int mod = (int)1e9+7;
const int mx=1000005;
const int maxInt = 2147483647;
ll ans;
vector <int> adj[(int)1e5+5];
int n,k,c[(int)1e5+5];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> k;
    for(int i=0;i<n-1;++i){
    	int u,v;cin >> u >> v;
    	--u;--v;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }
    ans=1;
    queue <pair <int,int> > q;
    q.push(make_pair(0,0));
    while(!q.empty()){
    	int now=q.front().first;
    	int par=q.front().second;
    	q.pop();
    	int cnt=k;
    	if(par==now){
    		ans*=cnt;
    		for(auto v : adj[now])q.push(make_pair(v, now));
    		continue;    	
    		}
    	cnt=cnt-1-c[par];
    	if(par!=0)--cnt;
    	++c[par];
    	ans*=cnt;
    	ans%=mod;
    	for(auto v : adj[now]){
    		if(v==par)continue;
    		q.push(make_pair(v, now));
    	}
    }
    cout << ans%mod;
    return 0;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
using namespace std;
int n,m;
multiset<int> s;

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        int x;
        scanf("%d",&x);
        s.insert(x);
    }
    scanf("%d",&m);
    for (int i=1;i<=m;++i) {
        int x;
        scanf("%d",&x);
        auto t=s.find(x);
        if (t==s.end()) return puts("NO"),0;
        s.erase(t);
    }
    puts("YES");
    return 0;
}

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

ll n,z,w,a[2005];

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

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

    if(n==1)
        cout<<abs(a[0]-w)<<endl;
    else
        cout<<max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]))<<endl;

    return 0;
}


Measured memory_bytes: 3632
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
  //  fileIO();
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == s[i+1])
        {
            cout <<"Bad";
            exit(0);
        }
    }
    cout << "Good";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
const int maxn = (int)(1e5+1);
int arr[maxn];
int main() {
	// #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	// rep(i,0,maxn)
	// arr[i] = 0;
	LL n;cin>>n;
	LL a;
	LL sum = 0;
	rep(i,0,n){
		cin>>a;
		arr[a]++;
		sum += a;
	}
	LL q;
	cin>>q;
	LL b,c;
	rep(i,0,q){
		cin>>b>>c;
		if(arr[b]){
			sum += arr[b]*(c - b);
			arr[c]+= arr[b];
			arr[b] = 0;
		}
		dout(sum);
	}
  	return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pow2(x) (ll(1)<<x)
#define pb push_back
#define mp make_pair
#define w(t) int t;scanf("%d",&t);while(t--)
#define For(i,n) for(int i=0;i<n;i++)
#define scan(n) int n;scanf("%d", &n);
using namespace std;
const int sz = 1e5 + 7;
int n;
vector<int> v(sz);
int mn;
int dp[sz];
int solve(int i=0)
{
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    if(i < n - 2)
        return dp[i] = min(solve(i + 1) + abs(v[i] - v[i+1]), solve(i+2) + abs(v[i] - v[i+2]));
    else if(i==n-2)
        return dp[i] = abs(v[i] - v[i+1]);
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    For(i,n)
        scanf("%d", &v[i]);
    cout<<solve();
}


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

int main() {
  int n, m, a = 0;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int x;
    cin >> x;
    a += x;
  }
  if ( n - a < 0) {
    cout << -1 << endl;
  }
  else {
    cout << n - a << endl;
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int  a[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    rep(i, n) {
        int b;
        cin >> b;
        rep(j, 3) {
            rep(k, 3) {
                if( b == a[j][k] ) {
                    a[j][k] = 0;
                }    
            }
        }
    }
    bool bingo = false;
    rep(i, 3) {
        int count = 0;
        rep(j, 3) {
            if( a[i][j] == 0 ) {
                count += 1;
            }
            if( count == 3 ) bingo = true;
        }
    }
    rep(i, 3) {
        int count = 0;
        rep(j, 3) {
            if( a[j][i] == 0 ) {
                count += 1;
            }
            if( count == 3 ) bingo = true;
        }
    }
    if( a[0][0] == 0 ) {
        if( a[1][1] == 0 ) {
            if( a[2][2] == 0 ) {
                bingo = true;
            }
        }
    }
    if( a[0][2] == 0 ) {
        if( a[1][1] == 0 ) {
            if( a[2][0] == 0 ) {
                bingo = true;
            }
        }
    }
    if( bingo == true ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.lang.RuntimeException

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val t = nextIntList()
    val n = t[0]
    val s = Array(n){ "" }
    repeat(n){
        val tmp = next()
        s[it] = tmp
    }
    s.sort()
    println(s.joinToString(""))

}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!
fun swap(a: String, b: String) = Pair<String, String>(b, a)
fun swap(a: Int, b: Int) = Pair<Int, Int>(b, a)
fun swap(a: Long, b: Long) = Pair<Long, Long>(b, a)
fun swap(a: Double, b: Double) = Pair<Double, Double>(b, a)

Measured memory_bytes: 35988
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int num10000 = 0; num10000 <= N && num10000 * 10000 <= Y; num10000++) {
      for (int num5000 = 0; num5000 + num10000 <= N && (num10000 * 10000 + num5000 * 5000) <= Y; num5000++) {
        int remainder = Y - (num10000 * 10000 + num5000 * 5000);
        if (remainder % 1000 == 0 && (remainder / 1000) + num10000 + num5000 == N) {
          System.out.println(num10000 + " " + num5000 + " " + remainder / 1000);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


Measured memory_bytes: 23508