akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
using namespace std;
 
int main(){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}



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

typedef unsigned long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1000 * 1000 * 1000;
const int MAX = 2000 * 1000 + 5;
const int MAX2 = 1000 * 1000 + 2;
const int MAX20 = MAX2 * 10;
bool allEq(string s)
{
	int res = 1;
	for(auto x : s)
		res &= x == s[0];
	return res;
}
int main()
{
    string s;
    LL k;
    cin >> s >> k;
    if(allEq(s))
    {
		cout << SZ(s) * k / 2;
		return 0;
	}
	vector<pair<LL , char> >  v;
	for(auto x : s)
	{
		if(!SZ(v) || v.back().Y != x)
			v.PB({1 , x});
		else
			v.back().X++;
	}
	LL ans = 0;
	if(v[0].Y != v.back().Y)
	{
		for(auto x : v)
			ans += (x.X / 2) * k;
		
		cout << ans << endl;
		return 0;
	}
	ans += v[0].X / 2;
	ans += v.back().X / 2;
	for(int i = 1; i < SZ(v) - 1; i++)
		ans += (v[i].X / 2) * k;
	ans += ((v[0].X + v.back().X) / 2) * (k - 1);
	cout << ans;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		string s=Console.ReadLine();
		long[] h=new long[26];
		long ans=1;
		for(int i=0;i<s.Length;i++){h[s[i]-'a']++;}
		for(int i=0;i<25;i++){
			for(int j=i+1;j<26;j++){ans+=h[i]*h[j];}
		}
		Console.WriteLine("{0}",ans);
	}
}

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

int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    sum+=min(k,a);
    if(k<a){
        cout << sum << endl;
        return 0;
    }
    k-=a;
    if(k<b){
        cout << sum << endl;
        return 0;
    }
    k-=b;
    sum-=min(k,c);
    if(k<=c){
        cout << sum << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
        int a,b;
        string str;
        stack<int> s;
        while(cin>>str){
                if(str[0]-'0'>=0&&str[0]-'0'<10)
                        s.push(stoi(str));
                else if(str=="+"){
                        a = s.top();s.pop();
                        b = s.top();s.pop();
                        s.push(a+b);
                }else if(str=="*"){
                        a = s.top();s.pop();
                        b = s.top();s.pop();
                        s.push(a*b);
                }
                else if(str=="-"){
                        a = s.top();s.pop();
                        b = s.top();s.pop();
                        s.push(b-a);
                }
        }
        cout<<s.top()<<endl;
        return 0;
}


Measured memory_bytes: 3144
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int ans = 12;
		if(b >= a) {
			ans = a;
		}else {
			ans = a - 1;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: u32 = s.next().unwrap().parse().unwrap();
	let mut a: Vec<u32> = s.map(|a| a.parse::<u32>().unwrap()).scan(0, |s, a|{
		*s = (*s + a) % m;
		Some(*s)
	}).collect();
	a.push(0);
	a.sort();
	let mut l = 0;
	let mut ans = 0;
	while l < n + 1 {
		let r = a.upper_bound(&a[l]);
		ans += (r - l) * (r - l - 1) / 2;
		l = r;
	}
	println!("{}", ans);
}

trait BinarySearch<'a, T: 'a> {
	fn upper_bound(&self, x: &T) -> usize;
}

impl<'a, T: 'a + Ord> BinarySearch<'a, T> for [T] {
	fn upper_bound(&self, x: &T) -> usize {
		let mut first = 0;
		let mut len = self.len() - first;
		while len > 0 {
			let half = len >> 1;
			let mid = first + half;
			use std::cmp::Ordering;
			match x.cmp(&self[mid]) {
				Ordering::Less => {
					len = half;
				}
				Ordering::Equal | Ordering::Greater => {
					first = mid + 1;
					len = len - half - 1;
				}
			}
		}
		first
	}
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint comb(int n, int k) {
    mint x = 1;
    mint y = 1;
    rep(i,k) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() 
{
    int n, m, k;
    cin >> n >> m >> k;

    mint ans = 0;
    for(int d=1; d<=n-1; d++) {
        mint pat = 1;
        pat *= (n-d);
        pat *= m;
        pat *= m;
        pat *= d;
        ans += pat;
    }

    for(int d=1; d<=m-1; d++) {
        mint pat = 1;
        pat *= (m-d);
        pat *= n;
        pat *= n;
        pat *= d;
        ans += pat;
    }
    ans *= comb(n*m-2, k-2);

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long  b = scan.nextLong();
		long c = scan.nextLong();

		if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
			System.out.println(0);
			return;
		}
		if (a >= b && a >= c) {
			System.out.println(b * c);
		} else if (b >= a && b >= c) {
			System.out.println(a * c);
		} else {
			System.out.println(a * b);
		}
	}
}


