akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

double  EPS=1e-5;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0.0;
	return a+b;
}

struct Point{
	double x,y,z;
	Point(double xx=0.0,double yy=0.0,double zz=0.0){
		x=xx;
		y=yy;
		z=zz;
	}
	Point operator + (Point p){
		return Point(add(x,p.x),add(y,p.y),add(z,p.z));
	}
	Point operator - (Point p){
		return Point(add(x,-p.x),add(y,-p.y),add(z,-p.z));
	}
	Point operator * (double d){
		return Point(x*d,y*d,z*d);
	}
	Point operator / (double d){
		return Point(x/d,y/d,z/d);
	}
};

typedef Point Vector;

double norm(Vector a){
	return add(a.x*a.x,add(a.y*a.y,a.z*a.z));
}

double abs(Vector a){
	return sqrt(norm(a));
}

double dot(Vector a,Vector b){
	return add(a.x*b.x,add(a.y*b.y,a.z*b.z));	
}

struct Segment{
	Point p1,p2;
	Segment(Point pp1=Point(),Point pp2=Point()){
		p1=pp1;
		p2=pp2;
	}
};

typedef Segment Line;

class Circle{
public:
	Point c;
	double r;
	Circle(Point cc=Point(),double rr=0.0){
		c=cc;
		r=rr;
	}
};

bool intersect(Segment s,Circle cir){
	if(abs(s.p2-cir.c)<cir.r && abs(s.p1-cir.c)<cir.r)return false;
	Vector v=s.p2-s.p1,c=cir.c-s.p1;
	if(dot(v,c)<0.0)return abs(c)<cir.r;
	if(dot(v,c)>norm(v)){
		Vector rv=s.p2-cir.c;
		return norm(rv)<pow(cir.r,2);
	}else{
		double len=norm(c)-pow(dot(v,c),2)/norm(v);
		return len<pow(cir.r,2);
	}
}


int n,m,r;
Circle s[2001];
Point t[16];
double score[16];
int out[2001];
Point e;
int main(void){
	while(1){
		scanf("%d %d %d",&n,&m,&r);
		if(n+m+r==0)break;
		memset(out,0,sizeof(out));
		for(int i=0;i<n;i++){
			scanf("%lf %lf %lf %lf",&s[i].c.x,&s[i].c.y,&s[i].c.z,&s[i].r);
		}
		for(int i=0;i<m;i++){
			scanf("%lf %lf %lf %lf",&t[i].x,&t[i].y,&t[i].z,&score[i]);
		}
		scanf("%lf %lf %lf",&e.x,&e.y,&e.z);
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(intersect(Segment(t[j],e),s[i]))out[i]+=(1<<j);
			}
		}
		double res=0.0;
		for(int i=(1<<m)-1;i>=0;i--){
			double get=0.0;
			for(int j=0;j<m;j++){
				if(i>>j & 1)get+=score[j]/norm(t[j]-e);
			}
			if(get<=res)continue;
			int cnt=0;
			for(int j=0;j<n;j++){
				if((i & out[j])>0)cnt++;
			}
			if(cnt<=r){
				res=get;
			}
		}
		printf("%.10f\n",res);
	}
	return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    lint ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int dist[100001];
bool visited[100001];

vector<int>adj[100001];

void bfs(int at)
{
    queue<int>q;

    visited[at]=true;
    q.push(at);

    while(!q.empty())
    {
        int u=q.front();
        q.pop();

        for(auto to:adj[u])
        {
            if(!visited[to])
            {
                visited[to]=1;
                dist[to]=u;
                q.push(to);
            }
        }
    }
}
void dfs(int at,int d)
{
   visited[at]=1;

   for(auto to :adj[at])
   {
       if(!visited[to])
        dfs(to,++d);
   }

}

void solve()
{
   int n,m,u,v;

   cin>>n>>m;

   while(m--)
   {
       cin>>u>>v;
       adj[u].push_back(v);
       adj[v].push_back(u);
   }

   int comp=0;

   for(int i=1;i<=n;i++)
   {
       if(!visited[i])
       {
           comp++;
           dfs(i,0);
       }
   }

   if(comp==1)
   {
       cout<<"Yes\n";

       for(int i=1;i<=n;i++)
        visited[i]=0;

       bfs(1);
       for(int i=2;i<=n;i++)
        cout<<dist[i]<<"\n";
   }
   else
   {
       cout<<"No\n";
   }

}


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

    solve();
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define Loop(i, a, b) for(int i = a ; i < b ; ++i)
#define loop(i, n) Loop(i, 0, n)
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define vl vector<ll>
#define vvl vector<vl>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vvll vector<vll>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18+5
#define inf 1e9+5
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

