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

using namespace std;

int main()
{
  int n,m,pos,flag=0;
  char val;
  cin>>n>>m;
  char a[n];
  for(auto i=0;i<n;i++)
  {
    a[i]='?';
  }
  for(auto i=0;i<m;i++)
  {
    cin>>pos>>val;
    if(flag==0)
    {
    if(a[n-pos]=='?')
    {
      a[n-pos]=val;
    }
    else
    {
      if(a[n-pos]==val)
      {
        continue;
      }
      else
      {
        cout<<"-1";
        flag=1;
      }
    }
  }


  }
  if(flag==0)
  {
  if(a[n-1]=='?' && n==1)
    a[n-1]='0';
  else if(a[n-1]=='?')
    a[n-1]='1';
  if(a[n-1]=='0' && n!=1)
    cout<<"-1";
  else
  {
    for(auto i=n-1;i>=0;i--)
    {
      if(a[i]=='?')
        cout<<'0';
      else
        cout<<a[i];
    }
  }}
  return 0;
}


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

using namespace std;

int frog2(int N, int a[], int k)
{
    int dp[N+1];
    dp[0] = 0;
    dp[1] = a[0];
    dp[2] = abs(a[1] - a[0]);
    for( int i = 3; i <= N; i++)
    {
        dp[i] = INT_MAX;
        for(int j = 1 ; j <= k; j++)
        if(i-j-1>=0)
        {
            if(i-j-1 == 0)
                dp[i] = min(dp[i], abs(a[i-1] - a[i-j-1]));
            else
                dp[i] = min(dp[i], dp[i-j] + abs(a[i-1]-a[i-j-1]));
        }  
    }

    return dp[N];
}


int main()
{
    int N, k;
    cin>>N>>k;
    int a[N];
    for(int i = 0; i < N; i++) cin>>a[i];
    cout << frog2(N,a,k);
}

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

int main() {
  int N, x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];

  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    long long dif = max(a[i] + a[i + 1] - x, 0ll);
    ans += max(dif, 0ll);
    a[i + 1] = max(a[i + 1] - dif, 0ll);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s == "Sunny")cout<<"Cloudy"<<endl;
	else if(s == "Cloudy")cout<<"Rainy"<<endl;
	else if(s == "Rainy")cout<<"Sunny"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  double n;
  while( cin >> n ){
    double a[10];
    double sum = n;
    a[0] = n;
    for(int i = 1; i < 10; i++){
      // even
      if(i % 2 == 1)
	{
	  a[i] = a[i-1] * 2;
      }
      // odd
      else
	{
	  a[i] = a[i-1]/3;
      }
      sum += a[i];
    }
    printf("%.9lf\n", sum);
  }

  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int i;
    for(i = 0;i < s.length();++i){
        if(i%2 == 0){
            if(s.at(i) == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s.at(i) == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define MODULO 1000000007l
#define INF 100000000
#define FOR(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const int maxn = 2e5 + 10;

string S;
int len[maxn];
char beginChar[maxn];
int nxt[maxn];

vector<int> bucket['z'-'a'+1];
int n;

int calc(int st) {
    if (len[st]>0) return len[st];
    for (char x='a'; x<='z';x++) {
        if (bucket[x-'a'].empty() || bucket[x-'a'][bucket[x-'a'].size()-1] < st) {
            beginChar[st] = x;
            return (len[st] = 1);
        }
    }

    int lnn = 2e6;

    for (char x='a'; x<='z';x++) {
        int ind = *lower_bound(bucket[x-'a'].begin(), bucket[x-'a'].end(), st);
        if (x == 'a' || (1+calc(ind+1)) < lnn) {
            lnn = 1+calc(ind+1);
            beginChar[st] = x;
            nxt[st] = ind+1;
        }
    }

    return (len[st] = lnn);
}

int main() {

#ifdef CONTEST
    freopen("input.in", "r", stdin);
#endif
    IOS
    cin >> S;
    n = S.length();
    FOR(i,0,n-1) {
        bucket[S[i]-'a'].push_back(i);
    }
    FOR(i,0,'z'-'a') {
        sort(bucket[i].begin(), bucket[i].end());
    }

    int lnn = calc(0);
    int ind = 0;
    FOR(i,1,lnn) {
        cout << beginChar[ind];
        ind = nxt[ind];
    }
    cout << endl;

}

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

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

    rep(i, 10) rep(j, 10)
        if(i*j == n) {
            cout << "Yes" << endl; 
            return 0;
        }
    

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in[0]*-~n]
for i in[0]*~-n:
    a,b,c=map(int,input().split())
    G[a]+=(b,c),
    G[b]+=(a,c),
q,k=map(int,input().split())
d=[0]*-~n
def f(v,p,u):
    d[v]=u
    for t,c in G[v]:
        if p!=t:f(t,v,u+c)
f(k,0,0)
for i in[0]*q:
    x,y=map(int,input().split())
    print(d[x]+d[y])

Measured memory_bytes: 133028
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;
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;}

int N;
ll a[3010];

ll dp[3010][3010];

ll rec(int i, int j) {
    if(dp[i][j] > 0) return dp[i][j];
    ll rsl = -1;
    if((N - (j - i)) % 2 == 0) { // 先攻
        if(j - i == 1) return a[i];
        rsl = max(rec(i + 1, j) + a[i], rec(i, j - 1) + a[j - 1]);
    } else {
        if(j - i == 1) return 0;
        rsl = INF;
        rsl = min(rec(i + 1, j), rec(i, j - 1));
    }
    return dp[i][j] = rsl;
}

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

    cin >> N;
    ll sum = 0;
    rep(i, 0, N) {
        cin >> a[i];
        sum += a[i];
    }

    memset(dp, -1, sizeof(dp));
    ll x = rec(0, N);
    ll y = sum - x;
    cout << x - y << endl;
}


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

