akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<climits>
#include<numeric>
using namespace std;
int main()
{
	int c[10][10],n,m,i,j,k,x,y,z;
	while(scanf("%d",&m),m)
	{
		for(i=0;i<10;++i)
			for(j=0;j<10;++j)
				c[i][j]=INT_MAX/2,c[i][i]=0;
		for(n=i=0;i<m;++i)
			scanf("%d%d%d",&x,&y,&z), c[x][y]=c[y][x]=z, n=max(n,max(x,y)+1);
		for(k=0;k<n;++k)
			for(i=0;i<n;++i)
				for(j=0;j<n;++j)
					c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
		x=INT_MAX,y=INT_MAX;
		for(i=0;i<n;++i)
			if(z=accumulate(c[i],c[i]+n,0),x>z)
				x=z,y=i;
		printf("%d %d\n",y,x);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int cnt[510][510];

int main(){
  int h,w;
  while(cin>>h>>w, h|w){
    vector<string> vec(h);
    rep(i,h) cin>>vec[i];
    fill(cnt[0], cnt[h], 0);
    rep(j,w) if(vec[0][j]=='.') cnt[0][j]=1;
    repl(i,1,h)rep(j,w){
      if(vec[i][j]=='.') cnt[i][j]=cnt[i-1][j]+1;
    }

    int res=0;
    rep(i,h){
      stack<pair<int,int>> s;
      s.push(mp(-1,-1)); //???????????§?¨?
      rep(j,w+1){
        if(s.top().fi < cnt[i][j]){
          s.push(mp(cnt[i][j], j));
        } else if(s.top().fi > cnt[i][j]){
          int pos = j;
          while(!s.empty() && cnt[i][j] < s.top().fi){
            auto p = s.top(); s.pop();
            res = max(res, p.fi*(j-p.se));
            pos = p.se;
          }
          s.push(mp(cnt[i][j], pos));
        }
      }
    }
    cout << res << endl;

  }

  return 0;
}

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

void trn(int *check,int a,int b,int c,int d);

int main(){
	int n;
	cin >> n;
	int dices[n][7];
	cin >> dices[0][1] >> dices[0][2] >> dices[0][3] >> dices[0][4] >> dices[0][5] >> dices[0][6];
	
	for(int h = 1;h < n;h++){
		cin >> dices[h][1] >> dices[h][2] >> dices[h][3] >> dices[h][4] >> dices[h][5] >> dices[h][6];
		
		for(int i = 0;i < 4;i++){
			if(dices[0][1] == dices[h][1]){
				for(int j = 0;j < 4;j++){
					if(dices[0][2] == dices[h][2]){
						i = 10;
						j = 10;
					}
					else trn(dices[h],2,4,5,3);
				}
			}
			else trn(dices[h],1,2,6,5);
		}
		for(int i = 0;i < 4;i++){
			if(dices[0][1] == dices[h][1]){
				for(int j = 0;j < 4;j++){
					if(dices[0][2] == dices[h][2]){
						i = 10;
						j = 10;
					}
					else trn(dices[h],2,4,5,3);
				}
			}
			else trn(dices[h],1,3,6,4);
		}
	}

	string ans = "Yes";
	for(int i = 0;i < n-1;i++){
		for(int j = i+1;j < n;j++){
			for(int k = 1;k < 7;k++){
				if(dices[i][k] == dices[j][k]){
					ans = "No";
				}
				else{
					ans = "Yes";
					break;
				}
			}
			if(ans == "No")break;
		}
		if(ans == "No")break;
	}
	cout << ans << "\n";
	
	return 0;
	}
	
	void trn(int *check,int a,int b,int c,int d){
		int tmp = check[a];
		check[a] = check[b];
		check[b] = check[c];
		check[c] = check[d];
		check[d] = tmp;
	}

Measured memory_bytes: 3224
s = list(str(input()))
t = int(len(s))
ans = 0
for i in range(t-1):
    if s[i] == s[i + 1]:
        if s[i + 1] == "1":
            s[i + 1] = "0"
            ans += 1
        else:
            s[i + 1] = "1"
            ans += 1

print(ans)


Measured memory_bytes: 3956
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector <int> p(a), q(b), r(c);
    cin >> p >> q >> r;
    sort(rall(p)), sort(rall(q)), sort(rall(r));
    vector <int> red(x), green(y);
    int bst = 0, cur = 0;
    for (int i = 0; i < x; ++i)
        red[i] = p[i], cur += p[i];
    for (int i = 0; i < y; ++i)
        green[i] = q[i], cur += q[i];
    sort(all(red)), sort(all(green));
    bst = max(bst, cur);
    int i = 0, j = 0; 
    for (int k = 0; k < min(c, x + y); ++k)
    {
        if (i == x)
        {
            cur -= green[j++];
            cur += r[k];
        }
        else if (j == y)
        {
            cur -= red[i++];
            cur += r[k];
        }
        else
        {
            if (red[i] < green[j])
            {
                cur -= red[i++];
                cur += r[k];
            }
            else
            {
                cur -= green[j++];
                cur += r[k];
            }
        }
        bst = max(bst, cur);
    }
    cout << bst;
    return 0;
}



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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	string ans;
	if (a + b > c + d) {
		ans = "Left";
	}
	else if (a + b == c + d) {
		ans = "Balanced";
	}
	else{
		ans = "Right";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include<chrono>
using namespace std::chrono; 
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
//#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	auto start = high_resolution_clock::now(); 
	cin>>n>>m;
	if(m<=2*n)
	{
		cout<<m/2;
		return 0;
		
	}
    ll ans=n;
	m-=(2*n);
	ans+=(m/4);
	cout<<ans;
	auto stop = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start); 
	//cout<<"\nRun time = ";
	//cout <<fixed<<setprecision(5)<<(long double)duration.count()/1000<<" //ms";
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,H = map(int,readline().split())
maxA = 0
B = [0] * N
for i in range(N):
  a,b = map(int,readline().split())
  B[i] = b
  if maxA < a:
    maxA = a

usefulB = []
for i in range(N):
  if B[i] > maxA:
    usefulB += [B[i]]

usefulB = sorted(usefulB,reverse = True)

cnt = 0
for b in usefulB:
  H -= b
  cnt += 1
  if H <= 0:
    print(cnt)
    break
else:
  cnt += (H + maxA - 1) // maxA
  print(cnt)

Measured memory_bytes: 9044
MODULO = 1_000_000_007


def main():
    N = int(input())
    A = [int(_x) for _x in input().split()]
    sums = [0]*N
    for i in reversed(range(N)):
        if (i == N-1):
            sums[i] = A[i]
        else:
            sums[i] = sums[i+1] + A[i]

    result = 0
    for i in range(N):
        if i == N-1:
            break
        result = (result + A[i] * sums[i+1]) % MODULO
    print(result)


main()


Measured memory_bytes: 31512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	int n,m;
	while(cin>>n>>m){
		if(!(n||m)) break;
		int t[20000]={0};
		for(int i=0;i<n+m; i++){
			cin >> t[i];
		}
		sort(t, t + n+m-1);
		int max = t[0];
		for(int i=1; i<n+m; i++){
			if(t[i]-t[i-1]>max) max = t[i]-t[i-1];
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 944
import bisect

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]

A.sort()
BC.sort(key=lambda x: x[1],reverse=True) 
ans=0
for j in range(M):
    if A[0]>=BC[j][1]:
        break
    else:
        b=BC[j][0]
        c=BC[j][1]
        R=bisect.bisect_left(A,c)
        n=len(A)
        if R>b:
            if n<=b:
                A=[]
                ans+=n*c
                break
            else:
                del A[0:b]
                ans+=b*c
        else:
            del A[0:R]
            ans+=R*c
    if len(A)==0:
        break        
print(sum(A)+ans)

Measured memory_bytes: 32980
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin >>n;
  int arr[n][3];
  int i,j,max1=0;
  for(i=0;i<n;i++)
    for(j=0;j<3;j++)
    {
      cin >>arr[i][j];
      max1=max(max1,arr[i][j]);
    }
  for(i=1;i<n;i++)
    for(j=0;j<3;j++)
    {
      if(j==0)
        arr[i][j]=arr[i][j]+max(arr[i-1][1],arr[i-1][2]);
      else if(j==1)
        arr[i][j]=arr[i][j]+max(arr[i-1][0],arr[i-1][2]);
      else
        arr[i][j]=arr[i][j]+max(arr[i-1][0],arr[i-1][1]);
       max1=max(max1,arr[i][j]);
    }
  cout <<max1<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
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 fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

vector<int>node[100009];

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>in(n);
  vector<int>cnt(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    node[x].push_back(y);
    in[y]++;
  }
  queue<int>que;
  vector<int>dp(n);
  rep(i,n){
    if(in[i]==0)que.push(i);
  }
  while(!que.empty()){
    int now=que.front();que.pop();
    for(auto e:node[now]){
      cnt[e]++;
      dp[e]=max(dp[e],dp[now]+1);
      if(cnt[e]==in[e]){
        que.push(e);
      }
    }
  }
  int ans=0;
  rep(i,n)ans=max(ans,dp[i]);
  cout<<ans<<endl;
  return(0);
}

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

int main()
{
  string a;
  string b;
  string c;
  string d;
  int i = 0;
  
  cin >> a;
  
  if(a[i] == a[i + 1]){
    if(a[i + 1] != a[i + 2] && a[i + 2] == a[i + 3]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else if(a[i] == a[i + 2]){
    if(a[i + 2] != a[i + 1] && a[i + 1] == a[i + 3]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else if(a[i] == a[i + 3]){
    if(a[i + 3] != a[i + 1] && a[i + 1] == a[i + 2]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    cout<<"No"<<endl;
  }
}
         








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

using namespace std;

int n, a[200], visit[200];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int res = 0;
    int tmp = 1;
    for (int i = 0; i < n; i++) {
        if (a[i] == a[i + 1]) {
            tmp++;
        } else {
            res += tmp / 2;
            tmp = 1;
        }
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

struct FOOD{
	string name;
	int w;
	int s;
};

bool checkWeight(const struct FOOD* food,const int* table,int n){
	for(int i=0;i<n;i++){
		int sum = 0;
		for(int j=i+1;j<n;j++){
			sum += food[table[j]].w;
		}
		if(food[table[i]].s < sum) return false;
	}

	return true;
}

double getG(const struct FOOD* food,const int* table,int n){

	double G=0;
	double sum=0;
	for(int i=0;i<n;i++){
		G += (double)food[table[i]].w * (i+1);
		sum += (double)food[table[i]].w;
	}
	return G / sum;
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		struct FOOD* food = new struct FOOD[n];

		for(int i=0;i<n;i++){
			char buf[64];
			int w,s;
			scanf("%s %d %d",buf,&w,&s);
			food[i].name = buf;
			food[i].s = s;
			food[i].w = w;
		}

		int* table = new int[n];
		for(int i=0;i<n;i++) table[i] = i;

		int* res = new int[n]();
		double minG = 1000000.0;

		do{
			double tmpG;
			if(checkWeight(food,table,n) &&
				minG > (tmpG = getG(food,table,n))){
					copy(table,table+n,res);
					minG = tmpG;
			}
		}while(next_permutation(table,table+n));

		for(int i=0;i<n;i++){
			printf("%s\n",food[res[i]].name.c_str());
		}

		delete[] food;
		delete[] table;
	}
}

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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  ll ans = 0;
  REP(i, 1, N) {
    if(A[i - 1] == A[i]) {
      A[i] = -1;
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main(void)
{
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A+3);
    if(A[0] == 5 && A[1] == 5 && A[2] == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
       int n=s.nextInt(),m=s.nextInt();
       int[] in_edge=new int[n+1];
       Map<Integer,Set<Integer>> map=new HashMap<>();
       Map<Integer,Set<Integer>> map2=new HashMap<>();
       for(int i=0;i<m;i++){
        int x=s.nextInt(),y=s.nextInt();
        in_edge[y]++;
        if(map.get(x)!=null){map.get(x).add(y);}
        else{
          map.put(x,new HashSet<Integer>());
          map.get(x).add(y);
        }

        if(map2.get(y)!=null){map2.get(y).add(x);}
        else{
          map2.put(y,new HashSet<Integer>());
          map2.get(y).add(x);
        }
       }
       Queue<Integer> min_heap=new LinkedList<>();
       for(int i=1;i<=n;i++){
        if(in_edge[i]==0){min_heap.add(i);}
       }
       //boolean[] b=new boolean[n+1];
       List<Integer>ts=new ArrayList<>();
       while(!min_heap.isEmpty()){
        int curr=min_heap.poll();
       // b[curr]=true;
       // sb.append(curr+" ");
        ts.add(curr);
        if(map.get(curr)!=null){
          for(int xx:map.get(curr)){
              in_edge[xx]--;
              if(in_edge[xx]==0){min_heap.add(xx);}
          }
        }
       }
       //System.out.println(ts);
       Map<Integer,Integer>indx=new HashMap<>();
       for(int i=0;i<n;i++){indx.put(ts.get(i),i);}
       int[] dp=new int[n];
       int res=0;
       Set<Integer>ss=new HashSet<>();
       ss.add(ts.get(0));
       for(int j=1;j<n;j++){
        int i=ts.get(j);
           if(map2.get(i)!=null){
            for(int zz:map2.get(i)){
                if(ss.contains(zz)){
                    dp[j]=Math.max(dp[j],dp[indx.get(zz)]+1);
                }
            }
           }
       res=Math.max(res,dp[j]);
       ss.add(i);
       }
       System.out.println(res);
        }
    }


Measured memory_bytes: 160232
using namespace std;
#include <iostream>
#include<bits/stdc++.h>
#define pb push_back
#define MAX 300
#define pi 3.1415926536
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ull unsigned long long
#define ll long long
#define MOD 1000000000
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fn(i,n) for (ll i=0; i<n; i++)
#define endl "\n"
#define Endl endl
#define EN cout<<endl;
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; } 
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
 
signed main ()
{
    inp(n);
    map<string, int> ma;

    for (int i=0; i<n; i++)
    {
        string s; cin>>s;
        sort(s.begin(), s.end());
        ma[s]++;
    }
    ll cnt=0;
    map<string, int>::iterator itr;
    for (itr=ma.begin(); itr!=ma.end(); ++itr)
    {
        ll val = itr->ss;
        cnt+=val*(val-1);
    }

    cout<<cnt/2;

}

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

int main()
{
  long long a, b, c;
  cin >> a >> b >> c;

  if (a * b * c % 2 == 0){
    cout << 0 << endl;
  } else {
    cout << min(a * b, min(b * c, c * a)) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  bool t[26];
  for(int i= 0; i < 23; i++) {
    t[i] = false;
  }
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++) {
    t[s[i] - 'a'] = true;
  }
  bool ok = false;
  for(int i = 0; i < 26; i++) {
    if(!t[i]) {
      cout << (char)(i + 'a') << endl;
      ok = true;
      break;
    }
  }
  if(!ok) cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        mp[tmp] = (mp.count(tmp) == 0) ? 1 : mp[tmp] + 1;
    }
    int ans = 0;
    for (auto itr : mp) {
        if (itr.second % 2 == 1) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (auto &Fi : F) for (auto &Fijk : Fi) cin >> Fijk;
    vector<vector<LLONG>> P(N, vector<LLONG>(11));
    for (auto &Pi : P) for (auto &Pic : Pi) cin >> Pic;
    // 全ての店の開き方（2^10-1）について全探索:O(10^3*10*N)=O(N*10^4)<O(10^6)
    LLONG maxPayoff = -10e11;
    for (int bit = 1; bit < (1 << 10); ++bit)
    {
        // 各店ごとの重複数を計算:O(10N)
        vector<int> overlapNums(N, 0);
        for (int t = 0; t < 10; ++t)
        {
            // 店を開店しているとき
            if (bit & (1 << t))
            {
                for (int i = 0; i < N; ++i)
                {
                    if (F[i][t] == 1) ++overlapNums[i];
                }
            }
        }
        // 各店ごとの重複数に応じて利益計算:O(N)
        LLONG tmpPayoff = 0;
        for (int i = 0; i < N; ++i)
        {
            tmpPayoff += P[i][overlapNums[i]];
        }
        maxPayoff = max(maxPayoff, tmpPayoff);
    }
    cout << maxPayoff << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ar := make([]string, h)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	hr := make([]bool, h)
	wr := make([]bool, w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if ar[i][j] == '#' {
				hr[i] = true
				wr[j] = true
			}
		}
	}
	for i, s := range ar {
		if !hr[i] {
			continue
		}
		for j, v := range s {
			if wr[j] {
				fmt.Printf("%c", v)
			}
		}
		fmt.Println()
	}
}


Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int m = 2019;
		Map<Integer, Integer> map = new HashMap<>();
		addCntMap(map, 0);
		long ans = 0;
		int now = 0;
		int n = s.length;
		for (int i = n - 1; i >= 0; i--) {
			int d = s[i] - '0';
			d *= power(10, n - 1 - i, m);
			now += d;
			now %= 2019;
			ans += ntz(map.get(now));
			addCntMap(map, now);
		}
		System.out.println(ans);
	}

	static int power(int x, int n, int m) {
		if (n == 0) {
			return 1;
		}
		int val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}

	static int ntz(Integer v) {
		return v == null ? 0 : v;
	}

	static void addCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	ll x;
	cin >> x;
	int check = x % 100;
	int num = x / 100 ;
	if ( x < 100 ){
		cout << 0 << endl;
		return 0 ;
	}
	//下2桁さえ合えばいい
	int need = 0 ; 
	//まず5で割った余りを求める
	need += check / 5 ;
	check %= 5;
	need += check /4 ;
	check %= 4;
	need += check /3 ;
	check %= 3;
	need += check /2 ;
	check %= 2;
	need += check /1 ;
	check %= 1;


	if(num >= need){
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

	

}


Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll a, b; cin >> a >> b;

    cout << max(0LL, a - b * 2) << endl;
    
}

Measured memory_bytes: 764
while 1:
    n = input()
    if n == 0:
        break
    L = 500*n
    dp = [None]*(L+1)
    dp[0] = (0, 0)
    for i in xrange(n):
        dp2 = dp[:]
        cost = int(raw_input())
        d3 = cost % 1000
        for j in xrange(L+1):
            if dp[j] is None:
                continue
            num, su = dp[j]
            if d3 == 0:
                if 500 <= j:
                    dp2[j - 500] = max(dp2[j - 500], (num+1, su-cost))
            elif 1 <= d3 <= 500+j:
                dp2[j + (500 - d3)] = max(dp2[j + (500 - d3)], (num+1, su-cost))
            else:
                dp2[j + (1000 - d3)] = max(dp2[j + (1000 - d3)], (num, su-cost))
        dp, dp2 = dp2, dp
    num, su = max(dp)
    print num, -su

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll L, R, d, ans = 0 ;
    cin >> L >> R >> d ;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) ans++ ;
    }
    cout << ans ;

    return 0 ;
}


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

