akhauriyash/Code-Regression huggingface dataset:
using System;
class rev{
   public static void Main(){
      bool flag = true;
      int n = int.Parse(Console.ReadLine());
      String[] str = Console.ReadLine().Split(' ');
      for (int i = n - 1; i >= 0; i--){
         if (flag){
            Console.Write(str[i]);
            flag = false;
         }
         else {
            Console.Write(" ");
            Console.Write(str[i]);
         }
      }
      Console.WriteLine();
   }
}


Measured memory_bytes: 15888
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int D, G;
	cin >> D >> G;

	vint P(D), C(D);
	for (int i = 0; i < D; i++) {
		cin >> P[i] >> C[i];
	}


	int ans = INF;
	for (int bit = 0; bit < 1 << D; bit++) {

		int local = 0;
		int sum = 0;

		for (int i = 0; i < D; i++) {
			if (bit >> i & 1) {
				local += P[i];
				sum += 100 * (i + 1) * P[i] + C[i];
			}
		}

		if (sum >= G) {
			ans = min(ans, local);
			continue;
		}
		else {
			int nokori = G - sum;
			for (int i = D - 1; i >= 0; i--) {
				if (((bit >> i) & 1) == 0) {
					int need = (nokori + 100 * (i + 1) - 1) / (100 * i + 100);
					if (need < P[i]) {
						ans = min(ans, local + need);
					}
					break;
				}
			}
		}


	}


	cout << ans;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int dp[3005][3005];
int tmp[3005];
char s[3005];
int main(){
    int n;
    scanf("%d", &n);
    scanf("%s", s+1);
    for(int i=1;i<=n;i++) dp[0][i-1] = 1;
    for(int i=1;i<n;i++){
        memset(tmp, 0, sizeof(tmp));
        if(s[i] == '<'){
            for(int j=0;j<=n;j++){
                tmp[j] = (tmp[j] + dp[i-1][j])%mod;
            }
            int sum = 0;
            for(int j=0;j<n-i;j++){
                sum = (sum + tmp[j])%mod;
                dp[i][j] = sum;
            }
        }
        else{
            for(int j=1;j<=n;j++){
                tmp[j-1] = (tmp[j-1] + dp[i-1][j])%mod;
            }
            int sum = 0;
            for(int j=n;j>=0;j--){
                sum = (sum + tmp[j])%mod;
                dp[i][j] = sum;
            }
        }
    }
    printf("%d\n", dp[n-1][0]);
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n, m;
    ll x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    auto a = make_vec<ll>(n, m);
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    ll ans = LINF;
    rep(bit, 1 << n) {
        vector<ll> r(m);
        ll now = 0;
        rep(i, n) {
            if (bit >> i & 1) {
                rep(j, m) r[j] += a[i][j];
                now += c[i];
            }
        }
        if (*min_element(all(r)) >= x) chmin(ans, now);
    }
    cout << (ans == LINF ? -1 : ans) << endl;
}

Measured memory_bytes: 3632
import java.io.*;
class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader r =new BufferedReader(new InputStreamReader(System.in), 1);
		String is = r.readLine();
		if(!is.contains(" ")) return;
		String[] sp = is.split(" ");
		int a = Integer.parseInt(sp[0]);
		int b = Integer.parseInt(sp[1]);
		if(a>b) System.out.println("a > b");
		else if(a<b) System.out.println("a < b");
		else System.out.println("a == b");
	}
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	string s;
	double t;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> t >> s;
		if (s == "JPY") {
			ans += t;
		}
		else {
			ans += t * 380000.0;
		}	
	}
	printf("%.10f\n", ans);

	return 0;
}

Measured memory_bytes: 256
n,y = map(int,input().split())
flg=0

for i in range(n+1):
    for j in range(n-i+1):
        ans = 10000*i + 5000*j + 1000*(n-i-j)
        if  ans == y:
            print(i,j,n-i-j)
            flg = 1
            break
    else:
        continue
    break


if flg == 0:
    print("-1 -1 -1")
else:
    pass

