akhauriyash/Code-Regression huggingface dataset:
from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n = int(input())
    d = [''.join(sorted(list(input()))) for _ in range(n)]
    dd=Counter(d)
    cnt=0
    for i in dd.values():
        cnt += i*(i-1)//2
    print(cnt)




resolve()

Measured memory_bytes: 64220
s=input()
t=input()
b=[]
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()
for i in range(len(s)-len(t)+1):
    a=1
    c=''
    for j in range(len(t)):
        if s[i+j]=='?' or s[i+j]==t[j]:
            continue
        else:
            a=0
    if a==1:
        for j in range(i):
            c+=s[j] if s[j]!='?' else 'a'
        for j in range(len(t)):
            c+=t[j]
        for j in range(len(s)-len(t)-i):
            c+=s[j+i+len(t)] if s[j+i+len(t)]!='?' else 'a'
        b.append(c)
if len(b)==0:
    print('UNRESTORABLE')
else:
    print(min(b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
 
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
bool less_vectors(const vector<int>& a,const vector<int>& b) 
{
  return a.size() < b.size();
}
int32_t main()
{
    IOS;
   /* #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int n;
    cin>>n;
    vpi v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i].ff;
        v[i].ss=i;
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(abs(v[i].ss-i)%2==1)
            ans++;
    }
    cout<<ans/2;
    return 0;
} 

Measured memory_bytes: 1792
import itertools
from heapq import heapify,heappush,heappop

N=input()
a=[]
a=map(int, raw_input().split())
a1=a[0:N]
#print a1

heapify(a1)

l1=[]
sum_a1=sum(a1)
l1.append(sum_a1)

# Max
for i in range(N,2*N):
	if a[i]>a1[0]:
		sum_a1=sum_a1+a[i]-a1[0]
		heappop(a1)
		heappush(a1, a[i])

	l1.append(sum_a1)


l2=[]
a2=[ -x for x in a[2*N:3*N]]
heapify(a2)
sum_a2=-1*sum(a2)
l2.append(sum_a2)

# Min
for i in reversed(range(N,2*N)):
	if a[i]<-1*a2[0]:
		sum_a2=sum_a2+a[i]-(-1*a2[0])
		heappop(a2)
		heappush(a2,-1*a[i])
	l2.append(sum_a2)


ans=[]
for i in range(N+1):
	ans.append(l1[i]-l2[N-i])

print max(ans)



Measured memory_bytes: 28920
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b, c; cin >> a >> b >> c;
    int res = min(c, b/a);
    cout << res << ln;

}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int hoge(long long int a){
  switch (a % 4){
    case 3 :
    case 0 : return 0;
    case 1 :
    case 2 : return 1;
  }
}


long long int solve(long long a, long long b){
  long long ret = 0;
  for (long long i = 0; i < 50; i++){
    if (pow(2, i) > b)
      return ret;

    if (i == 0){
      /*
      if (a % 2 == b % 2 && a % 2 && (b - a) % 4 == 0)
        ret += (((b - a) % 4) / 2 + 1) % 2;
      else if (a % 2 == b % 2 && (b - a) % 4 == 2)
        ret += 1;
      else
        */
        ret += (hoge(b) + hoge(a - 1)) % 2;
      continue;
    }

    if (a % ((long long)1 << (i + 1)) < (long long)1 << i){
      if (b % ((long long)1 << (i + 1)) >= (long long)1 << i){
        ret += (long long)((((long long int)1) << i) * ((b + 1) % 2));
      }
    }
    else
      if (b % ((long long)1 << (i + 1)) < (long long)1 << i){
        ret += (long long)((((long long)1) << i) * (a % 2));
      }
      else{
        ret += (long long)((((long long int)1) << i) * ((b - a + 1) % 2));
      }

  }

}
  
