akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi xs(N),ys(N);
  v(char) c(N);
  rep(i,N) {
    cin >> xs[i] >> ys[i] >> c[i];
    xs[i]%=2*K;
    ys[i]%=2*K;
  }
  vvi b(2*K+1,vi(2*K+1,0)),w(2*K+1,vi(2*K+1,0));
  rep(i,N) {
    if(c[i]=='B') {
      b[xs[i]+1][ys[i]+1]++;
    } else {
      w[xs[i]+1][ys[i]+1]++;
    }
  }
  rep(i,2*K) {
    rep(j,2*K) {
      b[i+1][j+1]+=b[i+1][j];
      w[i+1][j+1]+=w[i+1][j];
    }
  }
  rep(i,2*K) {
    rep(j,2*K) {
      b[i+1][j+1]+=b[i][j+1];
      w[i+1][j+1]+=w[i][j+1];
    }
  }
  auto getW = [&](int il,int ir,int jl,int jr) {
    return w[ir][jr]+w[il][jl]-w[il][jr]-w[ir][jl];
  };
  auto getB = [&](int il,int ir,int jl,int jr) {
    return b[ir][jr]+b[il][jl]-b[il][jr]-b[ir][jl];
  };
  int ans = 0;
  rep(di,K+1) {
    rep(dj,K+1) {
      int res=0;
      {
        int a0 = getW(0,di,0,dj)    +getB(di,di+K,0,dj)+    getW(di+K,2*K,0,dj);
        int a1 = getB(0,di,dj,dj+K) +getW(di,di+K,dj,dj+K)+ getB(di+K,2*K,dj,dj+K);
        int a2 = getW(0,di,dj+K,2*K)+getB(di,di+K,dj+K,2*K)+getW(di+K,2*K,dj+K,2*K);
        chmax(res,a0+a1+a2);
      }
      {
        int a0 = getB(0,di,0,dj)+    getW(di,di+K,0,dj)+    getB(di+K,2*K,0,dj);
        int a1 = getW(0,di,dj,dj+K)+ getB(di,di+K,dj,dj+K)+ getW(di+K,2*K,dj,dj+K);
        int a2 = getB(0,di,dj+K,2*K)+getW(di,di+K,dj+K,2*K)+getB(di+K,2*K,dj+K,2*K);
        chmax(res,a0+a1+a2);
      }
      chmax(ans,res);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 32512
def divisor(x):
    div=[]
    for i in range(1,int(x**(1/2))+1):
        if x%i==0:
            div.append(i)
            if i!=x//i:
                div.append(x//i)
    return sorted(div)


X=int(input())
while True:
    if len(divisor(X))==2:
        break
    else:
        X+=1
print(X)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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;
};

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1ll; i * i <= n; i++) {
    if(n % i == 0ll) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(All(ret));
  return (ret);
};

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

  ll N;
  cin >> N;
  set<ll> s;
  auto divs1 = divisor(N-1);
  for (ll div: divs1) {
    if (div == 1ll) continue;
    s.insert(div);
  }

  auto divs2 = divisor(N);
  for (ll div: divs2) {
    if (div == 1) continue;
    ll n = N;
    while (1) {
      if (n % div == 0) n /= div;
      else break;
    }
    if (n % div == 1ll || n == 1ll) s.insert(div);
  }

  cout << (int)s.size() << endl;



  return 0;
};


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

