akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,dp[3333][3333],sum[3333][3333];
char s[3333];
bool f[3333];//0:< 1:>
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for (int i=0;i<n-1;i++)
	{
		if (s[i]=='<') f[i+2]=0;
		else f[i+2]=1;
	}
	dp[1][1]=1;sum[1][1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<=i;j++)
		{
			if (f[i]) dp[i][j]=sum[i-1][j-1];
			else dp[i][j]=(sum[i-1][i-1]-sum[i-1][j-1])%mod;
		}
		for (int j=1;j<=i;j++) sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
	}
	printf("%d\n",(sum[n][n]+mod)%mod);
	return 0;
} 

Measured memory_bytes: 80768
object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  val n = Scanner.nextInt()
  val s = Scanner.next().toCharArray
  val first = (1 to n-1).map(i=>{
    if (s(i)=='E'){
      1
    } else {
      0
    }
  }).sum
  var current = first
  var min = first
  (1 to n-1).foreach(i=>{
    if (s(i-1)=='W'){
      current = current + 1
    }
    if (s(i)=='E'){
      current = current -1
    }
    if (current < min){
      min = current
    }
  })
  println(min)
}

Measured memory_bytes: 35056
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << "   ";
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int N = 1e5 + 10;
int a[110];
int dp[N];
int n;


int solve(int k)
{

    if(dp[k] != 0){
        return dp[k];
    }
    if(k < a[0]){
        dp[k] = -1;
        return -1;
    }
    bool win = false;
    for(int i = 0; i < n; i++){
        if(k < a[i]) continue;
        if(solve(k-a[i]) == -1){
            win = true;
        }
    }
    dp[k] = (win ? 1 : -1);
    return dp[k];
}

int32_t SALI()
{
    int k; cin >> n >> k; for(int i = 0 ; i< n; i++) cin >> a[i];
    cout << (solve(k) == 1 ? "First" : "Second");
}


/**< WRITEN BY ALI ADELKHAH */



Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;
 
signed main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    for (int i = 1; i <= N; i++) ans = (ans * i) % mod;
    bool check = false;
    int temp = 0;
    for (int i = 0; i < 2 * N; i++) {
        if ((S[i] == 'B') == check) {
            if (temp == 0) {
                cout << 0 << endl;
                return 0;
            }
            ans = (ans * temp) % mod;
            --temp;
            check ^= 1;
        } else {
            ++temp;
            check ^= 1;
        }
    }
    if (temp) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define MOD 1000000007