int main(int argc, char** argv){
	int n;
	int s_list[1000];
	int i;
	int sum;
	double ave;
	double s_ave,a2_n;

	for(;;){
		/* Input n */
		scanf("%d",&n);
		/* Finish Check */
		if( n <= 0 ){
			break;
		}
		/* Input s & Calc Sum/Average */
		sum = 0;
		for(i=0;i<n;i++){
			scanf("%d",s_list+i);
			sum += s_list[i];
		}
		ave = sum * 1.0 / n;
		/*  Cacl a^2/n */
		a2_n = 0.0;
		for(i=0;i<n;i++){
			s_ave = s_list[i] - ave;
			a2_n += s_ave * s_ave; 
		}
		/* Output a */
		printf("%f\n",sqrt(a2_n/n));
	}

	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	//string s; cin>>s;
	cout<<(n>=30 ? "Yes":"No")<<endl;


	return 0;
}

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

int main()
{
  vector<int> T(5);
  for (int i=0; i<5 ;i++)
  {
    cin >> T.at(i);
  }
  for (int i=0; i<5; i++)
  {
    if (T.at(i) ==0)
    {
      cout << i+1 << endl;
      break;
    }
    
  }

}


Measured memory_bytes: 3548
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
#define int long long
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int x[n],y[n],p[n],N=1ll<<n;
    for(int i=0;i<n;i++)
    	cin >> x[i] >> y[i] >> p[i] ;
    int ans[n+1],mx[N][n]={0},my[N][n]={0};
    fill(ans,ans+n+1,1e18);
    for(int s=0;s<N;s++){
    	for(int i=0;i<n;i++){
    		int u=min(abs(x[i]),abs(y[i]))*p[i];
    		int v=u;
    		for(int j=0;j<n;j++){
    			if(s&(1ll<<j)){
    				u=min(u,abs(x[i]-x[j])*p[i]);
    				v=min(v,abs(y[i]-y[j])*p[i]);
    			}
    		}
    		mx[s][i]=u,my[s][i]=v;
    	}
    }
    for(int s=0;s<N;s++){
    	int m=N-1-s;
    	for(int t=m;;t=(t-1)&m){
    		int r=0;
    		for(int i=0;i<n;i++)
    			r+=min(mx[s][i],my[t][i]);
    		int c=__builtin_popcount(s)+__builtin_popcount(t);
    		ans[c]=min(ans[c],r);
    		if(!t)break;
    	}
    }
    for(int i=0;i<=n;i++)
    	cout << ans[i] << '\n';
}

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

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

    vector<pair<int, int>> war(m);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        war[i] = make_pair(b-1, a-1);
    }
    sort(war.begin(), war.end());

    int count = 0;
    int bridge = -1;
    for(int i=0; i<m; i++){
        if(war[i].second <= bridge) ;// do nothing
        else{
            bridge = war[i].first - 1;
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main()
{
  int n; cin>>n;
  int r=n%10;
  if(r==0|| r==1||r==6||r==8)
    cout<<"pon\n";
  else
    if(r==3)
      cout<<"bon\n";
  else cout<<"hon\n";
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  char c[1];
  cin >> c[0];
  c[0]++;
  cout << c[0] << endl;

	return 0;
}

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    int N;
    cin >> N;
    string S;
    cin >> S;
    
    set<string> one, two, three;
    
    rep(k,N){
        for(auto i = two.begin(); i!=two.end(); i++){
            three.insert((*i)+S[k]);
        }
        for(auto i= one.begin(); i!=one.end(); i++){
            two.insert((*i)+S[k]);
        }
        one.insert(S.substr(k,1));
    }
    cout << three.size() << endl;
//    dump(one, two, three);
    
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = k * pow(k - 1, n - 1);
  cout << ans << endl;
}

Measured memory_bytes: 256
const readline = require('readline');

class Node {
  constructor(val) {
    this.prev = null;
    this.next = null;
    this.val = val;
  }
}

class DoublyLinkedList {
  constructor() {
    this.first = null;
    this.last = null;
    this.size = 0;
  }

  insert(val) {
    let n = new Node(val);
    if (this.first) {
      let oldFirst = this.first;
      this.first = n;
      oldFirst.prev = this.first;
      this.first.next = oldFirst;
    } else {
      this.first = this.last = n;
    }
    this.size++;
  }

  delete(val) {
    for (let n = this.first; n !== null; n = n.next) {
      if (n.val === val) {
        if (n.prev === null) {
          this.deleteFirst();
        } else if (n.next === null) {
          this.deleteLast();
        } else {
          n.prev.next = n.next;
          n.next.prev = n.prev;
          this.size--;
        }
        break;
      }
    }
  }

  deleteFirst() {
    if (this.size === 0) {
      return;
    } else if (this.size === 1) {
      this.first = this.last = null;
      this.size = 0;
    } else {
      this.first = this.first.next;
      this.first.prev = null;
      this.size--;
    }
  }

  deleteLast() {
    if (this.size === 0) {
      return;
    } else if (this.size === 1) {
      this.first = this.last = null;
      this.size = 0;
    } else {
      this.last = this.last.prev;
      this.last.next = null;
      this.size--;
    }
  }
}

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let dll = new DoublyLinkedList();

rl.on('line', function (input) {
  let arr = input.split(' ');
  let [cmd, param] = arr;
  if (dll[cmd]) {
    dll[cmd](param);
  }
})

rl.on('close', function () {
  let arr = [];
  for (let n = dll.first; n !== null; n = n.next) {
    arr.push(n.val);
  }
  console.log(arr.join(' '));
})


Measured memory_bytes: 144680
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
int main(){
    int a,b,c,x;cin>>a>>b>>c>>x;
    int res=0;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                if(500*i+j*100+k*50==x)res++;
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3600
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for a in range(len(xyh_list)):
    if xyh_list[a][2] != 0:
        x1 = xyh_list[a][0]
        y1 = xyh_list[a][1]
        h1 = xyh_list[a][2]
        break

for cx in list_0_100:
    for cy in list_0_100:
        H = h1 + abs(x1 - cx) + abs(y1 - cy)
        count = 0
        for i in range(n):
            x = xyh_list[i][0]
            y = xyh_list[i][1]
            h = xyh_list[i][2]
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                count += 1
        if count == n:
            ansx = cx
            ansy = cy
            ansH = H
print(ansx, ansy, ansH)


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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const ull mod = 1e9 + 7;

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

	int a,b,c,N;	cin>>N;
	c = N % 10;
	b = (N % 100 - c)/10;
	a = (N - b)/100;
	
	if(a==7||b==7||c==7)	Yes();
	else No();

    return 0;
}

Measured memory_bytes: 3560
using System;

namespace _092_Square_Searching
{
	class Program
	{
		const char Exist = '*';

		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != "0")
			{
				int length = int.Parse (inputStr);

				string[] area = new string[length];
				for (int lp = 0; lp < length; lp++)
				{
					area[lp] = Console.ReadLine ();
				}

				var result = LargestSquare (area);
				Console.WriteLine (result);
			}
		}

		static int LargestSquare ( string[] area )
		{
			int width = area.Length;
			int height = area[0].Length;
			int[,] dp = new int[width + 1, height + 1];

			int maxLength = 0;

			for (int lp = 1; lp <= width; lp++)
			{
				for (int lp2 = 1; lp2 <= height; lp2++)
				{
					if (area[lp - 1][lp2 - 1] != Exist)
					{
						int minSize = Math.Min (dp[lp - 1, lp2], Math.Min (dp[lp, lp2 - 1], dp[lp - 1, lp2 - 1]));
						dp[lp, lp2] = minSize + 1;
						maxLength = Math.Max (maxLength, dp[lp, lp2]);
					}
				}
			}

			return maxLength;
		}
	}
}



