akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var arr=input.trim().split("\n");
while(arr.length!=0){
var nm=arr.shift().split(" ").map(Number);
var n=nm[0];
var m=nm[1];
var item1=[""];
var item2=[""];
var item3=[""];
for(var i=0;i<n;i++){
arr.shift();
var CVDL=arr.shift().split(" ").map(Number);
item1.push([CVDL[0],CVDL[1]]);
item2.push([CVDL[0],CVDL[2]]);
item3.push([CVDL[0],CVDL[3]]);
}

var ans=[];

var dp=[];
for(var i=0;i<=n;i++){
dp[i]=[];
for(var j=0;j<=m;j++){
dp[i][j]=0;
}
}

for(var i=1;i<=n;i++){
for(var j=1;j<=m;j++){
   var c=item1[i][0];
   var w=item1[i][1];
   if(c<=j)dp[i][j]=Math.max(dp[i-1][j],w+dp[i-1][j-c],w+dp[i][j-c]);
   else dp[i][j]=dp[i-1][j];
}
}

ans.push(dp[n][m]);

var dp=[];
for(var i=0;i<=n;i++){
dp[i]=[];
for(var j=0;j<=m;j++){
dp[i][j]=0;
}
}

for(var i=1;i<=n;i++){
for(var j=1;j<=m;j++){
   var c=item2[i][0];
   var w=item2[i][1];
   if(c<=j)dp[i][j]=Math.max(dp[i-1][j],w+dp[i-1][j-c],w+dp[i][j-c]);
   else dp[i][j]=dp[i-1][j];
}
}

ans.push(dp[n][m]);

var dp=[];
for(var i=0;i<=n;i++){
dp[i]=[];
for(var j=0;j<=m;j++){
dp[i][j]=0;
}
}

for(var i=1;i<=n;i++){
for(var j=1;j<=m;j++){
   var c=item3[i][0];
   var w=item3[i][1];
   if(c<=j)dp[i][j]=Math.max(dp[i-1][j],w+dp[i-1][j-c],w+dp[i][j-c]);
   else dp[i][j]=dp[i-1][j];
}
}

ans.push(dp[n][m]);

console.log(Math.max(ans[0],ans[1],ans[2]));


}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

#define int int64_t

/*global*/



signed main()
{
	int n; cin >> n;
	vector<int> h(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> h[i];

	reverse(h.begin(), h.end());
	int max{};
	int cnt{};
	for(int i = 1; i < n; ++i)
	{
		if(h[i-1] <= h[i]) cnt++;
		else cnt=0;//cnt{}初期化であって=0ではない
		amax(max, cnt);
	}
	cout << max << '\n';
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

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

#define lowbit(x) (x&-x)

using namespace std;

const int MAXN=2e5+1;

int sum[MAXN]={0},n,ans=0;

inline void update(const int &x) {
	for(int i=x; i<=n; i+=lowbit(i))
		++sum[i];
	return ;
}

inline int query(const int &x) {
	int res=0;
	for(int i=x; i; i-=lowbit(i))
		res+=sum[i];
	return res;
}

int main() {
	scanf("%d",&n);
	for(int i=0,p; i<n; ++i) {
		scanf("%d",&p);
		if(!query(p)) ++ans;
		update(p);
	}
	cout<<ans<<endl;
	return 0;
}

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

int func(int a){
  if(a%2==0){
    return a/2;
  }else{
    return a*3 + 1;
  }
}

int main() {
  int s;
  cin >> s;
  vector<int> as(1000);
  int a;
  for(int i=1;;i++){
    if(i==1){
      a = s;
      as.at(i-1) = a;
      continue;
    }
    a = func(a);
    as.at(i-1) = a;
    for(int j=1;j<i;j++){
      if( as.at(i-1) == as.at(j-1) ){
        cout << i << endl;
        return 0;
      }
    }
  }
    
  

  return 0;
  
}

Measured memory_bytes: 256
import sys

A, B = list(map(int, input().split()))
a = int(A/0.08)
b = int(B/0.1)

if a > b: a, b = b, a

a -= 1
b += 1

for i in range(a, b+1):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        sys.exit()
        
print(-1)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include <string>

using namespace std;


int ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return -1;
	}
}

int main() {
	char S[11];
	string ans;
	cin >> S;
	if (ctoi(S[5]) == 1)
		ans = "TBD";
	else if (ctoi(S[6]) > 4)
		ans = "TBD";
	else
		ans = "Heisei";

	cout << ans;

	return 0;
}



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