#define int long long
signed main(){
  int N,M;
  cin>>N>>M;
  vector<bitset<10>> A(M);
  rep(i,0,M){
    int X;
    cin>>X;
    rep(j,0,X){
      int Y;
      cin>>Y;
      A.at(i).set(Y-1);
    }
    //cout<<A.at(i)<<endl;
  }
  bitset<10> B;
  rep(i,0,M){
    bool X;
    cin>>X;
    //cout<<X<<endl;
    if(X)
      B.set(i);
  }
  //cout<<B<<endl;
  int count=0;
  rep(i,0,(1<<N)){
    bitset<10> C(i);
    bool flag=1;
    rep(j,0,M){
      bitset<10> X=A.at(j)&C;
      int sum=X.count()%2;
      if(B.test(j)){
        if(sum==0){
          flag=0;
          break;
        }
      }
      else{
        if(sum==1){
          flag=0;
          break;
        }
      }
    }
    if(flag){count++;
             //cout<<C<<endl;
            }
  }
  cout<<count<<endl;
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	int k,s;
	cin>>k>>s;

	int cnt=0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			int z = s - i - j;
			if(0 <= z && z <= k) cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;

const int LIM = 1e6 + 5;

int main() {
	int n, min = LIM, max = -1 * LIM;
	long long sum = 0;
	cin >> n;
	while(n--) {
		int a;
		cin >> a;
		if(min > a) min = a;
		if(max < a) max = a;
		sum += a; 
	}
	cout << min << ' ' << max << ' ' << sum << '\n';
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    ll l;
    cin >> n >> l;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    int last = INF;
    REP(i,n - 1){
        if(a[i] + a[i + 1] >= l){
            last = i;
            break;
        }
    }
    if(last == INF){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for(int i = 0; i < last; i++){
        cout << i + 1 << endl;
    }
    for(int i = n - 2; i > last; i--){
        cout << i + 1 << endl;
    }
    cout << last + 1 << endl;
}

Measured memory_bytes: 1664
N = input()
N_list = []

def func(M_len, M):
  if M_len == 0:
    if len(set(list(M))) == 3:
      N_list.append(M)
  else:
    for i in ['3','5','7']:
      func(M_len-1, M + i)
      
for i in range(len(N)+1):
  func(i, '')
print(len([x for x in N_list if int(x) <= int(N)]))
  

Measured memory_bytes: 5212
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elif else if
#define unint unsigned int
#define sint short int
#define lint long long int
#define Size 1000000000

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    cout<<ceil(double(n/2.0))<<endl;
    return 0;
}


Measured memory_bytes: 256
def z():
    print("Yes")
    exit()


a = []
for i in range(3):
    b, c, d = map(int, input().split())
    a.append([b, c, d])

n = int(input())

for i in range(n):
    t = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == t:
                a[y][x] = -1
# print(a)

for i in range(3):
    if sum(a[i]) == -3:
        z()

for i in range(3):
    if a[0][i] + a[1][i] + a[2][i] == -3:
        z()

if a[0][0] + a[1][1] + a[2][2] == -3:
    z()

if a[0][2] + a[1][1] + a[2][0] == -3:
    z()
print("No")


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
rate = [0] * 9
for v in map(int, input().split()):
    if v // 400 < 8:
        rate[v // 400] = 1
    else:
        rate[8] += 1

ans = sum(rate[:8])
if ans == 0:
    print('1 {}'.format(rate[8]))
elif rate[8] == 0:
    print('{} {}'.format(ans, ans))
else:
    print('{} {}'.format(ans, ans + rate[8]))


Measured memory_bytes: 61684
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  string s, t, ans = "";
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-10;
typedef complex<double> P;
typedef pair<P,P> L;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
P crosspoint(const L &l, const L &m) {
  double A=cross(l.S-l.F,m.S-m.F);
  double B=cross(l.S-l.F,l.S-m.F);
  if(fabs(A)<EPS&&fabs(B)<EPS) return m.F;
  return m.F+B/A*(m.S-m.F);
}

vector<P> convex_cut(vector<P> ps,P p1,P p2) {
  vector<P> v;
  for(int i=0; i<ps.size(); i++) {
    P a=ps[i];
    P b=ps[(i+1)%ps.size()];
    if(ccw(p1,p2,a)!=-1) v.push_back(a);
    if(ccw(p1,p2,a)*ccw(p1,p2,b)==-1) v.push_back(crosspoint(L(p1,p2),L(a,b)));
  }
  return v;
}

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) {
      double x,y;
      cin >> x >> y;
      a[i]=P(x,y);
    }
    vector<P> v;
    v.push_back(P(0,0));
    v.push_back(P(10000,0));
    v.push_back(P(10000,10000));
    v.push_back(P(0,10000));
    for(int i=0; i<n; i++) v=convex_cut(v,a[i],a[(i+1)%n]);
    cout << (v.size()?1:0) << endl;
  }
  return 0;
}

Measured memory_bytes: 3028
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// gp_hash_table<int, int> table;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int r;
  cin >> r;

  cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    N, W = map(int, input().split())
    wv = [tuple(map(int, input().split())) for i in range(N)]

    dp = [-1]*(W+1)
    dp[0] = 0
    for w, v in wv:
        for j in range(W-w, -1, -1):
            if dp[j] >= 0 and dp[j+w] < dp[j]+v:
                dp[j+w] = dp[j] + v

    print(max(dp))


main()


Measured memory_bytes: 7736
H, W = list(map(int, input().split()))
field = [[0 for i in range(W+2)] for j in range(H+2)]

for h in range(H):
    L = input()
    for w in range(W):
        if L[w] == "#":
            field[h+1][w+1] = "#"
            for i in range(3):
                for j in range(3):
                    try:
                        field[h+i][w+j] += 1
                    except TypeError:
                        continue
