akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

vector<ll> fact(2010, 1), inv(2010, 1);

ll comb(int n, int k)
{
    if(k<0 || n<k) return 0;
    ll ret = fact[n] * inv[k] % MOD;
    ret = ret * inv[n-k] % MOD;
    return ret;
}

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

    ll n, k;
    cin >> n >> k;
    for (ll i = 2; i <= 2000; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mypow(fact[i], MOD - 2);
    }
    for(int i=1;i<=k;i++)
    {
        cout << comb(n-k+1, i) * comb(k-1, i-1) % MOD << endl;
    }
}


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

using ll = long long;

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int k,n;
	cin>>k>>n;

	int ans=1e9;

	vector<int> A;

	for(int i=0; i<n; i++)
	{
		int a;
		cin>>a;
		A.push_back(a);

		if(i>0) ans=min(ans,k-(A[i]-A[i-1]));
	}

	ans = min(ans,k-(A[0]+k-A[n-1]));

	cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n), b(n);
	vector<ll> cnt(100001);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		cnt[a[i]] += b[i];
	}
	for (int i = 1; i <= 100000; i++) {
		if (k <= cnt[i]) {
			cout << i << endl;
			break;
		}
		k -= cnt[i];
	}
	return 0;
}

Measured memory_bytes: 1792
n, w = map(int, input().split())
x = []
y = []

for i in range(n):
  a,b = map(int, input().split())
  x.append(b)
  y.append(a)

max_num = sum(x)

dp = [[float("inf")] * (max_num + 1) for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
  for j in range(max_num + 1):
    if(j >= x[i]):
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - x[i]] + y[i])
    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
    
print(max(list(int(i) for i in range(max_num + 1) if dp[n][i] <= w)))


Measured memory_bytes: 311888
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    
    long N = scan.nextLong();
    long A = scan.nextLong();
    long B = scan.nextLong();
    
    if((B - A) % 2 == 0){
      System.out.println((long)((B - A) / 2));
    }else{
      if(B-1 < N-A){
        System.out.println(A + (long)((B - A) / 2));
      }else{
        System.out.println(N-B + 1 + (long)((B - A) / 2));
      }
    }
  }
}

Measured memory_bytes: 22484
gets
ary = [[], [], [], []]

4.times{|i|3.times{|a| ary[i] << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}
ARGF.each_line do |line|
  b, f, r, v = line.chomp.split.map(&:to_i)
  ary[b-1][f-1][r-1] += v
end
4.times do |n|
  puts "#"*20 unless n == 0
  3.times{|i| puts "\s" + ary[n][i].join("\s")}
end

Measured memory_bytes: 6116
#include <iostream>
int main(int argc, char** argv)
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,x;
    cin >> a >> b >> x;
    cout << (a > x ? "NO\n" : (b < x - a ? "NO\n" : "YES\n"));
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i=0; i<n; ++i) {
        cin >> c.at(i);
        for (int j=0; j<m; ++j) {
            cin >> a.at(i).at(j);
        }
    }

    int res = INF;
    for (int bits=0; bits<(1<<n); ++bits) {
        int cost = 0;
        vector<int> un(m);
        for (int i=0; i<n; ++i) {
            if (bits & (1<<i)) {
                cost += c.at(i);
                for (int j=0; j<m; ++j) {
                    un.at(j) += a.at(i).at(j);
                }
            }
        }
        bool ok = true;
        for (int i=0; i<m; ++i) {
            if (un.at(i) < x) {
                ok = false;
                break;
            }
        }
        if (ok) chmin(res, cost);
    }
    cout << (res == INF ? -1 : res) << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str
import bisect