Measured memory_bytes: 19632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

#define INF 1000000000
using namespace std;

// Ruisekiwa
int main() {
	int n;
	int sum = 0;
	cin >> n;
	vector<int> vec(n);
	fill(vec.begin(), vec.end(), 0);

	int w0;
	cin >> w0;
	vec.at(0) = w0;
	sum += w0;
	for (int i = 1; i < n; i++) {
		int w;
		cin >> w;
		vec.at(i) = w + vec.at(i - 1);
		sum += w;
	}

	int mini = INF;
	for (int i = 0; i < n; i++) {
		mini = min( mini, abs(2 * vec.at(i) - sum) );
	}

	cout << mini << endl;
}

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

int main() {
  std::string S;
  std::cin >> S;

  std::string T;
  std::string ans;

  for (auto c: S) {
    if (c == 'A' ||
        c == 'T' ||
        c == 'C' ||
        c == 'G') {
      T.push_back(c);
    } else {
      if (T.size() > ans.size()) {
        std::swap(T, ans);
        T.clear();
      }
    }
  }

  if (T.size() > ans.size())
    std::swap(T, ans);

  std::cout << ans.size() << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

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

    int multiple_4_count = 0;
    int multiple_2_count = 0;
    int other_count = 0;
    rep(i,N){
        if (A[i] % 4 == 0){
            multiple_4_count++;
        }
        else if (A[i] % 2 == 0){
            multiple_2_count++;
        }
        else{
            other_count++;
        }
    }

    if (multiple_4_count + 1 >= (multiple_2_count+other_count)){
        cout << "Yes" << endl;
    }
    else if (multiple_4_count >= other_count){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);

        //コンテストの参加人数
        int N=sc.nextInt();
        //各参加者のレート数配列
        int[] a=new int[N];
        //色を数えるための配列
        int[] colorCount=new int[8];

        //合計色のカウント
        int sumColor=0;
        int max=0;
        int min=0;

        //自由に色を変更可能な人数をカウント
        int freeColor=0;

        //各参加者のレート数と色のカウント
        for(int i=0;i<N;i++) {
            a[i]=sc.nextInt();

            if(1<=a[i]&&a[i]<399) {
                //灰色
                colorCount[0]=1;
            }else if(400<=a[i]&&a[i]<=799) {
                //茶色
                colorCount[1]=1;
            }else if(800<=a[i]&&a[i]<=1199) {
                //緑色
                colorCount[2]=1;
            }else if(1200<=a[i]&&a[i]<=1599) {
                //水色
                colorCount[3]=1;
            }else if(1600<=a[i]&&a[i]<=1999) {
                //青色
                colorCount[4]=1;
            }else if(2000<=a[i]&&a[i]<=2399) {
                //黄色
                colorCount[5]=1;
            }else if(2400<=a[i]&&a[i]<=2799) {
                //橙色
                colorCount[6]=1;
            }else if(2800<=a[i]&&a[i]<=3199) {
                //赤色
                colorCount[7]=1;
            }else if(3200<=a[i]) {
                //色自由の人
                freeColor += 1;
            }
        }

        //何色あるかカウント
        for(int count:colorCount) {
            sumColor +=count;
        }

        //最大値・最小値を出力
        if(freeColor == 0) {
            System.out.println(sumColor+" "+sumColor);
        }else {
            //最小値出力
            min = 1;
            if(sumColor != 0) {
                min = sumColor;
            }

            //最大値出力
            sumColor += freeColor;
            //if(sumColor >= 8){
            //    max = 8;
            //}else{
            //    max = sumColor;
            //}
            //System.out.println(min+" "+max);
          	System.out.println(min+" "+sumColor);
        }

	}

}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
const int M=2005;
int GA[M][M],ans[M];

