akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

bool is_kaibun(string s) {
  rep(i, 0, (int)s.length() / 2) {
    if (s[i] != s[s.length() - i - 1]) {
      return false;
    }
  }
  return true;
}

void solve() {
  VAR(string, S);
  int N = S.length();

  string s1 = S.substr(0, (N - 1) / 2);
  string s2 = S.substr((N + 3) / 2 - 1, N - ((N + 3) / 2) + 1);
  if (s1 == s2 && is_kaibun(s1)) {
    print("Yes");
  } else {
    print("No");
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  int N, K;
  cin >> S >> K;
  N = (int)S.size();
  vector<vector<vector<int>>> dp(N + 1,
                                 vector<vector<int>>(2, vector<int>(K + 1, 0)));
  dp[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      int c = S[i] - '0';
      for (int n = 0; n < 10; n++) {
        if (c < n && j == 0) continue;
        for (int k = 0; k < K + 1; k++) {
          int nj = j;
          if (c > n) nj = 1;

          int nk = k;
          if (n != 0) nk++;

          dp[i + 1][nj][nk] += dp[i][j][k];
        }
      }
    }
  }
  cout << dp[N][0][K] + dp[N][1][K] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
    
	int n;
	cin >> n;
	int m;
	cin >> m;
	vector<vector<int>> a(n, vector<int>(m, 0));
	for (int i = 0; i < n; ++i) {
	    for (int j = 0; j < m; ++j) {
	       cin >> a[i][j];
	    }
	}
	for (int i = 0; i < n; ++i) {
	    for (int j = 0; j < m; ++j) {
	       int x;
		   cin >> x;
		   a[i][j] -= x;
		   a[i][j] = abs(a[i][j]);	
	    }
	}
	vector<vector<vector<char>>> dp(n, vector<vector<char>>(m, vector<char>()));
	dp[0][0] = vector<char>(a[0][0] + 1, 0);
	dp[0][0][a[0][0]] = 1;  
	for (int i = 0; i < n; ++i) {
	   for (int j = 0; j < m; ++j) {
	       if (i == 0 && j == 0) continue;
		   vector<char> b;
		   if (i > 0) {
			   dp[i][j].resize(dp[i - 1][j].size() + a[i][j] + 1);
		       for (int k = 0; k < dp[i - 1][j].size(); ++k) {
	              if (dp[i - 1][j][k]) {
				      dp[i][j][abs(k + a[i][j])] = 1;
					  dp[i][j][abs(k - a[i][j])] = 1;
				  }
    		   }
		   }
		   if (j > 0) {
			   dp[i][j].resize(dp[i][j - 1].size() + a[i][j] + 1);
		       for (int k = 0; k < dp[i][j - 1].size(); ++k) {
				   if (dp[i][j - 1][k]) {
						dp[i][j][abs(k + a[i][j])] = 1;
						dp[i][j][abs(k - a[i][j])] = 1;
				   }
			   }			   
		   }
	   }
	}
	for (int i = 0; i < dp[n - 1][m - 1].size(); ++i) {
	    if (dp[n - 1][m - 1][i]) {
		    cout << i << endl;
			return 0;
		}
	}
	
    return 0;
}


Measured memory_bytes: 46208
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    int N;
    cin >> N;
    vector<lint> S(N);
    for (auto& s : S) cin >> s;

    lint ans = 0;
    for (int step = 1; step <= N; ++step) {
        int L = 0, R = N - 1;
        lint score = S[L] + S[R];  // = 0
        while (true) {
            L += step;
            R -= step;
            if (R < step ||
                (L >= R && R % step == 0)) break;
            score += S[L] + S[R];
            ans = max(ans, score);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
A,B,K=map(int, input().split())
ans=[]
for i in range(K):
  ans.append(A+i)
for i in range(K):
  ans.append(B-K+i+1)
ans=list(set(ans))
ans.sort()
for i in range(len(ans)):
  if A <= ans[i] <= B:
    print(ans[i])

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

if N == 3:
	print(2, 5, 63)
elif N == 4:
	print(2, 5, 20, 63)
else:
	n = N // 8
	ans = []
	for i in range(n):
		ans.append(12 * i + 2)
		ans.append(12 * i + 3)
		ans.append(12 * i + 4)
		ans.append(12 * i + 6)
		ans.append(12 * i + 8)
		ans.append(12 * i + 9)
		ans.append(12 * i + 10)
		ans.append(12 * i + 12)
	j =  N % 8
	if j == 1:
		ans.append(12 * n + 6)
	elif j == 2:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
	elif j == 3:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 12)
	elif j == 4:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 6)
		ans.append(12 * n + 12)
	elif j == 5:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 9)
	elif j == 6:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	elif j == 7:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	ans = list(map(str, ans))
	print(" ".join(ans))

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}