void answer() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if(k>0) {
    ans += min(a, k);
    k -= min(a, k);
  }
  if(k>0) {
    k -= min(b, k);
  }
  if(k>0) {
    ans -= min(c, k);
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

ll minCostDP(ll h[], ll n, ll k){
  ll dp[n+1];
  dp[0] = 0;
  for(ll i=1; i<n; i++){
    ll m = INT_MAX;
    for(ll j=1; j<=min(i,k); j++){
    	m = min(m, dp[i-j] + abs(h[i]-h[i-j]));
    }
    dp[i] = m;
  }
  return dp[n-1];
    
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n,k;
  cin>>n>>k;
  ll h[n];
  for(ll i=0; i<n; i++){
  	cin>>h[i];
  }
  ll ans = minCostDP(h,n,k);
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

#define PT pair<double, int>

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



	ll X[1002] = {}, Y[1002] = {}, R[1002] = {};
	int xt, yt;
	cin >> X[0] >> Y[0] >> xt >> yt;
	int N;
	cin >> N;
	X[N + 1] = xt;
	Y[N + 1] = yt;
	rep1(i, N) {
		cin >> X[i] >> Y[i] >> R[i];
	}

	vector<PT> E[1002];

	rep(i, N + 2) {
		for (int j = i + 1; j < N + 2; j++) {
			double k = max(0.0, sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])) - R[i] - R[j]);
			E[i].pb(mp(k, j));
			E[j].pb(mp(k, i));
		}
	}

	double D[100000];
	rep(i, N + 2) D[i] = 1e18;
	D[0] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;

	que.push(mp(0.0, 0));
	while (que.size()) {
		PT p = que.top();
		que.pop();
		int i = p.second;
		if (D[i] != p.first) continue;
		for (PT p2 : E[i]) {
			int j = p2.second;
			double d = D[i] + p2.first;
			if (D[j] > d) {
				D[j] = d;
				que.push(mp(d, j));
			}
		}
	}

	cout << fixed << setprecision(12) << D[N + 1];

	Would you please return 0;
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353

const int INF = MOD;

vi A(100005);
vi dp(100005);


