akhauriyash/Code-Regression huggingface dataset:
import copy, sys

class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

    def equal(self, dice):
        d = copy.copy(self)

        if(dice.front == d.top):
            d.roll('S')
        elif(dice.front == d.right):
            d.roll('WS')
        elif(dice.front == d.left):
            d.roll('ES')
        elif(dice.front == d.back):
            d.roll('SS')
        elif(dice.front == d.bottom):
            d.roll('N')

        if(dice.top == d.right):
            d.roll('W')
        elif(dice.top == d.left):
            d.roll('E')
        elif(dice.top == d.bottom):
            d.roll('WW')

        return not(dice.top != d.top or dice.front != d.front or dice.right != d.right or dice.left != d.left or dice.back != d.back or dice.bottom != d.bottom)

if __name__ == '__main__':
    n = int(input())
    dices = []
    for i in range(n):
        d = Dice([int(_) for _ in input().split()])
        for dice in dices:
            if d.equal(dice):
                print('No')
                sys.exit()
        dices.append(d)
    print('Yes')

Measured memory_bytes: 7356
n=int(input())
a=list(map(int,input().split()))
q=int(input())
from collections import Counter
a_count=Counter(a)
sum=sum(a)
for i in range(q):
  b,c=map(int,input().split())
  if b in a_count:
    sum+=(c-b)*a_count[b]
    a_count[c]+=a_count[b]
    a_count.pop(b)
  print(sum)
    
    

Measured memory_bytes: 21004
(k, s) = [int(i) for i in input().split(" ")]
total = 0
for x in range(0, k + 1):
    rem = s - x
    if rem < 0:
        break
    for y in range(0, k + 1):
        rem = s - x - y
        if rem < 0:
            break
        if rem <= k:
            total = total + 1

print(total)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int N; cin >> N;
    cout << (1000 - N % 1000) % 1000 << endl;
}


Measured memory_bytes: 3620
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var a = input[0];
        var b = input[1];

        if (a <= b && b % a == 0)
        {
            Console.WriteLine(a + b);
        }
        else
        {
            Console.WriteLine(b - a);
        }
    }
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		int y,m,d;
		cin>>y>>m>>d;
		int ans=0;
		int ty=1000-y-1;
		ans+=(20*20+19*10)*(ty/3);
		if(ty%3==1) ans+=20*10;
		else if(ty%3==2) ans+=20*15+19*5;
		if(y%3==0)
		{
			ans+=20*(10-m);
			ans+=21-d;
		}
		else
		{
			ans+=39*((10-m)/2);
			if(m%2) ans+=19+21-d;
			else ans+=20-d;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,flag=0;cin>>n;
	while(n>0)
	{
		if(n%10==7)
		{
		cout<<"Yes";flag=1;break;	
		}n/=10;
	}
	if(flag==0) cout<<"No";
 } 

Measured memory_bytes: 3624
N = int(input())

M = [2 for k in range(N+1)]
M[0] = 0
M[1] = 1

for k in range(2, N+1):
    if N//k >1:
        for j in range(k, N+1-k, k):
            M[k+j] +=1

ans = 0
for k in range(1, N+1):
    ans+=(k)*M[k]
print(ans)

Measured memory_bytes: 219484
#include<bits/stdc++.h>
#define ll long long
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 1234567
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL a[10005],b[10005];
int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    for(i = 1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i = 1;i<=n;i++)
    {
        int x=0;
        while(1)
        {
            if(a[i]%2) break;
            else a[i]/=2,x++;
        }
        b[i]=x;
    }
     for(i = 1;i<=n;i++)
    sum+=b[i];
    printf("%d\n",sum);
}



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

const int MAX = 1000000;
const int MOD = 1000000007;
const int MAX_N = 1<<18;
int N, dat[2*MAX_N -1];
void init(int m){
    N=1;
    while(N<m)N*=2;
    for(int i=0;i<2*N-1;i++)dat[i]=LLONG_MAX;
}
void update(int k,int a){
    k+=N-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
}

