akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n,k;
    cin >> n >> k;
    ll R,P,S;
    cin >> R >> S >> P;
    vector<string> mod(k);
    string s;
    cin >> s;
    ll ans=0;
    for(ll i=0;s[i]!='\0';i++)
    {
        if(s[i]=='r')
        {
            s[i]='p';
            ans+=P;
            //cout << ans;
        }
        else if(s[i]=='s')
        {
            s[i]='r';
            ans+=R;
            //cout << ans;

        }
        else if(s[i]=='p')
        {
            s[i]='s';
            ans+=S;
            //cout << ans;
        }

    }
    //cout << ans;
    //cout << s<<"\n";
    for(ll i=0;s[i]!='\0';i++)
    {
        mod[i%k]+=s[i];
    }
    /*for(ll i=0;i<k;i++)
    {
        cout << mod[i];
        cout <<"\n";
    }*/
    ll sub=0;
    for(ll i=0;i<k;i++)
    {
        //cout << i<<"\n";
        ll count=1;
        char d=mod[i][0];
        //cout << d;
        for(ll j=1;j<mod[i].size();j++)
        {
            if(mod[i][j]==mod[i][j-1])
            {
                d=mod[i][j-1];
                count++;
                //cout <<"count value"<< count<<"\n";
            }
            else
            {
                if(d=='r')
                {
                 //   cout <<"Rock found\n";
                    sub+=(count/2)*R;
                }
                else if(d=='s')
                {
               //     cout <<"Scissor found\n";
                    sub+=(count/2)*S;
                }
                else if(d=='p')
                {
             //       cout <<"Paper found\n";
                    sub+=(count/2)*P;
                }
                count=1;

            }

        }
        if(d=='r')
        {
           // cout <<"Rock found\n";
            sub+=(count/2)*R;
        }
        else if(d=='s')
        {
         //   cout <<"Scissor found\n";
            sub+=(count/2)*S;
        }
        else if(d=='p')
        {
       //     cout <<"Paper found\n";
            sub+=(count/2)*P;
        }
        count=1;



    }
    ans-=sub;
    cout << ans;

}


Measured memory_bytes: 6312
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
ll gi(){
	ll x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
int gc(){
	char ch=getchar();
	while(ch<'A'||ch>'Z')ch=getchar();
	return ch;
}
const int N=405;
struct edge{int to,nxt,w;ll cost;}E[N*N];
int n,m,x[N],y[N],t[N],a[N],b[N],L[N],R[N],D[N],U[N],head[N],cnt,S,T,vis[N],pe[N];
ll v[N],dis[N],ans;queue<int>Q;
void link(int u,int v,ll w){
	E[++cnt]=(edge){v,head[u],1,w};head[u]=cnt;
	E[++cnt]=(edge){u,head[v],0,-w};head[v]=cnt;
}
bool spfa(ll &res){
	memset(dis,63,sizeof(dis));
	dis[S]=0;Q.push(S);
	while(!Q.empty()){
		int u=Q.front();Q.pop();vis[u]=0;
		for(int i=head[u],v;i;i=E[i].nxt)
			if(E[i].w&&dis[v=E[i].to]>dis[u]+E[i].cost){
				dis[v]=dis[u]+E[i].cost;pe[v]=i;
				if(!vis[v])vis[v]=1,Q.push(v);
			}
	}
	if(dis[T]==dis[0])return false;res+=dis[T];
	for(int i=T;i!=S;i=E[pe[i]^1].to)--E[pe[i]].w,++E[pe[i]^1].w;
	return true;
}
ll cal(int k){
	for(int i=1;i<=k;++i)L[i]=D[i]=0,R[i]=U[i]=233;
	for(int i=1;i<=m;++i)
		if(b[i]<k){
			if(t[i]=='L')L[b[i]+1]=a[i]+1;
			if(t[i]=='R')R[k-b[i]]=a[i]-1;
			if(t[i]=='D')D[b[i]+1]=a[i]+1;
			if(t[i]=='U')U[k-b[i]]=a[i]-1;
		}
	for(int i=2;i<=k;++i)L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
	for(int i=k-1;i;--i)R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
	memset(head,0,sizeof(head));cnt=1;S=n+k<<1|1;T=n+k+1<<1;
	for(int i=1;i<=n;++i)link(i,n+i,-v[i]-1000000000000000ll);
	for(int i=1;i<=k;++i){
		link(S,n+n+i,0);link(n+n+k+i,T,0);
		for(int j=1;j<=n;++j){
			if(L[i]<=x[j]&&x[j]<=R[i])link(n+n+i,j,0);
			if(D[i]<=y[j]&&y[j]<=U[i])link(n+j,n+n+k+i,0);
		}
	}
	ll res=0;while(spfa(res));return -res-1000000000000000ll*k;
}
int main(){
	n=gi();
	for(int i=1;i<=n;++i)x[i]=gi(),y[i]=gi(),v[i]=gi();
	m=gi();
	for(int i=1;i<=m;++i)t[i]=gc(),a[i]=gi(),b[i]=gi();
	for(int i=1;i<=n;++i)ans=max(ans,cal(i));
	printf("%lld\n",ans);return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long s=0;
	long long t=0;
	long long f=9999999999;
	int a;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a<0)
		{
			t+=1;
			s+=a*-1;
			if(a*-1<f)
			f=a*-1;
		}
		else
		{
			s+=a;
			if(a<f)
			f=a;
		}
	}
	if(t%2==0)
	cout<<s;
	else
	cout<<s-f-f;
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<=n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define sz(v) ((int)(v).size())
#define get(a,st,en)  fl(i,st,en)       cin>>a[i]
#define pr(a,st,en)     fl(i,st,en)     cout<<a[i]<<" \n"[i==en]
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;
const int MAX=3005;
ll dp[MAX][MAX];
void solve()    {
        int n;  cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)    cin>>a[i];
        for(int L=n-1;L>=0;L--) {
                for(int R=L;R<n;R++)    {
                        if(L==R)        dp[L][R]=a[L];
                        else    {
                                dp[L][R]=max(a[L]-dp[L+1][R], a[R]-dp[L][R-1]);
                        }
                }
        }
        cout<<dp[0][n-1];
}
/*  Integer Overflow  */
int main()  {
    fast;
    //test()
        solve();
}

