akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int N;string s,t;
bool d[size];// hituji:0 ookami:1
map<bool,string> trans;
bool judge(bool a,bool b){
	bool r[N];r[0]=a;r[1]=b;
	t=trans[a]+trans[b];
	rep(i,2,N+2){
		r[i%N]=r[(i-2)%N]^r[(i-1)%N]^d[(i-1)%N];
        if(i>=N) continue;
		t+=trans[r[i%N]];
	}
	if(r[0]==a&&r[1]==b) return 1;
	else return 0;
}
int main(){
	cin>>N>>s;
	rep(i,0,N) d[i]=(s[i]=='x');
	trans[0]="S";trans[1]="W";
	rep(i,0,2)rep(j,0,2){
		if(judge(i,j)){
			cout<<t<<endl;
			return 0;
		}
	}cout<<-1<<endl;
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<int> L(N);
  for(int i = 0;i < N;i++) {
    cin >> L.at(i);
  }

  int ans = 0;
  sort(L.begin(),L.end());
  for(int i = 0;i < N-1;i++) {
    for(int j = i+1;j < N;j++) {
      ans += lower_bound(L.begin()+j+1,L.end(),L.at(i)+L.at(j)) - (L.begin()+j) - 1;
    }
  }

  cout << ans << endl;
  
}




Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    string s;
    cin >> s;
    bool odd = true;
    bool easy = true;
    for (const auto &c : s) {
        if (odd) {
            if (c == 'L') {
                easy = false;
                break;
            }
          } else {
            if (c == 'R') {
                easy = false;
                break;
            }
        }
        odd = !odd;
    }
    if (easy) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <map>
#include <string>
#include <set>

using namespace std;

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

  map<string,int> X;
  
  for (int n=0; n<N; ++n) {
    string S;
    cin >> S;

    auto itr = X.find(S);
    if (itr == X.end())
      X.emplace(S,1);
    else
      itr->second += 1;
  }

  int maxCount = 0;
  for (auto x : X)
    maxCount = max(x.second, maxCount);

  set<string> ans;
  for (auto x : X) {
    if (x.second == maxCount)
      ans.insert(x.first);
  }

  for (auto s : ans)
    cout << s << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