Measured memory_bytes: 9940
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let X = parseInt(input[0][0], 10);
	let v_TF = Array.from({length: 1e5 * 2}, () => true);
	for (let i = 2; i <= Math.sqrt(1e5 * 2); i++){
		for (let j = 2; j <= 1e5*2 / i; j++){
			v_TF[i * j - 1] = false;
		}
	}
	let v_prime = [];
	for (let i = 1; i < v_TF.length; i++){
		if (v_TF[i]) v_prime.push(i + 1);
	}

	const lowerBound = (arr, n) => {
		let first = 0, last = arr.length - 1, middle;
		while (first <= last) {
			middle = 0 | (first + last) / 2;
			if (arr[middle] < n) first = middle + 1;
			else last = middle - 1;
		}
		return first;
	}

	console.log(v_prime[lowerBound(v_prime, X)]);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 34188
//ll n_kai[pow(10.0, 5.0)]; なんでだめなの？


#include<iostream>
#include<queue>
#include<vector>

#define rep(i,n) for(int i = 0;i < n;i++)

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;



int main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	priority_queue<ll> p, q, r;

	rep(i,a){
		int t;cin >> t;
		p.push(t);
	}
	rep(i,b){
		int t;cin >> t;
		q.push(t);
	}
	rep(i,c){
		int t;cin >> t;
		r.push(t);
	}

	ll ans = 0;
	rep(i,x){
		ll t = p.top();p.pop();
		r.push(t);
	}
	rep(i,y){
		ll t = q.top();q.pop(); 
		r.push(t);
	}
	rep(i,x+y){
		ans += r.top();r.pop();
	}

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


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

const int N = 1299709;   // main??????????§??????¨?\¨
bool sieve[N + 1] = {1, 1, 0};   // false:?´???°

int main() {
  vi primes;

  FOR(i, 2, N + 1){
    if (sieve[i]) continue;
    primes.push_back(i);
    for(int j = i * 2; j < N  + 1; j += i) {
      sieve[j] = true;
    }
  }

  int n;
  while(cin >> n, n) {
    if(!sieve[n]) cout << 0 << endl;
    else{
      auto sprime = lower_bound(ALL(primes), n);
      cout << *sprime - *(sprime - 1) << endl;
    }
  }
}

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const ll MAX = 1e+12 + 1;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<ll> cnt(41);
/* function */
void g(ll x) {
    ll p = 2, tmp = x + 1;
    for (int i = 0; i < 41; p *= 2, i++) {
        cnt[i] += (tmp / p) * (p / 2);
        if (tmp % p != 0) cnt[i] += max(tmp % p - p / 2, 0LL);
    }
}
/* main */
int main(){
    ll A, B;
    cin >> A >> B;
    g(A - 1);
    for (int i = 0; i < 41; i++) cnt[i] = -cnt[i];
    g(B);
    ll ans = 0;
    ll p = 1;
    for (int i = 0; i < 41; i++, p *= 2) {
        ans += (cnt[i] % 2) * p;
    }
    cout << ans << '\n';
}


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

int const N=1e5+5, M=10+5, OO = 0x3f3f3f3f;

long long ans;
int n,h,a,mx;
int arr[N];


int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
//    freopen("mo3gza.txt","wt",stdout);
    cin>>n>>h;
    for(int i=0; i<n; i++)
    {
        cin>>a>>arr[i];
        mx=max(mx,a);
    }
    sort(arr,arr+n);
    int i=n-1;
    while(h>0 && arr[i]>mx)
    {
        h-=arr[i];
        ans++;
        i--;
    }
