akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int F[105][105];
int xg,yg;


void DFS(int Y,int X,int c){
  if(F[Y][X] != c){
    return;
  }

  F[Y][X] = -1;
  DFS(Y-1,X  ,c);
  DFS(Y  ,X+1,c);
  DFS(Y+1,X  ,c);
  DFS(Y  ,X-1,c);
}


int main(){
  int w,h,xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<20; i++){
      for(int j=0; j<20; j++){
        F[i][j]=0;
      }
    }
    
    cin >> xs >> ys >> xg >> yg >> n;


    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
if(F[xs][ys]==0){
      cout << "NG" << endl;
      continue;
    }
  DFS(xs,ys,F[xs][ys]);

  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3084
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll L = 0;
	ll P = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 1;
	ll dist1 = 0;
	ll dist2 = 0;
	ll now = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	
	
	
	cin >>N;
	vector<int> tr(3);
	
	
	if(N < 1200)
	cout << "ABC" << endl;
	else
		cout << "ARC" << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}

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

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(ALL(a), greater<int>());
    sort(ALL(b), greater<int>());

    set<int> c;
    rep(i, n){
        if(c.find(a[i]) != c.end()){
            cout << 0 << endl;
            return 0;
        }
        c.insert(a[i]);
    }
    c = set<int>();
    rep(i, m){
        if(c.find(b[i]) != c.end()){
            cout << 0 << endl;
            return 0;
        }
        c.insert(b[i]);
    }

    vector<bool> both(n * m + 1, false), exist(n * m + 1, false);
    rep(i, n){
        rep(j, m){
            int x = min(a[i], b[j]);
            exist[x] = true;
            if(a[i] == b[j]){
                both[x] = true;
            }
        }
    }

    if(not both[n*m]){
        cout << 0 << endl;
        return 0;
    }

    int sum = 0;
    int row = 0;
    int column = 0;
    int ans = 1;
    for(int i = n * m; i >= 1; i--){
        if(row + 1 < n && a[row+1] == i){
            row++;
        }
        if(column + 1 < m && b[column+1] == i){
            column++;
        }

        if(both[i]){
            continue;
        }

        if(exist[i]){
            if(a[row] == i){
                ans *= (column + 1);
            }else{
                ans *= (row + 1);
            }
            ans %= MOD;
            continue;
        }

        int tmp = (row + 1) * (column + 1);
        tmp -= n * m - i;
        ans *= tmp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

class CPoll {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    map<string, int> check;
    vector<string> temp_;
    rep(i, N) {
      string temp;
      cin >> temp;
      check[temp] += 1;
      temp_.emplace_back(temp);
    }
    int maxi = 0;
    rep(i, N) {
      maxi = max(maxi, check[temp_[i]]);
    }
    sort(ALL(temp_));
    rep(i, N) {
      if (check[temp_[i]] == maxi) {
        check[temp_[i]] = 0;
        cout << temp_[i] << endl;
      }
    }
  }
};


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


Measured memory_bytes: 27376
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;



int main(void) {
   string S;
   cin>>S;
   if (S=="SUN") cout<<7<<endl;
   if (S=="MON") cout<<6<<endl;
   if (S=="TUE") cout<<5<<endl;
   if (S=="WED") cout<<4<<endl;
   if (S=="THU") cout<<3<<endl;
   if (S=="FRI") cout<<2<<endl;
   if (S=="SAT") cout<<1<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7;

int dp[4005][4005], a[200005], b[200005], pre[4005][4005];

int pw(int a, int b) {
	if(b == 0) return 1;
	int t = pw(a, b/2);
	if(b & 1) return t * t % M * a % M;
	else return t * t % M;
}

signed main()
{
	IO_OP;
	
	int n, ans = 0;
	cin >> n;
	pre[0][0] = 1;
	for(int i=0;i<=4000;i++)
		for(int j=0;j<=4000;j++) {
			if(i-1>=0) pre[i][j] += pre[i-1][j];
			if(j-1>=0) pre[i][j] += pre[i][j-1];
			pre[i][j] %= M;
		}
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		dp[-a[i]+2000][-b[i]+2000]++;
		ans -= pre[2*a[i]][2*b[i]];
	}
	for(int i=0;i<=4000;i++)
		for(int j=0;j<=4000;j++) {
			if(i-1>=0) dp[i][j] += dp[i-1][j];
			if(j-1>=0) dp[i][j] += dp[i][j-1];
			dp[i][j] %= M;
		}
	for(int i=0;i<n;i++)
		ans += dp[a[i]+2000][b[i]+2000];
	ans = (ans%M + M) % M;
	ans = ans * pw(2, M-2) % M;
	cout << ans << endl;
}





