akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};


vector<ll> a;
ll b = 0;
ll c = 0;
priority_queue<ll> que1;
priority_queue<ll, vector<ll>, greater<ll>> que2;
ll que1_sum = 0, que2_sum = 0;

void query1() {
    ll aa, bb;
    cin >> aa >> bb;

    if(!que1.empty() && aa < que1.top()) {
        que1.push(aa);
        que1_sum += aa;
        if(que1.size() > que2.size()+1) {
            ll  t = que1.top();
            que2.push(t);
            que1.pop();
            que2_sum += t;
            que1_sum -= t;
        }
    } else {
        que2.push(aa);
        que2_sum += aa;
        if(que1.size() < que2.size()) {
            ll t = que2.top();
            que1.push(t);
            que2.pop();
            que1_sum += t;
            que2_sum -= t;
        }
    }
    c = que1.top();
    a.push_back(aa);
    
    b += bb;
}

void query2() {
    // cerr << que1.size() << " " << que2.size() << " " << b << endl;
    ll ans = b + c * que1.size() - que1_sum + que2_sum - c * que2.size();
    cout << c << " " <<  ans << endl;
}

void solve() {
    int q;
    cin >> q;
    if(q == 1) {
        query1();
    } else {
        query2();
    }
}

int main() {
    int q;
    cin >> q;
    while(q--) {
        solve();
    }
}


Measured memory_bytes: 4712
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1000000007;

set<ll> ans;
void rec(int n,string now){
    ans.insert(stoll(now));
    if(n == 10)return;

    int num = (int)(now[0] - '0');

    for(int i = -1;i <= 1;i++){
        if(num + i >= 0 && num + i <= 9){
            rec(n+1,(char)(num+i+'0')+now);
        }
    }
}