//    cout<<h<<endl;
    if(h>0)
    {
        ans+=(h/mx);
        if(h%mx)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 640
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
UVAB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for u,v,a,b in UVAB:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))

import heapq
INF = float('inf')
dy = [INF]*N
dy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    d,v = heapq.heappop(hq)
    for to,a,_ in es[v]:
        if d+a >= dy[to]: continue
        dy[to] = d+a
        heapq.heappush(hq, (d+a, to))
ds = [INF]*N
ds[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    d,v = heapq.heappop(hq)
    for to,_,a in es[v]:
        if d+a >= ds[to]: continue
        ds[to] = d+a
        heapq.heappush(hq, (d+a, to))

ans = []
m = 0
for y,s in reversed(list(zip(dy,ds))):
    m = max(m, 10**15-y-s)
    ans.append(m)
ans.reverse()
print(*ans, sep='\n')

Measured memory_bytes: 77708
s=int(input())
l=[0]*10000
for i in range(1,10000):
    if i==1:
        f=s
        l[i]=f
        setl=2
    else:
        tmp=setl
        if f%2==0:
            f=f//2
        else:
            f=3*f+1
        l[i]=f
        setl=len(set(l))
        
        if tmp==len(set(l)):
            print(i)
            exit()

Measured memory_bytes: 3188
a, b, c, x, y = map(int, input().split())

#注文パターンを列挙する
#1. AとBのみを頼む
#2. CをAを満たすだけ頼んで、残りはBを買う
#3. CをBを満たすだけ頼んで、残りはAを買う
#4. Cのみを頼む <- 上記パターンに内包できそう

#Cは2の倍数ずつしか注文されない

#1
ans_1 = a*x + b*y
#2
ans_2 = c*x*2 + max(0, (y-x)*b)
#3
ans_3 = c*y*2 + max(0, (x-y)*a)
#4
ans_4 = c*max(x, y)*2

ans = min(ans_1, ans_2, ans_3, ans_4)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){

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

   if(a > b){
   d = a;
   a = b;
   b = d;
}
   if(b > c){
   d = b;
   b = c;
   c = d;
}
   if(a > b){
   d = a;
   a = b;
   b = d;
   
}
   cout << a << " " << b << " " << c << endl;

   return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int main(){
    int N;cin>>N;
    int x=N%2,y=(N+1)%2;
    int a[3010];
    for(int i=0;i<N;i++)cin>>a[i];
    mat dp(3010,vec(3010));
    for(int i=0;i<=N;i++)dp[i][i]=0;
    
    int i=N-1;
    while(i>=0){
        int j=i+1;
        while(j<=N){
            if((j-i)%2==x)
                dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1]);
            if((j-i)%2==y)
                dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1]);
            j++;
        }
        i--;
    }
    cout<<dp[0][N]<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) cout << "Bad" << endl;
	else cout << "Good" << endl;
	
	return 0;
}

Measured memory_bytes: 256
// C - ID
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()

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

	vi P(M);//[city-1]<prefecture>
	vi Y(M);//[city-1]<year>
	vvi PNY(N, vi());//[prefecture-1][no-1]<year>

	rp(c, M){
		cin>>P[c]>>Y[c];
		PNY[--P[c]].push_back(Y[c]);
	}

	rp(p, N) sort(all(PNY[p]));

	rp(c, M){
		int p = P[c], y = Y[c];
		//binary search: left <- same value range = [left, right).
		auto ite = lower_bound(all(PNY[p]), y);
		int no = ite - PNY[p].begin() + 1;
		printf("%06d%06d\n", p+1, no);
	}

}

