akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2)return puts("No") *0;
  for(int i = 0; i < n/2; ++i){
    if(s[i] != s[n/2 + i]) return puts("No") *0;
  }
  puts("Yes") ;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int stricmp(char* ch1,char* ch2){
    int ch1_length = 0,ch2_length = 0,div;
    for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
    for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
    if(ch1_length != ch2_length) return -1;
    for(int i = 0; ch1[i] != '\0';i++)
    {
        div = ch1[i] -ch2[i];
        if(div != 0 && div != 32 && div != -32)
            return -1;
    }
    return 0;
}
 
int main(){
    char W[11],T[1001];
    int count = 0;
    scanf("%s",W);
    while(true){
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T) == 0) break;
        if(stricmp(T, W) == 0) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2720
#include <cstdio>
#include <cmath>
using namespace std;
const double PI=acos(-1);
int n;
void koch (int cur,double p1x,double p1y,double p2x,double p2y) {
	if (cur==n) return;
	double sx,sy,ux,uy,tx,ty;
	sx=(2*p1x+p2x)/3;
	sy=(2*p1y+p2y)/3;
	tx=(p1x+2*p2x)/3;
	ty=(p1y+2*p2y)/3;
	ux=(tx-sx)*cos(PI/3)-(ty-sy)*sin(PI/3)+sx;
	uy=(tx-sx)*sin(PI/3)+(ty-sy)*cos(PI/3)+sy;
	koch (++cur,p1x,p1y,sx,sy);
	printf ("%.8lf %.8lf\n",sx,sy);
	koch (cur,sx,sy,ux,uy);
	printf ("%.8lf %.8lf\n",ux,uy);
	koch (cur,ux,uy,tx,ty);
	printf ("%.8lf %.8lf\n",tx,ty);
	koch (cur,tx,ty,p2x,p2y);
}
int main () {
	scanf ("%d",&n);
	printf ("0.00000000 0.00000000\n");
	koch (0,0,0,100,0);
	printf ("100.00000000 0.00000000\n");
    return 0;
}


Measured memory_bytes: 2772
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
int main(){
    char s[5];
    int flag=1;
    int count=0;
    for (int i=0;i < 4;i++)cin >> s[i];
    for(int i=0;i<4;i++){
        count=0;
        for(int j=0;j<4;j++){
            if(s[i]==s[j])count++;
        }
        if(count != 2)flag=0;
    }
    if(flag==1)
    cout << "Yes" << endl;
    else 
    cout << "No"  << endl;
    return 0;
}

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

using namespace std;