int main(){
    int k;
    cin >> k;

    for(int i = 0;i <= 9;i++){
        rec(1,string(1,(char)('0'+i)));
    }


    int cnt = 0;
    ans.erase(0LL);
    for(auto itr = ans.begin();cnt < k;itr++,cnt++){
        if(cnt == k-1){
            cout << *itr << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    ll T;
    cin >> N >> T;
    vi t(N);
    cin >> t;
    REP(i, N - 1) {
        if (t[i + 1] - t[i] > T)
            ans += T;
        else
            ans += t[i + 1] - t[i];
    }
    ans += T;
    cout << ans << endl;
}

Measured memory_bytes: 3944
import sys
import numpy as np
from scipy.sparse.csgraph import bellman_ford, connected_components
from scipy.sparse.csgraph._shortest_path import NegativeCycleError

input = sys.stdin.buffer.readline
epsilon = 2 ** -26 # > 10 ** -8, which is the smallest cost scipy's bellman_ford can deal with. 

N, M, P = map(int, input().split())
graph = np.zeros((N, N), np.float64)
for _ in range(M):
    a, b, c = map(int, input().split())
    if graph[a-1][b-1] == 0:
        if -c+P == 0:
            graph[a-1][b-1] = epsilon
        else:
            graph[a-1][b-1] = -c+P
    elif graph[a-1][b-1] > -c+P:
        if -c+P == 0:
            graph[a-1][b-1] = epsilon
        else:
            graph[a-1][b-1] = -c+P

tmp = graph[-1, 0]
#connect N to 1
graph[-1, 0] = epsilon
_, labels = connected_components(graph, connection = "strong")
mask = (labels == labels[0])

#recover original N to 1 path.
graph[-1, 0] = tmp
graph = graph[mask, :][:, mask]

try:
    ans = bellman_ford(graph, directed = True, indices = 0)[-1]
    ans = max(0, int(round(-ans)))
except NegativeCycleError:
    ans = -1

print(ans)


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

int main ()
{
  int a,b,c;
  cin >> a >> b;
  string s;
  s += to_string(a);
  s += to_string(b);
  c = stoi(s);
  if ((int)sqrt(c)*(int)sqrt(c) == c)
    cout << "Yes";
  else
    cout << "No";  
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	
	if(a == b){
		cout<<"Draw"<<endl;
		return 0;
	}
	
	if(a == 1){
		cout<<"Alice"<<endl;
		return 0;
	}else if(b == 1){
		cout<<"Bob"<<endl;
		return 0;
	}
	
	if(a>b){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Bob"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 10000000;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;
const int MM = 1000000007;

ll p10[105];

int g;
pii ex_gcd(int a, int b){
	if( b == 0 ){
		g = a;
		return pii(1, 0);
	}
	pii r = ex_gcd(b, a%b); // r.first * b + r.second * (a - a/b*b)
	return pii(r.second, r.first - a/b * r.second);
}

ll divi(ll l, ll r){
	return l%r < 0? l/r-1 : l/r;
}

ll solve(int a, int c, int b, int d, int k){
//	printf("%d %d %d %d %d\n", a, c, b, d, k);
	pii r = ex_gcd(a, b);
	if( k%g ) return 0;
	if( a == 0 ) return 0 <= k/b && k/b <= d;
	ll x = (ll)k / g * r.first;
	ll y = (ll)k / g * r.second;
	ll u = b/g, v = a/g;

	ll s = max(divi(-x+u-1, u), divi(-d+y+v-1,v)), e = min(divi(c-x, u), divi(y, v));
	/*
	printf("%lld,%lld %lld,%lld\n", u, x, -v, y);
	printf("%lld~%lld %lld~%lld\n", divi(-x+u-1, u), divi(c-x, u), divi(-d+y+v-1, v), divi(+y, v));
	printf("%lld %lld %lld\n", s, e, e-s+1);
	// */
	return max(0ll, e-s+1);
}

int main()
{
	p10[0] = 1;
	for(int i = 1; i <= 20; i++) p10[i] = p10[i-1] * 10;
	int S;
	scanf("%d", &S);
	ll ans = 0;
	for(int i = 0; i <= 9; i++){
		for(int j = i+1; j <= 10; j++){
			ll tot = 0;
			for(int k = i+1; k < j; k++){
				tot += (p10[k] - p10[k-1]) * k;
			}
			if( tot > S ) continue;
			ans = (ans + solve(i, (i ? p10[i-1]*9-1 : 0), j, min((ll)S, p10[j-1]*9-1), S-tot)) % MM;
		}
	}

	ll m = 1;
	for(int i = 1; i <= S; i++){
		if( S%i == 0 && (i >= 10 || S/i+1 <= p10[i-1] * 9)) ans += m*9 - S/i - 1;
		m = m*10 % MM;
	}
	for(int i = 10; i <= S; i++){
		ans += S/i - (S+i)/(i+1) + 1;
	}
	printf("%lld\n", ans % MM);
}


Measured memory_bytes: 256
n = int(input())
a_list = []
for i in range(n):
	a_list.append(int(input()))
r = -1
num = 1
count = 0
while True:
	num = a_list[num-1]
	count += 1
	if num == 2:
		r = count
		break
	if count == n:
		break
print(r)

Measured memory_bytes: 49240
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long int ll;
constexpr ll bigNum = 1000000007;
 
signed main()
{
    fast;
    //ここから本体
    ll n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++)
    {
        string x;
        cin >> x;
        sort(all(x));
        a[i] = x;
    }
    sort(all(a));
 
    ll ans = 0;
    ll c = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] == a[i + 1])
            c++;
        else
        {
            ans += (c * (c - 1)) / 2;
            c = 1;
        }
    }
    ans += (c * (c - 1)) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 5760
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

string s;
 
void solve(){
	cin >> s;

    if (s[2] == s[3] && s[5] == s[4])
    	cout << "Yes";
  	else
  		cout << "No";      
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> a >> b >> c;
    if (a < b) {
        Yn(a <= c && c <= b)
    } else {
        Yn(b <= c && c <= a)
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  if (n==1) {
    printf("Hello World\n");
  }else {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    printf("%d\n", a+b);
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int count=1,max=sc.nextInt(),buff;

		for(int i=1;i<n;i++) {
			buff=sc.nextInt();
			if(max<=buff) {
				count++;
				max=buff;
			}
		}

		System.out.println(count);
	}
}

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));




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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

const int mod = 1e9 + 7;

#define pow abcdef
int pow(int a, int b) {
  if (b == 0) return 1;
  int t = pow(a, b / 2);
  t = (t * t) % mod;
  if (b % 2) return (t * a) % mod;
  return t;
}