int main(){
	//fri("a.gir");
	//fro("a.cik");
	long long n;
	cin>>n;
	n=n*n;
	cout<<n;
 
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

seikai = set()
pena_num = 0
pena = [0] * (n + 1)

for i in range(m):
    p, s = map(str, input().split())
    if s == 'WA':
        if p not in seikai:
            pena[int(p)] += 1
        else:
            continue
    else:
        if p not in seikai:
            pena_num += pena[int(p)]
            seikai.add(p)
        else:
            continue
print(len(seikai), pena_num)

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (auto&& si : s) cin >> si;
	for (int r = 0; r < h; r++)
	{
		for (int c = 0; c < w; c++)
			if (s[r][c] == '.')
			{
				s[r][c] = '0';
				for (int i = -1; i <= 1; i++)
					for (int j = -1; j <= 1; j++)
					{
						if (r+i >= 0 && r+i < h && c+j >= 0 && c+j < w && s[r+i][c+j] == '#') s[r][c]++;
					}
			}
		cout << s[r] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize( "Ofast" )

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;
 
int n, m, k, a, b, c, d, mod = 1e9 + 7;
long long res;
vector< long long > factorial( 2e5 + 5, 1 ), invfactorial( 2e5 + 5, 1 ), dp( 3e3 + 3, 0 );
vector< pair< int, int > > arr;

long long inv( long long a, long long p )
{
	long long res = 1;
	while( p > 0 )
	{
		if( p & 1 )
		{
			res *= a;
			res %= mod;
		}
		a *= a;
		a %= mod;
		p >>= 1;
	}
	return res;
}

void precompute( void )
{
	for( int i = 2; i <= 2e5 + 4; ++i )
	{
		factorial[ i ] = ( factorial[ i - 1 ] * i ) % mod;
		invfactorial[ i ] = inv( factorial[ i ], mod - 2 );
	}
}
 
long long nCr( int n, int r )
{	
	long long res = factorial[ n ];
	res = ( res * invfactorial[ r ] ) % mod;
	res = ( res * invfactorial[ n - r ] ) % mod;
	return res;
}
 
int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	precompute();
	cin >> n >> m >> k;
	for( int i = 1; i <= k; ++i )
	{
		cin >> a >> b;
		arr.emplace_back( a, b );		
	}
	sort( arr.begin(), arr.end() );
	arr.emplace_back( n, m );
	for( int i = 0; i <= k; ++i )
	{
		c = arr[ i ].first;
		d = arr[ i ].second;
		dp[ i ] = nCr( c + d - 2, c - 1 );
		res = 0;
		for( int j = 0; j <= i - 1; ++j )
		{
			a = arr[ j ].first;
			b = arr[ j ].second;
			if( a <= c && b <= d )
			{
				res += dp[ j ] * nCr( c - a + d - b, c - a );
				if( res >= mod )
				{
					res %= mod;
				}
			}
		}
		dp[ i ] -= res;
		if( dp[ i ] < 0 )
		{
			dp[ i ] += mod;
		}
	}
	cout << dp[ k ] << "\n";
	return 0;
}

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

const int maxn=3010;
long long dp[maxn][maxn];
int t[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&t[i]);
	if(!(n&1))
		for(int i=1;i<n;i++)
			dp[i][i+1]=max(t[i],t[i+1])-min(t[i],t[i+1]);
	if(n&1)
		for(int i=1;i<=n;i++)
			dp[i][i]=t[i];
	for(int i=(n&1) ? 3 : 4; i<=n;i+=2)
		for(int j=1;(j+i-1)<=n;j++)
		{
			long long right=min(dp[j][j+i-3]+t[j+i-1]-t[j+i-2],dp[j+1][j+i-2]+t[j+i-1]-t[j]);
			long long left=min(dp[j+2][j+i-1]+t[j]-t[j+1],dp[j+1][j+i-2]+t[j]-t[j+i-1]);
			dp[j][j+i-1]=max(left,right);
		}
	/*for(int i=1;i<=n;i++)
	{
		for(int j=1;(j+i-1)<=n;j++)
			printf("%lld ",dp[j][j+i-1]);
		printf("\n");
	}*/
	printf("%lld",dp[1][n]);
}

Measured memory_bytes: 70016
cnt5 = 0
cnt7 = 0

def check57(m):
    global cnt5
    global cnt7
    if m == 5:
        cnt5 += 1
    elif m == 7:
        cnt7 += 1

a, b, c = map(int, raw_input().split())
check57(a)
check57(b)
check57(c)
if cnt5 == 2 and cnt7 == 1:
    print "YES"
