akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;
s64 k;
int dp[1 << 9][100001];
vector< P > vw;

int rec(int v, int l)
{
    if (v == 0) return 0;
    if ((1 << k) > v)
    {
        return dp[v][l];
    }

    int ret = rec(v / 2, l);
    if (l >= vw[v - 1].second) ret = max(ret, rec(v / 2, l - vw[v - 1].second) + vw[v - 1].first);

    return ret;
}


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

    int n;
    cin >> n;

    vw.resize(n);
    rep (i, n)
    {
        cin >> vw[i].first >> vw[i].second;
    }

    while ((1ll << (2 * k)) < n) ++k;
    for (int v = 1; v < (1 << k); ++v)
    {
        rep (l, 100000 + 1)
        {
            if (l >= vw[v - 1].second)
            {
                dp[v][l] = max(dp[v / 2][l], dp[v / 2][l - vw[v - 1].second] + vw[v - 1].first);
            }
            else
            {
                dp[v][l] = dp[v / 2][l];
            }
        }
    }

    int q;
    cin >> q;
    while (q--)
    {
        int v, l;
        cin >> v >> l;
        cout << rec(v, l) << "\n";
    }

    return 0;
}



Measured memory_bytes: 205020
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    int r2 = 0, r4 = 0, r1 = 0;
    for (ll l : v) {
        if (l % 4 == 0) r4++;
        else if (l % 2 == 0) r2++;
        else r1++;
    }

    if (r4 + 1 >= (r2 + r1)) {
        cout << "Yes" << endl;
        ret();
    }

    if (r1 == 0) {
        cout << "Yes" << endl;
        ret();
    }

    if (r4 * 2 == (r2 + r1) && r2 >= 2) {
        cout << "Yes" << endl;
        ret();
    }

    cout << "No" << endl;
}


Measured memory_bytes: 4004
#include<stdio.h>
#include<string.h>
int main(){
	char s[256],tmp[256];
	int n,h,i,j;
	while(1){
		scanf("%s",s);
		if(!strcmp(s,"-"))break;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&h);
			for(j=0;j<h;j++)tmp[j]=s[j];
			for(j=0;j<strlen(s)-h;j++)s[j]=s[j+h];
			for(j=0;j<h;j++)s[strlen(s)-h+j]=tmp[j];
		}
		printf("%s\n",s);
	}
	return 0;
}

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

using ll = long long;