Measured memory_bytes: 40812
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  ll ans=0;
  rep(i,k){
    if(i%2==0&&s[i]=='1'){
      ans++;
    }
    else if(i%2==1&&s[i]=='0'){
      ans++;
    }
  }
  cout << min(ans,k-ans) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n, x, m;
	cin >> n >> x >> m;
	vector<ll> a(m * 2 + 5);
	a[0] = x;
	rep(i, m * 2 + 4) a[i + 1] = a[i] * a[i] % m;

	int s = 0;
	for (int i = m * 2 + 3; i >= 0; i--) {
		if (a[i] == a[m * 2 + 4]) {
			s = m * 2 + 4 - i;
			break;
		}
	}

	int st = -1;
	rep(i, m * 2 - s) {
		if (a[i] == a[i + s]) {
			st = i;
			break;
		}
	}

	rep(i, m * 2 + 4) a[i + 1] += a[i];
	if (n <= 2 * m + 4)
		cout << a[n - 1] << endl;
	else if (st == 0) {
		ll ans = a[s - 1] * (n / s);
		if (n % s) ans += a[n % s - 1];
		cout << ans << endl;
	} else {
		ll ans = (a[st + s] - a[st]) * ((n - st) / s) + a[st - 1];
		if ((n - st) % s != 0) ans += a[(n - st) % s + st - 1] - a[st - 1];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0
 
ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}
 
int h,w,n,k;
 
int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}
 
int ans[50][50];
 
void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if((h == w && rand()%2) || h > w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}
 
int main(){
    srand(time(0));
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);
 
    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }
 
    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}

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

int main() {

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000
 
 
int main()
{
	ll n,x,t;
	cin>>n>>x>>t;
	cout<<setprecision(20)<<ceil((double)n/(double)x)*t;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;
const LL p = 1e15;

int n, k, pos;
vector<int> l, r;

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(!x) k--;
        else if(x > 0) r.push_back(x);
        else if(x < 0) l.push_back(-x);
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.begin());

    if(!k)
    {
        puts("0");
        return 0;
    }

    int res = 0x3f3f3f3f;
    for(int i = 0; i <= k; i++)
    {
        int ll = i, rr = k - i;
        if(ll > l.size() || rr > r.size()) continue;

        int s1 = 0, s2 = 0;
        if(ll > 0) s1 = l[ll - 1];
        if(rr > 0) s2 = r[rr - 1];
        res = min(res, s1 + s2 + min(s1, s2));
    }

    cout << res << endl;
    return 0;
}


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

typedef pair<int, int> ii;

const int N = 100009;

int n, color[N] = {};
vector<ii> adj[N];