Measured memory_bytes: 253952
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let _ = lines.next();
    let s = lines.next().unwrap().unwrap();
    let mut s = s.chars().collect::<Vec<char>>();

    s.dedup();
    let ans = s.len();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

LL INF = 1e18;

LL dp[100][10];

int main() {
	rep(i, 0, 9) dp[1][i] = 1;
	rep(j, 2, 99)
		rep(i, 0, 9)
			rep(c, 0, 9)
				if (abs(i - c) <= 1) {
					dp[j][i] += dp[j - 1][c];
					dp[j][i] = min(dp[j][i], INF);
				}
	int k;
	scanf ("%d", &k);
	rep(len, 1, 99) {
		LL sum = 0;
		rep(i, 1, 9) {
			sum += dp[len][i];
			sum = min(sum, INF);
		}
		if (sum < k) {
			k -= sum;
			continue;
		}
		int last = -1;
		rep(i, 1, len) {
			rep(j, (i == 1), 9) {
				if (last != -1 && abs(j - last) > 1) continue;
				LL sum = (i == len ? 1 : 0);
				rep(c, 0, 9)
					if (abs(j - c) <= 1) {
						sum += dp[len - i][c];
						sum = min(sum, INF);
					}
				if (sum < k) k -= sum;
				else {
					printf ("%d", j);
					last = j;
					break;
				}
			}
		}
		return 0;
	}
				
	
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int in(n, h);
  int a[n], b[n];
  rep(i, n) {
    cin >> a[i] >> b[i];
  }

  int max_value = *max_element(a, a + n);
  int cnt = 0;
  sort(b, b + n, lambda(left, right, left > right));
  rep(i, n) {
    if(max_value >= b[i]) {
      break;
    }

    h -= b[i];
    cnt++;
    if(h <= 0) {
      out(cnt) exit(0);
    }
  }

  out((h + max_value - 1) / max_value + cnt);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int A,P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
}


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