void Main() {
  int n; cin >> n;
  vector<int> a(n), b(60);
  int sum = 0;
  for (auto &i : a) {
    cin >> i;
    sum += ((i % mod) * (n - 1)) % mod;
    sum %= mod;
    for (int j = 0; j < 60; j++) {
      b[j] += getBit(i, j);
    }
  }
  int cal = 0;
  for (int j = 0; j < 60; j++) {
    cal += ((1ll << j) % mod) * ((((b[j] * (b[j] - 1)) % mod) * pow(2, mod - 2)) % mod);
    cal %= mod;
  }
  cout << (sum - 2 * cal + mod * mod) % mod << '\n';
}

signed main() {
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 5552
N, Y = map(int, input().split())
for i in range(N + 1):
    if 10000 * i > Y:
        continue
    for j in range(N - i + 1):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 40684
#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
#define float double
const int  LMT =1000000000+5;
#define int long long 
#define lp(i,n) for( i=0;i<n;i++)
const int N=3005,M=3005;
int n,m,w[N],v[N],i,j;string a,b;
int dp[N][M];bool vis[N][M];
void solve(int n,int m){
for(int i=1;i<n;i++){
    for(int j=1;j<m;j++){
      if(a[i]==b[j])dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

    }

}
}
int32_t main(){
  #ifndef ONLINE_JUDGE 
  freopen("input.txt", "r", stdin); 
  freopen("output.txt", "w", stdout); 
 #endif
 cin>>a>>b;
 a='@'+a;b='@'+b; memset(dp,0,sizeof(dp));
 solve(n=a.length(),m=b.length());
  // cout<<dp[n-1][m-1]<<endl;
  i=n-1;j=m-1; string ans="";

/*for(int i=0;i<n;i++){cout<<endl;
    for(int j=0;j<m;j++)
   cout<<dp[i][j]<<" ";

    }*/

  while(i>0 && j>0){
   // cout<<ans<<endl;
    //cout<<i<<" "<<j<<" ";
    int curr=dp[i][j],ca=dp[i-1][j-1],cl=dp[i][j-1],cu=dp[i-1][j];
    int mx=max(max(cl,cu),ca);
    //cout<<"mx="<<mx<<endl;
    if(mx==ca){

      if(mx < dp[i][j])ans+=a[i];
      i--;j--;continue;
    }
    if(mx==cl){
      if(mx < dp[i][j])ans+=a[i];
      j--;continue;

    }
    else{
      if(mx<dp[i][j])ans+=a[i];
      i--;
    }
  }

 reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
 
} 

Measured memory_bytes: 74188
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
 
n = int(input())
edge = [[] for _ in range(n)]
edge_dict = dict()
edges = []
 
for i in range(n - 1):
    a, b = [int(item) - 1 for item in input().split()]
    edge[a].append(b)
    edge[b].append(a)
    if a > b:
        edge_dict[(b, a)] = i
        edges.append((b, a))
    else:
        edge_dict[(a, b)] = i
        edges.append((a, b))
 
m = int(input())
uv = []
for _ in range(m):
    uv.append([int(item) - 1 for item in input().split()])
 
def dfs(p, v, dest):
    if v == dest:
        return [v]
    if p != -1 and len(edge[v]) == 1:
        return False
    for nv in edge[v]:
        if nv == p:
            continue
        ret = dfs(v, nv, dest)
        if ret:
            return ret + [v]
    return False
 
state = [set() for _ in range(m)]
for i, (u, v) in enumerate(uv):
    ret = dfs(-1, u, v)
    for uu, vv in zip(ret, ret[1:]):
        if uu > vv:
            uu, vv = vv, uu
        if (uu, vv) in edge_dict:
            state[i].add(edge_dict[(uu, vv)])

# DP[i-th item][fills uv as st]
dp = [[0] * 2**m for _ in range(n - 1)]
# White
dp[0][0] = 1
a, b = edges[0]
status = 0
for i, st in enumerate(state):
    if 0 in st:
        status |= 1 << i
dp[0][status] += 1
 
for i, (a, b) in enumerate(edges):
    if i == 0:
        continue
    status = 0
    for j, st in enumerate(state):
        if i in st:
            status |= 1 << j
    for k in range(2**m):
        # Fill black
        dp[i][k | status] += dp[i-1][k]
        # Fill white
        dp[i][k] += dp[i-1][k]
 
print(dp[-1][-1])

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

int main(void)
{
    string str;
    cin >> str;

    int first, last;

    for(int i = 0; i < str.size(); i++)
    {
        if(str.at(i) == 'A')
        {
            first = i;
            break;
        }
    }

    //cout << first << endl;

    reverse(str.begin(), str.end());

    for(int i = 0; i < str.size(); i++)
    {
        if(str.at(i) == 'Z')
        {
            last = str.size() - 1 - i;
            break;
        }
    }

    //cout << last << endl;

    cout << last - first + 1 << endl;

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int n;
    in >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        in >> a[i];
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 != 0 && i % 2 == 0)
            ++res;
    }
    out << res << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    ll N,A,B; cin >> N >> A >> B;
    if((B-A)%2 == 0) cout << (B-A)/2 << endl;
    else cout << min(A-1,N-B) + 1 + (B-A-1)/2 << endl;
}

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

