akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=101234;

ll n,a[3012],dp[3001][3001],dp2[3001][3001];
ll DP(ll l,ll r);


ll DP2(ll l,ll r)
{
    if(dp2[l][r])
        return dp2[l][r];
    if(l!=r)
        return dp2[l][r]=min(DP(l+1,r)-a[l],DP(l,r-1)-a[r]);
    else
        return dp2[l][r]=-a[l];
}

ll DP(ll l,ll r)
{
    if(dp[l][r])
        return dp[l][r];
    if(l!=r)
        return dp[l][r]=max(DP2(l+1,r)+a[l],DP2(l,r-1)+a[r]);
    else
        return dp[l][r]=a[l];
}

int main()
{
    scanf("%lld",&n);
    for(ll i=0; i<n; ++i)
    {
        scanf("%lld",&a[i]);
    }
    DP(0,n-1);
    printf("%lld",dp[0][n-1]);
    return 0;
}


Measured memory_bytes: 139904
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	string s; cin >> s;
	int m = stoi(s.substr(5, 2));
	if (m <= 4) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ll int
#define mod 100000007
#define ln printf("\n");
using namespace std;
inline void in(ll &x){x=0;char c;bool f=0;while((c=getchar())>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=getchar())<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}
inline void out(ll x){if(x<0){putchar('-');x=-x;}if(x>9)out(x/10);putchar(x%10+48);}
inline void outn(ll x){out(x);printf("\n");}
ll x;
int main(){
	in(x);outn(48-x);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

int main()
{
	INT n;

	cin >> n;

	vector<INT> a;
	INT total = 0;
	for (size_t i = 0; i < n; i++)
	{
		INT tmp;
		cin >> tmp;
		total += tmp;
		a.push_back(tmp);
	}
	
	for (size_t i = 0; i < n; i++)
	{
		if ((total - a[i]) <= a[i])
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s;
    cin >> s;

    for(int i = 0;i < s.size();i++){
        cout << 'x';
    }
    cout << endl;
    

    

}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int N = s.size();
  ll ret = 0;
  for( int i=0; i<(1<<(N-1)); i++ ){
    ll c = 0;
    for( int j=0; j<N; j++ ){
      c = c*10 + s[j] - '0';
      if( j == N-1 || (i & (1<<j)) != 0 ){
        ret += c;
        c = 0;
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
s = input()

A_list = []
Z_list = []

for i, char in enumerate(s, 1):
    if char == "A":
        A_list.append(i)

for i, char in enumerate(s, 1):
    if char == "Z":
        Z_list.append(i)

print(int(max(Z_list) - min(A_list) + 1))

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

#define ll long long
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
const int N = 2e5 + 5;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    ll l = 0;
    while(n != 0) {
        n /= 2;
        l++;
    }
    cout << (1LL << (l )) -1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
ll N=1e5+10;
using namespace std;



int main() {
	// your code goes here
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=t[i])
		{
			cout<<"No";
			return 0;
		}
		
	}
	cout<<"Yes";

	
	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;


int main(){
  int N, M; cin >> N >> M;
  vector<int> R(N, 0);
  for(int i = 0; i < M; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    R[a]++; R[b]++;
  }
  for(int i = 0; i < N; i++) cout << R[i] << endl;
}


Measured memory_bytes: 256
PROGRAM piyo
      IMPLICIT NONE
      integer,parameter :: prec = 4
      integer(prec) :: n,m
      integer(prec),allocatable :: h(:),a(:),b(:)
      integer(prec) :: i,k,ans
      logical,allocatable :: good(:)
      
      read*,n,m
      allocate( h(n), a(m),b(m) )
      allocate( good(n) )
      good = .true.
      read*,h(1:n)
      
      do i = 1,m
        read*,a(i),b(i)
      end do
      
      
      do i = 1,m
        
        if( h(a(i)) > h(b(i)) )then
          good(b(i)) = .false.
        else if( h(a(i))<h(b(i)) )then
          good(a(i)) = .false.
        else
          good(a(i)) = .false.
          good(b(i)) = .false.
        end if
      end do
      
      ans = count( good )
      print*,ans
      
      END PROGRAM

Measured memory_bytes: 4488
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;

int makeA(int a,int l);

int main(){
  while(1){
    vector<int> aArray;
    int a0,l;
    cin >> a0 >> l;
    if(a0==0&&l==0) break;
    aArray.push_back(a0);
    int i=0;
    while(1){
      int a = makeA(aArray[i],l);
      //cout << i+1 << " " << a << endl;
      vector< int >::iterator it = find(aArray.begin(),aArray.end(),a);
      int pos = (int)distance( aArray.begin(), it );
      if(it!=aArray.end()){
        cout << pos << " " << a << " " << (i+1)-pos << endl;
        break;
      }
      aArray.push_back(a);
      i++;
    }
  }
 
  return 0;
}

int makeA(int a,int l){
  vector<int> aParts;
  int temp = a;
  for(int i=0;i<l;i++){
    aParts.push_back(temp%10);
    temp /= 10;
  }
  sort(aParts.begin(),aParts.end());

  int aMax=0,aMin=0;
  for(int i=0;i<l;i++){
    int pow10 = (int)pow(10,i);
    aMax += aParts[i]*pow10;
    aMin += aParts[l-i-1]*pow10;
  }
  //cout << "aMax:" << aMax << " aMin:" << aMin << endl;

  return aMax - aMin;
}

Measured memory_bytes: 1264
#include<cstdio>

int main(){
  int fib[45],n;
  fib[0] = 1;
  fib[1] = 1;
  for(int i=2;i<45;i++){
    fib[i] = fib[i-1] + fib[i-2];
  }
  scanf("%d",&n);
  printf("%d\n",fib[n]);
  return 0;
}

Measured memory_bytes: 1028
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	map<string, int> s;
	char tmp[11];
	long long count = 0;
	for (int i = 0; i < N; i++) {
		scanf("%10s", tmp);
		sort(tmp, tmp + 10);
		string str(tmp);
		if (s.find(str) == s.end()) {
			s.emplace(str, 1);
		}
		else {
			count += s.at(str);
			s.at(str) += 1;
		}
	}
	printf("%lld\n", count);
}
	

Measured memory_bytes: 8064
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)

Measured memory_bytes: 14432
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E5 + 10;

void Input()
{

}

void Solve()
{
    int x, y, z;
    cin >> x >> y >> z;
    if (x + y + z >= 22) cout << "bust";
    else cout << "win";
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}



Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs;
    int t,ans=0;
    cin>>t;
    repp(i,1,t){
        repp(j,1,t){
            repp(k,1,t) ans+=__gcd(i,__gcd(j,k));
        }
    }
    cout<<ans;
}


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

int main () {
    string w;
    cin >> w;
    if (w == "Rainy") {
        cout << "Sunny";
    } else if (w == "Cloudy") {
        cout << "Rainy";
    } else {
        cout << "Cloudy";
    }
    cout << endl;
}

Measured memory_bytes: 256
import Data.Char
import Data.List
import System.IO
import Control.Applicative
import Control.Monad
-- https://hoogle.haskell.org で関数検索

{- お客様の中でHaskellを書ける方はいらっしゃいますか？
    と、Haskellの例がなくて困っていたところを @tanakh さんに助けて頂きました。本当にありがとうございました。-}
main :: IO ()
main = do
    [n,r] <- getIntegerList 
    print $ r + 100* (max (10-n) 0)

    
 
 
 
 
 
 
same3 [a,b,c]
    | a==b && b==c = True
    | otherwise         = False       
       
diff3 [a,b,c] 
    | a==b = False
    | b==c = False
    | c==a = False
    | otherwise = True

yesno cond x 
    | cond x      = putStrLn "Yes"
    | otherwise = putStrLn "No"
    
    
    
{-

main = readLn >>= print . ceiling . (/2) 


(+) 3 $ (*) 4 4
-> 19
pure (+) <*> (Just 1) <*> ( Just 3)
-> Just 4

main = do 
    [a,b] <- getIntegerList 
    print $ (a*(a-1)+b*(b-1)) `div` 2
    -- / じゃなくて'div' ！！！！！

main = do
    s <- getLine    
    samecoffee s

samecoffee [x,y,a,b,c,d] 
    | a==b && c==d = do putStrLn "Yes"
    | otherwise         = do putStrLn "No"
samecoffee s = do putStrLn ""
         
putStrLn $ (show c) ++ " " ++ (show a) ++ " " ++ (show b)


main :: IO ()
main = do
    -- 整数の入力
    a <- readLn
    -- スペース区切り整数の入力
    [b, c] <- getIntegerList

    --[b, c] <- map read . words <$> getLine
    -- 文字列の入力
    s <- getLine
    -- 出力
    putStrLn $ show (a + b + c) ++ " " ++ s
-}

-- レイアウト規則

fac 0 = 1
fac n = n * fac (n-1)

-- FileName   : 164a
-- CreatedDate: 2020-04-26 20:56:13

--------------------------------------------  https://atcoder.jp/contests/abc164/submissions/12342628

getIntList        = map (read :: String -> Int) . words <$> getLine
getIntegerList    = map (read :: String -> Integer) . words <$> getLine
getIntegerListN m = map (read :: String -> Integer) <$> replicateM m getLine


base :: Integer
base = 1000000007

plus :: Integer -> Integer -> Integer
plus a b = (a+b) `mod` base

times :: Integer -> Integer -> Integer
times a b = a * b `mod` base

minus :: Integer -> Integer -> Integer
minus a b
   | a < b     = a-b + base
   | otherwise = a-b

power :: Integer -> Integer -> Integer
power n k
   | k == 0         = 1
   | k `mod` 2 == 0 = power (times n n) (k`div`2)
   | otherwise      = times n $! power n (k-1)

inv :: Integer -> Integer
inv n = power n $ base - 2

binom :: Integer -> Integer -> Integer
binom n m
   | (n-m) < m = times (foldr times 1 [m+1..n]) $ inv $ foldr times 1 [1..n-m]
   | otherwise = times (foldr times 1 [n-m+1..n]) $ inv $ foldr times 1 [1..m]



















Measured memory_bytes: 508
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int h, a, c = 0;
  cin >> h >> a;
  while (h > 0) {
    h -= a;
    c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> d(m);//cost(a), num(i)
	rep(i, m){
		int a, b;
		cin >> a >> b;
		int c = 0;
		rep(j, b){
			int in;
			cin >> in;
			in--;
			c += 1 << in;
		}
		d.at(i) = make_pair(a, c);
	}

	vector<int> dp(1 << n, INF);
	dp.at(0) = 0;
	rep(i, 1 << n){
		rep(j, m){
			int a, c;
			tie(a, c) = d.at(j);
			int nx = i | c;
			dp.at(nx) = min(dp.at(nx), dp.at(i) + a);
		}
	}
	if(dp.at((1 << n) - 1) == INF) dp.at((1 << n) - 1) = -1;
	cout << dp.at((1 << n) - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
d = [[0, -1],
     [0, 1],
     [-1, 0],
     [1, 0]]

INF = 1000000

tile = {"0":0,
        "1":1,
        " ":2}

def idx(i):
    return 2*i

output = []
while True:
    w, h = input().split()
    w = int(w)
    h = int(h)

    if w == 0:
        break

    maze = [[2 for i in range(2*w-1)] for j in range(2*h-1)]
    l = [[INF for i in range(w)] for j in range(h)]
    for j in range(2*h-1):
        row = input()
        for i in range(len(row)):
            maze[j][i] = tile[row[i]]
    
    queue = [(0, 0, 1)]
    while queue:
        x, y, count = queue.pop(0)

        for ud, rl in d:
            xxt = idx(x)+ud
            yyt = idx(y)+rl
            if xxt>=0 and xxt<w*2-1 and yyt>=0 and yyt<h*2-1:
                if maze[yyt][xxt] == 0:
                    xt = x+ud
                    yt = y+rl
                    if l[yt][xt] > count+1:
                        l[yt][xt] = count+1
                        queue.append((xt, yt, count+1))

    if l[h-1][w-1] == INF:
        output.append(0)
    else:
        output.append(l[h-1][w-1])

for i in output:
    print(i)

Measured memory_bytes: 7752
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, k;
bool d[10];

int solve(){
    for(int i = n; i < 1000000; ++i){
        string s = to_string(i);
        bool ok = 1;
        for(int j = 0; j < sz(s); ++j){
            if(d[s[j] - '0']){
                ok = 0;
                break;
            }
        }
        if(ok) return i;
    }
    return n;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0, x; i < k; ++i){
        cin >> x;
        d[x] = 1;
    }
    
    cout << solve() << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    int N;
    cin>>N;
    ll sum=0;
    FOR(i,1,N+1){
        if(i%3==0||i%5==0){
            sum+=0;
        }else if(i%3==0){
            sum+=0;
        }else if(i%5==0){
            sum+=0;
        }else{
            sum+=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(max(a,x)-min(a,x)>max(x,b)-min(b,x))ou('B');
  else ou('A');
}

Measured memory_bytes: 256
X,N=map(int,input().split())
p=list(map(int,input().split()))

ans=1000
flg=False
if X not in p:
    print(X)
    flg = True
else:
    for i in range(0,102):
        if i not in p and abs(X-i)<abs(X-ans) and i!=X:
            ans=i
        
if flg==False:
    print(ans)


Measured memory_bytes: 9180
//Littleboy123 Template 1.7
#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;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")t
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(int (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(int (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("walk.in", "r", stdin);
}

void outfile(){
    freopen("output.txt", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2LL, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1LL)
        tmp = (tmp * a) % mod;
    return tmp;
}

ll ex(ll a, ll b){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = ex(a, b/2LL);
    tmp = (tmp * tmp);
    if(b & 1LL)
        tmp = (tmp * a);
    return tmp;
}

//End of template

map<ll, int> pos;
ll cycle[100005];

int main(){
    init();

    ll n, x, m;
    cin >> n >> x >> m;
    cycle[1] = x;
    pos[x] = 1;
    ll sum = x;
    ll tmp;
    ll s, e;
    int flag = 0;
    FOR(i, 1, n){
        tmp = modex(cycle[i], 2, m);
        if(pos[tmp] != 0){
            flag = 1;
            s = pos[tmp];
            e = i;
            break;
        }
        cycle[i+1] = tmp;
        pos[tmp] = i+1;
        sum += tmp;
    }
    if(!flag){
        cout << sum << endl;
        return 0;
    }
    ll cycsum = 0;
    FORE(i, s, e){
        cycsum += cycle[i];
    }
    n -= e;
    ll div = n/(e-s+1LL);
    sum += div * cycsum;
    n %= (e-s+1);
    FOR(i, 0, n){
        sum += cycle[s+i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 7144
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

constexpr int MOD = 1000000007;

int mod(ll x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(ll x,ll m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n, m, k;
    cin >> n >> m >> k;
    ll dn = 0;
    FOR(i,1,n) dn = mod(dn + modm(i,n-i));
    ll dm = 0;
    FOR(i,1,m) dm = mod(dm + modm(i,m-i));
    int c = 1;
    for(int nm = n*m-2,d = 1; d <= k-2; nm--,d++) {
        c = modd(modm(c,nm), d);
    }

    int ans = mod(modm(dn,modm(m,m)) + modm(dm,modm(n,n)) );
    ans = modm(ans,c);

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,k;
ll memo[100100],h[100100];
bool done[100100];

ll solve(int i){
	int j;
	if(done[i]){
		return memo[i];
	}
	done[i] = true;
	if(i==n-1){
		memo[i] = 0ll;
		return memo[i];
	}
	memo[i] = INFLL;
	for(j=1; j<=k; ++j){
		if(i+j>=n){
			continue;
		}
		memo[i] = min(memo[i],solve(i+j)+abs(h[i]-h[i+j]));
	}
	return memo[i];
}

int main(void){
	int i;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	cout << solve(0) << endl;
	return 0;
}


Measured memory_bytes: 6528
/*-- ILSH  --*/

// Multipoll evaluation + Divide and Conquer
// Time ( Iterative ) < Time ( Recursive )

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;

#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll > 
#define len length 
#define fi first
#define se second
#define dt cout<<"HEre\n";
#define sz(x) (ll)x.size()
const ll inf=1e18+1e17;
const ll mod = 1e9+7;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}


void solve(){
	string s;
	cin>>s;
	ll n=s.len();
	for ( int i=0;i<n-1;i++){
		if ( s[i]==s[i+1]){
			cout<<i+1<<' '<<i+2<<'\n';
			return;
		}
	}
	for ( int i=0;i<n-2;i++){
		if ( s[i]==s[i+2]){
			cout<<i+1<<' '<<i+3<<'\n';
			return;
		}
	}
	cout<<-1<<' '<<-1<<'\n';
	return;



}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
    //	cout << clock() / double(CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 // ここにプログラムを追記
 //入力は以下の形式で標準入力から与えられる。
 int m; cin >> m;
 //12 月 30 日の M 時から次の年になるまでが x 時間のとき、x を出力せよ。
 
 //12月って31日までなので、　31日までになるまでの時間から24時間を足せばｘになる
 //x =24+(24-M)=48-M
 cout << 48-m <<endl;
}

Measured memory_bytes: 256
H,W = [int(x) for x in input().split()]
S = ['.'*(W+2)]+['.'+input()+'.' for _ in range(H)]+['.'*(W+2)]
ans = []
for i in range(1,H+1):
    s = ''
    for j in range(1,W+1):
        cnt = 0
        li = [[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]]
        for x in li:
            if(S[i+x[0]][j+x[1]]=='#'):
                cnt += 1
        if(S[i][j]=='#'):
            s+='#'
        else:
            s+=str(cnt)

    ans.append(s)
for i in ans:
    print(i)


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

int main() {
    int H, W;
    cin >> H >> W;

    string A[H];
    for (int i = 0; i < H; i++) {
        cin >> A[i];
    }

    int row[H] = {false};
    int col[W] = {false};
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        if (row[i]) {
            for (int j = 0; j < W; j++) {
                if (col[j]) {
                    cout << A[i][j];
                }
            }
            cout << endl;
        }
    }
    cout << endl;
    return 0;    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		map<char, char>convert;
		for (int i = 0; i < N; ++i) {
			char a, b; cin >> a >> b;
			convert[a] = b;
		}
		int M; cin >> M;
		while (M--) {
			char c; cin >> c;
			if (convert.find(c) == convert.end())cout << c;
			else cout << convert[c];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3088
A, B, C, K = list(map(int, input().split()))

ans = 0

while True:
    if (K <= A):
        ans += K * 1
        break
    elif (K > A):
        K -= A
        ans += A * 1
    
    if (K <= B):
        break
    elif (K > B):
        K -= B

    if (K <= C):
        ans -= K * 1
        break
    else:
        ans -= C * 1

    break

print(ans)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
    using namespace std;
    #define ff first
    #define ss second
    typedef long long ll;

    int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    puts("Left");
  }
  else if(a+b<c+d){
    puts("Right");
  }
  else {
    puts("Balanced");
  }
    }


Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int
#define F first
#define S second
#define f(i,x,n) for(ll i=x;i<n;i++)
using namespace std;
const int mod=100001;
ll dp[mod][3];
void solve(int a[][3], int n){
	f(i,0,mod) f(j,0,3) dp[i][j]=0;
	f(i,1,n+1){
		f(j,0,3)
	f(k,0,3){
		if(k!=j){
			if( (a[i-1][j]+ dp[i-1][k]) > dp[i][j] ){
				dp[i][j] = (a[i-1][j]+ dp[i-1][k]);
			}
		}	
}
}
}
int main(){
	int n; cin>>n;
	int a[n][3];
	f(i,0,n){
		f(j,0,3) cin>>a[i][j];
	}
	solve(a, n);
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
	
	return 0;
	}

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

int INDEX(long int x){
    int index=1;
    while(x>=10){
        x/=10;
        ++index;
    }
    return index;
}

int MAX(int a,int b){
    if(a<b) return b;
    else return a;
}

int main()
{
    long int n;
    cin >> n;
    int min;
    for(int a=1;a<=sqrt(n);++a){
        if(n%a==0){
            long b = n/a;
            int ax = INDEX(a);
            int bx = INDEX(b);
            if(a==1) min = MAX(ax,bx);
            if(min>MAX(ax,bx)) min = MAX(ax,bx);
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
var l = require('fs').readFileSync('/dev/stdin','utf8').trim().split(' ').map(a=>Number(a));
var c = 0;
for (var i = 0; i < 2; i++) {
  if (l[0] > l[1]) {
    c += l[0];
    l[0]--;
  } else {
    c += l[1];
    l[1]--;
  }
}
console.log(c);


Measured memory_bytes: 7500
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int inf=pow(2,31)-1;
int size=1;
vector<int> tree;

void init(int n){
  while(size<n){
    size*=2;
  }
  tree.assign(size*2,0);
}

/*void update(int m,int x){
  tree[m+=size]=x;
  while(m/=2){
    tree[m]=min(tree[m*2],tree[m*2+1]);
  }
}

int find(int l,int r){
  l+=size,r+=size;
  int al=inf,ar=inf;
  for(;l<r;l/=2,r/=2){
    if(l%2==1)al=min(tree[l++],al);
    if(r%2==1)ar=min(tree[--r],ar);
  }
  return min(al,ar);
  }*/

void add(int i,int x){
  tree[i+=size]+=x;
  while(i/=2){
    tree[i]=tree[i*2]+tree[i*2+1];
  }
}

int getSum(int l,int r){
  l+=size,r+=size;
  int sl=0,sr=0;
  for(;l<r;l/=2,r/=2){
    if(l%2==1)sl+=tree[l++];
    if(r%2==1)sr+=tree[--r];
  }
  return sl+sr;
}

signed main(){
  int n,q;
  cin>>n>>q;
  init(n);
  rep(i,q){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      x--;
      cout<<getSum(x,y)<<endl;
    }else{
      x--;
      add(x,y);
    }
  }
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
string S,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>S>>T;
	
	ll g=__gcd(N,M);
	ll L=N/g*M;
	ll a=L/N;
	ll b=L/M;
	
	int ok=1;
	FOR(i,N) if(i*a%b==0 && S[i]!=T[i*a/b]) ok=0;
	if(ok==1) {
		cout<<L<<endl;
	}
	else {
		cout<<-1<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,j,a,b;
	cin >> n >> k;
		a=n%k;
		if(a!=0)
		{
			a=min(a,k-a);
		}
		cout << a << "\n";
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a + b == 15) cout << '+' << endl;
  else if (a * b == 15) cout << '*' << endl;
  else cout << 'x' << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	sort(ALL(a));
	ll l = 0, r = 0;
	ll ans = 0;
	REP(i,n / 2) {
		if(i % 2 == 0) {
			if(i == 0) {
				l = a[0 + i];
				r = a[n - 1 - i];
				ans += abs(r - l);
			} else {
				ans += abs(a[0 + i] - l);
				ans += abs(a[n - 1 - i] - r);
				l = a[0 + i];
				r = a[n - 1 - i];
			}
		} else {
			ans += abs(a[0 + i] - r);
			ans += abs(a[n - 1 - i] - l);
			r = a[0 + i];
			l = a[n - 1 - i];
		}
	}
	if(n % 2) {
		ans += max(abs(a[n / 2] - l), abs(a[n / 2] - r));
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n, m = 200000, c = 0;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  rep(i, n){
    if(m >= v[i]) ++c;
    m = min(m, v[i]);
  }
  cout << c << endl;
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


def judg(s):
    if s[0] != "A":
        return False
    if "C" not in s[2:-1] and s[2:-1].count("C") != 1:
        return False
    del s[s.index("C")]
    s = "".join(s[1:])
    if s.lower() != s:
        return False
    return True


def main():
    s = list(input().strip())

    if judg(s):
        print("AC")
    else:
        print("WA")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import itertools

aList = []

for i in range(5):
  aList.append(int(input()))

k = int(input())

aiList = list(itertools.combinations(aList,2))

for j in aiList:
  if j[1] - j[0] >k:  
    print(":(")
    exit(0)

print("Yay!")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    ll x,k,d;

    Int(x,k,d);

    x=abs(x);
    ll need = x/d;

    ll ans=0;
    if(k <= need){
        ans = x - k*d;
    }
    else{
        ll extra = k-need;

        if(extra%2 ==0) ans = x - need*d;
        else{
            ans = abs(x- (need+1)*d);
        }
    }
    printf("%lld\n", ans);

   
    return 0;
}






Measured memory_bytes: 3744
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

signed main() {
	string s; cin >> s;
	if (s == "a" || s == "i" || s == "u" || s == "e" || s == "o") {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    cin>>T;
    map<string,int> mp;
    while(T --> 0)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"]<<'\n';
    cout << "WA x " << mp["WA"]<<'\n';
    cout << "TLE x " << mp["TLE"]<<'\n';
    cout << "RE x " << mp["RE"];
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string a[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    rep(i, 0, 7){
        if(s == a[i]){
            cout << 7 - i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
max = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        ans += 1
    else:
        if max < ans:
            max = ans
        ans = 0
if max < ans:
    max = ans
print(max)

Measured memory_bytes: 15020
#include <stdio.h>

int main(){
    int j, m, s, e, sa, sb;
    scanf("%d %d %d %d", &j, &m, &s, &e);
    sa = j+m+s+e;
    scanf("%d %d %d %d", &j, &m, &s, &e);
    sb = j+m+s+e;
    if(sa >= sb)
        printf("%d\n", sa);
    else
        printf("%d\n", sb);
    return 0;
}

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

#define int long long

signed main(){
    int n;
    map<int, int> mp;

    priority_queue<int> que;
    cin >> n;

    int a;
    for(int i = 0;i < n;i++){
        cin >> a;
        que.push(a);
        mp[a]++;
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        int num = que.top();
        que.pop();
        if(mp[num] > 0){
            mp[num]--;
            int tmp = 1;
            while(tmp <= num) tmp*=2;
            if(mp[tmp-num] > 0){
                ans++;
                mp[tmp-num]--;
            }else{
                mp[num]++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 26736
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a;
	cin>>a;
	cout<<"Christmas";
	if(a==25) return 0;
	for(int i=25;i>a;i--)
	{
		cout<<" Eve";
	}
	
	
return 0;
}


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

int V[100010];
int N;
vector<int> mem(100010,-1);
int dp(int i){
    if(i>N-1){
        return 1e9+1;
    }
    if(i==N-1){
        return 0;
    }
    if(mem[i]!=-1){
        return mem[i];
    }
    return mem[i]=min(abs(V[i]-V[i+1])+dp(i+1),abs(V[i]-V[i+2])+dp(i+2));
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    int ans=dp(0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
# https://atcoder.jp/contests/abc061/tasks/abc061_c



N, K = gets.split.map(&:to_i)

hash = Hash.new(0)
N.times do |i|
  a, b = gets.split.map(&:to_i)
  hash[a] += b
end

count = 0
hash.sort.each do |a, b|
  count += b
  if count >= K
    puts a
    exit
  end
end


Measured memory_bytes: 9992
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;

    int ma = max({a, b, c});
    int sum = a + b + c;

    cout << (((ma * 3 - sum) % 2 == 0) ? (ma * 3 - sum) / 2 : ((ma + 1) * 3 - sum) / 2) << '\n';
    return (0);
}


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

int main() {
	int a, b, c;
	char s[11];
	scanf("%s", s);
	sscanf(s, "%d/%d/%d", &a, &b, &c);
	if (a==2017&&b==1){
		printf("2018/01/");
		if (c < 10) printf("0%d\n", c);
		else printf("%d\n", c);
	} else printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	vector<pair<int, int>>v(M);
	vector<vector<int>>num(N + 1, vector<int>(N + 1));
	for (int i = 0; i < M; i++) {
		cin >> v[i].first >> v[i].second;
		num[v[i].first][v[i].second]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			num[i][j] += num[i][j - 1];
		}
	}
	for (int i = 0; i < K; i++) {
		cin >> L >> R;
		int ans = 0;
		for (int j = L; j <= R; j++) {
			ans += num[j][R] - num[j][j - 1];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3456
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

ll gcd(ll A, ll B){
  ll M = max(A, B), m = min(A, B);
  while (M % m != 0){
    ll c = M % m;
    M = m; m = c;
  }
  return m;
}

int main(){
  ll A, B; cin >> A >> B;
  cout << A / gcd(A, B) * B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;

pii iden(131, 133), dp[16];

pii mul(pii a, pii b) { return pii(a.x * b.x, a.y * b.y); }
pii add(pii a, pii b) { return pii(a.x + b.x, a.y + b.y); }
pii sub(pii a, pii b) { return pii(a.x - b.x, a.y - b.y); }

int main() {
    dp[0] = pii(1, 1);
    for(int i = 1; i < 18; ++i) dp[i] = mul(dp[i-1], iden);
    int n; scanf("%d", &n);
    char A[40]; scanf("%s", A);
    map<pii, int> M;
    for(int i = 0; i < (1 << n); ++i) {
        int p1 = n, p2 = 0;
        pii r1, r2;
        for(int j = 0; j < n; ++j) 
            if(i >> j & 1) r1 = add(r1, mul(pii(A[j], A[j]), dp[--p1]));  
            else r2 = add(r2, mul(pii(A[j], A[j]), dp[p2++]));  
        M[sub(r1, r2)]++;
    } 
    for(int i = 0; i < n; ++i) A[i] = A[i + n];
    long long sum = 0;
    for(int i = 0; i < (1 << n); ++i) {
        int p1 = 0, p2 = n;
        pii r1, r2;
        for(int j = n-1; ~j; --j) 
            if(i >> j & 1) r1 = add(r1, mul(pii(A[j], A[j]), dp[p1++]));  
            else r2 = add(r2, mul(pii(A[j], A[j]), dp[--p2]));  
        sum += M[sub(r2, r1)];
    }
    printf("%lld\n", sum);
}


Measured memory_bytes: 33024
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<string>
using namespace std;
int main (void)
{
 int a,b,c,d;
cin>>a>>b>>c>>d;
 int e=max(a,c);
 int f=min(b,d);
if(f-e<0)
{
cout<<"0"<<endl;
}
else{

cout<<f-e<<endl;
}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	vector<bool> allowed(26, true);
	string s;
	cin >> s;
	trav(c, s) allowed[c - 'a'] = false;
	if(sz(s) < 26){
		rep(j,0,26){
			if(allowed[j]){
				s.push_back('a'+j);
				cout << s << endl;
				return 0;
			}
		}
	}
		
	rrep(i,0,sz(s)){
		int c = s[i] - 'a';
		rep(j,c,26) if(allowed[j]){
			s[i] = j + 'a';
			cout << s.substr(0,i+1) << endl;
			return 0;
		}
		allowed[c] = true;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 50009
vector<ll>seq;
ll l,r,ten=10,last=1000000000000;
map<ll,ll>cnt;
map<ll,ll>sub;
ll arra[100009];
ll aps[1009][1009];
string str1[1009];
ll vis[109][109];
ll dp[209][209][209];
ll once[209];
ll forever[209];
vector<ll>anse;
int main()
{
  ios::sync_with_stdio(false);
  ll i,j,m,p=10000000000000,x,q,z,sum=0,n,k,y;
  string str;
  cin>>str;
   x=str.size();
   if(str[x-1]=='s')
    cout<<str<<"es"<<'\n';
   else
   cout<<str<<"s"<<'\n'; 
 
  
    
    
   	
 }
  
  
   




Measured memory_bytes: 3656
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

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

  val s = in.next()
  val t = in.next()

  val sl = s.length
  val tl = t.length

  //
  val indices = Array.fill[List[Int]](26)(Nil)
  for (i <- 0 until sl) {
    val ind = s(i).toInt - 97
    indices(ind) = i :: indices(ind)
  }

  val hoge: Array[(Array[Int], Int)] = // (indices, length)
    indices.map{ indice =>
      (indice.reverse.toArray, indice.length)
    }


  def check(i: Int, nowi: Int, cnum: Int): Boolean = {
    hoge(cnum)._1(i) > nowi
  }

  // 条件を満たす最小の値を返す
  def binarySearch(min: Int, max: Int, nowi: Int, cnum: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(min, nowi, cnum) match{
          case true  => min
          case false => max
        }
      case _ =>
        (check(mid, nowi, cnum)) match{
          case true  => binarySearch(min, mid, nowi, cnum)
          case false => binarySearch(mid, max, nowi, cnum)
        }
    }
  }


  var ans = 0L
  var nowi = -1
  breakable {
    for (c <- t) {
      val cnum = c.toInt-97
      val (indice, len) = hoge(cnum)
      if (len == 0) {
        ans = -1
        break
      }
      else {
        if (nowi >= indice(len-1)) {
          ans += sl
          nowi = indice(0)
        }
        else {
          val ind = binarySearch(0, len-1, nowi, cnum)
          nowi = indice(ind)
        }
      }
    }

    ans += nowi + 1
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

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


Measured memory_bytes: 43656
function Main(input){
  input = input.split('\n').map(num => Number(num));
  var n = input[0];
  var k = input[1];
  var x = input[2];
  var y = input[3];

    var price = 0;

  if(n - k < 0) {
    price = n * x;
  } else {
    price = k * x + (n - k) * y;
  }

  console.log(price);


}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20296