for h in range(1,H+1):
    print("".join(list(map(str, field[h][1:W+1]))))
        



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int ans = 0;
  int ter = 0;
  for (int i = 0;i < n-1;i++) {
    if (s[i] == 'R' && s[i+1] == 'L') ans += 2;
  }
  if (s[0] == 'L') {
    ans++;
    ter++;
  }
  if (s[n-1] == 'R') {
    ans++;
    ter++;
  }
  int j;
  for (int i = 0;i < k;i++) {
    if (ans == ter) {
      j = i;
      break;
    }
    ans -= 2;
  }
  for (int i = j;i < k;i++) {
    if (ans <= 1) {
      ans = 1;
      break;
    }
    ans--;
  }
  ans = n - ans;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char a[55][55];
int t,h,v,x[9]={0,-1,-1,0,1,1,1,0,-1},y[9]={0,0,1,1,1,0,-1,-1,-1};
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	  scanf("%s",a[i]+1);
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=m;j++)
	    if (a[i][j]=='.')
	    {
	    	t=0;
	    	for (int k=1;k<=8;k++)
	    	{
	    		h=i+x[k];
	    		v=j+y[k];
	    		if (a[h][v]=='#') t++;
			} 
			a[i][j]=t+'0';
		}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		  printf("%c",a[i][j]);
		printf("\n"); 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M; cin >> N >> M;
  if(N == 1 && M == 1){
    cout << 1 << endl;
  }else if(N == 1){
    cout << max(0LL, M-2) << endl;
  }else if(M == 1){
    cout << max(0LL, N-2) << endl;
  }else{
    cout << (N-2)*(M-2) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef grief
#define IOS
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) =",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<'\n';}
template<typename I,typename ...T> void _DO(I&&x,T&&...tail){cerr<<x<<'\n';_DO(tail...);}
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
typedef long long ll;
typedef pair<ll,ll> pll;
const ll MAX=1e5+5;
const ll INF=4e18;
#define eb emplace_back
ll n,m,mi,ma;
vector<pll> adj[MAX];
bool arv[MAX];
ll loc[MAX];
bool can=1;
void dfs(int now){
	arv[now]=1;
	ma=max(ma,loc[now]);
	mi=min(mi,loc[now]);
	for(auto ii:adj[now]){
		ll nxt=ii.first,d=ii.second;
		if(arv[nxt]){
			if(loc[nxt]!=loc[now]+d)
				can=0;
		}
		else{
			loc[nxt]=loc[now]+d;
			dfs(nxt);
		}
	}
}
int main(){
	IOS
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int l,r;	cin>>l>>r;
		ll d;		cin>>d;
		adj[l].eb(r,d);
		adj[r].eb(l,-d);
	}
	for(int i=1;i<=n;i++){
		if(!arv[i]){
			mi=INF;
			ma=-INF;
			dfs(i);
			if(ma-mi>1000000000)	can=0;
		}
	}
	if(can)	cout<<"Yes\n";
	else	cout<<"No\n";
}

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

int main() {
  ll n, k, a;
  cin >> n >> k;
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a;
    mp[a]++;
  };

  vector<P> vec;
  for (auto x : mp) vec.emplace_back(x.second, x.first);
  sort(vec.begin(), vec.end());

  ll types = mp.size();
  ll ans = 0;
  rep(i, vec.size()) {
    if (types <= k) break;
    ans += vec[i].first;
    types--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14964
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,K;
      string S;
      cin >> N >> K;
      cin >> S;
      
      if(S.at(K-1) == 'A'){
        S.at(K-1) = 'a';
      }
      if(S.at(K-1) == 'B'){
        S.at(K-1) = 'b';
      }
      if(S.at(K-1) == 'C'){
        S.at(K-1) = 'c';
      } 
      cout << S << endl;
    }

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