int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return LLONG_MAX;
    if(a<=l&&r<=b)return dat[k];
    return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
}
signed main() {
 int n,a;
 cin>>n;
 init(n);
 for(int i=0;i<n;i++){
   cin>>a;
   update(i,a);
 }
 //cerr<<'i';
 int ok,ng,mid,j,k,ans=0;
 for(int i=0;i<n;i++){
   ng=-1;ok=i;
   while(abs(ok-ng)>1){
     mid=(ok+ng)/2;
     if(query(mid,i+1,0,0,N)==dat[i+N-1])ok=mid;
     else ng=mid;
   }
   j=ok;
   ng=n;ok=i;
   while(abs(ok-ng)>1){
     mid=(ok+ng)/2;
     if(query(i,mid+1,0,0,N)==dat[i+N-1])ok=mid;
     else ng=mid;
   }
   k=ok;
   ans=(ans+dat[i+N-1]*(i-j+1)*(k-i+1));
  // cerr<<'i';
 }
 cout<<ans;

return 0;
}


Measured memory_bytes: 4480
A,B,C,D = map(int, input().split())
MOD = 998244353
MAX_SIZE = 3010
dp = [[0] * MAX_SIZE for _ in range(MAX_SIZE)]

dp[A][B] = 1
for h in range(A, C+1):
    for w in range(B, D+1):
        if h == A and w == B: continue
        dp[h][w] = dp[h-1][w] * w + dp[h][w-1] * h - dp[h-1][w-1] * (h-1) * (w-1)
        dp[h][w] %= MOD

print(dp[C][D])


Measured memory_bytes: 136876
#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 = 9e18;