Measured memory_bytes: 7808
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
typedef double db;
const ll inf=4e18;
const ll mod=1e9+7;
const int MAX_N=2e5+5;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline db qd(){
    char c=getchar();int flag=1;double ans=0;
    while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
    if(c=='-') flag=-1,c=getchar();
    while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
    if(c=='.'){c=getchar();for(register int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
    return ans*flag;
}
//start!
int n,a[MAX_N],b[MAX_N];
int ca[MAX_N],cb[MAX_N]; 
void ok(){ puts("Yes"); repi(i,1,n) printf("%d%c",b[i],ce(i,n)); }
void no(){ puts("No"); }
int main()
{
	n=qi();
	repi(i,1,n) a[i]=qi();
	repi(i,1,n) b[i]=qi();
	reverse(b+1,b+1+n);
	bool flag=false;
	int id;
	repi(i,1,n)if(a[i]==b[i]){ id=a[i]; flag=true; break; }
	if(!flag){ ok(); return 0; }
	int la=n+1,ra=-1;
	repi(i,1,n)if(a[i]==id){ gmn(la,i),gmx(ra,i); }
	int lb=n+1,rb=-1;
	repi(i,1,n)if(b[i]==id){ gmn(lb,i),gmx(rb,i); }
	int l=max(la,lb),r=min(ra,rb);
	int pos=l,now=1; 
	while(pos<=r&&now<min(la,lb)) swap(b[pos++],b[now++]);
	now=max(rb,ra)+1; 
	while(pos<=r&&now<=n) swap(b[pos++],b[now++]);
	if(pos>r) ok();
	else no();
	return 0;
}

Measured memory_bytes: 5332
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
       int K=scan.nextInt();
        int N=scan.nextInt();
        int A[]=new int [N];

for(int i=0;i<N;i++){A[i]=scan.nextInt();}

        Arrays.sort(A);
int M=0;
for(int i1=0;i1<N-1;i1++){if(A[i1+1]-A[i1]>M){M=A[i1+1]-A[i1];}}
if(A[0]+K-A[N-1]>M){M=A[0]+K-A[N-1];}
int L=K-M;
        System.out.println(L);


    }

}



Measured memory_bytes: 78880
from fractions import gcd


N = int(input())
*x, = map(int, input().split())
MOD = 10**9+7

m = 1
for i in range(1, N):
    m *= i
    m %= MOD

va, vb = 0, 1
ans = 0

for i in range(N-1):
    d = x[i+1]-x[i]
    va = ((i+1)*va+vb)%MOD
    vb = ((i+1)*vb)%MOD
    ans += (d*va*pow(vb, MOD-2, MOD)*m)
    ans %= MOD

print(ans)


Measured memory_bytes: 88300
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 = Integer.parseInt(sc.next());
        Set<String> set = new HashSet<>();
        for(int i = 0; i < n; i++){
            set.add(sc.next());
        }
        System.out.println(set.size());
    }
}

Measured memory_bytes: 78376
n=int(input())
p=list(map(int,input().split()))
k=0
count=0
while True:
    if k==n:
        break
    elif p[k]==k+1:
        k+=1
    else:
        count+=1
        k+=1
if count==0 or count==2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    x <- readLn
    let solve :: Int -> Int -> Int
        solve n m = if x <= m then n else solve (n+1) (floor $ (fromIntegral m)*1.01)
    print $ solve 0 100

Measured memory_bytes: 3844
using System;
using System.Linq;

namespace AizuOnlineJudge {
    class Program {
        static void Main() {
            var v = Console.ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();

            Console.WriteLine((v[0] * v[1] & v[2] + v[3] & 1) == 1 ? "No" : "Yes");
        }
    }
}



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

int main(){
   char b;
   cin >> b;
   if(b=='A')cout << "T" << endl;
   if(b=='T')cout << "A" << endl;
   if(b=='G')cout << "C" << endl;
   if(b=='C')cout << "G" << endl;
}

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

//https://atcoder.jp/contests/abc076/tasks/abc076_d

int n, x[103], v[102], m;
double l, r, ans = 0;

double f(double t, int i) {
	if (t < x[i])
		return v[i] + x[i] - t;
	if (t > x[i + 1])
		return v[i] + t - x[i + 1];
	return v[i];
}

double sup(double t) {
	double rv = m;
	for (int i = 0; i < n + 2; i++) {
		double s = f(t, i);
		rv = min(rv, s);
	}
	return rv;
}

