akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
typedef pair<int,int> P;
const int INF = 1<<29;

int view[100][100];
int photo[4][50][50];

int main(){
    while(1){
        int n,m;
        scanf("%d%d",&n,&m);
        if(n==0)break;

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                scanf("%d",&view[i][j]);
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                scanf("%d",&photo[0][i][j]);
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                photo[1][j][m-1-i] = photo[0][i][j];
                photo[2][m-1-i][m-1-j] = photo[0][i][j];
                photo[3][m-1-j][i] = photo[0][i][j];
            }
        }

        int ansx = 0, ansy = 0;
        for(int i=0;i+m-1<n;i++){
            for(int j=0;j+m-1<n;j++){
                for(int k=0;k<4;k++){
                    bool is_same = true;
                    for(int pi=0;pi<m;pi++){
                        for(int pj=0;pj<m;pj++){
                            if(photo[k][pi][pj]!=-1 && view[i+pi][j+pj]!=photo[k][pi][pj]){
                                is_same = false;
                                break;
                            }
                        }
                        if(!is_same)break;
                    }
                    if(is_same){
                        for(int pi=0;pi<m;pi++){
                            for(int pj=0;pj<m;pj++){
                                if(photo[k][pi][pj]!=-1){
                                    ansy = i+pi+1; ansx = j+pj+1;
                                    break;
                                }
                            }
                            if(ansx)break;
                        }
                        break;
                    }
                }
                if(ansx)break;
            }
            if(ansx)break;
        }
        if(ansx) printf("%d %d\n",ansx,ansy);
        else printf("NA\n");
    }

    return 0;
}

Measured memory_bytes: 1272
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int a,b,q;
	std::cin >> a >> b >> q;
	std::vector<int> s(a);
	for(auto&&x:s) std::cin >> x;
	std::vector<int> t(b);
	for(auto&&x:t) std::cin >> x;
	const int INF = 1e17;
	rep(i,q) {
		int x;
		std::cin >> x;
		int min = INF;
		// both left
		{
			auto si=std::lower_bound(all(s),x);
			auto ti=std::lower_bound(all(t),x);
			if(si!=s.end() && ti!=t.end()) {
				min = std::min(min,std::max(*si,*ti)-x);
			}
		}
		// both right
		{
			auto si=std::lower_bound(s.rbegin(),s.rend(),x,std::greater<int>());
			auto ti=std::lower_bound(t.rbegin(),t.rend(),x,std::greater<int>());
			if(si!=s.rend() && ti!=t.rend()) {
				min = std::min(min,x-std::min(*si,*ti));
			}
		}
		// left and right
		{
			auto si=std::lower_bound(all(s),x);
			auto ti=std::lower_bound(t.rbegin(),t.rend(),x,std::greater<int>());
			if(si!=s.end() && ti!=t.rend()) {
				min = std::min(min,*si-*ti+std::min(*si-x,x-*ti));
			}
		}
		{
			auto si=std::lower_bound(s.rbegin(),s.rend(),x,std::greater<int>());
			auto ti=std::lower_bound(all(t),x);
			if(si!=s.rend() && ti!=t.end()) {
				min = std::min(min,*ti-*si+std::min(*ti-x,x-*si));
			}
		}
		print(min);
	}

	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

template <class T> vector<T> prime(T N) {
    vector<T> pri;
    vector<bool> is_prime;
    is_prime    = vector<bool>(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < N + 1; i++) {
        if (is_prime[i]) {
            pri.push_back(i);
            for (int j = 2 * i; j < N + 1; j += i)
                is_prime[j] = false;
        }
    }
    return pri;
}

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

    auto pri = prime(1E5);
    vector<int> cnt((int)1E5 + 1);
    REP(i, pri.size()) {
        if (binary_search(ALL(pri), (pri[i] + 1) / 2)) {
            cnt[pri[i]]++;
        }
    }
    partial_sum(ALL(cnt), cnt.begin());

    int Q;
    scan(Q);
    REP(i, Q) {
        int l, r;
        scan(l, r);
        int ans = cnt[r] - cnt[l - 1];
        print(ans);
    }

    return 0;
}

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


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



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