int main(){
	int n,x,y,i,j;
	cin>>n>>x>>y;
	
	for(i=1;i<=n;i++)
	for(j=i+1;j<=n;j++)
	GA[i][j]=j-i;
	
	for(i=1;i<=n-1;i++)
	for (int j=i+1;j<=n;j++)
	{
		int xx=abs(j-y)+1+abs(i-x),yy=abs(j-x)+1+abs(i-y);
		GA[i][j]=min(GA[i][j],min(xx,yy));
	}
	
	for(i=1;i<=n-1;i++)
	for(j=i+1;j<=n;j++)
	ans[GA[i][j]]++;
	
	for(i=1;i<=n-1;i++)
	cout<<ans[i]<<endl;
}


Measured memory_bytes: 15360
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int n, k; cin >> n >> k;
    ll ans = k;
    for (int i = 2; i <= n; i++)
    {
        ans *= (k -1);
    }
    cout << ans << 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;
using P = pair<int,int>;

int main(){
	int a,b;
	cin >> a >> b;
	if(a == 1 && b == 2) cout << 3 << endl;
	if(a == 2 && b == 1) cout << 3 << endl;
	if(a == 1 && b == 3) cout << 2 << endl;
	if(a == 3 && b == 1) cout << 2 << endl;
	if(a == 3 && b == 2) cout << 1 << endl;
	if(a == 2 && b == 3) cout << 1 << endl;
}

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