int main() {
	cin >> n;
	for (int i = 0, t; i < n; i++) {
		cin >> t;
		x[i + 2] = x[i + 1] + t;
	}
	x[n + 2] = x[n + 1];
	for (int i = 0; i < n; i++) {
		cin >> v[i + 1];
		m = max(m, v[i + 1]);
	}
	for (double t = 0; t < x[n + 1]; t += 0.5)
		ans += sup(t) + sup(t + 0.5);
	cout <<fixed<< ans / 4 << endl;
}


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

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

    int K, X;
    cin >> K >> X;
    for (int i = -1000000; i <= 1000000; i++) {
        if (abs(i - X) < K)
            cout << i << ' ';
    }
    cout << '\n';

    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	bool ok = true;
	map<string, int> m;
	char moji;
	for (int ii = 0; ii < N; ++ii){
		string w;
		cin >> w;

		if (ii > 0){
			if(m[w] || w[0] != moji){
				ok = false;
				break;
			}
		}

		m[w] = 1;
		moji = w[w.size()-1];
	}

	if (ok){
	cout << "Yes" << "\n";
	} else {
	cout << "No" << "\n";
	}


	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

/* gcd */
template<typename T>
T gcd(T a,T b)
{
	if(a==0 || b==0)return 0;
	T r;
	while(1)
	{
		r=a%b;
		if(r==0)break;
		a=b;
		b=r;
	}
	return b;
}

template<typename T>
T gcd(T *x,size_t size)
{
	T ret=x[0];
	for(size_t i=0;i<size;i++)
	{
		ret=gcd(ret,x[i]);
	}
	return ret;
}

int main()
{
	int N,X;
	int x[100010]={};

	cin >> N >> X;
	for(int i=0;i<N;i++)
	{
		cin >> x[i];
		x[i]=abs(X-x[i]);
	}
	
	cout << gcd(x,N) << endl;
	return 0;
}


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

int main() {
  int a,alice = 0,bob = 0;
  cin >> a;
  vector<int> b(a); 
  
  
  rep(i,a){
    cin >> b.at(i);
  }
  
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
   rep(i,a){
    if (i % 2 == 0){
     alice += b.at(i)  ;
    } else {
     bob += b.at(i)  ;
    }
      
    
  }
  cout << alice - bob << endl ;
  
}

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

int main() {
  int N;
  cin >> N;
  char S;
  bool p = false;
  bool w = false;
  bool g = false;
  bool y = false;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'P')
      p = true;
    else if (S == 'W')
      w = true;
    else if (S == 'G')
      g = true;
    else if (S == 'Y')
      y = true;
  }
  if (p && w && g && y) {
    cout << "Four" << endl;
  }
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    char a[101];
    cin>>n>>m;
    for(int i=1;i<=n;i++)
	{
        cin>>a;
        puts(a);
        puts(a);
    }
    return 0;
} 

Measured memory_bytes: 256
// 2020-08-17 23:02:01
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  reverse(ALL(s));
  vector<int> a;
  a.push_back(0);
  {
    int x = 0;
    REP(i, 1, s.size()) {
      if(s[i] == '0') {
        a.push_back(a.back() + 1 + x);
        x = 0;
      } else x++;
    }
  }
  vector<int> ans;
  ans.push_back(0);
  REP(i, 1, a.size()) {
    if(a[i] - a[i-1] > m) {
      cout << -1 << '\n';
      return;
    }
    int ci = ans.back();
    if(a[i] - a[ci] <= m) continue;
    ans.push_back(i-1);
  }
  ans.push_back(a.size()-1);
  bool first = true;
  REPCM(i, ans.size()-2, 0) {
    if(first) first = false;
    else cout << ' ';
    cout << a[ans[i+1]] - a[ans[i]];
  }
  cout << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;
 
void solve(){
	int sm= 0 ;
	cin >> s;
	for(int i =0;i<s.length();i++){
		sm=(sm+(s[i]-'0'))%9;
	}
 	cout << (sm==0?"Yes":"No");
}
 