/// Constant:
#define         eps         0.000000001
#define         pi          2*acos(0)
#define         P1          1000000007
#define         P2          1000000009

#define         fast        ios_base::sync_with_stdio(false);   cin.tie(NULL);
#define         lli         long long int
#define         PB          push_back
#define         pb          pop_back
#define         mp          make_pair
#define         I           insert
/// Loop:
#define         f1(a,b)     for (int i=a; i<=b; i++)
#define         f2(a,b)     for (int j=a; j<=b; j++)
#define         f-1(a,b)     for (int i=b; i>=a; i--)
#define         f-2(a,b)     for (int j=b; j>=a; j--)
///Print:
#define         pY          cout<<"YES"<<endl;
#define         pN          cout<<"NO"<<endl;
#define         py          cout<<"Yes"<<endl;
#define         pn          cout<<"No"<<endl;

using namespace std;
///ISNNJB

///Global Variable:
int ara[200005],brr[200005];

/// Functions:
//lli bigmod(lli b, lli p, lli m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ lli res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//lli mod_inverse(lli a, lli mod) { return bigmod(a,mod-2,mod); }
//lli LCM(lli a, lli b) { return a*b/ __gcd(a,b); }
//vector<int>divisors[1000005]; void divisor(int n) { for (int i=1; i<=n; i++)    for (int j=i; j<=n; j+=i)   divisors[j].PB(i);}

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {

    /**freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    fast;

    lli a,b,c,d,t,k,n,m,x,y,q,ctn=0,l1,l2,total=0,l,r;
    string s;

    for (int i=1; i<=3; i++) {
        cin>>ara[i];
    }
    cin>>k;

    for (int i=2; i<=3; i++) {
        while(ara[i-1]>=ara[i]) {
            ara[i]=2*ara[i];
            ctn++;
        }
    }

    if(ctn>k)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

    return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            int[] NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = NK[0], K = NK[1];
            var fruits = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var orderedByFruits = fruits.OrderBy(x => x);
            var takeList = orderedByFruits.Take(K);
            Console.WriteLine(takeList.Sum());
        }
    }
}


Measured memory_bytes: 28448
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

int N, K; cin >> N >> K;

int star = (N-1) * (N-2) / 2;
if (K > star){
    cout << "-1\n";
    return 0;
}

VP res;
rep(i, 1, N) res.emplace_back(i, N);
int rem = star - K;

int ci = 1, cj = 2;
while (rem--){
    res.emplace_back(ci, cj);

    ++cj;
    if (cj == N){
        ++ci;
        cj = ci + 1;
    }
}


cout << res.size() << "\n";
for(PII p: res) cout << p.first << ' ' << p.second << "\n";


return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader =
				new BufferedReader(new InputStreamReader(System.in));

			String str = reader.readLine();
			int x = Integer.parseInt(str.split(" ",0)[0]);
			int y = Integer.parseInt(str.split(" ",0)[1]);
			
			System.out.println(x * y);
			
			reader.close();
	}
}

Measured memory_bytes: 17092
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <memory.h>
#include <time.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cassert>
#include <string>
#include <cstring>
using namespace std;
#define oo 2000000000
#define mod 1000000007
const int N = 300010;
int n, m , u , v;
bool vis[N];
char s[N];
vector< int > g[N];
int can[N][2], can2[N][2], cnt = 0 , node;
queue < int > q;
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	scanf("%d%d", &n, &m);
	scanf("%s", s);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u, &v);
		u--, v--;
		if(u != v){
			g[u].push_back(v);
			g[v].push_back(u);
		}
		if(u != v)
			can[u][s[v] - 'A']++;
		can[v][s[u] - 'A']++;
	}
	for (int i = 0; i < n; i++) {
		if (can[i][0] == 0 || can[i][1] == 0) {
			q.push(i);
			vis[i] = true;
		}
	}
	while (!q.empty()) {
		node = q.front();
		q.pop();
		cnt++;
		for (int i = 0; i < g[node].size(); i++) {
			if (vis[g[node][i]]) continue;
			can[g[node][i]][s[node] - 'A']--;
			if (can[g[node][i]][s[node] - 'A'] == 0) {
				vis[g[node][i]] = true;
				q.push(g[node][i]);
			}
		}
	}
	if (cnt == n)
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 16256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rep(a, b) for(int i = a; i < b; i++)

int main() {
	int n;
	cin >> n;
	vector<int> a = vector<int>(n, 0);
	rep(0, n) cin >> a[i];

	sort(a.begin(), a.end());

	int sum = 0;
	for (int i = a.size() - 1; i > 0; i--) {
		sum += a[i] - a[i - 1];
	}

	cout << sum << endl;

	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000007

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}


int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n;
 cin>>n;
 vector<double> v;
 double p;
 v.pb(0);
 fl(i,0,n)
 {
    cin>>p;
    v.pb(p);
 }
 double dp[n+1][n+1];
 memset(dp,1,sizeof(dp));
 dp[1][0]=1-v[1];
 dp[1][1]=v[1];
 fl(i,2,n+1)
 {
    fl(j,0,i+1)
    {
        if(j==0)
            dp[i][j]=dp[i-1][j]*(1-v[i]);
        if(j<i)
            dp[i][j]=dp[i-1][j]*(1-v[i])+dp[i-1][j-1]*v[i];
        if(j==i)
            dp[i][j]=dp[i-1][j-1]*v[i];      
    }
 }
 double ans=0;
 for(ll i=n;i>n/2;i--)
    ans+=dp[n][i];
 cout << fixed << setprecision(10);
 cout <<  ans;
}

Measured memory_bytes: 70656
use std::error::Error;
use std::io;
use std::cmp::max;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let nmk: Vec<i64> = input.trim().split_whitespace().map(|f| f.parse::<i64>().unwrap()).collect();
    input.clear();
    let n = nmk[0];
    let m = nmk[1];
    let k = nmk[2];

    io::stdin().read_line(&mut input)?;
    let a_s: Vec<i64> = input.trim().split_whitespace().map(|f| f.parse::<i64>().unwrap()).collect();
    input.clear();

    io::stdin().read_line(&mut input)?;
    let b_s: Vec<i64> = input.trim().split_whitespace().map(|f| f.parse::<i64>().unwrap()).collect();
    input.clear();


    let mut a_s_sum = vec![0i64; n as usize];
    a_s_sum[0] = a_s[0];
    for i in 1..n as usize {
        a_s_sum[i] = a_s_sum[i - 1] + a_s[i];
    }

    let mut b_s_sum = vec![0i64; m as usize];
    b_s_sum[0] = b_s[0];
    for i in 1..m as usize {
        b_s_sum[i] = b_s_sum[i - 1] + b_s[i];
    }

    let mut result = 0;
    for i in 0..n as usize {
        let remain = k - a_s_sum[i];
        if remain < 0 {
            continue;
        }
        if remain == 0 {
            result = max(result, i + 1);
            continue;
        }
        let count = match b_s_sum.binary_search(&remain) {
            Ok(index) => {
                index + 1
            }
            Err(index) => {
                index
            }
        };
        result = max(result, i + 1 + count);
    }

    for i in 0..m as usize {
        let remain = k - b_s_sum[i];
        if remain < 0 {
            continue;
        }
        if remain == 0 {
            result = max(result, i + 1);
            continue;
        }
        let count = match a_s_sum.binary_search(&remain) {
            Ok(index) => {
                index + 1
            }
            Err(index) => {
                index
            }
        };
        result = max(result, i + 1 + count);
    }
    println!("{}", result);
    Ok(())
}


Measured memory_bytes: 10424
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

lint N;

/* nの約数を列挙 */
vector<long long> divisors(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i != 0) continue;
    res.push_back(i);
    if (n / i == i) continue;  // 上の行で追加済み。
    res.push_back(n / i);
  }
  return res;
}

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

  cin >> N;

  vector<lint> tmp = divisors(N);
  sort(all(tmp));
  lint ans = 1e18;
  for (int i = 0; i < (int)tmp.size() / 2 + 1; i++) {
    lint x = tmp[i];
    lint y = N / x;
    ans = min(ans, (x - 1) + (y - 1));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;


int main(){

	int h,w;
	cin>>h>>w;
	char m[8][8];
	int sn=0;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>> m[i][j];
			if(m[i][j]=='#' ){
				sn++;
			}
		}
	}
	//cout << sn << endl;
	if(sn==(h-1)+(w-1)+1){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}

	//while(1);

}


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