int main() {
  int N;
  cin >> N;
  string c;
  cin >> c;
  int i = 0;
  int j = N - 1;
  ll ans = 0;
  while (i < j) {
    if (c[i] == 'W' && c[j] == 'R') {
      swap(c[i], c[j]);
      ans++;
    }
    if (c[i] == 'R') {
      i++;
    }
    if (c[j] == 'W') {
      j--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3748
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in L:
    for j in L:
        for k in L:
            if i < j < k:
                if i + j + k > max(i,j,k) * 2:
                    ans += 1
else:
    print(ans)

Measured memory_bytes: 9116
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;

    if(a==b && b==c){
        cout<<1<<endl;
    }
    else if(a!=b && b!=c && a!=c){
        cout<<3<<endl;
    }
     else
     {
         cout<<2<<endl;
     }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int tousuu = 0;
        int honsuu = 0;

        tousuu = scanner.nextInt();
        honsuu = scanner.nextInt();

        int turuasi = 2;
        int kameasi = 4;

        int kame = (honsuu - turuasi * tousuu) / (kameasi - turuasi);
//        System.out.println(kame);
        int turu = tousuu - kame;
//        System.out.println(turu);
//                System.out.println((turuasi +" " +turu + " " +kameasi +" " + kame));
//                System.out.println((turuasi * turu + kameasi * kame));
        if (turu >= 0 && kame >= 0) {
            if ((turuasi * turu + kameasi * kame) == honsuu) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35760
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define Temp template<typename T>
using namespace std;
typedef long long LL;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

const int maxn=100000+10;
int n;
int t,x,y,px,py,pt;

inline int _abs(int x){
	if(x<0)return -x;
	return x;
} 

inline int dis(int x,int y){
	return _abs(x-px)+_abs(y-py);
}

int main(){
	read(n);
	for(Rint i=1;i<=n;i++){
		read(t);read(x);read(y);
		int k=t-(dis(x,y)+pt);
		if(k<0||(k&1==1)){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define maxim INT_MAX
#define fi first
#define se second
#define INF 1e16
/* 1. If you can't keep solution in mind, then visualize it on a paper.
 * 2. Try to identify the type of problem - DP, Greedy, Graph, Constructive,
 * 	  Prefix/Suffix, Difference Array, BIT/Segment Tree, etc.
 * 3. Look at the problems from different perspectives - reverse the problem,
 * 	  add instead of delete (maybe?)
 * 4. Divide difficult solutions into cases and/or sequences.
 * 5. Use math rules to solve Nested Summation.
 * 6. Optimisation problems are generally solved with DP, greedy, binary search or brute-force.
 * 7. Try fixing a solution then proving we can't do better or worse than that.
 * ------------------------------------------------------------------
 */
vector <ll> adj[100005];
ll dis[100005];
ll ans=0;
 void dfs(ll node)
{
    for(auto child:adj[node])
    {
        if(dis[child]==0)
            dfs(child);
        dis[node]=max(dis[node],1+dis[child]);
    }
}
int main()
{
    ll n,m;
    cin>>n>>m;
    vector <ll> indeg(n+1,0);

    for(ll i=1;i<=m;i++)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
        indeg[v]++;
    }
    vector <ll> vertices;
    for(ll i=1;i<=n;i++)
    {
        if(indeg[i]==0)
            vertices.pb(i);
    }
    memset(dis,0,sizeof(dis));
    for(auto vertex:vertices)
    {
        dis[vertex]=0;
        dfs(vertex);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans=max(ans,dis[i]);
    cout<<ans<<endl;



}


Measured memory_bytes: 14728
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define nl "\n"

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

	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(2 * a - 1, 2 * b - 1));
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,a,b;
	
	cin>>n;
	
	if(n==1){
		cout<<"Hello World"<<endl;
	}
	
	if(n==2){
		cin>>a>>b;
		
		cout<<a+b<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define f first
#define s second
#define inp(a) cin >> a
#define out(a) cout<<a<<endl
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
ll power(ll x,ll y); 
int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
	    {
	    	ll n,k;
	    	cin >> n>>k;
	    	ll rem = n/k;
	    	n = n - rem*k;
	    	ll ans = min(n,abs(n-k));
	    	cout <<ans<<endl;

	    }

}
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

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

int main(){
int a,b,k;
cin >> a >> b >> k;
vector<int> n(100);
int cur = 0;
for (int i = 1;i < 101;i++){
  if (a % i == 0 and b % i == 0){
    n[cur] = i;
    cur += 1;
  }
}
cout << n[cur-k] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string ss = s.Substring(1,s.Length-2);
            Console.WriteLine(s[0]+""+ss.Length+""+s[s.Length-1]);
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

void solve(long long N, long long K, std::vector<long long> p){
    sort(ALL(p));
    ll ans = 0;
    REP(i, K) ans += p[i];
    cout<<ans<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
 
using namespace std;
 
//const int MOD=1e9+7;
 
const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<pair<double,double>> vp(n);
    for(auto &p:vp){
        double x,y;
        cin>>x>>y;
        p={x,y};
    }
    double tot=0;
    vector<int> perm(n);
    for(int i=0; i<n; i++){
        perm[i]=i;
    }
    double nfact=1;
    for(int i=1; i<=n; i++){
        nfact*=i;
    }
    auto sq=[](auto x1){return x1*x1;};
    do{
        //double stot=0;
        for(int i=1; i<n; i++){
            tot+=sqrt(sq(vp[perm[i]].first-vp[perm[i-1]].first)+sq(vp[perm[i]].second-vp[perm[i-1]].second));
            //vp[i].first-vp[i-1].first*(vp[i].first-vp[i-1].first) 
        }
        //cout<<stot<<'\n';
        
    }while(next_permutation(perm.begin(),perm.end()));
    cout<<setprecision(12)<<tot/nfact;
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll M, K;
  cin>>M>>K;
  ll ans = 0;
  for(ll i=0;i<(1<<M);++i) {
    if(i==K) continue;
    ans ^= i;
  }
  if(K==0) {
    for(ll i=0;i<(1<<M);++i) {
      cout<<i<<" "<<i<<" ";
    }
    cout<<endl;
    return 0;
  }
  if(ans!=K) {
    cout<<-1<<endl;
    return 0;
  }
  cout<<0<<" "<<K<<" "<<0<<" ";
  for(ll i=1;i<(1<<M);++i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<K<<" ";
  for(ll i=(1<<M)-1;i>=1;--i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 3624
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-12-01 20:49:34
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;

  auto possible = [&](int x1, int x2, int x3) -> bool {
    char c1 = x1 + 48;
    char c2 = x2 + 48;
    char c3 = x3 + 48;

    int pos = 0;
    bool f1 = false, f2 = false, f3 = false;
    for (int i = 0; i < n; ++i) {
      if (!f1 && s[i] == c1) {
        f1 = true;
      } else if (f1 && !f2 && s[i] == c2) {
        f2 = true;
      } else if (f1 && f2 && s[i] == c3) {
        f3 = true;
      }
    }
    return f1 && f2 && f3;
  };

  int ans = 0;

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int k = 0; k < 10; ++k) {
        if (possible(i, j, k)) {
          //cerr << i << " " << j << " " << k << '\n';
          ++ans;
        }
      }
    }
  }

  //cerr << (int)'1' << endl;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((ll)301*1000)
#define MOD ((ll)1e9+7)

ll n,a[N],b[N];

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	ll add=0;
	for(int i=n-1;i>=0;i--)
	{
		ll ex=(add+a[i])%b[i];
		if(ex)ex=b[i]-ex;
		add+=ex;
	}
	cout<<add;
	return 0;
}

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


int main(){
    ll a, b;
    cin >> a >> b;
    if (a * b <= 0) cout << "Zero" << endl;
    else if (a < 0 || b < 0){
        if ((b - a + 1) % 2 != 0) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    else cout << "Positive" << endl;
}

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

typedef long long ll;

ll enemy_attack(ll H){
  if (H==1) return 1;
  else{
    ll N=floor(H/2);
    return 2*enemy_attack(H/2)+1;
  }
}

int main(){
  ll H;
  cin >> H;
  ll ans=enemy_attack(H);
  cout << ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  if(n<m) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i = n-m; i >= 0; i--) {
    string u = s;
    bool ok = true;
    rep(j,m) {
      if(u[i+j]=='?') u[i+j] = t[j];
      else {
        if(u[i+j]==t[j]) continue;
        else ok = false;
      }
    }
    if(ok) {
      rep(i,n) if(u[i]=='?') u[i] = 'a';
      cout << u << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
  
    if(a==b){
        if(b==c){
            printf("1\n");
        }else{
            printf("2\n");
        }
    }else{
        if(a==c||b==c){
            printf("2\n");
        }else{
            printf("3\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1612
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
ans = 0
for m in get_divisor(N):
    m-=1
    if m==0 : continue
    if N//m == N%m: ans+=m
print(ans)

Measured memory_bytes: 3424
object Main extends App {
  val Array(n, l) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var min = 9999
  var apple = List[Int]()
  (1 to n).foreach { i =>
    val now = l + i - 1
    apple = apple :+ now
    if (Math.abs(min) > Math.abs(now)) {
      min = now
    }
  }

  println(apple.sum - min)
}


Measured memory_bytes: 27464
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline

def solve(a,b,c,d):
    anss = [a*c,a*d,b*c,b*d]
    print(max(anss))

            

def main():
    a,b,c,d = map(int,input().split())
    solve(a,b,c,d)


if __name__ == "__main__":
    main()

Measured memory_bytes: 65024
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

// const int N = 1e3+1;
// lli dp[N][N];

bool isValid(int i, int j, int h, int w, vector<vector<char>>& grid) {
	if(i<0 || j<0 || i>=h || j>=w || grid[i][j]=='#') return false;
	return true;
}

// lli numbersOfPath(int i, int j, int h, int w, vector<vector<char>>& grid) {
// 	if(dp[i][j] != -1) return dp[i][j];
// 	lli ans = 0;
// 	if(isValid(i-1, j, h, w, grid)) ans += numbersOfPath(i-1, j, h, w, grid);
// 	ans %= mod;
// 	if(isValid(i, j-1, h, w, grid)) ans += numbersOfPath(i, j-1, h, w, grid);
// 	ans %= mod;
// 	return dp[i][j] = ans;
// }

lli solve(int h, int w, vector<vector<char>>& grid) {
	lli new_dp[h][w];
	mem(new_dp, 0);
	new_dp[0][0] = 1;
	fo(i, h) fo(j, w) {
		if(isValid(i-1, j, h, w, grid)) new_dp[i][j] += new_dp[i-1][j];
		new_dp[i][j] %= mod;
		if(isValid(i, j-1, h, w, grid)) new_dp[i][j] += new_dp[i][j-1];
		new_dp[i][j] %= mod;
	}
	return new_dp[h-1][w-1];
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int h, w;
	cin >> h >> w;

	vector<vector<char>> grid(h, vector<char>(w));
	fo(i, h) fo(j, w) cin >> grid[i][j];

	// mem(dp, -1);
	// dp[0][0] = 1;

	// lli ans = numbersOfPath(h-1, w-1, h, w, grid);
	lli ans = solve(h, w, grid);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9088
s=input()
s1=s[::-1]
a,b=0,0
ca,cb=0,0
while a<len(s) and b<len(s):
    if s[a]==s1[b]:
        a+=1
        b+=1
    else:
        if s[a]=='x':
            ca+=1
            a+=1
        elif s1[b]=='x':
            cb+=1
            b+=1
        else:
            ca,cb=-1,-1
            break
print(max(ca,cb))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	r1--;
	ll cnt1,cnt2;
    COMinit();

    // 計算例
    //cout << COM(100000, 50000) << endl;	
	cnt1=cnt2=0;
	for(ll i=c1;i<=c2;i++){
		cnt1+=COM(r1+i+1,r1);
		cnt1%=inf;
	}
	for(ll i=c1;i<=c2;i++){
		cnt2+=COM(r2+i+1,r2);
		cnt2%=inf;
	}	
	ll ans=cnt2-cnt1;
	if(ans<0){
		ans+=inf;
	}
	//cout << cnt1<<endl;
	//cout <<cnt2<<endl;
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 123096
import numpy as np

N, D = map(int, input().split())
X = [np.array(list(map(int, input().split()))) for i in range(N)]
ans = 0

for i in range(N-1):
    x = (X[i] - X[i+1:]) ** 2
    total = np.sum(x, axis=1) ** 0.5

    for t in total:
        if t.is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 12500
#include<bits/stdc++.h>
const int N=9e4+5,mo=998244353;
int n,a[305],i,j,f[N],s,ans;
int main(){
	scanf("%d",&n);*f=ans=1;
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<=n;++i){
		s+=a[i];ans=3ll*ans%mo;
		for(j=s;j>=a[i];--j)f[j]=(2ll*f[j]+f[j-a[i]])%mo;
		for(;j>=0;--j)f[j]=f[j]*2%mo;
	}
	j=0;
	for(i=s;i>=s-i;--i)j=(j+f[i])%mo;
	ans=(ans+mo-3ll*j%mo)%mo;
	if(!(s&1)){
		memset(f,0,sizeof f);*f=1;
		for(i=1,s=0;i<=n;++i){
			s+=a[i];
			for(j=s;j>=a[i];--j)f[j]=(f[j]+f[j-a[i]])%mo;
		}
		ans=(ans+3ll*f[s>>1])%mo;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    int n,a,x; cin >> n >> x;
    ll ans=1,rep=0;
    for (int i=0;i<n;i++)
    {
        cin >> a;
        rep+=a;
        if (rep<=x) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    a = numinput()
    if a[0] < a[1] and a[1] < a[2]: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()



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

int main() {
	string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u){
    	a = a - 1;
    }else{
        b = b - 1;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3520
n = int(input())
a = list(map(int, input().split()))
b = []; c = 0
while len(a) > 0:
    for j in range(len(a)):
        if a[-j-1] == len(a)-j: b.append(a.pop(-j-1)); break
    else: c = 1; break
else:
    b.reverse()
    for i in range(n):
        if b[i] > i+1: c = 1
print(-1) if c == 1 else print(*b, sep="\n")

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

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

int main(){
    long n, sum=0;
    cin >> n;
    for(long i=1; i<n+1; i++){
        for(long j=1; j<n+1; j++){
            for(long k=1; k<n+1; k++){
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
max_num = 0
for i, v in c.items():
    max_num = max(max_num, v)

ret_list = []
for i, v in c.items():
    if v == max_num:
        ret_list.append(i)
ret_list.sort()
for i in ret_list:
    print(i)


Measured memory_bytes: 101072
//write：Sakura
//id：
//problem：
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

char s[10005];
int len=0;
int w;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s",s+1);
	len=strlen(s+1);
	scanf("%d",&w);
	for(int i=1;i<=len;i+=w){
		cout<<s[i];
	}cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

 string s;
 int l;
 cin >> s;
	
	l=s.length();
	string f="";
 while(l-->0)
	{
		f=f+"x";
	}
	
	cout << f << endl;

	return 0;
}











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

int N = 0;
std::vector<int> T;
int M = 0;

int main(void){
    int i, sum = 0;
    std::cin >> N;
    T.resize(N);
    for(i=0; i<N; ++i){
        std::cin >> T[i];
        sum += T[i];
    }
    std::cin >> M;

    int P = 0, X = 0;
    for(i=0; i<M; ++i){
        std::cin >> P >> X;
        std::cout << (sum-T[P-1]) + X << std::endl;
    }
}


Measured memory_bytes: 256
import math
import itertools

# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


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


answer = 0
routes = [c for c in itertools.permutations(range(0, n), n) if c[0] == 0]
for route in routes:
    seen = set()

    is_one_stroke = True
    for index in range(len(route) - 1):
        node = route[index]

        seen.add(node)
        next_node = route[index+1]
        if not graph[node] or next_node not in graph[node] or next_node in seen:
            is_one_stroke = False
            break

    if is_one_stroke:
        answer += 1

print(answer)

Measured memory_bytes: 74708
#include <stdio.h>

int main(){
  long long int N,A,B;
  long long int ans=0LL;
  scanf("%lld %lld %lld",&N,&A,&B);
  if(A>B){
    A^=B;
    B^=A;
    A^=B;
  }
  if((B-A)%2LL!=0){
    if(A-1<=N-B){
      ans=A;
      B=B-A;
      A=1;
    }else{
      ans=N-B+1;
      A=A+ans;
      B=N;
    }
  }
  ans+=(B-A)/2LL;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1736
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double ans = ((double)N/2);
		System.out.println((int)Math.ceil(ans));
	}
}

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

using lli = long long int;

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

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

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

int main(void){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int main()
{
    IOS; 
    int n;
    cin>>n;
    double p[n+1];
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    double ans=0;
    double dp[n+1][n+1]={{0}};
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0){
                dp[i][j]=dp[i-1][j]*(1-p[i]);;
            }
            else{
                dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
            }
        }
    }
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 70528
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
    if (i%2==0):
        v1.append(v[i])
    else:
        v2.append(v[i])
w1 = collections.Counter(v1)
w2 = collections.Counter(v2)
w1 = w1.most_common()
w2 = w2.most_common()

if (w1[0][0] != w2[0][0]):
    print(n-w1[0][1]-w2[0][1])
    exit()
else:
    if len(w1) ==1:
        if len(w2) ==1:
            print(n//2)
        else:
            print(n-w1[0][1]-w2[1][1])
    else:
        if len(w2) ==1:
            print(n-w2[0][1]-w1[1][1])
        else:
            if (w1[0][1]-w1[1][1]) >= (w2[0][1]-w2[1][1]):
                print(n-w1[0][1]-w2[1][1])
            else:
                print(n-w2[0][1]-w1[1][1])
            

Measured memory_bytes: 20700
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<cmath>
#define ll long long
#define INF 1000000000
#define clr(x) memset(x,0,sizeof(x))
using namespace std;

inline int read()
{
	register int ret=0,c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))ret=ret*10+c-'0',c=getchar();
	return ret;
}

ll a,b,c,d,n,l,r;

int main()
{
	n=read(),a=read(),b=read(),c=read(),d=read();
	b=abs(b-a);
	r=(n-1)*d;
	l=(n-1)*c;
	for(int i=1;i<=n-1;i++)
	{
		if(b<=r&&b>=l)return puts("YES"),0;
		r-=d+c;
		l-=d+c;
	}
	return puts("NO"),0;
}

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

vector<int> G[102];
int d[102];
int f[102];
bool used[102];


int dfs(int i, int t){
    d[i] = t++;
    used[i] = true;
    for(vector<int>::iterator it = G[i].begin(); it != G[i].end(); ++it){
        if(!used[*it]){
            t = dfs(*it, t);
        }
    }
    
    f[i] = t++;
    return t;
}

int main()
{
    int n,u,k,v;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
            cin >> v;
            G[u].push_back(v);
        }
    }
    int t = 1;
    for(int i = 1; i <= n; ++i){
        if(!used[i]){
            t = dfs(i,t);
        }
    }
    
    for(int i = 1; i <= n; ++i){
        cout << i << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

Measured memory_bytes: 1216
<?php

$hw = explode(' ', trim(fgets(STDIN)));
$h = $hw[0];
$w = $hw[1];

$n=[];
for($i=0; $i<$h; $i++){
  $s = trim(fgets(STDIN));
  for($j=0; $j<$w; $j++){
    $n[$i][$j] = $s[$j];
  }
}

for($j=0; $j<$w; $j++){
  $l = [];
  for($i=0; $i<$h; $i++){
    array_push($l,$n[$i][$j]);
  }
  if (!in_array('#',$l)){
    for($k=0; $k<$h; $k++){
    	unset($n[$k][$j]);
  	}	
  }
}

for($i=0; $i<$h; $i++){
  $n[$i] = array_values($n[$i]);
}

for($i=0; $i<$h; $i++){
  if (!in_array('#',$n[$i])) unset($n[$i]);
}

$n = array_values($n);

for($i=0; $i<count($n); $i++){
  if ($i !== 0) echo "\n";
  for($j=0; $j<count($n[$i]); $j++){
    echo $n[$i][$j];
  }
}
?>

Measured memory_bytes: 4728
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	int n;
	cin >> n;
	int cnt[100001] = {};
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	int ans = cnt[0] + cnt[1];
	for(int i = 1; i < 100000; i++){
		ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	ans = max(ans, cnt[99999] + cnt[100000]);
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n, m;

    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];

    cin >> m;
    int b[m];
    for(int i = 0; i < m; i++)  cin >> b[i];

    int res = -1;
    for(int i = 0; i < min(n, m); i++){
        if(a[i] == b[i])    continue;

        if(a[i] > b[i]) res = 0;
        if(a[i] < b[i]) res = 1;

        break;
    }

    if(res == -1)   res = m>n;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3128
n = int(input())
siritolist = []

flag = 1
for i in range(n):
    oi = str(input())
    if oi in siritolist:
        flag = 0
        
    else:
        if len(siritolist) == 0:
            siritolist.append(oi)
        else:
            if list(siritolist[-1])[-1] == list(oi)[0]:
                siritolist.append(oi)
            else:
                flag = 0

if flag == 1:
    print('Yes')
else:
    print('No')
                

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

using namespace std;

#define INF ((int)2e18)
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
#define double long double
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

vector<string> ans;
void gen(string s, char lim, int n) {

  if (s.size() == n) {
    ans.eb(s);
    return;
  }

  for (char c = 'a'; c <= lim; c++) {
    gen(s + c, max(char(c + 1), lim), n);
  }
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;

  cin >> n;

  gen("", 'a', n);

  for (string &s : ans)
    cout << s << endl;
}

Measured memory_bytes: 7796
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def ceil(a, b):
    if a%b == 0:
        return a//b
    return a//b+1

def solve() -> Any:
    N, H = read_ints()
    A = 0
    answer = 0
    B = []
    for _ in range(N):
        a, b = read_ints()
        A = max(A, a)
        B.append(b)
    B.sort()
    while B and B[-1] > A:
        H -= B.pop()
        answer += 1
        if H <= 0:
            return answer
    return answer+ceil(H, A)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 83716
#!/usr/bin/env python3

N,K,Q = [int(i) for i in input().split()]
A = [0]*(Q+1)
P = [K-Q]*(N+1)
for i in range(1,Q+1):
    A[i] = int(input())
    P[A[i]] += 1

for p in P[1:]:
    if p <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 16376
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    int N;
    int T, A;

    vector<int> H;

    cin >> N;
    cin >> T >> A;
    for (int i = 0; i < N; ++i) {
        int h;
        cin >> h;
        H.push_back(h);
    }

    vector<float> G;
    for (int i = 0; i < N; ++i) {
        float g = T - H[i] * 0.006;
        G.push_back(g);
    }

    float x = 10000;
    int z = -1;
    for (int i = 0; i < N; ++i) {
        float r = abs((float)A  - G[i]);

        if(r < x){
            z = i + 1;
            x = r;
        }
    }

    cout << z << endl;
    return 0;

}

Measured memory_bytes: 256
(N, X) = list(map(int, input().split()))

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

a = 0
cnt = 0
for n in range(N):
    if a <= X:
       cnt = cnt + 1 

    a = a + L[n]

if a <= X:
    cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Arrays;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    int sum = 0;
    int[] list = {0,0,0};
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int j2 = 1; j2 <= k; j2++) {
          list[0] = i;list[1] = j;list[2] = j2;
          Arrays.sort(list);
          sum += gcd(list);
        }
      }
    }

    System.out.println(sum);
  }

  public static int gcd(int[] list) {
    if (list[1]%list[0] == 0 && list[2]%list[0] == 0) {
      return list[0];
    } else {
      for (int i = list[0]/2; i > 0; i--) {
        if (list[0]%i != 0) continue;
        if (list[1]%i == 0 && list[2]%i == 0) {
          return i;
        }
      }
      return 1;
    }
  }
}

Measured memory_bytes: 37116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int r = accumulate(a.begin(), a.end(), 0, [](int m, int n) {
    return gcd(m, n);
  });

  cout << r << endl;

  return 0;
}

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

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

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

  sort(A.begin(), A.end());

  int x = 0, y = 0;
  int same = 0;

  for (int i = A.size() - 1; i > 0; i--) {
    if (A[i - 1] == A[i]) {
      if (x == 0) {
        x = A[i];
        same = 2;
      }
      else {
        if (same == 0) {
          y = A[i];
          break;
        }
        if (same == 2) {
          same = 3;
        }
        else if (same == 3) {
          y = A[i];
          break;
        }
      }
    }
    else {
      same = 0;
    }
  }

  cout << (long)x * y << endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python
# coding: utf-8

from collections import Counter

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lx, ly = [], []
    for _ in range(n):
        x, y = rli()
        lx.append(x)
        ly.append(y)
    dd = {}
    dc = Counter()
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            d = (lx[i]-lx[j], ly[i]-ly[j])
            dd[(i, j)] = d
            dc[d] += 1
    if len(dc) == 0:
        print(n)
    else:
        v = dc.most_common()[0][1]
        print(n-v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}

int modinv(int a){ return power(a,mod-2);}

void solve()
{
	int n,m;
	cin>>n>>m;
	if(n<=m)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 3652
n = int(input())

adj_list = [[] for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj_list[a].append(b)
    adj_list[b].append(a)

c = list(map(int, input().split()))
c.sort(reverse=True)
idx = 0

from collections import deque

dq = deque()

dq.append(0)
ans = [-1] * n

while len(dq) > 0:
    node = dq.popleft()
    ans[node] = c[idx]
    idx += 1
    for next_node in adj_list[node]:
        if ans[next_node] < 0:
            dq.append(next_node)

print(sum(c[1:]))
print(*ans)


Measured memory_bytes: 77416
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<char> a(n);

  queue<int>pos;
  vector<int> vi;
  rep (i, n) {
    char ch;
    cin >> ch;
    if (ch == 'R') vi.push_back(i);
    a[i] = ch;
  }
  reverse(vi.begin(), vi.end());
  for (auto v : vi) pos.push(v);

  ll ans = 0;
  rep (i, n) {
    if(a[i] == 'W' && !pos.empty()) {
      int next = pos.front();
      pos.pop();
      if (next < i) continue;

      a[next] = 'W';
      a[i] = 'R';

      ans++;
    }
  }

  

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


Measured memory_bytes: 4940
import java.util.*;
public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if(op.equals("?")) break;
			if(op.equals("+")) System.out.println(a + b);
			if(op.equals("-")) System.out.println(a - b);
			if(op.equals("*")) System.out.println(a * b);
			if(op.equals("/")) System.out.println(a / b);
		}
	}
}



Measured memory_bytes: 26396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
ll n,k,t,m,q,flag=0;
ll po(ll k ,ll n,ll ans,ll temp,ll ans1){
    if(n==0)return ans;
    while(temp<=n){
        ans*=ans1;ans%=mod;ans1=ans1*ans1;ans1%=mod;n=n-temp;temp*=2;
    }
    return po(k,n,ans,1,k)%mod;
    //eg. po(2,78,1,1,2);
}
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    //cin>>t;
    t=1;
    while(t--){
        cin>>k>>n;
        ll a[n];
        ll ans=0;
        fo(i,n){
            cin>>a[i];
            if(i>0){
                ans=max(ans, a[i]-a[i-1]);
            }

        }
        ans=max(ans, a[0]+k - a[n-1]);
        cout<<k-ans;
    }

    return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

vector<int> make_bit_primes(int n) {
    vector<int> v(n + 1, 1);
    v[0] = v[1] = 0;
    inc(i, 2, sqrt(n)) {
        if (v[i]) {
            for (int j = 0; i * (j + 2) < n; j++) {
                v[i * (j + 2)] = 0;
            }
        }
    }
    return v;
}

signed main() {
    auto ps = make_bit_primes(1e5);
    vector<int> as(1e5), bs(1e5);
    inc(i, 1, 1e5+1) if (ps[i] && ps[(i + 1) / 2]) as[i] = 1;
    inc(i, 1, 1e5+1) bs[i] = bs[i - 1] + as[i];
    int q;
    cin >> q;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << bs[r] - bs[l-1] << nl;
    }
}


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

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	SegmentTree(vector<T> data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(size(data_.size()) * 2, id_) {
		for (int i = 0; i < data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) {
		assert(0 <= p && p < n);
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};


int main()
{
	int n, q;
	int com, x, y;
	cin >> n >> q;
	SegmentTree<int> st(n, 0x7fffffff, [](int a, int b) { return a <= b ? a : b; });
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com)
			cout << st.Find(x, y) << endl;
		else
			st.Update(x, y);
	}
	return 0;
}

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

int main() {
	int N[4], F[4]={1, 4, 7, 9};
	for(int i=0; i<4; ++i) cin >> N[i];
	sort(N, N+4);
	bool f=true;
	for(int i=0; i<4; ++i){
	    if(N[i]!=F[i]){
	        f=false;
	        break;
	    }
	}
	if(f) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256