def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    ab = list(zip(a,b))
    ab.sort(key=lambda x: x[0])
    a.sort()

    for aabb in ab:
        if aabb[0] != 1:
            break 

        next_index = bisect.bisect_left(a,aabb[1])
        next_index2 = bisect.bisect_left(a,aabb[1]+1)

        for i in range(next_index,next_index2):
            if ab[i][1] == N:
                print(YES)
                return

    print(NO)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 36608
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n,m,x;
         cin>>n>>m>>x;
         ll c[n];
         ll a[n][m];
         vector<vector<ll>>v;
         for(int i=0;i<n;i++)
         {
            vector<ll>v1;
            for(int j=-1;j<m;j++)
            {
                ll p;
                cin>>p;
                if(j==-1)
                  c[i]=p;
                else
                  a[i][j]=p;
                v1.pb(p);
            }
            v.pb(v1);
         }
         ll ans = 1e18;
         for(int i=0;i<(1<<n);i++)
         {
             ll have[m];
             for(int l=0;l<m;l++) have[l]=0;
             ll cur=0;
             for(int j=0;j<n;j++)
             {
                  if(i & (1<<j))
                  {
                       for(int k=1;k<v[j].size();k++)
                       {
                           have[k-1]+=v[j][k];
                       }
                       cur+=v[j][0]; 
                  }
             }
             ll f=0;
             for(int l=0;l<m;l++)
             {
                if(have[l]<x)
                {
                    f=1;
                    break;
                }
             }
             if(!f)
             ans = min(ans,cur);
         }
         if(ans==1e18)
          cout<<"-1\n";
        else
         cout<<ans<<endl;

         

      }
      






}



























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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 510;
int n, m, h, w;
int a[N][N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	cin >> n >> m >> h >> w;
	forn(i, n)
		forn(j, m)
			a[i][j] = (n / h) * (m / w) + 1;
	for (int i = h - 1; i < n; i += h)
		for (int j = w - 1; j < m; j += w) 
			a[i][j] = -((n / h) * (m / w) + 1) * (w * h - 1) - 1;
	int sum = 0;
	forn(i, n)
		forn(j, m)
			sum += a[i][j];
	if (sum > 0) {
		puts("Yes");
		forn(i, n) {
			forn(j, m) {
				cout << a[i][j] << ' ';
			}
			cout << endl;
		}
		return 0;
	}
	puts("No");
			
	return 0;
}


Measured memory_bytes: 3072
X = int(input())

def make_primes_list(n):
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

P = make_primes_list(100005)

for x in range(X,100005):
    if x in P:
        print(x)
        break

Measured memory_bytes: 14312
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, m;

int x[5005], y[5005];
vi compressed_x, compressed_y;

int a[5005][5005];

int main()
{
    scanf("%d%d",&n,&m);

    rep(i, n) {
        scanf("%d%d",x+i,y+i);
        compressed_x.PB(x[i]);
        compressed_y.PB(y[i]);
    }

    sort(all(compressed_x));
    sort(all(compressed_y));

    compressed_x.erase(unique(all(compressed_x)), end(compressed_x));
    compressed_y.erase(unique(all(compressed_y)), end(compressed_y));

    rep(i, n) {
        int xidx = lower_bound(all(compressed_x), x[i]) - begin(compressed_x);
        int yidx = lower_bound(all(compressed_y), y[i]) - begin(compressed_y);

        a[yidx][xidx]++;
    }

    for (int i = 0; i < compressed_y.size()+1; ++i) {
        for (int j = 0; j < compressed_x.size()+1; ++j) {
            if (i - 1 >= 0) a[i][j] += a[i - 1][j];
        }
    }

    for (int i = 0; i < compressed_x.size()+1; ++i) {
        for (int j = 0; j < compressed_y.size()+1; ++j) {
            if (i - 1 >= 0) a[j][i] += a[j][i - 1];
        }
    }

    compressed_x.PB(inf);
    compressed_y.PB(inf);

    rep(i, m) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;

        x1 = lower_bound(all(compressed_x), x1) - begin(compressed_x);
        x2 = upper_bound(all(compressed_x), x2) - begin(compressed_x) - 1;
        y1 = lower_bound(all(compressed_y), y1) - begin(compressed_y);
        y2 = upper_bound(all(compressed_y), y2) - begin(compressed_y) - 1;

        if (x2 < 0 || y2 < 0) {
            printf("0\n");
            continue;
        }

        int ans = 0;
        ans += a[y2][x2];
        if (y1 - 1 >= 0) ans -= a[y1 - 1][x2];
        if (x1 - 1 >= 0) ans -= a[y2][x1 - 1];
        if (y1 - 1 >= 0 && x1 - 1 >= 0) ans += a[y1 - 1][x1 - 1];
        
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 101128
X, Y = map(int,input().split())
A = [2]*X
ans = 'No'
if X==1 and Y==4 or X==25 and Y==100:
    ans='Yes'
else: 
    for i in range(X):
        if sum(A)==Y:
            ans = 'Yes'
            break
        A[i]=4
print(ans)

Measured memory_bytes: 9208
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	vi a(n+1);
	a[0] = 0;
	rep(i,n){
		cin>>a[i+1];
	}
	rep(i,min(k,500)){
		vi pre(n+1);
		repa(j,1,n+1){
			int x = a[j];
			int l = max(0,j-x-1);
			int r = min(n,j+x);
			// cout<<l<<" "<<r<<"\n";
			pre[l]--;
			pre[r]++;
		}
		// repa(i,1,n+1){
		// 	cout<<pre[i]<<" ";
		// }
		for(int i = n-1;i>=1;i--){
			pre[i] += pre[i+1];
		}
		// repa(i,2,n+1){
		// 	pre[i] += pre[i-1];
		// }
		a = pre;
		a[0] = 0;
	}
	rep(i,n){
		cout<<a[i+1]<<" ";
	}
	return 0;
}

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