int main() {
    int64_t H, W, K, x1, y1, x2, y2;
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;

//    H = W = 1e3;
//    K = 1e3 / 2 - 1;
//    x1 = y1 = 0;
//    x2 = y2 = 1e3 - 1;

    vector<string> c(H);
    for (string& C : c) {
        cin >> C;
    }
//    for (string& C : c) {
//        C.assign(W, '.');
//    }

    vector<vector<int64_t>> cost(H, vector<int64_t>(W, LLONG_MAX));
    struct Element {
        int64_t x, y, cost;
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;
    pq.push({ x1, y1, cost[x1][y1] = 0 });

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

    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.x][t.y]) {
            continue;
        }

        for (int64_t i = 0; i < 4; i++) {
            int64_t nx = t.x, ny = t.y;
            int64_t new_cost = t.cost + 1;
            int64_t fail_num = 0;
            for (int64_t j = 0; j < K; j++) {
                nx += dx[i];
                ny += dy[i];
                if (nx < 0 || H <= nx || ny < 0 || W <= ny || c[nx][ny] == '@') {
                    break;
                }
                if (new_cost < cost[nx][ny]) {
                    pq.push({ nx, ny, cost[nx][ny] = new_cost });
                    fail_num = 0;
                } else if (++fail_num >= 5) {
                    break;
                }
            }
        }
    }

    int64_t ans = cost[x2][y2];
    cout << (ans == LLONG_MAX ? -1 : ans) << endl;
}

Measured memory_bytes: 19976
/*
15 1
##@........##..
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

char board[21][21];
int w, h;
int x, y;// ?????¨?????????

void slove(void){
	int cnt = 0;
	queue<pint> q;
	q.push(make_pair(y, x));//?????¨????????????queue?????\??????

	while(!q.empty()){
		pint now = q.front(); q.pop();
		rep(i, 4){
			int nowy = now.fi + dy[i];
			int nowx = now.se + dx[i];
			if (0 <= nowy && nowy <= h - 1 && 0 <= nowx && nowx <= w - 1){
				if (board[nowy][nowx] == '.'){
					cnt++;
					board[nowy][nowx] = 0;
					//printf("board %c\n", board[nowy][nowx]);
					q.push(make_pair(nowy, nowx));
				}
			}
		}
		/*
		rep(i, h){
			rep(j, w){
				printf("%c", board[i][j]);
			}
			printf("\n");
		}
		*/
	}
	printf("%d\n", cnt + 1);//?§?????????´????????\??????
	return;
}

void scan(int w, int h){
	rep(i, h){
		rep(j, w){
			cin >> board[i][j];
			if (board[i][j] == '@'){
				y = i; x = j;
			}
		}
		getchar();
	}

	slove();
	return;
}

int main(void){
	rep(i, 1000){
		cin >> w >> h;

		if (w == 0) break;
		scan(w, h);
	}
	return 0;
}

Measured memory_bytes: 3068
N = int(input())
AB = []

for _ in range(N):
    AB.append(list(map(int, input().split())))

AB.sort()
AB = sorted(AB, key = lambda x: x[1])

now = 0 
for ab in AB:
    now += ab[0]
    if now > ab[1]:
        print("No")
        exit()
print("Yes")

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