namespace Test1 {

    class ClassMain {

        public static void Main(String[] args) {

            int num;
                
            while ((num=int.Parse(Console.ReadLine()))!=0) {
                int[] hist = new int[6];
                for (int i = 0; i < num; i++) {
                    double height = double.Parse(Console.ReadLine());
                    if (height < 165) { hist[0]++; }
                    else if (height < 170) { hist[1]++; }
                    else if (height < 175) { hist[2]++; }
                    else if (height < 180) { hist[3]++; }
                    else if (height < 185) { hist[4]++; }
                    else { hist[5]++; }

                }
                
                Console.WriteLine("1:" +new String('*', hist[0]) );
                Console.WriteLine("2:" + new String('*', hist[1]));
                Console.WriteLine("3:" + new String('*', hist[2]));
                Console.WriteLine("4:" + new String('*', hist[3]));
                Console.WriteLine("5:" + new String('*', hist[4]));
                Console.WriteLine("6:" + new String('*', hist[5]));


                break;
            }
        }

        
        
    }
}

Measured memory_bytes: 5656
#模範解答 tの文字列の数に絞って全探索を掛ける
S = input()
T = input()

N = len(T)

s_list = []
for i in range(len(S) - N + 1):
    s = S[i: i + N]
    s_list.append(s)

answer = N
for s in s_list:
    counter = 0
    for i in range(N):
        if s[i] != T[i]:
            counter += 1

    answer = min(answer, counter)

print(answer)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    REP(i,7){
        int a,b;
        cin>>a>>b;
        cout<<a-b<<endl;
    }
}





Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

//-----------------------------------------



int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  vector<P> vp;
  rep(i,N-1){
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(make_pair(a,b));
  }
  
  int K = 0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0);
  vector<int> used(N,0);
  queue<int> que;
  que.emplace(0);
  used[0] = 1;
  while(!que.empty()){
    int v = que.front(); que.pop();
    if(K < (int)G[v].size()) K = G[v].size();
    int cur = 1;
    for(int u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++; // 色が親ノード等しい時は1増やす
      cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
      used[u] = 1;
      que.emplace(u);
    }
  }


  cout << K << endl;
  for(auto p: vp) cout << I[p] << endl;
  return 0;
}