int dfs(int u, int prev_color) {
    int c = 1;
    for (ii edge : adj[u]) {
        int v = edge.first;
        int id = edge.second;
        if (!color[id]) {
            while (c == prev_color) {
                c += 1;
            }
            color[id] = c;
            dfs(v, c);
            c += 1;
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(ii(v, i));
        adj[v].push_back(ii(u, i));
    }

    dfs(1, 0);

    int k = *max_element(color, color + n);
    cout << k << endl;

    for (int i = 0; i < n - 1; i++) {
        cout << color[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 7424
H,W,D=map(int,input().split())
x=[0 for i in range(H*W+1)]
y=[0 for i in range(H*W+1)]
memo=[None for i in range(H*W+1)]
for j in range(H):
    A=list(map(int,input().split()))
    for i,a in enumerate(A):
        x[a]=i
        y[a]=j
Q=int(input())
ans=[]
for i in range(Q):
    L,R=map(int,input().split())
    if memo[D] is None:
        memo[D] = [0]*(D+1)
        for i in range(D+1,H*W+1):
            memo[D].append(memo[D][i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]))
    ans.append(memo[D][R]-memo[D][L])
for a in ans:
    print(a)


Measured memory_bytes: 66112
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define f first
#define s second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"	
#define no cout<<"NO"<<"\n"
#define INF (int)1e5
#define nax (int)1e6+2
using namespace std;
// look for  all edge cases
//bool seq[nax] = {false};


int main(){
	fast;
	int n ;
	cin >> n;
	ll sum = 0;
	for(int i = 1 ; i<= n; i++){
		if(i%3 == 0){
		}	
		else if(i%5 == 0){
		}
		else{
			ll temp = i;
			sum += temp;
		}
			
		
	}
	cout<<sum;
	return 0;
	
}


Measured memory_bytes: 3640
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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 COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  string a,b;
  cin>>n>>a>>b;
  vector<char> v;
  for(ll i=0;i<n;){
    if(a[i]==b[i]){
      v.push_back('x');
      i++;
    }else{
      v.push_back('y');
      i+=2;
    }
  }
  ll ans;
  if(v[0]=='x') ans=3;
  else ans=6;
  rep(i,v.size()-1){
    if(v[i]=='x' && v[i+1]=='y') ans*=2,ans%=MOD;
    else if(v[i]=='x' && v[i+1]=='x') ans*=2,ans%=MOD;
    else if(v[i]=='y' && v[i+1]=='y') ans*=3,ans%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int bubbleSort(int p[],int n)
{
   // int flag=1;
    int count=0;
    for(int i=0;i<n-1;i++){
      //  if(!flag)break;
      //  flag=0;
        for(int j=n-1;j>i;j--)
           if(p[j]<p[j-1]){
             //  flag=1;
               int t=p[j];
               p[j]=p[j-1];
               p[j-1]=t;
               count++;
           }
    }
    return count;
}
int main(){
    int n;
    cin>>n;
    int *p=new int[n];
    for(int i=0;i<n;i++) cin>>p[i];
    
    int m=bubbleSort(p,n);
    for(int i=0;i<n-1;i++) 
        cout<<p[i]<<' ';
    cout<<p[n-1]<<endl;
    cout<<m<<endl;
    
    
}


Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define FOR(i,a,b) for (ll i = (a) ; i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

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<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい


void Main(){
	ll N, M, K, ans=0, rt, j;
	cin >> N >> M >> K;
	j = M;
	VL a(N+1), b(M+1);

	a[0] = 0;
	FOR(i, 1, N){
		cin >> a[i];
		a[i] += a[i-1];
	}

	b[0] = 0;
	FOR(i, 1, M){
		cin >> b[i];
		b[i] += b[i-1];
	}


	rep(i, N+1){
		if(a[i] > K) continue;
		rt = K - a[i];
		while(j >= 0){
			if(rt >= b[j]) {
				ans = max(ans, i+j);
				break;
			}else{
				j--;
			}
		}
	}

	cout << ans << endl;


}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;

void solve(){
    int n;
    scanf("%d",&n);
    vector<int> v1,v2;
    for(int i = 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v1.pb(x+y);
        v2.pb(x-y);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    printf("%d\n",max(v1.back()-v1[0],v2.back()-v2[0]));
}
int main(){
    int t=1;
    int T=1;
    while(t--){
        solve();
    }
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/

Measured memory_bytes: 5108
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    bool one[20];
    fill(one, one + 20, false);
    int num = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        vector<int> bit;
        for (int j = 0; j < 20; j++) {
            if (A[i] >> j & 1) {
                bit.push_back(j);
            }
        }
        bool ok = true;
        int bitnum = bit.size();
        for (int j = 0; j < bitnum; j++) {
            if (one[bit[j]]) {
                ok = false;
            }
        }
        while (!ok) {
            bool b = true;
            for (int j = 0; j < bitnum; j++) {
                if (one[bit[j]]) {
                    b = false;
                }
            }
            if (b) {
                break;
            }
            for (int j = 0; j < 20; j++) {
                if (A[num] >> j & 1) {
                    one[j] = false;
                }
            }
            num++;
        }
        for (int j = 0; j < bitnum; j++) {
            one[bit[j]] = true;
        }
        ans += i - num + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
// https://beta.atcoder.jp/contests/abc064

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

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(6
)))())
)");
#endif
    int n;
    stream >> n;

    stack<string> s;
    int left_count = 0;
    for (int i = 0; i < n; ++i) {
        char c;
        stream >> c;
        if (c == ')') {
            string a = ")";

            string t;
            while (!s.empty()) {
                t = s.top(); s.pop();
                a.insert(0, t);
                if (t == "(") break;
            }

            if (t == "(") {
                s.push(a);
                left_count--;
            }
            else s.push("(" + a);
        }
        else {
            s.push("(");
            left_count++;
        }
    }

    vector<string> ans_rev;
    while (!s.empty()) {
        ans_rev.push_back(s.top()); s.pop();
    }
    string ans = accumulate(ans_rev.rbegin(), ans_rev.rend(), string());
    for (int i = 0; i < left_count; ++i) ans += ")";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    cout << min(n, k) * x + max(0, n - k) * y << endl;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
A=list(map(int, input().split()))
from collections import defaultdict
D=defaultdict(int)


L=[0]*(N+1)
D[0]+=1
for i in range(1,N+1):
    L[i]=(L[i-1]+A[i-1])%M
    D[L[i]]+=1
D=dict(D)
#print(D)
ans=0
for v in D.values():
    if v>1:
        ans+=v*(v-1)//2
print(ans)

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> arr[i][j];
        }
    }
    int dp[3][n];
    dp[0][0] = arr[0][0];
    dp[1][0] = arr[0][1];
    dp[2][0] = arr[0][2];
    
    for(int i=1;i<n;i++){
        dp[0][i] = arr[i][0] + max(dp[1][i-1],dp[2][i-1]);
        dp[1][i] = arr[i][1] + max(dp[0][i-1],dp[2][i-1]);
        dp[2][i] = arr[i][2] + max(dp[0][i-1],dp[1][i-1]);
    }
    
    cout << max(max(dp[0][n-1], dp[1][n-1]), dp[2][n-1]) << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
    int e;
    while(cin >> e, e){
        int m = e;
        for(int z=0; z*z*z<=e; ++z){
            int y = 1, n = e - z*z*z;
            for(; (y+1)*(y+1)<=n; ++y);
            int x = n - y*y;
            if(x+y+z < m)m = x+y+z;
        }
        cout << m << '\n';
    }
    return 0;
}