int main(void){
  long long a, b;

  cin >> a >> b;


  cout << solve(a, b) << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;
#define P (31LL)
#define MOD1 (1000000009LL)
#define INV1 (838709685LL)
#define MOD2 (1000000007LL)
#define INV2 (129032259LL)

int n, m, a[400000];
Int B1[400000], B2[400000];
char s[400000], op[10];

int main() {
    scanf("%d%d", &n, &m);
    scanf("%s", s);
    rep (i, n) a[i] = s[i]-'a'+1;
    B1[0] = 1;
    rep (i, n) B1[i+1] = B1[i]*P % MOD1;
    B2[0] = 1;
    rep (i, n) B2[i+1] = B2[i]*P % MOD2;
    set<pair<Int, Int> > st;
    int L = 0, R = 0;
    Int cur1 = a[0], cur2 = a[0];
    rep (_, m) {
        scanf("%s", op);
        if (op[0] == 'L') {
            if (op[1] == '+') {
                cur1 = (cur1 - a[L]*B1[R-L]%MOD1 + MOD1) % MOD1;
                cur2 = (cur2 - a[L]*B2[R-L]%MOD2 + MOD2) % MOD2;
                L++;
            }
            else {
                cur1 = (cur1 + a[L-1]*B1[R-L+1]%MOD1) % MOD1;
                cur2 = (cur2 + a[L-1]*B2[R-L+1]%MOD2) % MOD2;
                L--;
            }
        }
        else {
            if (op[1] == '+') {
                cur1 = (cur1 * P + a[R+1]) % MOD1;
                cur2 = (cur2 * P + a[R+1]) % MOD2;
                R++;
            }
            else {
                cur1 = ((cur1 - a[R] + MOD1) % MOD1 * INV1) % MOD1;
                cur2 = ((cur2 - a[R] + MOD2) % MOD2 * INV2) % MOD2;
                R--;
            }
        }
        st.insert(make_pair(cur1, cur2));
    }
    printf("%d\n", (int)st.size());
    return 0;
}

Measured memory_bytes: 27876
#include<stdio.h>
int main()
{
	int n,m,h[100000],a[100000],b[100000];
	int i,j,c=0,x[100000];
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&h[i]);
		x[i]=0;
	}
	for(i=1;i<=m;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(h[a[i]]==h[b[i]]){
			x[a[i]]=1;
			x[b[i]]=1;
		}
		if(h[a[i]]>h[b[i]]){
			x[b[i]]=1;
		}
		if(h[a[i]]<h[b[i]]){
			x[a[i]]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(x[i]==0){
			c++;
		}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 3264
#include <cstdio>

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a == b && b == c)
        printf("1\n");
    else if(a != b && b != c && c != a)
        printf("3\n");
    else
        printf("2\n");

    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
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<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
//const long mod=(long)1e9+7;
inline void solve(void){
  int N;in(N);
  rep(i,N){
    int A;in(A);
    if(A%2==0){
      if(A%3!=0&&A%5!=0){
        out("DENIED");
        return;
      }
    }
  }
  out("APPROVED");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

int digit(const string& str, size_t i) {
  return stoi(str.substr(i,1));
}

int main(){
  string str;
  cin >> str;
  size_t n = str.size();

  std::vector<int> mod2019(2019,0);
  ++mod2019[0];
  int m{0};
  int m10{1};
  for (auto i = n; i; --i) {
    m10 = (m10*10) % 2019;
    m = (m10 * digit(str,i-1) + m) % 2019;

    ++mod2019[m];
  }

  auto cnt = std::accumulate(begin(mod2019),end(mod2019),0,
                             [](int a, int b){
                               return a + b*(b-1)/2;
                             });

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int a,b,c;
    cin>>a>>b>>c;
    ll int k;
    cin>>k;
    ll int cnt=0;
    while(b<=a)
    {
    	cnt++;
    	b=b*2;
    }
    while(c<=b)
    {
    	cnt++;
    	c=c*2;
    }
    if(cnt<=k)
    	cout<<"Yes\n";
    else
    	cout<<"No\n";
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
//g++??????
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
using namespace std;


int main(void)
{
	double a, b, angle;
	cin >> a >> b >> angle; 
	
	double radian = angle * M_PI / 180.0;
	double h = b * sin(radian);//??????
	
	double S = 1/2.0 * a * h;//??¢???

	double cc = a * a - 2 * a * b * cos(radian)+ b * b;

	double c = sqrt(cc);
	
	double L = a + b + c;//??¨?????????
	
	printf("%.4f\n%.4f\n%.4f\n", S, L, h);
	//cout << y << endl;
	
	return 0;
}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int m,d;
	cin>>m>>d;
	int output = 0;
	for(int i=1;i<=d;i++)
	{
		int d01 = i%10;
		int d10 = i/10;
		if(d01>1&&d10>1)
		{
			//cout<<d01<<"  "<<d10<<endl;
			int mapp = d01*d10;
			if(mapp<=m)output++;
		}
	}
	cout<<output;
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[1], reverse=True)
    bluedots = sorted(bluedots, key=lambda x: x[0])

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                reddots.remove(red)
                break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

template <class T, size_t D> struct _Vec {
    using type = vector<typename _Vec<T, D-1>::type>;
};
template <class T> struct _Vec<T, 1> {
    using type = vector<T>;
};
template<class T, size_t D> using Vec = typename _Vec<T, D>::type;

template <class T>
vector<T> make_v(size_t size, const T& init){ return vector<T>(size, init); }

template<class... Ts>
auto make_v(size_t size, Ts... rest) {
    return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}

int main() {
    int n, w;
    cin >> n >> w;
    vector<vector<ll>> v(4);
    ll a, b;
    cin >> a >> b;
    v[0].emplace_back(b);
    for (int i = 0; i < n-1; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        v[x-a].emplace_back(y);
    }
    for (int i = 0; i < 4; ++i) {
        sort(v[i].begin(), v[i].end(), greater<>());
        partial_sum(v[i].begin(), v[i].end(), v[i].begin());
    }
    ll ans = 0;
    for (int i = 0; i <= v[0].size(); ++i) {
        for (int j = 0; j <= v[1].size(); ++j) {
            for (int k = 0; k <= v[2].size(); ++k) {
                for (int l = 0; l <= v[3].size(); ++l) {
                    if(a*(i+j+k+l)+j+2*k+3*l <= w){
                        ll p = 0;
                        if(i > 0) p += v[0][i-1];
                        if(j > 0) p += v[1][j-1];
                        if(k > 0) p += v[2][k-1];
                        if(l > 0) p += v[3][l-1];
                        ans = max(ans, p);
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    string a,b;
    cin>>a>>b;
    ll n=sz(a),m=sz(b);
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    rep(i,1,n){
        rep(j,1,m){
            if(a[i-1]!=b[j-1]) dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            else dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
    }
    string ans="";
    ll i=n,j=m;
    while(sz(ans)!=dp[n][m]){
        if(dp[i][j]==dp[i-1][j]) i--;
        else if(dp[i][j]==dp[i][j-1]) j--;
        else ans+=a[i-1],i--,j--;
    }
    reverse(all(ans));
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 70656
#include<stdio.h>
#define N 250

int parent(int i){
  return i/2;
}
int Left(int i){
  return 2*i;
}
int Right(int i){
  return 2*i+1;
}

int main(void){
  int i,n;
  int heap[N];
  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d",&heap[i]);
  }
  
  for(i=1;i<n+1;i++){
    if(i==1)printf("node %d: key = %d, ",i,heap[i]);
    else if(i>1)printf("node %d: key = %d, parent key = %d, ",i,heap[i],heap[parent(i)]);
    
    if(Left(i)<=n)printf("left key = %d, ",heap[Left(i)]);
    if(Right(i)<=n)printf("right key = %d, ",heap[Right(i)]);
    printf("\n");
    
  }
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  vi h(n);
  ARRIN(h, n);
  for(int i=n-1; i>0; --i){
    if(h[i]+1<h[i-1]){
      ECHO("No");
      return 0;
    }
    if(h[i]+1==h[i-1]){
      --h[i-1];
    }
  }
  ECHO("Yes");
  return 0;
}


Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    for ans in ("SS","SW","WS","WW"):
        for c in s[1:]:
            if ans[-1]=="S":
                ans+="W" if (ans[-2]=="W")^(c=="x") else "S"
            else:
                ans+="S" if (ans[-2]=="W")^(c=="x") else "W"
        if ans[0]==ans[-1] and (((ans[0]=="W")^(s[0]=="x"))^(ans[-2]==ans[1])):
            print(ans[:-1])
            sys.exit()
    print(-1)


if __name__=='__main__':
    main()

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	if (a == b)
		cnt++;
	if (b == c)
		cnt++;
	if (c == a)
		cnt++;
	cout << (cnt == 1 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (x,y,z,k) = get!(usize, usize, usize, usize);
    let mut a = get!([usize]);
    let mut b = get!([usize]);
    let mut c = get!([usize]);

    let mut e = Vec::with_capacity(x*y);
    for va in a.iter() {
        for vb in b.iter() {
            e.push(va+vb);
        }
    }
    e.sort_by(|x1,x2| x2.cmp(&x1));
    let e = e.into_iter().take(k).collect::<Vec<_>>();

    let mut res = Vec::with_capacity(e.len()*z);
    for ve in e.iter() {
        for vc in c.iter() {
            res.push(ve+vc);
        }
    }
    res.sort_by(|x1,x2| x2.cmp(&x1));
    for v in res.into_iter().take(k) {
        println!("{}", v);
    }
}


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

int main() {
  string c;
  cin >> c;
  string ans = "consonant";
  if (c == "a" or c == "e" or c == "i" or c == "o" or c == "u"){
    ans ="vowel";
  }
  cout << ans << endl;
}

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

int main() {
  string N;
  int ans=0;
  cin >> N;
  for (int i=0; i<4; i++) {
    if (N.at(i)=='2') {
      ans=ans+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
T=readline()
#println("Input: ",split(tmp))
N=parse(Int64,T)
T=readline()
A=parse.(Int128,split(T))
#println("Input: $N, $A")
#println("typeof each args... ",typeof(A))

if minimum(A) != 0
    let i = 1
        ans = 1
        while i <= N
            ans = ans * A[i]
            if ans > Int64(1e18)
                ans = -1
                break
            end
            i += 1
        end
    #    if ans < 0
    #        ans = -1
    #    end
        println(ans)
    end
else
    println(0)
end

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

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

    int now = 0;
    int ans = 0;
    while(1){
        if(now == 360){
            break;
        }

        now += n;
        ans++;
        if(now > 360){
            now -= 360;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;

int main()
{

    int X,Y;
    cin >> X >> Y;

    bool y_flag=0;
    bool x_flag = 0;

    if(Y -2*X >=0){

        if((Y - 2*X)%2==0){

            y_flag=1;
        } 
    }

    if(4*X -Y >=0){

        if((4*X - Y)%2==0){

            x_flag=1;
        } 
    }



    if(x_flag*y_flag==1){


        cout << "Yes" << endl;
    }
    else{

        cout << "No" << endl;
    }

    return 0;



}

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;
class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	
    public static void main(String args[]) throws Exception
    {
		char[] a=br.readLine().toCharArray();
		for(char ch:a)
		{
			if(ch==',')
			{
				out.print(" ");
			}
			else
			{
				out.print(ch);
			}
		}
		out.println("");out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 8020
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
int a[214514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	sort(a,a+n);
	int few=-1;
	int sum=0;
	int sum1=0;
	rep(0,i,n-1){
		if(a[i]+1==a[i+1])few=i+1;
		if(a[i]!=a[i+1]){
			sum++;
			if(a[i]+1==a[i+1]){
				sum1++;
			}
		}
	}
	if(sum>=1&&sum1!=1){
		c("No")
		return 0;
	}		
	if(few==-1){
		if(a[0]<=n/2||a[0]==n-1)c("Yes")
		else c("No")
	}
	else{
		if(a[n-1]<=(n-few)/2+few&&a[n-1]>few)c("Yes")	
		else c("No")
	}	
}	

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define one(x) cout<<#x<<" : "<<x<<endl;
#define two(x,y) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;


signed main()
{
    int  n , i ,j ;
    cin >> n;
    int a[n];
    for(i=0 ;i<n ; i++)
    {
        cin >> a[i];
    }
    int ans=0;
    for(i=0 ; i<n ; i++)
    {
        int sum=0;
        for(j=i+1 ; j<n; j++)
        {
            sum+=a[i]*a[j];
        }
        ans+=sum;
    }
    cout<<ans<<endl;


}




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

count = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long n,a[200005];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=n-1;i>=0;i-=2)cout<<a[i]<<" ";
	for(int i=n%2;i<n;i+=2)cout<<a[i]<<" ";
	cout<<endl;
}


Measured memory_bytes: 3712
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    map<ll,ll> mp,mp2;
    map<pll,ll> mp3;

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,m,k,a,b,i,j;
            cin>>n>>m>>k;
            for(i=1;i<=k;++i)
            {
                cin>>a>>b;
                ++mp3[{a,b}];
                ++mp[a];
                ++mp2[b];
            }
            ll ans=0,maxi=0,maxi2=0;
            for(auto it:mp)
            {
                maxi=max(maxi,it.s);
            }
            maxi2=0;
            for(auto it:mp2)
            {
                maxi2=max(maxi2,it.s);
            }
            vector<ll> v,v2;
            for(auto it:mp)
            {
                if(it.s==maxi)
                {
                    v.pb(it.f);
                }
            }
            for(auto it:mp2)
            {
                if(it.s==maxi2)
                {
                    v2.pb(it.f);
                }
            }
            // cout<<maxi<<" "<<maxi2<<endl;
            ans=maxi+maxi2-1;
            for(auto it:v)
            {
                for(auto it2:v2)
                {
                    // cout<<it<<" "<<it2<<endl;
                    if(mp3.find({it,it2})==mp3.end())
                    {
                        ++ans;
                        goto end;
                    }
                }
            }
            end:
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 67788
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	char C1 = toupper(s1[0]);
	char C2 = toupper(s2[0]);
	char C3 = toupper(s3[0]);

	cout << C1 << C2 << C3;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m;
int num;

int main(){
	int ans = 0;
	cin >> m >> n;
	REP(i, m){
		int cnt = 0;
		REP(j, n){
			cin >> num;
			if (num)cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

ll N;
vector<ll> E[100010];

ll solve(ll now){
  if(E[now].size() == 0) return 0;
  vector<ll> xs;
  for(ll to : E[now]){
    xs.pb(solve(to));
  }
  sort(xs.begin(), xs.end());
  reverse(xs.begin(), xs.end());
  rep(i, xs.size()){
    xs[i] += i + 1;
  }
  sort(xs.begin(), xs.end());
  return xs.back();
}

int main(){
  cin >> N;
  rep(i, N-1){
    ll a;
    cin >> a;
    a--;
    E[a].pb(i+1);
  }
  cout << solve(0) << endl;

}


Measured memory_bytes: 13568
def calc_pos(x, y, R, C):
    if y == 0:
        return x
    if y == C:
        return 2 * R + C - x
    if x == R:
        return R + y
    if x == 0:
        return 2 * R + 2 * C - y

def read_data():
    R, C, N = map(int, input().split())
    pairs = []
    xys = []
    idx = 0
    for i in range(N):
        x1, y1, x2, y2 = map(int, input().split())
        xys.append((x1, y1))
        xys.append((x2, y2))
        if (x1 != 0 and x1 != R and y1 != 0 and y1 != C) or (x2 != 0 and x2 != R and y2 != 0 and y2 != C):
            continue
        a = calc_pos(x1, y1, R, C)
        b = calc_pos(x2, y2, R, C)
        pairs.append((a, idx))
        pairs.append((b, idx))
        idx += 1
    pairs.sort()
    return pairs, xys

def is_valid(xys):
    xys.sort()
    prev_x, prev_y = xys[0]
    for x, y in xys[1:]:
        if prev_x == x and prev_y == y:
            return False
        prev_x = x
        prev_y = y
    return True

def solve(pairs, xys):
    if len(xys) == 2:
        return "YES"
    if not is_valid(xys):
        return "NO"    
    idxs = [i for a, i in pairs]
    stack = []
    for idx in idxs:
        if stack and stack[-1] == idx:
            stack.pop()
            continue
        stack.append(idx)
    if stack:
        return "NO"
    else:
        return "YES"

pairs, xys = read_data()
print(solve(pairs, xys))


Measured memory_bytes: 51464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PI acos(-1.0)
const ll MOD = 1e9+7;
const int MAX = 10000000;
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); }
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int d,t,s;
  cin >> d >> t >> s;

  if(s*t >= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3616
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
  int n,k;
  cin>>n>>k;
  vector<ll>h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  vector<ll>dp(10000000,INF);
  dp[0]=0;
  
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 79104
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		
		Scanner cin = new Scanner(System.in);
		String s = cin.nextLine();
		long cnt[] = new long[26];
		long pairs = 1;
		for(int j = 0;j<26;j++) {
			cnt[j] = 0;
		}
		for(int j = 0;j<s.length();j++) {
			cnt[s.charAt(j)-97]++;
		}
		for(int j = 1;j<26;j++) {
			for(int x = 0;x<j;x++) {
				pairs += cnt[j]*cnt[x];
			}
		}
		System.out.println(pairs);
	}
}

Measured memory_bytes: 25980
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

gcd' :: Integer -> Integer -> Integer
gcd' a 0 = a
gcd' a b = gcd' b (a `mod` b)

main = do
    [n,m]<- map (read::String->Integer) . words <$> getLine
    print $ gcd' n m



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

int main(){
    ll N;
    cin >> N;
    vector<P> V(N);
    for(auto &e : V) cin >> e.first >> e.second;
    sort(V.begin(), V.end(), [](P a, P b){ 
            ll get = a.first - b.first;
            ll lost = b.second - a.second;
            return get - lost > 0;
            });
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(i % 2 == 0) ans += V[i].first;
        else ans -= V[i].second;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int X;

    cin >> X;

    for (int i = X;; i++)
    {
        bool flg = false;

        for (int j = 2; j < i; j++)
        {
            if (i % j == 0)
            {
                flg = true;
            }
        }

        if (flg == false)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(final String[] args){

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] a = new int[n];
        for(int i=0; i<a.length; i++){
            a[i] = scanner.nextInt();
        }
        String delimiter = "";
        for(int i=a.length-1; i>=0; i--){
            System.out.print(delimiter);
            System.out.print(a[i]);
            delimiter = " ";
        }
        System.out.println();
    }
}



Measured memory_bytes: 26300
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  ll x,y,z,k;
  cin>>x>>y>>z>>k;
  vector<ll> a(x);
  REP(i,x) cin>>a[i];
  vector<ll> b(y);
  REP(i,y) cin>>b[i];
  vector<ll> c(z);
  REP(i,z) cin>>c[i];
  vector<ll> s;
  REP(i,x)REP(j,y) s.push_back(a[i] + b[j]);
  sort(ALL(s), greater<ll>());
  vector<ll> t;
  REP(i,min(3000, (int)s.size())) REP(j,z) {
    t.push_back(s[i] + c[j]);
  }
  sort(ALL(t), greater<ll>());
  REP(i,k) {
    cout << t[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 43368
a=int(input())
b=list(map(int,input().split()))
c=1
b.sort()
if 0 in b:
    print(0)
else:
    b.sort(reverse=True)
    for i in range(a):
        c*=b[i]
        if c>1000000000000000000:
            print(-1)        
            break
    else:
        print(c)

Measured memory_bytes: 21644
using System;
using System.Collections.Generic;
/*using System.Linq;
using System.Text;
using System.Threading.Tasks;*/
 class Program
{
    static void Main(string[] args)
    {
        String s = Console.ReadLine();
        String[] sarray = s.Split(' ');          //?????????????????????????´?

        int a = int.Parse(sarray[0]);
        int b = int.Parse(sarray[1]);
                                                 //a??¨b???????´?????????????
        if(a > b)
        {
            Console.WriteLine("a > b");
        }
        if (a < b)
        {
            Console.WriteLine("a < b");
        }
        if(a == b)
        {
            Console.WriteLine("a == b");
        }

    }
}

Measured memory_bytes: 8900
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int N;
  cin >> N;
  vector<vector<int>> to(N), cost(N);
  for(int i = 0; i < N - 1; i++) {
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    to[a].push_back(b); cost[a].push_back(c);
    to[b].push_back(a); cost[b].push_back(c);
  }
  vector<int> ans(N, -1);
  queue<int> q;
  ans[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int v = q.front(); q.pop();
    for(int i = 0; i < to[v].size(); i++) {
      int u = to[v][i];
      int w = cost[v][i];
      if (ans[u] != -1) continue;
      ans[u] = (ans[v] + w) % 2;
      q.push(u);
    }
  }
  for (auto a : ans) {
    cout << a << endl;
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int x;
  cin >> x;
  
  if(399 < x && x < 600) cout << 8 << endl;
  else if(x < 800) cout << 7 << endl;
  else if(x < 1000) cout << 6 << endl;
  else if(x < 1200) cout << 5 << endl;
  else if(x < 1400) cout << 4 << endl;
  else if(x < 1600) cout << 3 << endl;
  else if(x < 1800) cout << 2 << endl;
  else if(x < 2000) cout << 1 << endl;
}


Measured memory_bytes: 3632
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = list()
A.extend(A1)
A.extend(A2)
A.extend(A3)
N = int(input())
B = list()
result = list()
for _ in range(N):
    B.append(int(input()))
for e in B:
    if e in A:
        result.append(A.index(e))
loopflag = False
result.sort()
# print(result)
if N >= 3:
    for i in range(len(result)):
        for j in range(len(result)):
            for k in range(len(result)):
                if (i!=j and j!=k and k!=i):
                    if((result[i] % 3 == result[j] % 3 == result[k] % 3 ) or (result[i] // 3 == result[j] // 3 == result[k] // 3) or (result[i] == 0 and result[j] == 4 and result[k] ==8 ) or (result[i] == 2 and result[j]  == 4 and result[k] == 6 )):
                        loopflag = True
    if loopflag:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
n = int(input())
T = list(map(int, input().split()))
m = int(input())
PX = []
for i in range(m):
  PX.append(list(map(int, input().split())))
for i in range(len(PX)):
  print(sum(T)+PX[i][1]-T[PX[i][0]-1])

Measured memory_bytes: 3060
import sys


def main():
    N, K = list(map(int, input().split()))
    values = list(map(int, input().split()))
    res = sys.maxsize - 1
    for i in range(N - K + 1):
        start = values[i]
        end = values[i + K - 1]

        if start * end > 0:
            cur = (max(abs(start), abs(end)))
            res = min(res, cur)
        else:
            cur = (end - start + min(abs(start), abs(end)))
            res = min(res, cur)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=pow(2,18)+2;

int main(){
    int X,N;
    cin>>X>>N;
    int used[102];
    CLR(used);
    REP(i,N){
        int p;
        cin>>p;
        used[p]=1;
    }
    int pos1=X,pos2=X;
    while(used[pos1])pos1--;
    while(used[pos2])pos2++;
    if(abs(pos1-X)<=abs(pos2-X)){
        cout<<pos1<<endl;
    }else{
        cout<<pos2<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628