else:
    print "NO"

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  vector<int> a(10, 0);
  vector<int> b(100, 0);
  vector<int> c(1000, 0);
  for(int i = 0; i < n - 2; ++i){
    int x = s[i] - '0';
    if(!a[x]){
      a[x] = 1;
      for(int j = i + 1; j < n - 1; ++j){
	int y = x * 10 + (int)(s[j] - '0');
	if(!b[y]){
	  b[y] = 1;
	  for(int k = j + 1; k < n; ++k){
	    int z = y * 10 + (int)(s[k] - '0');
	    c[z] = 1;
	  }
	}
      }
    }
  }
  int ans = 0;
  for(int i =0; i < 1000; ++i)
    if(c[i])
      ans++;
  cout<<ans<<'\n';  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> BA(N);
  for (int i=0; i<N; i++) {
    cin >> BA[i].first >> BA[i].second;
    swap(BA[i].first, BA[i].second);
  }
  // 締め切り順で昇順ソート
  sort(BA.begin(), BA.end());
  ll num = 0;
  bool can = true;
  for (int i=0; i<N; i++) {
    num += BA[i].second;
    // 締め切り超えたらアウト
    if (num>BA[i].first) {
      can = false;
      break;
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<pair<int, int>> v;
  for(int i=0;i<n;++i) {
    ll a; cin >> a;
    v.push_back(make_pair(a, 0));
  }
  for(int i=0;i<n;++i) {
    ll b; cin >> b;
    v.push_back(make_pair(b, 1));
  }
  sort(v.begin(), v.end());
  ll acnt=0, bcnt=0;
  ll res=1;
  for(int i=0;i<2*n;++i) {
    if(v[i].second==0) {
      if(bcnt) {
        res *= bcnt;
        res %= MOD;
        bcnt--;
        continue;
      }
      acnt++;
    } else {
      if(acnt) {
        res *= acnt;
        res %= MOD;
        acnt--;
        continue;
      }
      bcnt++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
typedef long long ll;
ll n, x, s, a[55]={1}, b[55]={1};

void f(ll p, ll q) {
	if(p==0) {s++; return;}
	if(q==1) return;
	ll md = (a[p]+1) / 2;
	if(q < md) f(p-1, q-1);
	else {
		s += b[p-1] + 1;
		if(q>md) f(p-1, q-md);
	}
}

int main() {
	cin>>n>>x;
	for(int i=1; i<=n; i++) {
		a[i] = a[i-1]*2 + 3;
		b[i] = b[i-1]*2 + 1;
	}
	f(n, x);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <set>
#include <map>

using namespace std;

int main() {
    string s;
    stringstream ss;
    map<int, int> count; // 取引回数
    map<int, bool> sengetsu; // 先月取引したかどうか
    set<int> ryouhou; //  先月も今月も取引した客の顧客番号

    int cust_n, date;
    char d; // dummy
    while (getline(cin, s)) {
        if (!s.length()) break;
        ss.clear();
        ss.str(s);
        ss >> cust_n >> d >> date;
        count[cust_n]++;
//        cout << cust_n << ": " << count[cust_n] << endl;
        sengetsu[cust_n] = true;
    }
    while (cin >> s) {
        ss.clear();
        ss.str(s);
        ss >> cust_n >> d >> date;
        count[cust_n]++;
        if (sengetsu[cust_n]) {
            ryouhou.insert(cust_n);
        }
    }
    for (set<int>::iterator i = ryouhou.begin(); i != ryouhou.end(); i++) {
        cout << (*i) << ' ' << count[(*i)] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main() {
	int S = 0;
	cin >> S;
	cout << (S - (S % 3600)) / 3600 << ":" << ((S % 3600) - ((S % 3600) % 60)) / 60 << ":" << ((S % 3600) % 60) << endl;
	return 0;
}


Measured memory_bytes: 3092
N = int(input())
pre2 = [0,0]
pre1 = [0,0]
cur = [0,0]
cnt = 0
flg = 0
for i in range(N):
    if i == 0:
        pre2 = list(map(int,input().split()))
        if pre2[0] == pre2[1]:
            cnt += 1
    elif i == 1:
        pre1 = list(map(int,input().split()))
        if pre1[0] == pre1[1]:
            cnt += 1
    else:
        cur = list(map(int,input().split()))
        if cur[0] == cur[1]:
            cnt += 1
            if cnt == 3:
                flg = 1
                cnt = 0
        else:
            cnt = 0
        pre2 = pre1
        pre1 = cur
if flg:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
 
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007
#define PRECISE cout.precision(18);
#define F first
#define S second




int main(){
 

    FAST
	//PRECISE


ll n;
cin>>n;
ll v[10][10];
memset(v,0,sizeof(v));
ll c=0;
FOR(i,1,n+1){
ll t=i%10;
ll y=i/10;
ll t2=i%10;
while(y>0){
	t2=y%10;
	y=y/10;
}

v[t][t2]++;


}
ll ans=0;
FOR(i,1,10){
	FOR(j,1,10)
	
	ans+=v[i][j]*v[j][i];
}
cout<<ans;


return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
ab = [0 for _ in range(n+2)]

for _ in range(m):
    a, b = map(int, input().split())
    if a==1:
        ab[b] += 1
        continue
    elif b == n:
        ab[a] += 1
        continue
if max(ab) == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 4656
#include <iostream>

int main() {
  int A, B;
  char op;
  std::cin >> A >> op >> B;

  int eval = 0;
  if ( op == '+' ) {
    eval = A + B;
  } else if ( op == '-' ) {
    eval = A - B;
  }
  std::cout << eval << std::endl;

  return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)
#define quit exit(0)

ll N, K, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
string S = "";

bool isPalin(string X) {
	ll low = 0;
	ll high = X.size() - 1;
	while(high > low) {
		if(X[high] != X[low]) {
			return 0;
		}
		high--;
		low++;
	}
	return 1;
}

int main() {
	cin >> S;
	N = S.size();
	if(!isPalin(S)) {
		printf("No\n");
		quit;
	}

	string X = S.substr(0, (N - 1) / 2);
	string Y = S.substr(((N + 3) / 2) - 1);
	// cout << X << " " << Y << " ";
	if(isPalin(X) && isPalin(Y)) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template <class T>
class segtree {
public:
    int n;
    vector<T> dat, sum;  //区間の和,区間に一様に足された値
    segtree(int size, T x) {
        n = 1;
        while (n < size) n *= 2;
        dat.assign(2 * n - 1, 0);
        sum.assign(2 * n - 1, 0);
        add(0, size, x);
    }
    void add(int a, int b, T x) { add(a, b, x, 0, 0, n); }
    T add(int a, int b, T x, int k, int l, int r) {
        if (b <= l or r <= a) return dat[k];
        if (a <= l and r <= b) {
            sum[k] += x;
            return dat[k] += x;
        }
        int m = (l + r) / 2;
        return dat[k] = max(add(a, b, x, 2 * k + 1, l, m), add(a, b, x, 2 * k + 2, m, r)) + sum[k];
    }
    T query(int a, int b) { return query(a, b, 0, 0, n); }
    T query(int a, int b, int k, int l, int r) {
        if (b <= l or r <= a) return -inf64;
        if (a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return max(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)) + sum[k];
    }
    T at(int i){
        return query(i,i+1);
    }
    void update(int i, T x){
        add(i,i+1,-at(i)+x);
    }
};

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,M;
    cin >> N >> M;

    vector<vector<pair<i64,i64>>> r_to_la(N);
    rep(i,0,M){
        i64 l,r,a;
        cin >> l >> r >> a;
        --l;
        --r;
        r_to_la[r].emplace_back(make_pair(l,a));
    }

    const i64 maxn=200000;
    segtree<i64> dp(maxn,-inf64);
    rep(r,0,N){
        i64 val=max(i64(0),dp.query(0,r));
        dp.update(r,val);

        for(auto &p:r_to_la[r]){
            i64 l=p.first,a=p.second;
            dp.add(l,r+1,a);
        }
    }

    cout << max(i64(0),dp.query(0,N)) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 19456
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N, Q, sum = 0;
    cin >> N;
    vector<int> A(N);
    unordered_map<int,int> mp;
    REP (i, N) {
        cin >> A[i];
        mp[A[i]]++;
        sum += A[i];
    }
    cin >> Q;
    vector<int> B(Q), C(Q);
    REP (i, Q) {
        cin >> B[i] >> C[i];
        sum -= B[i] * mp[B[i]];
        sum += C[i] * mp[B[i]];
        mp[C[i]] += mp[B[i]];
        mp[B[i]] = 0;
        cout << sum << endl;
    }


    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc171/abc171_d && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc171/abc171_d && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc171/abc171_d && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 9456
N=int(input())
l=[]
for n in range(N):
    l.append(list(map(int,input().strip().split())))

dp=[[0,0,0] for n in range(N)]
dp[0]=l[0]
for n in range(1,N):
    for i in range(3):
        for j in range(3):
            if i!=j:
                dp[n][i]=max(dp[n][i],dp[n-1][j]+l[n][i])
print(max(dp[N-1]))

Measured memory_bytes: 50116
d, g = map(int, input().split())
pc = [0] + [list(map(int, input().split())) for i in range(d)]
def dfs(ind,score):
  if ind == 0:
    return float("inf")
  cnt = min(score//(ind*100),pc[ind][0])
  add_sc = cnt*(ind*100)
  if cnt == pc[ind][0]:
    add_sc += pc[ind][1]
  if add_sc < score:
    cnt += dfs(ind-1,score-add_sc)
  return min(cnt,dfs(ind-1,score))

print(dfs(d,g))

Measured memory_bytes: 9128
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;

class C {
	int N;
	vector<int> a;
public:
	void solve()
	{
		int ans;
		int tot = 0;

		for (int i{ 0 }; i < N + 1; i++)
			tot += abs(a[i + 1] - a[i]);

		for (int giveUp{ 1 }; giveUp <= N; giveUp++)
		{
			ans = tot - abs(a[giveUp + 1] - a[giveUp]) - abs(a[giveUp] - a[giveUp - 1]) + abs(a[giveUp + 1] - a[giveUp - 1]);
			cout << ans << endl;
		}

	}

	C() 
	{
		cin >> N;
		a.resize(N + 2);
		a[0] = a[N + 1] = 0;
		for (int i{ 0 }; i < N; i++)
			cin >> a[i + 1];
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    string s; cin >> s;
    REP(i, 0, s.length()) cout << 'x';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
main(){float a,b,c,d,e,f;for(;scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=-1;printf("%.3f %.3f\n",((e*c-f*b==0)?0:(e*c-f*b)/(e*a-b*d)),((a*f-c*d)==0?0:(a*f-c*d)/(a*e-b*d))));exit(0);}

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

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

    int n, q, l, r, tmp = 0, sum = 0;
    string s;
    cin >> n >> q >> s;
    int length = s.size();
    vector<int> cnt(q), yes(length);

    for (int i = 0; i < length-1; i++) {
        if ((s[i] == 'A') && (s[i+1] == 'C')) {
            yes[i] = sum;
            yes[++i] = ++sum;
        }
        else yes[i] = sum;
    }
    yes[length-1] = sum;

    while (q--) {
        cin >> l >> r;
        cout << (yes[r-1] - yes[l-1]) << endl;


//        cin >> l >> r;
//        cnt[tmp++] = yes[r-1] - yes[l-1];
    }
//    for (int i = 0; i < tmp; i++) cout << cnt[i] << endl;
    return 0;
}


Measured memory_bytes: 1872
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int D, G;
    cin >> D >> G;

    vector<int> p(D), c(D);
    REP(i, D) cin >> p[i] >> c[i];

    REP(i, D) {
        c[i] += (i + 1) * 100 * p[i];
    }

    int ans = inf;
    REP(i, 1LL << D) {
        int cnt = 0;
        int s = 0;
        REP(j, D) {
            if (i >> j & 1) {
                s += c[j];
                cnt += p[j];
            }
        }

        REP(j, D) {
            if (s >= G) break;

            int k = D - j - 1;
            if (!(i >> k & 1)) {
                int n = ceil(float(G - s) / (k + 1) / 100);
                n = min(n, p[k] - 1);
                s += n * (k + 1) * 100;
                cnt += n;
            }

        }

        if (s >= G) ans = min(ans, cnt);
    }

    cout << ans << endl;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

bool check(string s)
{
  if(s.find("AGC") != string::npos) return false;

  int n = s.size();
  rep(i, 0, 3){
    swap(s[i], s[i+1]);
    if(s.find("AGC") != string::npos) return false;
    swap(s[i], s[i+1]);
  }

  return true;
}

signed main()
{
  int n;
  cin >> n;
  
  map<string, int> dp[n+1];
  string s = "AGCT";

  dp[0]["TTT"] = 1;
  rep(i, 0, n){
    rep(j, 0, 4) rep(k, 0, 4) rep(l, 0, 4) rep(m, 0, 4){
      string t = (string)"" + s[j] + s[k] + s[l] + s[m];
      if(check(t)){
        (dp[i+1][t.substr(1, 3)] += dp[i][t.substr(0, 3)]) %= mod;
      }
    }
  }


  int ans = 0;
  rep(j, 0, 4) rep(k, 0, 4) rep(l, 0, 4){
    string t = (string)"x" + s[j] + s[k] + s[l];
    if(check(t)){
      (ans += dp[n][t.substr(1, 3)]) %= mod;
    }
  }
  cout << ans << endl;

/*
  for(auto it : dp[3]){
    cout << it.first << " : " << it.second << endl;
  }
*/

  return 0;
}


Measured memory_bytes: 896
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type Count struct {
	w, e int
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	S := sc.nextRuneSlice()
	c := make([]Count, N+1)
	c[0] = Count{0, 0}
	for i := 0; i < N; i++ {
		if S[i] == 'E' {
			c[i+1] = Count{c[i].w, 1 + c[i].e}
		} else {
			c[i+1] = Count{1 + c[i].w, c[i].e}
		}
	}
	ans := int(1e+9)
	for i := 1; i <= N; i++ {
		leftCount := c[i-1].w
		rightCount := c[N].e - c[i].e
		if leftCount+rightCount < ans {
			ans = leftCount + rightCount
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 998244353;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int Q;
  cin >> Q;
  ll sum = 0, c = 0;
  priority_queue<int> q;
  priority_queue<int, vector<int>, greater<int> > q2;
  q.push(-inf);
  q2.push(inf);

  while (Q--) {
    int qu;
    cin >> qu;
    if (qu == 1) {
      int a, b;
      cin >> a >> b;
      sum += b;
      if (a >= q.top() && a <= q2.top()) {
        if (sz(q) == sz(q2)) {
          c -= a;
          q.push(a);
        } else {
          c += a;
          q2.push(a);
        }
      } else if (a < q.top()) {
        if (sz(q) == sz(q2)) {
          c -= a;
          q.push(a);
        } else {
          c += 2 * q.top();
          q2.push(q.top());
          q.pop();
          c -= a;
          q.push(a);
        }
      } else {
        if (sz(q) == sz(q2)) {
          c -= 2 * q2.top();
          q.push(q2.top());
          q2.pop();
          c += a;
          q2.push(a);
        } else {
          c += a;
          q2.push(a);
        }
      }
    } else {
      // cout << endl << sz(q) << " " << sz(q2) << endl;
      // cout << q.top() << " " << c << " " << sum << endl;
      cout << q.top() << " ";
      cout << sum + c + (sz(q) != sz(q2) ? q.top() : 0) << endl;
    }
  }
}


Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
signed main(){
  char a[10],b;
  int c=0;
  cin>>a;
  for(int i=0;i<4;i++){
    if(a[i]==b)
      c++;
    else
      b=a[i];
  }
  if(c>=1)
    cout<<"Bad"<<endl;
  else
    cout<<"Good"<<endl;
  return(0);
}


Measured memory_bytes: 256
import Control.Applicative
import qualified Control.Monad as Monad

main = loop

loop :: IO ()
loop = do
    [h,w] <- map (read :: String -> Int) . words <$> getLine
    Monad.when (h /= 0 || w /= 0) $ do
        printChessboard h w
        loop

printChessboard :: Int -> Int -> IO ()
printChessboard h w = do
    Monad.forM_ [1..h] $ \i -> do
        putStrLn $ squareLine w i
    putStrLn ""

squareLine :: Int -> Int -> String
squareLine w i = if (odd i) then
                   takeSquare w "#" "."
                 else
                   takeSquare w "." "#"

takeSquare :: Int -> String -> String -> String
takeSquare w s1 s2 = take w $ concat $ zipWith (++) (repeat s1) (repeat s2)

Measured memory_bytes: 4072
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      PROGRAM_ID.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
01 N            PIC 9(3).
01 ans          PIC Z9.
 
PROCEDURE                        DIVISION.
    ACCEPT N.
    COMPUTE ans = (N + 1) / 2.
    DISPLAY ans.
    STOP RUN.

Measured memory_bytes: 384
#include <iostream>
#include <fstream>

#include <vector>

using namespace std;

int main(){

    double T,X;

    double res;

    cin >> T >> X;

    //X * t = T
    //t = T/X
    res = T/X;

    printf("%.10f\n",res);
    //cout << n << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

//for binomial coefficients
const int MAX=510000;
vector<modint> fac(MAX,0);
vector<modint> finv(MAX,0);
vector<modint> inv(MAX,0);
void COMinit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(int i=2;i<MAX;i++){
    fac.at(i)=fac.at(i-1)*i;
    inv.at(i)=-inv.at(MOD%i)*(MOD/i);
    finv.at(i)=finv.at(i-1)*inv.at(i);
  }
}
modint COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac.at(n)*finv.at(k)*finv.at(n-k);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,K;
  cin >> N >> K;
  chmin(K,N-1);

  COMinit();
  modint ans=0;
  for(int i=0;i<=K;i++){
    //cout << COM(N,i)*COM(N-i-1+i,N-i-1) << endl;
    ans+=COM(N,i)*COM(N-i-1+i,N-i-1);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from itertools import permutations
from math import sqrt, pow

n = int(input())
x = []
y = []
for i in range(n):
    m = input().split()
    x.append(int(m[0]))
    y.append(int(m[1]))

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end

ll pos[200010][20],neg[200010][20];
const int mx=15;

int main(){
   int n; scanf("%d",&n);
   vector<ll> a(n); rep(i,0,n)scanf("%lld",&a[i]);
   //ifstream in("test.txt"); in>>n; a.resize(n); rep(i,0,n)in>>a[i];
   rep(j,0,mx+1)pos[n-1][j]=neg[0][j]=j;
   rrep(i,n-2,-1){
      ll s=1;
      rep(j,0,mx+1){
         int lg=0; ll t=1;
         while(a[i]*s>a[i+1]*t)t*=4,lg++;
         if(lg<=mx)pos[i][j]=pos[i+1][lg]+j;
         else pos[i][j]=pos[i+1][mx]+j+(n-i-1)*(lg-mx);
         s*=4;
      }
   }
   rep(i,1,n){
      ll s=1;
      rep(j,0,mx+1){
         int lg=0; ll t=1;
         while(a[i]*s>a[i-1]*t)t*=4,lg++;
         if(lg<=mx)neg[i][j]=neg[i-1][lg]+j;
         else neg[i][j]=neg[i-1][mx]+j+i*(lg-mx);
         s*=4;
      }
   }
   ll ans=pos[0][0]*2;
   rep(i,1,n)chmin(ans,(pos[i][0]+neg[i-1][0])*2LL+i);
   printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 64256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int count5=0;
		int count7=0;
		
		for(int i=0;i<3;i++) {
			int j=0;
			j=sc.nextInt();
			if(j==5)	count5+=1;
			if(j==7)	count7+=1;
		}
		
		if(count5==2&&count7==1) 
			System.out.println("YES");
		else
			System.out.println("NO");
		
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(void)
{
	int a,b,i,j,s,ss;
	s=0;
	for(i=0;i<4;i++){
		scanf("%d",&a);
		s+=a;
	}
	ss=0;
	for(j=0;j<4;j++){
		scanf("%d",&b);
		ss+=b;
	}
	if(s>=ss){
		printf("%d\n",s);
	}
	else if(s<ss){
		printf("%d\n",ss);
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int>t(n);
    int total=0;
    for(int i=0;i<n;i++){
        cin >> t.at(i);
        total+=t.at(i);
    }
    int m;
    cin >> m;
    vector<int> p(m),x(m);
    for(int i=0;i<m;i++){
        cin >> p.at(i) >> x.at(i);
        cout << total-t.at(p.at(i)-1)+x.at(i) << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

const int MAXN = 100010;

int n;
int a[MAXN];

int main()
{
	
	scanf("%d", &n);
	int x = 0, y = 0, z = 0;
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &a[i]);
		if (a[i]%4 == 0)
			++ x;
		else if (a[i]%2 == 0)
			++ y;
		else
			++ z;
	}
	
	if (y == 0)
		puts(x+1 >= z ? "Yes" : "No");
	else
		puts(x >= z ? "Yes" : "No");
	
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=1e9+7,N=1<<20;
int cnt[N],a[N],p[N],n,ans;
void solve(int u,int l,int r){
	if(l==r) return (void)(a[l]=u);
	int mid=(l+r)>>1;
	solve(u<<1,l,mid);
	solve(u<<1|1,mid+1,r);
	for(int i=l;i<=mid;++i)
		a[i]=a[i]*u%mod;
	for(int i=l;i<=mid;++i){
		int v=(1<<n-1)+p[i]-1,num=a[i];
		while(v) num=num*v%mod,cnt[v]=(cnt[v]+num)%mod,v>>=1;
	}
	for(int i=mid+1;i<=r;++i){
		int v=(1<<n-1)+p[i]-1,num=a[i],las=0;
		while(v) las=las*v%mod,ans=(ans+(cnt[v]-las+mod)%mod*num%mod)%mod,num=num*v%mod,las=cnt[v],v>>=1;
	}
	for(int i=l;i<=mid;++i){
		int v=(1<<n-1)+p[i]-1;
		while(v) cnt[v]=0,v>>=1; 
	}
	for(int i=mid+1;i<=r;++i)
		a[i]=a[i]*u%mod;
}
signed main(){
	cin>>n;
	for(int i=1;i<=(1<<n-1);++i)
		cin>>p[i];
	solve(1,1,1<<n-1);
	cout<<ans;
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll ma = -1e9;
    for(i = 0;i < n;++i){
        cin >> a.at(i);
        ma = max(a.at(i), ma);
    }
    ll sup = 0;
    ll inf = ma;
    while((inf - sup) > 1){
        ll mid = (sup + inf)/2;
        ll cnt = 0;
        for(i = 0;i < n;++i){
            if(a.at(i)%mid == 0){
                cnt += a.at(i)/mid-1;
            }else{
                cnt += a.at(i)/mid;
            }
        }
        if(cnt > k) sup = mid;
        else inf = mid;
    }
    cout << inf << endl;

    return 0;
}

Measured memory_bytes: 4776
import java.util.*;

class Main {
	Scanner sc;
	String S, T, U;
	int A, B;
	
	private void calc() {
		sc = new Scanner(System.in);
		S = sc.next();
		T = sc.next();
		A = sc.nextInt();
		B = sc.nextInt();
		U = sc.next();
		if (S.equals(U)) A--;
		else B--;
		System.out.println(A+" "+B);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}


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

/* 
The read function reads a string according to each one. 
*/
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")
}

//main function
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    println!("{}",(a*3+b)/2);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int _n,_k;
int ranks[101010];
int tmp[101010];

bool compare_sa(int i,int j){
  if(ranks[i]!=ranks[j])return ranks[i]<ranks[j];
  else{
    int ri=i+_k<=_n?ranks[i+_k]:-1;
    int rj=j+_k<=_n?ranks[j+_k]:-1;
    return ri<rj;
  }
}
void construct_sa(string s,int *sa){
  _n=s.length();
  for(int i=0;i<=_n;i++){
    sa[i]=i;
    ranks[i]=i<_n?s[i]:-1;
  }
  for(_k=1;_k<=_n;_k*=2){
    sort(sa,sa+_n+1,compare_sa);
    tmp[sa[0]]=0;
    for(int i=1;i<=_n;i++){
      tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
    }
    for(int i=0;i<=_n;i++){
      ranks[i]=tmp[i];
    }
  }
}

ll n,h;
string s;
ll cnt[101010];
int sa[101010];
ll sum[101010];

int main(){
  cin>>n>>h>>s;
  for(ll i=0;i<n;){
    if(s[i]!='0'){
      sum[i]++;
      ll suf=n-i;
      cnt[1]++;
      cnt[suf+1]--;
      i++;
      continue;
    }
    ll j;
    for(j=i;j<n&&s[j]=='0';j++);
    ll len=j-i;
    ll suf=n-j;
    sum[j]+=len;
    cnt[0]+=len*(len+1)/2;
    cnt[1]+=len;
    cnt[suf+1]-=len;
    i=j;
  }

  for(ll i=1;i<100001;i++)cnt[i+1]+=cnt[i];

  construct_sa(s,sa);

  if(h<=cnt[0]){
    cout<<0<<endl;
  }else{
    h-=cnt[0];
    ll d=-1;
    repl(i,1,n+1){
      if(h<=cnt[i]){
        d=i;
        break;
      }else h-=cnt[i];
    }
    repl(i,1,n+1){
      if(n-sa[i]>=d&&s[sa[i]]!='0'){
        if(h<=sum[sa[i]]){
          cout<<s.substr(sa[i],d)<<endl;
          return 0;
        }else h-=sum[sa[i]];
      }
    }
  }

  return 0;
}



Measured memory_bytes: 5964