akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 500
#define MAX_M 200'000
#define MAX_Q 100'000
i64 N, M, Q;
i64 LR[MAX_N + 1][MAX_N + 1];

int main() {
    cin >> N >> M >> Q;

    REP(i, N + 1)REP(j, N + 1) LR[i][j] = 0;

    i64 l, r;
    REP(i, M) {
        cin >> l >> r;
        LR[l][r] += 1;
    }

    vector<vector<i64> > d(N + 1, vector<i64>(N + 1, 0));
    REP(i, N) {
        REP(j, N) {
            d[i + 1][j + 1] = d[i + 1][j] + d[i][j + 1] - d[i][j] + LR[i + 1][j + 1];
        }
    }

    i64 p, q;
    REP(i, Q) {
        cin >> p >> q;
        i64 res = d[q][q] - d[p - 1][q] - d[q][p - 1] + d[p - 1][p - 1];
        cout << res << endl;
    }


    return 0;
}

Measured memory_bytes: 4864
H, W, D = gets.split.map(&:to_i)
A = H.times.map{gets.split.map(&:to_i)}
Q = gets.to_i
LR = Q.times.map{gets.split.map(&:to_i)}

a = Array.new(H * W)
c = Array.new(H * W, 0)
H.times{|y| W.times{|x| a[A[y][x] - 1] = [y, x] }}
D.times{|i| 
    k = i + D
    while k < c.length 
        c[k] = c[k-D] + (a[k][0] - a[k-D][0]).abs + (a[k][1] - a[k-D][1]).abs
        k += D
    end
}
LR.each{|k| puts c[k[1]-1] - c[k[0]-1] }

Measured memory_bytes: 18300
import numpy as np
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
y1=a1*t1-b1*t1
y2=a2*t2-b2*t2
if y1 == -y2:
    print('infinity')
else:
    if y1<0:
        y1*=-1
        y2*=-1
    n=int(np.trunc(y2/(y1+y2)))
    if n<1:
        print(0)
    elif(y2/(y1+y2)==n):
        print((n-1)*2)
    else:
        print((n-1)*2+1)

Measured memory_bytes: 12504
n = int(input())
s,t = [str(x) for x in input().split(' ')]
s,t = list(s),list(t)
ans = ""
for i in range(2*n):
	if i%2 == 0:
		ans += s[i//2]
	else :
		ans += t[i//2]
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int i,n,ans,move,min=1000,max;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d ",&ans);
        if(max<ans)max=ans;
        if(min>ans)min=ans;
    }
    printf("%d\n",max-min);
    return 0;
}

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

/* #define MULTI_INPUT 0 */

void solve()
{
    int n;
    cin >> n;
    ll x, y;
    ll maxXpY = INT_MIN, minXpY = INT_MAX, maxXsY = INT_MIN, minXsY = INT_MAX;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        maxXpY = max(maxXpY, x + y);
        minXpY = min(minXpY, x + y);
        maxXsY = max(maxXsY, x - y);
        minXsY = min(minXsY, x - y);
    }
    cout << max(maxXpY - minXpY, maxXsY - minXsY) << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef MULTI_INPUT
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        solve();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const ll mod = 1000000007;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

ll f(ll a, ll b){
  ll ca = 0, cb = 0;
  while(a > 0){
    a /= 10;
    ca++;
  }
  while(b > 0){
    b /= 10;
    cb++;
  }
  return max(ca, cb);
}