const int N = 100005;
const int MOD = 1000000007;

int n;
int a[N];

long long pre[N];

long long fact[N], ifact[N];

long long C(int n, int k) {
  return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

long long power(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = ret * x % MOD;
    x = x * x % MOD;
  }
  
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) scanf("%d", a + i);
  
  pre[0] = a[0];
  for (int i=1; i<n; i++) pre[i] = (pre[i-1] + a[i]) % MOD;
  
  fact[0] = 1;
  for (int i=1; i<=n; i++) fact[i] = fact[i-1] * i % MOD;
  ifact[n] = power(fact[n], MOD-2);
  for (int i=n-1; i>=0; i--) ifact[i] = ifact[i+1] * (i+1) % MOD;
  
  long long sum = 0;
  long long ans = 0;
  for (int i=1; i<n-1; i++) {
    sum = (sum + pre[n-i-1] - pre[i-1]) % MOD;
    ans += C(n, i+2) * fact[2] * fact[i] % MOD * fact[n-i-2] % MOD * sum % MOD;
  }
  
  ans %= MOD;
  sum = 0;
  for (int i=1; i<n; i++) {
    sum = (sum + a[n-i]) % MOD;
    ans += C(n, i+1) * fact[1] * fact[i] % MOD * fact[n-i-1] % MOD * (pre[i-1] + sum) % MOD;
  }
  
  ans = ans + fact[n] * pre[n-1] % MOD;
  ans %= MOD;
  
  printf("%lld\n", ans);
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[101010];
int cnt[101010];
ll mo=1000000007;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	int fail=0,prex=0;
	FOR(i,N) {
		cin>>X[i];
		
		if(i==0) {
			X[0]=1;
		}
		else{
			
			if(X[i]>=X[i-1]+2) X[i]=X[i-1]+2;
			cnt[(fail+1)/2]++;
			if(X[i-1]+1==X[i]) fail++;
		}
	}
	
	ll ret=1;
	ll tot=1;
	FOR(i,N) {
		tot += cnt[i];
		(ret *= tot)%=mo;
		tot--;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef long double ld;
typedef pair<ld, ll> P;

void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001000000;
const ll mod=1000000007;


int main(){
  string s;
  cin>>s;
  int ans=0;
  if(s=="RRR"){
    cout<<3<<endl;
  }
  else if(s=="SRR"||s=="RRS"){
    cout<<2<<endl;
  }
  else if(s=="SSS"){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 3624
# Problem: https://atcoder.jp/contests/abc042/tasks/abc042_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(allNumber, eachStrings):
    result = ''
    # algorithm
    eachStrings.sort()
    result = "".join(eachStrings)
    return result


if __name__ == "__main__":
    N, L = MI()
    SI = []
    for j in range(0, N):
        tmpStrList = list(map(str, sys.stdin.readline().split()))
        SI.append(tmpStrList[0])
    print("{}".format(solver(N, SI)))


Measured memory_bytes: 3064
h, w = list(map(int, input().split()))
s = [list(map(str, list(input()))) for i in range(h)]  # 文字列の二次元配列入力
yoko = [[] for _ in range(h)]
tate = [[] for _ in range(w)]
for i in range(h):
    cnt = 0
    for j in range(w):
        if j == w-1:
            if s[i][j] == '.':
                cnt += 1
                yoko[i] += [cnt] * (cnt)
            else:
                yoko[i] += [cnt] * (cnt)
                yoko[i].append(0)
        else:
            if s[i][j] == '.':
                cnt += 1
            else:
                yoko[i] += [cnt] * (cnt)
                yoko[i].append(0)
                cnt = 0

for i in range(w):
    cnt = 0
    for j in range(h):
        if j == h-1:
            if s[j][i] == '.':
                cnt += 1
                tate[i] += [cnt] * (cnt)
            else:
                tate[i] += [cnt] * (cnt)
                tate[i].append(0)
        else:
            if s[j][i] == '.':
                cnt += 1
            else:
                tate[i] += [cnt] * (cnt)
                tate[i].append(0)
                cnt = 0

ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans, yoko[i][j]+tate[j][i]-1)
print(ans)


Measured memory_bytes: 251656
#include <iostream>
#include <stdio.h>

#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iomanip>

#define ll long long
/*
axb
abx

111
112
123
*/
using namespace std;

string s, t; int dp[3005][3005]; //bool sv[3005], tv[3005];

int main(){
    cin>>s>>t;

    for(int i=0 ; i<=s.length() ; i++){
        for(int j=0 ; j<=t.length() ; j++){
            if(i==0 || j==0){
                dp[i][j] = 0;
            }
            else if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string ans = ""; int w = dp[s.length()][t.length()], i=s.length(), j=t.length();

    while(w>0){
        if(dp[i-1][j]==dp[i][j]){
            --i;
        }
        else if(dp[i][j-1]==dp[i][j]){
            --j;
        }
        else if(dp[i][j]-1==dp[i-1][j-1]){
            //cout<<i<<" "<<j<<s[i-1]<<'\n';
            ans+=s[i-1];
            i-=1; j-=1;
            --w;
        }
    }

    reverse(ans.begin(), ans.end());

    cout<<ans;
}


Measured memory_bytes: 35456
N = int(input())
array = []

for i in range(N-1):
  _input = str(input().replace('\r','')).split(' ')
  array.append((int(_input[0]), int(_input[1]), int(_input[2])))

for i in range(N-1):
  time = array[i][0] + array[i][1]
  for j in range(i+1, N-1):
    if array[j][1] > time:
      time = array[j][1]
    elif time % array[j][2] != 0:
      time = time - time % array[j][2] + array[j][2]
    time = time + array[j][0]
  print(time)

print(0)

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

using namespace std;

const int N = 2e5 + 7 , mod  =998244353; 
int n ,m; 
long long dp[N]; 
 
int main(){
   // freopen("in.in" , "r" , stdin); 
    cin>>n>>m; 
    dp[0] = 1ll;
    long long ans = 0ll;  
    for(int i = 0 ; i< n ;i++){
        int t ; 
        cin>>t ; 
        for(int j = m ; j>0 ; j--){
            dp[j+t]+=dp[j];
            dp[j+t]%=mod;
        }
        dp[t]+=i+1;
        dp[t]%=mod ;    
        ans+=dp[m];
        ans%=mod;
    }
    cout<<ans ; 
    return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll m=1000000007;
int main()
{
	int n;
	cin>>n;
	int arr[n],dp[n]; 
	for(int i=0;i<n;i++)
		cin>>arr[i];
	dp[0]=0,dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1];
}



Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b,ll c){if(a==b)out(c);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi g;
vb used;
int c=0;
vvi color;
vi v;
void dfs(int i){
    if(used[i])return;
    color[c].pb(v[i]);
    used[i]=true;
    for(auto x:g[i])if(!used[x])dfs(x);
}
int main(){
    ll n,m;cin>>n>>m;
    ll k=(n-m-1)*2;
    if(k==0)dame(0);
    if(k>n)dame("Impossible");
    v=vi(n);
    rep(i,n)cin>>v[i];
    color=vvi(n-m);g=vvi(n);
    rep(i,m){
        ll a,b;cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    ll ans=0;
    used=vb(n,false);
    rep(i,n)if(!used[i]){
        dfs(i);
        c++;
    }
    vi s;
    rep(i,n-m){
        sort(all(color[i]));
        rep(j,color[i].size()-1)s.pb(color[i][j+1]);
        ans+=color[i][0];
    }
    sort(all(s));
    rep(i,k-n+m)ans+=s[i];
    out(ans);
}

Measured memory_bytes: 9464
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  vi a(3);
  cin >> a;
  sort(all(a));
  int ans = 0;
  ans += (a[1] - a[0] + 1) / 2;
  if ((a[1] - a[0]) % 2) ans++;
  ans += (a[2] - a[1]);
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;
  cin >> n >> x;
  vi b(n),l(n),u(n);
  REP(i,n) cin >> b[i] >> l[i] >> u[i];
  int d0 = 0;
  REP(i,n) d0 += b[i]*l[i];
  V<pii> f(n);
  REP(i,n) f[i].fi = (x-b[i])*u[i]+b[i]*l[i], f[i].se = i;//pairのfirstには各数列の総和、secondにはindexを入れておく。
  sort(rALL(f));//降順ソート
  int le = -1,ri = n*x;
  //(le,ri]で二分探索
  while(le+1<ri){// lower_bound
    int m = (le+ri)/2;
    int k = m;
    int q = k/x;
    int sum = 0;
    REP(i,q) sum += f[i].fi;
    int mx = sum;
    int r = k - q*x;
    RREP(i,n){
      static int a;
      a = l[f[i].se]*min(b[f[i].se],r)+u[f[i].se]*max(0LL,r-b[f[i].se]);
      if(i<q) sum += f[i+1].fi - f[i].fi;
      maxs(mx,sum+a);
    }
    if(mx<d0) le = m;
    else ri = m;
  }
  cout << ri << endl;
}



Measured memory_bytes: 4224
# -*- coding: utf-8 -*-

mod = 10 ** 9 + 7


'''Snippets for combination.

Available functions:
- count_combination: Count the total number of combinations.
'''


def count_combination(n: int, r: int, mod: int = 10 ** 9 + 7) -> int:
    '''Count the total number of combinations.
        nCr % mod.

    Args:
        n   : Elements. Int of number (greater than 1).
        r   : The number of r-th combinations. Int of number (greater than 0).
        mod : Modulo. The default is 10 ** 9 + 7.

    Returns:
        The total number of combinations.

    Landau notation: O(n)

    See:
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    '''

    if r > (n - r):
        return count_combination(n, n - r)

    if r == 0 or r == n:
        return 1

    if r == 1:
        return n

    multiple = 1
    division = 1

    for i in range(r):
        multiple *= n - i
        division *= i + 1
        multiple %= mod
        division %= mod

    return multiple * pow(division, mod - 2, mod) % mod


def solve(n: int, m: int):
    from math import sqrt

    ans = 1
    remain = m

    for j in range(2, int(sqrt(m)) + 1):
        if remain % j == 0:
            count = 0

            while remain % j == 0:
                count += 1
                remain //= j

            ans *= count_combination(n + count - 1, n - 1)
            ans %= mod

    if remain != 1:
        ans *= count_combination(n, 1)
        ans %= mod

    return ans


def main():
    n, m = map(int, input().split())

    # See:
    # https://www.youtube.com/watch?v=gdQxKESnXKs
    print(solve(n, m))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d", $n);
$array = explode(' ', trim(fgets(STDIN)));
 
$count = 0;
 
if (isGusu($array)) {
  while (true) {
    $count++;
    for ($i = 0; $i < $n; $i++) {
      $array[$i] = $array[$i] / 2;
    }
    if (isGusu($array) == false) {
      break;
    }
  }
}
 
function isGusu($array) {
  $len = count($array);
  for ($i = 0; $i < $len; $i++) {
    if ($array[$i] % 2 == 1) {
      return false;
    } 
  }
  return true;
}
 
echo $count;

Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <cmath>
#include<iomanip>
#include <unordered_map>
using namespace std;
static const long long MOD = 1000000007LL;
typedef long long ll;
bool abc=1;
int n;
long long cnt=0;
unordered_map <string,int> ump;


int main()
{
	cin>>n;
	
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		sum+=ump[s];
		ump[s]++;

	}
	
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 10660
#include <stdio.h>
int main(void){
  int h,w,i,j,x,d,e;
  scanf("%d %d",&h,&w);
  char s[51][51];
  for(i=0;i<h;i++){
      scanf("%s",s[i]);
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      x=0;
      if(s[i][j]=='#'){
	putchar('#');
      }
      else {
	for(d=-1;d<=1;d++){
	  for(e=-1;e<=1;e++){
	    if(s[i+e][j+d]=='#'){
	      x++;
	    }
	  }
	}
	printf("%d",x);
      }
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N;
int s = 0;
int x = 0;
int y=10000;

int main() {
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		s = s + v[i];
	}
	vector<int>s1(N);
	vector<int>x(N);
	for (int j = 1; j < N; j++) {
		s1[j] = 0;
		for (int k = 0; k < j; k++) {
			s1[j] = s1[j] + v[k];
		}
		x[j] = abs(s - 2 * s1[j]);
	}
	for (int l = 1; l < N; l++) {
		if (x[l] <= y)
			y = x[l];
	}
	cout << y;

	return 0;
}

Measured memory_bytes: 384
def c_average_length():
    from itertools import permutations
    from math import factorial
    N = int(input())
    Positions = [[int(i) for i in input().split()] for j in range(N)]

    ans = 0.0
    for route in permutations(range(N), N):
        tmp = 0.0
        for i in range(N - 1):
            cur_v = route[i]
            next_v = route[i + 1]
            tmp += ((Positions[next_v][0] - Positions[cur_v][0])**2 +
                    (Positions[next_v][1] - Positions[cur_v][1])**2)**0.5
        ans += tmp
    return ans / factorial(N)

print(c_average_length())

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main(void)
{
    int n;
    cin >>n;

    vector<int> d;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >>tmp;
        d.push_back(tmp);
    }

    sort(d.begin(), d.end());
    int ans = d[n/2] - d[n/2-1];


    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 892
import sys
sys.setrecursionlimit(10**7)

class LCA:
    def __init__(self,N,G,r):
        self.dist=[-1]*N
        self.K=0
        while(2**self.K<N):
            self.K+=1
        self.doubling=[[-1]*N for i in range(self.K+1)]
        self.dfs(G,r,-1,0)
        for k in range(1,self.K+1):
            for i in range(1,N):
                self.doubling[k][i]=self.doubling[k-1][self.doubling[k-1][i]]
        
    def dfs(self,G,v,p,d):
        self.dist[v]=d
        self.doubling[0][v]=p
        for nv in G[v]:
            if nv==p:
                continue
            self.dfs(G,nv,v,d+1)
        
    def get(self,u,v):
        if self.dist[u]<self.dist[v]:
            u,v=v,u
        for k in range(self.K+1):
            if (self.dist[u]-self.dist[v])>>k&1:
                u=self.doubling[k][u]
        if u==v:
            return u
        for k in reversed(range(self.K+1)):
            if self.doubling[k][u]!=self.doubling[k][v]:
                u=self.doubling[k][u]
                v=self.doubling[k][v]
        return self.doubling[0][u]
    
    def getdist(self,u,v):
        return self.dist[u]+self.dist[v]-2*self.dist[self.get(u,v)]

def main():
    N=int(input())
    G=[[] for i in range(N)]
    for i in range(N):
        k=list(map(int,input().split()))
        for j in range(1,len(k)):
            G[i].append(k[j])
            G[k[j]].append(i)
    lca=LCA(N,G,0)
    Q=int(input())
    for i in range(Q):
        a,b=map(int,input().split())
        print(lca.get(a,b))

if __name__=='__main__':
    main()


Measured memory_bytes: 151492
#include <stdio.h>
#include <stdlib.h>
#define LIMITATION 1000000000

int gcd(int a, int b);
int main(int argc, char** argv) {
    
  

    int a, b;

    int readScan = scanf("%d %d", &a, &b);
    if (readScan == EOF)
    {
        printf("data not enough! \n");
        return(EXIT_FAILURE);
    }
    if (readScan != 2)
    {
        printf("Input data error!\n");
        return(EXIT_FAILURE);
    }

    if (a < 0 || b < 0)
    {
        printf("Number should be non-negative!\n");
        return(EXIT_FAILURE);
    }  

    if (a > LIMITATION || b > LIMITATION)   
    {
        printf("Number should be less than 10^9! \n");
        return(EXIT_FAILURE);
    }
      
    int gCD;
    gCD = gcd(a, b);
    printf("%d\n", gCD);

    return (EXIT_SUCCESS);
}

int gcd(int x, int y)
{
	while (x != y)
	{
		if (x > y)	x = x - y;
		else        y = y - x;
	}
	return x;
}



Measured memory_bytes: 2140
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 500, MAX_C = 30;
    int N, C, D[MAX_C][MAX_C];
    int cc[3][MAX_C];
    memset(cc[0], 0, sizeof(cc));
    cin >> N >> C;
    REP(i, C) {
        REP(j, C) {
            cin >> D[i][j];
        }
    }
    REP(i, N) {
        REP(j, N) {
            int c;
            cin >> c;
            cc[(i + j) % 3][c - 1]++;
        }
    }
    int res = INT_MAX;
    REP(i, C) {
        REP(j, C) {
            if (i == j) {
                continue;
            }
            REP(k, C) {
                if (i == k || j == k) {
                    continue;
                }
                int sum = 0;
                REP(l, C) {
                    sum += D[l][i] * cc[0][l];
                }
                REP(l, C) {
                    sum += D[l][j] * cc[1][l];
                }
                REP(l, C) {
                    sum += D[l][k] * cc[2][l];
                }
                amin(res, sum);
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N, Y;
    cin>>N>>Y;
    for(int i = 0; i <= N; i++)
        for(int j = 0; j+i<= N; j++)

    {
        int k = N-(i+j);
        if(i*10000+j*5000+k*1000==Y)
        {
            printf("%d %d %d", i, j, k);
            return 0;
        }
    }
    puts("-1 -1 -1");
    return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc141/tasks/abc141_d
# 割引券は半額にする操作
# 値段が大きいものに貪欲に使っていきたい
# 割って逐一挿入して最大のものをまた割る？
# 配列平衡二分木で実装←atcoderの環境が古くて使えなかった！


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


from heapq import heapify, heappop, heappush, heappushpop


class PriorityQueue:
    def __init__(self, heap):
        '''
        heap ... list
        '''
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap

    def __len__(self):
        return len(self.heap)


N, M = read_ints()
A = read_ints()
que = PriorityQueue([-a for a in A])
for _ in range(M):
    x = -que.pop()
    x //= 2
    que.push(-x)

print(-sum(que.heap))


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

namespace WelcomeAtcordet
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);
            List<string> output = new List<string>();

            for (int i = 0; i < H; i++)
            {
                output.Add(Console.ReadLine());
            }

            foreach (string s in output)
            {
                for (int i = 1; i <= 2; i++)
                {
                    Console.WriteLine(s);
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int n;
ll a[N];
ll b[N];

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();

	for(int i=1;i<=n;++i){
		a[i]=read();
	}

	for(int i=n;i>=1;--i){
		b[i]=b[i+1]%mod+a[i]%mod;
	}

	ll res=0;

	for(int i=1;i<=n;++i){
		res+=a[i]%mod*b[i+1]%mod;
		res%=mod;
	}

	printf("%lld\n",res);

    return 0;
}

Measured memory_bytes: 6836
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll INF = 1e18;

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = lin();

    VVL dp(n + 1, VL(5, INF));
    dp[0][0] = 0;
    REP(i,n) REP(j,5){
        if (dp[i][j] == INF) continue;
        FOR(k,j,4){
            if (k == 0 || k == 4) dp[i+1][k] = min(dp[i+1][k], dp[i][j] + a[i]);
            if (k == 1 || k == 3) dp[i+1][k] = min(dp[i+1][k], dp[i][j] + (a[i] == 0 ? 2 : a[i] % 2));
            if (k == 2) dp[i+1][k] = min(dp[i+1][k], dp[i][j] + ((a[i] + 1) % 2));
        }
    }

    // REP(i,n+1){
    //     REP(j,5) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    ll ans = INF;
    REP(j,5) ans = min(ans, dp[n][j]);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = -1;
  for (int i = 1; i <= 10000; i++) {
    if (i * 8 / 100 == A and i / 10 == B) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


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


namespace Sample
{
  class Sample
  {
    static void Main()
    {
      
      string p = Console.ReadLine();
      int q = p.Length;

      for(int i=0;i<q;i++){
      Console.Write("x");
      }
      
		}
	}
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
	string s;
int sum=0;
cin>>s;
if(s[0]!='A'||isupper(s[1])||isupper(s.back())){cout<<"WA";return 0;}
for(int i=2;i<s.size()-1;i++){
if(s[i]=='C')
sum++;
if(s[i]!='C' && isupper(s[i])){cout<<"WA";return 0;}
}
cout<<((sum==1)?"AC":"WA");
	return 0;
}


Measured memory_bytes: 256