Measured memory_bytes: 20084
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ll x=n%k;
	cout<<min(x,k-x);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        double y;
        cin >> y;

        pair<int, double> p;
        auto f1 = [](double y, double r){ return 1 + y * r / 100; };
        auto f2 = [](double y, double r){ return pow(1 + r / 100,y); };
        rep(i,n){
            int b,t;
            double r;
            cin >> b >> r >> t;
            if(p.second < (t == 1 ? f1(y,r) : f2(y,r))){
                p.first = b;
                p.second = (t == 1 ? f1(y,r) : f2(y,r));
            }
        }
        cout << p.first << endl;
    }
}

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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int d[3][105];
  rep(i, 0, n){
    cin >> d[1][i] >> d[2][i];
  }
  rep(i, 1, n - 1){
    if(d[1][i] == d[2][i] && d[1][i - 1] == d[2][i - 1] && d[1][i + 1] == d[2][i + 1]){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String X = sc.next();
		String ret = "";
		
		int size = X.length();
		
		char[] ch = X.toCharArray();
		
		for(int i=0; i<size; i++){
			
			if (i%2 == 0){
				System.out.print(ch[i]);				
			}
		}
		System.out.println("");
		
		

	}

}


Measured memory_bytes: 31564
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;

int main() {
  long long r, d, x; cin >> r >> d >> x;

  for (int i = 1; i <= 10; i++) {
    x = r * x - d;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int f[200001];
int ans[200000];
vector <int> v[200000];
vector <int> w[2];

void dfs(int x, int y, int z) {
    int i;
    
    w[z].push_back(x);
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        dfs(v[x][i], x, 1 - z);
    }
}

int main() {
    int n, i, j;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        a--;
        b--;
        
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    dfs(0, -1, 0);
    
    if (w[0].size() <= n / 3) {
        for (i = 0; i < w[0].size(); i++) {
            int x = (i + 1) * 3;
            
            ans[w[0][i]] = x;
            f[x] = 1;
        }
        
        for (i = 0, j = 1; i < w[1].size(); i++) {
            while (f[j] == 1) j++;
            
            ans[w[1][i]] = j++;
        }
    } else if (w[1].size() <= n / 3) {
        for (i = 0; i < w[1].size(); i++) {
            int x = (i + 1) * 3;
            ans[w[1][i]] = x;
            f[x] = 1;
        }
        
        for (i = 0, j = 1; i < w[0].size(); i++) {
            while (f[j] == 1) j++;
            
            ans[w[0][i]] = j++;
        }
    } else {
        for (i = 0; i < w[0].size(); i++) {
            int x = i * 3 + 1;
            
            if (x > n) break;
            
            ans[w[0][i]] = x;
            f[x] = 1;
        }
        
        for (i = 0; i < w[1].size(); i++) {
            int x = i * 3 + 2;
            
            if (x > n) break;
            
            ans[w[1][i]] = x;
            f[x] = 1;
        }
        
        for (i = 0, j = 1; i < n; i++) {
            if (ans[i] > 0) continue;
            while (f[j] == 1) j++;
            
            ans[i] = j++;
        }
    }
    
    for (i = 0; i < n; i++) {
        if (i > 0) putchar(' ');
        printf("%d", ans[i]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 20084
s = input()
ans = [0]*len(s)

count_even = 0
count_odd = 0
for i in range(len(s)):
    if s[i] == 'R':
        if i%2==0:
            count_even+=1
        else:
            count_odd+=1
    if s[i] == 'L':
        if i%2 == 0:
            ans[i]+=count_even
            ans[i-1]+=count_odd
            count_even=0
            count_odd=0
        else:
            ans[i]+=count_odd
            ans[i-1]+=count_even
            count_even=0
            count_odd=0

count_even = 0
count_odd = 0
s = s[::-1]
ans = ans[::-1]
for i in range(len(s)):
    if s[i] == 'L':
        if i%2==0:
            count_even+=1
        else:
            count_odd+=1
    if s[i] == 'R':
        if i%2 == 0:
            ans[i]+=count_even
            ans[i-1]+=count_odd
            count_even=0
            count_odd=0
        else:
            ans[i]+=count_odd
            ans[i-1]+=count_even
            count_even=0
            count_odd=0
ans = ans[::-1]
print(' '.join(map(str,ans)))
    

Measured memory_bytes: 10896
import sys
readline = sys.stdin.readline
N = int(readline())
XYH = [list(map(int, readline().split())) for _ in range(N)]
X, Y, H = map(list, zip(*XYH))
i = 0
for i in range(N):
    if H[i] != 0:
        x, y, h = X[i], Y[i], H[i]
        break
mh = min(H)
Mh = max(H)
for i in range(101):
    for j in range(101):
        ch = abs(x-i) + abs(y-j) + h
        for xi, yi, hi in XYH:
            if hi != max(0, -abs(xi- i) - abs(yi-j) + ch):
                break
        else:
            ans = (i, j, ch)
print(*ans)


Measured memory_bytes: 43504
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 300100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int32_t main(){
	fastio;
	int r,c;
	cin>>r>>c;
	if(r!=1 && c!=1)cout<<(r*c+1)/2<<endl;
	else cout<<1<<endl;
}

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

int number(string &S, int &i);
int term(string &S, int &i);
int expr(string &S, int &i);

int number(string &S, int &i){
    int ret = 0;
    while(isdigit(S[i])){
        ret*=10;
        ret+=S[i]-'0';
        i++;
    }
    return ret;
}

int term(string &S, int &i){
    const int64_t mod=1000000007;
    if(S[i]=='S'){
        i+=2;//"S<"
        int64_t x = expr(S,i);
        i++;//'>'
        x=x*x%mod;
        return x;
    }else{
        return number(S,i);
    }
}

int expr(string &S, int &i){
    int ret = term(S,i);
    while(i<S.size()){
        int cnt=0;
        for(int j=i;j<S.size();j++){
            if(S[j]=='>')cnt++;
            else break;
        }
        if(cnt==2&&i+2<S.size()){
            i+=2;//">>"
            int y = term(S,i);
            if(y>=31){
                ret=0;
            }else{
                ret>>=y;
            }
            continue;
        }else{
            return ret;
        }
    }
    return ret;
}

int main(){
    string S;
    while(getline(cin,S)){
        if(S[0]=='#') break;
        int i=0;
        string ss;
        for(auto c:S){
            if(c!=' ') ss.push_back(c);
        }
        // cout<<ss<<endl;
        cout<<expr(ss,i)<<endl;
    }

    return 0;
}

Measured memory_bytes: 6364
s = input()
even, odd = [], []
for i in range(len(s)):
    if i%2:
        odd.append(s[i])
    else:
        even.append(s[i])
e = list(set(odd))
o = list(set(even))
if('L' in o or 'R' in e):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 8828
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005,mod=1e9+7;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int Fac[N],Inv[N];
void prework(){
	int n=N-1;
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
}
int C(int n,int m){
	if (m>n||m<0)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int n;
int a[N];
int s[N];
int sum(int L,int R){
	return Del(s[R]-s[L-1]);
}
int main(){
	prework();
	n=read();
	For(i,1,n)
		a[i]=read();
	For(i,1,n)
		s[i]=Add(s[i-1]+a[i]);
	int ans=0;
	//[1..n]
	Add(ans,sum(1,n));
	//[1..i]
	For(i,1,n-1)
		Add(ans,(LL)sum(1,i)*Pow(i+1,mod-2)%mod);
	//[i..n]
	Fod(i,n,2)
		Add(ans,(LL)sum(i,n)*Pow(n-i+1+1,mod-2)%mod);
	//[a..b]
	int tmp=0;
	For(i,1,n-2){
		Add(tmp,(LL)a[i+1]*i%mod);
		Add(tmp,(LL)a[n-i]*i%mod);
		int len=n-1-i,p=(LL)Fac[2]*Fac[len]%mod*Inv[len+2]%mod;
		Add(ans,(LL)tmp*p%mod);
		Add(ans,(LL)i*sum(i+2,n-i-1)%mod*p%mod);
	}
	ans=(LL)ans*Fac[n]%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    int odd;
    bool check = true;
    rep(i, n) {
        cin >> x[i] >> y[i];
        if(i == 0) {
            odd = 1&(x[0]+y[0]);
        } else {
            if(odd != (1&(x[i]+y[i]))) check = false;
        }
    }

    if(!check) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> ra(1, 1LL<<30);
    while(*(ra.end()-1)) ra.push_back(*(ra.end()-1)>>1);
    *(ra.end()-1) = 1;
    if(odd) {
        ra.push_back(1);
    }

    int m = ra.size();
    vs ans(n);

    rep(i, n) {
        ll nx = x[i], ny = y[i];
        rep(j, m) {
            if(nx+ny>=0 and nx-ny>=0) {
                ans[i] += 'R';
                nx -= ra[j];
            } else if(nx+ny>=0) {
                ans[i] += 'U';
                ny -= ra[j];
            } else if(nx-ny>=0) {
                ans[i] += 'D';
                ny += ra[j];
            } else {
                ans[i] += 'L';
                nx += ra[j];
            }
        }
    }

    cout << m << endl;
    rep(i, m) {
        cout << ra[i] << (i == m-1?'\n':' ');
    }
    rep(i, n) {
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 384
N=int(input())
data=dict()
check=2
now=N
bef=1
while check<1+int(N**0.5):
    if now==1:break
    if now<=int(N**0.5):break
    if now%check==0:
        now//=check
        bef*=check
        if check in data:
            data[check]+=1
        elif check not in data:
            data[check]=1
    else:
        check+=1
if now!=1:
    if now not in data:
        data[now]=1
    elif now in data:
        data[now]+=1
if len(data)==0:
    print(len(str(N)))
else:
    A=1
    B=1
    
    while len(data)>0:
        big=max(data.keys())
        if B<A:
            A,B=B,A
        if len(str(B*big))==len(str(B)):
            B*=big
        else:
            A*=big
        data[big]-=1
        if data[big]==0:
            data.pop(big)
    print(len(str(max(A,B))))

Measured memory_bytes: 3064
def main():
    n,x=map(int,input().split())
    A=list(map(int,input().split()))
    c=0
    prev = A[0]
    for a in A[1:]:
        remove = max(0, a + prev - x)
        if prev > x:
            prev = 0
        else:
            prev = a - remove
        c += remove
    print(c)
main()

Measured memory_bytes: 14060
#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(){
    string S; cin >> S;
    vector<ll> count(26);
    rep(i, S.size()){
        int idx = (int)(S[i] - 'a');
        count[idx]++;
    }
    ll ans = 1;
    for(int i = 0;i < 25; i++) {
        for(int j = i+1;j < 26;j++) {
            ans += count[i] * count[j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3700
input = gets.chomp.split ''
stack1 = []
stack2 = []
answer = 0

input.each_with_index do |char, index|
  stack1 << index if char == '\\'
  next unless char == '/' && !stack1.empty?
  j = stack1.pop
  a = index - j
  answer += a
  a += stack2.pop[1] while !stack2.empty? && stack2[-1][0] > j
  stack2 << [j, a]
end

puts answer
areas = []
stack2.each do |array|
  areas << array[1]
end
result = [areas.size].concat(areas)
puts result.join ' '



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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> pos(N);
  rep(i,N){
    int p;
    cin >> p;
    p--;
    pos.at(p)=i+1;
  }

  ll ans=0;
  set<int> S;
  S.insert(0);
  S.insert(N+1);
  for(int i=N-1;i>=0;i--){
    int x=pos.at(i);
    set<int>::iterator it_l = S.lower_bound(x);
    set<int>::iterator it_r = S.lower_bound(x);
    it_l--;
    if(*it_l != 0){
      set<int>::iterator tmp = it_l;
      tmp--;
      ans += ll(i+1) * ll((*it_l) - (*tmp)) * ll((*it_r) - x);
    }
    if(*it_r != N+1){
      set<int>::iterator tmp = it_r;
      tmp++;
      ans += ll(i+1) * ll((*tmp) - (*it_r)) * ll(x - (*it_l));
    }
    S.insert(x);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= 9; j++) {
			if(i * j == n) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(N - 2):
        for j in range(i + 1, N - 1):
                max_c = L[i] + L[j]
                count += bisect.bisect_left(L[j+1:], max_c)
print(count)

Measured memory_bytes: 50780