Measured memory_bytes: 1160
#import sys

#input = sys.stdin.readline
import math
#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True


def main():
#    h,w,a,b = map(int, input().split())
    n=int(input())

    if sosuhante(n)==True:
        print(n-1)
    else:
        for i in range(int(math.sqrt(n)+1),1,-1):
            if n%i==0:
                print((n//i + i -2))
                break






if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>199
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
const long int MAXN = 2e5+100;
#define PI 3.14159265358979323846264338327950

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

void solve()
{
  li n;
  cin>>n;

  
  li a=0,b=0,c=0,d=0;
  while(n--)
  {
    string str;
    cin>>str;

    if(str=="AC")
      a++;
    else if(str=="WA")
      b++;
    else if(str=="TLE")
      c++;
    else 
      d++;
  }

  cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
      cout<<"TLE x "<<c<<endl;
        cout<<"RE x "<<d<<endl;
}
int main()
{
    IOS;

    solve();
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >;
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
using namespace std;
string s;
int a;
int main(){
	cin>>a>>s;
	if(a<3200)
	cout<<"red";
	else
	cout<<s;
	re 0;
}


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

const vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        vector<vector<int>> grid(h, vector<int>(w));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> grid[i][j];
            }
        }
        int ans = 0;
        while (true) {
            stack<pair<int, int>> sk;
            bool flag = false;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (grid[i][j]) {
                        sk.push(mp(i, j));
                        flag = true;
                        break;
                    }
                }
                if (flag) break;
            }
            if (!flag) {
                cout << ans << endl;
                break;
            }
            while (!sk.empty()) {
                pair<int, int> v = sk.top();
                grid[v.first][v.second] = 0;
                sk.pop();
                for (int i = 0; i < 8; ++i) {
                    pair<int, int> nv = mp(v.first + dx[i], v.second + dy[i]);
                    if (nv.first < 0 || nv.first >= h || nv.second < 0 || nv.second >= w) continue;
                    if (grid[nv.first][nv.second] == 0) continue;
                    grid[nv.first][nv.second] = 0;
                    sk.push(mp(nv.first, nv.second));
                }
            }
            ans++;
        }
    }
}