mint dp[55][55][2600];

int main(){
  int N, K;
  cin >> N >> K;

  dp[0][0][0] = 1;
  rep(i,N){
    rep(j,N){
      rep(k,2600){
        { //どちら側も保留
          if(k+2*(j+1)<2600) dp[i+1][j+1][k+2*(j+1)] += dp[i][j][k];
        }
        { //i+1同士をつなぐ
          if(k+2*j<2600) dp[i+1][j][k+2*j] += dp[i][j][k];
        }
        { //片方を保留とつなぐ
          if(k+2*j<2600) dp[i+1][j][k+2*j] += dp[i][j][k] * (2*j);
        }
        { //両方を保留とつなぐ
          if(j-1>=0 && k+2*(j-1)<2600) dp[i+1][j-1][k+2*(j-1)] += dp[i][j][k] * (j*j);
        }
      }
    }
  }

  cout << dp[N][0][K] << endl;
  
  return 0;
}


Measured memory_bytes: 61696
#B
s = input()

s_f = s[:2]
s_s = s[2:]

if (int(s_f) > 12 or int(s_f) == 0) and (int(s_s) > 12 or int(s_s) == 0):
    print('NA')
elif int(s_f) > 12 or int(s_f) == 0:
    print('YYMM')
elif int(s_s) > 12 or int(s_s) == 0:
    print('MMYY')

else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[list(input()) for i in range(h)]

#幅優先で解く。
dx=[1,0,-1,0]
dy=[0,1,0,-1]
def bfs():
  maze=[[-1]*w for i in range(h)]
  maze[ch-1][cw-1]=0
  qu=deque([])
  qu.append((cw-1,ch-1))
  magic=0
  
  while qu:
    x,y=qu.popleft()
    for i in range(4):
      nx=dx[i]+x
      ny=dy[i]+y
      if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]):
        qu.appendleft((nx,ny))
        maze[ny][nx]=maze[y][x]
    for i in range(x-2,x+3):
      for j in range(y-2,y+3):
        nx=i
        ny=j
        if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]+1):
          qu.append((nx,ny))
          maze[ny][nx]=maze[y][x]+1
  return maze
    
maze = bfs()
print(maze[dh-1][dw-1])