const int MOD = 1e9 + 7;

template<typename T> struct Mod {
  T p;
  vector<T> fact, factInv;
  Mod() {}
  Mod(T n, T p = 1e9 + 7) : p(p), fact(n + 1), factInv(n + 1) {
    fact[0] = 1;
    for (T i = 1; i < n + 1; ++i) fact[i] = fact[i - 1] * i % p;
    for (T i = 0; i < n + 1; ++i) factInv[i] = modPow(fact[i], p - 2);
  }
  T modPow(T x, T n) {
    if (n == 0) return 1;
    T res = modPow(x * x % p, n / 2);
    if (n & 1) res = res * x % p;
    return res;
  }
  T modComb(T n, T k) {
    return ((fact[n] * factInv[k]) % p * factInv[n - k]) % p;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  Mod<ll> m(N, MOD);
  vector<ll> sum(N + 1, 0);
  for (int i = 0; i < N; i++) {
    sum[i + 1] = sum[i] + m.fact[N] * m.modPow(i + 1, MOD - 2);
    sum[i + 1] %= MOD;
  }

  ll ans = 0;
  auto c = [&](int i) {
    return sum[i + 1] + sum[N - i] - sum[1];
  };
  for (int i = 0; i < N; i++) {
    ans += c(i) * A[i];
    ans %= MOD;
  }

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


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=1005;

map<int, int> data;

int main()
{
    int n;
    while(~scanf("%d", &n)){
        int ans=0, x;
        data.clear();
        for(int i=0;i<n;i++){
            scanf("%d", &x);
            if(data[x]){
                data[x]=0;
                ans--;
            }
            else {
                data[x]++;
                ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 4992
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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 FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll H = 0, W = 0;
    cin(H);cin(W);

    vector<vector<char>> S(H+2,vector<char>(W+2));
    for(int i=1;i<H+1;i++){
        for(int j =1; j<W+1;j++){
            cin(S[i][j]);
        }
    }

    vector<vector<char>> ans(H, vector<char>(W,'#'));

    for(int i=1;i<H+1;i ++){
        for(int j =1; j<W+1;j++){
            if(S.at(i).at(j)=='.'){
            int a =0;
            if(S.at(i-1).at(j-1)=='#') a++;
            if(S.at(i-1).at(j)=='#') a++;
            if(S.at(i-1).at(j+1)=='#') a++;
            if(S.at(i).at(j-1)=='#') a++;
            if(S.at(i).at(j+1)=='#') a++;
            if(S.at(i+1).at(j-1)=='#') a++;
            if(S.at(i+1).at(j)=='#') a++;
            if(S.at(i+1).at(j+1)=='#') a++;

            string b = to_string(a);
            const char* cs = b.data();
            ans.at(i-1).at(j-1) = cs[0];
        }
        }
    }

    REP(i,H){
        REP(j,W){
            cout << ans[i][j];
            if(j == W-1) cout << endl;
        }

    }


    //本文
    //出力
    //cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3720
s = input()
start = 1000000
end = 0

for i in range(len(s)):
    #print(s[i])
    if s[i] == 'A' and start > i:
        start = i
        #print(start)
    elif s[i] == 'Z' and end < i:
        end = i

print(end - start + 1)


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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

const int N = 2e5+10;

int n, a[N];
LL res;
set<int> f;

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    cin >> n;
    For(i, 1, n) cin >> a[i];
    if (a[1]) cout << -1;
    else {
        LL timer = 0;
        LL sum = 0;
        Rep(i, n, 2) {
            if (!f.empty()) {
                auto it = --f.end();
                if (*it > a[i]+timer) {
                    cout << -1;
                    return 0;
                }
            }
            f.insert(a[i]+timer);
            while (!f.empty() && *f.begin()-timer == 0) f.erase(f.begin());
            res += sz(f);
            timer++;
        }
        cout << res;
    }
}




Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
double a[4][4];
int main()
{
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            scanf("%lf",&a[i][j]);
        }
    }
    if(a[1][2]+a[2][3]+a[3][1]+a[1][3]+a[2][1]+a[3][2]==(a[1][1]+a[2][2]+a[3][3])*2)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

n=int(input())
L=[[] for i in range(n)]
V=[]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    L[a].append(b)
    L[b].append(a)
    V.append([a,b])
k=max(len(l) for l in L)
C=[-1]*n
D=[-1]*n
def dfs(s,p=-1,d=0): #深さ優先探索(親,上の辺の色,深さ)
    c=C[s]
    for i in L[s]: #子に対して
        if i!=p: #親と一緒じゃないとき
            c=(c+1)%k
            C[i]=c
            D[i]=d
            dfs(i,s,d+1) #色をつけ、スタートを更新し、再探索

dfs(0)
print(k)
for v in V:
    if D[v[0]]>D[v[1]]:
        print(C[v[0]]+1)
    else:
        print(C[v[1]]+1)

Measured memory_bytes: 107336