int main(){

int N,D;
cin >>N>>D;
int Ans=0;
while(N>0){
N-=2*D+1;
Ans++;
}

cout <<Ans<<endl;

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin>>s;
  int n = s.size();
  vecint bs(n);
  vecint front;
  int cur = 0;
  for(int i=n-1; i>=0; --i) {
    bs[i] = cur;
    cur |= 1 << (s[i] - 'a');
    if (cur == (1 << 26) - 1) {
      cur = 0;
      front.push_back(i);
    }
  }
  int idx = 0;
  while (!front.empty()) {
    REP(i,26) {
      if (((cur>>i)&1) == 0) {
        char c = 'a' + i;
        cout<<c;
        idx = front.back();
        front.pop_back();
        while (s[idx] != c) {
          ++idx;
        }
        cur = bs[idx];
        break;
      }
    }
  }
  REP(i,26) {
    if (((cur>>i)&1) == 0) {
      char c = 'a' + i;
      cout<<c;
      break;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1428
H, W, K = map(int, input().split())
c = [input() for i in range(H)]

ans = 0
# bit 全探索 2^6^2 = 4096
for maskR in range(2 ** H):
    for maskC in range(2 ** W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1
print(ans)

Measured memory_bytes: 9116
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
char s[100005];
int main(){
    scanf("%s",s);
    int l=strlen(s);
    for(int i=0;i<l-8;i++)
        printf("%c",s[i]);
    printf("\n");
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toLong() }
    val burger = LongArray(n.toInt()+1){0L}
    val patty = LongArray(n.toInt()+1){0L}

    burger[0] = 1L
    patty[0] = 1L

    repeat(n.toInt()) {
        burger[it+1] = (2L * burger[it]) + 3L
        patty[it+1] = (2L * patty[it]) + 1L
    }

    fun cal(n: Int, eat: Long): Long {
        if (n == 1) {
            return (when {
                eat >= 4L -> 3L
                eat > 1L -> eat - 1L
                else -> 0L
            })
        }

        if (eat <= 1 + burger[n-1]) {
            return cal(n-1, eat-1)
        } else {
            return patty[n-1] + 1L + cal(n-1, eat - burger[n-1] - 2L)
        }
    }

    println(cal(n.toInt(), x))
}

Measured memory_bytes: 36016
# -*- coding: utf-8 -*-
from operator import itemgetter
n = int(input())
restList = []
for i in range(n):
    city, p = map(str, input().split())
    restList.append([i + 1, city, int(p)])
restList.sort(key=itemgetter(1))

city = restList[0][1]
same_list = []
for R in restList:
    if R[1] == city:
        same_list.append(R)
    else:
        if same_list:
            same_list.sort(key=itemgetter(2), reverse=True)
            for s in same_list:
                print(s[0])
            same_list = []
            same_list.append(R)
    city = R[1]
if same_list:
    same_list.sort(key=itemgetter(2), reverse=True)
    for s in same_list:
        print(s[0])


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
typedef long long LL;

int main() {
	LL n, a, b;
	cin >> n >> a >> b;
	LL dis[100005];
	for (int i = 0;i < n;i++) {
		cin >> dis[i];
	}

	long long ans = 0;
	for (int i = 0;i < n - 1;i++) {
		int d = dis[i + 1] - dis[i];
		if (d*a < b)ans += d*a;
		else ans += b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
use std::io;

fn main() {
    get_line();
    let ns: Vec<u32> = read_ints();
    println!("{}", solve(&ns));
}

fn solve(ns: &[u32]) -> u32 {
    let mut count = 0;
    let mut skip = false;
    for (i, &n) in ns.iter().enumerate() {
        if !skip && i + 1 == n as usize {
            count = count + 1;
            skip = true;
        } else {
            skip = false;
        }
    }
    count
}

fn read_ints() -> Vec<u32> {
    get_line()
        .trim()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect()
}

fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < 60; i++) {
        ll num0 = 0;
        ll num1 = 0;
        for (int j = 0; j < n; j++){
            if (a[j] >> i & 1) num1++;
            else num0++;
        }
        ll sum = num0 * num1;
        sum %= mod;
        ll res = (1LL << i) % mod;
        res *= sum;
        res %= mod;
        ans += res;
        ans %= mod;
    }
    cout << ans << "\n";
}

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

int N, K;
void solve(){
    cin >> N >> K;
    int hight;
    //vector<int> h(N);
    int count = 0;
    for(int i=0; i<N; i++){
        //cin >> h[i];
        cin >> hight;
        if(hight >= K) count++;
        
    }
    cout << count << endl;
}
int main(){
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    vector<ll> p(N,0);
    vector<ll> q(N,0);
    rep(i,N) cin>>A.at(i);
    rep(i,N){
        for(int j=i+1; j<N; j++){
            if(A.at(i)>A.at(j)) p.at(i)++;
        }
    }
    rep(i,N){
        rep(j,N){
            if(A.at(i)>A.at(j)) q.at(i)++;
        }
    }
    ll ans=0;
    ll mod=1e9+7;
    rep(i,N){
        ans+=(K*p.at(i)+q.at(i)*((K*(K-1)/2)%mod))%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int i,n;
	int c[20], v[20];

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (i = 0; i < n; i++) {
		cin >> c[i];
	}

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


	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())))

if n == 1:
  print(1)
  exit()
elif n%2 == 0:
  for i in range(0,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()
else:
  if a[0] != 0 or a[1] == 0:
    print(0)
    exit()
  for i in range(1,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()

mod = 10**9+7
if n%2 == 0: print(2**(n//2)%mod)
else: print(2**((n-1)//2)%mod)

Measured memory_bytes: 20600
#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 pll pair<ll,ll>
#define mod 1000000007
#define wi while
#define vl vector<ll>
#define vi vector<int>
#define map map<char,ll>
#define endl "\n"
const int mxN = 200001;
template <class T>
inline bool chmax(T &a,T b)
{
    if(a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a,T b)
{
    if(a > b)
    {
        a = b;
        return true;
    }
    return false;
}
const ll INF = 1e17;
ll n,m,l,q;
ll fuel[305][305];
ll dist[305][305];
ll s[105000],t[105000];
ll a[100000],b[100000],c[100000];
void input()
{
    cin>>n>>m>>l;
    for(int i=1;i<=m;i++)cin>>a[i]>>b[i]>>c[i];
    cin>>q;
    for(int i=1;i<=q;i++)cin>>s[i]>>t[i];

}
void solve()
{
    input();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            fuel[i][j] = INF;
            dist[i][j] = INF;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    for(int i=1;i<=m;i++)
    {
        chmin(fuel[a[i]][b[i]],c[i]);
        chmin(fuel[b[i]][a[i]],c[i]);
    }
    //floyd warshall algorithm
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                chmin(fuel[i][j],fuel[i][k]+fuel[k][j]);
            }
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(i==j)continue;
            if(fuel[i][j] <= l) chmin(dist[i][j],1ll);
        }
    }
    //again warshall algorithm
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                chmin(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    for(int i=1;i<=q;i++)
    {
        if(dist[t[i]][s[i]] < INF) cout<<dist[t[i]][s[i]] - 1<<endl;
        else
            cout<<-1<<endl;
    }
    return;

}
int main()
{
    
    solve();
    
    return 0;

}


Measured memory_bytes: 7484
#include <iostream>

int main(int argc, char** argv)
{
    int K, X;
    std::cin >> K;
    std::cin >> X;

    for (int i = X - K + 1; i <= X+K-1; i++) {
        std::cout << i << " ";
    }

    std::cout << std::endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    ll ans;
    int tu;
    tu=0;
    if(n%2==1){
        ans=b[(n+1)/2-1]-a[(n+1)/2-1]+1;
    }
    else{
        if((a[n/2-1]+a[n/2])%2==0){
            tu=tu;
        }
        else{
            --tu;
        }
        if((b[n/2-1]+b[n/2])%2==0){
            tu=tu;
        }
        else{
            ++tu;
        }
        ans=((b[n/2-1]+b[n/2])/2-(a[n/2-1]+a[n/2])/2)*2+1+tu;

    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6424
NN = input().split()
N = int(NN[0])
K = int(NN[1])
LL = input().split()
list1 =[]
for i in LL:
  list1.append(int(i))
list1.sort()

total = 0
for i in range(K):
  total += list1[i]
print(total)

Measured memory_bytes: 9152
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
const int N=55,dx[8]={0,0,1,1,1,-1,-1,-1},dy[8]={1,-1,0,1,-1,0,1,-1};
char str[10]={"012345678"};
int main()
{
    int n,m;
    char s[N][N],t[N];
    while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<n;i++){
            scanf("%s",t);
            for(int j=0;j<m;j++)
                s[i][j]=t[j];
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){

                if(s[i][j]=='.'){
                    int ans=0;
                    for(int k=0;k<8;k++)
                        if(i+dx[k]>=0&&i+dx[k]<n&&j+dy[k]>=0&&j+dy[k]<m&&s[i+dx[k]][j+dy[k]]=='#')
                            ans++;
                    s[i][j]=str[ans];
                }

            }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                printf("%c",s[i][j]);
            printf("\n");
        }

    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static bool IsOdd(long n)
		{
			bool isOdd = n % 2 == 1;
			return isOdd;
		}

		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long n = array[0];
			long x = array[1];
			var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			var totals = new long[n - 1];
			for (int i = 0; i < n - 1; ++i) {
				totals[i] = a[i] + a[i + 1];
			}

			long count = 0;
			if (a[0] > x) {
				long diff = a[0] - x;
				count += diff;
				a[0] -= diff;
				totals[0] -= diff;
			}

			for (int i = 0; i < n - 1; ++i) {
				if (totals[i] > x) {
					long diff = totals[i] - x;
					count += diff;

					if (i < n - 2) {
						totals[i + 1] -= diff;
					}
				}
			}

			Console.WriteLine($"{count}");
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 30044
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mod=1000*1000*1000+7;

int n;

ll dp[nax];

ll wyn;

ll sil[nax];
//~ ll kom[nax][nax];

ll dziel(ll a, ll b)
{
	a%=mod;
	b%=mod;
	ll wyk=mod-2;
	while(wyk)
	{
		if (wyk&1)
			a=(a*b)%mod;
		b=(b*b)%mod;
		wyk>>=1;
	}
	return a;
}

ll kom(int a, int b)
{
	if (b>a || b<0)
		return 0;
	return dziel(sil[a], sil[b]*sil[a-b]);
}

int main()
{
	sil[0]=1;
	for (int i=1; i<nax; i++)
		sil[i]=(sil[i-1]*i)%mod;
	scanf("%d", &n);
	dp[1]=1;
	ll s=1;
	for (int i=2; i<=n; i++)
	{
		dp[i]=(sil[i]+sil[i-1]*s)%mod;
		s=(s+dziel(dp[i], sil[i]))%mod;
	}
	debug() << range(dp+1, dp+1+n);
	for (int i=1; i<=n; i++)
	{
		dp[i]=(dp[i]+mod-sil[i])%mod;
	}
	debug() << range(dp+1, dp+1+n);
	for (int i=1; i<=n; i++)
	{
		ll x;
		scanf("%lld", &x);
		ll mno=dp[i]*sil[n-i];
		mno%=mod;
		mno*=kom(n, i);
		mno%=mod;
		wyn=(wyn+x*mno)%mod;
		mno=dp[n-i+1]*sil[i-1];
		mno%=mod;
		mno*=kom(n, i-1);
		mno%=mod;
		wyn=(wyn+x*mno)%mod;
		wyn=(wyn+x*sil[n])%mod;
	}
	wyn%=mod;
	wyn+=mod;
	wyn%=mod;
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 10496
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

road = [a1, b1, a2, b2, a3, b3]

city = [0, 0, 0, 0]

for i in road:
  if i == 1:
    city[0] += 1
  elif i == 2:
    city[1] += 1
  elif i == 3:
    city[2] += 1
  elif i == 4:
    city[3] += 1

if max(city) > 2:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
double dp[305][305][305];
int a[5];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int k=0;k<=n;k++)
    {	
	    for(int j=0;j<=n;j++)
	    {
		    for(int i=0;i<=n;i++)
			{
			    if(i||j||k) 
			    {
			        if(i) dp[i][j][k]+=dp[i-1][j][k]*i/(i+j+k);
			        if(j) dp[i][j][k]+=dp[i+1][j-1][k]*j/(i+j+k);
			        if(k) dp[i][j][k]+=dp[i][j+1][k-1]*k/(i+j+k);
			        dp[i][j][k]+=(double)n/(i+j+k);
			    }
		    }
	    }
    }
    printf("%.15lf\n",dp[a[1]][a[2]][a[3]]);
    return 0;
} 

Measured memory_bytes: 219520
#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <queue>
#include <cmath>
 
using namespace std;

void shortestPathSPFA(vector< vector< pair<int, long long int> > > &graph, vector<long long int> &dist, vector<int> &prev, int root) {
	dist[root] = 0;
	queue<int> q; q.push(root);
	vector<bool> in_q(graph.size(), false); in_q[root] = true;
	while(q.size() > 0) {
		int u = q.front(); q.pop(); in_q[u] = false;
		for (int i = 0; i < graph[u].size(); ++i) {
			int v = graph[u][i].first;
			int w = graph[u][i].second;
			if (dist[u] + w < dist[v]) {
				dist[v] = dist[u] + w;
				prev[v] = u;
				if (!in_q[v]) {
					in_q[v] = true;
					q.push(v);
				}
			}
		}
	}
}
 
int main(void) {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s -= 1; t -= 1;
 
	vector< vector< pair<int, long long int> > > graph_s(n);
	vector< vector< pair<int, long long int> > > graph_t(n);
 
	int u, v, a, b;
	for (int i = 0; i < m; ++i) {
		cin >> u >> v >> a >> b;
		u -= 1; v -= 1;
		graph_s[u].push_back(make_pair(v, a));
		graph_s[v].push_back(make_pair(u, a));
		graph_t[u].push_back(make_pair(v, b));
		graph_t[v].push_back(make_pair(u, b));
	}
	vector<long long int> dist_s(n * 2, LLONG_MAX), dist_t(n * 2, LLONG_MAX);
	vector<int> prev_s(n * 2, -1), prev_t(n * 2, -1);
	shortestPathSPFA(graph_s, dist_s, prev_s, s);
	shortestPathSPFA(graph_t, dist_t, prev_t, t);
 
	vector<long long int> res(n, LLONG_MAX);
	res[n - 1] = dist_s[n - 1] + dist_t[n - 1];
	for (int i = n - 2; i >= 0; --i) {
		res[i] = min(res[i + 1], dist_s[i] + dist_t[i]);
	}
 
	long long int init = 1e15;
	for (int i = 0; i < n; ++i) {
		cout << init - res[i] << endl;
	}
 
	return 0;
 
}

Measured memory_bytes: 22016
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int ok = 1;

int main() {
	cin >> s;
	reverse(s.begin(), s.end());
	while (s.size() != 0) {
		if (s[0] == 'r') {
			if (s.substr(0, 7) == "remaerd") {
				s = s.substr(7, s.size() - 7);
			}
			else if (s.substr(0, 6) == "resare") {
				s = s.substr(6, s.size() - 6);
			}
			else {
				ok = 0;
				break;
			}
		}
		else if (s[0] == 'm') {
			if (s.substr(0, 5) == "maerd") {
				s = s.substr(5, s.size() - 5);
			}
			else {
				ok = 0;
				break;
			}
		}
		else if (s[0] == 'e') {
			if (s.substr(0, 5) == "esare") {
				s = s.substr(5, s.size() - 5);
			}
			else {
				ok = 0;
				break;
			}
		}
		else {
			ok = 0;
			break;
		}
	}
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
const int N=305,mo=1e9+7;
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int head[N],nn[N],l[N],x[N],cnt,f[N][N][N];
inline void dp(int &x,int y){
  x+=y; if (x>=mo) x-=mo;
  return;
}
inline int Max(int a,int b){
  return a>b?a:b;
}
int main(){
  int n=gi(),m=gi(),a,b,c,ans=0;
  for (int i=1; i<=m; ++i){
    a=gi(),b=gi(),c=gi();
    nn[++cnt]=head[b],head[b]=cnt;
    x[cnt]=c,l[cnt]=a;
  }
  f[0][0][0]=1;
  for (int i=0; i<=n; ++i)
    for (int j=0; j<=n; ++j)
      for (int k=0; k<=n; ++k)
	if (f[i][j][k]){
	  c=Max(Max(i,j),k),b=1;
	  for (a=head[c]; a; a=nn[a])
	    if ((i>=l[a])+(j>=l[a])+(k>=l[a])!=x[a])
	      { b=0; break; }
	  if (!b) continue;
	  if (c==n){
	    dp(ans,f[i][j][k]);
	    continue;
	  }
	  dp(f[c+1][j][k],f[i][j][k]);
	  dp(f[i][c+1][k],f[i][j][k]);
	  dp(f[i][j][c+1],f[i][j][k]);
	}
  cout<<ans;
  return 0;
}


Measured memory_bytes: 110848
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> x(3, 0), y(3, 0);
    x[0] = 1e9;
    x[1] = 1;
    y[1] = N / x[0] + (N % x[0] != 0);
    y[0] = (x[0] * y[1]) - N;
    for (int i = 0; i < 3; i++) {
        cout << x[i] << " " << y[i];
        cout << (i == 2 ? '\n' : ' ');
    }
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n = readline() |> parseInt
	d = readline() |> split |> parseMap
	z = zeros(Int,13)
	for i in 1:n
		z[d[i]+1]+=1
	end
	f = z[1]
	for i in 2:13
		if z[i]>2
			f = 1
		end
	end
	if f>0
		println(0)
	else
		a = Int[]
		base = zeros(Int,24)
		base[1] = 1
		for i in 1:12
			if z[i+1]==1
				push!(a,i)
			elseif z[i+1]>1
				base[i+1]+=1
				base[25-i]+=1
			end
		end
		l = length(a)
		z = zeros(Int,l)
		q = 0
		while z!=0
			c = copy(base)
			for i in 1:l
				if z[i]==0
					c[a[i]+1]+=1
				else
					c[25-a[i]]+=1
				end
			end
			dis = 24
			nd = 1
			for i in 2:24
				if c[i]>1
					dis = 0
				elseif c[i]==1
					dis = min(dis,nd)
					nd = 1
				else
					nd += 1
				end
			end
			if c[1]>1
				dis = 0
			elseif c[1]==1
				dis = min(dis,nd)
				nd = 1
			end
			q = max(q,dis)
			if isempty(z)
				z=0
			else
				z[l]+=1
				z=moveup(z,2)
			end
		end
		println(q)
	end
end

main()

Measured memory_bytes: 116780
fun main(args: Array<String>) {
  val A = readLine()!!.toInt()
  val B = readLine()!!.toInt()
  if (A != 1 && B != 1) {
    println(1)
  }
  if (A != 2 && B != 2) {
    println(2)
  }
  if (A != 3 && B != 3) {
    println(3)
  }
}


Measured memory_bytes: 29744
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  return a<6?0:a>12?b:b/2;
}

Measured memory_bytes: 21956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n;
   cin>>n;
   ll base=26;
   vector<ll>v;
   while(n){
       n-=1;
       v.push_back(n%base);
       n=n/base;
   }
   reverse(v.begin(),v.end());
   for(ll i=0;i<v.size();i++){
       cout<<(char)(97+v[i]);
   }
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
    int k,a,b,x[1000],y[1000],z[1000];
    scanf("%d",&k);
    scanf("%d%d",&a,&b);
    if(k==1){
        printf("OK");
        return 0;
    }
    
    else{
        for(int i=a;i<=b;i++){
            if(i%k==0){
                printf("OK");
                return 0;
            }
        }
    printf("NG");
    return 0;
    }
}



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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    vector<string> in;
    string str, s;
    getline(cin, str);
    stringstream ss{str};
    while(getline(ss, s, ' ')) {
        in.push_back(s);
    }

    /*for(const string& s : in) {
        cout << s << endl;
    }*/

    stack<int> v;

    for(int i = 0; i < in.size(); i++) {
        //cin >> in;
        /*if(i != 0) i++;
        int j;
        char in[];
        for(j = 0; bf[j] != ' ' && bf[j] != '\0'; j++) {
            in[j] = bf[i + j];
        }
        i += j;
        */

        //dbg
        //cout << in[i] << endl;

        int op = 0;
        if(in[i] == "+") {
            op = 1;
        } else if(in[i] == "-") {
            op = 2;
        } else if(in[i] == "*") {
            op = 3;
        } else {
            v.push(stoi(in[i]));
        }

        if(op) {
            int y = v.top();
            v.pop();
            int x = v.top();
            v.pop();
            int res;

            switch(op) {
                case 1:
                    res = x + y;
                    break;
                case 2:
                    res = x - y;
                    break;
                case 3:
                    res = x * y;
                    break;
            }
            v.push(res);
        }
    }
    int ot = v.top();
    cout << ot << endl;
    v.pop();
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 3184
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int n,a[200005],tmp=0,tmp2=0;
ll k;
ll Check(ll x) {
	ll ret=0;
	if(x>=0) {
		ret=1ll*tmp2*(2*n-tmp2-1)/2+1ll*tmp*(n-tmp-tmp2);
		for(int i=tmp+tmp2+1,j=n; i<=n; i++) {
			while(j>tmp+tmp2&&1ll*a[i]*a[j]>x)j--;
		//	cout<<i<<' '<<j<<endl;
			if(j<=i)break;
			ret+=j-i;
		}
		for(int i=tmp,j=1; i>0; i--) {
			while(j<=tmp&&1ll*a[i]*a[j]>x)j++;
		//	cout<<i<<' '<<j<<endl;
			if(j>=i)break;
			ret+=i-j;
		}
		return ret;
	}
	else {
		for(int i=1,j=tmp+tmp2+1;i<=tmp;i++){
			while(j<=n&&1ll*a[i]*a[j]>x)j++;
			ret+=n-j+1;
		}
	}
	return ret;
}
int main() {
	scanf("%d%lld",&n,&k);
	for(int i=1; i<=n; i++)scanf("%d",&a[i]),tmp+=(a[i]<0),tmp2+=(a[i]==0);
//	cout<<tmp<<' '<<tmp2<<endl;
//	Check(1000000000000000000ll);
//	return 0;
	sort(a+1,a+n+1);
	ll l=-1000000000000000000ll,r=1000000000000000000ll,ans=0;
	while(l<=r) {
		ll mid=(l+r)/2;
		//cout<<mid<<' '<<Check(mid)<<endl;
		if(Check(mid)>=k)ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  int n,k,x,ans=0;
  vector<int>l;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    cin>>x;
    l.push_back(x);
  }
  sort(l.begin(),l.end());
  for(int i=n-1;i>=n-k;i--){
    ans+=l[i];
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
char ans3[11][11]={
    "aa.",
    "..b",
    "..b"};
char ans4[11][11]={
    "aacd",
    "bbcd",
    "cdgg",
    "cdhh",
};
char ans5[11][11]={
    "abbc.",
    "a..ck",
    "dee.k",
    "d.fii",
    "ggfhh"
};
char ans6[11][11]={
    "aad..f",
    "..deef",
    "bbe..k",
    "..eiik",
    "ccg..n",
    "..ghhn"
};
char ans7[11][11]={
    "aa.bb.c",
    "b.d...c",
    "b.d.ss.",
    ".ffg.hh",
    "c..g.n.",
    "c....nf",
    ".ddee.f"
};
char ans[N][N];
int main()
{
    int n;scanf("%d",&n);
    if(n<=2) printf("-1\n");
    else if(n==3)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            printf(j==n-1?"%c\n":"%c",ans3[i][j]);
    else if(n==4)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            printf(j==n-1?"%c\n":"%c",ans4[i][j]);
    else if(n==5)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            printf(j==n-1?"%c\n":"%c",ans5[i][j]);
    else if(n==6)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            printf(j==n-1?"%c\n":"%c",ans6[i][j]);
    else if(n==7)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            printf(j==n-1?"%c\n":"%c",ans7[i][j]);
    else
    {
        int r=0,c=0;
        memset(ans,'.',sizeof(ans));
        int t=n;
        if(n&1)
        {
            for(int i=0;i<5;i++)
                for(int j=0;j<5;j++)
                ans[r+i][c+j]=ans5[i][j];
            r+=5;c+=5;
            n-=5;
        }
        if(n%4)
        {
            for(int i=0;i<6;i++)
                for(int j=0;j<6;j++)
                ans[r+i][c+j]=ans6[i][j];
            r+=6;c+=6;
            n-=6;
        }
        while(n)
        {
            for(int i=0;i<4;i++)
                for(int j=0;j<4;j++)
                ans[r+i][c+j]=ans4[i][j];
            r+=4;c+=4;
            n-=4;
        }
        for(int i=0;i<t;i++)
            for(int j=0;j<t;j++)
            printf(j==t-1?"%c\n":"%c",ans[i][j]);
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    map<ll,ll> mp;
    vector<pair<ll,ll>> p;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
        p.push_back({a,i});
    }
    sort(ALL(p));
    vector<ll> b,ans(n),c;
    // b[i] := 左からi番目までの累積和
    // c[i] := 右からi番目までの累積和

    for(auto x:mp){
        ll a = x.second*(x.second-1)/2;
        b.push_back(a);
    }

    int m = b.size();
    c.resize(m);
    c[m-1] = b[m-1];

    for(int i=m-2;i>=0;i--){
        c[i] = b[i] + c[i+1];
    }
    for(int i=1;i<m;i++){
        b[i] += b[i-1];
    }
    // ある数値を入れたらO(1)で値を返すようにしたい。
    // 左右から累積和をして、真ん中の数値をそのつど計算して足す感じで
    // あるpについて考える
    // そのpが何番目か? mpのイテレータを加算していく
    int x = p[0].first;
    int cnt = 0;
    auto it = mp.begin();
    for(int i=0;i<n;i++){
        int now = p[i].first;
        if(now > x){
            x = now;
            it++;
            cnt++;
        }
        ans[p[i].second] = (cnt-1>=0?b[cnt-1]:0) + (cnt+1<m?c[cnt+1]:0) + ( ((it->second)-1) * ((it->second)-2))/2;
    }
    rep(i,n)cout << ans[i] << endl;
}

Measured memory_bytes: 16748
#include<bits/stdc++.h>
using namespace std;
const int N=200100;
typedef long long ll;

int n,a[N],zr[N],cnt;
ll ans,f[N],lans[N];

int main()
{
	//freopen("data.in","r",stdin);
	//freopen("program.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<n;i++)
		if(!a[i])zr[i+1]+=zr[i]+1;
	for(int i=1;i<=n;i++)
		if(a[i]||i==n)a[++cnt]=a[i],zr[cnt]=zr[i];
	n=cnt;
	for(int i=1;i<=n;i++)
	{
		lans[i]=(ll)(1+zr[i])*zr[i]/2;
		f[i]=1+zr[i];
		if(a[i])
		{
			for(int j=i-1,tmp=a[i];j&&j-i<22;j--)
				if(tmp+a[j]==(tmp^a[j]))
				{
					tmp+=a[j];
					f[i]+=(1+zr[j]);
				}
				else break;
			for(int j=i-1,tmp=0;j&&j-i<22;j--)
				if(tmp+a[j]==(tmp^a[j]))
				{
					tmp+=a[j];
					lans[i]+=(ll)zr[i]*(1+zr[j]);
				}
				else break;
		}
		else f[i]+=f[i-1]*(zr[i]+1);
		ans+=f[i]+lans[i];
	}
	//for(int i=1;i<=n;i++)printf("%d %d %lld %lld\n",a[i],zr[i],f[i],lans[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a == 2 || b == 2) {
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
		
	}
}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void _run(){
    string s;
    cin>>s;
    int cnt =0,mx=-1;
    int n = sz(s);
    lp(i,n){
        if(s[i]=='R')cnt++;
        else mx = max(cnt,mx),cnt =0;
    }
    mx = max(cnt,mx);
    cout<<mx<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int t=1;
    // scanf("%d",&t);
    while(t--)_run();
    
    return 0;
}

Measured memory_bytes: 3560
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long N = scan.nextLong();
    long K = scan.nextLong();
    scan.close();

    long x = N % K;
    System.out.println(Math.min(x, K-x));
  }
}

Measured memory_bytes: 21844
def ReversePolishNotation(string):

    priority = {"(": 0, ")": 0, "+": 1, "-": 1, "*": 2, "/": 2}

    stack = []
    signStack = []
    isContinue = False

    for item in string[:-1]:

        if str.isdigit(item):
            if not isContinue:
                stack.append(item)
                isContinue = True
            else:
                stack[-1] += item
            continue
        elif item == "(":
            signStack.append(item)
        elif item == ")":
            while signStack[-1] != "(":
                stack.append(signStack.pop())
            signStack.pop()
        else:
            while len(signStack) != 0 and priority[item] <= priority[signStack[-1]]:
                stack.append(signStack.pop())

            signStack.append(item)

        isContinue = False

    while len(signStack) != 0:
        stack.append(signStack.pop())

    return stack


def Calculate(formulaList):

    signs = ["+", "-", "*", "/"]

    stack = []

    for item in formulaList:

        if item not in signs:
            stack.append(item)
        else:
            num1 = int(stack.pop())
            num2 = int(stack.pop())

            if item == "+":
                result = num2 + num1
            elif item == "-":
                result = num2 - num1
            elif item == "*":
                result = num2 * num1
            else:
                result = int(num2 / num1)

            stack.append(result)

    return int(stack[0])


inputCount = int(input())

for lp in range(inputCount):
    formula = input()

    rpn = ReversePolishNotation(formula)
    answer = Calculate(rpn)

    print(answer)



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> c(h);
    for (int i = 0; i < h; i++)
    {
        cin>>c[i];
    }
    int ans=0;
    for (int hbit = 0; hbit < (1<<h); hbit++)
    {
        for (int wbit = 0; wbit < (1<<w); wbit++)
        {
            int cnt=0;
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    if(((hbit & (1<<y))!=0) && ((wbit & (1<<x))!=0) && c[y][x]=='#')
                    {
                        cnt++;
                    }
                }
                
            }
            
            if(cnt==k) ans++;
            //cout<<hbit<<" "<<wbit<<" "<<cnt<<endl;
        }
        
    }
    
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int N = sc.nextInt();
        int[] p = new int[N];
        boolean[] q = new boolean[102];
        for(int i=0; i<N; i++){
            p[i]=sc.nextInt();
            q[p[i]] = true;
        }

        int res=X;
        for(int i=0; i<X+1; i++){
            if(!q[X-i]){
                res=X-i;
                System.out.println(res);
                return;
            }
            if(!q[X+i]){
                res=X+i;
                System.out.println(res);
                return;
            }
        }
        if(X>50){
            res=101;
        }else{
            res=-1;
        }
        System.out.println(res);
        
    
        }
    }

Measured memory_bytes: 35768
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    ans += min(a,k);
    k-= a;
    k-= b;
    ans -= max({0LL,k}); 
    cout << ans << endl;
}

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