int main() {
    vector<int> a(5);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    vector<int> cnt(5);

    int ans = 0;
    for (int i = 0; i < 5; i++) {
        while (a[i] % 10 != 0) {
            a[i]++;
            cnt[i]++;
        }
        ans += a[i];
    }

    int mx = 0;
    for (int i = 0; i < 5; i++) {
        mx = max(mx, cnt[i]);
    }

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

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

int main() {
    long long int a,b,c,d, ans, ans1, ans2;
    cin >> a >> b >> c >> d;
    ans1 = max(a*c, a*d);
    ans2 = max(b*c, b*d);
    ans = max(ans1, ans2);
    cout << ans << endl;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n; cin>>n;
    ll sq=sqrt(n),mind=n-1,t=1,t1=n;
    for(int i=sq;i>=1;i--){
        if((n%i)==0){
            if(abs((n/i)-i)<mind){
                mind=abs((n/i)-i); t=n/i; t1=i;
            }
        }
    }
    cout<<(t-1)+(t1-1);
    return 0;
}


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

int main()
{
  int N ;
  cin >> N ;
  string str[N] ;
  for(int i = 0;i < N;i++)
  {
    cin >> str[i];
  }
  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;
  for(int i = 0;i < N;i++)
  {
    if(str[i] == "AC" )
    {
      AC++;
    }
    if(str[i] == "WA" )
    {
      WA++;
    }
     if(str[i] == "TLE" )
    {
      TLE++;
    }
       if(str[i] == "RE" )
    {
      RE++;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  return 0;
}


Measured memory_bytes: 5548
#include<bits/stdc++.h>
using namespace std;
int n,m,c;
vector<bool> edge(8);
vector<int> to[8];
void dfs(int now,int cnt){
  if(cnt==n){
    c++;
    return;
  }
  for(auto au:to[now]){
    if(!edge[au]){
      edge[au]=true;
      dfs(au,cnt+1);
      edge[au]=false;
    }
  }
}
int main(){
  cin>>n>>m;
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--,b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  edge[0]=true;
  dfs(0,1);
  cout<<c<<endl;
}

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

int main() {
    stack<int> s1;
    stack<pair<int,int> > s2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; i++) {
        if(ch == '\\') s1.push(i);
        else if(ch == '/' && !s1.empty()) {
            int j = s1.top(); s1.pop();
            sum += (i - j);
            int a = i - j;
            while(!s2.empty() && s2.top().first > j) {
                a += s2.top().second; s2.pop();
            }
            s2.push(make_pair(j,a));
        }
    }
    vector<int> ans;
    while(!s2.empty()) {
        ans.push_back(s2.top().second); s2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++) {
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>

int main()
{   
    int n;
    std::cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int temp;
        std::cin >> temp;
        sum += temp - 1;
    }
    std::cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <list>
#include <iomanip>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}


Int fact_mod(Int n, Int mod) {
    Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}

// 繰り返し二乗法 (modの世界での累乗)
Int mod_pow(Int x, Int n, Int mod) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 組み合わせ nCr を求める
Int combination_mod(Int n, Int r, Int mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    Int a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    Int b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

int main() {
    //COMinit();
    IOS;
    prec;
    Int a,b,c,n,m,k,x,y=0,ans=1;
    string str,s="",t,u;
    cin>>s;

    int now=0;
    if(s.substr(0,4)=="YAKI")cout<<"Yes";
    else cout<<"No";




    cout<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    if(y%2!=0){
        cout << "No" << endl;
    } else if(y/2>x*4){
        cout << "No" << endl;
    } else{
        int a=x, b=0;
        bool val = false;
        while(a>=0){
            //cout << a << " " << b << endl;
            if(a*2+b*4==y){
                val = true;
                break;
            }
            a--;
            b++;
        }
        if(val){
            cout << "Yes" << endl;
        } else{
            cout << "No" << endl;
        }
    }
    
    
    return 0;
}

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  for(int i=0;i<k;i++){
    if(a>=b) b*=2;
    else c*=2;
  }
  
  if(a<b&&b<c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

vector<ll> a(1,1),p(1,1);

void f(ll n){
    //cout << "e" << endl;
    for(int i=0;i<n;i++){
        a.push_back(a[i] * 2 + 3);
        p.push_back(p[i] * 2 + 1); 
    }
    //cout << "e1" << endl;
    return ;
}

ll func(ll n,ll x){
    //cout << "error" << endl;
    if(x==1){
        //cout << "e0" << endl;
        if(n==0) return 1;
        return 0;
    }else if(1<x && x<=1+a[n-1]){
        //cout << "e1" << endl;
        return func(n-1,x-1);
    }else if(x==2+a[n-1]){
        //cout << "e2" << endl;
        return p[n-1] + 1;
    }else if(2+a[n-1]<x && x<=2+2*a[n-1]){
        //cout << "e3" << endl;
        return p[n-1] + 1 + func(n-1,x-2-a[n-1]);
    }else if(x==3+2*a[n-1]){
        //cout << "e4" << endl;
        return 2*p[n-1] + 1;
    }
}

int main(){
    ll n,x;cin>>n>>x;
    f(n);
    cout << func(n,x) << endl;
}

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

using namespace std;
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll N = 1e7, oo = LONG_LONG_MAX, mod = 24;

void debug() { cerr << endl; }

template<typename Head, typename... Tail>
void debug(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug(T...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a;
  cin >> n >> a;
  int ans = (n % mod + a % mod) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
import unittest
import functools


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 3, 4]), 13)

    def test_2(self):
        self.assertEqual(think([12, 12, 12, 12, 12]), 5)

    def test_3(self):
        self.assertEqual(think([1000000, 999999, 999998]), 996989508)

    def test_4(self):
        self.assertEqual(gcd(3, 2), 1)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7

    lcm_of_all_a = functools.reduce(lambda x, y: lcm(x, y), a, 1)
    lcm_of_all_a %= mode

    result = 0
    for e in a:
        result += lcm_of_all_a * inverse(e, mode) % mode
        result %= mode
    return result


def write(result):
    print(result)


def lcm(a, b):
    return (a * b) // gcd(a, b)


def gcd(a, b):
    if a < b:
        return gcd(b, a)

    while True:
        if a % b == 0:
            return b
        a, b = b, a % b


def inverse(x, mode):
    return pow(x, mode - 2, mode)


if __name__ == '__main__':
    # unittest.main()
    solve()

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

main()
{
  int n,w;
  cin>>n>>w;
  int x,y;
  pair<ll,ll> p[n+1];
  p[0]=mp(0,0);
  for(int i=1;i<=n;++i)
   cin>>x>>y,p[i]=mp(x,y);
  sort(p,p+n);
  ll dp[n+1][w+1]={};
  for(int i=1;i<=n;++i)
  {
  	for(int j=1;j<=w;++j)
  	{
  		if(j<p[i].first) dp[i][j]=dp[i-1][j];
  		else dp[i][j]=max(p[i].second+dp[i-1][j-p[i].first],dp[i-1][j]);
  	}
  }
  cout<<dp[n][w];
  
}

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


using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vi A(n);
    rep(i,0,n){
        cin>>A[i];
    }






int x = 0;
for (int i = 0; i < n; i++)
    x ^= A[i];

for (int i = 0; i < n; i++)
        {A[i] = x ^ A[i];
        cout<<A[i]<<" ";
}}

Measured memory_bytes: 3956
#include <stdio.h>

int main(int argc,char* argv[]){
  char str[10];
  
  while(scanf("%s",str) != EOF){
    if(str[0] == 'o' && str[1] == 'o' && str[2] == 'o'){
      printf("o\n");
      continue;
    }else if(str[0] == 'x' && str[1] == 'x' && str[2] == 'x'){
      printf("x\n");
      continue;
    }

    if(str[3] == 'o' && str[4] == 'o' && str[5] == 'o'){
      printf("o\n");
      continue;
    }else if(str[3] == 'x' && str[4] == 'x' && str[5] == 'x'){
      printf("x\n");
      continue;
    }

    if(str[6] == 'o' && str[7] == 'o' && str[8] == 'o'){
      printf("o\n");
      continue;
    }else if(str[6] == 'x' && str[7] == 'x' && str[8] == 'x'){
      printf("x\n");
      continue;
    }
    
    if(str[0] == 'o' && str[3] == 'o' && str[6] == 'o'){
      printf("o\n");
      continue;
    }else if(str[0] == 'x' && str[3] == 'x' && str[6] == 'x'){
      printf("x\n");
      continue;
    }
    
    if(str[1] == 'o' && str[4] == 'o' && str[7] == 'o'){
      printf("o\n");
      continue;
    }else if(str[1] == 'x' && str[4] == 'x' && str[7] == 'x'){
      printf("x\n");
      continue;
    }

    if(str[2] == 'o' && str[5] == 'o' && str[8] == 'o'){
      printf("o\n");
      continue;
    }else if(str[2] == 'x' && str[5] == 'x' && str[8] == 'x'){
      printf("x\n");
      continue;
    }
    
    if(str[0] == 'o' && str[4] == 'o' && str[8] == 'o'){
      printf("o\n");
      continue;
    }else if(str[0] == 'x' && str[4] == 'x' && str[8] == 'x'){
      printf("x\n");
      continue;
    }

    if(str[2] == 'o' && str[4] == 'o' && str[6] == 'o'){
      printf("o\n");
      continue;
    }else if(str[2] == 'x' && str[4] == 'x' && str[6] == 'x'){
      printf("x\n");
      continue;
    }

    printf("d\n");
  }
  return 0;
  
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b, c, d; cin >> a >> b >> c >> d;
    int l = a + b, r = c + d;
    if (l > r) {
        cout << "Left\n";
        exit(0);
    }
    if (l == r) {
        cout << "Balanced\n";
        exit(0);
    }
    cout << "Right\n";
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

bool IsPrime(vt num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

int main() {
	ll x;
	cin >> x;
	while (!(IsPrime(x))) x++;
	cout << x;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(n) cout<<n<<endl
ll a, b, c, d, e, f;
bool w[100], s[3100];
int main() {
	cin >> a >> b >> c >> d >> e >> f;
	rep(i, 31) {
		if (i == 0 || w[i] != 0) w[i + a] = w[i + b] = 1;
	}
	s[0] = 1;
	rep(i, 3000) {
		if (s[i] != 0)s[i + c] = s[i + d] = 1;
	}
	ll ans=1, ans2=0;
	double mx=-1;
	for (int i = 0; i <= f / 100; ++i) {
		if (!w[i])continue;
		for (int j = i * e; j >= 0; --j) {
			if (s[j] && f >= i * 100 + j) {
				double per = (double)j / (100 * i + j);
				if (mx < per) { mx = per; ans = i, ans2 = j; break; }
			}
		}
		if (ans!=0&&ans2 / ans == e && ans2%ans == 0)break;
	}
	print(ans * 100 + ans2 << " " << ans2);
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import Text.Printf
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

main = do
  inp <- getIs
  putStrLn . show . succ $ foldr1 (-) inp


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

using namespace std;

int main(){
    string s;
    string t;

    cin >> s;
    cin >> t;

    int count = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] != t[i]){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

string s;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	cout << (s[0]==s[1]||s[1]==s[2]||s[2]==s[3] ? "Bad" : "Good") << "\n";
}

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

int main(){
    //入力
    int N;

    cin >> N;

    vector<int> a(N),a_sort(N);

    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }

    //計算
    int count=0;
    int num=0;
    for(int i=0;i<N;i++){
        count++;
        num=a.at(num)-1;
        if(num==1){
            cout <<  count << endl;
            return 0;
        }
    }

    //出力
    cout << -1 << endl;
    return 0;

}

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

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

counter = 0
flag = 1

while flag == 1:
	for i in range(len(l)):
		if l[i] % 2 != 0:
			flag = 0
			break
		else:
			l[i] = int(l[i] / 2)
	if flag == 1:
		counter += 1

print(counter)

Measured memory_bytes: 9120
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(Enumerable.Repeat(0, 6).Select(_ => Reader.NextInt).GroupBy(x => x).Max(x => x.Count()) == 3 ? "NO" : "YES");
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = 0;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }

    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 13524
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 1000000007
typedef long long ll;

int main(){
  ll X,Y,count=1;
  cin>>X>>Y;
  while(X*2<=Y){
    X*=2;
    count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
def main():
    import sys
    import math
    import numpy as np

    a,b = map(str, input().split())
    a = [int(i) for i in a]
    a += [0]*2
    a = np.array(a)
    b = b.replace('.','')
    b = [int(i) for i in b]
    ans = a*b[0]
    ans[1:] += a[:-1]*b[1]
    ans[2:] += a[:-2]*b[2]
    from functools import reduce
    l = reduce(lambda a,b:10*a+b, ans)
    print(l//100)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 27224
function Main(input) {
  N = input.split("\n")[0];
  d = input.split("\n")[1].split(" ").map(function(a) { return a * 1 });
  arr = new Array(30);
  for (i=0; i<arr.length; i++) {
      arr[i] = 0;
  }
  for (i=0; i<N; i++) {
     a = ("000000000000000000000000000000" + d[i].toString(2)).slice(-30).split("");
     for(j=0; j < a.length; j++) {
         arr[j] += a[j] * 1;
     }
  }

  ans = true;
  for (i=0; i<arr.length; i++) {
      ans = ans && arr[i] % 2 === 0;
  }
  console.log(ans ? 'Yes' : 'No')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28840
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        printf("%d\n",min(a*c+b*d,(a*max(c,5)+b*max(d,2))*4/5));
    }
	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e12

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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    string s;
    cin >> s;
    vector<int> a(2);
    a[0] = 0;
    a[1] = 0;

    rep(i, s.size()){
        if(s[i] == 'A') a[0]++;
        else a[1]++;
    }

    if((a[0] == 0) | (a[1] == 0)) cout << "No" << endl;
    else cout << "Yes" << endl;

}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seq = new int[n];
        for (int i = 0; i < seq.Length; i++)
        {
            seq[i] = int.Parse(Console.ReadLine());
        }

        var seqDesc = seq.ToArray();
        Array.Sort(seqDesc);
        Array.Reverse(seqDesc);

        var ms = new int[seq.Length];
        for (int i = 0; i < ms.Length; i++)
        {
            ms[i] = seqDesc.First() == seq[i] ? seqDesc.Skip(1).First() : seqDesc.First();
        }
        Console.WriteLine(string.Join(Environment.NewLine, ms));
    }
}


Measured memory_bytes: 27220
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a = "CODEFESTIVAL2016";
	string b;
	cin >> b;
	int out = 0;
	for (int i = 0; i < a.length(); ++i){
		if (a[i] != b[i])
			++out;
	}
	cout << out << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto A = RDA;
	A.sort();

	bool ans = true;
	foreach (i; 1..N)
	{
		if (A[i] == A[i-1])
			ans = false;
	}

	writeln(ans ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 11224
N = int(input())
T, A = [int(_) for _ in input().split()]
tmp = 1000
pos = 0

for p, x in enumerate((int(_) for _ in input().split())):
    t = abs(T - x * 0.006 - A)
    if tmp > t:
        tmp = t
        pos = p

print(pos + 1)


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

int main(){
    int a,b;
    cin>>a>>b;
    //cout<<a/b<<" "<<a%b<<" "<<(double)a/(double)b<<endl;
    printf("%d %d %.5f\n",(a/b),(a%b),((double)a/(double)b));
    return 0;
}


Measured memory_bytes: 3216
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	LL N, M;
	cin >> N >> M;
	vector<LL> P, Y;
	P.resize(M);
	Y.resize(M);
	REP(i, M) {
		cin >> P[i] >> Y[i];
	}

	map<pair<LL, LL>, LL> index;
	vector<vector<LL>> D;
	D.resize(N + 1);
	REP(i, M) {
		D[P[i]].push_back(Y[i]);
	}

/*	FOR(i, 1, N + 1) {
		cout << "@" << i << endl;
		for (auto x: D[i]) {
			cout << x << endl;
		}
		}*/
	FOR(i, 1, N + 1) {
		if (SZ(D[i]) == 0) continue;
		SORT(D[i]);
		REP(j, SZ(D[i])) {
			index[MP(i, D[i][j])] = (j + 1);
		}
	}

	REP(i, M) {
		cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6) << index[MP(P[i], Y[i])] << endl;
	}

	return 0;
}


Measured memory_bytes: 14720
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5] AS;
int[int] RI;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        auto A = readln.chomp.to!int;
        AS[i] = A;
        RI[A] = i;
    }
    sort(AS[0..N]);
    int c;
    foreach (i; 0..N) {
        if (i%2 != RI[AS[i]]%2) ++c;
    }
    writeln(c/2);
}

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

int main(){
  int N,K;
  cin >> N >> K;
  int h[N];
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  sort(h,h+N);
  int ans = h[N-1] - h[0];
  for(int i=0;i<N-K+1;i++){
    ans = min(ans,h[i+K-1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int a[3]; CINA(a,3);
  sort(a,a+3);
  int dif_A = a[2]-a[0];
  int dif_B = a[2]-a[1];
  int r;
  if(dif_A%2==0){
    if(dif_B%2==0){
      r = (dif_A+dif_B)/2;
    }else{
      r = (dif_A+dif_B+1)/2+1;
    }
  }else{
    if(dif_B%2==0){
      r = (dif_A+dif_B+1)/2+1;
    }else{
      r = (dif_A+dif_B-2)/2+1;
    }
  }
  cout << r;
}

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

using namespace std;

int main(void){
    int N; cin >> N;
    int A[N];
    for(int i = 0; i < N; i++)cin >> A[i];
    int numOfChange = 0;
    for(int i = 0; i < N; i ++){
        int minNum = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minNum]) minNum = j;
        }
        if(i != minNum){
            int temp = A[i];
            A[i] = A[minNum];
            A[minNum] = temp;
            numOfChange ++;
        }
    }
    cout << A[0];
    if(1 < N)for(int i = 1; i < N; i++)cout << " " << A[i];
    cout << endl << numOfChange << endl;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,ans=0;
  cin>>N;
  
  ll A[N+1],B[N];
  for(int i=0; i<=N; ++i) cin>>A[i];
  for(int i=0; i<N; ++i) cin>>B[i];
  
  for(int i=0; i<N; ++i){
    if(A[i+1]+A[i]<=B[i]){
      ans+=A[i]+A[i+1];
      A[i+1]=0;
      A[i]=0;
    }
    else if(A[i]<=B[i]){
      if(i==N-1) ans+=B[i];
      else ans+=B[i];
      A[i+1]-=(B[i]-A[i]);
    }
    else ans+=B[i];
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = t.len();

    for si in 0..s.len() + 1 - t.len() {
        let mut temp = 0;
        for ti in 0..t.len() {
            if t[ti] != s[si + ti] {
                temp += 1;
            }
        }
        ans = min(ans, temp);
    }

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
#define pb push_back
#define F first
#define S second
using namespace std;

int main(void) {
	boost;
	ll a,b;
	cin >> a>>b;
	ll ans=(b-a)*(b-a+1)/2 - b;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
  int h, w; cin >> h >> w;
  int c[10][10];
  int a[h][w];

  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++) cin >> c[i][j];
  }

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++) cin >> a[i][j];
  }

  for(int k=0; k<10; k++){
    for(int i=0; i<10; i++){
      for(int j=0; j<10; j++){
        c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
      }
    }
  }

  int ans=0;

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(a[i][j]!=-1) ans+=c[a[i][j]][1];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384