signed main() {
    double ans = -1;
    double A, B;
    cin >> A >> B;
    for (double i = 1; i <= 100000; i++) {
        if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(){
    int n,i;
    char h[1000];
    char t[1000];
    int ph=0,pt=0;
    
    scanf("%d",&n);
  
    for(i=0;i<n;i++){
        scanf("%s%s",t,h);
        if(strcmp(t,h)>0) pt+=3;
        if(strcmp(t,h)==0){pt++; ph++;}
        if(strcmp(t,h)<0) ph+=3;
    }
    printf("%d %d\n",pt,ph);
    return 0;
}


Measured memory_bytes: 2044
n=int(input())

t = list(map(int,input().split()))

ans = 0

while sum(t) != 0:
    for i in range(n):
        if t[i] > 0 and i == n-1:
            ans += 1
            t[i] -= 1
        elif t[i] == 0 and i == n-1:
            continue
        elif t[i] > 0 and t[i+1] == 0:
            ans += 1
            t[i] -= 1
        elif t[i] > 0 and t[i+1] > 0:
            t[i] -=1
    #print(t)

print(ans)

Measured memory_bytes: 39408
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int calc_distance(string a, string b) {
    
    for(int i = (int)min(a.size(), b.size()); i >= 0; i--) {
        bool ok = true;
        for(int j = 0; j < i; j++) {
            if(a[a.size() - i + j] != b[j]) {
                ok = false;
                break;
            }
        }
        
        if(ok) {
            return -i;
        }   
    }
           
    return 0;
}


int n;
int dist[15][15];
int memo[15][1 << 15];

int dfs(int v, int state) {
    int res = 0;
    
    if(memo[v][state] <= 0) {
        return memo[v][state];   
    }
    
    for(int i = 0; i < n; i++) {
        if(!(state >> i & 1)) {
            res = min(res, dfs(i, state | 1 << i) + dist[v][i]);
        }
    }
    
    return memo[v][state] = res;
}

int main() {
    
    while(true){
        cin >> n;
        
        if(n == 0) {
            break;
        }
        
        vector<string> s(n);
      
        for(int i = 0; i < n; i++) {
            cin >> s[i];
        }
        
        int len = 0;
        
        for(int i = n - 1; i >= 0; i--) {
            for(int j = 0; j < n; j++) {
                if(i == j) {
                    continue;
                }
                
                if(s[j].find(s[i]) != s[j].npos) {
                    s.erase(s.begin() + i);
                    n--;
                    
                    break;
                }
            }
        }
        
        for(int i = 0; i < n; i++) {
            len += s[i].size();
        }
        
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                dist[i][j] = calc_distance(s[i], s[j]);
            }
        }

        int mini = 0;
        fill((int*)memo, (int*)(memo + 15), 1);

        for(int i = 0; i < n; i++) {
            mini = min(mini, dfs(i, 1 << i));   
        }

        cout << len + mini << endl;
    }
}


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




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
struct node{
	int t,la;
}A[200001];
bool comp(node a,node b){
	return a.la<b.la;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&A[i].t,&A[i].la);
	sort(A+1,A+n+1,comp);
	long long T=0;
	for(int i=1;i<=n;i++){
		T+=A[i].t;
		if(T>A[i].la){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

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

int main() {
    

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    double a;
    double b = 0;
    
    cin >> a;
    
    for (int i = 0; i <= a; i++) {
        if (i % 2 == 1) {
            b += 1;
        }
    }
    
    double c = b / a;
    
    cout << c << endl;
}


Measured memory_bytes: 256
/*
 * aoj/dpl_5_j/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
/* Mod */
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

// P(n, k) = P(n-k, k) + P(n, k-1) (n, k>=0)
// P(0, k) = 1
int N, K;
mint P[1010][1010];
void solve() {
  cin >> N >> K;
  if (N<K) {
      cout << 0 << endl;
      return;
  }
  loop(k,0,K+1) P[0][k] = 1;
  for (int n=1; n<=N; n++) {
    for (int k=1; k<=K; k++) {
      P[n][k] = (n-k>=0 ? P[n-k][k] : 0) + P[n][k-1];
    }
  }
  cout << P[N-K][K] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}



Measured memory_bytes: 11076
#include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector<int> ans;
string s ;
int main(){
  int N;
  cin >>N;
  while(N != 0){
    vector<int> num;
    for (int j = 0;j < N;j++){
      int x;
      cin >> x;
      num.push_back(x);
    }
    sort(num.begin(),num.end());
    int z;
    z = accumulate(num.begin()+1,num.end()-1,0);
    z = (int)z/(N-2);
    ans.push_back(z);
    cin >> N;
}

for (int i = 0 ; i < (int)ans.size();i++){
  cout <<ans[i]<<endl;
}

  return 0;
}



Measured memory_bytes: 3136
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
    int a,b;cin>>a>>b;
    for(int i=1;i<=100000;i++){
        int x=i*8;
        x/=100;
        int y=i*10;
        y/=100;
        if(x==a && y==b){
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int32_t main() {
    IOS;
    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
/*
 * 3 3
9 9 4
 6 6 8
2 1 1
 */

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

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

/* do your best */

// a, b の最大公約数を返す O( log max(a, b) )
long long gcd(long long a, long long b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

const long long MAXN = 1001024;

// ある整数の約数列挙
vector<long long> divisors(long long n) {
  vector<long long> res;
  for(long long i = 1; i*i <= n; ++i) {
    if(n % i != 0) continue;
    res.push_back(i);
    if(n/i == i) continue; // 上の行で追加済み。
    res.push_back(n/i);
  }
  sort(res.begin(), res.end());
  return res;
}


// 素因数分解
map<long long, long long> prime_factors(long long n) {
  map<long long, long long> res;
  if(n == 1) { // n=1 の素因数分解は n^1
    res[n] = 1;
    return res;
  }
  for(long long i = 2, _n = n; i*i <= _n; ++i) {
    while(n % i == 0) {
      ++res[i]; // 素数i^{res[i]}
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}


bool f(const vector<lint> &a) {
  int n = a.size();
  vector<bool> d(MAXN, false);
  for (int i = 0; i < n; i++) {
    auto divs = divisors(a[i]);
    for (auto e : divs) {
      if (e == 1) continue;
      if (d[e]) {
        cerr << e << endl;
        return false;
      }
      d[e] = true;
    }
  }

  return true;
}

bool g(const vector<lint> &a) {
  int n = a.size();
  lint G = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    G = gcd(G, a[i]);
  }

  return (G == 1);
}

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

  bool flag1 = f(a);
  bool flag2 = g(a);
  if (flag1) {
    cout << "pairwise coprime" << endl;
  } else {
    if (flag2) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 10808
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[10000];
void push(int x){
  S[++top]=x;
}
int pop(){
  top--;
  return S[top+1];
}
int main(){
  int x,i,j;
  char s[100];
  top=0;
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+' ){
      i=pop();
      j=pop();
      push(i+j);
    } else if ( s[0] == '-' ){
      i=pop();
      j=pop();
      push(j-i);
    } else if ( s[0] == '*' ){
      i=pop();
      j=pop();
      push(i*j);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n>=0){
    string num[10]={"0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111"};
    string nows="0000000";
    for(int i=0;i<n;i++){
      int d;cin>>d;
      for(int j=0;j<7;j++){
	if(num[d][j]!=nows[j]){
	  cout<<1;
	}else
	  cout<<0;
      }
      cout<<endl;
      nows=num[d];
    }
  }
  return 0;
}



Measured memory_bytes: 3144
object Main {
  def main(args: Array[String]): Unit = {
    val input = new java.util.Scanner(System.in)
    val n = input.nextInt
    val a = new Array[Int](n)
    for (i <- 0 until n) {
      a(i) = input.nextInt
    }

    println(a.mkString(" "))

    for(i <- 1 until n) {
      val v = a(i)
      var j = i - 1
      while(j >= 0 && a(j) > v){
        a(j+1) = a(j)
        j = j - 1
      }
      a(j+1) = v
      println(a.mkString(" "))
    }

  }
}

Measured memory_bytes: 45040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n,t;
  cin >> n >> t;
  vint C(n);
  vint T(n);
  rep(i,n) cin >> C[i] >> T[i];
  int ans = INF;
  rep(i,n){
    if(t >= T[i]){
      ans = min(ans,C[i]);
    }
  }
  if(ans == INF) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
 
int main() {
    string O, E;
    int i;
    cin >> O >> E;
    for (i = 0; i < E.size(); i++)
      cout << O[i] << E[i];
    if (i < O.size())
      cout << O[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
   int n;cin>>n;
   vvi v(3,vi(n));
   vvi dp(3,vi(n));
   rep(i,n)rep(j,3)cin>>v[j][i];
   rep(i,3)dp[i][0]=v[i][0];
   REP(i,1,n){
      rep(j,3){
         dp[j][i]=max(dp[(j+1)%3][i-1],dp[(j+2)%3][i-1])+v[j][i];
      }
   }
   cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
}

Measured memory_bytes: 5744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		String num="";
		int x=0;
		int sannzyou=0;

		  try{
			 num = input.readLine();
			  x=Integer.parseInt(num);
			  sannzyou=x*x*x;

			 System.out.println(sannzyou);

			  


		    }catch(IOException e)
		    {   System.out.println("Exception : " + e);
		    }


	}

}

Measured memory_bytes: 24212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
const int mod = 1e9 + 7;
int b[2010];
signed main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int khodi = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) khodi++;
        }
    }
    ans += khodi * k % mod;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) b[i]++;
        }
        ans += k * (k - 1) / 2 % mod * b[i];
        ans %= mod;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
//arc072_c.cpp
//Sat Jun  9 08:26:15 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int main(){
	int n;
	cin >> n;

	int a[n];
	ll sum = 0;

	ll ans1 = 0;
	int flag = 1;

	for (int i=0;i<n;i++){
		cin >> a[i];
		sum = sum + a[i];
		if (flag == 1){
			while (sum < 1){
				sum++;
				ans1++;
			}
			flag = -1;
		}else if (flag == -1){
			while (sum > -1){
				sum--;
				ans1++;
			}
			flag = 1;
		}
	}

	sum = 0;
	ll ans2 = 0;
	flag = -1;

	for (int i=0;i<n;i++){
		sum = sum + a[i];
		if (flag == 1){
			while (sum<1){
				sum++;
				ans2++;
			}
			flag = -1;
		}else if (flag == -1){
			while (sum>-1){
				sum--;
				ans2++;
			}
			flag = 1;
		}
	}

	if (ans1>ans2){
		cout << ans2 << endl;
	}else {
		cout << ans1 << endl;
	}
}