int main() {
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c;cin>>a>>b>>c;
        if(a*a+b*b==c*c ||a*a+c*c==b*b ||b*b+c*c==a*a){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define all(n)      (n).begin(), (n).end()
#define ll long long 
#define PI 3.14159265358979323846

void solve(){
	int r; cin >> r; 
	long double ans;
	ans = (2 * PI * (long double)r);
	cout << setprecision(25) << ans << endl;
	

}


int main (){
	#ifndef ONLINE_JUDGE
		freopen ("input.txt","r",stdin);
		freopen ("output.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	//Write from here.
	
		solve();
	
	return 0;
}

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


typedef long long LL;
using namespace std;
 
void read(int &v) {
    int k = 0, l = 1;
    char ch;
    ch = getchar();
    while (ch > '9' || ch < '0') {
	if (ch == '-')
	    l = -1;
	ch = getchar();
    }
    while (ch >= '0' && ch <= '9') k = k * 10 + ch - '0', ch = getchar();
    v = l * k;
}

void print(int v) {
    if (v < 0)
	putchar('-'), v = -v;
    if (v > 9)
	print(v / 10);
    putchar(v % 10 + '0');
}
static int n, max2, max1, num1, num2, x;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i ) {
		read(x);
		if (x > max1) max1 = x, num1 = i;
		else if (x > max2) max2 = x, num2 = i;
	}
	for (int i = 1; i <= n; ++i) {
		if (i == num1) print(max2), puts("");
			else print(max1), puts("");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(){
  int n,m, x;
  vector< int > ai(102);
  vector< bool > check(102, false);
  cin >> n >> m >> x;
  for(int i=0; i<m; i++){
    int tmp;
    cin >> tmp;
    check[tmp] = true;
  }
  int cost1=0, cost2=0;
  for( int i=x-1; i>0; i--){
    if( check[i] ) cost1++;
  }
  for( int i=x+1; i<n; i++){
    if( check[i] ) cost2++;
  }
  if( cost1 > cost2 ) printf("%d\n", cost2);
  else printf("%d\n", cost1);
  return 0;
  
}


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

int main(){
  int n,m,x; cin>>n >>m >>x;
  vector<int> a(n+1,0);
  for(int i=0;i<m;i++){
    int cost; cin>>cost;
    a.at(cost)++;
  }
  int left=0;
  for(int i=0;i<x;i++){
    left += a.at(i);
  }
  int right=0;
  for(int i=x;i<n;i++){
    right += a.at(i);
  }
  
  cout<<min(left,right)<<endl;
}

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

#define MAXN 100005
#define ll long long int 

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto &x:a)cin>>x;
    sort(a.begin(),a.end());
    int s=0;
    for(int i=0;i<k;i++)s+=a[i];
    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    int N, K, d, temp, ans;

    cin >> N >> K;

    vector<int> A(N);

    for(int i=0; i < K; i++){
        cin >> d;
        for(int j=0; j < d; j++){
            cin >> temp;
            A[temp-1] += 1;
        }
    }

    for(int i=0; i < N; i++){
        if(A[i] == 0){
            ans++;
        }
    }

    cout << ans << endl;


}

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

void fnInsertionSort(vector<int> &argviSort, int argiGap, int &argiSortCnt)
{
  for (int ixSorting = argiGap; ixSorting < argviSort.size() ; ixSorting++)
  {
    int iTarget = argviSort[ixSorting];
    int ixSorted = ixSorting - argiGap;

    while (ixSorted >= 0              &&
           iTarget < argviSort[ixSorted])
    {
      argviSort[ixSorted + argiGap] = argviSort[ixSorted];
      ixSorted -= argiGap;

      argiSortCnt++;
    }
    argviSort[ixSorted + argiGap] = iTarget;
  }
}

void fnShellSort(vector<int> &argviSort, vector<int> &argviGap, int &argiSortCnt)
{

  for (int iGap = 1; iGap <= argviSort.size(); iGap = 3 * iGap + 1)
    argviGap.push_back(iGap);
  
  for (int i = argviGap.size() - 1; i >= 0; i--)
    fnInsertionSort(argviSort, argviGap[i], argiSortCnt);
}

void fnOutput(const vector<int> &argviSort, const vector<int> &argviGap, int argiSortCnt)
{
  cout << argviGap.size() << endl;

  for (int i = argviGap.size() - 1; i >= 0; i--)
  {
    if (i != argviGap.size() - 1) cout << " ";
    cout << argviGap[i];
  }
  cout << endl;

  cout << argiSortCnt << endl;

  for (int i = 0; i < argviSort.size(); i++)
    cout << argviSort[i] << endl;
}

int main()
{
  vector<int> viSort;
  vector<int> viGap;
  int iSortCnt = 0;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnShellSort(viSort, viGap, iSortCnt);
  fnOutput(viSort, viGap, iSortCnt);

  return 0;
}

Measured memory_bytes: 5672
N,Q = map(int,input().split())
S = list(input())
S = ["_"]+S
LR = [tuple(map(int,input().split())) for _ in range(Q)]

C = [0 for _ in range(N+1)]
#C[i]:i文字目までで"AC"が出てくる回数
for i in range(1,N):
    if S[i] == "A" and S[i+1] == "C":
        C[i+1] += 1

for i in range(N):
    C[i+1] += C[i]


for l,r in LR:
    print(C[r]-C[l])


Measured memory_bytes: 22084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int H, W, M; cin >> H >> W >> M;
    int h[M], w[M];
    vector<int> bomH(H, 0);
    vector<int> bomW(W, 0);
    map<Pint, bool> bomExist;
    rep(i, M) {
        cin >> h[i] >> w[i];
        --h[i];--w[i];
        bomExist[mp(h[i], w[i])] = true;
        bomH[h[i]]++;
        bomW[w[i]]++;
    }
    int maxH = 0, maxW = 0;
    int maxH_h = 0, maxW_w = 0;
    rep(i, H) {
        if(bomH[i] > maxH) {
            maxH = max(bomH[i], maxH);
            maxH_h = i;
        }

    }
    rep(i, W) {
        if(bomW[i] > maxW) {
            maxW = max(bomW[i], maxW);
            maxW_w = i;
        }
    }
    int ans = 0;
    rep(i, H) {
        if(bomExist[mp(i, maxW_w)]) {
            ans = max(maxW + bomH[i] - 1, ans);
        } else {
            ans = max(maxW + bomH[i], ans);
        }
    }
    rep(i, W) {
        if(bomExist[mp(maxH_h, i)]) {
            ans = max(maxH + bomW[i] - 1, ans);
        } else {
            ans = max(maxH + bomW[i], ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 64188
# coding: utf-8
import copy
N, K = map(int,input().split())
A = list(map(int,input().split()))

L = [False] * (N+1)
L2 = copy.deepcopy(L)
c = 1
cnt = 0
for i in range(N):
    if L[c]:
        break
    else:
        L[c] = True
        cnt += 1
        c = A[c-1]


cnt2 = 0
for i in range(N):
    if L2[c]:
        break
    else:
        L2[c] = True
        cnt2 += 1
        c = A[c-1]

if K <= cnt:
    ans = 1
    for i in range(K):
        ans = A[ans-1]
else:
    K -= cnt
    K %= cnt2
    ans = c
    for i in range(K):
        ans = A[ans-1]

print(ans)

Measured memory_bytes: 33240
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(N - 1):
    if x >= a[i]:
        ans += 1
        x -= a[i]
    else:
        break

if a[N - 1] == x:
    ans += 1

print(ans)


Measured memory_bytes: 9156
import java.util.*;
import java.util.stream.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        long num = 0, d = 1;
        for(int i = 0; i < K; i++)  {
            num += d;
            if(calc(num + 2 * d) < calc(num + d)) {
                d *= 10L;
            }
            System.out.println(num);
        }
    }
 
    public static double calc(long num) {
        double n = (double) num;
        double sum = 0;
        while(num != 0L) {
            sum += num % 10;
            num /= 10;
        }
        return n / sum;
    }
}

Measured memory_bytes: 21844
def F(N):
    if N%2 == 0:
        if N%4 == 0:
            return 0^N
        else:
            return 1^N
    else:
        if (N+1)%4 == 0:
            return 0
        else:
            return 1

A,B = map(int,input().split())

print(F(A-1)^F(B))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    // input
    int n, m, l;
    cin >> n >> m >> l;

    int arrA[n*m];
    for(int i=0; i<n; i++) {
        for(int ii=0; ii<m; ii++) {
            cin >> arrA[m*i + ii];
        }
    }

    int arrB[m*l];
    for(int j=0; j<m; j++) {
        for(int jj=0; jj<l; jj++) {
            cin >> arrB[l*j + jj];
        }
    }
    
    // calc
    long arrC[n*l];
    for(int r=0; r<n; r++) {
        for(int c=0; c<l; c++) {
            long sum = 0;
            for(int idxm=0; idxm<m; idxm++) {
                sum += arrA[m*r + idxm] * arrB[l*idxm + c];
            }
            arrC[l*r + c] = sum;
        }
    }
    
    // output
    for(int k=0; k<n; k++) {
        for(int kk=0; kk<l; kk++) {
            cout << arrC[l*k + kk];
            if(kk != l-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3264
n,k = [int(i) for i in input().split()]
l = [int(i) + 1 for i in input().split()]

ans = [0 for _ in range(n+1)]
for i in range(n):
    ans[i+1] = ans[i]+ l[i]

expect = 0   
for i in range(k,n+1):
    expect = max(expect,(ans[i] - ans[i-k])/2)
    
print(expect)
        

Measured memory_bytes: 25188
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 1e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[N];
bool f(int l,int r){
    while(l<=r){
        if(s[l]!=s[r]) return 0;
        l ++;r --;
    }
    return 1;
}
int main(){
    cin >>(s+1);
    int l = strlen(s+1);
    bool r = 0;
    r = f(1,(l-1)/2);
    r &= f((l+3)/2,l);
    r &= f(1,l);
    if(r) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

const int MAX_N = int(1e5);
int n;
unordered_map<int, int> mp_even, mp_odd;

void solve() {
    vector<pair<int, int> >
            elem_even(mp_even.begin(), mp_even.end()),
            elem_odd(mp_odd.begin(), mp_odd.end());
    sort(elem_even.begin(), elem_even.end(),
         [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
    sort(elem_odd.begin(), elem_odd.end(),
         [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });

    if (elem_even[0].first != elem_odd[0].first) {
        cout << n - elem_even[0].second - elem_odd[0].second << endl;
    } else {
        cout << min(n - elem_even[1].second - elem_odd[0].second,
                    n - elem_even[0].second - elem_odd[1].second) << endl;
    }
}

int main() {
    cin >> n;
    int temp;
    REP(i, n) {
        cin >> temp;
        if (i % 2 == 0) mp_even[temp]++;
        else mp_odd[temp]++;
    }
    solve();
    return 0;
}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int ans=t.size();
  int y=s.size()-t.size()+1;
  int z=t.size();
  if(s==t){
    ans=0;
  }
  for(int i=0;i<y;i++){
    int x=0;
    for(int j=0;j<z;j++){
      if(t[j]!=s[i+j]){
        x++;
      }
    }
    if(x<ans){
      ans=x;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={1,0,-1,1,-1,1,0,-1};
    int H,W;
    cin>>H>>W;
    string S[100];
    for(int i=0;i<H;i++)cin>>S[i];
    int fie[100][100]={0};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#')fie[i+1][j+1]=1;
        }
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(fie[i][j]==1)cout<<'#';
            else{
                int cou=0;
                for(int k=0;k<8;k++){
                    cou+=fie[i+dy[k]][j+dx[k]];
                }
                cout<<cou;
            }
        }
        cout<<endl;
    }
    return 0;
}


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

using namespace std;
int n,i,a,b,c,nr,ok,v[100005];
long long sum;
int main()
{
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>v[i];
        if (i!=v[i])
        {
            nr++;
        }
    }
    if (nr==0||nr==2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
void add(int s, int t, vector<ll> &imos) {
    if (s < t) {
        imos[s + 1]++;
        imos[t]--;
    } else {
        imos[s + 1]++;
        imos.back()--;
        imos[1]++;
        imos[t]--;
    }
}


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

    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, 0, n) {
        cin >> a[i];
    }
    vector<ll> fueru(m + 1), imos(m + 2);

    rep(i, 0, n - 1) {
        add(a[i], a[i + 1], imos);
        fueru[a[i + 1]] += (a[i + 1] - a[i] + m) % m - 1;
    }
    rep(i, 0, m + 1) {
        imos[i + 1] += imos[i];
    }
    ll ans = 0;
    ll cnt = 0;
    rep(i, 0, n-1) {
        ans += min((a[i + 1] - a[i] + m) % m, 1 + (a[i + 1] - 1 + m) % m);
    }
    cnt = ans;
    rep(c,1,m){
        cnt -= imos[c];
        cnt += fueru[c];
        ans = min(ans,cnt);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

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

int N;
cin >> N;
mint power = 1;
rrep(i,N) power *= i;
cout << power << endl;
return 0;
}

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

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5+10;
vector<pair<int,int> > G[N];
LL par[N];
int dfs(int x,int y)
{
    for(int i = 0; i < G[x].size(); i++) {
        int j = G[x][i].first;
        if(j == y) continue;
        par[j] = par[x] + G[x][i].second;
        dfs(j, x);
    }
}
int main()
{
    int n;
    int x, y, z;
    scanf("%d",&n);
    for(int i = 0; i < n-1; i++) {
        scanf("%d%d%d",&x,&y,&z);
        G[x].push_back(make_pair(y,z));
        G[y].push_back(make_pair(x,z));
    }
    int q, k;
    scanf("%d%d",&q,&k);
    par[k] = 0; dfs(k, -1);
    while(q--) {
        scanf("%d%d",&x,&y);
        printf("%lld\n",par[x]+par[y]);
    }
return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define pb push_back
#define vi vector<ll>
#define all(_x) _x.begin(), _x.end()
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define lb(_x, _a) (lower_bound(all(_x), _a) - _x.begin())
#define ub(_x, _a) (upper_bound(all(_x), _a) - _x.begin())
ll n, tc;

int main()
{
  	// ll is int now
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    vi arr(n); for(auto &x : arr) cin>>x;
    vi dp(n, 0);
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for(int i=2; i<n; i++)
    {
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <utility> 
#include <tuple>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;


int main() {
	int n,m;

while(cin>>n &&n!=0){
	map<char, char> ta;
	for(int i=0;i<26;i++){
		ta['a'+i]=i+'a';
	}
	for(int i=0;i<26;i++){
		ta['A'+i]=i+'A';
	}
	for(int i=0;i<10;i++){
		ta['0'+i]=i+'0';
	}
	for(int i=0;i<n;i++){
		char e,f;
		cin>>e>>f;
		ta[e]=f;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		char e;
		cin>>e;
		cout<<ta[e];
	}
	cout<<endl;
	
}



	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) cin >> D.at(i);
  sort(D.begin(), D.end());
  cout << D.at(N/2) - D.at(N/2-1) << endl;
}

Measured memory_bytes: 640
program main
  implicit none
  integer(8) :: n, i, res, kill
  integer(8), allocatable :: a(:), b(:)
  read (*, *) n
  allocate (a(n + 1), b(n))
  read (*, *) a
  read (*, *) b
  res = 0
  do i = 1, n
    kill = min(a(i), b(i))
    res = res + kill
    b(i) = b(i) - kill
    kill = min(a(i + 1), b(i))
    res = res + kill
    a(i + 1) = a(i + 1) - kill
  end do
  write (*, "(i0)") res
end program main


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

int main(){
	double a[50];
	int n = 0;
	while(cin >> a[n]){n++;}
	sort(a, a+n);
	cout << a[n-1] - a[0] << endl;
	return 0;
}

/*
3776.0
1819.0
645.2
2004.1
1208.6
*/

Measured memory_bytes: 3164
from math import factorial

B,W = map(int, input().split())
mod = 10**9 + 7

def comb(n,r):
  if n >= r:
    numer = factorial(n) % mod
    denom_inv = pow(((factorial(r) % mod)* (factorial(n-r) % mod)), mod-2, mod)
    return (numer * denom_inv) % mod
  else:
    return 0

ans = [0] * (B + W + 1)
ans_change = [0] * (B + W + 1)
change = (comb(B-1,0) * pow(2, W, mod)) % mod
two_inv = pow(2, mod-2, mod)
for i in range(W+1):
  if i < W:
    if i > 0:
      change = (change * (B+i-1) * pow(i, mod-2, mod) * two_inv) % mod
    change2 = (change * (B-1) * pow(B+i-1, mod-2, mod)) % mod
    ans_change[1] = (ans_change[1] + change2) % mod if B+i-1 > 0 else ans_change[1] + change
    ans_change[B+i] = (ans_change[B+i] + change - change2) % mod if B+i-1 > 0 else ans_change[B+i]
    ans_change[B+i+1] = (ans_change[B+i+1] - change) % mod
  else:
    change = (comb(W-1, 0) * pow(2, B, mod)) % mod
    for j in range(B):
      if j > 0:
        change = (change * (W+j-1) * pow(j, mod-2, mod) * two_inv) % mod
      change2 = (change * j * pow(W+j-1, mod-2, mod)) % mod
      ans_change[1] = (ans_change[1] + change2) % mod if W+j-1 > 0 else ans_change[1]
      ans_change[W+j] = (ans_change[W+j] - change2) % mod if W+j-1 > 0 else ans_change[W+j]
      ans_change[W+j+1] = (ans_change[W+j+1] + change) % mod
for i in range(B+W+1):
  ans[i] = (ans[i-1] + ans_change[i]) % mod
x = pow(2, B+W, mod)
for y in ans[1:]:
  print(int((pow(x, mod-2, mod) * y) % mod))

Measured memory_bytes: 108252
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

#define P 1000000007

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}

int main(void){
	int n=nextint();
	int ans = getk(10,n) + getk(8,n) - getk(9,n)*2;
	ans=(ans%P+P)%P;
	printf("%d\n", ans);
}


Measured memory_bytes: 1576
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(np.array([sortA[i]-a_large/2 for i in range(N-1)])))]
print(a_large,a_small)

Measured memory_bytes: 23740
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
#define int ll
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;
int a, b;

int prime_factorize(ll x){
	int cnt = 1;
	for(int i=2; i*i<=x; i++){			
		if (x % i == 0) cnt++;
		while(x % i == 0) x /= i;
	}
	if (x > 1) cnt++;
	return cnt;
}

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> a >> b;
	int ans = prime_factorize(__gcd(a, b));
	cout << ans << endl;
	return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end(), greater<int>());
    int a = 0, b = 0;
    for(int i=0; i<n; i++){
        if(i%2 == 0){
            a += v.at(i);
        }else{
            b += v.at(i);
        }
    }
    cout << a - b << endl;
    return 0;
}

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

void main()
{
    auto N = readln.chomp.to!int;

    int[] nn, xs;
    foreach (i; 1..N+1) nn ~= i;
    do {
        int x;
        foreach (i; 0..N) {
            x *= 10;
            x += nn[i];
        }
        xs ~= x;
    } while (nextPermutation(nn));
    sort(xs);
    int[int] rs;
    foreach (i, x; xs) {
        rs[x] = (i+1).to!int;
    }
    
    auto ps = readln.split.join.to!int;
    auto qs = readln.split.join.to!int;

    writeln(abs(rs[ps] - rs[qs]));
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
 
ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	map <ll,ll> mapp;
	ll ans = 1;
	mapp[-1] = 3;
	for (int z=0;z<n;z++){
		ll temp;
		cin >> temp;
		ans *= mapp[temp-1]-mapp[temp];
		mapp[temp]++;
		ans %= mod;
	}
	cout << ans << endl;
}

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL),cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x,ll y,ll p);
const ll inf=999999999;
const ll mod=1e9+7;
bool tc=false;

void solve()
{
	ll n; cin>>n;
	ll ar[n];
	for(ll i=0;i<n;i++) cin>>ar[i];
	vector <ll> sum;
	ll res=0;
	for(ll i=n-1;i>=0;i--)
	{
		sum.pb(res);
		res=(res+ar[i])%mod;
	}
	res=0;
	for(ll i=0;i<n;i++)
		res=(res+(ar[i]*sum[n-i-1])%mod)%mod;
	cout<<res;
}

int main() 
{
    FASTIO1;
    FASTIO2;
    clock_t start=clock();
    ll t=1; 
    if(tc) cin>>t;
    while(t--)
        solve();
    cerr<<fixed<<setprecision(6);
    cerr<<(double)(clock()-start)/CLOCKS_PER_SEC<<endl;
    return 0;
}

ll power(ll x,ll y,ll p)  
{  
    ll res=1; x=x%p;
    if(x==0) return 0;
    while(y>0)  
    {
        if(y&1) res=(res*x)%p;
        y=y>>1; x=(x*x)%p;  
    }
    return res;  
}  


Measured memory_bytes: 6956
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(S[int(input())-1])

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

#define mod (ll) (1e9)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
//#define make_pair mp
#define pi acos(-1)

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    int n;
    cin>>n;
    map<string,int>ar;
    while(n--)
    {
        string s;
        cin>>s;

        ar[s]++;
    }
    int count=0;
    for(auto x:ar)
    {
        count=max(count,x.second);
    }
    set<string>ans;
    for(auto x:ar)
    {
        if(x.second==count)
        {
            ans.insert(x.first);
        }
    }
    for(auto x:ans)
        cout<<x<<endl;
}