int main(){
  ll n;
  cin >> n;
  vector<ll> div = divisor(n);

  ll ans = 1000;
  rep(i, div.size()){
    for(ll j = i; j < div.size(); ++j){
      ll mul = div[i] * div[j];
      if(mul > n) break;
      else if (mul != n)  continue;
      ll res = f(div[i], div[j]);
      ans = min(ans, res);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string S; cin >> S;
    
    //Sが回文
    for (int i=0; i<S.length()/2; i++){
        if (S[i]!=S[S.length()-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    //
    for (int i=0; i<S.length()/2-1; i++){
        if (S[i]!=S[S.length()/2-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    for (int i=S.length()/2+1; i<=S.length()-1; i++){
        if (S[i]!=S[S.length()-1-i]){
            cout << "No" << endl;
        }
    }
    cout << "Yes" << endl;
    return 0;
    
}

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

void init() {
  cin.tie(nullptr); // cin 時に cout を flush しない
  // cout << "hogehoge" << '\n';  // endl は改行後に flush するので、改行のみとする
  // ios::sync_with_stdio(false); // cin/cout と scanf/printf が混在する場合は注意
}

int main() {
  init();

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll ans = -1e9 * 1e9;
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>

struct Point { double x, y; };

void koch( int n, Point a, Point b) {
  if ( n == 0 ) return;
  Point a1, b1, ab;
  double th = M_PI * 60.0 / 180.0;
  
  a1.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  a1.y = (2.0 * a.y + 1.0 * b.y) / 3.0;

  b1.x = (1.0 * a.x + b.x * 2.0) / 3.0;
  b1.y = (1.0 * a.y + b.y * 2.0) / 3.0;
  
  ab.x = (b1.x - a1.x) * cos(th) - (b1.y - a1.y) * sin(th) + a1.x;
  ab.y = (b1.x - a1.x) * sin(th) + (b1.y - a1.y) * cos(th) + a1.y;

  koch( n - 1, a, a1);
  printf("%.8f %.8f\n", a1.x, a1.y);
  koch( n - 1, a1, ab);
  printf("%.8f %.8f\n", ab.x, ab.y);
  koch( n - 1, ab, b1);
  printf("%.8f %.8f\n", b1.x, b1.y);
  koch( n - 1, b1, b);
}

int main() {
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}


Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    string s;
    int n;
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
        char q = 'A'+((s[i]-'A')+n)%26;
        cout<<q;


    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, m;
  cin >> n >> m;
  int time = 1900 * m + 100 * (n - m);
  double x = 1;
  rep(i, m) x /= 2;
  double y = 1 - x;
  int log = 1;
  rep(i, m) log *= 2;
  out(time * log);
}
int main(void) { solve(); }


Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		int N = Integer.parseInt(line);
		String[] str = reader.readLine().split("");
		int white = 0;
		int black = 0;
		for (int j = 0; j < N; j++) {
			if (str[j].equals(".")) {
				white++;
			}
		}
		int ans = Math.min(white, N-white);   //白と黒のうち小さいほう以下
		int ans_j = 0;
		for (int j = 0; j < N; j++) {
			if (str[j].equals("#")) {
				black++;
			}
			if (str[j].equals(".")) {
				white--;
			}
			ans_j = black + white;
			if (ans > ans_j) {
				ans = ans_j;
			}
		}
		System.out.println(ans);
	}
}

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

int main() {
    string str;
    int m;
    int h[100];
    
    while (1) {
        cin >> str;
        if (str == "-") {
            return 0;
        }
        cin >> m;
        for (int i = 0; i < m; i++) {
            cin >> h[i];
        }
        
        for (int i = 0; i < m; i++) {
            str.insert(str.size(), str.substr(0, h[i]));
            str.erase(0, h[i]);
        }
        
        cout << str << endl;
    }
}


Measured memory_bytes: 3204
import Data.List

main = do
  n <- readLn :: IO Int
  as <- getLine >>= return . map (\x -> (head x, length x)) . group . sort . zipWith (flip (-)) [1..] . map read . words :: IO [(Int, Int)]

  let
    solve list@(x:xs) = t : solve' (scanl1 (\(x1,y1) (x2,y2) -> (x2, y1+y2)) list) t
      where t =  sum $ map (\y -> abs ((fst y - fst x) * (snd y))) xs
    solve' (_:[]) _ = []
    solve' ((x1,y1):(x2,y2):rest) s = t : (solve' ((x2,y2):rest) t)
      where t = s + (x2-x1) * (y1-(n-y1))

  print $ minimum $ solve as


Measured memory_bytes: 73724
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
name_count = [0 for _ in range(5)]
for i in s:
    if i[0] == "M":
        name_count[0] += 1
    elif i[0] == "A":
        name_count[1] += 1
    elif i[0] == "R":
        name_count[2] += 1
    elif i[0] == "C":
        name_count[3] += 1
    elif i[0] == "H":
        name_count[4] += 1

result = 0
for s in range(3):
    for t in range(s+1, 4):
        for u in range(t+1, 5):
            result += name_count[s]*name_count[t]*name_count[u]
print(result)

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

using namespace std;

namespace dsu {
	int p[4];
	
	void init(int n) {
		iota(p, p + n, 0);
	}
	
	int get(int v) {
		if (p[v] != v) p[v] = get(p[v]);
		return p[v];
	}
	
	bool merge(int u, int v) {
		u = get(u);
		v = get(v);
		p[u] = v;
		return u != v;
	}
}

int deg[4];

int main() {
	dsu::init(4);
	
	for (int i = 0, u, v; i < 3; i++) {
		ignore = scanf("%d %d", &u, &v);
		u--;
		v--;
		dsu::merge(u, v);
		deg[u]++;
		deg[v]++;
	}
	
	sort(deg, deg + 4);
	
	for (int i = 0; i < 4; i++)
		if (deg[i] != 1 + i / 2 || dsu::get(i) != dsu::get(0)) {
			printf("%s\n", "NO");
			return 0;
		}
	
	printf("%s\n", "YES");
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;

int main()
{
	int ans = 0;
	int pos[10][10], dis[1000] = {};
	int n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
		{
			cin >> pos[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			int sum = 0;
			for (int k = 0; k < d; k++)
			{
				int dis1 = abs(pos[i][k] - pos[j][k]);
				sum += dis1 * dis1;
			}
			bool flag = 0;
			for (int k = 0; k <= sum; k++)
			{
				if (k*k == sum)
				{
					flag = 1;
				}
			}
			if (flag)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

bool G[50][50];
bool seen[50];

int n,m;

void dfs(int v){
  seen[v] = true;
  rep(nv, n){
    if(seen[nv] || !G[v][nv]) continue;
    dfs(nv);
  }
}

int main(){
  cin >> n >> m;
  vi a(m), b(m);
  rep(i, m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]][b[i]] = G[b[i]][a[i]] = true;
  }

  int ans = 0;
  rep(i, m){
    G[a[i]][b[i]] = G[b[i]][a[i]] = false;
    rep(v, n) seen[v] = false;
    dfs(0);

    bool bridge = false;
    rep(v, n) if(!seen[v]) bridge = true;
    if(bridge) ans++;

    G[a[i]][b[i]] = G[b[i]][a[i]] = true;
  }

  std::cout << ans << '\n';
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  string s; cin >> s;
  s[3] += 1;
  cout << s << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[maxn];

int32_t main(){
	fastio();
	int n,x;
	cin>>x>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		cnt[a]++;
	}
	int ans;
	int diff = mod;
	for(int i=-maxn;i<=maxn;i++){
		int k = abs(i-x);
		if(i<0){
			if(k<diff) diff = k,ans = i;
		}
		if(i>=0 and !cnt[i]){
			if(k<diff) diff = k, ans  = i;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3580
(_,K),*T=[map(int,t.split())for t in open(0)]
A,B=map(sorted,T)
d=[0,2**40]
exec("i=sum(d)//2;d[-sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K]=i;"*41)
print(d[1])

Measured memory_bytes: 123296
s = input()

alp = [0]*26
a_int = ord('a')

ans = -1
cand = []
if len(s) == 26:
    for i in reversed(range(1, 26)):
        if s[i] < s[i-1]:
            cand.append(s[i])
            continue
        else:
            cand.append(s[i])
            cand = sorted(cand, reverse=True)
            c = min(list(filter(lambda x: x > s[i-1], cand)))
            ans = s[0:i-1]+c
            break

else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    long long int x;
    int i = 0;
    long long int money = 100;
    scanf("%lld",&x);
    while(1){
        i++;
        money = money*1.01;
        if(x <= money){
            printf("%d",i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
int const nax = 3000 + 4, mod = 998244353;

void plusle (int &a, int b) {
    if (( a += b) >= mod ) a -= mod ;
}
void minun (int &a, int b) {
    if ((a -= b) < 0) a += mod ;
}
int add (int a, int b) {
    return (( a += b ) >= mod ) ? a - mod  : a;
}
int sub (int a, int b) {
    return (( a -= b) < 0) ? a + mod : a;
}
int mul (int a, int b) {
    return 1LL * a * b % mod;
}
int power (int a, int b) {
    int res = 1;
    for (; b > 0 ; b >>= 1 , a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res ;
}


const int Mx = nax + 10;
int fac[Mx], invf[Mx] ;
void prefact () {
    fac[0] = 1 ;
    for (int i = 1 ; i < Mx ; i ++) {
        fac[i] = mul(fac[i - 1], i);
    }
    invf[Mx - 1] = power (fac[Mx - 1] ,  mod - 2 );
    for (int i = Mx - 2 ; i >= 0 ; i --) {
        invf[i] = mul(invf[i + 1], i + 1);
    }
}

int ncr (int N, int R) {
    if (R > N) return 0;
    if (R == 0 || R == N) return 1;
    return mul (fac[N], mul(invf[N - R], invf[R]));
}

int dp[nax][nax];
int a, b, c, d;

int main () {

    prefact();
    scanf("%d %d %d %d", &a, &b, &c, &d);

    int x = c - a;
    int y = d - b;

    dp[0][0] = 1;

    for (int i = 0 ; i <= x ; ++ i)
    for (int j = 0 ; j <= y ; ++ j) {
        if (i + j == 0) continue;
        if (i > 0) {
            plusle(dp[i][j], mul(dp[i - 1][j], b + j));
        }
        if (j > 0) {
            plusle(dp[i][j], mul(dp[i][j - 1], a + i));
        }

        if (i > 0 && j > 0) {
            int valid = mul(a + i - 1, b + j - 1);
            minun(dp[i][j], mul(valid, dp[i - 1][j - 1]));
        }
    }

    printf("%d\n", dp[x][y]);
}
/*
    Good Luck
        -Lucina
*/


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

namespace AGC10_A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            IEnumerable<int> a = Console.ReadLine().Split().Select(int.Parse);
            int oddCount = a.Count(x => x % 2 == 1);
            Console.WriteLine(oddCount % 2 == 0 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 20192
chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my %h;
$h{$_}++ for @a;
my $ans = 0;
for $_ (keys %h) {
  if ($h{$_} > $_) {
    $ans += $h{$_} - $_;
  } elsif ($h{$_} < $_) {
    $ans += $h{$_};
  }
}
print "$ans\n";

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int n; cin >> n;
	vector<int> v(n + 1);
	rep(i, 1, n + 1) cin >> v[i];
	int cnt = 0;
	rep(i, 1, n + 1) if (v[v[i]] == i) cnt++;
	cout << cnt/2 << endl;
}



Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int l = 0, r = N-1;
  while(S[l] == '<') ++l;
  while(S[r] == '>') --r;
  cout << N - min(l,N-1-r) << endl;
  return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
 
using namespace std;
  
bool c(int x)
{
    int e = x % 10; x /= 10;
    while (x > 0) {
        if (x % 10 + 1 != e) {
            return 0;
        }
        e = x % 10;
        x /= 10;
    }
    return 1;
}
 
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
     
    int res = -1;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int b = a[i] * a[j];
            if (c(b) && res < b) res = b;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3120
#include <stdio.h>

const int NMAX = 2005;

char S[NMAX][NMAX];
int R[2][NMAX][NMAX];
int JS[2][NMAX][NMAX], ST[2][NMAX][NMAX];

int main(){
	
	//freopen("file", "r", stdin);
	
	int N, M, Q;	scanf("%d %d %d", &N, &M, &Q);
	
	for(int i = 1; i <= N; ++i){
		scanf("%s", (S[i] + 1));
	}
	
	for(int i = 1; i <= N; ++i){
		for(int j = 1; j <= M; ++j){
			for(int k = 0; k < 2; ++k){
				R[k][i][j] = R[k][i - 1][j] + R[k][i][j - 1] - R[k][i - 1][j - 1];
			}
			
			if(S[i][j] == '1'){
				R[0][i][j] += 1;
				R[1][i][j] += (S[i - 1][j] == '1' ? 1 : 0) + (S[i][j - 1] == '1' ? 1 : 0);
			}			
		}
	}
	
	for(int i = 1; i <= N; ++i){
		for(int j = 1; j <= M; ++j){
			JS[0][i][j] = JS[0][i][j - 1];
			JS[1][i][j] = JS[1][i][j - 1];
			
			if(S[i][j] == '1'){
				JS[0][i][j] += (S[i + 1][j] == '1' ? 1 : 0);
				JS[1][i][j] += (S[i - 1][j] == '1' ? 1 : 0);
			}
		}
	}
	
	for(int j = 1; j <= M; ++j){
		for(int i = 1; i <= N; ++i){
			ST[0][i][j] = ST[0][i - 1][j];
			ST[1][i][j] = ST[1][i - 1][j];
			
			if(S[i][j] == '1'){
				ST[0][i][j] += (S[i][j - 1] == '1' ? 1 : 0);
				ST[1][i][j] += (S[i][j + 1] == '1' ? 1 : 0);
			}
		}
	}
	
	
	
	
	
	for(; Q > 0; --Q){
		
		int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		
		int vr = R[0][x2][y2] - R[0][x1 - 1][y2] - R[0][x2][y1 - 1] + R[0][x1 - 1][y1 - 1];
		int mu = R[1][x2][y2] - R[1][x1 - 1][y2] - R[1][x2][y1 - 1] + R[1][x1 - 1][y1 - 1];
		
		int a = (JS[1][x1][y2] - JS[1][x1][y1 - 1]);
			//(JS[0][x2][y2] - JS[0][x2][y1 - 1])
		int b = (ST[0][x2][y1] - ST[0][x1 - 1][y1]);
			//(ST[1][x2][y2] - ST[1][x1 - 1][y2]);

		mu -= a + b;
		
		printf("%d\n", vr - mu);
	}
	
return 0;	
}


Measured memory_bytes: 99840
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
bool kaibun(int x) {
	int a[5];
	rep(i, 5) {
		a[i] = x % 10; x /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3])return true;
	else return false;
}
int main() {
	int a, b; cin >> a >> b; int cnt = 0;
	Rep1(i, a, b) {
		if (kaibun(i))cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    Map<Character, Integer> cmap = new HashMap<>(); 
    for (char c = 'a'; c <= 'z'; c++) {
        cmap.put(c, 0);
    }
    
    StringBuffer sb = new StringBuffer();
    while (sc.hasNext()) {
        sb.append(sc.nextLine());
    }

    char[] cs = sb.toString().toLowerCase().toCharArray();
    for (char c : cs) {
        if (Character.isAlphabetic(c)) {
            cmap.put(c, cmap.get(c) + 1);
        }
    }

    for (char c = 'a'; c <= 'z'; c++) {
        pw.println(c + " : " + cmap.get(c));
    }

    pw.flush();
  }
}


Measured memory_bytes: 26096
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[3 * N];

        for (int i = 0; i < 3 * N; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        long sum = 0;
        for (int i = 3 * N - 1; i >= N; i -= 2) {
            sum += a[i - 1];
        }

        System.out.println(sum);
        
        return;
    }

}

Measured memory_bytes: 93972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define int long long
string s;
ll w2[150005];
ll b[300005],r[300005];
int cnt;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
signed main(){
	b[0] = 1;
	for(int i=1;i<300005;i++) b[i] = b[i-1]*2LL%mod;
	for(int i=0;i<300005;i++) r[i] = modpow(b[i],mod-2);
	cin>>s;
	//reverse(s.begin(),s.end());
	int n = s.size();
	rep(i,n) cnt += (s[i]=='?');
	bool en = 0;
	ll pre = 1;
	if(s[n-1]=='0'){
		w2[(n-1)/2] = 0;
	}
	else if(s[n-1] == '1'){
		w2[(n-1)/2] = b[cnt];
		en = 1;
	}
	else{
		w2[(n-1)/2] = b[cnt-1];
		cnt--;
	}
	for(int i=(n-3)/2;i>=0&&!en;i--){
		if(s[i*2]=='0' || s[i*2+1]=='0'){
		    if(s[i*2]=='?') {cnt--;pre=pre*2LL%mod;}
		    if(s[i*2+1]=='?'){cnt--;pre=pre*2LL%mod;}
			w2[i] = 0;
		}
		else if(s[i*2] == '1' && s[i*2+1] == '1'){
			w2[i] = b[cnt]*pre%mod;
			en = 1; pre = 0;
			break;
		}
		else if(s[i*2] == '1' && s[i*2+1] == '?'){
			w2[i] = b[cnt-1]*pre%mod;
			cnt--;
		}
		else if(s[i*2+1] == '1' && s[i*2] == '?'){
			w2[i] = b[cnt-1]*pre%mod;
			cnt--;
		}
		else{
			w2[i] = b[cnt-2]*pre%mod;
			cnt-=2;
			pre=pre*3ll%mod;
		}
		//cout<<w2[i]<<" "<<i<<endl;
	}
	//cout<<w2[0]<<" "<<w2[1]<<" "<<w2[2]<<" "<<w2[3]<<" "<<cnt<<" "<<pre<<endl;
	pre = 1LL;
	cnt = 0;
	rep(i,n) cnt += (s[i]=='?');
	int C = 0;
	ll ans = 0;
	ll cur = 0;
	for(int i=0;i<150005;i++) cur = (cur+w2[i])%mod;
	if(s[0] == '0'){
	}
	else if(s[0] == '1'){
		ans += cur;
		en = 1; pre = 0;
		cout<<(ans%mod+mod)%mod<<endl; return 0;
	}
	else{
		ans += (cur-w2[0]) * r[1] % mod;
		ans += w2[0];
		C++;
	}
	cur = (cur+mod-w2[0])%mod;
	for(int i=1;i<=(n-1)/2;i++){
		if(s[i*2-1]=='0' || s[i*2]=='0'){
		    if(s[i*2-1]=='?'){C++;pre=pre*2LL%mod;}
		    if(s[i*2]=='?'){C++;pre=pre*2LL%mod;}
		}
		else if(s[i*2-1] == '1' && s[i*2] == '1'){
			ans += cur * r[C]%mod*pre%mod;
			en = 1; pre = 0;
		}
		else if(s[i*2-1] == '1' && s[i*2] == '?'){
			ans += (cur-w2[i]) * r[C+1]%mod*pre%mod;
			ans += w2[i] * r[C]%mod*pre%mod;
			C++;
		}
		else if(s[i*2] == '1' && s[i*2-1] == '?'){
			ans += (cur) * r[C+1]%mod*pre%mod;
			C++;
		}
		else{
			ans += (cur-w2[i])*r[C+2]%mod*pre%mod;
			ans += w2[i] * r[C+1]%mod*pre%mod;
			C+=2;
			pre=pre*3%mod;
		}
		cur = (cur+mod-w2[i])%mod;
	}
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 6532
n=int(input())
a,b=[],[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
a.sort()
b.sort(reverse=True)
ans=0
if n%2==1:
    s=a[n//2]
    g=b[n//2]
    ans=g-s+1
else:
    s1,s2=a[n//2-1],a[n//2]
    g2,g1=b[n//2-1],b[n//2]
    ans=(g2+g1)-(s2+s1)+1
print(ans)

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

int main(){
  long long n;cin >> n;
  long long ans = 0;
  for(long long i=1;i<=n;i++){
    if(i == n){
      cout << ans << endl;
      return 0;
    } else {
      ans += i;
    }
  }
  return 0;
}


Measured memory_bytes: 256
s=str(input())
k=int(input())
li=[1]
ans=0
if len(set(s))==1:
    print(len(s)*k//2)
    exit()
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        li[-1]+=1
    else:
        li.append(1)

for j in range(len(li)):
    ans+=int(li[j]//2)*k

if s[0]==s[-1] and li[0]%2==li[-1]%2==1:
    ans+=k-1

print(ans)          
            
    

Measured memory_bytes: 3064
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//入力データを変数で受け取る
		int n = sc.nextInt();

		Set<Integer> set = new HashSet<>();

		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if(set.contains(num)) {
				set.remove(num);
			} else {
				set.add(num);
			}
		}

		System.out.println(set.size());
		//入力データを処理して、結果を出力


	}
}


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

#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> pii;

int par[100001];
int we[100001];
int rnk[100001];

pii getW(int x) {
	if(x == par[x]) return pii(x,0);
	pii res = getW(par[x]);
	par[x] = res.first;
	we[x] += res.second;
	return pii(par[x], we[x]);
}

int find(int x) {
	return getW(x).first;
}

void uni(int x, int y, int w) {
	int a = find(x);
	int b = find(y);
	if(a == b) return;
	if(rnk[a] > rnk[b]) {
		par[b] = a;
		we[b] = w - we[y] + we[x];
	} else {
		par[a] = b;
		we[a] = -(w - we[y] + we[x]);
		if(rnk[a] == rnk[b]) rnk[b]++;
	}
}


int main() {
	int n, m;
	while(cin >> n >> m, n and m) {
		rep(i,n+1) {par[i] = i; we[i] = 0; rnk[i]=1;}
		rep(i, m) {
			char c;
			int x, y;
			x--; y--;
			cin >> c >> x >> y;
			if(c == '!') {
				int w;
				cin >> w;
				uni(x, y, w);
			} else {
				int a = find(x), b = find(y);
				if(a != b) cout << "UNKNOWN" << endl;
				else cout << we[y] - we[x] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2336
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

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

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int n, m;
int a[114514], b[114514];
int ans[114514];
signed main() {
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
	}
	ans[0] = n * (n - 1) / 2;
	for (int i = m - 1; i >= 1; i--) {
		if (uf.same(a[i], b[i]))ans[m - i] = ans[m - i - 1];
		else {
			int ai = uf.getsize(a[i]);
			int bi = uf.getsize(b[i]);
			ans[m - i] = ans[m - i - 1] - ai * bi;
		}
		uf.unite(a[i], b[i]);
	}
	for (int i = m - 1; i >= 0; i--)cout << ans[i] << endl;
	ggr
}

Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    vector < pair<int, ll> > co;
    ll X, Y, A, B, C, p, u;
    cin>>X>>Y>>A>>B>>C;
    u=X+Y;
    rep(i, A) {cin>>p; co.push_back({p, 0});}
    rep(i, B) {cin>>p; co.push_back({p, 1});}
    rep(i, C) {cin>>p; co.push_back({p, 2});}
    sort(all(co));
    ll count=0, selec=0;
    rep(i, A+B+C){
        ll th=A+B+C-i-1;
        if(co[th].second==0 && X>0){
            selec++;
            count+=co[th].first;
            X--;
        }
        else if(co[th].second==1 && Y>0){
            selec++;
            count+=co[th].first;
            //cout<<co[th].first<<endl;
            Y--;
        } else if(co[th].second==2){
            count+=co[th].first;
            
            selec++;
        }
        //cout<<selec<<sp<<count<<sp<<X<<sp<<Y<<endl;
        if(selec==u) break;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll i;
    bool is_unfair = false;

   if (k % 2 == 1) {
       cout << b - a << endl;
   }
   else
   {
       cout << a - b << endl;
   }
   

    return 0;
}

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

int main(){
    int a,b;
    cin >> a>>b;
    int ans = 1;
    if(b ==1)cout << 0;
    else{
    int k = a;
    while(true){
        if(a>=b)break;
        int temp = k;
        a+=temp-1;
        ans++;    
    }
    cout << ans;
    }
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7

ans = 0
for i in range(n-1):
    count=0
    for j in range(i+1, n):
        if A[i]>A[j]:
            count+=1
    ans = (ans + (count*((k*(k+1))//2)%mod))%mod

for i in range(n-1):
    count=0
    for j in range(i+1, n):
        if A[i]<A[j]:
            count+=1
    ans = (ans + (count*((k*(k-1))//2)%mod))%mod
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    cout << n*800 - n/15 * 200 << endl;
    return 0;
}

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

int main()
{
  int n,x;
  cin>>n>>x;
  std::vector<int> vec(n);
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>vec[i];
  }
  a=vec;
  for (int i = 0; i < n-1; ++i)
  {
    if(vec[i]+vec[i+1]>x){
      if(vec[i+1]>=vec[i]+vec[i+1]-x){
        vec[i+1]-=vec[i]+vec[i+1]-x;
      }
      else{
        vec[i+1]=0;
        vec[i]-=vec[i]-x;
      }
    }
  }

  int64_t ans=0;
  for (int i = 0; i < n; ++i)
  {
    ans+=a[i]-vec[i];
  }
  cout<<ans;
}

Measured memory_bytes: 1024
s=int(input())
a=s
if s==1 or s==2 or s==4:
  print(4)
else:
  cnt=0
  flag=True
  while flag:
    if a%2==0:
      a=a//2
    else:
      a=3*a+1
    cnt+=1
    if a == 4:
      flag=False
  print(cnt+3+1)
  

Measured memory_bytes: 2940
#include <stdio.h>
#include <malloc.h>
#define NIL -1

typedef struct t{
	int r;
	int l;
	int k;
}node;
node T[500000];
int s;
void view(void);
void inorder(int);
void preorder(int);
void insert(int k) {
int p = 0;
	while (1) {
		if (k < T[p].k) {
			if (T[p].l == NIL) {
				T[p].l = s;
				T[s++].k = k;
				break;
			}
			else p = T[p].l;
		}
		else {
			if (T[p].r == -1) {
				T[p].r = s;
				T[s++].k = k;
				break;
			}
			else p = T[p].r;
		}
	}
}
int main() {
	int i, x,root,n;
	char com[20];
	scanf("%d", &n);
	for (i = 0; i < n; i++) T[i].k = T[i].l = T[i].r = -1;
	s = 0;
	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &x);
			if (i == 0) {
				root = x;
				T[s++].k = x;
			}
			else {
				insert(x);
			}
		}
		else if (com[0] == 'p') {
			inorder(0);
			printf("\n");
			preorder(0);
			printf("\n");
		}
	}

	return 0;
}
void inorder(int z) {
	if (T[z].l != NIL) {
		inorder(T[z].l);
	}
	printf(" %d",T[z].k);
	if (T[z].r != NIL) {
		inorder(T[z].r);
	}
}
void preorder(int z) {
	printf(" %d", T[z].k);
	if (T[z].l != NIL) {
		preorder(T[z].l);
	}
	if (T[z].r != NIL) {
		preorder(T[z].r);
	}
}


Measured memory_bytes: 7568
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"
 
//ポップカウントの計算
int pcnt(int x){ 
    return __builtin_popcount(x);  //2進数の1の数を数えす
}
 
//再帰的にf(n)を求める
int f(int x){
    if(x==0) return 0;
    return f(x%pcnt(x))+1; //1度割ることができたら1回操作が増えるので+1している
}
 
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll ans=1, chg=0;
    rep(i, n){
        cin >> a[i];
        if(a[i]<=MX_ll/ans){
            ans *= a[i];
        }else{
            chg = 1;
        }
        if(a[i]==0){
            cout << "0" << endl;
            return 0;
        }
    }
    if(chg==0) cout << ans << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 4060
import java.util.Scanner;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long max=k;
		for(int i=1;i<n;i++) {
			max=max*(k-1);
		}
		System.out.println(max);

	}

}

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

ans = 0
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
  s = input()
  if s[0] == "M": m += 1
  if s[0] == "A": a += 1
  if s[0] == "R": r += 1
  if s[0] == "C": c += 1
  if s[0] == "H": h += 1

ans += m * a * r
ans += m * a * c
ans += m * a * h
ans += m * r * c
ans += m * r * h
ans += m * c * h

ans += a * r * c
ans += a * r * h
ans += a * c * h

ans += r * c * h

print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=1,x=0,y;
    VI m(5);
    string s,s1,s2;
    cin >> n >> x >> y;
    cout << (n-x+1) * (n-y+1) << endl;
    return 0;
} 

Measured memory_bytes: 256
/*input
13
ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
/**
    Author: Kristopher Paul
    Date Created: 23-11-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    FOR(i,0,s.length()){
        int x = s[i]-'A';
        x += n;
        x %= 26;
        s[i] = char('A'+x);
    }
    cout << s << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
n = []
x = []

while True:
    n1,x1, = map(int,input().split())
    if (n1 == 0)*(x1 == 0) :
        break
    n.append(int(n1))
    x.append(int(x1))

s = []
comb = 0
for u in range(len(n)):
    for i in range(1,n[u]+1):
        for j in range(i,n[u]+1):
            for k in range(j,n[u]+1):
                if (i != j)*(j != k)*(k!=i)*(x[u]==i+j+k):
                    s1 = [i,j,k]
                    s1.sort()
                    if s1 not in s:
                        s.append(s1)
    print(len(s))
    s = []



Measured memory_bytes: 5656
f=->n,m,a,b{s=a/m*n*~-n/2+b/m*n
b%=m
x=b-m*y=(b+n*a%=m)/m
y>0&&s+=f[y,a,m,x%a]+y*=n+x/a
s}
gets
$<.map{p f[*_1.split.map(&:to_i)]}

Measured memory_bytes: 15116
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		int ans = 0;
		if(n <= 99) {
			System.out.println(n * (int)Math.pow(100, d));
		}else {
			System.out.println(101 * (int)Math.pow(100, d));
		}
	}

}


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

int main()
{
	ll N;
	vector<ll> a;
	cin >> N;
	REP(i, 0, 3*N) {
		ll in;
		cin >> in;
		a.push_back(in);
	}
	sort(a.begin(), a.end(), std::greater<int>());

	ll ans = 0;
	REP(i, 0, N) {
		ans += a[1 + 2 * i];
	}

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

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

const int nax = 3005;
ll a[nax];
vector<vector<ll>> dp;

ll recurse(int st, int en){
    if(st > en) return 0ll;
    if(~dp[st][en]) return dp[st][en];

    ll &z = dp[st][en];
    ll lt = recurse(st + 1, en);
    ll rt = recurse(st, en - 1);
    return z = max(a[st] - lt, a[en] - rt);
}


void solve(){
    int n;
    cin>>n;
    dp.resize(n, vector<ll>(n, -1));
    fr(i, n) cin>>a[i];
    cout<<recurse(0, n-1);   /// bool turn = 1, 0 for second player
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 70912
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner (System.in);
    int N = sc.nextInt();
    int[] array = new int[N];
    for (int i=0; i<N; i++) {
      int n = sc.nextInt();
      array[i] = n;
    }
    int[] dp = new int[N];
    dp[1] = Math.abs(array[0] - array[1]);
    for (int i=2; i<N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(array[i-2]-array[i]), dp[i-1] + Math.abs(array[i-1]-array[i]));
    }
    System.out.println(dp[N-1]);
  }
}

Measured memory_bytes: 59580
#include <iostream>
#include <cstdio>

int A[10001];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  
  int q, key, sum = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d", &key);
    A[n] = key;
    int j = 0;
    while (A[j] != key) { j++; }
    if (j != n) { sum++; }
  }
  
  printf("%d\n", sum);
  return 0;
  
}

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


static const string mark[4] = {"S", "H", "C", "D"};

int main(void) {

	int n;
	cin >> n;

	int card[4][13] = {};
	string a;
	int b;
	for(int i=0;i<n;i++) {
		cin >> a >> b;
		if(a == "S")		card[0][b-1] = 1;
		else if(a == "H")	card[1][b-1] = 1;
		else if(a == "C")	card[2][b-1] = 1;
		else if(a == "D")	card[3][b-1] = 1;
	}

	for(int i=0;i<4;i++) {
		for(int j=0;j<13;j++) {
			if(card[i][j] == 0) {
				cout << mark[i] << " " << j+1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1212