Measured memory_bytes: 640
#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() {
  vector<bool> ok(5, false);
  rep(i, 5) {
    int a;
    cin >> a;
    if (a == 0) continue;
    ok[a - 1] = true;
  }
  rep(i, 5) if (ok[i] == false) cout << i + 1 << endl;
}

Measured memory_bytes: 3632
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    A.push_back(0);
    ll ans = 1000;
    ll s = 0;
    REP(i, N)
    {
        if (A[i + 1] > A[i])
        {
            s += ans / A[i];
            ans %= A[i];
        }
        if (A[i + 1] < A[i])
        {
            ans += s * A[i];
            s = 0;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 3632
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "TLE":
        tle += 1
    elif s == "WA":
        wa += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

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

int main()
{
  string S, K = "keyence";
  cin >> S;
  string revS = S;
  reverse(revS.begin(), revS.end());
  for (int i = 0; i <= S.size(); i++)
  {
    string front = S.substr(0, i);
    for (int j = 0; j <= S.size() - i; j++)
    {
      string back = revS.substr(0, j);
      reverse(back.begin(), back.end());
      if (K == front + back)
      {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  int n;
  cin>>n;
  map<int,int> ma1,ma2;
  for (int i=0; i<n; i++) {
    int v;
    cin>>v;
    if (i%2==0) ma1[v]++;
    else ma2[v]++;
  }
  
  int fi1=0,se1=0,v1;
  for (auto p: ma1) {
    if (fi1<p.second) {
      se1=fi1;
      fi1=p.second;
      v1=p.first;
    }
    else if (se1<p.second) {
      se1=p.second;
    }
  }
  int fi2=0,se2=0,v2;
  for (auto p: ma2) {
    if (fi2<p.second) {
      se2=fi2;
      fi2=p.second;
      v2=p.first;
    }
    else if (se2<p.second) {
      se2=p.second;
    }
  }
  if (v1==v2) {
    cout<<min(n-(fi1+se2),n-(fi2+se1))<<endl;
  }
  else cout<<n-(fi1+fi2)<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main(void) {
    int64_t X, Y;
    cin >> X >> Y;
    if((X+Y)%2 == 0) {
        if(X == Y) {
            cout << "Brown" << endl;
        } else {
            cout << "Alice" << endl;
        }
    } else if(X == 0 || Y == 0) {
        cout << "Alice" << endl;
    } else if(abs(X-Y) == 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}


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

int n, a[100100], b[100100], c[100100];
long long sum[100100], ans;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for(int i = 1; i <= n; i++)
		scanf("%d", &c[i]);
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	sort(c + 1, c + n + 1);
	for(int i = n; i >= 1; --i) {
		sum[i] = n - (upper_bound(c + 1, c + n + 1, b[i]) - c) + 1;
		sum[i] += sum[i + 1];
	}
	for(int i = 1; i <= n; i++) {
		ans += sum[upper_bound(b + 1, b + n + 1, a[i]) - b];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean result = isBooleanAns(N);
		System.out.println(result == true ? "Yes" : "No");
	}
	public static boolean isBooleanAns(int n){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(n == 4 * i + 7 * j){
					return true;
				}
			}
		}
	return false;
	}
}


Measured memory_bytes: 22740
#include<iostream>

typedef long long i64;

using namespace std;

int main(){
    i64 A,B,C,K;
    cin>>A>>B>>C>>K;

    i64 ans;

    if(K % 2 == 0){
        ans = A-B;
    }
    else ans = B - A;

    if(ans >= 1e18 || ans <= -1e18){
        cout<<"Unfair\n";
        return 0;
    }

    cout<<ans<<endl;
 
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x | (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    LL sum=0;
    int n;
    cin >> n;
    FOR(i,1,n){
        if(i%3==0 or i%5==0) continue;
        sum+=(LL)i;
    }
    cout << sum;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        float result = N / (2f * D + 1);
        System.out.println((int) Math.ceil(result));
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long combi(int n,int k){
    k = min(k,n-k);
    long long p = 1;
    for(int i = n;i>=n-k+1;i--){
        p*=i;
    }
    rep(i,k){
        p/=(i+1);
    }
    return p;
}
int main(){
    int n,p;
    cin >> n >> p;
    int even = 0;
    int odd = 0;
    int t;
    rep(i,n){
        cin >> t;
        if(t%2==0){
            even++;
        }
        else{
            odd++;
        }
    }
    long long ans = 1;
    rep(i,even){
        ans*=2;
    }
    long long od = 0;
    rep(i,odd+1){
        if(i%2 == p){
            od+=combi(odd,i);
        }
    }
    cout << ans*od << endl;
}

Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for(_ <- 1 to M) {
    val a, b = in.next().toInt
    graph(a) = b :: graph(a)
  }


  //
  val dp = Array.fill[Int](N+1)(-1)
  val stack = new scala.collection.mutable.Stack[Int]

  def calc(): Unit = {
    while(!stack.isEmpty) {
      val now = stack.pop()
      if(now < 0) {
        var res = 0
        for(e <- graph(-now)){
          res = Math.max(res, dp(e)+1)
        }
        dp(-now) = res
      }
      else {
        stack.push(-now)
        for(e <- graph(now)){
          if(dp(e) == -1) {
            stack.push(e)
          }
        }
      }
    }
  }

  
  for (i <- 1 to N) {
    if(dp(i) == -1){
      stack.push(i)
      calc()
    }
  }


  println(dp.max)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

using namespace std;

const int value = INT_MAX;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for( int &x : p){
     cin >> x;   
    }
    vector<int> dp(n,value);
    dp[0] = 0;
    for ( int i = 0; i < n; i++){
        for ( int j = i+1 ; j <= (i + k); j++ ){
            dp[j] =  min(dp[j],dp[i] + abs(p[i] - p[j]));
        }
    }
    cout << dp[n-1];
}

Measured memory_bytes: 1024
/*
g++ --std=c++17 A.cpp
*/

#include <iostream>
#include <iomanip> //! for setprecision(20)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < int(n); ++i)
template<class T> inline bool chmax(T& a, T b) { bool ret = (a < b); if (ret) { a = b; } return ret; }
template<class T> inline bool chmin(T& a, T b) { bool ret = (b < a); if (ret) { a = b; } return ret; }
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int INF = 1e9;
const LL INFL = 1e18;
const int MOD = 1000000007;


template<typename T>
T gcd(T a, T b) 
{
    if (b < a) { //! make sure a <= b
        T tmp = b;
        b = a;
        a = tmp;
    }

    T r = b % a;
    while (r) {
        b = a;
        a = r;
        r = b % a;
    }

    return a;
}


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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> lg(n), rg(n);
  for (int i = 1; i <= n-1; ++i) {
    if (i == 1) {
      lg[1] = a[0];
      rg[1] = a[n-1];
    } else {
      lg[i] = gcd(lg[i-1], a[i-1]);
      rg[i] = gcd(rg[i-1], a[n-i]);
    }
  }
 
  // cout << "lg" << endl; dump(lg); cout << endl;
  // cout << "rg" << endl; dump(rg); cout << endl;

  int ans = max(lg[n-1], rg[n-1]);
  for (int l = 1; l <= n-2; ++l) {
    int r = n-l-1;
    int tmp = gcd(lg[l], rg[r]);
    // cout << "  l = " << l << ", r = " << r << ", tmp = " << tmp << endl;
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4536
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  double ans=0;
  int n;
  cin>>n;
  rep(i,n){
    double num;
    cin>>num;
    ans+=1/num;
  }
  cout<<1/ans<<endl;

  return 0;
}

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

int main()
{
	int n[5];
	int x=0;

	for(int i=0 ;i<5 ;i++){
		cin >> n[i];

	}
	for(int i=0 ;i<5 ;i++){
		for(int j=i+1 ;j<5 ;j++){
			if(n[i] < n[j]){
				x = n[i];
				n[i] = n[j];
				n[j] = x;
			}
		}
	}

	for(int i=0 ;i<5 ;i++){
		cout << n[i] ;
		if(i < 4)
			cout << ' ' ;
		else if(i == 4)
			cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 1000000007
#define N 100
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int n;
string a,b;
int f[N][3][3];
int main() {
	n=read();
	cin >> a >> b;
	if (a[0]==b[0]) f[0][0][0]=f[0][1][1]=f[0][2][2]=1;
	else f[0][0][1]=f[0][0][2]=f[0][1][0]=f[0][1][2]=f[0][2][0]=f[0][2][1]=1;
	for (int i=1; i<n; i++) {
		if (a[i]==a[i-1]) 
			for (int x=0; x<=2; x++) 
				for (int y=0; y<=2; y++) f[i][x][y]=f[i-1][x][y];
		else {
			if (a[i-1]==b[i-1]) {
				if (a[i]==b[i]) {
					for (int x=0; x<=2; x++) 
						for (int y=0; y<=2; y++) if (x^y) (f[i][x][x]+=f[i-1][y][y])%=mod;
				} else {
					for (int x=0; x<=2; x++) 
						for (int y=0; y<=2; y++) if (x^y) 
							for (int o=0; o<=2; o++) if (o!=x&&o!=y) (f[i][x][y]+=f[i-1][o][o])%=mod;
				}
			} else {
				if (a[i]==b[i]) {
					for (int x=0; x<=2; x++) 
						for (int y=0; y<=2; y++) if (x^y) {
							for (int o=0; o<=2; o++) if (o!=x&&o!=y) (f[i][o][o]+=f[i-1][x][y])%=mod;}
				} else {
					for (int x=0; x<=2; x++) 
						for (int y=0; y<=2; y++) if (x^y) {
							for (int j=0; j<=2; j++) if (j!=x) {
								for (int k=0; k<=2; k++) if (k!=y&&k!=j) (f[i][x][y]+=f[i-1][j][k])%=mod;}}
				}
			}
		}
	}
	int ans=0;
	for (int i=0; i<=2; i++)
		for (int j=0; j<=2; j++) (ans+=f[n-1][i][j])%=mod;
	cout << ans << endl;
}

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

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

struct Edge{ int dst, cost; };
typedef vector<Edge> Node;
typedef vector<Node> Graph;
const int INF = 1000000000;
void add_edge(Graph& G, int a, int b) {
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
}
vector<int> SPFA(const Graph& G, int s) {
    int n = G.size();
    vector<int> dist(n, INF);
    vector<bool> inque(n);
    queue<int> que;

    dist[s] = 0;
    que.push(s);
    inque[s] = true;
    while(!que.empty()){
        int v = que.front();
        que.pop();
        inque[v] = false;
        for(Edge e : G[v]) {
            if(dist[e.dst] > dist[v] + e.cost) {
                dist[e.dst] = dist[v] + e.cost;
                if(!inque[e.dst]) {
                    que.push(e.dst);
                    inque[e.dst] = true;
                }
            }
        }
    }
    return dist;
}
int main(){
    iostream_init();
    int N, M, s, t;
    while(cin >> N >> M >> s >> t) {
        s--; t--;
        Graph G(N);
        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            add_edge(G, a, b);
        }

        vector<int> ds = SPFA(G, s);
        vector<int> dt = SPFA(G, t);
        vector<int> cnt(N+10);
        for(int x : dt){
            if(x < INF) cnt[x]++;
        }
        int D = ds[t];
        long long ans = 0;
        REP(i, N) {
            // ds[i] + 1 + E == D-1
            int E = D - ds[i] - 2;
            if(E >= 0) ans += cnt[E];
        }
        cout << ans << endl;

    }

    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 9408
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

vector<string> split(const string &s)
{
	vector<string> v;

	string buf = "";
	rep(i,s.length())
	{
		if (s[i] == ' ')
		{
			v.push_back(buf);
			buf = "";
		}
		else
		{
			buf += s[i];
		}
	}
	if (!buf.empty()) v.push_back(buf);
	return v;
}

int main()
{
	string str;
	while(getline(cin, str), str != "END OF INPUT")
	{
		vector<string> words = split(str);
		rep(i,words.size())
		{
			cout << words[i].length();
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from bisect import bisect_left
N, M = map(int, input().split())
s = input()
safe = []
cnt = 0
for i, m in enumerate(s):
  if m=='1':
    cnt += 1
    if cnt==M:
      print(-1)
      break
  else:
    safe += [i]
    cnt = 0
else:
  ps = N
  ans = []
  while ps!=0:
    ind = bisect_left(safe,ps-M)
    ans += [ps-safe[ind]]
    ps = safe[ind]
  print(*ans[::-1])
    


Measured memory_bytes: 10340
#include<bits/stdc++.h>
#define shreyans ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define mod 1000000007 
#define MINI LLONG_MIN
using namespace std;
typedef long long ll;

ll dp[100007][3],a[100007][3];
int main(){
	
	shreyans
	ll n;cin>>n;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++)cin>>a[i][j];
	}
	for(ll i=0;i<3;i++)dp[0][i] = a[0][i];
	for(ll i=1;i<n;i++){
		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
	
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int a, b, res = 0;
    cin>>a>>b;
    if(a>9||b>9){
        cout<<-1<<endl;
        return 0;
    }
    cout<<a*b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> pq;
  vector<vi> v(110000);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  int ans = 0;
  for(int i = 1; i<=m; i++) {
    rep(j,v[i].size()) pq.push(v[i][j]);
    if(!pq.empty()) {
      int k = pq.top();
      ans += k;
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5888
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j;
	cin>>n;
	map<ll,ll>m;
	for(i=2;i<=n;i++){
		cin>>j;
		m[j]++;
	}
	for(i=1;i<=n;i++)cout<<m[i]<<"\n";
	return 0;
}

Measured memory_bytes: 16148
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
bo = [False] * 8
free = 0
for x in a:
    now = x//400
    if now < 8:
        bo[now] = True
    else:
        free += 1
mi = sum(bo) if sum(bo) > 0 else 1
print(mi, sum(bo) + free)

Measured memory_bytes: 5476
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    string s; cin >> s;
    char min_c = '{';
    for(char c = 'a'; c <= 'z'; c++){
        bool non_exsit = true;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == c){
                non_exsit = false;
                break;
            }
        }
        if(non_exsit) min_c = min(min_c, c);
    }
    if(min_c == '{') cout << "None" << endl;
    else cout << min_c << endl;
}

Measured memory_bytes: 512