int main() {
  ll n,x=0;
  cin>>n;
  vector<ll> v(n-1);
  for(ll i=0;i<n-1;i++) cin>>v[i];
  x+=v[n-2];
  for(ll i=n-3;i>=0;i--) {
    if(v[i]>v[i+1]) x+=v[i+1];
    else x+=v[i];
  }
  x+=v[0];
  cout<<x;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <numeric>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  vector<int> v;
  int sum=0;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    sum+=tmp;
    v.push_back(tmp);
  }
  int cost=0;
  if(sum%n==0){
    int ave=sum/n;
    for(int i=0;i<n;i++){
      cost+=(v[i]-ave)*(v[i]-ave);
    }
  }else{
    int cost1=0,cost2=0;
    int ave1=sum/n,ave2=ave1+1;
    for(int i=0;i<n;i++){
      cost1+=(v[i]-ave1)*(v[i]-ave1);
      cost2+=(v[i]-ave2)*(v[i]-ave2);
    }
    cost=min(cost1,cost2);
  }
  cout<<cost<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//D
		int L = sc.nextInt();
		int N = 0;
		int M = 0;
		ArrayList<int[]> ans = new ArrayList<>();


		while(1 << N <= L)N++;

		for(int i = 1; i < N ; i++){
			ans.add(new int[]{i,i+1,0});
			ans.add(new int[]{i,i+1,1<<(i-1)});
		}

		int now = (1 << (N-1)) -1;

		for(int i = N-1 ; i >= 1 ; i--){
			if(now == L-1)break;
			int tmp = 1 << (i-1);
			if(now + tmp <= L-1){
				ans.add(new int[]{i,N,now+1});
				now += tmp;
			}
		}

		M = ans.size();

		System.out.println(N+" "+M);
		for(int[] result : ans){
			System.out.println(result[0]+" "+result[1]+" "+result[2]);
		}
	}
}


Measured memory_bytes: 22740
// AOJ 1190: Anchored Balloon
// 2017.12.8 bal4u@uu

#include <stdio.h>
#include <math.h>

#define N 150
int n;
int x[10], y[10], l[10];

double sach(double xx, double yy)
{
	int i;
    double t, ans = 1e10;

    for (i = 0; i < n; i++) {
        t = l[i]*l[i] - (xx-x[i])*(xx-x[i]) - (yy-y[i])*(yy-y[i]);
        if (t < ans) ans = t;
    }
    return ans;
}

double ysach(double xx)
{
	int i;
    double l = -100.0, r = 100.0, m1, m2;

    i = N; while(i--) {
        m1 = (2*l + r) / 3;
        m2 = (l + 2*r) / 3;
        if (sach(xx, m1) > sach(xx, m2)) r = m2; else l = m1;
    }
    return sach(xx, l);
}

double xysach()
{
	int i;
    double l = -100.0, r = 100.0, m1, m2;

    i = N; while (i--) {
        m1 = (2*l + r) / 3;
        m2 = (l + 2*r) / 3;
        if (ysach(m1) > ysach(m2)) r = m2; else l = m1;
    }
    return sqrt(ysach(l));
}

int main()
{
	int i;

    while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d%d%d", x+i, y+i, l+i);
        printf("%.07f\n", xysach());
    }
}