template <typename T> T max(T a, T b, T c){ return max(a, max(b, c));}
template <typename T> T min(T a, T b, T c){ return min(a, min(b, c));}

const int M = 1e9+7; //check
ll lcm(ll a, ll b)
{
	return a*b/__gcd(a,b);
}
int main() {
	_69e27;
	ll n, m;
	scanf("%lld %lld", &n, &m);
	vl v(n);
	loop(i, n) scanf("%lld", &v[i]);
	int two = -1;
	ll rest = -1;
	loop(i, n)
	{
		ll temp = v[i];
		int cur = 0;
		while( temp%2 == 0 )
		{
			temp /= 2;
			++cur;
		}
		if(two == -1)
		{
			two = cur;
			rest = temp;
		}
		else if(cur != two) return printf("0"), 0;
		else rest = lcm(rest, temp);
	}
	ll num = rest * (1LL*pow(1LL*2, 1LL*two));
	ll ans = 2*m/num;
	debug() << trace(num) trace(ans) trace(two) trace(rest);
	if(ans%2) ans = ans/2+1;
	else ans = ans/2;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
def get_int_array
    gets.strip.split(' ').map(&:to_i)
end

def get_float_array
    gets.strip.split(' ').map(&:to_f)
end

a,b,n = get_int_array

if n < b
    puts (a * n / b).floor - a * (n / b).floor
else
    puts (a * (b - 1) / b).floor - a * ((b - 1) / b).floor
end

Measured memory_bytes: 14232
import numpy as np


def solve(string):
    n, k, *xyc = string.split()
    k = int(k)
    l = 2 * int(k)
    xy = [(int(x) % l, int(y) % l) if c == "W" else (int(x) % l, (int(y) + k) % l)
          for x, y, c in zip(xyc[::3], xyc[1::3], xyc[2::3])]
    ans = [[0 for j in range(l + 0)] for i in range(l + 0)]
    for _x, _y in xy:
        if (_x - k + 0.5) * (_y - k + 0.5) > 0:
            _x %= k
            _y %= k
            ans[_x][_y] += 2
            ans[_x + k][_y] -= 2
            ans[_x][_y + k] -= 2
            ans[_x + k][_y + k] += 2
            ans[_x + k][0] += 1
            ans[0][_y + k] += 1
            ans[0][0] += 1
            ans[_x][0] -= 1
            ans[0][_y] -= 1
        else:
            _x %= k
            _y %= k
            ans[_x][_y] -= 2
            ans[_x + k][_y] += 2
            ans[_x][_y + k] += 2
            ans[_x + k][_y + k] -= 2
            ans[_x + k][0] -= 1
            ans[0][_y + k] -= 1
            ans[_x][0] += 1
            ans[0][_y] += 1
    return str(np.asarray(ans).cumsum(axis=1).cumsum(axis=0).max())


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 136804
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;


//配列の要素を順番に出力
void trace(int A[], int N) {
    int i;
    
    for (i = 0; i < N; i++) {
        if (i > 0)    printf(" ");    //隣接する要素の間に1つの空白を出力
        printf("%d", A[i]);
    }
    printf("\n");
}


//挿入ソート
void insertionSort(int A[], int N)       //N個の要素を含む0-オリジンの配列A
{
    //i: 未ソートの部分列の先頭を示すループ変数
    //v: A[i]の値を一時的に保持しておく変数
    //j: ソート済みの部分列からvを挿入するためのイチを探すループ変数
    int v, i, j;          

    for (i = 1; i < N; i++) {
        v = A[i];          
        j = i - 1;

        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
       trace(A, N);
    }
}

int main() {
    int N, i, j;
    int A[100];

    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    trace(A, N);
    insertionSort(A, N);

    return 0;   
}


Measured memory_bytes: 3224
h,w = map(int,input().split())
l = []
for i in range(h):
  x = list(input())
  if "#" in x:
    l.append(x)
for j in range(w):
  if all(l[i][j] == "." for i in range(len(l))):
    for i in range(len(l)):
      l[i][j] = ""
for i in range(len(l)):
  print(''.join(l[i]))

Measured memory_bytes: 3064
# input 
n, m = map(int, input().split(" "))
ck = {}

for i in range(0, n) :
    ck[i] = list(map(int, input().split(" ")))

# calculate for 2^3 patterns 
curmaxsum = 0

for mx in [-1, 1] :
    for my in [-1, 1] :
        for mz in [-1, 1] :
            # do foreach element in list 
            li_sum = {}
            for k, li in ck.items() :
                sum_tmp = (li[0] * mx) + (li[1] * my) + (li[2] * mz)
                li_sum[k] = sum_tmp
                
            # sort li_sum by value 
            counter = 0
            tmpsum = 0
            for k, v in sorted(li_sum.items(), key = lambda x : x[1], reverse = True) :
                if counter <= m - 1 :
                    tmpsum += v
                    counter += 1
                    
            # print("DBG_tmpsum : ", tmpsum)
            
            if tmpsum > curmaxsum :
                curmaxsum = tmpsum
                
print(curmaxsum)

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 20

using namespace std;

int n, m;
int v[maxn+5][maxn+5], d[maxn*maxn+5][maxn*maxn+5];

bool ok (int a, int b) {
  return a>=0 && a<n && b>=0 && b<m;
}

int to (int a, int b) {
  return a*m+b;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  int i, j, z;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    for (j = 0; j < m; j++)
      if (s[j] == '#') v[i][j] = 1;
  }
  for (i = 0; i < n*m; i++)
    for (j = 0; j < n*m; j++) d[i][j] = inf;
  for (i = 0; i < n*m; i++) d[i][i] = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (!v[i][j]){
        if (ok(i-1,j) && !v[i-1][j]) d[to(i,j)][to(i-1,j)] = 1;
        if (ok(i+1,j) && !v[i+1][j]) d[to(i,j)][to(i+1,j)] = 1;
        if (ok(i,j-1) && !v[i][j-1]) d[to(i,j)][to(i,j-1)] = 1;
        if (ok(i,j+1) && !v[i][j+1]) d[to(i,j)][to(i,j+1)] = 1;
      }
  for (z = 0; z < n*m; z++)
    for (i = 0; i < n*m; i++)
      for (j = 0; j < n*m; j++)
        if (i != j) d[i][j] = min(d[i][j], d[i][z]+d[z][j]);
  int ans = 0;
  for (i = 0; i < n*m; i++)
    for (j = 0; j < n*m; j++)
      if (!v[i/m][i%m] && !v[j/m][j%m]) ans = max(ans, d[i][j]);
  cout << ans;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define M 1e9 + 5
#define C 998244353
#define pi 3.14159265359
#define loop(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define rloop(i,a,b) for(ll i = ll(a); i >= ll(b); --i)
#define sloop(i,a) for (std::set<ll>::iterator i = a.begin(); i != a.end(); ++i)
#define pb push_back
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long int ull;

int solve(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll u = abs(x/d);
    // k -= u;
    // x -= u*d;
    if(u>=k){
        if(x>=0)
            cout << x - k*d << "\n";
        else{
            cout << -x - k*d << "\n";
        }
        return 0;
    }
    k -= u;
    if(x>=0)
        x -= u*d;
    else{
        x += u*d;
    }
    // if(k<=0){
    //     cout << x << "\n";
    //     return 0;
    // }
    if(k%2==0){
        cout << abs(x) << "\n";
    }
    else{
        cout << abs(d-abs(x)) << "\n";
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    loop(f,0,t){    
        solve();
    }   
}

Measured memory_bytes: 3644
n,m = $stdin.gets.split.map(&:to_i)
ary = []
k = []
m.times do |i|
  k[i] = $stdin.getc.to_i
  ary[i] = $stdin.gets.split.map(&:to_i)
end
p = $stdin.gets.split.map(&:to_i)
result = 0
(2**n).times do |i|
  i = i.to_s(2).rjust(n)
  flg = false
  m.times do |j|
    if flg
      break
    end
    xor = 0
    k[j].times do |l|
      xor ^= i[ary[j][l]-1].to_i
    end
    if xor != p[j]
      flg = true
      break
    end
  end
  if !flg 
    result += 1
  end
end
 
puts result

Measured memory_bytes: 3836
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
const int MaxN = 1e3;

int a[MaxN + 5];

int main()
{
	int n,vis,m,x;
	while(~scanf("%d %d",&n,&x))
	{
		for(int i = 1;i <= n;i++) 
		{
			scanf("%d",&a[i]);
			x -= a[i];
		}
		sort(a + 1, a + 1 + n);
		printf("%d\n",x/a[1] + n);
	}
	return 0;
}

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

int a[101];
int main(){
	int n,x;
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>x;
		a[x]=1;
	}
	int s=0;
	for(int i=1; i<=100; i++){
		if(a[i]==1){
			s++;
		}
	}
	cout<<s<<endl;
	
	return 0;
}

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

int main() {
    int A, P;
    cin >> A >> P;
    P = P + A*3;
    cout << P/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
   long long n;
   cin>>n;
   vector<long long> dp(n+1);
   int m;
   dp[0]=0;
   dp[1]=1;
   dp[2]=2;
   cin>>m;
   for(int i=0;i<m;i++)
   {
   	 int j;
   	 cin>>j;
   	 dp[j]=-1;
   }
   
   if(dp[1]==-1 && dp[2]!=-1)
   {
   	 dp[1]=0;
   	 dp[2]=1;
   }

   if(dp[1]==-1 && dp[2]==-1)
   {
   	 dp[1]=0;
   	 dp[2]=0;
   	 cout<<0<<" ";
   	 return;
   }

   if(dp[2]==-1)
   {
   	 dp[2]=0;
   }


   for(int i=3;i<=n;i++)
   {
   	  if(dp[i]==-1)
   	  	{ dp[i]=0;
   	  		continue;
   	  	}

   	  dp[i]=(dp[i-1]+dp[i-2])%1000000007;
   }

   cout<<dp[n]<<"";
}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int main(){
    int n, x; cin >> n >> x;
    int a[n];
    
    rep(i,n) cin >> a[i] ;
    
    sort(a,a+n);
    
    
    
    int res=0;
    for(int i=0;i<n;i++){
        
        if(x>= a[i]){
            if(i==n-1 && x> a[i])
                break;
            res++;
            x-=a[i];
        }
    }
    
    cout << res << endl;
}












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

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<ll>a(n + 1, 0);
	ll sum = 0;
	for (int i = 1; i <= n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 1; i < n; i++)a[i + 1] += a[i];

	ll ans = 1e12;
	for (int i = 1; i < n; i++) {
		ll snuke = a[i] - a[0], arai = sum - snuke;
		ans = min(ans, abs(snuke - arai));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int main(void){
  char s[5],t[5];
  scanf("%s",s);
  scanf("%s",t);
  int c=0;
  for(int i=0;i<strlen(s);i++){
    if(s[i]==t[i]){
      c++;
    }
  }
  
  printf("%d",c);
  return 0;
}
    


Measured memory_bytes: 1708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}
		long start =1000;
		for (int i=0;i<N;i++) {
			int now = i;
			while (now<N-1&&A[now+1]<=A[now]) {
				now++;
			}
			if (now==N-1) {
				break;
			}
			long buy = start /A[now];
			start = start - buy*A[now];
			while (now<N-1&&A[now+1]>A[now]) {
				now++;
			}
			start += buy*A[now];
			i = now;
		}
		System.out.println(start);
	}
}

