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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w;
string s[52];

int main() {
	cin >> h >> w;
	inc(i, h) { cin >> s[i]; }
	
	inc(i, h) {
	inc(j, w) {
		if(s[i][j] != '.') { continue; }
		s[i][j] = '0';
		incII(ii, -1, 1) {
		incII(jj, -1, 1) {
			int iii = i + ii;
			int jjj = j + jj;
			if(! inII(iii, 0, h)) { continue; }
			if(! inII(jjj, 0, w)) { continue; }
			if(s[iii][jjj] == '#') { s[i][j]++; }
		}
		}
	}
	}
	
	inc(i, h) { cout << s[i] << "\n"; }
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, max = 0, odd = 0;
    cin >> N;
    int a[100000];
    for(int i=0;i<N;i++){
        cin >> a[i];
        if(a[i] % 2 != 0)
            odd++;
    }

    if(odd != 0)
        cout << "first" << endl;
    else
        cout << "second" << endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;


int main() {
    int n;
    cin >> n;
    REP(i, 100 / 4 + 1) {
        REP(j, 100 / 7 + 1) {
            if (i * 4 + j * 7 == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


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

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	for (auto& x : a)--x;
	set<ll> vs;
	vector<ll> vv;
	ll i = 0;
	vs.insert(i);
	while (true) {
		vv.push_back(i);
		i = a[i];
		ll siz = vs.size();
		vs.insert(i);
		if (siz == vs.size())break;
	}
	vector<ll> loop = vector<ll>(find(vv.begin(), vv.end(), i), vv.end());
	if (k < vv.size())cout << vv[k] + 1 << endl;
	else {
		k -= vv.size();
		cout << loop[k % loop.size()] + 1 << endl;
	}
}


Measured memory_bytes: 16368
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val x = sc.nextInt() - 1
    val y = sc.nextInt() - 1
    var ans = Array(n - 1) { 0 }
    for (i in 0 until n) {
        val dist = Array(n) { 0 }
        val visited = Array(n) { false }
        visited[i] = true
        val que = ArrayDeque<Pair<Int, Int>>()
        que.add(i to 0)
        while (que.count() > 0) {
            val (v, step) = que.pollFirst()
            dist[v] = step
            if (v > 0 && !visited[v - 1]) {
                visited[v - 1] = true
                que.add(v - 1 to step + 1)
            }
            if (v < n - 1 && !visited[v + 1]) {
                visited[v + 1] = true
                que.add(v + 1 to step + 1)
            }
            if (v == x && !visited[y]) {
                visited[y] = true
                que.add(y to step + 1)
            }
            if (v == y && !visited[x]) {
                visited[x] = true
                que.add(x to step + 1)
            }
        }
        for (j in 0 until n) {
            if (dist[j] != 0) {
                ans[dist[j] - 1]++
            }
        }
    }
    println(ans.map { it / 2 }.joinToString("\n"))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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


int main(){
	
	int w,q;
	while(cin>>w>>q,(w + q)){
		int hei[114];
		for(int i=0;i<114;i++){
			if(i<w)hei[i]=-1;
			else hei[i]=810893;
		}
		
		for(int i=0;i<q;i++){
			char c;
			cin>>c;
			if(c=='s'){
				int a,b;
				cin>>a>>b;
				int f=-1;
				for(int j=0;j<w;j++){
					f=j;
					for(int k=0;k<b;k++){
						if(hei[j+k]!=-1)f=-1;
					}
					if(f!=-1){
						break;
					}
				}
				if(f==-1){
					cout<<"impossible"<<endl;
				}
				else{
					cout<<f<<endl;
					for(int j=0;j<b;j++){
						hei[f+j]=a;
					}
				}
			}
			else{
				int a;
				cin>>a;
				for(int j=0;j<w;j++){
					if(hei[j]==a)hei[j]=-1;
				}
			}
			
		}
		cout<<"END"<<endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 10000 + 7;
set<int> g[N];
int c[N];
int ans[N];
PII e[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	int n;
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int u, v;
		cin >> u >> v;
		--u; -- v;
		g[u].insert(v);
		g[v].insert(u);
		e[i] = MP(u, v);
	}
	
	FOR(i, 0, n)
		cin >> c[i];
	sort(c, c + n);
	
	set<PII> s;
	FOR(i, 0, n)
		s.insert(MP(SZ(g[i]), i));
	
	FOR(i, 0, n)
	{
		int top = s.begin()->Y;
		s.erase(s.begin());
		
		ans[top] = c[i];
		for(auto j: g[top])
		{
			s.erase(MP(SZ(g[j]), j));
			g[j].erase(top);
			s.insert(MP(SZ(g[j]), j));
		}		
	}

	LL res = 0;	
	FOR(i, 0, n - 1)
		res += min(ans[e[i].X], ans[e[i].Y]);
		
	cout << res << endl;	
	FOR(i, 0, n)
		cout << ans[i] << ' ';
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int inf = 1012345678;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll n,x,mx,mx2;
	vector<ll> v,v2;
	cin>>n;
	REP(i,0,n-1)
	{	
		cin>>x;
		v.push_back(x);
		v2.push_back(x);
	}
	sort(v.begin(),v.end());
	mx=v[n-1];mx2=v[n-2];
	REP(i,0,n-1)
	{
		if(v2[i]!=mx)
			cout<<mx<<endl;
		else
			cout<<mx2<<endl;
	}
}

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

int main(){
  int a,b,c,x;
  int i,j,out=0;
  cin >> a >> b >> c >> x;
  x /= 50;
  for(i=0;i<=a && (x-10*i)>=0;i++){
    for(j=0;j<=b && (x-10*i-2*j)>=0; j++){
      if( c>=(x-10*i-2*j) ) out++;
    }
  }
  cout << out << endl;

  return 0;
}


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

int main(){
  string S, T;
  cin >> S >> T;
  
  int count = 0;
  for (int i = 0; i < S.size(); i++){
    if (S[i] != T[i]){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3864
H, W, K = map(int, input().split())
s = [list(input()) for _ in range(H)]

ans = [[-1]*W for _ in range(H)]

berry = []

for row in range(H):
    for col in range(W):
        if s[row][col] == "#":
            berry.append([row,col])

n = 0
for b in berry:
    n += 1
    row, col = b
    left, right = col, col
    ans[row][col] = n
    for c in range(col+1, W):
        if s[row][c] == "." and ans[row][c] == -1:
            right += 1
            ans[row][c] = n
        else:
            break
    for c in reversed(range(col)):
        if s[row][c] == "." and ans[row][c] == -1:
            left -= 1
            ans[row][c] = n
        else:
            break
    for r in range(row+1, H):
        for c in range(left, right+1):
            if s[r][c] == "#" or ans[r][c] != -1:
                break
        else:
            for c in range(left, right+1):
                ans[r][c] = n
            continue
        break
    for r in range(row):
        for c in range(left, right+1):
            if s[r][c] == "#" or ans[r][c] != -1:
                break
        else:
            for c in range(left, right+1):
                ans[r][c] = n
            continue
        break

for a in ans:
    print(*a)

Measured memory_bytes: 17936
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007ll
using namespace std;

int main() {
	speed;
	string a, b;
	cin >> a >> b;
	int i = 0, j = 0;
	while (i != a.size() || j != b.size()) {
		if (i < a.size())
			cout << a[i++];
		if (j < b.size())
			cout << b[j++];
	}
}

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

int main() {
	int n;
	string com,word;
	set<string> dic;
	scanf("%d",&n);
	for(int i=0; i<n; ++i) {
		cin >> com >> word;
		if(com=="insert") {
			dic.insert(word);
		} else if(com=="find") {
			if(dic.find(word)!=dic.end()) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}

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

int main(){
    int N,M,sum=0;
    scanf("%d %d",&N,&M);
    int *a=(int*)malloc(sizeof(int)*M);
    for(int i=0;i<M;i++){
        scanf("%d",a+i);
        sum+=a[i];
    }
    if(N>=sum)printf("%d\n",N-sum);
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 1736
n = int(input())
dp = [0]*(n+1)
for i in range(1,n+1):
    dp[i] = 10**9

for i in range(1,n+1):
    for j in range(1,i+1):
        j = 6**(j-1)
        if j> i:break
        dp[i] = min(dp[i],dp[i - j]+1)
    for k in range(1,i+1):
        k = 9**(k-1)
        if k > i:break
            
        dp[i] = min(dp[i] ,dp[i-k]+1)

        
print(dp[n])

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

typedef long long lint;
typedef unsigned long long ulint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline lint ty()
	{
		lint a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007;

int n;
ulint per,val[_],sval[_]={0};

int main()
{
	n=ty(),per=ty();
	for(int i=1;i<=n;i++)val[i]=ty();
	sort(val+1,val+n+1);
	for(int i=1;i<=n;i++)sval[i]=sval[i-1]+val[i];

	ulint ans=per*n+sval[n]*5;

	for(int i=1;i<=n;i++)
	{
		ulint sum=per*i;
		if(i+i>=n)sum+=sval[n]*5;
		else
		{
			int las=n-i-i;
			sum+=(sval[n]-sval[las])*5;
			ulint dlt=7;
			while(las>=i)sum+=(sval[las]-sval[las-i])*dlt,dlt+=2,las-=i;
			sum+=sval[las]*dlt;
		}
		ans=min(ans,sum);
	}

	printf("%lld\n",ans+per*n);

	return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(int argc, char *argv[]) {
	int A, B;
	scanf("%d", &A);
	scanf("%d", &B);
	int plus = A + B;
	int minus = A - B;
	int mult = A * B;

	int result = plus;
	if (minus > result) result = minus;
	if (mult > result) result = mult;

	printf("%d", result);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int a = 0; a < A+1; ++a) {
        for (int b = 0; b < B+1; ++b) {
            int res = X-500*a-100*b;
            if ((res >= 0) and (res/50 < C+1)) {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	static ArrayList<Integer> list;
	static ArrayList<Integer> listA;
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int b = stdIn.nextInt();
			int r = stdIn.nextInt();
			int g = stdIn.nextInt();
			int c = stdIn.nextInt();
			int s = stdIn.nextInt();
			int t = stdIn.nextInt();
			
			if( b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0) {
				break;
			}
			int ans = 100;
			ans -= t*3;
			ans += s*3;
			ans += c*2;
			ans += g*7;
			ans += (r)*16*3;
			ans += r*15;
			ans += (b)*16*5;
			ans += b*15;
			
			System.out.println(ans);
		}
	}
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int n,m,x,y;
int cnt[200020];
int ans=0;

signed main() {
    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x>=100001){
            ans++;
            continue;
        }
        cnt[x]++;
    }
    
    rep(i,1,100001){
        if(cnt[i]==i)continue;
        else if(cnt[i]>i)ans+=cnt[i]-i;
        else ans+=cnt[i];
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    N, M = LMIIS()
    dp = [0] * (M+1)

    DV = [[0] for _ in range(M+1)]

    for _ in range(N):
        A,B = LMIIS()
        if A > M:
            continue
        DV[A].append(B)


    from heapq import heappush, heappop
    ans = 0
    h = []
    for l in DV:
        for item in l:
            heappush(h,-item)
        ans -= heappop(h)
    print(ans)
        
        



    pass
if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
const ll mod = 1000000007;

int n, m;
int a;
priority_queue<int> pq;
int ans;
signed main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a;
        pq.push(a);
    }

    for (int i = 0; i < m; i++) {
        int temp = pq.top();
        pq.pop();
        temp /= 2;
        pq.push(temp);
    }

    while(!pq.empty()) {
        ans += pq.top(); pq.pop();
    }

    cout << ans << endl;

}

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

#define fst first
#define snd second

int N;
vector<pair<int,int>> dat; // until, duration

int main() {
    scanf("%d", &N);
    for(int i=0; i<N; i++) {
        int A, B;
        scanf("%d%d", &A, &B);
        dat.push_back(make_pair(B, A));
    }
    sort(dat.begin(), dat.end());

    int cur = 0;
    for(auto d : dat) {
        int until = d.fst, dur = d.snd;
        if(cur + dur > until) {
            printf("No");
            return 0;
        }
        else {
            cur += dur;
        }
    }
    printf("Yes");
    return 0;
}

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

using namespace std;

int main() {
    int N, D;
    cin >> N >> D;
    int i;
    if(N % (2 * D + 1) == 0) i = N / (2 * D + 1);
    else i = N / (2 * D + 1) + 1;
    cout << i << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		int N = Integer.parseInt(Ws[0]);

		W = in.readLine();
		Ws = W.split(" ");
		int[] X = new int[N];
		for(int i=0;i<N;i++){
			X[i] = Integer.parseInt(Ws[i]);
		}

		Arrays.sort(X);

		long ans = Long.MAX_VALUE;

		long st = X[0];
		long ed = X[X.length-1];
		for(long i=st;i<=ed;i++){
			long tmp=0;
			for(int k=0;k<N;k++){
				tmp+=Math.pow(X[k]-i, 2);
			}
			ans = Math.min(ans, tmp);
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) x.begin(), x.end()
#define PI 3.141592653589793

int main() {
    double R;
    cin >> R;
    double res = 2 * R * PI;
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 3776
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;


int main() {

	long N, M;
	long C;
	cin >> N >> M >> C;

	long num = 0;
	long ans = 0;
	long val = 0;
	vector<long> B(M, 0);
	for (long i = 0; i < B.size(); i++) {
		cin >> B[i];
	}

	for (long i = 0; i < N; i++) {
		num = 0;
		for (long j = 0; j < M; j++) {
			cin >> val;
			num += val * B[j];
		}
		num += C;
		if (num > 0) {
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
k = 0
flg = False
for ai in a:
  if ai == k + 1:
    k += 1
  else:
    flg = True
if k == 0 and flg:
  print(-1)
else:
  print(n - k)

Measured memory_bytes: 32264
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
//using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
 





void solve()
{
  string s;
  cin >> s;
  if(s[0]=='S' and s[1] == 'S' and s[2] == 'S')
  {
    cout << 0 << endl;
    return;
  }
  if(s[1] == 'S')
  {
    cout << 1;
    return;
  } 

  int tot = 0;
  for(auto it:s)
    if(it == 'R')
      tot++;
  cout << tot;
}

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

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

int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a>=13)
        cout<<b;
    else if(a>=6)
        cout<<b/2;
    else
        cout<<"0";
    return 0;
}


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


int main() {
	string S;

	cin >> S;
	int count = 0, ans = 0;
	rep(i, S.size()) {
		if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
			count++;
		}
		else {
			count = 0;
		}

		if (ans < count)
		{
			ans = count;
		}

	}
	cout << ans << endl;


}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする
template<class T> void chmin(T &a, T b){ if(a>b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 *
 *
 * */

int main() {

    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    rep(i, M) cin >> B[i];

    int A[N][M];
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
        }
    }

    int res = 0;
    rep(i, N){
        int score = 0;
        rep(j,M){
            score += A[i][j]*B[j];
        }
        score += C;

        if(score > 0){
            res++;
        }
        // init
        score = 0;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>

using namespace std;
string S;
int a;
int main(){
	cin >> S;
	int n = S.size();
	for(int i=0;i<n-1;i++){
		if(S[i] == S[i+1]){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
	}
	for(int i=0;i<n-2;i++){
		if(S[i] == S[i+2]){
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		String input = s.next();

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

			char c = input.charAt(i);
			char c2 = input.charAt(i+1);

			if(c==c2) {
				System.out.println("Bad");
				return;
			}

		}
		System.out.println("Good");
	}

}


Measured memory_bytes: 21588
p = 10**9+7
def pow(x,m):
    if m==0:return 1
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2))%p
X,Y = map(int,input().split())
K = X+Y
A = [1 for _ in range(K)]
for i in range(2,K):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(K)]
B[K-1] = pow(A[K-1],p-2)
for i in range(K-2,1,-1):
    B[i] = ((i+1)*B[i+1])%p
if 2*Y-X>=0 and Y<=2*X and (X+Y)%3==0 and (2*Y-X)%3==0:
    k = (X+Y)//3
    i = (2*Y-X)//3
    cnt = (A[k]*B[i]*B[k-i])%p
    print(cnt)
else:
    print(0)

Measured memory_bytes: 223920
#include<stdio.h>

void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insSort(int A[],int N){
    int i,j,v;
    for(i=1;i<N;i++){
        v = A[i];
        j = i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}


int main(){
  int N;
  int A[100];
  scanf("%d",&N);
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  trace(A,N);
  insSort(A,N);
  
  return 0;
}

Measured memory_bytes: 1852
#include<stdio.h>

void bubblesort(int,char *,char *);
void selectionsort(int,char *,char *);
void checkstable(int ,char *,char *,char *,char *);
void swap(char *,char *);

int main(){
  int i,n;
  scanf("%d",&n);
  char a[n],b[n],row[n][2],c[n],d[n];
  for(i=0;i<n;i++){
	scanf("%s",row[i]);
	a[i]=row[i][0];
	c[i]=row[i][0];
	b[i]=row[i][1];
	d[i]=row[i][1];
  }
 
  /*
  for(i=0;i<n;i++){
	if(i!=n-1)printf("%c%c ",a[i],b[i]);
	else printf("%c%c\n",a[i],b[i]);
	}*/
 
  bubblesort(n,&a[0],&b[0]);

  for(i=0;i<n;i++){
	if(i!=n-1) printf("%c%c ",a[i],b[i]);
	else printf("%c%c\n",a[i],b[i]);
  }
  printf("Stable\n");
 
  selectionsort(n,&c[0],&d[0]);
  for(i=0;i<n;i++){
	if(i!=n-1) printf("%c%c ",c[i],d[i]);
	else printf("%c%c\n",c[i],d[i]);
  }
  checkstable(n,&a[0],&b[0],&c[0],&d[0]);
  return 0;
}

void bubblesort(int n,char *a,char *b){
  int i,j;
  for(i=0;i<n-1;i++){
	for (j=n-1;j>=i+1;j--){
  	if (b[j] < b[j-1]){
    swap(&a[j],&a[j-1]);
    swap(&b[j],&b[j-1]);
  	}
	}
  }
}

void selectionsort(int n,char *a,char *b){
  int i,j;
  for(i=0;i<n;i++){
	int minj=i;
	for(j=i;j<n;j++){
  	if(b[j]<b[minj]){
    minj=j;
  	}
	}
	if(minj!=i){
  	swap(&a[i],&a[minj]);
  	swap(&b[i],&b[minj]);
	}
  }
}

void checkstable(int n,char *a,char *b,char *c,char *d){
  int i,f=0;
  for(i=0;i<n;i++){
	if(a[i]!=c[i] || b[i]!=d[i])f=1;
  }
  if(f==0)printf("Stable\n");
  else printf("Not stable\n");

}

void swap(char *a,char *b){
  char tmp = *a;
  *a = *b;
  *b = tmp;
}





Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

void insetrtionsort(int a[], int n){
    int j, v;
    for (int i = 0; i < n - 1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    for (int i = 1; i < n; i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for (int i = 0; i < n - 1; i++){
            cout << a[i] << " ";
        }
        cout << a[n-1] << endl;
    }
}

int main()
{   
    int n;
    cin >> n; 
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
  	insetrtionsort(a,n);
    return 0;
}



Measured memory_bytes: 3124
#include <stdio.h>

int main(){
	int i;
	char n[1000]={};
	scanf("%s", n);
	for(i=0;i<1000;i++){
		if(n[i]>=68 && n[i]<=90){
			n[i]=n[i]-3;
		}else if(n[i]==67){
			n[i]=90;
		}else if(n[i]==66){
			n[i]=89;
		}else if(n[i]==65){
			n[i]=88;
		}
	}
	printf("%s\n", n);
	return 0;
	
	
}

Measured memory_bytes: 524
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(L: int):
    # ans = 0
    # for i in range(1, L, 1):
    #     for j in range(1, L-i, 1):
    #         k = L-i-j
    #         if k > 0:
    #             ans = max(ans, i*j*k)
    # print(ans)
    print((L/3)**3)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    solve(L)

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x[ohara],y[ohara],sum=0,pos,t[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      rep(i,n){
        cin>>t[i+1]>>x[i+1]>>y[i+1];
      }
      rep(i,n){
        if((t[i+1]-t[i])%2!=(abs(x[i]-x[i+1])+abs(y[i]-y[i+1]))%2 || abs(x[i]-x[i+1])+abs(y[i]-y[i+1])>t[i+1]-t[i]){
          Cout("No");
          return 0;
        }
      }
      Cout("Yes");
     

       
return 0;
}


Measured memory_bytes: 9216
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 200010;
int n;
ll a[MAXN];
ll sum[MAXN];

void solve() {
  sum[0] = a[0];
  for (int i=1;i<n;i++) {
    sum[i] = sum[i-1] + a[i];
  }

  ll minimum = 1e11;
  for (int i=1;i<n;i++) {
    minimum = min(minimum, abs(2 * sum[i-1] - sum[n-1]));
  }
  cout << minimum << endl;
}

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


Measured memory_bytes: 3328
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S=next();
		int N=S.length();
		int one=0,two=0;
		for(int i=0;i<N;i+=2){
			if(S.charAt(i)=='1')
				one++;
			if(i+1<N&&S.charAt(i+1)=='0')
				one++;
		}
		for(int i=0;i<N;i+=2){
			if(S.charAt(i)=='0')
				two++;
			if(i+1<N&&S.charAt(i+1)=='1')
				two++;
		}
		System.out.println(Math.min(two,one));
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 32880
n = int(input())
t = [0]*24
t[0] = 1
a = 1
for i in sorted(list(map(int, input().split()))):
    t[a*i] += 1
    a *= -1
for i in t:
  if i > 1:
    print(0)
    break
else:
  m = 24
  c = 1
  t += [1]
  for i in t[1:]:
    if i == 1:
      if m > c:
        m = c
      c = 1
    else:
      c += 1       
  print(m)

Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //回数
		
		Map<String,Integer>map = new HashMap<>();
		
		for(int i = 0; i < n; i++) {
			String s = stdIn.next();
			if(map.containsKey(s)) {
				map.put(s,map.get(s)+1);
			}else {
				map.put(s,1);
			}
		}
		
		long cnt = 0;
		
		for(String a: map.keySet()) {
			cnt++;
		}
		System.out.println(cnt);
		
		
	}

}


Measured memory_bytes: 78768
#include<iostream>
using namespace std;
int main()
{
    int a[5];
    for(int i=0;i<5;i++)
        cin>>a[i];
    for(int i=0;i<5;i++)
    {
        if(a[i]==0)
            cout<<i+1<<endl;
    }
    return 0;
}


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

using namespace std;

const double PI = 3.14159265358979;

int dp[1401][1401];
int mapx[1401][1401];

struct Point
{
	int i, j;
	int val;

	Point(int a, int b) {
		if (a < 0 || b < 0)
			val = -1;
		else {
			i = a;
			j = b;
		}
	}
};


int min_square(int i, int j) {
	
	int a = dp[i - 1][j - 1];
	int b = dp[i - 1][j];
	int c = dp[i][j - 1];

	return min(min(a, b), c);
}

int main() {

	int H, W; cin >> H >> W;

	

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> mapx[i][j];
		}
	}

	for (int i = 0; i <= H; i++) {
		dp[i][0] = 0;
	}

	for (int j = 0; j <= W; j++) {
		dp[0][j] = 0;
	}

	int maxx = -1;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			
			dp[i][j] = mapx[i][j] == 0 ? min_square(i, j) + 1 : 0;
			if (maxx < dp[i][j]) 
				maxx = dp[i][j];
		}
	}
	
	cout << maxx * maxx << endl;

	return 0;
}



Measured memory_bytes: 18428
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;

  map<char, ll> ans;
  rep(i, N) {
    string S;
    cin >> S;

    if (i == 0) {
      rep(i, S.size()) {
        ans[S[i]]++;
      }
      continue;
    }

    map<char, ll> m;
    rep(i, S.size()) {
      m[S[i]]++;
    }

    for (auto mm : ans) {
      ans[mm.first] = min(mm.second, m[mm.first]);
    }
  }

  for (auto mm : ans) {
    rep(i, mm.second) {
      cout << mm.first;
    }
  }
  ENDL;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

vector<string> v[20];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int K;
    cin >> K;
    if(K <= 9){
        cout << K << endl;
        return 0;
    }
    string tmp;
    for(int i = 0; i <= 9; i++) v[1].push_back(tmp+(char)('0'+i));
    int cnt = 9;
    for(int i = 2; i < 100; i++){
        for(int j = 0; j <= 9; j++){
            for(int k = 0; k < v[i-1].size(); k++){
                int diff = abs(v[i-1][k][0]-'0' - j);
                if(diff <= 1){
                    string buf;
                    buf+=(char)('0'+j);
                    v[i].push_back(buf+v[i-1][k]);
                    // cout << buf+v[i-1][k] << endl;
                    if(j != 0){
                        cnt++;
                        if(cnt >= K) {
                            cout << buf+v[i-1][k] << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 6264
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

int w, h;
int a[102][102];
int odx[6] = {1, 1, 1, 0, -1, 0};
int edx[6] = {0, 1, 0, -1, -1, -1};
int dy[6] = {-1, 0, 1, 1, 0, -1};
int ans;
typedef pair<int, int> P;
queue<P> q;

void bfs(){
	q.push(P(0, 0));
	a[0][0] = -1;
	while(q.size()){
		P p = q.front();
		q.pop();
		for(int i=0; i<6; i++){
			int nx, ny;
			ny = p.second + dy[i];
			if(p.second % 2 == 1){
				nx = p.first + odx[i];
			}else{
				nx = p.first + edx[i];
			}
			if(0 <= nx && nx < w+2 && 0 <= ny && ny < h+2 && a[nx][ny] != -1){
				if(a[nx][ny] == 0){
					q.push(P(nx, ny));
					a[nx][ny] = -1;
				}else{
					ans++;
				}
			}
		}
	}
}

int main(){
	scanf("%d %d", &w, &h);
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			scanf("%d", &a[j+1][i+1]);
		}
	}
	bfs();
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,K;
    cin >> N >> K;
    vector<long long> H(N);
    for(long long i = 0; i < N; i++){
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    reverse(H.begin(), H.end());
    
    for(long long i = 0; i < K; i++){
        H[i] = 0;
        if(i == N){
            break;
        }
    }
    
    long long S = 0;
    for(long long i = 0; i < N; i++){
        S += H[i];
    }
        cout << S << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
    int N,T,bestCost = -1;
    scanf("%d %d", &N, &T);

    for(int i = 0; i < N; i++){
        int ci,ti;
        scanf("%d %d",&ci,&ti);
        if(ti <= T && (bestCost > ci || bestCost == -1)){
            bestCost = ci;
        }
    }
    if(bestCost == -1)
        cout << "TLE" << endl;
    else   
        cout << bestCost << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (abs(a - c) <= d)cout << "Yes\n";
	else if (abs(a - b) <= d&&abs(b - c) <= d)cout << "Yes\n";
	else cout << "No\n";
}

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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 3e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue

int n;
int a[maxn];
vector < int > v;
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    for(int i = 1; i <= n; i++){
        if(v[n / 2 - 1] >= a[i]){
            cout << v[n / 2] << "\n";
        }
        else {
            cout << v[n / 2 - 1] << "\n";
        }
    }
}


Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    vector<int> line;
    vector<int> son;
    bool check;
}POS;

vector<int> check(POS *pos, int point);
void push(POS *pos, int point, ULL *count, ULL *sums, ULL sum);
int main(){
    int N,Q;
    POS *pos;
    ULL *count;
    ULL *sum;
    vector<int> son;
    int i,j;
    int a,b;
    int p;
    ULL x;
    ULL size;

    cin >> N >> Q;
    pos = new POS[N];
    sum = new ULL[N];
    count = new ULL[N];
    for(i=0;i<N-1;i++){
        cin >> a >> b;
        pos[a-1].line.push_back(b-1);
        pos[i].check = false;
        count[i] = 0;
        sum[i] = 0;
    }
    pos[i].check = false;
    count[i] = 0;
    sum[i] = 0;
    //check(pos,0);

    for(i=0;i<Q;i++){
        cin >> p >> x;
        p--;
        sum[p] += x;

    }
    
    push(pos,0,count,sum,0);

    /*
    for(i=0;i<N;i++){
        if( sum[i] > 0 ){
            push(pos,i,count,sum[i]);
        }
    }
    */

    for(i=0;i<N;i++){
        cout << count[i] << " ";
    }
    cout << endl;
    
    return 0;
}
vector<int> check(POS *pos, int point){
    int i;

    
    vector<int> son;
    vector<int> temp;

    pos[point].check = true;
    for(i=0;i<pos[point].line.size();i++){
        temp = check(pos,pos[point].line[i]);
        son.insert(son.end(),temp.begin(),temp.end());
    }
    son.push_back(point);
    pos[point].son = son;
    
    return son;
}
void push(POS *pos, int point, ULL *count, ULL *sums, ULL sum){
    int i;
    sum += sums[point];
    count[point] = sum;
    for(i=0;i<pos[point].line.size();i++){
        push(pos,pos[point].line[i],count,sums,sum);
    }
}

Measured memory_bytes: 35200
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

const int MAX_ROW = 510; // to be set appropriately
const int MAX_COL = 510; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);

    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
}


int main() {
    int N, M; cin >> N >> M;
    BitMatrix A(M, N);
    vector<int> b(M);
    for (int i = 0; i < M; ++i) {
        int k; cin >> k;
        for (int j = 0; j < k; ++j) {
            int s; cin >> s; --s;
            A[i][s] = 1;
        }
    }
    for (int i = 0; i < M; ++i) {
        int p; cin >> p;
        b[i] = p;
    }
    vector<int> res;
    int rank = linear_equation(A, b, res);
    if (rank == -1) cout << 0 << endl;
    else cout << (1<<(N-rank)) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int MaxN(5003),Mod(1000000007);
int d[MaxN],f[MaxN][MaxN][2],fac[MaxN],inv[MaxN];
int fexp(int x,int k)
{
	int res=1;
	while(k)
	{
		if(k&1) res=1ll*res*x%Mod;
		x=1ll*x*x%Mod;
		k>>=1;
	}
	return res;
}
inline void upd(int &x,int y)
{ (x+=y)%=Mod; }
inline int mul(int x,int y)
{ return 1ll*x*y%Mod; }
int main()
{
	int N,Ans=0;
	bool flag=1;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&d[i]);
	fac[0]=1,inv[0]=1;
	for(int i=1;i<=N;i++)
	{
		fac[i]=1ll*fac[i-1]*i%Mod;
		inv[i]=fexp(fac[i],Mod-2);
		flag&=d[i]==2;
	}
	if(flag)
	{
		printf("%d\n",1ll*fac[N-1]*inv[2]%Mod);
		return 0;
	}
	f[0][0][0]=1;
	for(int i=1;i<=N;i++)
		f[0][0][0]=mul(f[0][0][0],inv[d[i]-1]);
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<i;j++)
			for(int k=0;k<=1;k++)
				f[i][j][k]=f[i-1][j][k];
		if(d[i]>1)
			for(int j=0;j<i;j++)
				for(int k=0;k<=1;k++)
					upd(f[i][j+1][k],mul(f[i-1][j][k],mul(fac[d[i]-1],inv[d[i]-2])));
		if(d[i]>2)
			for(int j=0;j<i;j++)
				upd(f[i][j+1][1],mul(f[i-1][j][0],mul(fac[d[i]-1],inv[d[i]-3])));
	}
	for(int i=3;i<N;i++)
		upd(Ans,mul(f[N][i][1],mul(fac[N-i-1],mul(fac[i-1],inv[2]))));
	printf("%d\n",Ans);
	return 0;
}


Measured memory_bytes: 10752
import sys
n = input()
list_num =list(map(int,input().split()))
output = 1
if 0 in list_num:
    print(0)
    sys.exit()
for i in list_num:
    output = output * i
    if output > 10 ** 18:
        print(-1)
        sys.exit()
print(output)

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

int main(){
    
    int n, a, b;
    cin >> n >> a >> b;
    
    if(a == b){
        cout << 1 << endl;
        return 0;
    }
    
    cout << max(0LL, (b-a)*1LL*(n-2) + 1) << endl;
    
    
    return 0;
    
}


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

#define int long long

using namespace std;

int a[100001];
int pref[100001];
int suff[100001];
int d[100001];

 main () {
	int n, k;
	cin >> n >> k;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		d[i] = d[i - 1] + a[i];
		pref[i] = pref[i - 1] + max (0ll, a[i]);
	}
	for (int i = n;i >= 1;i --) {
		suff[i] = suff[i + 1] + max (0ll, a[i]);
	}
	int ans = 0;
	for (int l = 1;l + k - 1 <= n;l ++) {
		int r = l + k - 1;
		int jkl = d[r] - d[l - 1];
		int cur = max (0ll, jkl);
		cur += pref[l - 1];
		cur += suff[r + 1];
		ans = max (ans, cur);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328