Measured memory_bytes: 3148
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();

        System.out.println(f(h));
    }

    private static long f(long x) {
        if (x == 1) return 1;
        long a = f(x/2);
        return a*2+1;
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>

int compare_ll(const void *a, const void *b) {
  return *(long long*)a - *(long long*)b;
}

int main() {
  long long q, h, s, d, n;
  int flag = 0;
  scanf("%lld %lld %lld %lld", &q, &h, &s, &d);
  scanf("%lld", &n);
  long long pertwo[4];
  pertwo[0] = q*8;
  pertwo[1] = h*4;
  pertwo[2] = s*2;
  pertwo[3] = d;
  qsort(pertwo, 4, sizeof(long long), compare_ll);
  if (pertwo[0] == d) {
    if (pertwo[1] == d) {
      flag = 1;
    } else {
      flag = 2;
    }
  } else {
    flag = 1;
  }
  if (flag == 1) {
    long long ans = n*pertwo[0] / 2;
    printf("%lld", ans);
  }
  if (flag == 2) {
    if (n % 2 == 0) {
      long long ans = n*pertwo[0] / 2;
      printf("%lld", ans);
    } else {
      long long ans = (n-1)*pertwo[0] / 2 + pertwo[1]/2;
      printf("%lld", ans);
    }
  }
  return 0;
}


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

int main() {  
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int mincost;
  if(x==y) {
  	if(a+b > 2*c) {
    	mincost = 2*c*x;
    }
    else {
    	mincost += a*x+b*y;
    }
  }
  else if(x > y) {
  	  if(a+b > 2*c) {
    	mincost = 2*c*y;
        if(a*(x-y) > 2*c*(x-y)) {
        	mincost += 2*c*(x-y);
        }
        else mincost += a*(x-y);
    }
     else {
    	mincost += a*x+b*y;
    }
  }
  else {
  	if(a+b > 2*c) {
    	mincost = 2*c*x;
        if(b*(y-x) > 2*c*(y-x)) {
        	mincost += 2*c*(y-x);
        }
        else mincost += b*(y-x);
    }
     else {
    	mincost += a*x+b*y;
    }
  }
  cout << mincost << endl;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int e = c/b;
    if(c%b == 0){
        if(d*(e-1) >= a){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
    else{
        if(d*e >= a){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
}

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

int main() {
	// your code goes here
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i=0; i<n; i++)
		cin >> v[i];
	vector<int> dp(n, INT_MAX);
	dp[0]=0;
	for(int i=1; i<n; i++){
		for(int j=i-1; j>=max(0, i-k); j--){
			dp[i]=min(dp[i], dp[j]+abs(v[i]-v[j]));
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
int main()
{
    cout.precision(10);
    int n;
    cin>>n;
    cout<<fixed<<2*acos(-1.0)*n<<endl;
}


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

int main()
{
  int n;
  cin >> n;
  set<string> s;
  for(int i = 0;i < n;i++){
    string str;
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
}


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

int dPow(int x){
  int a=1;
  for(int i=0;i<x;i++)
    a*=2;
  return a;
}

signed main(){
  vector<int> d(45,0);
  int a,b;
  cin >> a >> b;
  a--;
  for(int i=0;i<45;i++){
    int key;
    if(i==0){
      key=a%4;//が1の出てくる回数(2を法として合同の値)
      if(key==1||key==2){
        d.at(i)=1;
      }else
        d.at(i)=0;
    }else{
      key = a%dPow(i+1);//余りが2以下なら0 2以上ならその回数分
      if(key/dPow(i)==0){
        d.at(i)=0;
      }else{
        d.at(i)=key%dPow(i)+1;
      }
    }
  }
  vector<int> e(45,0);
  for(int i=0;i<45;i++){
    int key;
    if(i==0){
      key=b%4;//が1の出てくる回数(2を法として合同の値)
      if(key==1||key==2){
        e.at(i)=1;
      }else
        e.at(i)=0;
    }else{
      key = b%dPow(i+1);
      if(key/dPow(i)==0){
        e.at(i)=0;
      }else{
        e.at(i)=key%dPow(i)+1;
      }
    }
  }
  int ans=0;
  for(int i=0;i<45;i++){
    int ess;
    ess=d.at(i)+e.at(i);
    ess%=2;
    ans+=ess*dPow(i);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll a_max = a[N - 1];
  double half_a_max = (double)a[N - 1] / 2.0;
  ll cand = 0;
  ll res = INF;
  for (int i = 0; i < N - 1; i++) {
    if (abs(half_a_max - a[i]) < res) {
      cand = a[i];
      res = abs(half_a_max - a[i]);
    }
  }
  cout << a_max << " " << cand << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  map<pair<string,string>,ll> cnt;
  string s1=s.substr(0,n);
  string s2=s.substr(n,n);
  reverse(s2.begin(),s2.end());
  for(ll i=0;i<(1<<n);i++) {
    string r="",b="";
    for(ll j=0;j<n;j++) {
      if(i>>j&1) {
        r=r+s1[j];
      }
      else {
        b=b+s1[j];
      }
    }
    cnt[{r,b}]++;
  }
  ll ans=0;
  for(ll i=0;i<(1<<n);i++) {
    string r="",b="";
    for(ll j=0;j<n;j++) {
      if(i>>j&1) {
        r=r+s2[j];
      }
      else {
        b=b+s2[j];
      }
    }
    ans+=cnt[{r,b}];
  }
  cout << ans << endl;
}

Measured memory_bytes: 87808
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

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

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	
	int dp[100010][13]={0};
	int N = S.size();
	
	dp[0][0] = 1;
	REP(i, N) {
		int c;
		if (S[i] == '?') c = -1;
		else c = S[i] - '0';

		REP(j, 10) {
			if (c != -1 && c != j)continue;
			REP(k, 13) {
				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
			}
		} 
		
		REP(j, 13)
			dp[i + 1][j] %= mod;
	}

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



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


def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    mi = min(a)
    ma = max(a)

    if ma-mi > 1:
        print("No")
    elif ma == mi:
        if 1 <= mi <= n//2 or mi == n-1:
            print("Yes")
        else:
            print("No")
    else:
        nmi = a.count(mi)
        nma = a.count(ma)
        if nmi+1 <= ma <= nmi+nma//2:
            print("Yes")
        else:
            print("No")

    return None

if __name__ == '__main__':
    main()


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

int main(){
    long long n, count = 0;
    vector<long long> a, b;
    cin >> n;
    for(int i = 0; i < n + 1; i++){
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    for(int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        b.push_back(temp);
    }

    for(int i = 0; i < n; i++){
        count += min(a[i], b[i]);
        if(a[i] < b[i]){
            int temp = b[i] - a[i];
            if(a[i+1] > temp) count += temp;
            else count += a[i+1];
            a[i+1] = max(0LL, a[i+1]-temp);
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
int MOD = 1000000007;
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; }
ll modpow(ll a, ll b, ll M) {
	ll res = 1;
	for (; b > 0; b >>= 1) {
		if (b & 1) res = (res * a) % M;
		a = a * a % M;
	}
	return res;
}
ll comb(int n,int r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res = res * (n - i) % MOD;
		res = res * modpow(i + 1, MOD - 2, MOD) % MOD; // 逆元は下から掛けていく
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	ll ans = modpow(2, n, MOD) - 1;
	int a, b;
	cin >> a >> b;
	ans -= comb(n, a);
	ans -= comb(n, b);
	if (ans < 0) while (ans < 0) ans += MOD;
	if (ans > MOD) while (ans > MOD) ans -= MOD;
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
n = gets.to_i
w = gets.split.map(&:to_i)

ans = (w[0] - w[1..-1].inject(:+)).abs

(n - 1).times do |i|
  s1 = w[0..i].inject(:+)
  s2 = w[i + 1..-1].inject(:+)

  abs = (s1 - s2).abs
  ans = abs if abs <= ans
end

puts ans


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    char b;
    cin >> b;

    if (b == 'A') {
        cout << "T" << endl;
    } else if (b == 'T') {
        cout << "A" << endl;
    } else if (b == 'G') {
        cout << "C" << endl;
    } else if (b == 'C') {
        cout << "G" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long


int binarysearch(int A[], int n, int key)
{
    int left = 0, right = n;
    while(left < right)
    {
        int mid = (left + right) / 2;
        if(A[mid] == key)
        {
            return 1;
        } 
        else if(key < A[mid])
        {
            right = mid;
        }
        else
        {
            left = mid + 1;
        }
    }
    return 0;
}


int main()
{
    int s[100001];
    int n, q, key;
     
    cin >> n;
    REP(i, n) cin >> s[i];
    cin >> q;
 
    int sum = 0;
    REP(i, q)
    {
        cin >> key;
        if(binarysearch(s, n, key)) sum++;
    }
    cout << sum << endl;
 
}

Measured memory_bytes: 3440
a, b, c = map(int, input().split())
ans_1 = abs((a*b*(c//2)) - (a*b*(c - (c//2))))
ans_2 = abs((c*b*(a//2)) - (c*b*(a - (a//2))))
ans_3 = abs((c*a*(b//2)) - (c*a*(b - (b//2))))
ans = min(min(ans_1, ans_2), ans_3)
print(ans)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/06  Problem: 066_Abc_a / Link: http://abc066.contest.atcoder.jp/tasks/abc066_a?lang=en  ----- */
/* ------問題------

snuke 君は自転車を買いに来ました。 snuke 君はすでに買う自転車を決めたのですが、その自転車にはベルが付いていないため、 自転車とは別にベルも買う必要があります。

snuke 君は安全意識が高いので、ベルをどちらの手でも鳴らせるよう、両方のハンドルに 1 つずつ 付けることにしました。

お店にあるベルは 3 種類で、それぞれ a円、 b円、 c円です。 この 3 つのうち、異なる 2 つのベルを選んで買うときの、値段の合計の最小値を求めて下さい。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


int ans = 0LL;

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

	VI a(3);
	FOR(i, 0, 3)cin >> a[i];
	ans = INF;
	FOR(i, 0, 3) {
		FOR(j, i + 1, 3) {
			ans = min(ans, a[i] + a[j]);
		}
	}
	cout << ans << "\n";

	return 0;
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int64_t n, k;
    cin >> n >> k;
    if (k == 1) {
    	cout << "0\n";
    	exit(0);
    }
	int64_t d = n/k;
	int64_t res = n - d*k;
	cout << min(abs(res), abs(res - k)) << '\n';
}

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

int main() {
  string s;
  bool ans=false;
  for(int i=0;i<4;i++){
    cin>>s[i];
  }
  for(int i=0;i<4;i++){
    if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3]){
      ans=true;
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 1000000000+7;
    long[] fac, inv;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        main.solve();
        out.println(main.solve());
        out.flush();
    }
    long solve() throws IOException {
        int n = sc.nextInt(), k = sc.nextInt();
        ini(n);
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = sc.nextLong();
        Arrays.sort(a);
        long pos = 0, nega = 0;
        for(int i=k-1;i<n;i++){
            pos += a[i]*combine(i, k-1)%mod;
            pos %= mod;
        }
        for(int i=n-1;i>=0;i--){
            nega += a[i]*combine(n-1-i,k-1)%mod;
            nega %= mod;
        }
        long ans = (pos-nega+mod)%mod;
        return ans;
    }
    long combine(int n, int m){
        if(n<m) return 0;
        return fac[n]*inv[m]%mod*inv[n-m]%mod;
    }
    void ini(int n){
        fac = new long[n+1]; inv = new long[n+1];
        fac[0] = 1;
        for(int i=1; i<=n; i++) fac[i] = fac[i-1]*i%mod;
        inv[0] = 1; inv[n] = power(fac[n],mod-2);
        for(int i=n-1;i>0;i--){
            inv[i] = inv[i+1]*(i+1)%mod;
        }
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
}

Measured memory_bytes: 61164
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <signal.h> 
#include <locale> 
#include <algorithm>

#define fo(i,n) for(long long int i=0;i<n;i++)
#define fo1(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define pb push_back
#define fill_vector(n,v) for(long long int i=0;i<n;i++){long long int temp;cin>>temp;v.push_back(temp); }
#define print_vector(n,v) for(long long int i=0;i<n;i++){cout<<v[i]<<"\n"; } 
#define sortv(v) sort(v.begin(), v.end())
#define sortvo(v) sort(v.begin(), v.end(),greater<long long int>())
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector< int>
#define vs vector<string>
#define y() cout<<"YES"<<"\n"
#define n() cout<<"NO"<<"\n"
#define logbase(x,y) {log10(y)/log10(x)}

typedef int long long ll;
using namespace std;

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll a,b,c,ans;
		cin>>a>>b>>c;
		if(a>=b) ans=ceil((double)a/b)*c;
		else ans=c;
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3676
import itertools

N = int(input())
lst = [i for i in range(1, N  + 1)]

per = list(itertools.permutations(lst))


a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))


s = per.index(a)
t = per.index(b)

ans = abs(s - t)
print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll q;
    cin >> q;
    priority_queue<ll, vector<ll>, greater<ll>> pq2;
    priority_queue<ll> pq1;
    ll ans = 0;
    rep(i, 0, q) {
        ll n;
        cin >> n;
        if (n == 1) {
            ll a, b;
            cin >> a >> b;
            ans += b;
            pq1.push(a), pq2.push(a);
            if(pq1.top() > pq2.top()) {
                ll tmp1 = pq1.top(), tmp2 = pq2.top();                
                pq1.pop(), pq2.pop();
                pq1.push(tmp2), pq2.push(tmp1);
                ans += abs(tmp1 - tmp2);
            }
        }
        else {
            cout << pq1.top() << " " << ans << endl;
        }
    }
}

Measured memory_bytes: 4588