int main() {
    int N; cin >> N;
    A.assign(N,0);
    rep(i,N) cin >> A[i];
    reverse(all(A));

    dp.assign(N,INF);
    dp[0] = A[0];
    int ans = 1;
    for(int i = 1; i < N; i++){
        if(dp[ans-1] <= A[i]){
            dp[ans++] = A[i];
        }
        else{
            *lower_bound(all(dp),A[i]+1) = A[i];
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int a, b, c; cin >> a >> b >> c;
	vector<int> p = {a, b, c};
	sort( p.begin(), p.end() );
	if(
		p[0] != p[1] and p[1] == p[2]
			or 
		p[0] == p[1] and p[1] != p[2]
	) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.6
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  
  map<int,int> odd,even;
  int qw,er;
  rep(i,0,n/2){
    cin >> qw >> er;
    odd[qw]++;
    even[er]++;
  }
  Vi oddd(1),evenn(1);
  int maxo=0,maxe=0;
  int keyo,keye;
  for (auto p : odd) {
    auto k = p.first;
    auto v = p.second;
    oddd.pb(v);
    maxo = max(maxo,v);
    if(maxo==v) keyo = k;
  }
  for (auto p : even) {
    auto k = p.first;
    auto v = p.second;
    evenn.pb(v);
    maxe = max(maxe,v);
    if(maxe==v) keye = k;
  }
  
  sort(ALL(evenn));
  reverse(ALL(evenn));
  sort(ALL(oddd));
  reverse(ALL(oddd));
  
  if(keye!=keyo) cout << n - oddd[0] - evenn[0] << endl;
  else cout << min(n-oddd[0]-evenn[1],n-oddd[1]-evenn[0]) << endl;

  return 0;
}


Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int x;
    cin >> x;

    for(int a=0; a*a*a*a<=x; a++){
        for(int b=0; a*a*a*a+b*b*b*b<=x; b++){
            if(a*a*a*a*a + b*b*b*b*b == x){
                if(b > a) swap(a, b);
                cout << a << " " << -b << endl;
                return 0;
            }
            else if(a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli dp[2005][2005];
long long binpow(long long a, long long b, long long m) {
    m = MOD;
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout)
    lli t;
    //cin>>t;
    t = 1;
    while(t--){
       // lli n;
        lli n;
        cin>>n;
        vector <lli> a,b,c,d;
        for(lli i = 0; i<n; i++){
            lli x,y;
            cin>>x>>y;
            a.push_back(x+y);
            b.push_back(-x-y);
            c.push_back(-x+y);
            d.push_back(x-y);
        }
        lli x1 = *max_element(a.begin(),a.end());
        lli x2 = *min_element(a.begin(),a.end());
        lli ans = x1-x2;
         x1 = *max_element(b.begin(),b.end());
         x2 = *min_element(b.begin(),b.end());
        ans = max(x1-x2,ans);
         x1 = *max_element(c.begin(),c.end());
         x2 = *min_element(c.begin(),c.end());
        ans = max(x1-x2,ans);
         x1 = *max_element(d.begin(),d.end());
         x2 = *min_element(d.begin(),d.end());
        ans = max(x1-x2,ans);
         cout<<ans<<endl;
    }
}

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

int main(){
  string s;cin>>s;
  int u=0,v=0,n=s.size();
  for(int i=0;;i++){
    u=i;
    if(s[i]=='A')break;
  }
  for(int i=n;;i--){
    v=i;
    if(s[i]=='Z')break;
  }
  // cout<<u<<' '<<v<<endl;
  cout<<v-u+1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

int w, h, ans = 0;
int state[1001][1001];
int score[1001][1001];
void show(){
	rep(i,h){
		rep(j,w){
			if(state[j][i] == 0)cout << '.';
			else cout << state[j][i];
		}
		cout << endl;
	}
}

int main(void){
	cin >> h >> w;
	fill_n(*state, 1001*1001, -1);
	rep(i,h)rep(j,w){
		char c;
		cin >> c;
		if(c == '.')state[j][i] = 0;
		else state[j][i] = c-'0';
	}
	queue<P> que;
	rep(i,h)rep(j,w){
		if(state[j][i] == 0)continue;
		int count = 0;
		rep(k,8){
			int nx = j+dx[k];
			int ny = i+dy[k];
			if(nx < 0 || ny < 0 || state[nx][ny] == -1)continue;
			if(state[nx][ny] == 0)count++;
		}

		score[j][i] = count;
		if(state[j][i] <= count){
			que.push(P(j, i));
		}
	}
	///show();
	int memo[1001][1001] = {0};
	while(!que.empty()){
		queue<P> reQue;
		while(!que.empty()){
			reQue.push(que.front());
			///cout << "(" << que.front().first << "," << que.front().second << ")" << endl;
			P p = que.front();
			int x = p.first;
			int y = p.second;
			state[x][y] = 0;
			score[x][y] = 0;
			rep(k,8){
				int nx = x+dx[k];
				int ny = y+dy[k];
				score[nx][ny]++;
			}
			que.pop();
		}
		while(!reQue.empty()){
			P p = reQue.front();
			reQue.pop();
			int x = p.first;
			int y = p.second;
			///cout << "(" << x << "," << y << ")" << endl;
			rep(k,8){
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(nx < 0 || ny < 0 || state[nx][ny] == -1)continue;
				if(state[nx][ny] == 0 || state[nx][ny] == 9)continue;
				if(state[nx][ny] <= score[nx][ny] && !memo[nx][ny]){
					memo[nx][ny]=1;
					que.push(P(nx, ny));
				}
			}
		}
		ans++;
	}
	cout << ans << endl;

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 12976
using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
	    chokudai.AtCoder();
	}
}

public class Kyopuro{
    public void AtCoder(){
        string[] s = Console.ReadLine().Split(' ');
        int n = int.Parse(s[0]);
        int a = int.Parse(s[1]);
        int b = int.Parse(s[2]);
        int x = 0;
        int y = 0;
        int ta = a;
        int tb = b;
        for(int i=0; i<n; i++){
            if(ta % 2 == 1) x++;
            if(tb % 2 == 1) y++;
            ta /= 2;
            tb /= 2;
        }
        if(x % 2 == y % 2){
            Console.WriteLine("NO");
            return;
        }
        Console.WriteLine("YES");
        int[] t = new int[n+1];
        t[0] = 1;
        for(int i=1; i<=n; i++){
            t[i] = t[i-1] * 2;
        }
        
        int[] z = new int[t[n]];
        z[0] = 0;
        z[1] = 1;
        for(int i=1; i<n; i++){
            for(int j=t[i]; j<t[i+1]; j++){
                z[j] = z[t[i+1] - j - 1];
                z[j] += t[i];
            }
        }
        int[] z1 = new int[t[n-1]];
        int[] z2 = new int[t[n-1]];
        for(int i=0; i<t[n]; i++){
            if(x % 2 == 0){
                if(i % 2 == 0) z1[i/2] = z[i];
                if(i % 2 == 1) z2[i/2] = z[i];
            }
            if(x % 2 == 1){
                if(i % 2 == 0) z2[i/2] = z[i];
                if(i % 2 == 1) z1[i/2] = z[i];
            }
        }
        int start = 0;
        while(z1[start] != a) start++;
        int p = start;
        while(true){
            Console.Write(z1[p]+" ");
            if(z2[p] == b) break;
            Console.Write(z2[p]+" ");
            p++;
            if(p>=t[n-1]) p = 0;
        }
        int f = 0;
        while(true){
            if(p + 1 == start || (p + 1 == t[n-1] && start == 0)){
                f = 1;
                break;
            }
            p++;
            if(p>=t[n-1]) p = 0;
            Console.Write(z2[p]+" ");
            
            if(p + 1 == start || (p + 1 == t[n-1] && start == 0)){
                f = 2;
                break;
            }
            p++;
            if(p>=t[n-1]) p = 0;
            Console.Write(z1[p]+" ");
        }
        
        if(f == 1){
            p++;
            if(p>=t[n-1]) p = 0;
            while(true){
                p--;
                if(p<0) p = t[n-1] - 1;
                if(z2[p] == b) break;
                Console.Write(z2[p]+" ");
                p--;
                if(p<0) p = t[n-1] - 1;
                Console.Write(z1[p]+" ");
            }
        }
        if(f == 2){
            p++;
            if(p>=t[n-1]) p = 0;
            while(true){
                p--;
                if(p<0) p = t[n-1] - 1;
                Console.Write(z1[p]+" ");
                p--;
                if(p<0) p = t[n-1] - 1;
                if(z2[p] == b) break;
                Console.Write(z2[p]+" ");
            }
        }
        Console.WriteLine(b);
    }
    
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}

Measured memory_bytes: 18092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
int dp[110][4][4][4];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	dp[0][3][3][3] = 1;
	rep(i, n) {
		rep(j, 4) {
			rep(k, 4) {
				rep(l, 4) {
					rep(m, 4) {
						if (j == 0 && k == 1 && l == 2) continue;
						if (j == 0 && k == 2 && l == 1) continue;
						if (j == 1 && k == 0 && l == 2) continue;
						if (m == 0 && j == 1 && l == 2) continue;
						if (m == 0 && k == 1 && l == 2) continue;
						dp[i + 1][j][k][l] += dp[i][m][j][k];
						dp[i + 1][j][k][l] %= mod;
					}
				}
			}
		}
	}
	int ans = 0;
	rep(j, 4) rep(k, 4) rep(l, 4) ans += dp[n][j][k][l];
	cout << ans % mod << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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

int main(){
	int N; cin>>N;
	vector<ip> M(N);
	rep(i,N)cin>>M[i].first>>M[i].second;
	vector<vector<int>> dp(N,vector<int>(N,inf));
	rep(i,N)dp[i][i] = 0;
	for(int i = 1; i<N; ++i){
		int l = 0, r = i;
		for(int j = 0; j<N-i; ++j){
			for(int k = l; k<r; ++k){
				chmin(dp[l][r], dp[l][k] + dp[k+1][r] + M[l].first * M[k].second * M[r].second);
				// chmin(dp[l][r], dp[l][r-1] + M[l].first * M[r].first * M[r].second);
			}
			// printf("[l,r] => [%d,%d]\n",l,r);
			++l; ++r;
		}
	}
	cout<<dp[0][N-1]<<endl;
	return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const int MOD=1e9+7;
const ll INF=1e18;
const ll inf=1e9;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

ll dp[3010][3010][4];
int mas[3010][3010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int R, C, K;
  cin >> R >> C >> K;
  
  while(K--){
    int y, x, v;
    cin >> y >> x >> v;
    y--;
    x--;
    mas[y][x] = v;
  }
  
  memset(dp, 0, sizeof(dp));
  rep(i, R+1)rep(j, C+1)rep(k, 4){
    if(k == 3){
      if(i+1 <= R) chmax(dp[i+1][j][0], dp[i][j][k]);
      if(j+1 <= C) chmax(dp[i][j+1][k], dp[i][j][k]);
    }
    else{
      if(i+1 <= R) chmax(dp[i+1][j][0], dp[i][j][k]+mas[i][j]);
      if(j+1 <= C){
        chmax(dp[i][j+1][k], dp[i][j][k]);
        chmax(dp[i][j+1][k+1], dp[i][j][k]+mas[i][j]);
      }
    }
  }
  
  ll ans = 0;
  rep(k, 4) chmax(ans, dp[R][C][k]);
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 321996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin>>n;
pair<pair<string,int>,int> a[105];
  for(ll i = 1; i<=n; i++){
      cin>>a[i].first.first>>a[i].first.second;
      a[i].first.second *= -1;
      a[i].second = i;
      
  }
  sort(a,a+n+1);
  for(ll i = 1; i<=n; i++){
      cout<<a[i].second<<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 pii pair<int,int>
#define INF 1000000000

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

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

  int getmin(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    if(r<=a||b<=l) return INF;
    if(a<=l&&r<=b) return node[k];
    int vl = getmin(a,b,2*k+1,l,(l+r)/2);
    int vr = getmin(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }

  void show(){
    for(int i=n-1;i<node.size()-1;i++){
      cout << node[i] << " ";
    }
    cout << node[node.size()-1] << endl;
  }
};

int main(){

  int w;
  cin >> w;
  vector<int> a(w);
  rep(i,w)cin >> a[i];
  int n_e=0;
  vector<int> escape;
  rep(i,w)if(a[i]==0){
    n_e++;
    escape.push_back(i);
  }
  if(n_e==0){
    cout << 0 << endl;
    return 0;
  }
  // 各ユニットの最寄りの出口
  vector<int> nearL(w,-INF),nearR(w,-INF);
  vector<int> dd,dd2;
  int ind = -1;
  rep(i,w){
    if(a[i]>0){
      nearL[i] = ind;
      nearR[i] = ind+1;
      if(ind+1==n_e)nearR[i]=-1;
      dd.push_back(INF);
      dd2.push_back(INF);
    }else if(a[i]==0){
      ind++;
      dd.push_back(INF/2);
      dd2.push_back(INF/2);
    }else{
      dd.push_back(-a[i]+i);
      dd2.push_back(-a[i]-i);
    }
  }

  SegmentTree st1(dd),st2(dd2);

  int sum = 0;
  int el,er,flag,minl,minr;
  int lflag=1,rflag=1;
  rep(i,w){
    if(a[i]>0){
      if(nearL[i]>=0) {el = escape[nearL[i]];lflag=1;}
      else lflag=0;
      if(nearR[i]>=0) {er = escape[nearR[i]];rflag=1;}
      else rflag=0;
      flag = 0;
      minl = -INF; minr = -INF;
      if(lflag&&st1.getmin(el,i)<INF/2){minl = max(st1.getmin(el,i)-i,0);flag=1;}
      else if(lflag&&st1.getmin(el,i)==INF/2){minl = a[i];}
      if(rflag&&st2.getmin(i+1,er+1)<INF/2){minr = max(st2.getmin(i+1,er+1)+i,0);flag=1;}
      else if(lflag&&st2.getmin(i+1,er+1)==INF/2){minr = a[i];}
      int ret = min(max(minl,minr),a[i]);
      if(flag)sum += ret;
      else sum += a[i];
    }
  }
  
  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 7768
#include<iostream> 
#include<string>  
#include<algorithm> 
#include<vector>
using namespace std;
 
int main() {
	vector <int> a(3);  
	for (int i = 0; i < 3; i++)
	{
		cin >> a.at(i);
	} 
	sort(a.begin(), a.end());
		cout << a.at(0) + (a.at(2) * 10 + a.at(1)) << "\n";

 

	


}

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

int main(){
 int N;
 cin >> N;
 int d[N];
 for(int i= 0;i<N;i++){
     cin >> d[i];
 }
 int z = 0;
 for(int i= 0;i<N;i++){
    for(int j=i+1;j<N;j++){
         z += d[i]*d[j];
        }
 }
     cout << z << endl;
     return 0;
}

Measured memory_bytes: 256
li = [list(map(int, input().split())) for _ in range(3)]
sum1 = li[0][0] + li[1][1] + li[2][2]
sum2 = li[1][0] + li[2][1] + li[0][2]
sum3 = li[2][0] + li[0][1] + li[1][2]
if sum1 ==sum2 and sum2 == sum3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> nedan(n);
    rep(i,n) cin >> nedan[i];
    sort(nedan.begin(),nedan.end());

    int ans=0;
    rep(i,k){
        ans += nedan[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a.insert(0,-1)

freq=[]
for i in range(n+1):
	freq.append(0)

pos=1
pos=a[pos]
cycle=[]
while freq[pos]==0:
	freq[pos]+=1
	cycle.append(pos)
	pos=a[pos]

flag=0
c1=[]
c2=[]
for i in range(len(cycle)):
	if cycle[i]==pos:
		flag=1
	if flag==0:
		c1.append(cycle[i])
	else:
		c2.append(cycle[i])

#print(c1,c2)

l1=len(c1)
l2=len(c2)

if k<=l1:
	print(c1[k-1])
else:
	k-=l1
	print(c2[k%l2-1])

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
P a[100010];
signed main(){
  int n,m;cin>>n>>m;
  rep(i,n)cin>>a[i].F>>a[i].S;
  sort(a,a+n);
  int ans=0;
  rep(i,n){
    if(m<=a[i].S){
      ans+=(a[i].F)*m;
      break;
    }
    else {
      ans+=(a[i].F)*(a[i].S);
      m-=a[i].S;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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


int N, M, H, K;
int a[510], b[510], c[510], h[510], r[510];
int S, T;
int P;
int l[1000], d[1000];
vector<int> k[1000];

vector<tuple<int, int, int>> G[110]; // i -> j cost time

void init() {
	rep(i, 110) G[i].clear();
	rep(i, 1000) k[i].clear();
}

int dp[1000];
int fadd(int x) {
	int ret = 0;
	for(int i = 0; i < l[x]; i++) {
		ret += (1<<k[x][i]);
	}
	return ret;
}
void bitdp(void) {
	rep(i, 1000)dp[i] = INF;
	dp[0] = 0;
		
	for(int i = 0; i < P; i++){
		int addmask = fadd(i); // i????????????????????????
		for(int mask = 0; mask < (1<<K); mask++) {
			if(dp[mask] == INF) continue;
			dp[mask | addmask] = min(dp[mask | addmask], dp[mask] + d[i]);// use 
		}
	}
}
	
	
	
int dist[110][30]; // tyouten time := cost
using tup = tuple<int, int, int>;
int dijkstra(int start, int goal, int limit){
	dist[start][0] = 0;
	rep(i, 110)rep(j, 30) dist[i][j] = INF;
	priority_queue<tup, vector<tup>, greater<tup>> que; // cost v time
	que.push(make_tuple(0, start, 0));
	while(!que.empty()) {
		int cost, u, time; tie(cost, u, time) = que.top(); que.pop();
		//cout << "cost u time " << cost << " " << u << " " << time << endl;
		if(u == goal) return cost;
		if(dist[u][time] < cost) continue;
		for(auto tmp : G[u]) {
			int v, nc, nt; tie(v, nc, nt) = tmp;
			int ncost = cost + nc;
			int ntime = time + nt;
			if(ntime > limit) continue;
			if(dist[v][ntime] > ncost) {
				dist[v][ntime] = ncost;
				que.push(make_tuple(ncost, v, ntime));
			}
		}
	}
	return INF; // -1
}
	
int main(void) {
	while(1) {
		init();
		
		cin >> N >> M >> H >> K;
		if(N == 0 && M == 0 && H == 0 && K == 0) break;
		rep(i, M) cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i];
		rep(i, M) a[i]--, b[i]--, r[i]--;
		cin >> S >> T;
		S--; T--;
		cin >> P;
		rep(i, P) {
			cin >> l[i] >> d[i];
			rep(j, l[i]) {
				int tmp; cin >> tmp; tmp--;
				k[i].push_back(tmp);
			}
		}
		
		bitdp();
		/*
		cout << "dp" << endl;
		rep(i, (1<<K)) cout << dp[i] << endl;
		cout << endl;
		*/
		int ans = INF;
		for(int mask = 0; mask < (1<<K); mask++) { // O(10^3) tukau tetudoukaisya
			rep(i, 110) G[i].clear();
			//cout << "mask " << mask << endl;
			// ????????????
			rep(i, M){
				int cost = c[i];
				//cout << "r " << r[i] << endl;
				if((mask & (1<<r[i])) != 0)  cost = 0;
				//cout << "co " << cost <<" " << c[i] << endl;
				G[a[i]].push_back(make_tuple(b[i], cost, h[i]));
				G[b[i]].push_back(make_tuple(a[i], cost, h[i]));
			}
			int di = dijkstra(S, T, H);
			//cout << "di " << di << " " << dp[mask] << endl;
			ans = min(ans, di + dp[mask]);
		}
		if(ans != INF) cout << ans << endl;
		else cout << -1 << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3344
mod=10**9+7
k=int(input())
s=input()
l=len(s)
fact=[1]
for i in range(1,k+l+1):
  fact.append((fact[-1]*i)%mod)
revfact=[]
for i in range(k+l+1):
  revfact.append(pow(fact[i],mod-2,mod))
pow1=[1]
pow2=[1]
for i in range(1,k+l+1):
  pow1.append((pow1[-1]*25)%mod)
  pow2.append((pow2[-1]*26)%mod)
ans=0
for i in range(k+l):
  coef1=(pow1[k-i]*pow2[i])%mod
  if i<=k:
    coef2=(fact[k+l-1-i]*revfact[l-1]*revfact[k-i])%mod
  else:
    coef2=0
  ans+=coef1*coef2
  ans%=mod
print(ans)

Measured memory_bytes: 227552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int A[M];
    for (int i=0; i<M; i++){
        cin >> A[i];
    }
    
    int res1=0, res2=0;
    for (int i=0; i<M; i++) {
        if (X <= A[i]) res1++;
        else res2++;
    }

    cout << min(res1, res2) << endl;
}


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

int main(){
    long long n, m;
    cin >> n >> m;
    vector< pair<long, long> > p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    long long ans = 0;
    for(int i = 0; i < n; i++){
        if(m <= p[i].second){
            ans += m * p[i].first;
            break;
        }else{
            ans += p[i].second * p[i].first;
        }
        m -= p[i].second;
    }
    cout << ans << endl;




}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int A, B, H, M;
long double ans;
int main()
{
	cin >> A >> B >> H >> M;
	int t = abs(60 * H - 11 * M);
	if (t > 360)
	{
		t = 720 - t;
	}
	if (t == 360)
	{
		ans = A + B;
	}
	else if (t == 0)
	{
		ans = abs(A - B);
	}
	else
	{
		ans = sqrt(A * A + B * B - 2 * A * B * cos((long double)t / 2.0 * (acos(-1.0) / 180.0)));
	}
	printf("%.20Lf\n", ans);
	return 0;
}


Measured memory_bytes: 4152
#include<stdio.h>
main(){
  int K,sum=0,x,i;
  while(scanf("%d",&K)){
    if(K==0)break;
    sum=0;
    for(i=0;i<K*(K-1)/2;i++){
      scanf("%d",&x);
      sum+=x;
    }
    printf("%d\n",sum/(K-1));
    
  }
}

Measured memory_bytes: 0
def solve():
    INF = float('inf')
    P = 0
    D = 1

    Ts = input().rstrip()

    N = len(Ts)

    dp = [[-INF]*(2) for _ in range(N+1)]
    dp[0][D] = 0
    prevss = [[-1]*(2) for _ in range(N+1)]
    for i, T in enumerate(Ts, start=1):
        if T == 'P' or T == '?':
            dpP = dp[i-1][P]
            dpD = dp[i-1][D]
            if dpP >= dpD:
                dp[i][P] = dpP
                prevss[i][P] = P
            else:
                dp[i][P] = dpD
                prevss[i][P] = D
        if T == 'D' or T == '?':
            dpP = dp[i-1][P] + 2
            dpD = dp[i-1][D] + 1
            if dpP >= dpD:
                dp[i][D] = dpP
                prevss[i][D] = P
            else:
                dp[i][D] = dpD
                prevss[i][D] = D

    #for i in range(N+1):
    #    print(dp[i], Ts[i-1])

    if dp[-1][P] >= dp[-1][D]:
        j = P
    else:
        j = D
    anss = [j]
    for i in reversed(range(2, N+1)):
        j = prevss[i][j]
        anss.append(j)
    #print(anss)

    anss = ''.join(['P' if ans == P else 'D' for ans in anss[::-1]])
    print(anss)


solve()


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

using namespace std;
int main(void) {

long long int a,b,n,maxx=0,x,f;cin>>a>>b>>n;
 long long int hope_x=b-1;
  if(hope_x<=n) x=hope_x;
  else  x=n; 
 // for(int i=1;i<=x;i++){
   // f=(a*i)/b-a*(i/b);
    //maxx=max(maxx,f);
  //}
  cout<<(a*x)/b-a*(x/b);
}


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

int main() {
  int r,g,b; cin >> r >> g >> b;
  int num = 100*r + 10*g + b;
  if ( num % 4 == 0 ) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int k, s;

void solve(){
    int cnt = 0;
    for (int i = 0; i <= k; i++)
        for (int j = 0; j <= k; j++)
            if (0 <= s - i - j && s - i - j <= k) cnt++;
 
    printf("%d\n", cnt);
}
 
int main(void){
    cin >> k >> s;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    long long int n,a=10,count=0;
    scanf("%lld",&n);
    if(n%2==0)
    {
        while(a<=n)
        {
            count+=n/a;
            a*=5;
        }
    }
    printf("%lld",count);
return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x)
{
	cout << s << " = " << x << "\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args)
{
	cout << s.substr(0, s.find(',')) << " = " << x << " | ";
	debug(s.substr(s.find(',') + 2), args...);
}
template<class T> void print_container(T &container)
{
	for (auto &t : container)
	{
		cout << t << " ";
	}
	cout << endl;
}
template<class T> void print_pair_container(T &container)
{
	for (auto &t : container)
	{
		cout << t.first << " " << t.second << endl;
	}
	cout << endl;
}
template<class T> void printArr(T &a, int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
int n;
int a[N];

ll power(ll a, ll n, ll m) {
	a %= m;
	ll res = 1;
	while (n > 0) {
		if (n % 2)
			res = res * a % m;
		a = a * a % m;
		n /= 2;
	}
	return res;
}



void solve()
{
	ll e = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		e += a[i];
		e %= mod;
	}

	e = power(e, 2, mod);


	ll prod = 0;
	for (int i = 0; i < n; i++) {
		prod += power(a[i], 2, mod);
		prod %= mod;
	}

	ll ans = (e - prod + mod) % mod;

	ans = (ans * power(2, mod - 2, mod)) % mod;

	cout << ans << endl;
}

int32_t main()
{
	IOS;

	solve();

	return 0;
}




Measured memory_bytes: 5164
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    E = list(map(lambda x: (1+x)/2, P))
    tmp = sum(E[:K])
    ans = tmp
    for i in range(K, N):
        tmp += E[i] - E[i-K]
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 77448
#include <string>
#include <math.h>
#include <iostream>
 
using namespace std;
 
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int x = c - b;
  int y = b - a;
  if (x == y)
    cout << "YES";
  else
    cout << "NO";
}

Measured memory_bytes: 3616
// Contest: AtCoder Beginner Contest 176 (https://atcoder.jp/contests/abc176)
// Problem: B: Multiple of 9 (https://atcoder.jp/contests/abc176/tasks/abc176_b)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    string n; cin >> n;
    int s = 0;
    trav(c, n)
        s += c - '0';
    cout << (s % 9 ? "No\n" : "Yes\n");

    return 0;
}


Measured memory_bytes: 3688
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 A;
    string B;
    cin >> A >> B;
    int64 C=0;
    for(auto b:B){
        if('0'<=b and b<='9'){
            C*=10;
            C+=b-'0';
        }
    }
    // debug(A)
    // debug(C)
    cout << A*C/100 << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <utility>

using namespace std;

int main()
{
  pair<int, int> perf[20], max;
  int i, n;

  cin >> n;
  for (i = 0; i < n; i++) {
	cin >> perf[i].first >> perf[i].second;
  }

  max = perf[0];
  for (i = 1; i < n; i++) {
    if ((max.second < perf[i].second) || 
        (max.second == perf[i].second && max.first > perf[i].first)) {
      max = perf[i];
    }
  }

  cout << max.first << " " << max.second << endl;

  return 0;
}

Measured memory_bytes: 1164
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

//↑template↑






int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << a + b + c - max({ a,b,c }) << endl;
}

Measured memory_bytes: 256
n=int(input())
k=int(input())
ab=[]
for _ in range(k):
    ab1=list(map(int,input().split()))
    ab.append([ab1[1]-1,ab1[0]-1])
c=[]
if n%2==0:
    nn=n//2
    for i in range(k):
        y=ab[i][0]
        x=ab[i][1]
        if ab[i][0]>=nn:
            y=n-ab[i][0]-1
            if ab[i][1]>=nn:
                x=n-ab[i][1]-1
        else:
            if ab[i][1]>=nn:
                x=n-ab[i][1]-1
        c.append((min(x,y)+1)%3)
else:
    nn=(n+1)//2
    for i in range(k):
        y=ab[i][0]
        x=ab[i][1]
        if ab[i][0]>=nn:
            y=n-ab[i][0]-1
            if ab[i][1]>=nn:
                x=n-ab[i][1]-1
        else:
            if ab[i][1]>=nn:
                x=n-ab[i][1]-1
        c.append((min(x,y)+1)%3)
for i in c:
    if i!=0:
        print(i)
    else:
        print(3)


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

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a%2==0 || b%2==0 || c%2==0){
    cout<<0<<endl;
  }else{
    if(a>b)swap(a,b);
    if(b>c)swap(b,c);
    if(a>b)swap(a,b);
    cout<<a*b<<endl;
  }
  return 0;
}


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

const ll mod=1000000007;

int main() {
 string s;
 cin >> s;
  r(i,s.size()){
    if(s[i]!='D'&&s[i]!='P')s[i]='D';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3752
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <stdio.h>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int H, W;
    while(true){
    scanf("%d %d", &H, &W);
    if(H == 0) break;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if((i % 2 == 0 && j % 2 == 0) || i % 2 != 0 && j % 2 != 0)
                printf("#");
            else
                printf(".");
        }
        printf("\n");
    }
    printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2564