using namespace std;
int main()
{
    char arr[]={'a','e','o','u','i'};
    char v;
    cin>>v;
    bool flag=false;
    for(int i=0 ;i<strlen(arr);i++)
    {
        if(arr[i]==v){cout<<"vowel";flag=true;};
    }
    if(flag==false)
        cout<<"consonant";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int c[30];
int s[400][30];
int t[400];
int main() {
	int d;
	cin >> d;
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}
	for (int i = 1; i <= d; i++) {
		int m = 0, mi = 0;
		for (int j = 1; j <= 26; j++) {
			cin >> s[i][j];
			if (m < s[i][j]) {
				m = s[i][j];
				mi = j;
			}
		}
		cout << mi << endl;
	}
	return 0;
}



Measured memory_bytes: 3656
s=input()

count=0
a_list=[]
b_list=["A", "C", "G", "T"]
num=len(s)

for i in range(num):
    if s[i] in b_list:
        count+=1
    else:
        a_list.append(count)
        count=0
a_list.append(count)

print(max(a_list))

Measured memory_bytes: 9048
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int main(void)
{

  char a, b;
  char comma;  
  int  n[3] = {0};
  int s = 10000000;
  n[0] = true;
  while(cin >> a >> comma >> b){

    int temp   = n[a - 'A'];
    n[a - 'A'] = n[b - 'A'];
    n[b - 'A'] = temp;

  }

  for(int i = 0; i < 3; i++){
    if(n[i]){
      putchar('A'+i);
      putchar('\n');
    }
  }

  return 0;
}

Measured memory_bytes: 0
N = gets.to_i
as = gets.split.map(&:to_i)
hash = {}
a2 = [0, 0]
a4 = [0]
as.each do |a|
    hash[a] ||= 0
    hash[a] += 1
    a2.push(a) if hash[a] == 2
    a4.push(a) if hash[a] == 4
end

a2.sort!
a4.sort!

puts [a2[-1] * a2[-2], a4[-1] * a4[-1]].max

Measured memory_bytes: 14980
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ss =s.substring(0,s.length()-1);
        int len = ss.length();
        
        for(int i =0;i<len;i++){
            if(ss.length()%2==0){
                String s1=ss.substring(0,(ss.length()/2));
                String s2=ss.substring(ss.length()/2,ss.length());
                if(s1.equals(s2)){
                    System.out.println(ss.length());
                    break;
                }
            }
            ss = ss.substring(0,ss.length()-1);
        }
    }
}






Measured memory_bytes: 23124
#include <algorithm>
#include <stdio.h>
#include <map>
#define MAXN 200005
using namespace std;
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	a=a>b?b:a;
	c=c>d?d:c;
	printf("%d\n",a+c);
	return 0;
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d %d", $h, $w);
$in_l = [];
for($i = 0; $i < $h; $i++) {
    $in_l[] = trim(fgets(STDIN));
}
$arr = [];
for($i = 0; $i < $h + 2; $i++) {
    for($j = 0; $j < $w + 2; $j++) {
        $arr[$i][$j] = '#';
    }
}
for($i = 0; $i < $h; $i++) {
    for($j = 0; $j < $w; $j++) {
        $arr[$i + 1][$j + 1] = $in_l[$i][$j];
    }
}
for($i = 0; $i < $h + 2; $i++) {
    for($j = 0; $j < $w + 2; $j++) {
        echo $arr[$i][$j];
    }
    echo "\n";
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int a;
    string s;
    cin>>a>>s;
    if(a<3200){
        cout<<"red"<<endl;
    }
    else{
        cout<<s<<endl;
    }
}


Measured memory_bytes: 3636
# coding: utf-8
# Your code here!
N=int(input())

P=list(map(int,input().split()))

temp=sum(P)/len(P)
temp//=1
temp2=temp+1

ans=0
for item in P:
    ans+=(item-temp)**2
    
ans2=0
for item in P:
    ans2+=(item-temp2)**2
    