int main(){

	t=1;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3676
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
L = [0]*(n+1)
L[0] = 2
L[1] = 1
for i in range(2,n+1):
    L[i] = L[i-1] + L[i-2]
print(L[n])

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

int main (){

  long a, b, k;
  cin >> a >> b >> k;
  
  if(a >= k) cout << a-k << " " << b << endl;
  else if (b >= (k-a)) cout << 0 << " " << a+b-k << endl;
  else cout << 0 << " " << 0 << endl;

}

Measured memory_bytes: 256
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
#define debug(x) cout << #x << " => " << x << endl
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int ten[15],nine[15];
ll l,r,mid,ans;
char t;

int main() {
    //file_put();
    
    ten[0]=1;
    for (int i=1; i<=9; i++) {
    	ten[i]=10*ten[i-1];
    	nine[i]=ten[i]-1;
	}
	printf("? %d\n",nine[9]);
	fflush(stdout);
	scanf("%c",&t);
	cin.ignore();
	if (t=='N') {
		printf("! %d\n",ten[9]);
		fflush(stdout);
		return 0;
	}
	printf("? %d\n",ten[9]);
	fflush(stdout);
	scanf("%c",&t);
	cin.ignore();
	if (t=='Y') {
		for (int i=1; i<=9; i++) {
			printf("? %d\n",nine[i]);
			fflush(stdout);
			scanf("%c",&t);
			cin.ignore();
			if (t=='Y') {
				printf("! %d\n",ten[i-1]);
				fflush(stdout);
				return 0;
			}
		}
	}
	for (int i=1; i<=9; i++) {
		printf("? %d\n",ten[i]);
		fflush(stdout);
		scanf("%c",&t);
		cin.ignore();
		if (t=='N') {
			l=ten[i-1]+1;
			r=ten[i]-1;
			break;
		}
	}
	while (l<=r){
		mid=(l+r)>>1;
		printf("? %lld\n",mid*10);
		fflush(stdout);
		scanf("%c",&t);
		cin.ignore();
		if (t=='Y') r=mid; else l=mid;
		if (l==r || l==r-1) break;
	}
	if (l+1==r) {
		printf("? %lld\n",l*10);
		fflush(stdout);
		scanf("%c",&t);
		cin.ignore();
		if (t=='N') l++;
	}
	printf("! %I64d\n",l);
	fflush(stdout);

    return 0;
}


Measured memory_bytes: 596
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

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

    if(a == b && b == c) {
        if(a % 2 == 0) return cout << -1 << endl, 0;
    }

    ll num = 0, d;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        a /= 2; b /= 2; c /= 2;
        d = a + b;
        a += c;
        b += c;
        swap(a, b);
        c = d;
        num++;
    }

    cout << num << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

const int MAX = 303030;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	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;
	}
}
ll 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;
}
ll modpow(ll a, ll n) {
	ll res = 1;
	a %= MOD;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}


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

	ll n, a, b;
	cin >> n >> a >> b;
	combinit();
	ll ans = modpow(2, n) - 1;
	ll nca = 1;
	ll ncb = 1;
	for (ll i = 0; i < a; i++) {
		nca *= (n-i);
		nca %= MOD;
		nca *= inv[i+1];
		nca %= MOD;
	}
	for (ll i = 0; i < b; i++) {
		ncb *= (n - i);
		ncb %= MOD;
		ncb *= inv[i + 1];
		ncb %= MOD;
	}
	ans -= nca;
	ans -= ncb;
	ans += 12LL * MOD;
	ans %= MOD;
	puts(ans);


	return 0;
}


Measured memory_bytes: 7424
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


int solve(int l, int r, const string& st,vector<vector<int>>&memo,vector<vector<int>>&flags) {
	if (memo[l][r] == -1) {
		if(l==r)memo[l][r]=0;
		else if(l+1==r)memo[l][r]=1;
		else {

			if (st[l] == st[r - 1]) {
				memo[l][r]=2+solve(l+1,r-1,st,memo,flags);
				flags[l][r]=3;
			}
			else {
				int lk=solve(l+1,r,st,memo,flags);
				int rk=solve(l,r-1,st,memo,flags);

				if (lk > rk) {
					flags[l][r]=2;
				}
				else {
					flags[l][r]=1;
				}
				memo[l][r]=max(lk,rk);
			}
		}
	}
	return memo[l][r];
}