Measured memory_bytes: 130204
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main()
{
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string a="dream";
    string b="dreamer";
    string c="erase";
    string d="eraser";
    string q="dreamereraser";
    string w="dreameraser";
    string r="dreamererase";
    string t="dreamerase";
    size_t i;
     /* i=s.find(q);
    while(i!=string::npos){
        s.erase(i,q.size());
        i=s.find(q);
    }
     i=s.find(r);
    while(i!=string::npos){
        s.erase(i,r.size());
        i=s.find(r);
    }
     i=s.find(w);
    while(i!=string::npos){
        s.erase(i,w.size());
        i=s.find(w);
    }
     i=s.find(t);
    while(i!=string::npos){
        s.erase(i,t.size());
        i=s.find(t);
    }*/
     i=s.find(d);
    while(i!=string::npos){
        s.erase(i,d.size());
        i=s.find(d);
    }
     i=s.find(c);
    while(i!=string::npos){
        s.erase(i,c.size());
        i=s.find(c);
    }
    i=s.find(b);
    while(i!=string::npos){
        s.erase(i,b.size());
        i=s.find(b);
    }
     i=s.find(a);
    while(i!=string::npos){
        s.erase(i,a.size());
        i=s.find(a);
    }
    if(s.empty())cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    string s;cin>>s;
    cout<<s.substr(0, 3)<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n, m;
ll mod = 1e9+7;
ll a[55][55];
void mult(ll x[55][55], ll y[55][55]){
    ll z[55][55];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j){
            z[i][j] = 0;
            for(int k = 0; k < n; ++k)
                z[i][j] = (z[i][j] + x[i][k]*y[k][j]%mod)%mod;
        }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            x[i][j] = z[i][j];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> a[i][j];
    ll fin[55][55];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            fin[i][j] = (i == j);
    while(m > 0){
        if(m % 2)
            mult(fin, a);
        mult(a, a);
        m /= 2;
    }
    ll ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            ans = (ans + fin[i][j])%mod;
    cout << ans << "\n";
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {

    static String S;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        S = sc.next();

        System.out.println( solve() );
    }

    static int solve() {
        if( S.length() == 1 ) {
            return 1;
        }

        int mid = -1;
        for (int border = 1; border < S.length(); border++) {
            char prev = S.charAt(border-1);
            char post = S.charAt(border);

            if( prev != post ) {
                mid = moreMid(border, mid);
            }
        }

        if( mid == -1 ) {
            return S.length();

        } else {
            return S.length()-mid;
        }
    }

    static int moreMid(int border, int mid) {
        if( mid == -1 ) return mid(border);

        return Math.max(mid(border), mid);
    }

    static int mid(int border) {
        int bm = (S.length()+1) / 2;
        if( border < bm ) return border;
        else return S.length() - border;
    }

    @SuppressWarnings("unused")
    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



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

int main() {
	int x,y;
	cin >> x >> y;
	if (x > y) {
		cout << "a" << " > " << "b" << endl;
	}
	else if(x < y) {
		cout << "a" << " < " <<"b" << endl;
	}
	else{
	    cout << "a" << " == " << "b" << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i=0; i<N; i++) {
    cin >> W.at(i);
  }
  bool shiritori = true;
  for (int i=0; i<N; i++) {
    for (int j=1; j<N-i; j++) {
      if (W.at(i) == W.at(i+j)) {
        shiritori = false;
        break;
      }
    }
    if (!shiritori) {
      break;
    }
  }
  for (int i=0; i<N-1; i++) {
    if (W.at(i).back() != W.at(i+1).at(0)) {
      shiritori = false;
      break;
    }
  }
  string answer;
  if (shiritori) {
    answer = "Yes";
  }
  else {
    answer = "No";
  }
  cout << answer << endl;
}

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

const int MXN=100005;

int n,h[MXN];
int dp[MXN];

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",h+i);
  dp[n-1]=abs(h[n-1]-h[n]);
  for(int i=n-2;i>=0;--i){
    dp[i]=1e9;
    dp[i]=min(dp[i],abs(h[i]-h[i+1])+dp[i+1]);
    dp[i]=min(dp[i],abs(h[i]-h[i+2])+dp[i+2]);
  }
  printf("%d\n",dp[1]);
}


Measured memory_bytes: 1024
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepa(i,a,n) for (int i = n; i >= a; i--)
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
	char a;
  	cin>>a;
  	if(isupper(a))
      	cout<<"A"<<endl;
 	else
      	cout<<"a"<<endl;
}