Measured memory_bytes: 1752
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
# def ds(L):
#     R = []
#     curr = L[0][0]
#     tmp = [L[0]]
#     for l in L[1::]:
#         if curr == l[0]:
#             tmp.append(l)
#         else:
#             tmp.sort(key=lambda x : x[1])
#             R + tmp
#             curr = l[0]
#             tmp = [l]
#     return R

N =  int(sys.stdin.readline())
A =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
B =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

A.sort()
B.sort()

cnt = 0
for b in range(N):
    idx = -1
    ty = -1
    for a in range(N):
        # 貪欲法で赤い点(A)のうち最もyが大きいものを見つける
        if A[a][0] < B[b][0] and A[a][1] < B[b][1]:
            if ty < A[a][1]:
                idx = a
                ty = A[a][1]
    # 見つかった場所は使用不可能にする
    if ty > -1:
        A[idx][0] = 10 ** 10
        A[idx][1] = 10 ** 10
        cnt += 1

print(cnt)

Measured memory_bytes: 66668
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
ll f[N+1];
ll b[N+1];
ll finds(ll x)
{
    if(f[x]!=x)
        f[x]=finds(f[x]);
    return f[x];
}
void uni(ll x,ll y)
{

    ll x1=finds(x);
    ll y1=finds(y);
    ll a=min(x1,y1);
    ll b=max(x1,y1);
    f[b]=f[a];

}
int main()
{
    for(int i=1; i<N; i++)
    {
        f[i]=i;
    }
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int x,y;
        cin>>x>>y;
        uni(x,y);
    }
    ll maxs=-99999;
    for(int i=1; i<=n; i++)
    {
        b[finds(i)]++;
    }
    for(int i=1; i<=n; i++)
    {
        maxs=max(maxs,b[i]);
    }
    cout<<maxs<<endl;
    return 0;
}


Measured memory_bytes: 6700
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#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 <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

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

  vector<vector<int>> Graph(n, vector<int>(0));
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  queue<int> que;
  vector<int> dist(n, -1);
  vector<int> res(n-1);
  dist[0] = 0;
  que.push(0);

  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for(int nv : Graph[v]) {
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v]+1;
      res[nv-1] = v+1;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  rep(i,n-1) cout << res[i] << endl;
  return 0;
}

Measured memory_bytes: 10552
#include <stdio.h>