int main() 
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && b != c)
	{
		cout << "Yes" << endl;
	}
	else if(a == c && a != b)
	{
		cout << "Yes" << endl;
	}
	else if(b == c && b != a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			int[] ball = new int[10];
			while (sc.hasNextInt()) {
				int dataset = sc.nextInt();
				for (int i = 0; i < dataset; i++) {
					for (int j = 0; j < 10; j++) {
						ball[j] = sc.nextInt();
					}
					if (isReapAll(ball)) {
						System.out.println("YES");
					} else {
						System.out.println("NO");
					}
				}
			}
		} finally {
			sc.close();
		}
	}

	public static boolean isReapAll(int[] numbers) {
		Stack<Integer> stack1 = new Stack<Integer>();
		Stack<Integer> stack2 = new Stack<Integer>();

		for (int number : numbers) {
			if (stack1.isEmpty() || stack1.peek() < number) {
				stack1.push(number);
			} else if (stack2.isEmpty() || stack2.peek() < number) {
				stack2.push(number);
			} else {
				return false;
			}
		}
		return true;
	}
}

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

int main() {
  long n,k,ans=1,mod=1000000007;
  cin >> n >> k;
  vector<vector<long>> aaa(n);
  vector<bool> bo(n,true);
  for(long i=0;i<n-1;i++) {
    long a,b;
    cin >> a >> b;
    aaa[a-1].push_back(b-1);
    aaa[b-1].push_back(a-1);
  }
  queue<long> q;
  queue<long> q1;
  queue<long> q2;
  q.push(0);
  q1.push(0);
  q2.push(0);
  bo[0]=false;
  while(q.size()!=0) {
    long x=q.front();
    long y=q1.front();
    long z=q2.front();
    ans=ans*max(0L,k-y-z)%mod;
    for(long i=0;i<aaa[x].size();i++) {
      if(bo[aaa[x][i]]) {
        bo[aaa[x][i]]=false;
        q.push(aaa[x][i]);
        q1.push(1);
        q2.push(y);
        y++;
      }
    }
    q.pop();
    q1.pop();
    q2.pop();
  }
  cout << ans << endl;
}

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