Measured memory_bytes: 35740
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    li n;
    cin >> n;
    map<string,int> freq;
    for(int i=0;i<n;i++) {
        string s;
        cin >> s;
        freq[s]++;
    }
    int mxcnt = 0;
    for(auto e : freq) {
        mxcnt = max(mxcnt, e.second);
    }
    vector<string> ans;
    for(auto e : freq) {
        if(e.second==mxcnt) {
            ans.pb(e.first);
        }
    }
    sort(ans.begin(),ans.end());
    for(string s : ans) {
        cout << s << "\n";
    }
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int k=c/b;
    int m=a/d;
    if(c%b!=0){
        k++;
    }
    if(a%d!=0){
        m++;
    }

    if(k<=m){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long long N, M;
    vector<long long> X, Y;

    cin >> N >> M;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        X.push_back(t);
    }
    for (long long i = 0; i < M; i++)
    {
        long long t;
        cin >> t;
        Y.push_back(t);
    }

    long long x = 0, y = 0;
    for (long long i = 0; i < N - 1; i++)
    {
        x += (X[i + 1] - X[i]) * (i + 1) % MOD * (N - i - 1) % MOD;
        x %= MOD;
    }
    for (long long i = 0; i < M - 1; i++)
    {
        y += (Y[i + 1] - Y[i]) * (i + 1) % MOD * (M - i - 1) % MOD;
        y %= MOD;
    }

    cout << (x * y) % MOD << endl;
}