print(int(min(ans,ans2)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  struct edge { int to, s; };
  vector< vector<edge> > G(n, vector<edge>());
  for (int i = 0; i < m; i++) {
    int u, v, s; cin >> u >> v >> s;
    u--; v--;
    G[u].push_back(edge{v, s});
    G[v].push_back(edge{u, s});
  }

  struct data { lint a0; int sign; };
  vector<data> a(n);
  for (auto&& i : a) {
    i.sign = 0;
  }
  queue<int> q;
  a[0].a0 = 0;
  a[0].sign = 1;
  q.push(0);
  bool fixed = false;
  lint s = 0;
  while (not q.empty()) {
    int v = q.front(); q.pop();
    for (auto&& e : G[v]) {
      if (a[e.to].sign == 0) {
        a[e.to].sign = a[v].sign * -1;
        a[e.to].a0 = e.s - a[v].a0;
        q.push(e.to);
      } else {
        if (not fixed) {
          if (a[v].sign != a[e.to].sign) {
            if (a[v].a0 + a[e.to].a0 != e.s) {
              cout << 0 << '\n';
              return 0;
            }
          } else {
            s = a[v].sign * (e.s - a[v].a0 - a[e.to].a0);
            if (s & 1) {
              cout << 0 << '\n';
              return 0;
            } else {
              s /= 2;
            }
            fixed = true;
          }
        } else {
          if (a[v].a0 + a[v].sign * s + a[e.to].a0 + a[e.to].sign * s != e.s) {
            cout << 0 << '\n';
            return 0;
          }
        }
      }
    }
  }

  if (fixed == false) {
    lint mi = 1e18, mi2 = 1e18;
    for (int i = 0; i < n; i++) {
      if (a[i].sign == 1) {
        mi2 = min(mi2, a[i].a0);
      } else {
        mi = min(mi, a[i].a0);
      }
    }
    if (mi <= 1 or mi2 + mi <= 0) {
      cout << 0 << '\n';
    } else {
      cout << mi + mi2 - 1 << '\n';
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i].a0 + a[i].sign * s <= 0) {
        cout << 0 << '\n';
        break;
      }
      if (i == n - 1) {
        cout << 1 << '\n';
      }
    }
  }
  return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;

int main() {
	int a, b; cin >> a >> b;
	int d = b - a;
	int s = 0;
	for (int i = 1; i <= d; i++) s += i;
	cout << s - b << endl;
	return 0;
}

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

int main() {
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> a(n),b(m);
  for(int i = 0; i<n;i++){
    cin >> a.at(i);
  }
  for(int i = 0; i<m;i++){
    cin >> b.at(i);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
 if(a.at(n-1) < y &&  x < b.at(0) && a.at(n-1) < b.at(0)){
   cout << "No War" << endl;
 }
  else {
    cout << "War" << endl;
  }
}



Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double das(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
inline void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }
int n;
int main(){
	int n;
	scanf("%d", &n);
	ll flag = n;
	ll a, b;
	ll sum = 0;
	ll bb=inf;
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &a, &b);
		if (a == b)
			flag--;
		sum += a;
		if (a > b)
			bb = min(bb, b);
	}
	if (flag) {
		cout << sum - bb << endl;
	}
	else 
	cout << 0 << endl;
	//system("pause");
}

Measured memory_bytes: 256
n = int(input())
s_li = [int(input()) for _ in range(n)]

s_li.sort()

s = sum(s_li)

if s%10 != 0:
    print(s)
    exit()
    
ans = 0

for i in range(n):
    temp = s - s_li[i]
    if temp%10 != 0:
        ans = max(ans, temp)
        
for i in range(n):
    for j in range(i+1,n):
        temp = s-s_li[i]-s_li[j]
        if temp%10 != 0:
            ans = max(ans,temp)
        
        
print(ans)

Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef LOCAL
    #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define debug(...) 42
    #define eprintf(...) 42
#endif

#define PI 3.1415926535897932384626433832795
#define INF 2e9
#define SINV(t) greater<t>()
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(auto i=(v).begin(); i!=(v).end(); ++i)
#define ALL(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
#define vv(t) vector<t>

#define CHC(mp, x) if(mp.end() != mp.find(x))

template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}

#pragma endregion

template<typename T>
void SV(vector<T> v){
    REP(i,v.size()){
        #ifdef LOCAL
            cout << i << " : " << v[i] << endl;
        #endif
    }
}
int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}