int main()
{
    fastIO();
    int t;
    t=1; 
    while (t--)
    {
        Solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
bool isBi(ll x){
    for(int i = 0; i <50; i++){
        if(x == (1ll << i)){
            return true;
        }
    }
    return false;
}

ll getMinBi(ll x){
    int i = 2;
    if(isBi(x)){
        return x;
    }
    while(true){
        if(i < x && x < i * 2){
             return i;
        }else{
            i *= 2;
        }
    }
}


int main() {
    ll N;
    cin >> N;
    map<ll,ll,greater<ll>> m = map<ll,ll,greater<ll>>();
    ll count = 0;
    for(int i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        m[tmp]++;
    }
    auto begin = m.begin(), end = m.end();
    for (auto iter = begin; iter != end; iter++) {
        // first: key, second: value
        ll val = iter -> first;
        if(m[val] == 0){
            continue;
        }
        ll target = getMinBi(val) *2 - val;
        if(val == target){
            int del = m[val] / 2;
            count += del;
            m[val] -= del * 2;
        }else{
            int del = min(m[val],m[target]);
            m[val] -= del;
            m[target] -= del;
            count += del;
        }
        //cout << "key = " << iter->first << "\n";
        //cout << "value = " << iter->second << "\n";
    }
    cout << count << endl;


}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi p(n + 1);
	REP(i, n)
	{
		int a; cin >> a;
		p[a] = i;
	}
	set<int> st = { -1, n };
	ll ans = 0;
	FOR(i, 1, n + 1)
	{
		ll l = *prev(st.lower_bound(p[i]));
		ll r = *st.upper_bound(p[i]);
		ans += (p[i] - l) * (r - p[i]) * i;
		st.insert(p[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11264
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 500020
using namespace std;
LL read(){
    LL nm=0,fh=1; char cw=getchar();
    for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
    for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
    return nm*fh;
}
LL n,m,q[M],hd,tl,num[M],now,V;
double ans=0.0,maxn,tot,T[M];
double calc(LL x){return (1.0*num[x])*T[x];}
int main(){
    n=read(),m=read(),maxn=m*1.0,hd=1;
    for(LL i=1;i<=n;i++){
        T[i]=read()*1.0,num[i]=read(),q[++tl]=i,ans+=calc(i),V+=num[i];
        for(bool fg=false;hd<tl&&T[q[tl]]<=T[q[tl-1]];fg=false){
            ans-=calc(q[tl])+calc(q[tl-1]);
            if(num[q[tl]]+num[q[tl-1]]>m) num[q[tl-1]]=m-num[q[tl]],fg=true;
            T[q[tl-1]]=(calc(q[tl-1])+calc(q[tl]))/((num[q[tl-1]]+num[q[tl]])*1.0);
            num[q[tl-1]]+=num[q[tl]],tl--;
            if(fg) hd=tl,ans=calc(q[tl]),V=m;
            else  ans+=calc(q[tl]);
        }
        while(V>m){
            if(V-num[q[hd]]>=m) ans-=calc(q[hd]),V-=num[q[hd]],hd++;
            else ans-=calc(q[hd]),num[q[hd]]-=V-m,ans+=calc(q[hd]),V=m;
        }
        printf("%.10f\n",ans/maxn);
    }
    return 0;
}


Measured memory_bytes: 22272
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M, K;
i64 fact[909090], frev[909090];
i64 invs[909090];

i64 modpow(i64 a, i64 p = MOD - 2)
{
	if (p == 0) return 1;
	i64 tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2) tmp = tmp * a % MOD;
	return tmp;
}

i64 C(int a, int b)
{
	if (a < b) return 0;
	return fact[a] * frev[b] % MOD * frev[a - b] % MOD;
}

int main()
{
	fact[0] = 1; frev[0] = 1;
	invs[0] = 1;
	invs[1] = 1;
	for (int i = 2; i < 909090; ++i) invs[i] = MOD - MOD / i * invs[MOD % i] % MOD;
	for (int i = 1; i < 909090; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		frev[i] = frev[i - 1] * invs[i] % MOD;
	}

	scanf("%d%d%d", &N, &M, &K);

	if (M > K) swap(M, K);
	i64 ret = 0, cur = 1;
	for (int w = 0; w <= M + K; ++w) {
		ADD(ret, C(N - 1 + w, w) * cur % MOD * modpow(3, M + K - w));
		cur = cur * 2 % MOD;
		
		int lo = min(w, M);
		if (w >= M) {
			ADD(cur, MOD - C(w, M));
		}
		if (w >= K) {
			ADD(cur, MOD - C(w, w - K));
		}
	}
	printf("%lld\n", ret);

	return 0;
}


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

int main() {
  vector<int> x(3);
  vector<int> y(3);
  vector<int> z(3);

  for (int i=0; i<3; i++) {
    cin >> x.at(i);
    cin >> y.at(i);
    cin >> z.at(i);
  }
  
  for (int i=0; i<2; i++) {
    if (x[i]-x[i+1]!=y[i]-y[i+1] || x[i]-x[i+1]!=z[i]-z[i+1]) {
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200000], b[200000];
vector<int> vec;
signed main(){
  int n, sum[2] = {0, 0};
  scanf("%lld", &n);
  rep(i,n)scanf("%lld", &a[i]);
  rep(i,n)scanf("%lld", &b[i]);
  rep(i,n)sum[0] += a[i];
  rep(i,n)sum[1] += b[i];
  if(sum[0] < sum[1]){
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  rep(i,n)if(a[i] > b[i])vec.pb(a[i]-b[i]);
  rep(i,n)if(a[i] == b[i])ans++;
  int d = sum[0]-sum[1];
  sort(all(vec));
  int idx = 0;
  while(d > 0){
    if(idx == vec.size())break;
    if(vec[idx] > d)break;
    d -= vec[idx];
    ans++;
    idx++;
  }
  printf("%lld\n", n-ans);
  return 0;
}






Measured memory_bytes: 2428
import java.io.*;
import java.util.StringTokenizer;

public final class Main{
    public static void main(String[] args){
        FastScanner stdIn = new FastScanner(System.in);
        long a = stdIn.nextLong();
        long b = stdIn.nextLong();
        long c = stdIn.nextLong();

        if(c-(a-b)<0){
            System.out.println(0);
        }else{
            System.out.println(c-(a-b));
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public long nextInt() {
        return Integer.parseInt(next());
    }

}


Measured memory_bytes: 23124
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int a;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < 9; i++){
			scanf("%d", &a);
			n -= a;
		}
		printf("%d\n", n);
	}
	return (0);
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        sc.useDelimiter(",");
//        DecimalFormat df = new DecimalFormat("0.00000000");

        final long N = Long.parseLong(sc.next());
        long sum = 0;
        for (long i = 1; i <= N; i++) {
            if (i % 3 != 0 && i % 5 != 0)   sum += i;
        }
        out.println(sum);
        
        out.flush();
    }
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N,D;
    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));
    REP(i,N){
        REP(j,D){
            cin >> X[i][j];
        }
    }

    ll count = 0;
    REP(i, N){
       for(int j = i+1; j < N; j++ ){
          ll d = 0;
          REP(k, D){
             d += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
          }

          ll sq = (long)sqrt(d);
          if( sq * sq == d ){
            count++;
          }
       }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(3));
	vector<vector<int>> B(M, vector<int>(3));
	for (auto& a : A) for (auto& x : a) cin >> x;
	for (auto& a : B) for (auto& x : a) cin >> x;
	map<int, int> xs, ys;
	xs[0] = 0; ys[0] = 0;
	xs[-(1<<30)] = 0; ys[-(1<<30)] = 0;
	xs[1<<30] = 0; ys[1<<30] = 0;
	for (auto a : A) {
		xs[a[0]] = 0;
		xs[a[1]] = 0;
		ys[a[2]] = 0;
	}
	for (auto a : B) {
		xs[a[0]] = 0;
		ys[a[1]] = 0;
		ys[a[2]] = 0;
	}
	vector<int> xp, yp;
	{
		int c = 0;
		for (auto& p : xs) {
			xp.push_back(p.first);
			p.second = c++;
		}
	}
	{
		int c = 0;
		for (auto& p : ys) {
			yp.push_back(p.first);
			p.second = c++;
		}
	}
	int nx = xs.size()-1;
	int ny = ys.size()-1;
	vector<vector<int>> b(nx, vector<int>(ny));
	for (auto a : A) {
		int x1 = xs[a[0]];
		int x2 = xs[a[1]];
		int y = ys[a[2]];
		for (int x = x1; x < x2; ++ x) {
			b[x][y-1] |= 1;
			b[x][y] |= 2;
		}
	}
	for (auto a : B) {
		int x = xs[a[0]];
		int y1 = ys[a[1]];
		int y2 = ys[a[2]];
		for (int y = y1; y < y2; ++ y) {
			b[x-1][y] |= 4;
			b[x][y] |= 8;
		}
	}
	vector<vector<bool>> painted(nx, vector<bool>(ny));
	queue<pair<int,int>> Q;
	{
		int x0 = xs[0];
		int y0 = ys[0];
		for (int i = 0; i <= 1; ++ i) for (int j = 0; j <= 1; ++ j) {
			int x = x0-i;
			int y = y0-j;
			painted[x][y] = true;
			Q.push({x,y});
		}
	}
	const int dx[] = { 0, 0,+1,-1};
	const int dy[] = {+1,-1, 0, 0};
	while (!Q.empty()) {
		int x = Q.front().first;
		int y = Q.front().second;
		Q.pop();
		for (int k = 0; k < 4; ++ k) if (!((b[x][y]>>k)&1)) {
			int xx = x + dx[k];
			int yy = y + dy[k];
			if (xx == 0 || xx == nx-1 || yy == 0 || yy == ny-1) {
				cout << "INF" << endl;
				return 0;
			}
			if (!painted[xx][yy]) {
				painted[xx][yy] = true;
				Q.push({xx,yy});
			}
		}
	}
	ll res = 0;
	for (int x = 0; x < nx; ++ x) for (int y = 0; y < ny; ++ y) if (painted[x][y]) {
		ll xx = xp[x+1] - xp[x];
		ll yy = yp[y+1] - yp[y];
		res += xx * yy;
	}
	cout << res << endl;
}


Measured memory_bytes: 40612
fun main(args: Array<String>) = yorukatsu17c()

fun yorukatsu17c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }


    val answer = (-100..100L).map { i -> aList.map { (i - it) * (i - it) }.sum() }.min()!!

    println(answer)
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(A + B - N, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
#define int long long
ll mod_pow(ll a, ll b, ll r) {
return b <= 0? 1: (b % 2? a: 1) * mod_pow(a * a % r, b / 2, r) % r;
}

vector<ll> fac(1123456); //n!(mod M)
vector<ll> ifac(1123456); //k!^{M-2} (mod M)

ll comb(ll a, ll b,ll M){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

ll dupc(ll a,ll b,ll M){
    if(a == 0 && b == 0)return 1;
    if(a < 0 || b == 0)return 0;
    ll tmp = ifac[a-1]* ifac[b] % M;
    return tmp * fac[a+b-1] % M;
}
vector<vector<ll> > cmemo;
ll combbi(int n, int k,int MOD){
  if (k==0||n==k) return cmemo[n][k]=1;
  if (cmemo[n][k])return cmemo[n][k];
  if (n<k) return 0;
  return cmemo[n][k]=((combbi(n-1,k-1,MOD)+combbi(n-1,k,MOD)) % MOD);
}
signed main(){
    ll n,k,ans=0LL;
    cin>>n>>k;


    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<112345; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*mod_pow(i+1, mod-2,mod); // k!^{M-2} (mod M)
    }
    cmemo.assign(n+1,vector<ll>(n+1,0));

    //dump(comb(4,2,mod));

    for (int i=1;i<=k;i++){
        ans=0LL;
        {
            int bres=k-i;
            int rres=n-k-(i-1);

            ans+=combbi(rres+i,i,mod)%mod;
            ans*=combbi(bres+i-1,i-1,mod);
            
        }
        cout<<ans%mod<<endl;
    }
    
 
}

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

int main(){
  int a,b;
  vector<int> machi={0,0,0,0};
  for(int i=0; i<3; ++i){
    cin >> a >> b;
    if(a==1 || b==1) ++machi.at(0);
    if(a==2 || b==2) ++machi.at(1);
    if(a==3 || b==3) ++machi.at(2);
    if(a==4 || b==4) ++machi.at(3);
  }
  int SE=0,middle=0;
  for(int i=0; i<4; ++i){
    if(machi.at(i)==1) ++SE;
    if(machi.at(i)==2) ++middle;
  }
  if(SE==2 && middle==2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader tec = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		for (String line; (line = tec.readLine()) != null;) {
			StringTokenizer st = new StringTokenizer(line);
			long a=Long.parseLong(st.nextToken());
			long b=Long.parseLong(st.nextToken());
			long cont=0;
			if(a==b){
				out.println(0);
				continue;
			}
			if(a<b){
				if(a<0&&b>0){
					cont++;
				}
			}else{	
				
				if(b>0&&a>0){
					cont+=2;
				}
				if(b<=0&&a>=0){
					cont++;
				}
				if(b<0&&a<0){
					cont+=2;
				}
			}
			cont+=Math.abs(Math.abs(a)-Math.abs(b));
			out.println(cont);
		}
		out.close();
	}
}

Measured memory_bytes: 23252
S = input()

MAXS = 0
SUMS = 0

for i in range(len(S)):
    if (S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C' ):
        SUMS += 1
        if SUMS > MAXS :
            MAXS = SUMS
    else:
        SUMS = 0
        
print(MAXS)

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

ll N,T,Q;
set<ll> S;

ll a[100005];
ll d[100005];

int main(){
  cin>>N>>T>>Q;
  for(int i=0;i<N;i++){
    cin>>a[i]>>d[i];
    if(i>0 && d[i-1]==1 && d[i]==2 ){
      S.insert( a[i]/2LL + a[i-1]/2LL);
    }
  }

  ll INF = 1000000000000000001LL;
  S.insert(INF);
  S.insert(-INF);

  for(int i=0;i<Q;i++){
    ll id;
    scanf("%lld",&id);
    id--;
    if( d[id] == 1 ){
      ll target = *S.lower_bound(a[id]);
      if( abs(target) == INF)cout<<a[id]+T<<endl;
      else cout<<min(a[id]+T,target)<<endl;
    }else{
      set<ll> :: iterator it;
      it=S.lower_bound(a[id]);
      it--;
      ll target = *it;
      if( abs(target) == INF)cout<<a[id]-T<<endl;
      else cout<<max(a[id]-T,target)<<endl;
    }
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

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

ll f(ll a, ll b) {

    if (a % b == 0) {
        return 3 * (a / b) * b;
    }

    return 3 * (a / b) * b + f(b, a % b);
}

int main() {
    ll N, X;
    cin >> N >> X;
    cout << f(N - X, X) << endl;
    return 0;
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,m = map(int,ipt().split())
    s = [int(i) for i in ipt().split()]
    t = [int(i) for i in ipt().split()]
    ans = 0

    dp = [[1]*(m+1) for i in range(n+1)]
    for i,si in enumerate(s):
        for j,tj in enumerate(t):
            if si == tj:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]

            else:
                dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
            dp[i+1][j+1] %= mod

    print(dp[n][m])

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 96288
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
  int n, p; cin >> n >> p;
  string s; cin >> s;
  ll ans = 0;
  ll x = 1;
  vector<int> d(p);
  
  if(p == 2 || p == 5){
    for(int i = 0; i < n; i++){
      if((s[i]-'0') % p == 0) ans += i+1;
    }
  }
  else{
    for(int i = n-1; i >= 0; i--){
      int a = (a+(s[i]-'0') * x) % p;
      d[a]++;
      x = x * 10 % p;
    }
    ans = d[0];
    for(int i = 0; i < p; i++){
      ans += 1LL * d[i] * (d[i]-1) >> 1;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
    string o, e;
    cin >> o >> e;

    for(int i = 0;i < o.size()+e.size();i++){
        if(i % 2 == 0){
            cout << o[i/2];
        }else{
            cout << e[i/2];
        }
    }

    cout << endl;

    return 0;
}



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

using namespace std;

int A[100], N, M;

int main() {
    int s, c;
    cin >> N >> M;
    for (int i=0; i<N; i++) {
        A[i] = -1;
    }
    for (int i=0; i<M; i++) {
        cin >> s >> c;
        if ((A[s-1] == -1) || (A[s-1] == c)) {
            A[s-1] = c;
            continue;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    if ((N==1) && (A[0] == -1)) {
        cout << 0 << endl;
        return 0;
    }
    if ((N != 1) && (A[0] == 0)) {
        cout << -1 << endl;
        return 0;
    }
    if (A[0] == -1) {
        A[0] = 1;
    }
    for (int i=0; i<N; i++) {
        if (A[i] == -1) {
            cout << 0;
        } else {
            cout << A[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
# すぬけ君は 1,2,3 の番号がついた 3 つのマスからなるマス目を持っています。
# 各マスには 0 か 1 が書かれており、マスi には si が書かれています。

# 入力は以下の形式で標準入力から与えられる。
# s1s2s3
array = gets.chomp.split("").map(&:to_i)
# p array

# すぬけ君は 1 が書かれたマスにビー玉を置きます。
# ビー玉が置かれるマスがいくつあるか求めてください。
ans = 0
array.each do |e|
  ans += e if e == 1
end

p ans

Measured memory_bytes: 1788
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>


struct City {
    int i;
    int p;
    int y;
};

int main()
{
    int N, M;
    std::cin >> N >> M;
    std::vector<std::vector<City>> cities(N);
    std::vector<std::string> answers(M);
    for (int i = 0; i < M; i++) {
        int p, y;
        std::cin >> p >> y;
        City city;
        city.i = i;
        city.p = p;
        city.y = y;
        cities.at(p - 1).emplace_back(city);
    }

    for (auto& city_in_pref : cities) {
        std::sort(city_in_pref.begin(), city_in_pref.end(),
            [](auto a, auto b) { return a.y < b.y; });
        for (size_t i = 0; i < city_in_pref.size(); i++) {
            City city = city_in_pref.at(i);
            std::ostringstream os;
            int x = i + 1;
            int p = city.p;
            os << std::setfill('0') << std::setw(6) << p << std::setw(6) << x
               << std::setfill(' ');
            answers.at(city.i) = os.str();
        }
    }
    for (auto a : answers) {
        std::cout << a << std::endl;
    }

    return 0;
}

Measured memory_bytes: 12416
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int result = 1;
		for(int i = 1; i <= sqrt(m); i++){
		    if(m%i == 0){
		        int a = m/i;
		        if(a >= n) result = max(result, i);
		        if(i >= n) result = max(result, a);
		    }
		}
		
		// 出力
		System.out.println(result);
		
	}
}

Measured memory_bytes: 23764
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: u64 = read();
    let mut cnt = 0;
    let mut m = n;
    while m > 0 {
        m /= 10;
        cnt += 1;
    }
    let mut ans = 0;
    for i in 1..cnt {
        if i % 2 == 1 {
            ans += 9 * 10u64.pow(i-1);
        }
    }
    if cnt % 2 == 1 {
        ans += n - 10u64.pow(cnt-1) + 1;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main()
{
  int64_t N, prev_a, a, da = 0, cnt = 1;
  cin >> N;
  cin >> prev_a;
  for (int i = 1; i < N; i++)
  {
    cin >> a;
    if ((a > prev_a && da < 0) || ((a < prev_a && da > 0)))
    {
      cnt++;
      da = 0;
    }
    else if (da == 0)
    {
      da = a - prev_a;
    }
    prev_a = a;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <string>
#include <algorithm>

using namespace std;

using veci = vector<int>;
using pii = pair<int, int>;
using vecii = vector<pii>;
using ll = long long;
using vecl = vector<ll>;
#define fi first
#define se second
#define endl '\n'

ll const MOD = ll(1e9+7);
void solve() {
    int n;
    cin >> n;

    vector<vector<int>> suffix(n+1, vector<int>(60, 0));
    ll ai;
    for (int i=0; i<n; ++i) {
        cin >> ai;
        for (int j=0; j<60; ++j) {
            if (ai & (1LL << j)) {
                suffix[i][j] += 1;
            }
        }
    }

    for (int i=n-1; i>=0; --i) {
        for (int j=0; j<60; ++j) {
            suffix[i][j] += suffix[i+1][j];
        }
    }

    ll ans = 0;
    for (int j=0; j<60; ++j) {
        ll mulBase = (1LL << j) % MOD;
        for (int i=0; i<n; ++i) {
            if (suffix[i][j] - suffix[i+1][j]) {
                ans += (mulBase * (n-1-i-suffix[i+1][j]));
                ans %= MOD;
            } else {
                ans += (mulBase * suffix[i+1][j]);
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#if defined(LOCAL_TEST)
    (void)argc;
    freopen(string(argv[0]).append("-test.in").c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 82304