Measured memory_bytes: 70016
#include <stdio.h>
#include <iostream>

using namespace std;

long N, K;
long long x[100000];
void solve() {
  long l = 0;
  long r = l + K - 1;
  long long res = 1 << 30, minor;
  while (r < N) {
    if (x[r + 1] < 0) {
      l++;
      r++;
      continue;
    } else if (x[r] < 0) {
      res = abs(x[l]);
      l++;
      r++;
      continue;
    } else if (x[l] > 0) {
      res = min(res, x[r]);
      break;
    }
    minor = min(abs(x[l]),abs(x[r]))+abs(x[l]-x[r]);
    res = min(minor, res);
    l++;
    r++;
  }
  cout << res << endl;
  return;
}

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  solve();
  return 0;
}


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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;

  vector<int> L(Q), R(Q);
  rep(i, Q) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    L[i] = l, R[i] = r;
  }

  vector<int> v(N);
  int cnt = 0;
  rep(i, N - 1) {
    if (S[i] == 'A' && S[i + 1] == 'C')
      ++cnt;
    v[i + 1] = cnt;
  }

  rep(i, Q) cout << v[R[i]] - v[L[i]] << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 500000;
int const inf = 1000000000;
ll init[5 + nmax];
ll v[5 + nmax];
std::string s;

bool solve(int n, ll lim) {
  lim *= 9;
  v[n] = lim;
  for(int i = 0;i < n; i++)
    v[i] = init[i];
  for(int i = 0; i < n - 1; i++) {
    ll coef = std::min((inf - v[i + 1]), v[i]);
    v[i + 1] += coef * 10;
    v[i] -= coef;
  }

  for(int i = n - 1; 0 < i; i--) {
    if(v[i + 1] < v[i]) {
      ll coef = (v[i] - v[i + 1] + 9) / 10;
      v[i] -= coef * 10;
      v[i - 1] += coef;
    }
    if(v[i] < 0)
      return false;
  }
  
  if(v[0] <= v[1])
    return true;
  else
    return false;
}

int main() {
  std::cin >> s;
  int n = s.size();
  for(int i = 0; i < s.size(); i++)
    init[i] = s[i] - '0';
  int result = 0;
  for(int jump = (1 << 30); 0 < jump; jump /= 2) 
    if(solve(n, result + jump) == 0)
      result += jump;
  std::cout << (result + 1);
  return 0;
}


Measured memory_bytes: 11644
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll L, R;
int n, q;
ll a[maxn];
ll tp[maxn], s[maxn], x[maxn], t[maxn];
ll ca(ll b) {
	for (int j = 0; j < q; j++) {
		if (tp[j] == 1 && b >= x[j])
			b = (b + s[j]) * t[j];
		if (tp[j] == 2 && b <= x[j])
			b = (b - s[j]) / t[j];
	}
	return b;
}
ll cal(ll k) {
	// 多少个 <= k 
	int l = 0, r = n - 1;
	if (ca(a[r]) <= k) return n; 
	while (l < r) {
		int mid = (l + r) >> 1;
		if (ca(a[mid]) > k) r = mid;
		else l = mid + 1;
	}
	return l;
}
int main() {
	cin >> n >> q >> L >> R;
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sort(a, a + n);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld%lld%lld", &tp[i], &x[i], &s[i], &t[i]);
	}
	ll ans = cal(R) - cal(L - 1);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 10844
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define inf 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
  
        return (y%2 == 0)? p : (x * p) % m; 
    } 
    int modInverse(int a, int m) 
    {   
        return power(a, m-2, m);
    }
    int nCrModPFermat(int n, int r, int p) 
    { 
           if (r==0) 
              return 1; 
  
        int fac[n+1]; 
        fac[0] = 1; 
        for (int i=1 ; i<=n; i++) 
            fac[i] = fac[i-1]*i%p; 
  
        return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
    } 
    signed main()
    {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll t=1;
        // cin >> t;
        /*SAARE INPUTS LENA*/
        /*VARIABLES KI RANGE DEKHLENA*/
        /*EXPONENT RANGE OF OUTPUT KA DHYAN RAKHNA*/
        while(t-->0)
        {
            ll n=0,k=0;
            cin>>n>>k;
            vector <int> v(n);
            for (int i = 0; i < n; ++i)
            {
                cin>>v[i];
            }
            int dp[n];
            dp[0]=0;
            for (int i = 1; i < n; ++i)
            {
                dp[i]=inf;
                for(int j=1;j<=min(i,k);j++)
                    dp[i]=min(dp[i-j]+abs(v[i]-v[i-j]),dp[i]);
            }
            cout<<dp[n-1];
        }
        return 0;
    }

