akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long MAXIMUM=1000000000001;
long long N,total=0;
int main(){
	cin>>N;
	vector<long long> factorization;
    for(long long i=2; i*i<=MAXIMUM; i++){
    	if(N%i==0){
    		long long first=0;
    		while(N%i==0){
    			if(first==0){
    				factorization.push_back(1);
    				first++;
    			}else{
    				factorization[factorization.size()-1]++;
    			}
    			N/=i;
    		}
    		long long l=1,r=8,catat;
    		while(l<=r){
    			long long mid=(l+r)/2;
    			long long tmp=(mid)*(mid+1)/2;
    			if(factorization.back()>=tmp){
    				catat=mid;
    				l=mid+1;
    			}else{
    				r=mid-1;
    			}
    		}
    		total+=catat;
    	}
    }
    if(N>1){
    	total++;
    }
    cout<<total<<'\n';
}

Measured memory_bytes: 3632
from collections import deque


N, M = map(int, input().split())
to = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    to[a].append(b)
    to[b].append(a)
    

def main():
    dist = [-1] * N
    dist[0] = 0
    que = deque([0])
    ans = [0] * (N - 1)
    
    while que:
        v = que.popleft()
        for nv in to[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                ans[nv - 1] = v + 1
                que.append(nv)
                
    print('Yes')
    print(*ans, sep='\n')
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 99792
def main():
    N = int(input())
    A = list(map(int, input().split()))
    limit = 10 ** 18

    if 0 in A:
        print(0)
        exit()
    ans = 1
    for a in A:
        ans *= a
        if ans > limit:
            print(-1)
            exit()

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21472
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int D,G;
  cin>>D>>G;
  vector<int> p(D),c(D);
  for (int i = 0; i < D; i++)
  {
    cin>>p[i]>>c[i];
  }
  int ANS = INF;
  for (int mask = 0; mask < (1<<D); mask++)
  {
    int s = 0,num = 0,rest_max = -1;
    for (int i = 0; i < D; i++)
    {
      if(mask >> i &1)
      {
        s += 100*(i+1)*p[i]+c[i];
              num += p[i];
      }
    else
    {
      rest_max = i;
    }
    }
    if(s <G){
      int s1 = 100*(rest_max +1);
      int need = (G -s +s1 -1)/s1;
      if(need >= p[rest_max])
      {
        continue;
      }
      num += need;
    }
    ANS = min(ANS,num);
    
  }
  cout<<ANS<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

int N;
vector<int64_t> V;  ///< Distance of a vertex i.
vector<vector<pair<int, int>>> E;  ///< Adjacency list with distance.

void dfs(int v, int64_t d) {  // vertex, distance
  V[v] = d;
  for (const auto& x : E[v]) {
    int v_next = x.first;
    int d_next = x.second;
    if (V[v_next] != -1) continue;  // already visited.
    dfs(v_next, d + d_next);
  }
}

int main() {
  cin >> N;
  V.push_back(-1);  // dummy for one-based.
  E.push_back(vector<pair<int, int>>());  // dummy for one-based.
  for (int i = 1; i <= N; ++i) {
    V.push_back(-1);
    E.push_back(vector<pair<int, int>>());
  }
  for (int i = 1; i <= N - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    // Connects vertice a and b with distance c.
    E[a].push_back(pair<int, int>(b, c));
    E[b].push_back(pair<int, int>(a, c));
  }
  int Q, K;
  cin >> Q >> K;
  dfs(K, 0);
  for (int i = 1; i <= Q; ++i) {
    int x, y;
    cin >> x >> y;
    cout << V[x] + V[y] << endl;
  }
}


Measured memory_bytes: 11816
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    if (N == 1) {
      System.out.println("Hello World");
    } else {
      System.out.println(scanner.nextInt() + scanner.nextInt());
    }
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> A(3,vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++)cin >> A.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> B(N);
  for(int i = 0; i < N; i++){
    cin >> B.at(i);
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(A.at(j).at(k) == B.at(i)) A.at(j).at(k) = 0;
      }
    }
  }
  bool ans = false;
  vector<int> zero = {0,0,0};
  for(int i = 0; i < 3; i++){
    if(A.at(i) == zero)ans = true;
    else{
      int count = 0;
      for(int j = 0; j < 3; j++){
        if(A.at(j).at(i) == 0)count++;
      }
      if(count == 3)ans = true;
    }
  }
  int counter = 0;
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(A.at(i).at(i) == 0)counter++;
    if(A.at(i).at(2-i) == 0)count++;
  }
  if(counter == 3 || count == 3)ans = true;
  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