int main(void){
    int N, K;
    cin >> N >> K;
    vv(bool) mm(N);
    REP(i, K){
        int d;
        cin >> d;
        REP(j, d){
            int a;
            cin >> a;
            mm[a-1] = true;
        }
    }
    int cnt=0;
    REP(i, mm.size()){
        if(!mm[i])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int n,m,a[1000];

map<int,int> c;

int main() {
    while(true) {
        cin >> n >> m;
        if(n == 0)break;
        rep(i,n){
            cin >> a[i];
            c[a[i]] = 0;
        }
        rep(i,n) {
            c[a[i]]++;
        }
        sort(a,a+n);//aをソート

        int ans = -1;
        rep(i,n) {
            auto itr = upper_bound(a,a+n,m - a[i]);//m-a[i]<a[j] となる最小のjのa[j]へのポインタを取得
            if(itr - a == 0) {//m - a[i]>=a[j]を満たすjが存在しない時
                continue;
            }
            itr--;//ポインタを一つ減算してm-a[i]>=a[j]となる最大のjのa[j]へのポインタを取得
            if(*itr == a[i] && c[a[i]] < 2) {//境界のものがa[i]だった時
                if(itr - a == 0) {//a[i]未満のものがない時
                    continue;
                }
                itr--;//さらに一つ前に
            }
            ans = max(ans,*itr + a[i]);
        }
        if(ans == -1)cout << "NONE" << endl;
        else cout << ans << endl;
    }

    return 0;
}


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


int main(){
  int N,T,ans;
  cin>>N>>T;
  vector<int>t(N);
  ans = 0;
  for(int i=0;i<N;i++){
    cin>>t.at(i);
    if(i>0){
      if(t.at(i)-t.at(i-1)<T){
        ans+=t.at(i)-t.at(i-1);
      }else{
        ans+=T;
      }
    }
  }
  ans+=T;

  cout<<ans<<endl;

}


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

int main(){
  int N;
  cin >> N;
  bool t = (N % 4 ==0);
  while (N > 0){
    N -=7;
    if ((N % 4 ==0) && (N >= 0)){
      t = 1;
      break;
    }
  }
  if (t){
    cout << "Yes";
  }
    else{
      cout << "No";
    }
    
    
  }
  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
} 

Measured memory_bytes: 3628
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    a,b,c=map(int,input().split())
    ans="No"
    if a==b and b!=c:
        ans="Yes"
    elif a==c and a!=b:
        ans="Yes"
    elif b==c and a!=b:
        ans="Yes"
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
from itertools import groupby as gb 
n=int(input())
sl,vl=[list(a) for a in zip(*[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))])]
m=int(input())
slm,vlm=[list(a) for a in zip(*[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))])]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))

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