Measured memory_bytes: 4760
//47行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b);
template<class T> bool chmax(T& a,T b);
template<class T> void debugger(vector<T>& a);
template<class T> void debugger(vector<vector<T>>& a);
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int a,b;cin >> a >> b;
    for(int i = 1;i <= 1000;i++){
        if((int)(i * 0.08) == a and (int)(i * 0.1) == b){
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
    return 0;
}

///////////////////////////////////////////////////////////
template<class T> bool chmin(T& a,T b){
    if(a > b){a = b;return true;}else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){a = b;return true;}else return false;
}
template<class T> void debugger(vector<T>& a){
    cerr << "{";
    for(int i = 0;i < a.size();i++){
        if(i == 0)cerr << a[i];
        else cerr << "," << a[i];
    }
    cerr << "}" << '\n';
    return;
}
template<class T> void debugger(vector<vector<T>>& a){
    int n = a.size();
    int m = a[0].size();
    cerr << "__|";
    for(int i = 0;i < m;i++){
        cerr << setw(5) << i;
    }
    cerr << '\n';
    for(int i = 0;i < n;i++){
        cerr << setw(3) << i;
        for(int j = 0;j < m;j++){
            if(a[i][j] >= 100000)cout << setw(5) << "INF";
            else cerr << setw(5) << a[i][j];
        }
        cerr << '\n';
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main()
{
	int i, n;
	int a[10005];
	scanf("%d", &n);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
	}
	int ans = 0;
	for(i = 1 ; i <= n ; i++)
	{
		if(a[i] % 2 == 0)
		{
			while(a[i])
			{
				a[i] = a[i] / 2;
				ans++;
				if(a[i] % 2 != 0)break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    int ans;
    cin >> n;
    if(n%2==0){
        ans=n/2;
    }else{
        ans=n/2+1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//Tag : #
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>

#define Inf                     1001001001
using namespace std;

typedef long long int           ll;
typedef pair<ll, ll>            p_ll;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
typedef unsigned char           uchar;
typedef unsigned int            ui;
typedef unsigned long long int  ull;
/*************************************************/
int N;
string X;
vi t;
vector<string> s;
void input() {
    cin >> N;
    t.resize(N);
    s.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i];
    }
    cin >> X;
}

void sol() {
    int idx = 0;
    while (X != s[idx]) idx++;

    if (idx == N - 1)
        cout << 0 << endl;
    else {
        int sum = 0;
        for (int i = idx + 1; i < N; i++)
            sum += t[i];
        cout << sum << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    input();
    sol();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll x, k, d;
  	cin >> x >> k >> d;
  	x = abs(x);
  	if (x / d > k) {
    	while (k) {
        	x -= d;
          	k--;
        }
      	cout << x;
      	return 0;
    }
  	k -= x / d;
  	x %= d;
    if (k % 2 == 1) 
      	cout << abs(x - d);
    else
      	cout << abs(x);
    return 0;
}


Measured memory_bytes: 3700
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int xymin = Math.min(x,y);
        long ans = xymin * Math.min(a+b,c*2);
        x -= xymin;
        y -= xymin;
        if(x == 0){
            ans += y*Math.min(b,c*2);
        }else{
            ans += x*Math.min(a,c*2);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
//File Name: tenka1_2017_c.cpp
  //Created Time: 2017年10月10日 星期二 23时22分28秒
                                   
#include <bits/stdc++.h>
using namespace std;

void solve(const int n){
	for(long long  i(1);i<=3500;++i){
		for(long long j(1);j<=i;++j){
			auto p = 4 * i * j - n * j - n * i;
			auto q = n * i * j;
			if(p > 0 && q % p == 0){
				long long k = q / p;
				cout << i << " " << j << " " << k << endl;
				return ;
			}
		}
	}
}
int main(){
	int n;
	cin >> n;
	solve(n);
	return 0;
}


Measured memory_bytes: 256
main(z){float d,e,f,g,h,i,m,n,M,N,p,q;for(scanf("%d",&z);z--;puts(((p*(f-d)*(n-e)>p*(m-d)*(g-e)&&p*(d-h)*(n-i)>p*(m-h)*(e-i))^(q*(f-d)*(N-e)>q*(M-d)*(g-e)&&q*(d-h)*(N-i)>q*(M-h)*(e-i)))?"OK":"NG"))scanf("%f%f%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n,&M,&N),p=(h-f)*(n-g)-(m-f)*(i-g),q=(h-f)*(N-g)-(M-f)*(i-g);}

Measured memory_bytes: 616
n = int(input())
a = list(map(int, input().split()))
d = dict()

for ai in a:
    if ai not in d.keys():
        d[ai] = 1
    else:
        d[ai] += 1

l2 = []
l4 = []
for k, v in d.items():
    if v >= 2:
        l2.append(k)
    if v >= 4:
        l4.append(k)

l2.sort()
l4.sort()
if len(l2) > 1:
    if len(l4) > 0:
        ans = max(l2[-1]*l2[-2], l4[-1]**2)
    else:
        ans = l2[-1]*l2[-2]
elif len(l2) == 1:
    if len(l4) > 0:
        ans = l4[-1]**2
    else:
        ans = 0
else:
    ans = 0
print(ans)


Measured memory_bytes: 21976
#include<bits/stdc++.h>
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 1e5 + 1;
const ll inf = 1e13;
void so(vector<ll>&x, vector<ll>&h, ll n){
    vector<pair<ll, ll> > v(n);
    f(i, n)v[i].first = x[i], v[i].second = h[i];
    sort(b_e(v));
    f(i, n)x[i] = v[i].first, h[i] = v[i].second;
}
void input(){
    ll n, d, A;
    cin >> n >> d >> A;
    vector<ll>x(n), h(n);
    f(i, n)cin >> x[i] >> h[i];
    so(x, h, n);
    vector<ll>a(n + 1, 0);
    ll ans = 0;
    f(i, n){
        a[i + 1] += (a[i]);
        if(h[i] + a[i] > 0){
            ll p = h[i] + a[i];
            p = (ll)ceil((double)p / (double)A);
            ans += p;
            a[i + 1] += (-p * A);
            ll k = lower_bound(b_e(x), x[i] + 2 * d + 1) - x.begin();
            a[k] += (p * A);

        }
    }
    cout << ans << endl;


}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;

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

		while(sc.hasNextInt()){
			int n = sc.nextInt();

			boolean[][] map = new boolean[7][7];
			int start = -1;
			boolean[] nodeFlg = new boolean[7];
			for(int i=0;i<n;i++){
				String s = sc.next();
				int from = s.charAt(0) - '0';
				int to = s.charAt(1) - '0';

				nodeFlg[from] = nodeFlg[to] = true;
				if(from != to){
					map[from][to] = map[to][from] = true;
					start = from;
				}
			}

			int nodeCount = 0;
			for(int i=0;i<7;i++) if(nodeFlg[i]) nodeCount++;

			if(start == -1){
				System.out.println(nodeCount==1 ? "Yes" : "No");
				continue;
			}

			if(reachableCount(start,map,new boolean[7]) != nodeCount){
				System.out.println("No");
				continue;
			}

			System.out.println(isEulerGraph(map,nodeCount) ? "Yes" : "No");
		}
	}

	private static int reachableCount(int from,boolean[][] map,boolean[] flg){
		int res = 1;

		flg[from] = true;
		for(int i=0;i<7;i++){
			if(map[from][i] && !flg[i]){
				res += reachableCount(i,map,flg);
			}
		}

		return res;
	}

	private static boolean isEulerGraph(boolean[][] map,int nodeCount){
		int n = map.length;
		int evenCount = 0;

		for(int i=0;i<n;i++){
			int count = 0;
			for(int j=0;j<n;j++){
				if(i != j && map[i][j]){
					count++;
				}
			}
			if(count != 0 && count % 2 == 0) evenCount++;
		}
		if(evenCount == nodeCount || evenCount == nodeCount-2) return true;
		return false;
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

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

int main(void){
    int n, m; scanf("%d%d", &n, &m);
    int l = 1, r = n;
    REP(i, m){
        int a, b; scanf("%d%d", &a, &b);
        if(l < a) l = a;
        if(r > b) r = b;
    }
    if(r < l) puts("0");
    else printf("%d\n", r - l + 1);
    return 0;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, t; cin >> n >> t;
  vector<int> a(n); REP(i, n) cin >> a[i];
  int profit = 0, mn = a[0], ans = 0;
  FOR(i, 1, n) {
    int tmp = a[i] - mn;
    if (tmp > profit) {
      profit = tmp;
      ans = 1;
    } else if (tmp == profit) {
      ++ans;
    }
    chmin(mn, a[i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
import sys
from collections import deque
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = deque([])
for i, a in enumerate(a_ls):
    if i % 2 == 0:
        b_ls.append(a)
    else:
        b_ls.appendleft(a)
if n % 2 == 1:
    b_ls.reverse()
print(" ".join([str(i) for i in b_ls]))

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 18;

int N;
array<int, 2> arr[MAXN];
int dp[(1 << MAXN)][MAXN];
int ans;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i][0];
    }
    FOR(i, 0, N)
    {
        cin >> arr[i][1];
    }
    FOR(i, 0, (1 << N))
    {
        fill(dp[i], dp[i] + N, N * N);
    }
    FOR(i, 0, N)
    {
        dp[(1 << i)][i] = 0;
    }
    FOR(i, 1, (1 << N))
    {
        int c = __builtin_popcount(i);
        FOR(j, 0, N)
        {
            if (!(i & (1 << j))) continue;
            int vj = arr[j][((c ^ j ^ 1) & 1)];
            // cerr << "dp " << i << ' ' << j << " = " << dp[i][j] << endl;
            FOR(k, 0, N)
            {
                if (i & (1 << k)) continue;
                int vk = arr[k][(c ^ k) & 1];
                if (vj > vk) continue;
                ckmin(dp[i + (1 << k)][k], dp[i][j] + (__builtin_popcount(i & ((1 << N) - (1 << k)))));
            }
        }
    }
    ans = N * N;
    FOR(i, 0, N)
    {
        ckmin(ans, dp[(1 << N) - 1][i]);
    }
    if (ans == N * N) ans = -1;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 18688
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int n, t, s1, s2, ans = 1000000, mi = 0;
    cin >> n;
    vector<int> w(n);
    for(int i = 0;i < n;i++){
        cin >> w[i];
    }

    for(int i = 0;i < n;i++){
        t = i;
        s1 = s2 = 0;
        for(int j = 0;j < n;j++){
            if(j <= t){
                s1 += w[j];
            }
            else{
                s2 += w[j];
            }
        }
        if(ans > abs(s1 - s2)){
            ans = abs(s1 - s2);
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
template<class T = ll> T in(){T x; cin >> x; return (x);}

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

  ll N;
  cin >> N;
  ll a=0,b=0;
  rep(i,N){
    ll ai,bi;
    cin >> ai >> bi;
    if(ai>a){
      a = ai;
      b = bi;
    }
  }

  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <set>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <iomanip>
#include <list>

using namespace std;

double const PI = atan(1.0) * 4;

class cPoint
{
	double mx;
	double my;
public:
	cPoint() {}

	cPoint(double x, double y)
		: mx(x), my(y)
	{
	}

	cPoint operator+(const cPoint& obj2)
	{
		return cPoint(mx + obj2.mx, my + obj2.my);
	}

	cPoint operator-(const cPoint obj2)
	{
		return cPoint(mx - obj2.mx, my - obj2.my);
	}

	cPoint operator*(const double& d)
	{
		return cPoint(mx * d, my * d);
	}

	cPoint operator/(const double& d)
	{
		if (d != 0.0)
		{
			return cPoint(mx / d, my / d);
		}
		return cPoint(0.0, 0.0);
	}

	bool operator==(const cPoint& obj2)
	{
		if (mx == obj2.mx && my == obj2.my)
			return true;
		return false;
	}

	void operator()(const double& a, const double& b)
	{
		mx = a;
		my = b;
	}

	double getLength(const cPoint& obj)
	{
		return sqrt(obj.mx * obj.mx + obj.my * obj.my);
	}

	cPoint gen(const cPoint& obj1, const cPoint& obj2, const double& angle, const double mul = 1.0)
	{
		cPoint temp = obj2;
		temp = temp - obj1;
		double length = getLength(temp);

		temp.mx = length * mul * cos(angle / 180.0 * PI);
		temp.my = length * mul * sin(angle / 180.0 * PI);

		return temp;
	}

	void display(ostream& out)
	{
		out << mx << " " << my;
	}
};

ostream& operator<<(ostream& o, cPoint& d)
{
	d.display(o);
	return o;
}

class cKochCurve
{
	int mn;
	cPoint m_p1, m_p2;
	list<cPoint> lpPoints;

public:
	
	cKochCurve(int n)
		: mn(n) 
	{
		m_p1(0.0, 0.0);
		m_p2(100.0, 0.0);
		lpPoints.push_front(m_p1);
		lpPoints.push_back(m_p2);

		calc(n, m_p1, m_p2, 0);
	}
	void calc(int, cPoint, cPoint, double);
	void output();
};

void cKochCurve::calc(int n, cPoint p1, cPoint p2, double angle) 
{
	if (n == 0) return;
	list<cPoint>::iterator ilpp;
	for (list<cPoint>::iterator it = lpPoints.begin(); it != lpPoints.end(); ++it)
	{
		if (*it == p1 && it != lpPoints.end())
		{
			list<cPoint>::iterator it2 = it;
			++it2;
			if (*it2 == p2)
			{
				ilpp = it2;
				break;
			}
		}
	}
	cPoint s, t, u;
	s = p1 + (p2 - p1) * (1.0 / 3.0);
	t = p1 + (p2 - p1) * (2.0 / 3.0);
	u = s + t.gen(s, t, angle + 60.0);

	lpPoints.insert(ilpp, s); 
	lpPoints.insert(ilpp, u); 
	lpPoints.insert(ilpp, t); 

	calc(n - 1, p1, s, angle);
	calc(n - 1, s, u, angle + 60);
	calc(n - 1, u, t, angle - 60);
	calc(n - 1, t, p2, angle);
}

void cKochCurve::output()
{
	for (list<cPoint>::iterator it = lpPoints.begin(); it != lpPoints.end(); ++it)
	{
		cout << fixed << setprecision(8) << *it << endl;
	}
}

int main()
{

	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	cin.ignore();

	cKochCurve ckc(n);
	ckc.output();

	return 0;
}

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

bool marks[11];
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < k; ++i) {
        int l;
        cin >> l;
        marks[l] = true;
    }

    for (int i = 0; i < 10 * n; ++i) {
        if ( i >= n ) {
            string s = to_string(i);
            bool chk = true;
            for (auto el: s) 
                if (marks[el - '0']) chk = false;
            if (chk) {
                cout << s << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

int main(){
	string s;
	cin>>s;
	bool b1=false,b2=false;
	for(int i=0;i<s.length();i++){
		if(s[i]=='C')b1=true;
		if(s[i]=='F' && b1){
			b2=true;
		}
	}
	if(b1 && b2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using LL = long long;
int pw[30];
int main () {
	pw[0] = 1;
	for (int i = 1; i < 30; ++i) pw[i] = pw[i-1] * 2;
	int n, k; cin >> n >> k;
	LL up = 0, dw = pw[20];
	for (int i = 1; i <= n; ++i) {
		int cnt = 0, tmp = i;
		while (tmp < k) cnt++, tmp *= 2;
		up += pw[20-cnt];
	}
	double ans = 1.0 * up / pw[20] / n;
	printf ("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int m,f,r,sum;

  while(1){
    scanf("%d %d %d",&m,&f,&r);
    sum = m + f;
    if(m == -1 && f == -1 && r  == -1) break;
    if(m == -1 || f == -1) printf("F\n");
    else if(sum >= 80) printf("A\n");
    else if(sum >= 65 && sum < 80) printf("B\n");
    else if(sum >= 50 && sum < 65) printf("C\n");
    else if(sum >= 30 && sum < 50){
      if(r >= 50) printf("C\n");
      else printf("D\n");
    }
    else printf("F\n");
  }
  return 0;
}



Measured memory_bytes: 2148
fun main(args: Array<String>) {
    agc013a()
}

fun agc013a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    if (n <= 2) return println(1)

    var answer = 0
    var left = 0
    while (left <= aList.lastIndex) {
        var right = left
        var pos: Boolean? = null
        while (right <= aList.lastIndex) {
            if (right + 1 > aList.lastIndex) break
            if (pos == null) {
                if (aList[right] < aList[right + 1]) pos = true else
                    if (aList[right] > aList[right + 1]) pos = false
            }

            if (pos == null) right++ else
                if (pos) {
                    if (aList[right] <= aList[right + 1]) right++ else break
                } else {
                    if (aList[right] >= aList[right + 1]) right++ else break
                }
        }
        left = right + 1
        answer++
    }

    println(answer)
}


Measured memory_bytes: 53640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans;
signed main(){
	n=1;
	int a,b;
	cin>>a>>b;
	while(n<b){
		n+=a-1;
		ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

class Solve:
    def __init__(self):
        self.flag = False

    def helper(self, a, b, c, k):
        if k == 0:
            if b > a and c > b:
                self.flag = True
                return
            else:
                return
        else:
            self.helper(a * 2, b, c, k - 1)
            self.helper(a, b * 2, c, k - 1)
            self.helper(a, b, c * 2, k - 1)


def main():
    a,b,c = [int(i) for i in input().strip().split()]
    k = int(input().strip())
    
    solver = Solve()

    solver.helper(a, b, c, k)
    if solver.flag:
        print("Yes")
    else:
        print("No")



    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 67676
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    
    int a[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    
    int dp[n][3];
    
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    
    for(int i=1;i<n;i++)
    {
        dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }
    
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 5964
import java.util.Scanner;
import java.text.DecimalFormat;

public class Main
{
    public static void main(String[] args)
    {
        Scanner key = new Scanner(System.in);
        double num = key.nextInt();
        key.close();
        
        System.out.println((num/3)*(num/3)*(num/3));
        
    }
}

Measured memory_bytes: 22868
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val edges = readListOfInt().sorted()

    val ans = edges[0] * edges[1] / 2

    println(ans)


    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37908
def my_index2(l, x, default=-1):
    return l.index(x) if x in l else default
n = int(input())
S = list(input())
for i in range(n):
  S[i] = int(S[i])
ans = 0
for i in range(10):
  a = my_index2(S[0:n-2],i)
  if a != -1:
    for j in range(10):
      b = my_index2(S[a+1:n-1], j) 
      if b!=-1:
        for k in range(10):
          c = my_index2(S[a+1+b+1::], k)
          if c!= -1:
            ans+=1
print(ans)

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

int E[5001], n[5001], C[5001], H[2501];
bool vis[2501];
void dfs(int v) {
	vis[v] = true;
	for (int p = H[v]; p; p = n[p]) {
		int to = E[p];
		if (!vis[to]) dfs(to);
	}
}

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


	int N, M, P;
	cin >> N >> M >> P;
	rep1(i, M) {
		int a;
		cin >> a >> E[i] >> C[i];
		n[i] = H[a];
		H[a] = i;
	}
	ll D[2501];
	rep1(i, N) D[i] = -2e9;
	D[1] = 0;
	int q[2501] = {};
	q[1] = 1;

	//こんな明らかに正しくない提出をして何をしたいというのかこの男は
	int mae[2501] = {};
	int cnt[2501] = {};

	rep1(k, N) {
		rep1(i, N) {
			if (q[i] == k) {
				for (int p = H[i]; p; p = n[p]) {
					int to = E[p];
					ll d = D[i] + C[p] - P;
					if (D[to] < d && cnt[to] < 100) {
						if (mae[to] == D[to] - d) {
							cnt[to]++;
						}
						else {
							mae[to] = D[to] - d;
							cnt[to] = 0;
						}
						D[to] = d;
						q[to] = k + 1;
					}
				}
			}
		}
	}

	rep1(i, N) {
		if ((q[i] == N + 1 || cnt[i] == 100) && !vis[i]) dfs(i);
	}

	if (vis[N]) co(-1);
	else co(max(0ll, D[N]));


	Would you please return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
long long W,H;
vector<long long> p;
vector<long long> q;
int main(){
	cin>>W>>H;
	long long ans=0;
	REP(i,W){
	    long long a;
	    cin>>a;
	    p.push_back(a);
	    ans+=a;
	}
	REP(j,H){
	    long long b;
	    cin>>b;
	    q.push_back(b);
	    ans+=b;
	}
	sort(p.begin(),p.end());
	sort(q.begin(),q.end());
        long long p_c=0;
        long long q_c=0;
        while((p_c!=p.size())&&(q_c!=q.size())){
       // cout<<ans<<endl;
            long long a=p[p_c];
            long long b=q[q_c];
            if(a<b){
               long long d=q.size()-q_c;
               ans+=d*p[p_c];
               p_c++;
            }else{
               long long d=p.size()-p_c;
               ans+=d*q[q_c];
               q_c++;
            }
        }
        cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 2548
import itertools as it

n=int(input())
A=input().split()
q=int(input())
M=input().split()
ans=[]
cnt=0

A=list(map(int,A))
M=list(map(int,M))

for i in range(len(A)):
    Ac=list(it.combinations(A,i+1))
    for j in Ac:
        ans.append(sum(j))

for i in M:
    flag=0
    for j in ans:
        if i==j:
            print("yes")
            flag=1
            break
    if flag==0:
        print("no")


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define S 0
#define W 1

signed main(){

	lli n;
	cin>>n;

	string s;
	cin>>s;

	REP(start,0,2)REP(side,0,2){
		lli ans[100100];
		REP(i,0,100100)ans[i]=-1;
		ans[0]=start;
		ans[1]=side;
		if(start==S){
			if(s.at(0)=='o')ans[n+2] = ans[1];
			else ans[n+2] = (ans[1]+1)%2;
		}
		else{
			if(s.at(0)=='o')ans[n+2] = (ans[1]+1)%2;
			else ans[n+2] = (ans[1]);
		}
		REP(i,1,n){
			ans[i+1] = (ans[i-1]+ans[i]+(s.at(i)!='o'))%2;
		}
		if(ans[0]==ans[n] && ans[n-1] == ans[n+2]){
			REP(i,0,n){
				if(ans[i]==0)cout<<"S";
				else cout<<"W";
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 1408
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i=0; i<n; i++){
			LinkedList<Integer> A, B, C;
			A = new LinkedList<Integer>();
			B = new LinkedList<Integer>();
			C = new LinkedList<Integer>();
			for(int j=0; j<10; j++)		A.add(in.nextInt());
			if(routine(A,B,C))		System.out.println("YES");
			else					System.out.println("NO");
		}
	}
	
	private static boolean routine(LinkedList<Integer> A, LinkedList<Integer> on, LinkedList<Integer> off){
		/*
		for(Integer i : A)		System.out.print(i+" ");
		System.out.println();
		for(Integer i : on)		System.out.print(i+" ");
		System.out.println();
		for(Integer i : off)	System.out.print(i+" ");
		System.out.println();
		System.out.println();
		*/
		
		if(A.isEmpty()){
			return true;
		}else if(on.isEmpty() || on.getLast() < A.getFirst()){
			on.addLast(A.getFirst());
			A.removeFirst();
			if(routine(A, on, off))			return true;
			else if(routine(A, off, on))	return true;
			else{
				A.addFirst(on.getLast());
				on.removeLast();
				return false;
			}
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int in = 0;;
	int out = 0;
	int sco = 0;
	rep(i, n) {
		if (i != n - 1) {
			if (s[i] == 'R' && s[i + 1] == 'L') {
				in++;
			}
			if (s[i] == 'L' && s[i + 1] == 'R') {
				out++;
			}
		}
		if (i == 0) {
			if (s[i] == 'R' && s[i + 1] == 'R') {
				sco++;
			}
		}
		else if (i == n - 1) {
			if (s[i] == 'L' && s[i - 1] == 'L') {
				sco++;
			}
		}
		else {
			if (s[i] == 'L' && s[i - 1] == 'L') {
				sco++;
			}
			if (s[i] == 'R' && s[i + 1] == 'R') {
				sco++;
			}
		}
	}

	sco += min(min(in, out),k) * 2;

	if (in != out && min(in, out) < k) {
		if (in > out) {
			if (s[0] == 'R' || s[0] == 'L') {
				sco++;
			}
		}
		else {
			if (s[0] == 'L' || s[0] == 'R') {
				sco++;
			}

		}
	}


	cout << sco << endl;
	

}


Measured memory_bytes: 512
#include<stdio.h>
long long M=1e9+7;
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int ta[200010],nt[400010],to[400010],tS[400010];
long long tu[200010],ANS[200020],tans[200020];
//sが親でtから帰ってきた時の処理 変えるやつ
void fc(int s,int t){tans[s]=tans[s]*tans[t]       %M;}
//fcの逆処理　変えるやつ
void ic(int s,int t){tans[s]=tans[s]*inv(tans[t],M)%M;}
//すべての子の処理が終わった時の処理　変えるやつ
void fp(int s){tans[s]=tans[s]*inv(tS[s],M)%M;}
//fpの逆処理　変えるやつ
void ip(int s){tans[s]=tans[s]*tS[s]       %M;}
//木DPの関数
void tDP(int s){//printf("!%d\n",s);
  long long i;
  tu[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(tu[to[i]])continue;
    tDP(to[i]);
    fc(s,to[i]);
    tS[s]+=tS[to[i]];
  }
  fp(s);
}
//根をsからtにする奴
void chrt(int s,int t){
  ip(s);
  ic(s,t);
  ip(t);
  tS[s]-=tS[t];
  tS[t]+=tS[s];
  fp(s);
  fc(t,s);
  fp(t);
}
//全方位やる奴
void atdp(int s){//printf("!!%d %d\n",s,cc[s]);
  int i;
  tu[s]=2;
  ANS[s]=tans[s];
  for(i=ta[s];i+1;i=nt[i]){
    if(tu[to[i]]==2)continue;
    chrt(s,to[i]);
    atdp(to[i]);
    chrt(to[i],s);
  }
}
//呼びだす奴
void atDP(int v,int *a,int *b){
  int i,I=1;
  for(i=0;i<v;i++)ta[i+I]=-1;
  for(i=0;i<v;i++)tS[i+I]=1;
  for(i=0;i<v;i++)tans[i+I]=1;
  for(i=0;i<v-1;i++){
    nt[i]=ta[to[i+v-1]=a[i]];
    nt[i+v-1]=ta[to[i]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+v-1;
  }
  tDP(I);
  atdp(I);
}
int main(){
  int n,i,a[200010],b[200010];
  long long p=1;
  scanf("%d",&n);
  for(i=0;i<n-1;i++)scanf("%d %d",&a[i],&b[i]);
  for(i=1;i<=n;i++)p=p*i%M;
  atDP(n,a,b);
  for(i=0;i<n;i++)printf("%lld\n",ANS[i+1]*p%M);
  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//
long double sq(ll x, ll y) {
    return x * x + y * y;
}

int main() {
    init();
    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];
    vector<ll> ivec(N);
    iota(all(ivec), 0);
    sort(all(ivec), [&](ll i, ll j) {
        return atan2(y[i], x[i]) < atan2(y[j], x[j]);
    });

    rep(i, N) ivec.eb(ivec[i]);

    long double ans = 0, tmp = 0, tans = 0;
    ll tx, ty;
    rep(i, N) {
        tx = 0;
        ty = 0;
        tans = 0;
        rep(j, N) {
            tx += x[ivec[i + j]];
            ty += y[ivec[i + j]];
            tmp = sq(tx, ty);
            if (tmp > tans) {
                tans = tmp;
                ans = max(ans, tans);
            } else {
                tx -= x[ivec[i + j]];
                ty -= y[ivec[i + j]];
            }
        }
    }
    cout << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 384