Measured memory_bytes: 3528
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	int x;
	if ((a + b) % 2 == 0) {
		x = (a + b) / 2;
	}
	else {
		x = (a + b) / 2 + 1;
	}
	cout << x;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;

void ans(bool qus){
    if (qus == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Ans(bool qust){
    if (qust == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

////////////////---START---////////////////

void solve(int a, int b, int c, int d){
    cout << min(a, b) + min(c, d) << endl;
}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    solve(a, b, c, d);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int aa, bb, tmp = 1, ans = 0;
  scanf("%d %d", &aa, &bb);
  while(tmp < bb)
  {
    tmp += aa - 1;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1700
n = int(input())
A = list(map(int, input().split()))
M = max(A)
m = min(A)

if M-m >= 2:
    print('No')
elif M-m == 0:
    # alone
    if M == n-1:
        print('Yes')
    elif M*2 <= n:
        print('Yes')
    else:
        print('No')
else:
    c = M
    x = 0
    for a in A:
        if a == m:
            x += 1
    if x < c and (c-x)*2 <= (n-x):
        print('Yes')
    else:
        print('No')


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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int score = 0;
  rep(i,n-1) {
    if (s[i] == s[i+1]) score++;
  }
  int ans = min(score+2*k, n-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import itertools

N = input()
N1 = int(N)
N2 = len(N)

num753_comb = []
for i in range(N2):
  num753_comb.append([0,3,5,7])
All_comb = list(itertools.product(*num753_comb))

count = 0
for i in range(len(All_comb)):
 tmp = list(All_comb[i])
 tmp_num = 0
 judge0,judge3,judge5,judge7 = 0,0,0,0

 for j in range(N2):
   tmp_num += tmp[j]*(10**(N2-1-j))   
   if((tmp_num > 0)and(tmp[j] == 0)): judge0 += 1
   elif(tmp[j] == 3): judge3 += 1
   elif(tmp[j] == 5): judge5 += 1
   elif(tmp[j] == 7): judge7 += 1
   
 if(tmp_num <= N1):
   if((judge3>=1)and(judge5>=1)and(judge7>=1)and(judge0 == 0)):
      count += 1     
print(count)
    

Measured memory_bytes: 36980
/*input
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
*/
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define mpr make_pair
#define MX 1000000007
#define ui unsigned int
#define ll long long
#define ld long double
#define fi first
#define se second
#define testcases int testcases;cin>>testcases;while(testcases--)
#define printvector(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";  cout<<endl
#define printarray(v,n)  for(int i=0;i<n;i++) cout<<v[i]<<" ";  cout<<endl
#define inputarray(v,n)  for(int i=0;i<n;i++)cin>>v[i]
#define debug(i) cout<<"debug: "<<i<<endl
#define pr(i) cout<<i<<endl
#define timetaken cerr<<clock()/double(CLOCKS_PER_SEC)<<endl
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define toDigit(a) (a-'0')
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll cal(int h, int w, vector<string> &a){
    vector<vector<ll>>dp(h,vector<ll>(w,0));

    for(int i=0;i<h;++i){
        if(a[i][0] == '#')break;
        else dp[i][0] = 1;
    }

    for(int i=0;i<w;++i){
        if(a[0][i] == '#')break;
        else dp[0][i] = 1;
    }

    for(int i=1;i<h;++i){
        for(int j=1;j<w;++j){
            if(a[i][j] != '#')
                dp[i][j] = (dp[i-1][j]%MX + dp[i][j-1]%MX)%MX;
        }
    }
    
    // for(int i=0;i<h;++i){
    //     for(int j=0;j<w;++j){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }

    return (dp[h-1][w-1])%MX;
}

int main() {
    fast_io;
    int h,w;
    cin>>h>>w;
    vector<string>a(h);
    for(int i=0;i<h;++i){
        cin>>a[i];
    }
    pr(cal(h,w,a));
    return 0;
}

Measured memory_bytes: 9216
N=int(input())
mylist=list(map(int, input().split()))
answer=0

for i in range(N):
    if mylist[i]%2==0:
        if mylist[i]%3==0 or mylist[i]%5==0:
            temp=0
        else:
            answer+=1
            #print(i)
    else:
        temp=0
        
if answer==0:
    print("APPROVED")
else:
    print("DENIED")
        

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vll;
const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll A,V,B,W;cin>>A>>V>>B>>W;
    ll T; cin>>T;
    if(A<B) swap(A,B);
    ll kyori = A-B;
    ll chi = V-W;
    if(chi == 0 && kyori != 0){
        cout<<"NO" << endl;
        return 0;
    }
    cout << (kyori > T*chi ? "NO" : "YES") <<endl;

}

Measured memory_bytes: 3652
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long[][] dp = new long[2001][2001];
    long mod = 1000000007;
    for(int i=1;i<=2000;i++){
      dp[i][0]=1;
      dp[i][1]=i;
    }
    for(int i=2;i<=2000;i++){
      for(int j=1;j<=i;j++){
        dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
      }
    }
    if(k==1)System.out.println(n);
    else
    for(int i=1;i<=k;i++){
      long ans = (dp[n-k+1][i]*dp[k-1][i-1])%mod;
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 80464
#include <iostream>

using namespace std;

int f(int x){return x*x;}
int integral(int d){
  int sum=0;
  for(int i=1;i<600/d;i++){
    sum+=f(i*d)*d;
  }
  return sum;
}
int main(){
  int d;
  while(cin>>d){
    cout<<integral(d)<<endl;
  }
}

Measured memory_bytes: 1160
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))

    b = [0 for _ in range(n)]

    for c in a:
        b[c-1] += 1

    for d in b:
        print(d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32372
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
int main() {
    ll N,M;
    cin >> N >> M;
    priority_queue<pair<ll,ll>> Q;
    rep(i,N){
        ll a;
        cin >> a;
        Q.push(mk(a, 1LL));
    }
    rep(i,M){
        ll B,C;
        cin >> B >> C;
        Q.push(mk(C,B));
    }
    ll cnt = 0;
    ll ans = 0;
    while(!Q.empty()) {
        pair<ll, ll> q = Q.top();Q.pop();
        if(q.second+cnt > N){
            ans += q.first * (N-cnt);
            break;
        } else {
            ans += q.first * q.second;
            cnt += q.second;
        }
    }

    cout << ans << endl;

   return 0;  
}

Measured memory_bytes: 6512
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC042-A.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 STR PIC X(100).
       77 A PIC 9(2).
       77 B PIC 9(2).
       77 C PIC 9(2).
       77 COUNT5 PIC 9(1) VALUE 0.
       77 COUNT7 PIC 9(1) VALUE 0.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
               ACCEPT STR FROM SYSIN.
               UNSTRING STR DELIMITED " "
                INTO A B C.
               EVALUATE A
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               EVALUATE B
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               EVALUATE C
                   WHEN 5
                       ADD 1 TO COUNT5
                   WHEN 7
                       ADD 1 TO COUNT7
               END-EVALUATE
               IF COUNT5 = 2 AND COUNT7 = 1 THEN
                   DISPLAY "YES"
               ELSE
                   DISPLAY "NO"
               END-IF
               STOP RUN.
       END PROGRAM ABC042-A.


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

int main() {
  long n;
  cin >> n;
  
  vector<long> vec(5);
  for (int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  if(vec.at(0) == 1) {
    cout << n + 4 << endl;
  } else {
    cout << n / vec.at(0) + 5 << endl;
  }
}


Measured memory_bytes: 256
/**
 *      purpose : ABC 84 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-12 01:38:27
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

bool isPrime(int N){
    if (N == 1) return false;
    else if (N == 2 || N == 3) return true;
    for (int i = 2; i * i <= N; ++i){
        if (N % i == 0) return false;
    }
    return true;
}

bool like2017(int N){
    if (isPrime(N) && isPrime((N + 1) / 2)) return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int Q; scanf("%d", &Q);
    int l[Q] = {}; int r[Q] = {};
    for (int i = 0; i < Q; ++i){
        scanf("%d %d", &l[i], &r[i]);
    }

    bool t[100005] = {};
    for (int i = 3; i <= 100000; i += 2){
        if (like2017(i)) t[i] = true;
    }

    int cnt[100005] = {};
    cnt[1] = t[1];

    for (int i = 2; i <= 100000; ++i){
        cnt[i] = cnt[i - 1] + t[i];
    }

    for (int i = 0; i < Q; ++i){
        print(cnt[r[i]] - cnt[l[i] - 1]);
    }
    
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
double a[ohara];
double dp[5000][5000];
double ans;

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

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

    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    dp[1][1]=a[0];
    dp[1][0]=(1.0-a[0]);
    rrep(i,2,n+1){
        rep(j,n+1){
            dp[i][j]=dp[i-1][j]*(1.0-a[i-1])+dp[i-1][j-1]*(a[i-1]);
        }
    }
    rep(i,n+1){
        if(i>n-i){
            ans+=dp[n][i];
        }
    }
    printf("%.15f\n",ans);
    return 0;
}


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

int main() {
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  int a[n][m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++) cin>>a[i][j];
  }

  int ans=0;

  for(int i=0;i<n;i++){
    int y=0;
    for(int j=0;j<m;j++) y += b[j]*a[i][j];
    if(y>-c) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n;
	cin>>n;
	vector<vector<ll>> v(n+1);
	for(ll i=2;i<=n;i++){
		ll x;
		cin>>x;
		v[x].push_back(i);
	}
	for(ll i=1;i<=n;i++)
	cout<<ll(v[i].size())<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


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

long long memo[200005][2], a[200005];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    memo[2][0] = a[1], memo[2][1]= a[2];
    for (int i = 3; i <= n; i++) {
        if (i%2 == 0) {
            memo[i][0] = a[i - 1] + memo[i - 2][0];
            memo[i][1] = a[i] + max(memo[i - 1][0], max(memo[i - 2][0], memo[i - 2][1]));
        }
        else {
            memo[i][0] = max(memo[i - 1][1], memo[i - 1][0]);
            memo[i][1] = a[i] + max(max(memo[i - 2][0], memo[i - 2][1]), max(memo[i - 3][0], memo[i - 3][1]));
        }
    }
    cout << max(memo[n][0], memo[n][1]) << "\n";
}


Measured memory_bytes: 8304
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll a, b, c, k; cin >> a >> b >> c >> k;

  bool ans = false;

  rep(i, k+1) {
    ll x = a;
    ll y = b;
    ll z = c;
    rep(j, i) y *= 2;
    rep(j, k-i) z *= 2;
    if (x < y && y < z) ans = true;
  }

  cout << (ans ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	string s;cin>>s;
	if(s[0]=='7' || s[1]=='7' || s[2]=='7'){cout<<"Yes"<<endl;}
	else {cout<<"No"<<endl;}
	
	
}

Measured memory_bytes: 3628
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
struct cube{
	int men[31];
	int cnt;
};
queue<cube> q;
void h();
int jg(cube,int,int);
cube cg(cube,int,int,int,int,int,int,int,int,int,int);
int minn;
int main(){
	int n,i,j;
	cube c;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		minn=8;
		for(j=0;j<30;j++){
			scanf("%d",&c.men[j+1]);
			c.cnt=0;
		}
		q.push(c);
		h();
		printf("%d\n",minn);
		while(!q.empty()){
			q.pop();
		}
	}
	return 0;
}
void h(){
	cube a;
	int i,v;
	while(!q.empty()){
		a=q.front();
		q.pop();
		v=jg(a,1,9)*jg(a,10,12)*jg(a,13,15)*jg(a,16,18)*jg(a,19,21)*jg(a,22,30);
		if(v){
			minn=a.cnt;
			break;
		}
		q.push(cg(a,1,28,2,29,3,30,15,16,19,21));
		q.push(cg(a,1,24,4,27,7,30,10,21,16,18));
		q.push(cg(a,3,22,6,25,9,28,13,15,12,19));
		q.push(cg(a,7,22,8,23,9,24,18,13,10,12));
	}
}
int jg(cube a,int s,int g){
	int i,l=1;
	for(i=s;i<g;i++){
		if(a.men[i]!=a.men[i+1]){
			l=0;
		}
	}
	return l;
}
cube cg(cube p,int a1,int a2,int b1,int b2,int c1,int c2,int d1,int d2,int e1,int e2){
	swap(p.men[a1],p.men[a2]);
	swap(p.men[b1],p.men[b2]);
	swap(p.men[c1],p.men[c2]);
	swap(p.men[d1],p.men[d2]);
	swap(p.men[e1],p.men[e2]);
	p.cnt++;
	return p;
}

Measured memory_bytes: 12744
h, w = map(int, input().split())
m = [input().strip() for _ in range(h)]

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

for y in range(h):
    for x in range(w):
        dy = y
        uy = h - y - 1
        if m[dy][x] == '.':
            if dy == 0:
                d[dy][x] = 1
            else:
                d[dy][x] = d[dy - 1][x] + 1
        if m[uy][x] == '.':
            if uy == (h - 1):
                u[uy][x] = 1
            else:
                u[uy][x] = u[uy + 1][x] + 1

        lx = x
        rx = w - x - 1
        if m[y][lx] == '.':
            if lx == 0:
                l[y][lx] = 1
            else:
                l[y][lx] = l[y][lx - 1] + 1
        if m[y][rx] == '.':
            if rx == (w - 1):
                r[y][rx] = 1
            else:
                r[y][rx] = r[y][rx + 1] + 1

ans = 0
for y in range(h):
    for x in range(w):
        t = l[y][x] + r[y][x] + u[y][x] + d[y][x] - 3
        if t > ans:
            ans = t
print(ans)

Measured memory_bytes: 179716
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


a,b = input().split()

print(b+a)






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

typedef long long int   ll;
#define int             ll
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%lld",&n)
#define pb              push_back
#define PI              3.1415926535897932384626433832795
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    int t=1;
//    scan(t);
    while(t--){
        int n;cin>>n;
        int ar[n];
        int ans=0;
        for(int i=0;i<n;i++){
            cin>>ar[i];
            ans^=ar[i];
        }
        for(int i=0;i<n;i++){
            cout<<(ans^ar[i])<<" ";
        }
    }
}


Measured memory_bytes: 4996
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    const C = parseInt(arg[0].split(" ")[2]);
    
    console.log(Math.max(0, C - (A - B)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    vector<ll> A(X),B(Y),C(Z);
    rep(i,X)cin>>A.at(i);
    rep(i,Y)cin>>B.at(i);
    rep(i,Z)cin>>C.at(i);
    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());
    set<tuple<ll,int,int,int>> cake;
    cake.insert({A.at(0)+B.at(0)+C.at(0),X,Y,Z});
    rep(i,K){
        tuple<ll,int,int,int> now=*rbegin(cake);
        cake.erase(now);
        ll ans;
        int a,b,c;
        tie(ans,a,b,c)=now;
        cout<<ans<<endl;
        a=X-a;b=Y-b;c=Z-c;
        if(a+1<X){cake.insert({A.at(a+1)+B.at(b)+C.at(c),X-a-1,Y-b,Z-c});}
        if(b+1<Y){cake.insert({A.at(a)+B.at(b+1)+C.at(c),X-a,Y-b-1,Z-c});}
        if(c+1<Z){cake.insert({A.at(a)+B.at(b)+C.at(c+1),X-a,Y-b,Z-c-1});}
    }
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll ans = A[N-1];
    int now = N-2;
    int cnt = 0;
    int k = 0;
    while(k < N-2){
        ans += A[now];
        if(cnt == 0){
            cnt++;
        } else {
            cnt = 0;
            now--;
        }
        k++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>
int main(void){
    int a,b,x,y,z,w;
    int i = 1;
    scanf("%d",&a);
    scanf("%d",&b);
    x = a + b;
    y = a-b;
    z = a*b;
    for(i=1;i<=6;i++){
    if (x<=y){
    w = x;
    x = y;
    y = w;
    }
    if(y<=z){
    w = y;
    y = z;
    z = w;
    }
    }
    printf ("%d\n",x);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, std::vector<long long> A) {
  vl sortedA;
  rep(n, 0, N) { sortedA.push_back(A[n]); }
  sort(all(sortedA));

  ll cnt = 0;
  rep(n, 0, N) {
    ll index = lower_bound(all(sortedA), A[n]) - sortedA.begin();
    if (index % 2 != n % 2) {
      cnt++;
    }
  }

  print(cnt / 2);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


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

long n,k;
long long w[100000];

int v(long long P){
    long I=0;
    
    for(long j=0;j<k;j++){
    long long wei=0;
    while(wei+w[I]<=P){
        wei+=w[I];
        I++;
        if(I==n){return n;}
    }
        
    }
    return I;
    
}



int main(){
    scanf("%ld%ld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%ld",&w[i]);
    }
    long long MAXW=10000*100000;
    long long left=0,right=MAXW,mid,V;
    while(right>left){
        if(right-left==1)break;
        mid=(left+right)/2;
        V=v(mid);
        if(V>=n){
            right=mid;
        }

        else left=mid;
        
        
    }
    cout<<right<<endl;
    
/*    if(ok){
        int i=0;
        while(1){
            if(v(mid+i)==n){
                cout<<mid+i<<endl;
                return 0;
            }
            else{
            i++;
            }
        }
    
    
    }*/
    

    return 0;
}





Measured memory_bytes: 3936
#include <iostream>
#include <vector>

using namespace std;

struct Edge {
	int to, cost;
};

struct dfsAns {
	int n, v;
};

int N;
vector< vector<Edge> > edges;

dfsAns dfs(int n, int prev) {
	dfsAns ret = {n, 0};
	for (int i = 0; i < edges[n].size(); ++i) {
		if (edges[n][i].to != prev) {
			dfsAns a = dfs(edges[n][i].to, n);
			if ( edges[edges[n][i].to].size() > 1 ) a.v += edges[n][i].cost;
			if (a.v > ret.v) {
				ret = a;
			}
		}
	}
	return ret;
}

int main() {
	while (cin >> N, N) {
		edges.clear();
		edges.resize(N);

		vector<int> p(N);
		for (int i = 0; i < N-1; ++i) {
			cin >> p[i];
		}
		for (int i = 0; i < N-1; ++i) {
			int d; cin >> d;
			edges[i+1].push_back({p[i]-1, d});
			edges[p[i]-1].push_back({i+1, d});
		}
		dfsAns a = dfs(0, -1);
		a = dfs(a.n, -1);

		int ans = 0;
		for (int i = 0; i < edges.size(); ++i) for (int j = 0; j < edges[i].size(); ++j) {
			ans += edges[i][j].cost;
		}
		ans /= 2;
		for (int i = 0; i < edges.size(); ++i) {
			if (edges[i].size() > 1) {
				for (int j = 0; j < edges[i].size(); ++j) {
					if (edges[edges[i][j].to].size() > 1) ans += edges[i][j].cost;
//					if (i == edges[i][j].to) cout << "error" << endl;
				}
			}
		}
		ans -= a.v;
		cout << ans << endl;
	}
}

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

int n;
int x;
int cnt = 0;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(x&1) cnt++;
	}
	if(n==2 && cnt == 2){
		printf("YES\n");
	} else {
		if(cnt&1){
			printf("NO\n");
		} else {
			printf("YES\n");
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<string>
#include<math.h>
using namespace std;

int main()
{
	int n;
	int a[1000];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = n - 1; j != 0; j--)
		{
			if (a[j]<a[j - 1])
			{
				int s = a[j];
				a[j] = a[j - 1];
				a[j - 1] = s;
				ans++;
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << a[i];
		if (i != n - 1)cout << " ";
	}
	cout << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>

int main(){
        int N;
        std::cin >> N;
        std::string ABC;
        ABC.resize(N);
        for (int i = 0; i < N; i++){
        std::cin >> ABC[i];
    }
        int abcs = 0;
        for (int i = 0; i < N-2; i++){
        if (ABC.substr(i,3) == "ABC") abcs++;
    }
        std::cout << abcs << std::endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int n;
int d[505][505], s[505][505];

void init() {
  rep(i, n) {
    rep(j, n) {
      d[i][j] = inf;
      s[i][j] = 1;
      chmin(d[i][j], i);
      chmin(d[i][j], n - 1 - i);
      chmin(d[i][j], j);
      chmin(d[i][j], n - 1 - j);
    }
  }
}

void bfs(int sy, int sx) {
  s[sy][sx] = 0;
  queue<pair<int, int>> q;
  q.push({sy, sx});
  while (!q.empty()) {
    int y = q.front().first, x = q.front().second;
    q.pop();
    rep(k, 4) {
      int ry = y + dy[k], rx = x + dx[k];
      if (ry < 0 || ry >= n || rx < 0 || rx >= n) continue;
      if (chmin(d[ry][rx], d[y][x] + s[y][x])) {
        q.push({ry, rx});
      }
    }
  }
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  cin >> n;

  init();
  int ans = 0;

  int q = n * n;
  while (q--) {
    int p;
    cin >> p;
    p--;

    ans += d[p / n][p % n];
    bfs(p / n, p % n);
  }
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int n, m, cnt;
vi adj[200001];
bool visited[200001];

void dfs(int a) {
		
	if(visited[a]) return;
	visited[a]=true;
	++cnt;
	
	for(auto b: adj[a]) dfs(b);	
	
}

int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;
	
	while(m--) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	int ans=0;
	
	for(int i=1; i<=n; ++i) {
		if(!visited[i]) dfs(i);
		ans=max(ans, cnt);
		cnt=0;
	}
	
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 20984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll X,Y;
    cin >> X >> Y;
    int ans = 0;
    while(true){
        if (X > Y){
            break;
        }
        else{
            Y /= 2;
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, m;
    cin >> n >> m;
    map<ll, ll, greater<ll>> mp;
    rep(i, n){
        int a;
        cin >> a;
        mp[a]++;
    }
    rep(i, m){
        int b, c;
        cin >> b >> c;
        mp[c] += b;
    }

    ll ans = 0;
    int cnt = 0;
    for(auto i = mp.begin(); i != mp.end(); i++){
        ans += i->first * min(n-cnt, i->second);
        cnt += i->second;
        if(cnt >= n)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<29;
const double EPS = 1e-8;
const int MOD = 1000000007;

#define X first
#define Y second
#define MAXSIZE 1001
int n;
vector<pii> p;
int X[MAXSIZE][MAXSIZE];
int K[MAXSIZE][MAXSIZE];

int solve(int n) {
  memset(X, 63, sizeof(X));
  for (int i = 0; i <= n; ++i) {
    X[i][i+1] = 0;
    K[i][i+1]= i;
  }
  for (int w = 2; w <= n; ++w) 
    for (int i = 0, j; (j = i+w) <= n; ++i) 
      for (int r = max(i+1, K[i][j-1]); r <= min(j-1, K[i+1][j]); ++r)  {
        int c = X[i][r] + X[r][j] + p[r-1].Y - p[j-1].Y + p[r].X - p[i].X;
        if (X[i][j] > c) { X[i][j] = c; K[i][j] = r; }
      }
  return X[0][n];
}
main(){
	ios::sync_with_stdio(false);
	while(cin >> n){
		p.resize(n);
		REP(i, n) cin >> p[i].X >> p[i].Y;
		cout << solve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 9044
import java.util.Scanner;

public class Main {
 
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int N = scanner.nextInt();
            int [][] A = new int[2][N];
            for (int i=0; i<2; i++)
                for (int j=0; j<N; j++)
                    A[i][j] = scanner.nextInt();
            int Point=0;
            for(int j=0; j<N; j++){
                int d= A[0][0];
                //System.out.println("================");
                for(int i=1; i<=j; i++){
                   // System.out.println("0-"+i+"="+A[0][i]);
                    d += A[0][i];
                }
                for(int i=j; i<N; i++){
                    //System.out.println("1-"+i+"="+A[1][i]);
                    d += A[1][i];
                }
                if (Point < d) Point=d;
            }
            System.out.println(Point);
        }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,X[100005],L;
int des[20][100005];
signed main(){
	cin>>N;
	rep(i,N)cin>>X[i];
	cin>>L;
	rep(i,N){
		des[0][i]=upper_bound(X,X+N,X[i]+L)-X-1;
	}
	rep(i,19)rep(j,N)des[i+1][j]=des[i][des[i][j]];
	int Q;cin>>Q;
	while(Q--){
		int a,b;cin>>a>>b;a--;b--;
		if(a>b)swap(a,b);
		int ans=0;
		for(int i=19;i>=0;i--){
			if(des[i][a]<b){
				a=des[i][a];ans+=1<<i;
			}
		}
		cout<<ans+1<<endl;
	}
}


Measured memory_bytes: 17280
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    auto S = sread();
    long m = long.max;
    auto sum = new long[][](2, N + 1);
    foreach (i; 0 .. N)
        sum[0][i + 1] = sum[0][i] + (0 ^^ (S[i] != 'W'));
    foreach (i; 0 .. N)
        sum[1][i + 1] = sum[1][i] + (0 ^^ (S[i] != 'E'));

    iota(N).map!(x => (sum[0][x] - sum[0][0]) + (sum[1][N] - sum[1][x + 1]))
        .reduce!min().writeln();
}


Measured memory_bytes: 7892
import java.util.*;

public class Main {
    public static void main(String[] args) {
        ProblemG.problemG_LongestPath();
    }
}

class ProblemG {
    /* Idea: build DP of the longest path from each node i
    * DP[i] = max{DP[c] + 1 | c is the child node of node i}
    * ans is max{DP[i]}
    * */
    static int N;
    static int M;
    static ArrayList<Integer>[] graph;
    static Integer[] memo;

    static void problemG_LongestPath() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        graph = new ArrayList[N+1];
        for (int i = 1; i <= N; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < M; i++) {
            // add the edges
            graph[sc.nextInt()].add(sc.nextInt());
        }

        int[] DP = new int[N + 1];
        memo = new Integer[N + 1];

        int max = 0;
        for (int i=1; i<= N; i++) {
            if (memo[i] == null) {
                int dfs_i = DFS(i);
                max = Math.max(dfs_i, max);
//                System.out.println("DFS[" + i + "] = " +dfs_i);
//                System.out.println("memo[i] = " + memo[i]);
            }
        }
        System.out.println(max);
    }

    static int DFS(int i) {
        if (memo[i]!=null) return memo[i];
        int ret = 0;
        for (int v: graph[i]) {
            ret = Math.max(ret, 1 + DFS(v));
        }
      	memo[i] = ret;
        return ret;
    }
}


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

vector<int> v;
int main()
{
    int n, a, uo = 0;

    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a;
        if (a == i)
            v.push_back(i);
    }

    int sol = 0;

    for (int i = 0; i < v.size(); ++i)
    {
        if (i != v.size()-1 && v[i + 1] - v[i] == 1)
            ++i;
        ++sol;
    }

    cout << sol << '\n';
}

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

int main() {
  char s[100000 + 1] = {'\0'};
  cin >> s;
  int n = strlen(s);
  vector<int> num(n);
  int i;
  for(i = 0; i < n; i++) num[i] = 0;
  int count_r = 0;
  int count_l = 0;
  int tmp = 0;
  for(i = 0; i < n; i++) {
    if(s[i] == 'R' && count_l == 0) {
      count_r++;
    }
    else if(s[i] == 'L') {
      if(count_l == 0) tmp = i - 1;
      count_l++;
      if(i == n - 1 || s[i + 1] == 'R') {
        num[tmp + 1] += count_r / 2;
        if(count_r % 2 == 0) num[tmp] += count_r / 2;
        else                 num[tmp] += count_r / 2 + 1;
        num[tmp] += count_l / 2;
        if(count_l % 2 == 0) num[tmp + 1] += count_l / 2;
        else                 num[tmp + 1] += count_l / 2 + 1;
        count_r = 0;
        count_l = 0;
      }
    }
  }
  for(i = 0; i < n; i++) cout << num[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 896