Measured memory_bytes: 2548
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define int long long

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

struct SegmentTree{
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v){
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val){
        x += (n - 1);
        node[x] = val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    long long getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        long long vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        long long vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        
        return max(vl, vr);
    }
};

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

    int n; cin>>n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    SegmentTree seg(vector<int>(n+1, 0));

    for(int i=0; i<n; i++){
        int rangemax = seg.getmax(0, h[i]);
        seg.update(h[i], rangemax + a[i]);
    }

    int ans = seg.getmax(0, n+1);

    cout << ans << endl;
}

Measured memory_bytes: 9088
n, m = map(int, input().split())
res = [[False for _ in range(m)] for _ in range(n)]

for i in range(n):
    o = list(map(int, input().split()))
    for j, x in enumerate(o):
        if j != 0:
            res[i][x - 1] = True

ans = 0
res = list(zip(*res))

for i, x in enumerate(res):
    if all(x):
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll a = n%k;
    PRINT(min(a,abs(a-k)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long k,q;
  cin >> k >> q;
  vector<long long> d(k);
  for (int i = 0; i < k; i++){
    cin >> d[i];
  }
  int n,x,m;
  //クエリ処理
  for (int i = 0; i < q; i++){
    cin >> n >> x >> m;
    //s: d%mの累積和
    vector<long long> s(k + 1);
    s[0] = 0;
    for (int i = 0; i < k; i++){
      s[i + 1] = s[i] + d[i] % m;
    }
    vector<bool> D(k);
    for (int i = 0; i < k; i++){
      if (d[i] % m == 0){
        D[i] = true;
      } else {
        D[i] = false;
      }
    }
    //M: 1-Dの累積和
    vector<int> M(k + 1);
    M[0] = 0;
    for (int i = 0; i < k; i++){
      if (D[i]){
        M[i + 1] = M[i];
      } else {
        M[i + 1] = M[i] + 1;
      }
    }
    long long A = (n - 1) / k * M[k] + M[(n - 1) % k];
    long long C = (x % m + (n - 1) / k * s[k] + s[(n - 1) % k]) / m;
    cout << A - C << endl;
  }
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(n):
  ans += b[a[i]-1]
  
  if i >= 1:
    if a[i-1] + 1 == a[i]:
      ans += c[a[i]-2]

print(ans)

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

long long n, k;
vector<long long> a;

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int x;
      cin >> x;
      ++a[x - 1];
    }
  }
  long long cnt = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] == 0) ++cnt;

  cout << cnt << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  long long int a[n], res = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int max = a[0];
  for(int i = 1; i < n; i++) {
    if(a[i] > max) {
      max = a[i];
    } else {
      res += max - a[i];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 5140
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Function
 
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
toTuple (x : y : _) = (x, y)
 
main = do
    [n,m] <- getIntList
    pys <- flip zip [1..] . map toTuple <$> replicateM m getIntList
    let ans = map snd . sort . concatMap (zipWith cityNum [1..]) . groupBy ((==) `on` (fst . fst)) $ sort pys
    mapM_ putStrLn ans
 
cityNum k ((p,y),i) = (i , ((six p) ++ (six k)))
    where six a = let n = length (show a) in drop n ("000000" ++ (show a))

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

int main() {
  int n;
  cin >> n;
  int l[n];
  for(int i = 0; i < n; i++) cin >> l[i];
  sort(l, l + n);
  int sum = 0;
  for(int i = 0; i < n - 1; i++) {
    sum += l[i];
  }
  if(sum > l[n - 1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++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 ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string a,b,c;cin>>a>>b>>c;
    int A=0,B=0,C=0,turn=0;
    while(true){
        if(turn==0){
            if(A==a.size()){
                cout << 'A' << endl;
                return 0;
            }
            char t = a[A++];
            turn = t - 'a';
        } else if(turn==1){
            if(B==b.size()){
                cout << 'B' << endl;
                return 0;
            }
            char t = b[B++];
            turn = t - 'a';
        } else {
            if(C==c.size()){
                cout << 'C' << endl;
                return 0;
            }
            char t = c[C++];
            turn = t - 'a';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
std::bitset<1000001> used;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int64_t s = 0;
	in >> s;
	int i = 2;
	used[s] = true;
	for (;;++i)
	{
		if (s % 2) {
			s = s * 3 + 1;
		}
		else {
			s = s / 2;
		}

		if (used[s]) {
			out << i << endl;
			break;
		}
		used[s] = true;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int D,E;
int main(){
  while(1){
    cin>>D>>E;
    if(D==0&&E==0)break;
    double ans=1e9;
    for(int x=0;x<=D;x++){
      int y=D-x;
      double dist=sqrt((double)y*y+x*x);
      ans=min(ans, abs(E-dist));
    }
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1196
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
    
for i in range(n-m+1):
    if b[0] in a[i]:
        p=[]
        for j in range(n-m+1):
            if b[0]==a[i][j:j+m]:
                p.append(j)
        for j in range(1,m):
            for k in p:
                if b[j]!=a[i+j][k:k+m]:
                    p.remove(k)
        if p!=[]:
            print("Yes")
            import sys
            sys.exit()
print("No")




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

int main(void){

    int n;
    cin >> n;
    
    unsigned long long sum = 0;
    for(int i=0; i<=n; i++) {
        if( !(i%3==0||i%5==0) ) sum += i;
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
    int a, b, o, t;
    cin >> a >> b;
    int sum = 0;
    for (int i = a; i<=b; i++) {
        o = i % 10;
        t = (i / 10) % 10;
        if ((i / 10000) == o && ((i / 1000) % 10) == t) {
            sum += 1;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int k = s.nextInt();

			double ans = 0;
			double a = 1 / (double) n;
			for (int i = 0; i < n; i++) {
				int count = count(i + 1, k);
				ans += a * Math.pow(0.5d, count);
			}
			System.out.println(ans);
		}
	}

	private static int count(int start, int max) {
		int count = 0;
		for (int i = start; i < max; i = i * 2) {
			count++;
		}
		return count;
	}

}

Measured memory_bytes: 21588
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char in[1001][1002];
char done[1001][1002];
int dist[1001][1002];
int H,W,N;
int main() {
	int a=0,b=0;
	cin >> H >> W >> N;
	for(int i=1;i<=H;i++){
		cin >> (in[i]+1);
		for(int j=1;j<=W;j++){
			if(in[i][j]=='S'){
				a=i;
				b=j;
			}
		}
	}
	int ret=0;
	for(int t=1;t<=N;t++){
		queue<P> q;
		q.push(P(a,b));
		done[a][b]=t;
		dist[a][b]=0;
		bool found=false;
		while(!found){
			int i=q.front().first;
			int j=q.front().second;
			q.pop();
			int dx[]={0,-1,0,1};
			int dy[]={-1,0,1,0};
			for(int k=0;k<4;k++){
				int x=i+dx[k];
				int y=j+dy[k];
				if(in[x][y]!=0&&in[x][y]!='X'&&done[x][y]<t){
					done[x][y]=t;
					dist[x][y]=dist[i][j]+1;
					q.push(P(x,y));
					if(in[x][y]==t+'0'){
						a=x;
						b=y;
						ret+=dist[x][y];
						found=true;
						break;
					}
				}
			}
		}
	}
	cout << ret << endl;

}

Measured memory_bytes: 7096
ans={}
n=int(input())
for i in range(n):
    a = input()
    if a in ans:
        ans[a]+=1
    else:
        ans[a] = 1
m=int(input())
for i in range(m):
    a = input()
    if a in ans:
        ans[a]-=1
    else:
        ans[a] = -1
ans = sorted(ans.items(), key=lambda x: x[1], reverse=True)
if ans[0][1] < 0:
    print(0)
else:
    print(ans[0][1])

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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    double a, b;
    cin >> a >> b;
    cout << ceil((b-1)/(a-1)) << endl;
}

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    set<int> p, q;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a == 1)p.insert(b);
        if (b == n)q.insert(a);
    }

    bool ret = false;
    for (auto x:p) {
        if (q.find(x) != q.end())ret = true;
    }
    cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0) {
		cout << "Possible" << endl;
	}
	else if (b % 3 == 0) {
		cout << "Possible" << endl;
	}
	else if ((a+b)% 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    vl s(n);rep(i,n)cin>>s[i];
    ll q;cin>>q;
    vl t(q);rep(i,q)cin>>t[i];

    ll ans=0;
    rep(i,q){
        ll hi=n,lo=-1;
        while(hi-lo>1){
            ll mid=(hi+lo)/2;
            if(s[mid]==t[i]){
                ans++;
                break;
            }
            if(s[mid]<t[i])lo=mid;
            else hi=mid;
        }
    }
    cout<<ans<<endl;
}

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



Measured memory_bytes: 3792
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
void chmin(int &a,int b){if(a>b) a=b;}

int N;

ll gcd(ll x, ll y) {
  while (y != 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}

int main()
{
    int l;
    int i=0,ans=0;
    int prev;
    cin>>N;
    vector<int> a;
    while (cin >> l) {
        a.push_back(l);
        i++;
        if (i >= N) {
            break;
        }
    }
    prev=a[0];
    for(int i=1;i<N;i++)
    {
        int bai=lcm(prev,a[i]);
        prev=bai;
    }
    for(int i=0;i<N;i++)
    {
        ans+=a[i]-1;
    }
    cout<<ans<<endl;

}

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

int N, M;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  
  cin >> N >> M;
  if(N == M){
    cout << "Yes" <<endl;
  } else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    while(a>0&&c>0){
        c-=b;
        if(c<=0){
            break;
        }
        a-=d;
    }

    if(a>0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr long long MAX_N = 100100;

ll fact[MAX_N];             // N!
ll fact_inv[MAX_N];         // N!の逆元

// O(log n)でx^n(modを法とする)
ll mod_pow(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res = (res*x)%mod;
        x = (x*x)%mod;
        n>>=1;
    }
    return res;
}

// O(log mod)で x^-1 を計算(法をmodとする)
ll invp(ll x,ll mod){
    return mod_pow(x,mod-2,mod);
}

// x / y をmodを法として行う
ll div_mod(ll x,ll y,ll mod){
    return x * invp(y,mod) % mod;
}

void init(){
    fact[0]=1;
    for(int i=1;i<MAX_N;i++) fact[i]=(fact[i-1]*i)%mod;
    for(int i=0;i<MAX_N;i++) fact_inv[i]=invp(fact[i],mod);
}

ll calc[MAX_N];
ll calcsum[MAX_N];

int main(){
    init();
    ll N; 
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    for(int i=0;i<=N;i++){
        if(i==0){
            calc[i] = 0;
        }else{
            calc[i] = div_mod(fact[N],i+1,mod);
        }
    }

    calcsum[0] = 0;
    for(int i=1;i<=N;i++){
        calcsum[i] = calcsum[i-1] + calc[i];
    }


    ll ans = 0;
    for(int i=0;i<N;i++){
        const ll L = i;
        const ll R = N - L - 1;

        ll calc = fact[N] + calcsum[L] + calcsum[R];
        calc %= mod;

        ans += calc * A[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


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

const int N_INF = (1 << 31);

int main(){
	int n, max = N_INF, sum;
	vector< vector< int > > mat;
	vector< vector< int > > table;
	
	cin >> n;
	
	mat.resize(n);
	for(int i = 0; i < n; ++i){
		mat[i].resize(n);
		for(int j = 0; j < n; ++j){
			cin >> mat[i][j];
		}
	}
	
	table.resize(n + 1);
	for(int i = 0; i <= n; ++i){
		table[i].resize(n + 1);
		
		if(i >= 1){
			table[i][1] = mat[i - 1][0];
			
			for(int j = 1; j <= n; ++j){
				table[i][j] = table[i][j - 1] + mat[i - 1][j - 1];
			}
		}
	}
	
	for(int j = 1; j <= n; ++j){
		for(int i = 1; i <= n; ++i){
			table[i][j] += table[i - 1][j];
		}
	}
	
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int k = i; k <= n; ++k){
				for(int l = j; l <= n; ++l){
					
					sum = table[k][l] - table[i - 1][l] - table[k][j - 1] + table[i - 1][j - 1];
					
					if(sum > max) max = sum;
				}
			}
		}
	}
	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}


ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
} 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
//O(r)
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
ll inv_mod(ll n){
    return pow_mod(n,mod-2);
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    vector<pair<ll,ll>> v;
    ll after=0;
    rep(i,n){
        pair<ll,ll> p;
        cin>>p.first>>p.second;

        if(p.first==0 and p.second==0){
            after++;
        }
        else{
            v.push_back(p);
        }
    }
    n-=after;

    // やくぶｎ，(分子，分母)　負なら，分子を負
    auto f=[](ll si,ll bo){
        if(si==0)return make_pair(0ll,1ll);
        if(bo==0)return make_pair(1ll,0ll);
        ll g=gcd(abs(si),abs(bo));
        si/=g;bo/=g;

        if(si>0 and bo>0) return make_pair(si,bo);
        if(si<0 and bo<0) return make_pair(abs(si),abs(bo));
        else return make_pair(-abs(si),abs(bo));
    };

    map<pair<ll,ll>,ll> cnt;
    for(int i=0;i<n;i++){
        cnt[f(v[i].second,v[i].first)]++;  
        auto p=f(v[i].first,v[i].second);
        p.first=-p.first;
    }

    vector<pair<ll,ll>> yabai;
    for(auto pp:cnt){
        auto p=pp.first;
        ll lf=pp.second;

        if(lf==0) continue;

        pair<ll,ll> target;
        if(p.first<0) target=make_pair(p.second,-p.first);
        else target=make_pair(-p.second,p.first);

        if(cnt.count(target)){

            if(cnt[target]) yabai.push_back(make_pair(lf,cnt[target]));
            cnt[target]=0;
        }
    }

    ll s=0;
    for(auto p:yabai) s+=p.first+p.second;
    ll ans=pow_mod(2,n-s);
    for(auto p:yabai){
        ll res=(pow_mod(2,p.first+p.second)+mod-(pow_mod(2,p.first)-1)*(pow_mod(2,p.second)-1)%mod)%mod;
        ans=ans*res%mod;
    }
    ans+=after-1;
    if(ans<0) ans+=mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18636
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
char s[1000009], t[10009];
int main() {
	scanf("%s%s", s, t);
	unsigned long long hs = 0, ht = 0, pw = 1;
	int sl = strlen(s), tl = strlen(t);
	for (int i = 0; i < tl; i++) {
		hs = hs * 257 + s[i];
		ht = ht * 257 + t[i];
		pw *= 257;
	}
	for (int i = tl; i <= sl; i++) {
		if (hs == ht) printf("%d\n", i - tl);
		hs = hs * 257 + s[i] - s[i - tl] * pw;
	}
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits.h>
#include <map>
#define MAXN 100000
#define Amari 1000000007
#define p pair <int,int>
using namespace std;
multimap <int, int> ship;
bool clear = false; 
vector <int> buckets(100004,0);
int main(int argc,char const* argv[])
{
  int n;
  cin >> n;
  vector <long long> a(n,0);
  vector <long long> b(n,0);
  long long answer=0;
  long long count=0;
  for(int i=0;i<n;i++)
    {
      cin >> a[i] >> b[i];
    }
  for(int i=n-1;i>=0;i--)
    {
      a[i]+=answer;
      long long temp=a[i]%b[i];
      if(temp !=0)answer+=(b[i]-temp);
    }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 2176
#125
from fractions import gcd
n = int(input())
a = [int(x) for x in input().split(' ')]

m_r = [0]
for i in range(n-1):
    m_r.append(gcd(m_r[-1], a[i]))

m_l = [0]
for i in range(1, n):
    m_l.append(gcd(m_l[-1], a[-i]))

m = []
for i in range(n):
    m.append(gcd(m_r[i], m_l[-i-1]))
print(max(m))

Measured memory_bytes: 16132
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	string S;
	cin >> S;
	int N = S.length();

	int ans, cnt = 0;
	//初手黒
	for (int i = 0; i < N; i++) {
		if (i % 2 != S[i] - '0') cnt++;
	}
	ans = cnt;

	//初手白
	cnt = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == S[i] - '0') cnt++;
	}

	ans = min(ans, cnt);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<vector>
#include<climits>
#define ll long long 
using namespace std;
ll dp[3001][3001][2];
ll solve(vector<int> &v,int i,int j,int turn)
{
    if(i>j) return 0;
    if(dp[i][j][turn]!=-1)
    {
        return dp[i][j][turn];
    }
    if(turn==1)
    {
        return dp[i][j][turn]=max(v[i]+solve(v,i+1,j,0),v[j]+solve(v,i,j-1,0));
    }
    else
    {
        return dp[i][j][turn]=min(solve(v,i+1,j,1),solve(v,i,j-1,1));
    }
}
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        sum+=v[i];
    }
    memset(dp,-1,sizeof(dp));
    ll sc_x=solve(v,1,n,1);
    ll sc_y=sum-sc_x;
    cout<<sc_x-sc_y<<'\n';
    return 0;
}

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

int p[100010];

int find(int n) {
	if (n == p[n]) return n;
	return p[n] = find(p[n]);
}

void merge(int a, int b) {
	a = find(a);
	b = find(b);

	if (a != b) p[b] = a;
}

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

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

	vector<int> arr(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		p[i] = i;
	}

	int a, b;
	while (m--) {
		cin >> a >> b;
		merge(a, b);
	}

	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if (find(i) == find(arr[i])) cnt++;
	}

	cout << cnt;
}

Measured memory_bytes: 1024