akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	string s, t, ans;
	cin >> s >> t;
	int s1 = s.length();
	int t1 = t.length();
	if (s1 > t1) {
		rep(i, t1) {
			ans += s[i];
			ans += t[i];
		}
		ans += s[s1 - 1];
	}
	else {
		rep(i, s1) {
			ans += s[i];
			ans += t[i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

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

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x % 2 && i % 2)
            ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int cnt = 0, ans = 0;
	rep(i, n) {
		if(s[i] == 'L') {
			if(i && s[i-1] == 'L') cnt++;
		} else {
			if(i+1 < n && s[i+1] == 'R') cnt++;
		}
	}

	ans = cnt + 2 * k;
	chmin(ans, n - 1);
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 512
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;

int main() {
    ll H, W;
    cin >> H >> W;
    auto make_id = [&](ll h, ll w) { return h * W + w; };
    auto in_range = [&](ll h, ll w) { 
        return 0 <= h && h < H &&
               0 <= w && w < W;
    };
    V<string> vs(H);
    for (auto &&s : vs) cin >> s;
    auto dists = make_v<ll>(inf, H * W, H * W);
    ll dh[] = { 1, 0, -1, 0, };
    ll dw[] = { 0, 1, 0, -1, };
    for (ll h = 0; h < H; h++) for (ll w = 0; w < W; w++) {
        if (vs[h][w] == '#') continue;
        ll fid = make_id(h, w);
        dists[fid][fid] = 0;
        for (ll i = 0; i < 4; i++) {
            ll nh = h + dh[i], nw = w + dw[i];
            if (!in_range(nh, nw)) continue;
            if (vs[nh][nw] == '#') continue;
            ll tid = make_id(nh, nw);
            dists[fid][tid] = 1;
        }
    }

    for (ll k = 0; k < H * W; k++) for (ll i = 0; i < H * W; i++) for(ll j = 0; j < H * W; j++) chmin(dists[i][j], dists[i][k] + dists[k][j]);

    ll ans = 0;
    for (ll i = 0; i < H * W; i++) for (ll j = 0; j < H * W; j++) {
        if (dists[i][j] == inf) continue;
        chmax(ans, dists[i][j]);
    }

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


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

int main()
{
    int n,i,k,j;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    cin>>arr[i];

    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);

    for(i=2;i<n;i++)
        dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);

        cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rg register
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
inline ll min(ll x,ll y){return x<y?x:y;}
inline ll max(ll x,ll y){return x>y?x:y;}
const int Maxn=2e5+5;
inline int read()
{
	rg int res=0,sign=1;
	rg char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
			sign=-1;
		ch=getchar();
	}
	do
	{
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}while(isdigit(ch));
	return res*sign;
}
int n;
int a[Maxn],Max,Min;
bool b[Maxn];
bool check(int x)
{
	for(int i=1;i<=2*n-1;i++)
		b[i]=a[i]>=x;
	if(b[n]==b[n+1]) return b[n+1];
	if(b[n]==b[n-1]) return b[n-1];
	int l=0,r=0;
	for(int i=n-1;i>=1;i--)
		if(b[i]!=b[i+1])
			l++;
		else
			break;
	for(int i=n+1;i<2*n;i++)
		if(b[i]!=b[i-1])
			r++;
		else
			break;
	return l<r?b[n-l]:b[n+r];
}
int Search(int l,int r)
{
	if(l==r)
		return l;
	int mid=(l+r>>1)+1;
	if(check(mid))
		return Search(mid,r);
	return Search(l,mid-1);
}
int main()
{
	cin>>n;
	for(int i=1;i<=2*n-1;i++)
		a[i]=read();
	Min=Max=a[1];
	for(int i=2;i<=2*n-1;i++)
	{
		Min=min(Min,a[i]);
		Max=max(Max,a[i]);
	}
	cout<<Search(Min,Max)<<endl;
	return 0;
}


Measured memory_bytes: 1280
import math
import fractions
a, b, c, d = (int(i) for i in input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y) 

def num_div(first, last, div):
  return last//div - (first-1)//div

c_div = num_div(a, b, c)
d_div = num_div(a, b, d)
cd_div = num_div(a, b, lcm(c, d))

print(b - a - (c_div + d_div - cd_div) + 1)

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define pow(x) (x)*(x)
#define mid(min, max) ((min + max) / 2)


int main() {
	in2(m1, d1);
	in2(m2, d2);

	out(m1==m2 ? 0 : 1);

	return 0;
}


Measured memory_bytes: 256
H,N=map(int,input().split())
lab=[]
maxa=0
for i in range(N):
    a,b=map(int,input().split())
    if a>maxa:
        maxa=a
    lab.append([a,b])
ldp=[10**9 for _ in range(H+maxa)]
ldp[0]=0
for i in range(1,H+maxa):
    ldp[i]=min(ldp[i-a]+b for a,b in lab)
print(min(ldp[H:]))


Measured memory_bytes: 3704
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    std::string S;
    std::cin >> S;

    bool flag = false;
    for (int i = 0; i < S.size(); i++) {
        for (int j = i; j < S.size(); j++) {
            std::string s1, s2;
            s1 = S.substr(0, i);
            s2 = S.substr(j, S.size() - j);
            if (s1+s2 == "keyence") {
                flag = true;
            }
        }
    }

    if (flag) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO"  << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n,q=map(int,input().split())
G=[[] for _ in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
count=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  count[p-1]+=x
stack=deque([0])
ans=[0]*n
ans[0]=count[0]
flag=[False]*n
while stack:
  v=stack.pop()
  flag[v]=True
  for nv in G[v]:
    if not flag[nv]:
      stack.append(nv)
      ans[nv]=ans[v]+count[nv]
print(*ans)

Measured memory_bytes: 128560
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1000000000 + 7, INF = 1e18;

lint N;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	lint curr = 1;
	while (curr * 2 <= N) curr *= 2;
	cout << curr << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;


ll fi(ll x, vi& par) {
  if (par[x] == x) {
    return x;
  }

  return par[x] = fi(par[x], par);
}

void unite(ll x, ll y, vi& par, vi& rk) {
  x = fi(x, par);
  y = fi(y, par);

  if (rk[x] > rk[y]) {
    par[y] = x;
  } else if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[x] = y;
    rk[y] += 1;
  }
}

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

  vvi v(m);

  for (ll i = 0; i < n; i++) {
    ll k;
    cin >> k;
    for (ll j = 0; j < k; j++) {
      ll l;
      cin >> l;
      l -= 1;
      v[l].push_back(i);
    }
  }

  vi par(n), rk(n);
  for (ll i = 0; i < n; i++) {
    par[i] = i;
  }

  for (ll i = 0; i < m; i++) {
    for (ll j = v[i].size() - 2; j >= 0; j--) {
      unite(v[i][j], v[i][j + 1], par, rk);
    }
  }

  for (ll i = 0; i < n; i++) {
    fi(i, par);
  }

  for (ll i = 0; i < n - 1; i++) {
    if (par[i] != par[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 5120
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

const int to[][4] = {
	{1, 2, 3, 4},
	{2, -1, 4, -3},
	{3, -4, -1, 2},
	{4, 3, -2, -1}
};

int main(){
	int n;
	int a[4], b[4], c[4];
	
	while(cin >> n, n){
		while(n--){
			rep(i, 4) cin >> a[i];
			rep(i, 4) cin >> b[i];
			rep(i, 4) c[i] = 0;
			
			rep(i, 4) rep(j, 4){
				int k = to[i][j];
				int sg = k > 0;
				k = abs(k) - 1;
				
				c[k] += (sg ? 1 : -1) * a[i] * b[j];
			}
			rep(i, 4) cout << c[i] << (i == 3 ? "\n" : " ");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int i;
char d[8][4]={"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"},s[4];
int main(void){
    scanf("%s",s);
    for(;;)
    {
        if (strcmp(d[i],s)==0)
        {
            break;
        }
        i++;
    }
    printf("%d\n",7-i);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int h, w;
vs maze;
vvi dist;
int inf = 1001000;
int dy[4] = { 0,-1,0,1 };
int dx[4] = { 1,0,-1,0 };

void dfs(int y, int x)
{
	rep(i, 4)
	{
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (0 <= ny && ny < h && 0 <= nx && nx < w
			&& maze[ny][nx] == '.' && dist[ny][nx]>dist[y][x] + 1)
		{
			dist[ny][nx] = dist[y][x] + 1;
			dfs(ny, nx);
		}
	}
}

int main()
{
	cin >> h >> w;
	maze = vs(h);
	rep(i, h)cin >> maze[i];
	dist = vvi(h, vi(w, inf));
	int ans = 0;
	rep(i, h)rep(j, w)
	{
		if (maze[i][j] == '#')continue;
		dist[i][j] = 0;
		dfs(i, j);
		int tmp = 0;
		rep(i, h)rep(j, w)
		{
			if (dist[i][j] < inf)chmax(tmp, dist[i][j]);
		}
		chmax(ans, tmp);

		dist = vvi(h, vi(w, inf));
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
using namespace std;

const int _ = 1e4 + 7 , MOD = 998244353;
int pw[_] , fac[_] , ifac[_] , f[_] , g[_] , N , c1 , c2;
char A[_] , B[_];

int poww(int a , int b){
	int tms = 1;
	while(b){
		if(b & 1) tms = 1ll * tms * a % MOD;
		a = 1ll * a * a % MOD; b >>= 1;
	}
	return tms;
}

int binom(int a , int b){return 1ll * fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;}

int main(){
	scanf("%s %s" , A + 1 , B + 1); N = strlen(A + 1);
	for(int i = 1 ; i <= N ; ++i) if(A[i] == '1') ++(B[i] == '1' ? c1 : c2);
	fac[0] = 1; for(int i = 1 ; i <= N ; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
	ifac[N] = poww(fac[N] , MOD - 2); for(int i = N - 1 ; ~i ; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % MOD;
	
	for(int i = 0 ; i <= c2 ; ++i) pw[i] = poww(i , c2);
	for(int i = 0 ; i <= c1 ; ++i){
		int sum = 0;
		for(int j = 0 ; j <= c2 ; ++j) sum = (sum + (j & 1 ? -1ll : 1ll) * binom(c2 , j) * pw[c2 - j] % MOD + MOD) % MOD;
		f[i] = 1ll * sum * fac[c1] % MOD * ifac[c1 - i] % MOD * ifac[i + c2] % MOD;
		for(int j = 0 ; j <= c2 ; ++j) pw[j] = 1ll * pw[j] * j % MOD;
	}

	g[0] = 1;
	for(int i = 1 ; i <= c1 ; ++i)
		for(int j = 1 ; j <= i ; ++j)
			g[i] = (g[i] + 1ll * binom(i - 1 , j - 1) * fac[j - 1] % MOD * g[i - j]) % MOD;
	int ans = 0;
	for(int i = 0 ; i <= c1 ; ++i) ans = (ans + 1ll * f[i] * g[c1 - i]) % MOD;
	printf("%lld\n" , 1ll * ans * fac[c1 + c2] % MOD * fac[c2] % MOD); return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
	
	ll n, s = 0, i;
	cin >> n;
	vll sm(n+1), as(n);
	for (i = 0; i < n; i++) {
		cin >> as[i];
		sm[i+1] = sm[i] + as[i];
	}
	
	for (i = 0; i < n; i++)
		s = (s + (as[i] * ((sm[n] - sm[i+1]) % MOD)) % MOD) % MOD;
		
	cout << s << "\n";
	
	return 0;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
 
int main() {


int K, odd, eve;
cin >> K;

if (K % 2 == 1){
  
  odd = (K + 1)/2;
  eve = odd - 1;
}
else {
  odd = K/2;
  eve = K/2;
}

cout << odd * eve << endl;
  
  
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int[][] map;
    static int[][] label;


    static ArrayList<String> list;

    static int M;
    static int N;
    static int T;
    static int P;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        int Z = scanner.nextInt();


        int temp = X - Z;

        System.out.println(temp / (Y + Z));

    }



}


Measured memory_bytes: 21204
import sys
import re
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    x = bool(getN())

    print(int(not x))
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

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

int main(){
    string s,p;
    cin>>s>>p;
    string ss;
    ss=s+s;
    rep(i,ss.length()){
        if(ss[i]==p[0]){
            int count=0;
            rep(j,p.length()){
                if(p[j]==ss[i+j])count++;
            }
            if(count==p.length()){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3204
import bisect
A,B,Q = map(int,input().split())
# INF = 10**18
# s=[-INF]
# t=[-INF]
# for _ in range(A):
    # s.append(int(input()))
# for _ in range(B):
    # t.append(int(input()))
# s.sort()
# t.sort()
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
# s.append(INF)
# t.append(INF)

def solve(x):
    sr = bisect.bisect(s,x)
    tr = bisect.bisect(t,x)
    sRight = s[sr] if sr < A else s[sr-1]
    tRight = t[tr] if tr < B else t[tr-1]
    sLeft = s[sr-1] if sr>0 else s[sr] 
    tLeft = t[tr-1] if tr>0 else t[tr]
    # return(min(
    # print([[sr,sLeft,sRight],[tr,tLeft,tRight]])
    # cand = [
    #     abs(x-sRight) + abs(sRight-tRight),
    #     abs(x-sRight) + abs(sRight-tLeft),
    #     abs(x-tRight) + abs(tRight-sRight),
    #     abs(x-tRight) + abs(tRight-sLeft),
    #     abs(x-sLeft) + abs(sLeft-tLeft),
    #     abs(x-sLeft) + abs(sLeft-tRight),
    #     abs(x-tLeft) + abs(tLeft-sRight),
    #     abs(x-tLeft) + abs(tLeft-sLeft),
    # ]
    # # print(cand)
    # return(min(cand))
    return(min(
        abs(x-sRight) + abs(sRight-tRight),
        abs(x-sRight) + abs(sRight-tLeft),
        abs(x-tRight) + abs(tRight-sRight),
        abs(x-tRight) + abs(tRight-sLeft),
        abs(x-sLeft) + abs(sLeft-tLeft),
        abs(x-sLeft) + abs(sLeft-tRight),
        abs(x-tLeft) + abs(tLeft-sRight),
        abs(x-tLeft) + abs(tLeft-sLeft),
    ))
for _ in range(Q):
    print(solve(int(input())))

Measured memory_bytes: 12092
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int a,b,k;
    while(cin>>a>>b>>k&&a>=1&&b>=1&&k>=1)
    {
        for(int i=a;i<=b;i++)
        {
            if(i<=a+k-1||i>=b-k+1)
                cout<<i<<endl;
        }
    }
}


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

int FindSumOfDigits(int n){
    int ans=0;
    while(n){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int f=FindSumOfDigits(n);
    if(n%f==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
using namespace std;
#define maxn 1000005
int a[maxn];
int n;//size of the array
vector<int> G;
int cnt=0;
void insertionSort(int g)
{
   for(int i=g;i<n;i++)
   {
       int key=a[i];
       int j=i-g;
       while(j>=0&&a[j]>key)
       {
           a[j+g]=a[j];
           j=j-g;
           cnt++;
       }
       a[j+g]=key;
   }
}
void makeShellArray()
{
    int num=1;
    for(num;;)
    {
        if(num>n)
            break;
        G.push_back(num);
        num=3*num+1;
    }
}
void shellSort()
{
    int m=G.size();
    for(int i=m-1;i>=0;i--)
    insertionSort(G[i]);
}
void print()
{
    int m=G.size();
    cout<<m<<endl;
    for(int i=m-1;i>=0;i--)
    {
       if(i!=0)
        cout<<G[i]<<" ";
       else
        cout<<G[i]<<endl;
    }
    cout<<cnt<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<endl;
}
int main()
{
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>a[i];
        makeShellArray();
        shellSort();
        print();
    }
    return 0;
}

Measured memory_bytes: 7016
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, q = LI()
G = [[] for _ in range(n)]
for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

D = [0] * n
for p, x in LIR(q):
    D[p - 1] += x


que = deque([0])
visited = [0] * n
visited[0] = 1
while que:
    u = que.popleft()
    for v in G[u]:
        if visited[v] == 0:
            visited[v] = 1
            D[v] += D[u]
            que += [v]


print(*D)












Measured memory_bytes: 124620
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, d;
    cin >> d >> n;
    if(n != 100) cout << n;
    else cout << 101;
    REP(i, d) cout << "00";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

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

Measured memory_bytes: 3632
import Foundation

let rating = Int(readLine()!)!

switch rating {
    case 400...599: print(8)
    case 600...799: print(7)
    case 800...999: print(6)
    case 1000...1199: print(5)
    case 1200...1399: print(4)
    case 1400...1599: print(3)
    case 1600...1799: print(2)
    case 1800...1999: print(1)
    default: fatalError()
}


Measured memory_bytes: 13144
#57c
import math

N = int(input()) #10**10
#FはA,Bの大きい方に引っぱられる　∴A,Bを同じくらいにするのが最良。 と思ったが、約数列挙の総当たりでいけそう。

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
         if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
    
divisors_list = make_divisors(N) #len(divisors_list)<=121 程度。総当たり出来る。

F_min = 11 #N<=10**10なので11桁が最大。

for divisors in divisors_list:
    A = divisors
    B = int(N/divisors)
    F = max(1+int(math.log10(A)),1+int(math.log10(B)))
    F_min = min(F_min,F)
    
print(F_min)

Measured memory_bytes: 3064
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
lst=[0]*100001

for i in range(n):
    a,b=map(int,input().split())
    lst[a]+=b

for i in range(100001):
    k-=lst[i]
    if k<=0:
        print(i)
        break

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

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    int a = p+q;
    int b = p+r;
    int c = r+q;
    if(a <= b){
        if(a <= c){
            cout << a;
        }else{
            cout << c;
        }
    }else{
        if(b <= c){
            cout << b;
        }else{
            cout << c;
        }
    }
    return 0;
}

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

int n;
vector<string> s;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        string t;
        cin >> t;
        s.push_back(t);
    }
    sort(s.begin(), s.end());
    auto it = unique(s.begin(), s.end());
    s.erase(it, s.end());
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 11624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n,n;){
		vi ps(n),js(n-1);
		rep(i,n) cin>>ps[i];
		rep(i,n-1) cin>>js[i];
		
		sort(all(js),greater<int>());
		
		ll psum=accumulate(all(ps),0),jsum=0;
		ll res=psum*n;
		rep(i,n-1){
			jsum+=js[i];
			res=max(res,(psum+jsum)*(n-1-i));
		}
		
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1524
n = int(raw_input())

s = set()
h = set()
c = set()
d = set()

def print_card(mark, nums):
    r = set(range(1,14)) - nums
    if not len(r) == 0:
        for i in sorted(r):
            print mark, i
    return 0

for i in range(n):
    mark, num = raw_input().split()
    num = int(num)
    if mark == "S":
        s.add(int(num))
    elif mark == "H":
        h.add(int(num))
    elif mark == "C":
        c.add(int(num))
    elif mark == "D":
        d.add(int(num))

print_card("S",s)
print_card("H",h) 
print_card("C",c)
print_card("D",d)   

Measured memory_bytes: 6492
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read();
    let y:usize = read();
    let mut ans = false;

    for i in 0..=x {
        if y == i*2+(x-i)*4 {
            ans = true;
        }
    }

    println!("{}", if ans { "Yes" } else { "No "});
}


Measured memory_bytes: 2088
#include<iostream>
 #include<algorithm>
 #include<cmath>
 #include<iomanip>
 #include<string.h>
 #include<cmath>
 #include<map>
 #include<vector>
using namespace std;
typedef long long ll;
char s[4005];
int main()
{

char a,b,c;
cin>>a>>b>>c;
if(b=='B')
cout<<"ARC";
else
cout<<"ABC";
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

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

    map<string, int> m;
    rep(i, n) {
        string s; cin >> s;
        m[s]++;
    }

    vector<pair<int,string>> vp;
    for (auto kv: m) {
        pair<int,string> p = make_pair(kv.second, kv.first);
        vp.push_back(p);
    }
    sort(all(vp), greater<pair<int,string>>());

    int M = 0;
    vector<string> ret;
    for (auto p: vp) {
        int cnt = p.first;
        string word = p.second;
        if (cnt >= M) {
            ret.push_back(word);
            M = cnt;
        }
    }

    sort(all(ret));
    for (auto x: ret) cout << x << endl;
}


Measured memory_bytes: 32876
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << "[DBG] " << #X << "=" << (X) << '\n';
	#define SAY(X) cout << "[SAY] " << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int BITS = 20;
int cntbits(int x) {
	int cnt = 0;
	for(int i = 0; i < BITS; ++i) {
		cnt += x&1;
		x >>= 1;
	}
	return cnt;
}

int check(int A, int B) {
	return cntbits(A ^ B) & 1;
}

vector<int> build(int A, int B, int n) {
	if(n == 1) {
		if(A == 0 && B == 1) return {A, B};
		if(A == 1 && B == 0) return {A, B};
		assert(false);
	} else if((A&1) == (B&1)) {
		auto v = build(A>>1, B>>1, n - 1);
		DBG(v);
		vector<int> rez;
		int flag = A&1;
		for(auto& el: v) {
			rez.push_back(2*el+flag);
			flag ^= 1;
			rez.push_back(2*el+flag);
		}

		return rez;
	} else {
		auto v = build(A>>1, (A>>1)^1, n - 1);
		auto u = build((A>>1)^1, B>>1, n - 1);
		vector<int> rez;
		for(auto& el: v) rez.push_back(2*el+(A&1));
		for(auto& el: u) rez.push_back(2*el+(B&1));
		return rez;
	}
}

void solve() {
	int n = fetch<int>();
	int A = fetch<int>();
	int B = fetch<int>();
	if(check(A, B)) {
		cout << "Yes\n";
		cout << build(A, B, n) << '\n';
	} else {
		cout << "No\n";
	}
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 1760
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    b = input()
    if b == 'A':
        print('T')
    elif b == 'T':
        print('A')
    elif b == 'C':
        print('G')
    elif b== 'G':
        print('C')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//============================================================================
// Name        : ALDS1_1_D.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int n;
	int temp, min=1000000000, p_max=-1000000000;
	cin >> n;
	cin >> min;
	for(int i=1; i<n; ++i) {
		cin >> temp;
		if(temp-min>p_max) p_max=temp-min;
		if(min>temp) min=temp;
	}
	cout << p_max << endl;
	return 0;
}

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

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

    int A[50], B[50], C[50], D[50];

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

    for(int j=0;j<M;j++){
        cin >> C[j] >> D[j];
    }

    for(int i=0;i<N;++i){
        int min=abs(A[i]-C[0])+abs(B[i]-D[0]);
        int checkpoint=1;

        for(int j=1;j<M;++j){
            int tmp=abs(A[i]-C[j])+abs(B[i]-D[j]);
            if(min>tmp){
                min=tmp;
                checkpoint=j+1;
            }
        }
        cout << checkpoint << endl;
    }
}

Measured memory_bytes: 3564
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set

main :: IO ()
main = do
  n <- readLn
  am <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  putStrLn . unwords . map show $ solve am

solve :: [[Int]] -> [Int]
solve am = head . filter isOk $ [[x,y,h] | (x,y) <- candidates, h <- heightCandidates]
  where
    maxHeight = maximum . map (!!2) $ am
    heightCandidates = [(maxHeight - 200)..(maxHeight + 200)]
    isOk (cx:cy:ch:_) = all (\(x:y:h:_) -> height ch (x,y) (cx,cy) == h) am

type Position = (Int, Int)
height :: Int -> Position -> Position -> Int
height h (x, y) (cx, cy) = max (h - (abs (x - cx)) - (abs (y - cy))) 0

candidates = [ (x,y)| x <- [0..100], y <- [0..100]]


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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define inf (long long int) 1e18
#define vl vector<ll> 
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define mod 1000000007
ll gcd(ll a,ll b);
ll palindrome(string s);
ll modexp(ll a,ll b,ll m);

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    ll x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    ll d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    ll y2y1=y2-y1;
    ll x2x1=x2-x1;
    ll x3,y3,x4,y4;
    if(y2y1>=0){
        ll r=-d;
         x3=(r*(y2y1))/d+x2;
         y3=(r*(-x2x1))/d+y2;
         x4=(r*(y2y1))/d+x1;
        y4=(r*(-x2x1))/d+y1;
    }
    else {
        ll r=d;
        y2y1=-1*y2y1;
        x2x1=-1*x2x1;
         x3=(r*(y2y1))/d+x2;
         y3=(r*(-x2x1))/d+y2;
         x4=(r*(y2y1))/d+x1;
         y4=(r*(-x2x1))/d+y1;   
    }
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}


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

ll palindrome(string s){
    ll l = 0;
    ll h = s.length() - 1;
    while (h > l){
        if (s[l++] != s[h--]){
            return 0;
        }
    }
    return 1;
}

ll modexp(ll a, ll b, ll m){
    if (b==0)
        return 1;
    ll temp = modexp(a,b/2,m);
    temp = (temp*temp)%m;
    if (b&1)
        return (temp*(a%m))%m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
    return temp;
}

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

int main() {
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    string s;
    cin>>s;
    if(s=="Y"){
      cout<<"Four";
      exit(0);
    }
  }
  cout<<"Three";
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 1145141919
#define EPS 1e-9
#define Pi acos(-1)

using namespace std;

typedef long long ll;

#define MAX_N 20

int N;
int hx, hy, dx, dy;
int cx[MAX_N], cy[MAX_N];

vector<string> ans_list;

double dist(int x1, int y1, int x2, int y2){
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)* (y1 - y2));
}

bool dfs(int S, int nowx, int nowy, double t){
	
	if (S == (1 << N) - 1)
		return true;

	//枝狩り
	for (int i = 0; i < N; i++){
		if (!(S >> i & 1) && dist(dx, dy, cx[i], cy[i]) - t <= dist(nowx, nowy, cx[i], cy[i]))
			return false;
	}

	//探索
	for (int i = 0; i < N; i++){
		if (!(S >> i & 1)){
			if (dfs(S | (1 << i), cx[i], cy[i], t + dist(nowx, nowy, cx[i], cy[i])))
				return true;
		}
	}

	return false;

}

int main(){

	while (cin >> N >> hx >> hy >> dx >> dy, N){
		
		for (int i = 0; i < N; i++){
			cin >> cx[i] >> cy[i];
		}

		if (dfs(0, hx, hy, 0))
			ans_list.push_back("YES");
		else
			ans_list.push_back("NO");

	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}


	return 0;

}

Measured memory_bytes: 1208
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 17:14:33 2020

@author: Kanaru Sato
"""

N = int(input())
A = input().split()

D = {}

for i in range(0,N):
    if A[i] not in D:
        D[A[i]] = 1
    elif A[i] in D:
        D[A[i]] += 1
        

flag = 0

for i in list(D.values()):
    if i > 1:
        flag = 1
        break
    elif i <= 1:
        continue

if flag==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38836
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
#define int long long int
#define pb push_back
#define fi first
#define se second
#define deb cerr << "Line no." << __LINE__
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
#ifndef LOCAL
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}
int pwr(int a,int b){
	int ans = 1;
	while(b){
		if(b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}
const int N = 1e5 + 5;
int dp[3][N], a[3][N];
void solve(){
	int n;
	cin >> n;
	fr(i, 1, n){
		cin >> a[0][i] >> a[1][i] >> a[2][i];
	}
	fr(i, 1, n){
		fr(j, 0, 2){
			fr(k, 0, 2){
				if(k == j) continue;
				dp[j][i] = max(dp[j][i], dp[k][i - 1] + a[j][i]);
			}
		}
	}
	cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
}
signed main(){
  	IO;
  	#ifdef LOCAL
		freopen("inp.txt","r", stdin);
		// freopen("out.txt", "w", stdout);
	#endif
 	clock_t clk = clock();
  	int t = 1;
  	// cin >> t;
  	fr(tt, 1, t){
    	solve();
  	}
  	cerr << endl << (double)(clock() - clk) / CLOCKS_PER_SEC;
  	return 0;
}

Measured memory_bytes: 4992
//#pragma GCC target("fma,avx")
//#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
#define endl '\n'
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define _ <<' '<<
using ll = long long;
#define debug(x) cerr << #x << " is " << x << endl


signed main(){
	FAST
    int N,K;
    cin >> N >> K;
    vector<double> tp(N);
    for(int i = 0; i<N; i++){
        double tmp;
        cin >> tmp;
        if(i == 0){
            tp[i] = (tmp+1)/2;
            continue;
        }else tp[i] = (tmp+1)/2+tp[i-1];
        //debug(tp[i]);
    }
    double ans = tp[K-1];
    for(int i = K; i<N; i++){
        ans = max(ans,tp[i]-tp[i-K]);
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct RMQ {
	int n;
	vector<int> dat;

	RMQ(int n_) {
		n = 1;
		while(n < n_) n *= 2;

		dat.resize(n*4);
		rep(i,n*4) dat[i] = (1LL<<31) - 1;
	}

	void update(int k,int a) {
		int i = k+n-1;
		dat[i] = a;

		while(i > 0) {
			i = (i-1) / 2;
			dat[i] = min(dat[i*2+1],dat[i*2+2]);
		}
	}

	//[a,b)
	//query(a,b,0,0,n)
	int _query(int a,int b,int k,int l,int r)
	{
		if(r <= a || b <= l) return (1LL<<31) - 1;

		if(a <= l && r <= b) return dat[k];
		else { 
			int vl = _query(a,b,k*2+1,l,(l+r)/2);
			int vr = _query(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}

	//[a,b)
	int query(int a,int b) {
		return _query(a,b,0,0,n);
	}
};

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

	RMQ rmq(n);

	rep(i, q) {
		int a, b, c;
		cin >> a >> b >> c;

		if(a == 0) {
			rmq.update(b, c);
		} else {
			cout << rmq.query(b, c+1) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3116
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	Max := 1001001
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0, Max), Max)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

//func fib(n int) int {
//	fmt.Println(n)
//	if n == 0 {
//		return 0
//	}
//	if n == 1 {
//		return 1
//	}
//	if done[n] {
//		fmt.Println("done" + fmt.Sprint(n))
//		return memo[n]
//	}
//	done[n] = true
//	memo[n] = fib(n-1) + fib(n-2)
//	return memo[n]
//}

var m map[string]int = make(map[string]int)
var mInt map[int]int = make(map[int]int)

//var dp []int = make([]int, n)

//func fib(n int) int {
//	dp[0] = 0
//	dp[1] = 1
//	for i := 2; i <= n; i++ {
//		dp[i] = dp[i-1] + dp[i-2]
//	}
//	return dp[n]
//}

func main() {
	n := nextInt()
	as := nextInts(n)
	sort.Ints(as)
	var bundle = make(map[int]int)
	var keys []int
	for i := n - 1; i >= 0; i-- {
		v := bundle[as[i]]
		if v <= 0 {
			keys = append(keys, as[i])
		}
		bundle[as[i]]++
	}
	var first int
	var second int
	for _, k := range keys {
		if bundle[k] >= 4 {
			if first <= 0 {
				first = k
				second = k
				break
			}
		}
		if bundle[k] >= 2 {
			if first <= 0 {
				first = k
			} else if second <= 0 {
				second = k
				break
			}
		}
	}

	fmt.Println(first * second)
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

signed main(void){
   int N;
   int A[214514];
   cin >> N;
   REP(i,N){
       cin >> A[i];
       A[i]-=(i+1);
   }
   sort(A,A+N);
   //REP(i,N){cout << A[i] << " ";}cout << endl<<endl;
   int x0=A[0],x1=0,x2=0,x3=A[N-1];
   int y0=0,y1=0,y2=0,y3=0;
   REP(i,N){
       y0+=abs(A[i]-x0);
   }
   REP(i,N){
       y3+=abs(A[i]-x3);
   }
   while(abs(x3-x0)>2){
       x1=(x0+x0+x3)/3;
       x2=(x0+x3+x3)/3;
       y1=0;y2=0;
       
       REP(i,N){
           y2+=abs(A[i]-x2);
       }
       REP(i,N){
           y1+=abs(A[i]-x1);
       }
       
       
       //cout << x0 << " " << x1 << " " << x2 << " " << x3 <<endl;
       //cout << y0 << " " << y1 << " " << y2 << " " << y3 <<endl;
       //cout << endl;
       
       if(y1<y2){
           x3=x2;
       }else{
           x0=x1;
       }
       
   }
   y0=0;REP(i,N){y0+=abs(A[i]-x0);}
   y1=0;REP(i,N){y1+=abs(A[i]-x1);}
   y2=0;REP(i,N){y2+=abs(A[i]-x2);}
   y3=0;REP(i,N){y3+=abs(A[i]-x3);}
   
   
   cout << min(min(y0,y1),min(y2,y3)) << endl;
  return 0;
}


Measured memory_bytes: 1792