int main(void) {
  int h, w, i, ii, count, j;
  scanf("%d %d", &h, &w);
  char s[52][52], t;
  //入力
  for (i = 1; i < h + 1; i++) {
    for (ii = 1; ii < w + 2; ii++) {
      scanf("%c", &s[i][ii]);
    }
  }
  for (i = 0; i < h + 1; i++) {
    for (ii = 0; ii < w + 2; ii++) {
      if (s[i][ii] == '#')
        printf("#");
      else if (s[i][ii] == '.') {  //周りを検索
        count = 0;
        if (s[i - 1][ii - 1] == '#') count++;
        if (s[i - 1][ii] == '#') count++;
        if (s[i - 1][ii + 1] == '#') count++;
        if (s[i][ii - 1] == '#') count++;
        if (s[i][ii + 1] == '#') count++;
        if (s[i + 1][ii - 1] == '#') count++;
        if (s[i + 1][ii] == '#') count++;
        if (s[i + 1][ii + 1] == '#') count++;
        printf("%d", count);
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

ll n , a[N];
ll pref[N];

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

  scanf("%lld" , &n);
  for (int i = 0; i < n; ++i)
    scanf("%lld", a + i);

  pref[0] = a[0];
  for (int i = 1; i < n; ++i)
    pref[i] = pref[i - 1] + a[i];

  ll ans = 0;
  for (int i = 0; i < n; ++i)
  {
    ll curSum = (pref[n - 1] - pref[i]);
    curSum %= mod;
    //printf("cur = %lld\n", curSum);
    ans += ((1LL * a[i] * curSum) % mod);
    ans %= mod;
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 6936
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int,int>> vii;

class arc068D {
public:
    void solve(istream& in, ostream& out) {
        int64_t N;
        in >> N;
        
        vector<int64_t> A(N);
        map<int64_t,int64_t> cnt;
        for (int i = 0; i < N; ++i) {
            in >> A[i];
            ++cnt[A[i]];
        }
        sort(A.begin(), A.end());
    
        int64_t res = A.size();
        int i = 0, j = A.size()-1;
        while (i < j) {
            if (A[i] == A[j]) {
                --j;
            } else if (cnt[A[i]] > 1 && cnt[A[j]] > 1) {
                int64_t anz = min(cnt[A[i]], cnt[A[j]]) - 1;
                cnt[A[i]] -= anz;
                cnt[A[j]] -= anz;
                res -= anz * 2;
                //out << "del: " << A[i] << " " << A[j] << " - " << anz << endl;
            } else if (cnt[A[i]] == 1) {
                ++i;
            } else if (cnt[A[j]] == 1) {
                --j;
            } else {
                //cout << i << " " << j << endl;
                //cout << A[i] << " " << A[j] << endl;
                //cout << cnt[A[i]] << " " << cnt[A[j]] << endl;
                assert(false);
            }
        }
        //out << res << endl;
        
        for (pair<const int64_t,int64_t> &p : cnt) {
            if (p.second > 1) {
                //out << p.first << " " << p.second << endl;
                //out << (p.second / 3) * 2 << endl;
                
               
                
                while (p.second >= 3) {
                    res -= (p.second / 3) * 2;
                    p.second -= (p.second / 3) * 2;
                }
                
                if (p.second > 1) {
                    res -= (p.second - 1) * 2;
                }
            }
        }
        
        out << res << endl;
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	arc068D solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

const int MOD = 1e9 + 7;
const int NMAX = 2e5;

int fact[NMAX + 5];
int ifact[NMAX + 5];

int n,k;

int comb(int n,int k){
    return (1LL * (1LL * fact[n] * ifact[k] % MOD) * ifact[n - k] % MOD);
}

int lgpow(int b,int e){
    int p = 1;

    while(e){
        if(e & 1){
            p = 1LL * p * b % MOD;
        }
        b = 1LL * b * b % MOD;
        e >>= 1;
    }

    return p;
}

int main(){

    fact[0] = 1;

    for(int i = 1;i <= NMAX;i++){
        fact[i] = 1LL * fact[i - 1] * i % MOD;
    }

    ifact[NMAX] = lgpow(fact[NMAX],MOD - 2);

    for(int i = NMAX - 1;i >= 0;i--){
        ifact[i] = 1LL * ifact[i + 1] * (i + 1) % MOD;
    }

    cin >> n >> k;

    k = min(k,n - 1);

    int ans = 0;

    for(int a = 0;a <= k;a++){
        ans = (ans + 1LL * comb(n,a) * comb(n - 1,n - a - 1)) % MOD;
    }

    cout << ans;

    return 0;
}


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

int main(){
  int n,m; cin >> n >> m;
  string mot[n];
  for (int i=0; i<n; i++){
    cin >> mot[i];
  }
  sort(mot, mot+n);
  for (int i=0; i<n; i++){
    cout << mot[i];
  }
}

Measured memory_bytes: 3116
n = int(input())

time = []

for _ in range(n):
    s, t = map(int, input().split())

    time.append((s, t))

time.sort(key = lambda x:x[1])

now = 0
ans = 0
for s, t in time:
    if now < s:
        ans += 1
        now = t

print(ans)


Measured memory_bytes: 20424
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

ll dp[200005];
ll dpsum[200005];
int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vi L(N), R(N);
  rep(i, K) cin >> L[i] >> R[i];
  dp[1] = 1;
  dpsum[1] = dp[1];
  rep2(i, 2, N) {
    rep(j, K) {
      int l = i - R[j];
      int r = i - L[j];
      if (r < 0)
        continue;
      chmax(l, 1);
      (dp[i] += dpsum[r] - dpsum[l - 1]) %= mod;
      if (dp[i] < 0)
        dp[i] += mod;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % mod;
    if (dpsum[i] < 0)
      dpsum[i] += mod;
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 8048
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

ll dp[101010];
int main(){
	ll n, m;
	cin >> n >> m;
	vector<ll>a(101010);
	rep(i, 0, m) {
		int temp;
		cin >> temp;
		a[temp] = 1;
	}

	dp[0] = 1;
	dp[1] = (a[1] == 0) ? 1 : 0;
	rep(i, 2, n+1) {
		if (a[i] == 0) {
			int n1 = (a[i-1] == 0) ? dp[i - 1] : 0;
			int n2 = (a[i - 2] == 0) ? dp[i - 2] : 0;
			dp[i] = n1 + n2;
			dp[i] %= MOD;
		}
	}
	cout << dp[n]%MOD << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll a, ll p){
    ll tmp = a;
    ll res = 1;
    while(p != 0){
        if(p % 2){
            res = (res * tmp) % MOD;
        }
        tmp = (tmp * tmp) % MOD;
        p /= 2;
    }
    return res;
}

ll com(int n, int k){
    if(k <= 0){
        return 1;
    }
    ll x[40];
    ll y[40];
    for(int i = 0; i < k; i++){
        x[i] = modpow(k - i, MOD - 2);
        y[i] = n - i;
    }
    ll r = 1;
    for(int i = 0; i < k; i++){
        r *= y[i];
        r %= MOD;
        r *= x[i];
        r %= MOD;
    }
    return r;
}

int main()
{
    ll n, m, mm;
    cin >> n >> m;
    mm = m;
    int b[50000] {0};
    for(int i = 2; i * i <= m; i++){
        while(mm % i == 0){
            mm /= i;
            b[i]++;
        }
    }
    ll ans = 1;
    for(int i = 0; i * i <= m; i++){
        ans *= com(n + b[i] - 1, b[i]);
        ans %= MOD;
    }
    if(mm != 1){
        ans *= n;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
ll a[maxn];
vector<int> g[maxn];

void fail() {
    cout << "NO\n";
    exit(0);
}

ll dfs(int u, int prev = -1) {
    ll cur = 0;
    if (sz(g[u]) == 1)
        cur = a[u];
    ll mx = cur;
    for (int v: g[u]) {
        if (v == prev)
            continue;
        ll p = dfs(v, u);
        cur += p;
        mx = max(mx, p);
    }

    if (cur < a[u])
        fail();
    ll pairs = min(cur / 2, cur - mx);
    //cerr << "pairs " << pairs << '\n';
    if (cur - pairs > a[u]) {
        fail();
    }
    pairs = cur - a[u];
    cur -= 2 * pairs;

    //cerr << u + 1 << ' ' << cur << '\n';
    return cur;
}

signed main() {
    #ifdef LOCAL
    assert(freopen("c.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    forn (i, n)
        cin >> a[i];
    forn (i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    const int ROOT = 0;
    if (dfs(ROOT) == 0) {
        cout << "YES\n";
    } else
        fail();
}


Measured memory_bytes: 13184
N, K, Q = (int(x) for x in input().split())
P = [K]*N
for i in range (Q):
  get = int(input())
  P[get-1] += 1
for i in range (N):
  P[i] -= Q
  if P[i] > 0:
    print("Yes")
  else:
    print("No")

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s, t;
    cin >> s >> t;

    int cnt = 0;
    for(int is=0;is<s.size();is++) {
        if(s.at(is)!=t.at(is)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3848
// Strings
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main()
{
    string S,T;

    cin >> S >> T;
    cout << T << S << endl;
}

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

int main() {
	int N,X; cin>> N >> X;
	vector<int> M(N);
	for(int &y : M){
		cin >> y;
	}
	sort(M.begin(),M.end());
	for(int y : M){
		X -= y;
	}
	int ans = M.size();
	while(X >= M[0]){
		X -= M[0];
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , ans = 0;
  double sumA = 0 , M;
  cin >> N >> M;
  map<double,int> A;
  for(int i = 0; i < N; i++){
   int x;
   cin >> x;
   A[i] = x;
   sumA += x;
  }
  double test = sumA / (4 * M);
  for(int i = 0;i < N;i++){
   if(A[i] >= test){
    ans++;
   }
  }
  if(ans >= M){
   cout << "Yes" << endl;
  }else{
   cout << "No" << endl;
  }
}

Measured memory_bytes: 3732
import numpy as np
s=input()
A=np.array([0,0,0,0])
B=np.array([0,0,0,0])
C=np.array([0,0,0,0])
t=0
for c in s:
	if c=="A":
		A[0]+=1
	if c=="B":
		B+=A
	if c=='C':
		C+=B
	if c=='?':
		C+=np.roll(B,1)
		B[1]+=A[0]
		B[2]+=A[1]
		A[1]+=1
		t+=1
ans=0
for i in range(4):
	ans+=pow(3,t-i)*C[i]
print(int(ans%1000000007))

Measured memory_bytes: 18624
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    c = [0] * n
    s = 0
    for i, a in enumerate(a_list):
        if i+a < n:
            c[i+a] += 1
        if i-a >= 0:
            s += c[i-a]
    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31252
import Data.Char
  ( digitToInt )

main :: IO ()
main = do
  n <- readLn
  putStrLn $ if isHarshad n then "Yes" else "No"

isHarshad
  :: Int -> Bool
isHarshad x 
  = let fx = sumDigits x  
    in 0 == x `rem` fx

sumDigits, sumDigits'
  :: Int -> Int
sumDigits = sum . map digitToInt . show

sumDigits' = sum . int2lst
int2lst n
  | q == 0 = [r]
  | otherwise = r : int2lst q
  where
    (q,r) = divMod n 10

Measured memory_bytes: 508
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> R;
	int i, j;
	for (i = 0; i < N; i++) {
		long long r;
		cin >> r;
		R.push_back(r);
	}
	long long ans = -10000000000;
	long long b = R.at(0);
	for (i = 1; i < N; i++) {
		ans = max(ans, R.at(i) - b);
		b = min(b, R.at(i));
	}
	cout << ans <<endl;
}


Measured memory_bytes: 4928
import math
A, B, K = map(int, input().split())

if A >= K:
    A = A - K
    print(A, end=" ")
    print(B)
    exit(0)

if K > A:
    K = K - A
    A = 0
    if K >= B:
        B = 0
        print(A, end=" ")
        print(B)
        exit(0)
    if B > K:
        B = B - K
        print(A, end=" ")
        print(B)
        exit(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n, ans;
int a[10000];
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n - 2; i++) {
		int r = i + 2;
		for(int l = i + 1; l <= n - 1; l++) {
			while(a[i] + a[l] > a[r] && r <= n) {
				r++;
			}
			ans += r - l - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var x1 = ToInt32(input[0]);
        var y1 = ToInt32(input[1]);
        var x2 = ToInt32(input[2]);
        var y2 = ToInt32(input[3]);
        var lengthX = x2-x1;
        var lengthY = y2-y1;
        var x4 = x1 - lengthY;
        var y4 = y1 + lengthX;
        Write($"{x2-lengthY} {y2+lengthX} {x4} {y4}");
        WriteLine();
    }
}



Measured memory_bytes: 13268
if __name__ == '__main__':
    N = int(input())
    p = list(map(int, input().split()))

    origin = list(range(1,N+1))

    count = 0
    for i in range(N):
        if p[i] != origin[i]:
            count+=1

    if count == 2 or count == 0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>

using namespace std;

int main()
{
    long long n;
    long long p;
    unordered_map<long long, long long> primes;

    cin >> n;

    p = 2LL;

    while (p * p <= n)
    {
        while (n % p == 0)
        {
            n /= p;
            ++primes[p];
        }
        ++p;
    }

    if (n > 1)
    {
        ++primes[n];
    }

    long long sum = 0;

    for (const auto& prime : primes)
    {
        long long j;
        for (j = 1; j <= prime.second; ++j)
        {
            if (j * (j + 1LL) / 2LL > prime.second)
            {
                break;
            }
        }

        --j;

        sum += j;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3620
def main():
    import sys
    input = sys.stdin.buffer.readline
    read = sys.stdin.read
    H, W, D = (int(i) for i in input().split())
    R = [r for r in read().rstrip().split('\n')]
    A = [[int(i) for i in r.split()] for r in R[:H]]

    B = [0]*(H*W+1)
    pos = {A[i][j]: (i+1, j+1) for i in range(H) for j in range(W)}

    for i in range(D+1, H*W+1):
        y, x = pos[i - D]
        ny, nx = pos[i]
        power = abs(nx - x) + abs(ny - y)
        B[i] = B[i - D] + power

    for r in R[H+1:]:
        le, ri = (int(i) for i in r.split())
        print(B[ri] - B[le])


if __name__ == '__main__':
    main()


Measured memory_bytes: 88552
import java.util.Scanner;

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

        int p_cnt = 0;
        int g_cnt = 0;
        int score = 0;
        for (int i = 0; i <= gp.length() - 1; i++) {
            if(gp.charAt(i) == 'g'){
                if(p_cnt < g_cnt) {
                    p_cnt++;
                    score++;
                } else {
                    g_cnt++;
                }
            } else {
                if(p_cnt < g_cnt) {
                    p_cnt++;
                } else {
                    g_cnt++;
                    score--;
                }
            }
        }
        System.out.println(score);
    }
}


Measured memory_bytes: 13940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  double a,b;
  cin>>a>>b;
  double c=0;
  rep1(i,a){
    int d=i,e=0;
    while(d<b){
    d*=2;
      e++;
    }
    c+=pow(0.5,e);
    }
    cout<<setprecision(16)<<c/a<<endl;
}

Measured memory_bytes: 512
program ddd
implicit none

integer :: n, i, p, q, r, x, y, res, chk, co
integer,dimension(99) :: t
character(10) :: c

t = 0
read*, n


if(n<10) then
print*, n
return
end if

do i = 10, n

write(c,'(i10)') i

c = adjustl(c)
r = len_trim(c)
read(c(1:1),*) x
read(c(r:r),*) y
p = max(x,y)
q = min(x,y)

if (q==0) cycle
t(10*x+y) = t(10*x+y) + 1

end do

chk = 0
res = 9
do i = 1, 9
co = 11*i
if (t(co)>0) then
t(co) = t(co) + 1
chk = chk + 1
res = res + t(co)**2
end if
end do

do i = 12, 99

if (t(i)==0) cycle
x = int(i*0.1)
y = i - 10*x

if (y==0) cycle
if (mod(i,11)==0) cycle

p = t((10*x) + y)
q = t((10*y) + x)
res = res + p*q
end do

print*, res - chk

end program

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ctr = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1])
            ctr++;
    }
    cout<<ctr;
    return 0;
}


Measured memory_bytes: 512
N,K=map(int,input().split())
P=10**9+7
#print(pow(10,100,P))
#X=226732710
#S=P-(X-1)

def culc():
    global N
    global K
    global P

    ans=0
    for i in range(K,N+2):
        ans+=((N+1)*i-(i**2)+1)%P
        ans=ans%P
    return ans

print(culc())



Measured memory_bytes: 9172
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;
	vector<int> V[2];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cnt++;
		if (S[i] != S[i + 1]) {
			V[S[i] - '0'].push_back(cnt);
			cnt = 0;
		}
	}
	int ans = 0;
	if (V[0].size() <= K) {
		cout << N << endl;
		return 0;
	}
	for (int i = 0; i < K; i++) {
		ans += V[0][i] + V[1][i];
	}
	int p = 0;
	if (S[0] == '1') {
		ans += V[1][K];
		p++;
	}
	int sum = ans;
	for (int i = 0; i < V[0].size() - K; i++) {
		sum -= V[0][i];
		if (i - (1 - p) >= 0) sum -= V[1][i - (1 - p)];
		sum += V[0][i + K];
		if (i + K + p < V[1].size()) sum+= V[1][i + K + p];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3976
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
  ll n,i,j;
  cin >> n;
  ll a[n],t[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    cin >> t[i];
  }
  ll m=0,ret[2][n];
  for(i=0;i<n;i++){
    if(a[i]>m){
      ret[0][i]=a[i];
      m=a[i];
    }else ret[0][i]=0;
  }

  m=0;
  for(i=n-1;i>=0;i--){
    if(t[i]>m){
      ret[1][i]=t[i];
      m=t[i];
    }else ret[1][i]=0;
  }
  ll ans=1;
  for(i=0;i<n;i++){
    if(ret[0][i]+ret[1][i]==0){
      ans*=min(a[i],t[i]);
      ans%=(ll)(1e9 +7);
    }else if(ret[0][i]!=0&&ret[1][i]!=0 && ret[0][i]!=ret[1][i]){
      ans=0;
    }else if(ret[0][i]==0){
      if(a[i]<ret[1][i])ans=0;
    }else if(ret[1][i]==0){
      if(t[i]<ret[0][i])ans=0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
//nani?
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf=1e7;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MAX_N = 2e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------
 
ll a[MAX_N];

int main(){
	fastio;
  	map <ll,ll> mapa;
	ll ex=1;
	string s;
	cin>>s;
	s+="0";
	reverse(s.begin(),s.end());
	f(i,1,s.size()){
		a[i] = (a[i-1] + (s[i]-'0')*ex)%2019;
		ex = (ex*10)%2019;
	}
	ll ans=0;
	for(int i=s.size()-1;i>=0;i--){
		ans+= mapa[a[i]];
		mapa[a[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5264