int main() {
	vector<vector<int>>nums(201,vector<int>(17,-1));
	for (int num = 0; num <= 200; ++num) {
		for (int D = 2; D <= 16; ++D) {
			int rest(num);
			vector<int>v(8);
			for (int i = 0; i < 8; ++i) {
				v[7-i]=rest%D;
				rest/=D;
			}
			if (all_of(v.begin(), v.end(), [](const int a) {return a < 10; })) {
				int sum=0;
				for (int i = 0; i < 8; ++i) {
					sum*=10;
					sum+=v[i];
				}
				nums[num][D]=sum;
			}
		}
	}
	int A,B,C;
	while (cin >> A >> B >> C) {
		if(A==-1)break;
		if (find(nums[A].begin()+2, nums[A].end(), B) == nums[A].end()) {
			cout<<-1<<endl;
		}
		else {
			int num=B;
			for(int k = A + 1; k <= C; ++k) {
				int min_num=1e9;
				for (int d = 2; d <= 16; ++d) {
					if (nums[k][d] >= num) {
						min_num=min(min_num,nums[k][d]);
					}
				}
				num=min_num;
			}
			if(num>=1e9)num=-1;
			cout<<num<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin>>n,n) {
    int M = 256;
    int I[n]; FOR(i,0,n) cin >> I[i];
    int ans[3];
    double mn = 1e18;
    FOR(S,0,16) {
      FOR(A,0,16) {
        FOR(C,0,16) {
          int R[n+1];
          R[0] = S;
          FOR(i,1,n+1) R[i] = (A * R[i-1] + C) % M;
          int O[n];
          FOR(i,0,n) O[i] = (I[i] + R[i+1]) % M;
          double H = 0;
          int num[300]; CLR(num);
          FOR(i,0,n) num[O[i]]++;
          FOR(i,0,300) {
            if(num[i] == 0) continue;
            H += num[i] * log((double)num[i]);
          }
          H = -H;
          if(H  < mn) {
            ans[0] = S;
            ans[1] = A;
            ans[2] = C;
            mn = H;
          }
        }
      }
    }
    FOR(i,0,3) {
      if(i) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
  
  string a,b;
  int c=0;
  cin >> a >> b;
  
  for(int i=0; i<a.size(); i++){
      
    if( a.at(i) != b.at(i) ){
      
      c++;
      
    }
  }
  
    cout << c << endl;
  
}

Measured memory_bytes: 3916
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;

typedef struct datum_name {
	int x;
	int y;
	int whosay;
	bool operator==(const datum_name& data) const
	{
		return (x == data.x && y == data.y);
	}
} datum;


bool cmp_who(const datum& left, const datum& right) {
	return left.whosay < right.whosay;
}


int main()
{
	long long N;
	cin >> N;

	if (N % 2 == 1) { //奇数なら答えは０
		cout << "0" << endl;
		return 0;
	}

	long long count = 0;
	long long divval = 10;

	while (divval <= N) {
		count += static_cast<long long>(N / divval);
		divval *= 5;
	}
	

	cout << count << endl;

	return 0;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 3e3 + 10;
const int M = 1e5 + 10;

ld p[N];

void solve() {
    int n;
    cin >> n;
    fr(i, n)
        cin >> p[i];
    vector<ld> cnt(n + 1, 0);
    cnt[0] = 1;
    fr(i, n) {
        vector<ld> ncnt(n + 1, 0);
        fr(j, n) {
            ncnt[j + 1] += cnt[j] * p[i];
            ncnt[j] += cnt[j] * (1 - p[i]);
        }
        cnt = ncnt;
    }

    ld ans = accumulate(cnt.begin() + (n + 1) / 2, cnt.end(), 0.0);
    cout << fixed << setprecision(12) << ans;
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


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

#define int long long
#define REP(i, l, r) REPEAT(i,l,r,true) // [l, r)
#define rep(i, n) REP(i,0,n)           // [0, n)
#define REPEAT(i, l, r, condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n, l, r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...) true
#define showlr(n,l,r) true
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int, int>;

struct io {
    io() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.tie(0);
        cout << fixed << setprecision(20);
    }
} io;

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &e:v)is >> e;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, vector<T> v) {
    os << "{";
    for (T &e:v)os << e << (v.size() - (int) (&e - &v[0]) > 1 ? ", " : "");
    os << "}";
    return os;
}

void _DEBUG() {}

template<typename H, typename... T>
void _DEBUG(H a, T...b) {
    cerr << a << (sizeof...(b) ? "," : "\n");
    _DEBUG(b...);
}

inline void in() {}

template<typename H, typename... T>
void in(H &a, T &... b) {
    cin >> a;
    in(b...);
}

inline void out() {}

template<typename H, typename... T>
void out(H a, T... b) {
    cout << a << (sizeof...(b) ? " " : "\n");
    out(b...);
}

template<class T>
void resz(int n, T &v) { v.resize(n); }

template<class H, class... T>
void resz(int n, H &a, T &... b) {
    a.resize(n);
    resz(n, b...);
}

template<typename V, typename H>
void resize(vector<V> &v, const H a) { v.resize(a); }

template<typename V, typename H, typename... T>
void resize(vector<V> &v, const H &a, const T... b) {
    v.resize(a);
    for (auto &v:v) resize(v, b...);
}

const int INF = 1LL << 55;
const int MOD = 1000000007;
const double EPS = 1e-8;

/*------------end of definitions------------*/

string S;

signed main() {

    in(S);
    if (S == "Sunny") {
        out("Cloudy");
    } else if (S == "Cloudy") {
        out("Rainy");
    } else {
        out("Sunny");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

ll f(vector<ll> &a){
    vector<ll> sums(61);
    ll len=a.size();
    rep(i,len){
        bitset<61> now(a[i]);
        rep(j,61){
            sums[j]+=now[j];
        }
    }
    
    ll ans=0;
    ll pows=1;
    rep(i,61){
        ans+=((((len-sums[i])%big)*sums[i])%big*pows)%big;
        ans%=big;
        pows*=2;
        pows%=big;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    /*a xor b==a+b-2*(a&b)
    a&b+a&c+...
    */
   ll ans=0;
   rep(i,n)ans=(ans+a[i]*(n-1))%big;
   cout << f(a) << endl;
}


Measured memory_bytes: 5500
#include <cstdio>

int main(){
  int i,j,n,a[10][10],b[10],c[10],sum;
  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    sum = 0;

    for(i=0;i<n;i++){
      b[i] = 0;
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	b[i] += a[i][j];
	sum += a[i][j];
      }
    }
    for(i=0;i<n;i++){
      c[i] = 0;
      for(j=0;j<n;j++){
	c[i] += a[j][i];
      }
    }

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	printf("%5d",a[i][j]);
      }
      printf("%5d\n",b[i]);
    }
    for(i=0;i<n;i++){
      printf("%5d",c[i]);
    }
    printf("%5d\n",sum);

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005

// it's swapnil07 ;)

signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n, k; cin>>n>>k;
    string s; cin>>s;
    s[k-1]=s[k-1]+32;
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const int M=3010;
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	long long ret=0;
	long long ks=1;
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		printf("? %d %d %d %d\n",i,j,i,j);
		fflush(stdout);
		int t;
		scanf("%d",&t);
		if(t)ret=(ret+ks)%d;
		ks=ks*2%d;
	}
	char *p = new char[1000000];
	printf("! %lld\n",ret);
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> dp(n + 1, 0);
    rep(i, n) dp[i + 1] = (dp[i] + a[i] - 1) % k;
    map<int, vector<int>> m;
    rep(i, n + 1) m[dp[i]].push_back(i);
    ll ans = 0;
    // rep(i, n + 1) printf("%d%s", dp[i], (i == n) ? "\n" : " ");
    for (auto x : m) {
        auto v = x.second;
        rep(i, sz(v)) {
            auto it = lower_bound(all(v), v[i] + k);
            int idx = it - v.begin() - 1;
            ans += idx - i;
            // printf("x.first=%d, idx=%d, i=%d\n", x.first, idx, i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
vector<pair<in,in> > cp;
const in mdl=1000000007;
in ab(in a){
  return a<0?-a:a;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  in t;
  for(in z=-1;z<=1;z+=2){
    forn(i,n){
      cin>>t;
      cp.PB(MP(t,z));
    }
  }
  sort(all(cp));
  in w=1;
  in sf=0;
  forv(i,cp){
    if(cp[i].second*sf<0)
      w=w*ab(sf)%mdl;
    sf+=cp[i].second;
  }
  cout<<w<<endl;
  return 0;
}


Measured memory_bytes: 4464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < S.Length - 2; i++)
            {
                if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
                {
                    count++;
                }
            }
            Console.WriteLine(count.ToString());
        }
    }
}


Measured memory_bytes: 11092