long long N, M, Q, A[1 << 17], B[1 << 17], C[1 << 17], cnt, col[1 << 17];
bool flag = false;
vector<int> X[100009];

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnt;
	for (int i = 0; i < X[pos].size(); i++) dfs(X[pos][i]);
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A[i] >> B[i] >> C[i];
		if (C[i] == 0) {
			X[A[i]].push_back(B[i]);
			X[B[i]].push_back(A[i]);
		}
		if (C[i] == 1) flag = true;
	}
	for (int i = 0; i < N; i++) {
		if (col[i] >= 1) continue;
		cnt++; dfs(i);
	}

	for (int i = 0; i < Q; i++) {
		if (col[A[i]] == col[B[i]] && C[i] == 1) {
			cout << "No" << endl;
			return 0;
		}
	}

	if (flag == true && cnt <= 2) {
		cout << "No" << endl;
	}
	else {
		long long cl = N, cr = (N - cnt) + cnt * (cnt - 1) / 2LL;
		if (flag == false) cl = N - 1;
		if (cl <= M && M <= cr) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define pp pair<int,int>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define mod 1000000007
#define int long long
int a[51][51];
int ans[51][51];
int n,k;

void fastexp(int po)
{
	if(po==1)
	{
		rep(i,0,n) rep(j,0,n) ans[i][j] = a[i][j];
		return;
	}
	fastexp(po/2);
	int temp[n][n];
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			temp[i][j] = 0;
			rep(k,0,n)
			{
				temp[i][j] += ans[i][k]*ans[k][j]%mod;
				temp[i][j] %= mod;
			}
		}
	}
	if(po%2)
	{
		int d[n][n];
		rep(i,0,n)
		{
			rep(j,0,n)
			{
				d[i][j] = 0;
				rep(k,0,n)
				d[i][j] += temp[i][k]*a[k][j]%mod,d[i][j]%=mod;
			}
		}
		rep(i,0,n)
		{
			rep(j,0,n) ans[i][j] = d[i][j];
		}
		return ;
	}
	else
	{
		rep(i,0,n) rep(j,0,n) ans[i][j] = temp[i][j];
		return ;
	}


}
 main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt.txt","r",stdin);
	// freopen("output.txt.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n>>k;
	rep(i,0,n) rep(j,0,n) cin>>a[i][j];

	int res = 0;
	fastexp(k);
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			res+= ans[i][j];
			
			res%=mod;

		}
		
	}
	cout<<res<<endl;


}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) cout<<#v<<": ";for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve(long long A, long long B){
    if(A<10 & B<10){
        cout << A*B << "\n";
    }else{
        cout << -1 << "\n";
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll ans;
    rep(i, 5) {
        ll num;
        cin >> num;
        if (num == 0) {
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define MAX_N 16
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0;i < (n);i++)
#define show(x) cout<<(#x)<<":"<<x<<" ";
#define showl(x) cout<<(#x)<<":"<<x<<endl;

using namespace std;
typedef long long ll;

template<typename T>
struct ConvexHullTrick{
private:
    vector<pair<T,T> > lines;
public:
    T calc(pair<T,T> p,T x){
        return p.first*x+p.second;
    }
    
    bool dodo(pair<T,T> A,pair<T,T> B,pair<T,T> C){
        bool ret = (C.second-B.second)*(A.first-C.first)<=(C.second-A.second)*(B.first-C.first);

      return ret;
    }
    
    void add(T a,T b){
        lines.pb(mp(a,b));
        int v;
        while((v=lines.size())>=3&&dodo(lines[v-3],lines[v-2],lines[v-1])){
            lines[v-2]=lines[v-1];
            lines.pop_back();
        }
    }
    
    T query(T x){
        int l = 0, r = lines.size();
        while(r-l>1){
            int mid = (l+r)/2;
            if(calc(lines[mid-1],x)>=calc(lines[mid],x))
                l=mid;
            else
                r=mid;
        }
        return calc(lines[l],x);
    }
};

int main(){
    int N;
    ConvexHullTrick<ll> ch;
    ll C;
    cin>>N>>C;
    vector<ll> dp(N,0),h(N);
    rep(i,N){
        cin>>h[i];
    }
    ll val = 0;
    for(int i = 0;i < N;i++){
//        show(i);
        if(i>0){val = ch.query(h[i])+h[i]*h[i];}
//        showl(val);
        ch.add(-2*h[i],val+h[i]*h[i]+C);
    }
    cout<<val<<endl;
}


Measured memory_bytes: 9328
N = int(input())
X = [int(i) for i in input().split()]

X_sort = sorted([[i,v] for i,v in enumerate(X)], reverse=True, key=lambda x: x[1
])
ans = [0] * N
ansA = X_sort[(N//2)-1][1]
ansB = X_sort[N//2][1]
for i in range(N):
    if i<(N//2):
        ans[X_sort[i][0]] = ansB
    else:
        ans[X_sort[i][0]] = ansA
        
for a in ans:
    print(a)


Measured memory_bytes: 45372
S = input()

cnt = 1
for i in S:
    if cnt%2 == 0:
        if i == "L" or i == "U" or i == "D":
            pass
        else:
            print("No")
            exit()
    else:
        if i == "R" or i == "U" or i == "D":
            pass
        else:
            print("No")
            exit()
    cnt += 1

print("Yes")


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
numcnt = [0] * (pow(10, 5) + 1)
for i in a:
    numcnt[i] += 1
s = sum(a)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s = s + (c - b) * numcnt[b]
    print(s)
    numcnt[c] += numcnt[b]
    numcnt[b] = 0

Measured memory_bytes: 20880
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defun displace (vec &optional (start 0) end)
  "displaced subseq"
  (let ((end (or end (length vec))))
    (make-array (- end start)
                :element-type (array-element-type vec)
                :displaced-to vec
                :displaced-index-offset start)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(declaim (inline extract))
(defun extract (mask s)
  (let* ((len (length s))
         (res (make-string (+ len len) :element-type 'base-char :initial-element #\Nul)))
    (loop with red-i = 0
          with blue-i = len
          for pos below len
          do (if (logbitp pos mask)
                 (progn (setf (aref res red-i) (aref s pos))
                        (incf red-i))
                 (progn (setf (aref res  blue-i) (aref s pos))
                        (incf blue-i))))
    res))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (s (read-line))
         (s1 (coerce (reverse (displace s 0 n)) 'simple-base-string))
         (s2 (coerce (displace s n (+ n n)) 'simple-base-string))
         (table (make-hash-table :test #'equal :size #.(expt 2 18))))
    (declare ((integer 1 18) n))
    (dotimes (mask (expt 2 n))
      (let ((key (extract mask s1)))
        (multiple-value-bind (value presentp) (gethash key table)
          (if presentp
              (setf (gethash key table) (1+ (the uint32 value)))
              (setf (gethash key table) 1)))))
    (let ((res 0))
      (declare (fixnum res))
      (dotimes (mask (expt 2 n))
        (let* ((key (extract mask s2))
               (value (gethash key table)))
          (when value
            (incf res (the uint32 value)))))
      (println res))))

#-swank(main)


Measured memory_bytes: 74216
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)

Measured memory_bytes: 7924
package main

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

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanNAndIntSlice(s *bufio.Scanner) (int, []int) {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n, scanIntSlice(s, n)
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}

func min(l ...int) int {
	r := l[0]
	for _, n := range l {
		if n < r {
			r = n
		}
	}
	return r
}

func main() {
	s := wordScanner(100)
	n, b := scanNAndIntSlice(s)
	b = b[:len(b)-1]

	a := b[0]
	for i := 1; i < n-1; i++ {
		a += min(b[i-1], b[i])
	}
	a += b[len(b)-1]

	fmt.Println(a)
}


Measured memory_bytes: 640
import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        init(System.in);
        int n = nextInt();
        long[] prefixSum = new long[n];
        HashMap<Long, Integer> occur = new HashMap<>();
        prefixSum[0] = (long) nextInt();
        occur.put(prefixSum[0], 1);
        for (int i = 1; i < prefixSum.length; i++) {
            prefixSum[i] = (long) nextInt();
            prefixSum[i] += prefixSum[i - 1];
            if (occur.containsKey(prefixSum[i])) occur.put(prefixSum[i], occur.get(prefixSum[i]) + 1);
            else occur.put(prefixSum[i], 1);
        }
        long ans = 0;
        if (occur.containsKey(0L)) ans += occur.get(0L);
        for (long val : prefixSum) {
            if (occur.get(val) > 0) occur.put(val, occur.get(val) - 1);
            ans += occur.get(val);
        }
        System.out.println(ans);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}



Measured memory_bytes: 77952
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

int main() {
  string S;
    ll K;
    
    cin >> S>>K;
  
  ll renzoku = 0, r = 0;
  char prev = 0;
  ll fs = -1, ed;
  
  for (auto i : S) {
    if (prev == i)
      renzoku++;
    else {
      r += (renzoku+1LL) / 2LL;
      if (fs == -1 && prev != 0)
        fs = renzoku+1LL;
      renzoku = 0;
    }
    prev = i;
  }
      r += (renzoku+1LL) / 2LL;
      if (fs == -1) {
        cout << (renzoku+1LL) * K / 2 << endl;
        return 0;
      }

  ed = renzoku+1LL;

    
  ll res = r * K;
  if (K > 1 && S.front() == S.back()) {
    if (fs % 2 && ed % 2)
      res += K - 1LL;
  }
    cout << res << endl;
    
    return 0;
}




Measured memory_bytes: 256