int main() {

	int n; cin >> n;
	vector<tuple<string, int, int>> t;
	for (int i = 0; i < n; i++) {
		string  s; int p; cin >> s >> p;
		t.push_back({ s,-p,i + 1 });
	}
	sort(t.begin(), t.end());
	for (int i = 0; i < n; i++) {
		cout << get<2>(t[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3580
// AOJ ALDS1_10_B Matrix Chain Multiplication
// 2018.4.30 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_RC 102
#define INF 0x30303030

int cost[MAX_RC][MAX_RC];
int rc[MAX_RC];

int matrixChainMul(int n, int *rc)
{
	int w, i, j, k;

	for (i = 1; i <= n; i++) cost[i][i] = 0;
	for (w = 1; w < n; w++) for (i = 1; i <= n-w; i++) {
		j = i+w, cost[i][j] = INF;
		for (k = i; k < j; k++) {
			int x = cost[i][k]+cost[k+1][j] + rc[i-1]*rc[k]*rc[j];
			if (x < cost[i][j]) cost[i][j] = x;
		}
	}
	return cost[1][n];
}

int main()
{
	int  n, i;

	n = in();
	for (i = 1; i <= n; i++) rc[i-1] = in(), rc[i] = in();
	printf("%d\n", matrixChainMul(n, rc));
	return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define X ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 
// long long p = 1e9+7;
 
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<int> VI;
typedef vector<pair<ll,ll>> VP;
typedef vector<ll> VL;
typedef vector<bool> VB;
 
// typedef pair<ll, ll> PL;
typedef unordered_map<ll, ll> UMP;
#define FOR(i,b) for(i=0;i<b;i++)
#define pb push_back
#define mp make_pair
 
// typedef  unordered_set<ll>;
 
 
void printa(VI &x,ll n){
    ll i;
    FOR(i, n){
        cout<<x[i]<<" ";
    }
    cout<<endl;
}
 
 
/////GLOABLS VARS
ll MOD = 1e9+7;
ll gmx = 1e6+7; 

VL fact(gmx, 1);
//////FUNCTIONS
ll powp(ll val, ll deg)
{
    // debug(val, deg);
    if (!deg)
        return 1;
    if (deg & 1)
        return (powp(val, deg - 1) * val) % MOD;
    ll res = powp(val, deg >> 1);
    // debug(res);
    return (res * res) % MOD;
}





//It is not easy but it can be fun, if you think!!!

//
// ll mx = 2*1e5+7;


int main(){
      ios::sync_with_stdio(0);
      cin.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #endif
    ll n,i;
    cin>>n;
    priority_queue<ll> l;
    VL arr(n);
    FOR(i,n){
        ll u;
        cin>>u;
        arr[i] = u;
        l.push(u);
    }
    FOR(i,n){
        ll u = l.top();
        if(u==arr[i]){
            l.pop();
            ll x = l.top();
            cout<<x<<'\n';
            l.push(u);
        } 
        else{
            cout<<u<<'\n';
        }
    }

    // }    
    
}

Measured memory_bytes: 14684
def main():
    N, K = (int(i) for i in input().split())
    c0 = 0
    c1 = 0
    for num in range(1, N+1):
        if num % K == 0:
            c0 += 1
        elif K % 2 == 0 and num % K == K//2:
            c1 += 1
    print(c0*c0*c0 + c1*c1*c1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768