int main() {
    int K, T, a, amax = 0;
    cin >> K >> T;
    rep(i, T) {
        cin >> a;
        amax = max(amax, a);
    }
    cout << max(0, amax - (K - amax + 1)) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	char d;
	int p;
	int card[4][13] = {0};
	char q[4] = {'S','H','C','D'};
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d >> p;
		if (d == 'S') {
			card[0][p-1] = 1;
		} else if (d == 'H') {
			card[1][p-1] = 1;
		} else if (d == 'C') {
			card[2][p-1] = 1;
		} else {
			card[3][p-1] = 1;
		}
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (card[i][j] == 0) {
				cout << q[i] << ' ' << j+1 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

int main(){
    int n,m;
    cin>>n>>m;
    ll a[100007];
    priority_queue<ll> pq1;
    rep(i,n){
        cin>>a[i];
        pq1.push(a[i]);
    }
    ll tp=0;
    rep(i,m){
        tp=pq1.top();
        tp /=2;
        pq1.pop();
        pq1.push(tp);
    }
    ll ss=0;
    rep(i,n){
        ss += pq1.top();
        pq1.pop();
    }
    cout<<ss<<endl;
}

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

int main() {
	int n,rem,c=0;
	cin>>n;
	while(n>0){
	   rem=n%10;
	   if(rem==7){
	   c++;
	   break;
	   }
	   n=n/10;
	   
	}
	if(c==1)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3560
def rec(m,i,j)
  m[i][j]=0
  rec(m,i,j+1) if j<11 and m[i][j+1]==1
  rec(m,i,j-1) if j>0 and m[i][j-1]==1
  rec(m,i+1,j) if i<11 and m[i+1][j]==1
  rec(m,i-1,j) if i>0 and m[i-1][j]==1
  return m
end
loop do
  m,c=[],0
  12.times{m<<gets.split("").map(&:to_i)}
  12.times do |i|
    12.times do |j|
      if m[i][j]==1
        m=rec(m,i,j)
        c+=1
      end
    end
  end
  p c
  break if !gets
end

Measured memory_bytes: 8752
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    S = input()
    
    for i in range(len(S)):
        if not i % 2:
            if S[i] == "R" or S[i] == "U" or S[i] == "D":
                continue
            else:
                print("No")
                exit()
        else:
            if S[i] == "L" or S[i] == "U" or S[i] == "D":
                continue
            else:
                print("No")
                exit()
    print("Yes")




if __name__ == "__main__":
    main()




Measured memory_bytes: 5168
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

//6桁未満の数字を0でパディングして表示
void convert(int n){
  int array[] = {0, 0, 0, 0, 0, 0};
  int i = 0;
  //逆順の方が入れやすい．後で補正する
  while(n != 0){
    if(n%10 != 0)
      array[i++] = n%10;
    else
      array[i++] = 0;
    n /= 10;
  }
  //最後に逆順に表示
  for(int i=5; i>=0; i--)
    cout << array[i];
}


int main(){
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  vector<vector<int> > v(N);
  rep(i, M){
    cin >> P[i] >> Y[i];
    v[P[i]-1].push_back(Y[i] );
  }
  //ここまで入力

  //年でソート
  rep(i, N)
    sort(v[i].begin(), v[i].end() );

  rep(i, M){
    //県iをパディング表示
    convert(P[i]);
    int pre = P[i]-1;
    //ソート済みの配列において，年が何番目か
    int num = lower_bound(v[pre].begin(), v[pre].end(), Y[i] )-v[pre].begin();
    //何番目かのパディング表示
    convert(num+1);
    cout << endl;
  }

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)){
  	cout<<"Bad";
  }
  else{
  	cout<<"Good";
  }
  cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int N;
        int[] Ai = null;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            Ai = new int[N];
            for (int i = 0; i < N; i++) {
                Ai[i] = sc.nextInt();
            }
        }

        Set<Integer> set = new TreeSet<>();
        for(int i : Ai){
            if(!set.add(i)){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<ll> kaisuu(n,-1);
    kaisuu.at(0) = 0;
    ll now = 0;
    ll next;
    ll times = 0;
    while(true){
        ++times;
        next = a.at(now)-1;
        if(kaisuu.at(next) == -1){
            kaisuu.at(next) = times;
            now = next;
        }else{
            break;
        }
    }
    if(k < times){
        for(i = 0;i < n;++i){
            if(kaisuu.at(i) == k%times){
                cout << i+1 << endl;
                return 0;
            }
        }
    }else{
        ll hazimari = kaisuu.at(next);
        ll syuuki = times-hazimari;
        k -= times;
        k %= syuuki;
        now = next;
        while(k){
            next = a.at(now)-1;
            --k;
            now = next;
        }
        cout << now+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 6424
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<iostream>

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

using namespace std;

map< string,set<string> > f;

set<string> solve(const string &g){
	set<string> member=f[g];
	set<string>::iterator it;
	while(1){
		bool ok=true;
		for(it=member.begin();it!=member.end();++it)if(f.count(*it)>0){
			set<string> tmp=solve(*it);
			member.erase(*it);	// erase group name
			member.insert(tmp.begin(),tmp.end());
			ok=false;
			break;
		}
		if(ok)	break;
	}
	return f[g]=member;
}

int main(){
	for(int n;cin>>n,n;){
		f.clear();
		string group1;
		rep(i,n){
			string s;	cin>>s;
			rep(j,s.length())if(s[j]==':' || s[j]==',' || s[j]=='.')	s[j]=' ';
			stringstream ss(s);
			string group;	ss>>group;
			set<string> member;
			while(ss>>s)	member.insert(s);
			f[group]=member;
			if(i==0)	group1=group;
		}
		cout<<solve(group1).size()<<endl;
	}

	return 0;
}

Measured memory_bytes: 1124
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

	int cnt;
	int ans = 1, max = 0;
	int N, n;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cnt = 0;
		n = i;
		while (n % 2 == 0) {
			n /= 2;
			cnt++;
		}
		if (max < cnt) {
			ans = i;
			max = cnt;
		}
	}

	cout << ans << endl;

	return 0;
}

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

void leave(string s) {
    cout << s << endl;
    exit(0);
}

int main() {
    lint m, k;
    cin >> m >> k;
    lint mx = pow(2, m);

    if(mx <= k)  leave("-1");
    if(m == 1 && k == 0)  leave("0 0 1 1");
    if(m == 1 && k == 1)  leave("-1");

    vector<lint> ans;
    for(lint i=0; i<mx; i++) {
        if(i == k)  continue;
        ans.push_back(i);
    }
    ans.push_back(k);

    for(lint i=mx-1; i>=0; i--) {
        if(i == k)  continue;
        ans.push_back(i);
    }
    ans.push_back(k);

    for(auto& e : ans)  cout << e << " \n"[&e == &ans.back()];
}

Measured memory_bytes: 3952
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        string S;
        cin >> S;

        int cnt0 = 0, cnt1 = 0;
        for (int i = 0; i < S.size(); i++)
        {
                if (S[i] == '1')
                {
                        cnt1++;
                }
                else
                {
                        cnt0++;
                }
        }

        cout << min(cnt0, cnt1) * 2 << endl;

        return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    ll K;
    cin >> S;
    cin >> K;

    ll N;
    N = S.length();
    vector<ll> A(N);

    REP(i, N){
        A[i] = ('z' - S[i] + 1)%26;
    }
  
    REP(i, N-1){
        if(K-A[i] >= 0){
            K = K - A[i]; 
            cout << 'a';
            // S[i] = 'a';
        }
        else{
            cout << S[i];
        }
        
    }

    K = K % 26;
    // cout << K << endl;
    ll t = (S[N-1] -'a' + K)%26;
    // S[N-1] = char('a'+t);
    cout << char('a'+t) << endl;
    // S[N-1] += K;
    // if(S[N-1]>'z'){
    //     S[N-1] -= 26;
    // }
    // cout << S << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int a, b, k;
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int main()
{
    int cnt = 0;
    int r = 0;
    cin >> a >> b >> k;
    for (int i = gcd(a,b); i >=1; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            cnt++;
            r = i;
        }
        if (cnt == k)
            break;
    }
    cout << r;
    return 0;
}

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

int main(){
    int n, m, q; cin >> n >> m >> q;
    int a[550][550];
    int s[550][550];

    rep(_,m){
        int l, r; cin >> l >> r ; l--; r--;
        a[l][r]++;
    }

    rep(i,n){
        rep(j,n){
            s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + a[i][j];
        }
    }

    rep(_,q){
        int a, b; cin >> a >> b; a--; b--;
        cout << s[b+1][b+1] - s[b+1][a] - s[a][b+1] + s[a][a] << endl;
    }

}

Measured memory_bytes: 3072
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main()
{
    int s;
    std::cin >> s;

    std::unordered_set<int> vals;

    vals.insert(s);
    int prev = s;
    for (int i = 2; i < 1000000; ++i) {
        int f = 0;
        if (prev % 2 == 0) {
            f = prev / 2;
        } else {
            f = 3 * prev + 1;
        }

        if (vals.count(f) != 0) {
            std::cout << i << std::endl;
            break;
        }
        vals.insert(f);
        prev = f;
    }

    return 0;
}

Measured memory_bytes: 256
import itertools
H,W,K =map(int,input().split())
c=[]
for i in range(H):
    c.append(list(input()))
ans=0

#K個の#が残るのは何通りか
i_list=[i for i in range(H)]
j_list=[j for j in range(W)]
#塗り替え
for i in range(H+1):
    i_ = list(itertools.combinations(i_list, i))#0-H個選ぶ
    for j in range(W+1):
        j_ = list(itertools.combinations(j_list, j))#0-H個選ぶ
        
        #あるNGパターンにおいて
        for ii in i_: 
            for jj in j_:
                count=0
                #print("START") 
                #print(ii,jj) 
                #各マスを判定
                for iii in range(H):
                    for jjj in range(W):
                        if c[iii][jjj]=="#" and (iii not in ii) and (jjj not in jj):
                            #print(iii,jjj) 
                            count+=1
                #print(count)
                if count==K:
                    ans+=1
print(ans) 


Measured memory_bytes: 74412
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
 
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;
 
using namespace std;
 
int main() {
    string w;
    string in;
    int i = 0;
    cin >> w;
    transform(w.begin(), w.end(), w.begin(), ::tolower);
    while(1){
        cin >> in;
        if(in == "END_OF_TEXT")
            break;
        transform(in.begin(), in.end(), in.begin(), ::tolower);
        int period = in.find('.', 0);
        int excramation = in.find('!', 0);
        int comma = in.find(',', 0);
        int mark = in.find('\"', 0);
        int question = in.find("?", 0);
        if (period != string::npos)
            in.erase(period);
        if (excramation != string::npos)
            in.erase(excramation);
        if (comma != string::npos)
            in.erase(comma);
        if (question != string::npos)
            in.erase(question);
        while (mark != string::npos) {
            in.erase(mark, 1);
            mark = in.find('\"', 0);
        }
 
 
//        cout << w << " " << in << endl;
        if(in == w)
            i++;
    }
    cout << i << endl;
 
    return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

enum { kN = 20002 };
int N, S, R[kN];

int main() {
  while (scanf("%d%d", &N, &S), N) {
    rep(i,N) scanf("%d",R+i);
    sort(R, R+N);
    int ans = 0;
    for (int i = 0; i < N-1; ++i) {
      if (R[i] >= S) {
        ans += N-i-1;
      } else {
        ans += (R+N) - lower_bound(R+i+1, R+N, S-R[i]+1);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 912
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	vi a(5);
	rep(i,5){cin>>a[i];}
	int k; cin>>k;
	sort(a);
	if(a[4]-a[0]>k){
		cout<<":( ";
		return 0;
	}
	cout<<"Yay!";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main(){
    int n;
    cin >> n;
    
    string s,s1;
    cin >> s;
    if(n % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    for(int i =0; i<n/2; ++i){
        if(s[i] != s[i+n/2]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <numeric>
#include <memory>
#include <cstring> 
#include <fstream>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans1,ans2,ans,res,now=1e18;
int o=0;
int vis[100004][2];
long long a[100004],b[100004];
vector <pair<pair<long long,int>,int > > v;
long long sml[100004],fd[100004];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i]>>b[i];long long x=a[i],y=b[i];
		ans1+=x,ans2+=y;
		v.push_back(make_pair(make_pair(x,0),i)); 
		v.push_back(make_pair(make_pair(y,1),i)); 
	}
	ans=min(ans1,ans2);
	sort (v.begin(),v.end());
	for (int i=0;i<n;i++){
		res+=v[i].first.first;
		vis[v[i].second][v[i].first.second]=1;
	}
	bool yes=0;
	for (int i=1;i<=n;i++)
		if (vis[i][0] && vis[i][1]) yes=1;
	if (yes){
		cout<<min(res,ans);return 0;
	}
	sml[0]=1e10;
	for (int i=1;i<=n;i++){
		sml[i]=sml[i-1];
		if (!vis[i][0])sml[i]=min(sml[i-1],a[i]);
		if (!vis[i][1])sml[i]=min(sml[i-1],b[i]);
	}
	fd[n+1]=1e10,fd[n+1]=1e10;
	for (int i=n;i>=1;i--){
		fd[i]=fd[i+1];
		if (!vis[i][0])fd[i]=min(fd[i+1],a[i]);
		if (!vis[i][1])fd[i]=min(fd[i+1],b[i]);
	}
	for (int i=1;i<=n;i++){
		if (vis[i][0]){
			now=min(now,res-a[i]+min(sml[i-1],fd[i+1]));
		}
		if (vis[i][1]){
			now=min(now,res-b[i]+min(sml[i-1],fd[i+1]));
		}
	}
	cout<<min(now,ans);
}

Measured memory_bytes: 10476
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int n, p[200020];
ll d[200020];
int E, t;

struct deq{
	deq(){f=r=0;}
	ll q[200020];
	int f, r;
	void push(ll x){
		while(f-r > 0 && q[f-1] > x)--f;
		q[f++] = x;
	}
	void pop(ll x){if(x==q[r])++r;}
	ll read(){return f==r ? 1e18 : q[r];}
}Q;

void solve(){
	scanf("%d%d%d", &n, &E, &t);
	for(int i=1;i<=n;i++)scanf("%d", p+i);
	Q.push(t);
	ll mn = 1e18;
	for(int i=1, j=1;i<=n;i++){
		while((p[i] - p[j]) * 2 > t){
			Q.pop(d[j-1] - p[j-1] + t);
			mn = min(mn, d[j-1] - p[j-1] - 2 * p[j]);
			++j;
		}
		d[i] = min(Q.read() + p[i], mn + 3LL * p[i]);
		Q.push(d[i] - p[i] + t);
	}
	printf("%lld", (E - p[n]) + d[n]);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;cin>>test;while(test--)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;

int main(){
    string s;
    cin>>s;
    ll ans=0,l=0;
    rep(i,s.length()){
        if(s[i]=='W'){
            ans+=i-l;
            l++;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
         char S[100],T[100];
         cin>>S;
         cin>>T;
         if(strlen(T)==strlen(S)+1)
         {

                           T[strlen(T)-1]='\0';



                  int i=strcmp(S,T);
                  if(i==0)
                           cout<<"Yes"<<endl;
                  else
                           cout<<"No"<<endl;
         }
         else
                  cout<<"No"<<endl;
         return 0;
}


Measured memory_bytes: 3600
//
// Created by Hideaki Imamura on 2020-03-15.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N;
ll x[100010][3];

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> x[i][0] >> x[i][1] >> x[i][2];

    vector<vector<ll>> dp(3, vector<ll>(N + 1, 0));
    dp[0][0] = dp[1][0] = dp[2][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[j][i + 1] = max(dp[(j + 1)%3][i], dp[(j+2)%3][i]) + x[i][j];
        }
    }
    cout << max(dp[0][N], max(dp[1][N], dp[2][N])) << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int dfs(int x,int y,int k){
	if(y==0)
		return x==0?1:0;
	if(x<0)
		return 0;
	int ans=0;
	for(int i=k+1;i<10;i++)
		ans+=dfs(x-i,y-1,i);
	return ans;
}
signed main(void){
	ios::sync_with_stdio(false);
	int x,y;
	while(cin>>y>>x&&(x||y))
		cout<<dfs(x,y,-1)<<endl;
}

Measured memory_bytes: 1192
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using lli = long long;

int N, M, L, Q, dist[310][310];
lli arr[310][310];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	memset(arr, 0x3f, sizeof arr);
	memset(dist, 0x3f, sizeof dist);
	cin >> N >> M >> L;
	for (int i = 0; i < M; ++i)
	{
		int u, v; lli w;
		cin >> u >> v >> w;
		if (w > L) continue;
		arr[u][v] = min(arr[u][v], w);
		arr[v][u] = min(arr[v][u], w);
	}
	for (int k = 1; k <= N; ++k)
		for (int i = 1; i <= N; ++i)
			for (int j = 1; j <= N; ++j)
				arr[i][j] = min(arr[i][j], arr[i][k] + arr[k][j]);
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			if (arr[i][j] <= L) dist[i][j] = 1;
	for (int k = 1; k <= N; ++k)
		for (int i = 1; i <= N; ++i)
			for (int j = 1; j <= N; ++j)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	cin >> Q;
	while (Q--)
	{
		int u, v;
		cin >> u >> v;
		if (arr[u][v] > 1000LL * INT_MAX) cout << "-1\n";
		else
		{
			cout << dist[u][v] - 1 << "\n";
		}
	}
}


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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = a * x + b * y;
    if(x < y){
        ans = min(ans, c * (2 * x) + b * (y - x));
        ans = min(ans, c * (2 * y));
    } else {
        ans = min(ans, c * (2 * y) + a * (x - y));
        ans = min(ans, c * (2 * x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
ok = s[0] == '1' and s[n-1] == '0'
for i in range(n-1):
    ok = ok and s[i] == s[n-2-i]
if not ok:
    print(-1)
    exit()
s2 = s[:n//2]
i = s2.rindex('1')
for k in range(i, n-1):
    print(n, k+1)
while i > 0:
    j = i - 1
    while s[j] != '1':
        j -= 1
    for k in range(j, i):
        print(i+1, k+1)
    i = j


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

#define MOD 1000000007LL

int main(){
	int N;
	cin >> N;
	vector<int> C(N);
	for(auto &i:C)cin >> i;
	
	vector<int> prev(222222,-1);
	vector<long long> dp(N,0);
	dp[0]=1;
	
	for(int i=0;i<N;i++){
		int p=prev[C[i]];
		prev[C[i]]=i;
		if(i==0)continue;
		if(p<0 || p==i-1)dp[i]=dp[i-1];
		else dp[i]=dp[i-1]+dp[p];
		dp[i]%=MOD;
	}
	//for(int i=0;i<N-1;i++)cout << dp[i] << " ";
	cout << dp[N-1] << endl; 
	return 0;
}

Measured memory_bytes: 3456
import Data.List

main :: IO ()
main = do
  [n,m,x,y] <- map read . words <$> getLine
  xs <- map read . words <$> getLine
  ys <- map read . words <$> getLine
  if (maximum $ x:xs :: Int) < (minimum $ y:ys :: Int)
    then putStrLn "No War"
    else putStrLn "War"

Measured memory_bytes: 1020
a = list(input())
b = list(input())

a = [int(a[i]) for i in range(len(a))]
b = [int(b[i]) for i in range(len(b))]

flag = True
if len(a) > len(b):
    print('GREATER')
    flag = False
elif len(b) > len(a):
    print('LESS')
    flag = False
else:
    for i in range(len(a)):
        if a[i] > b[i]:
            print('GREATER')
            flag = False
            break
        elif b[i] > a[i]:
            print('LESS')
            flag = False
            break
if flag:
    print('EQUAL')


Measured memory_bytes: 3064
S = input()

ans = 0

for i in range(len(S)):
  if i % 2 == 0:
    if S[i] in ["R", "U", "D"]:
      ans += 0
    else:
      ans += 1
      
  if i % 2 == 1:
    if S[i] in ["L", "U", "D"]:
      ans += 0
    else:
      ans += 1

if ans == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int N = 0;
    cin >> N;
    
    vector<int> costs;
    
    int previousPreviousHeight = 0;
    int previousHeight = 0;
    int currentHeight = 0;
    
    // First iteration is manual
    cin >> previousPreviousHeight;
    cin >> previousHeight;
    
    costs.push_back(0);
    costs.push_back(abs(previousPreviousHeight - previousHeight));
    
    for(int i = 2; i < N; i++){
        cin >> currentHeight;
        int oneStep = costs[i-1] + abs(previousHeight - currentHeight);
        int twoStep = costs[i-2] + abs(previousPreviousHeight - currentHeight);
        
        if(oneStep < twoStep){
            costs.push_back(oneStep);
        }
        else{
            costs.push_back(twoStep);
        }
        previousPreviousHeight = previousHeight;
        previousHeight = currentHeight;
    }
    cout << costs[costs.size()-1];
}

Measured memory_bytes: 892
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

check = 0
for i in range(n):
        c = min(a[i],b[i])
        check += c
        a[i] -= c;b[i] -= c
        c = min(a[i+1],b[i])
        check += c
        a[i+1]-=c;b[i]-=c
print(check)

Measured memory_bytes: 82148
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

ll func(string s){
  if (s.size()==1) return stoll(s);

  ll tot = stoll(s);
  ll pow2 = 1;
  for (int i=1;i<s.size();i++) {
    tot += func(s.substr(0,i)) + pow2*stoll(s.substr(i));
    pow2*=2;
  }
  
  return tot;
}

int main(){
  string s; cin >> s;
  cout << func(s) << endl;

  return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    public static void main (String[] args) throws IOException
    {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();
    	
    	int len = s.length();
    	int score = 0;
    	
    	for (int i = 1 ; i <= len ; i++){
    		if (i % 2 == 1){
    			if ("p".equals(s.substring(i-1,i))){
    				score = score - 1;
    			}
    			
    		} else {
    			if ("g".equals(s.substring(i-1,i))){
    				score = score + 1;
    			}
    			
    		}
    			
    	}
    	
    	System.out.println(score);
    }	
}
    
   

Measured memory_bytes: 18416
#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 mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> o_tree;

bool comp(array<ll,2> a,array<ll,2> b)
{
  if(a[0]==b[0])
  {
    return a[1]>b[1];
  }
  return a[0]<b[0];
}

void solve()
{
  ll n,t;
  cin>>n>>t;
  ll i,j;
  ll mx=5000+t;
  ll dp[n][mx];
  clr(dp);

  array<ll,2>a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i][0]>>a[i][1];  
  }
  sort(a,a+n,comp);
  // reverse(a,a+n);
  
  for(i=0;i<n;i++)
  {
    for(j=0;j<mx;j++)
    {
      dp[i][j]=max(dp[i][j],(i>0)?dp[i-1][j]:0ll);
    }
    for(j=0;j<t;j++)
    {
      if(j+a[i][0]<mx)
      {
        dp[i][a[i][0]+j]=max(dp[i][a[i][0]+j],(i>0?dp[i-1][j]:0ll)+a[i][1]);
      }
    }
  }
  ll res = *max_element(dp[n-1],dp[n-1]+mx);
  cout<<res<<"\n";
}


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

  if (fopen("input.txt", "r"))
  {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cout << setprecision(20);

  ll t = 1;

  // cin>>t;

  while (t--)
  {
    solve();
  }

  return 0;
}

Measured memory_bytes: 191180
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        String result = "B";
        if (Math.abs(x-a) < Math.abs(x-b)) result = "A";

        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll arr[N],dp[N],br[N];
main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>arr[i];
        if(i>1) br[i] = br[i-2]+arr[i];
        else br[i]=arr[i];
    }
    for(int i=1; i<n; ++i)
    {
        if(i&1)
            dp[i]= max(br[i-1],dp[i-2]+arr[i]);
        else
            dp[i]= max(dp[i-1],dp[i-2]+arr[i]);
    }
    cout<<dp[n-1]<<endl;
}


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

using Weight = long long;
using Vertex = int;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<Weight> Dijkstra(const Graph& G, Vertex s) {
  std::vector<Weight> d(G.size(), -1);
  std::priority_queue<Edge, std::vector<Edge>, std::function<bool(Edge,Edge)>> q([](Edge lhs, Edge rhs){return lhs.weight > rhs.weight;});
  q.push({s, s, 0});
  while(!q.empty()) {
    auto cur = q.top();
    q.pop();
    if(d[cur.to] != -1) continue;
    d[cur.to] = cur.weight;
    for(const auto& nex: G[cur.to]) if(d[nex.to] == -1) q.push({cur.to, nex.to, cur.weight + nex.weight});
  }
  return d;
}

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N);
  for(auto i=0; i<M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a].push_back({a,b,c});
    G[b].push_back({b,a,c});
  }
  set<pair<int,int>> S;
  for(auto v=0; v<N; ++v) {
    auto d = Dijkstra(G, v);
    for(const auto& E: G) for(const auto& e: E) if(d[e.from] + e.weight == d[e.to]) S.emplace(min(e.from, e.to), max(e.from, e.to));
  }
  cout<<M-S.size()<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pr;
typedef set<pr> st;

vvi g(1e5);
vvi tr(1e5);
vi pt(1e5);
vi vst(1e5);
st ans;

void tree(vvi &g, int p, int v)
{
    if (p != -1)
    {
        if (vst[v] == 1)
        {
            int lt = p > v ? v : p;
            int gr = p > v ? p : v;
            auto ret = ans.insert(pr(lt, gr));
            if (ret.second)
            {
                pt[lt] ^= 1;
            }
            return;
        }
        else
        {
            tr[p].push_back(v);
        }
    }
    vst[v] = 1;

    for (int u : g[v])
    {
        if (u != p)
        {
            tree(g, v, u);
        }
    }
}

void solve(int p, int v)
{
    for (int u : tr[v])
    {
        solve(v, u);
    }

    if (p == -1)
    {
        return;
    }

    if (pt[v] == 0)
    {
        ans.insert(pr(p, v));
        pt[p] ^= 1;
    }
    else
    {
        ans.insert(pr(v, p));
        pt[v] ^= 1;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    if (m % 2 == 0)
    {
        tree(g, -1, 0);
        solve(-1, 0);

        for (auto i : ans)
        {
            cout << i.first + 1 << " " << i.second + 1 << endl;
        }
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
// const ll MOD = 1000000007;

template<typename T>
struct DiameterForEdge{
  using Edge = pair<ll, T>;
  vector<T> dp;
  vector< vector<Edge> > G;
  DiameterForEdge(ll n):dp(n),G(n){}
  void add_edge(ll u, ll v, T c){
    G[u].emplace_back(v,c);
    G[v].emplace_back(u,c);
  }
  void dfs(ll v, ll p, ll &s){
    if(p<0) dp[v]=T(0);
    if(dp[s]<dp[v]) s=v;
    for(Edge e:G[v]){
      ll u=e.first;
      if(u==p) continue;
      dp[u]=dp[v]+e.second;
      dfs(u,v,s);
    }
  }
  pair<ll, ll> endPoints(){
    ll s=0;
    dfs(s,-1,s);
    ll t=s;
    dfs(t,-1,t);
    return make_pair(s,t);
  }
  T build(){
    ll t=endPoints().second;
    return dp[t];
  }
  vector<T> distance(ll v){
    dfs(v,-1,v);
    return dp;
  }
  vector<T> farthest(){
    ll t=endPoints().second;
    auto ds=dp;
    auto dt=distance(t);
    for(ll i=0;i<(ll)ds.size();i++)
      if(ds[i]<dt[i]) ds[i]=dt[i];
    return ds;
  }
};

int main() {
  ll N;
  cin>>N;
  DiameterForEdge<ll> G(N);
  for (ll i = 0; i < N - 1; i++) {
    ll u,v,w;
    cin>>u>>v>>w;
    u--; v--;
    G.add_edge(u,v,w);
  }
  vector<ll> dis = G.distance(0);
  for (ll i = 0; i < N; i++) cout<<(dis[i]&1)<<endl;
  return 0;
}

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

int n,a,b,sum,num,ans=0;

int main(){
	cin>>n>>a>>b;
	
	for(int i=1;i<=n;i++){
		num=i;sum=0;
		
		while(num!=0){
			sum+=num%10;
			num/=10;
		}
		
		if(a<=sum&&b>=sum)	ans+=i;
			  
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,l,t;
    ll x[100010],w[100010];
    ll after[100010];
    std::cin >> n>>l>>t;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> x[i]>>w[i];
        if(w[i]==1){
            after[i] = (x[i]+t)%l;
            cnt += (x[i]+t)/l;
        }else{
            after[i] = (x[i]-t%l+l)%l;
            if(x[i]-t<0){
                cnt--;
                cnt -= (t-x[i])/l;
                if( (t-x[i])%l==0 ){
                    cnt++;
                } 
            }
        }
        
    }
    sort(after,after+n);
    for(int i=0;i<n;i++){
        cout<<after[(i+cnt%n+n)%n]<<endl;
    }
}


Measured memory_bytes: 3584
import sys
from collections import Counter
MOD = 10 ** 9 + 7
n, *a = map(int, sys.stdin.read().split())

def main():
  c = Counter(a)
  if n & 1:
    if c[0] != 1:
      print(0); return
  for i in range(1 + (n & 1), n, 2):
    if c[i] != 2:
      print(0); return 
  print(pow(2, n // 2, MOD))

if __name__ ==  '__main__':
  main()

Measured memory_bytes: 14560
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// O(ElogV)

void shortest_path(int s, int V){
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
    int N;
    cin >> N;
    for(int loop = 0; loop < 2; loop++){
        vector<P> v;
        for(int i = 0; i < N; i++){
            long long int A;
            cin >> A;
            v.push_back(P(A, i));
        }
        sort(v.begin(), v.end());
        for(int i = 0; i < N - 1; i++){
            edge e;
            e.cost = v[i + 1].first - v[i].first;
            e.to = v[i + 1].second;
            G[v[i].second].push_back(e);
            e.to = v[i].second;
            G[v[i + 1].second].push_back(e);
        }
    }
    shortest_path(0, N);
    for(int i = 0; i < N; i++){
        cout << d[i] << endl;
    }
    return 0;
}


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

long long mod = 1000000007;

class UnionFind
{
public:
   vector<int> parent;
   UnionFind(int N)
   {
      for (int i = 0; i < N; i++)
      {
         parent.push_back(-1);
      }
   }
   int root(int A)
   {
      if (parent[A] < 0)
         return A;
      return parent[A] = root(parent[A]);
   }
   int size(int A)
   {
      return -parent[root(A)];
   }

   bool unite(int A, int B)
   {
      A = root(A);
      B = root(B);
      if (A == B)
         return false;
      if (size(A) < size(B))
         swap(A, B);
      parent[A] += parent[B];
      parent[B] = A;
      return true;
   }
};

int main(void)
{
   int N;
   cin >> N;
   long long ans = 0;
   for (int i = 1; i < N; i++)
   {
      for (int j = 1; i * j < N; j++)
      {
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}


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

int main(){
    vector<int> S(13,0);
    vector<int> H(13,0);
    vector<int> C(13,0);
    vector<int> D(13,0);
    int n;
    cin >> n;
    for (int i=0; i<n; i++){
        string s;
        int a;
        cin >> s >> a;
        if (s=="S") {S.at(a-1)++;}
        else if (s=="H") {H.at(a-1)++;}
        else if (s=="C") {C.at(a-1)++;}
        else {D.at(a-1)++;}
    }
    for (int i=0; i<13; i++){
        if (S.at(i)==0) {cout << "S " << i+1 << endl;}
    }
    for (int i=0; i<13; i++){
        if (H.at(i)==0) {cout << "H " << i+1 << endl;}
    }
    for (int i=0; i<13; i++){
        if (C.at(i)==0) {cout << "C " << i+1 << endl;}
    }
    for (int i=0; i<13; i++){
        if (D.at(i)==0) {cout << "D " << i+1 << endl;}
    }
}


Measured memory_bytes: 3128
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
string input;
bool dfs(string s, int i)
{
	s += input[i];
	i++;
	if (i == 4) {
		int ans;
		ans = s[0] - '0';
		if (s[1] == '+') {
			ans += s[2] - '0';
		} else {
			ans -= s[2] - '0';
		}
		if (s[3] == '+') {
			ans += s[4] - '0';
		} else {
			ans -= s[4] - '0';
		}
		if (s[5] == '+') {
			ans += s[6] - '0';
		} else {
			ans -= s[6] - '0';
		}
		if (ans == 7) {
			s += "=7";
			cout << s << endl;
			return true;
		} else {
			return false;
		}
	}
	if (dfs(s + '+', i)) return true;
	if (dfs(s + '-', i)) return true;
	return false;
}
int main()
{
	cin >> input;
	dfs("", 0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;


int main(){
	
	int n;
	while(cin>>n,n){
		cin.ignore();
		map<string, int>MP;
		
		for(int i=0;i<n;i++){
			string s;
			
			getline(cin,s);
			
			s+=" ";
			string t="";
			for(int j=0;j<s.size();j++){
				if(s[j]==' '){
					MP[t]++;
					t="";
				}else{
					t+=s[j];
				}
			}
		}
		
		char c;
		cin>>c;
		int cnt=0;
		/*
		cout<<"\n";
		map<string,int>::iterator it = MP.begin();
		for(;it!=MP.end();it++){
			cout<<(*it).first<<" "<<(*it).second<<endl;
		}
		*/
		
		for(int i=0;i<5;i++){
			string name="";
			int mx=0;
			map<string,int>::iterator it = MP.begin();
			for(;it!=MP.end();it++){
				if((*it).first[0]==c && (*it).second>mx){
					name=(*it).first;
					mx=(*it).second;
				}
			}
			if(mx){
				if(cnt)cout<<" ";
				cnt++;
				cout<<name;
				MP[name]=0;
			}
		}
		
		
		if(cnt==0){
			cout<<"NA";
		}
		cout<<endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 1228
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */



#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <limits>




#include <ostream>
#include <sstream>


using namespace std;
class B {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
    int h, w;
    string res;
    in >> h >> w;
    out << string(w + 2,  '#') << '\n';
    for(int i = 0; i < h; ++i){
      in >> res;
      res = '#' + res + '#';
      out << res << '\n';
    }
    out << string(w + 2,  '#') << endl;
	}
};


int main() {
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256