Measured memory_bytes: 34560
def main():
    n = int(input())
    a, b = [None]*n, [None]*n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    a.sort()
    b.sort()
    if n%2:
        print(b[n//2]-a[n//2]+1)
    else:
        bm = b[n//2]+b[n//2-1]
        am = a[n//2]+a[n//2-1]
        print(bm-am+1)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 89736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

using P = pair<int,int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vvec<int> g(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    int S,T;
    cin >> S >> T;
    S--; T--;
    int inf = 1e9;
    vvec<int> dp(N,vec<int>(3,inf));
    dp[S][0] = 0;
    queue<P> Q;
    Q.push({S,0});
    while(!Q.empty()){
        auto [cur,mod] = Q.front(); Q.pop();
        for(auto& to:g[cur]){
            int nmod = (mod+1)%3;
            if(dp[to][nmod]==inf){
                dp[to][nmod] = dp[cur][mod]+1;
                Q.push({to,nmod});
            }
        }
    }
    cout << (dp[T][0]!=inf? dp[T][0]/3:-1) << "\n";
}

Measured memory_bytes: 14244
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n), k(n);
    vl grundy(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> k[i];
    }
    for (int i = 0; i < n; ++i) {
        ll curr = a[i];
        while (true) {
            if (curr / k[i] == 0) {
                grundy[i] = 0;
                break;
            }
            if (curr % k[i] == 0) {
                grundy[i] = curr / k[i];
                break;
            }
            ll l = curr / k[i] * k[i] + 1;

            curr -= max(1LL, (curr - l) / (1 + curr / k[i])) * (1 + curr / k[i]);
        }
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ret ^= grundy[i];
    }
    if (ret == 0)
        cout << "Aoki"
             << "\n";
    else
        cout << "Takahashi"
             << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll g=0,now=-1,pcnt=0;
    rep(i,(ll)s.size()){
        if(s[i]=='g') g++;
        else g--;
        if(g==0) now=i;
    }
    rep2(i,now+1,(ll)s.size()){
        if(s[i]=='p') pcnt++;
    }
    cout<<(s.size()-now-1)/2-pcnt<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = in.nextInt();
			B[i] = in.nextInt();
		}
		long ans = 0;
		for (int i = N - 1; i >= 0; i--) {
			ans += (A[i] + ans) % B[i] > 0 ? B[i] - (A[i] + ans) % B[i] : 0;
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 65076