akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;

int main(){
vector<int>mm(9);
  rep(i,9){int a; cin>>a; mm.at(i)=a;}
  int N;cin>>N;
  rep(i,N){int t;cin>>t;
           if(mm.at(0)==t){mm.at(0)=0;}
           else if(mm.at(1)==t){mm.at(1)=0;}
           else if(mm.at(2)==t){mm.at(2)=0;}
            else if(mm.at(3)==t){mm.at(3)=0;}
            else if(mm.at(4)==t){mm.at(4)=0;}
            else if(mm.at(5)==t){mm.at(5)=0;}
            else if(mm.at(6)==t){mm.at(6)=0;}
            else if(mm.at(7)==t){mm.at(7)=0;}
            else if(mm.at(8)==t){mm.at(8)=0;}
          else{continue;}
           }
  if(mm.at(0)==mm.at(3)&&mm.at(3)==mm.at(6)){cout<<"Yes"<<endl;}
else if(mm.at(1)==mm.at(4)&&mm.at(4)==mm.at(7)){cout<<"Yes"<<endl;}
else if(mm.at(2)==mm.at(5)&&mm.at(5)==mm.at(8)){cout<<"Yes"<<endl;}
  else if(mm.at(0)==mm.at(1)&&mm.at(1)==mm.at(2)){cout<<"Yes"<<endl;}
  else if(mm.at(3)==mm.at(4)&&mm.at(4)==mm.at(5)){cout<<"Yes"<<endl;}
  else if(mm.at(6)==mm.at(7)&&mm.at(7)==mm.at(8)){cout<<"Yes"<<endl;}
  else if(mm.at(0)==mm.at(4)&&mm.at(4)==mm.at(8)){cout<<"Yes"<<endl;}
  else if(mm.at(2)==mm.at(4)&&mm.at(4)==mm.at(6)){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int h,w;
  cin>>h>>w;
  int c[10][10];
  int inf=1e5;
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++){
      cin>>c[i][j];
      if(c[i][j]<0) c[i][j]=inf;
    }
  for(int k=0;k<10;k++)
    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
  int ans=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int k;
      cin>>k;
      if(~k) ans+=c[k][1];
    }
  cout<<ans<<endl;
  return 0;
}


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

const int64_t mx = 1e18;

int main() {
  int N;
  cin >> N;
  bool ng = false;
  int64_t ans = 1;

  for (int i = 0; i < N; i++) {
    int64_t A;
    cin >> A;

    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (ng || mx/ans < A) {
      ng = true;
    }
    
    ans *= A;

  }

  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }

  vector<ll> B(N+1);
  B[0] = 0;
  for(int i = 0; i < N; i++){
    B[i+1] = B[i] + A[i];
  }

  map<ll, int> m;
  ll ans = 0;
  for(int i = 0; i <= N; i++){

    if(i >= K){
      ll del = (B[i-K] - (i-K) ) % K;
      m[del]--;
    }

    ll tmp = ( B[i] -i ) % K;

    if(m.count(tmp) == 0){
      m[tmp]++;
    } else {
      ans += m[tmp];
      m[tmp]++;
    }

  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
N = int(input())

INF = 10 ** 6
dp = [INF] * (10**5+1)
dp[0] = 0

for n in range(1, 100001):
    power = 1
    while power <= n:
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 6
    power = 1
    while power <= n:
        dp[n] = min(dp[n], dp[n-power] + 1)
        power *= 9

print(dp[N])


Measured memory_bytes: 3956
s = input()
ans = 1
cur = s[0]
temp = 1
if len(s) != 2:
    while temp != len(s):
        if s[temp] != cur:
            if temp != len(s)-2:
                ans += 1
                cur = s[temp]
                temp += 1
            else:
                if s[temp] == s[temp+1]:
                    ans += 1
                    temp += 2
                else:
                    ans += 1
                    cur = s[temp]
                    temp += 1
        else:
            ans += 1
            cur = s[temp]+s[temp+1]
            temp += 2
    print(ans)
else:
    if s[0] == s[1]:
        print(1)
    else:
        print(2)


Measured memory_bytes: 3500
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

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


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

item=[list(map(int,input().split())) for _ in range(N)]
item = sorted(item,key=lambda x:x[0])

dp=[0]*(T+1)

for a,b in item:
    for t in reversed(range(T)):
        dist=min(T,t+a)
        dp[dist] = max(dp[t]+b,dp[dist])
print(max(dp))


Measured memory_bytes: 47976
let () =
  let rec read () =
    let x = read_float () and
        h = read_float () in
    if x = 0. && h = 0. then ()
    else
      let h2 = sqrt(h*.h+.x*.x/.4.) in
      Printf.printf "%f\n" (x*.x+.2.*.x*.h2);
      read ()
  in read ()
;;

Measured memory_bytes: 2196
#include <stdio.h>
 
using namespace std;
 
int main(){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}


Measured memory_bytes: 2716
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = scanner.nextInt();
        }
        long minResult = 1000005;
        for (int p = 1; p <= 100; ++p) {
            long current = 0;
            for (int i = 0; i < n; ++i) {
                current += (a[i] - p) * (a[i] - p);
            }
            minResult = Math.min(minResult, current);
        }
        System.out.println(minResult);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();

		int con = N / X;
		if (N % X !=0) {
			con++;
		}

		System.out.println(con*T);

	}

}

Measured memory_bytes: 35616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll 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;
    }
}

// 二項係数計算
ll COM(ll n, ll 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 n;
cin>>n;
ll ca = 100000000000;
for(ll i=0; i<=n; i++){
ll k = 0;
ll h = i;
while(h){
k+=h%6;
h/=6;
}
ll g = n - i;
while(g){
k+=g%9;
g/=9;}
ca = min(ca,k);}
cout << ca << endl;}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dp[(int)1e6+1][2][2];
int x;
ll mod=1e9+7;
ll f(int i,bool n,bool z)
{
    if (i==x)
        return (n&&z);
    if (dp[i][n][z]!=-1)
        return dp[i][n][z];
    int sum=0;
    for (int j=0; j<10; j++)
    {
        bool zz=z,nn=n;
        if (j==0)
            zz=1;
        if (j==9)
            nn=1;
        sum=(sum%mod+f(i+1,zz,nn)%mod)%mod;
    }
    return dp[i][n][z]=sum;
}
int main()
{
    FASTINOUT;
    cin>>x;
    memset(dp,-1,sizeof dp);
    cout<<f(0,0,0);
    return 0;
}


Measured memory_bytes: 97232
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Q();
        }

        static void Q()
        {
            var NK = ReadSplitInt();
            var S = Read().ToArray();
            S[NK[1] - 1] = char.ToLower(S[NK[1] - 1]);
            Println(Join(S));
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13396
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

long long modpow(long long a, long long n, long long MOD) {//a^n(MOD)を求める
    long long res = 1%MOD;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  cout<<(modpow(10,n,mod)+mod+mod-2*modpow(9,n,mod)+modpow(8,n,mod))%mod<<ENDL;
  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll N;
    cin >> N;
    ll s[N];
    ll out = 0;
    rep(i,N){
        cin >> s[i];
        out += s[i];
    }
    sort(s,s+N);
    rep(i,N){
        if(out%10==0&&s[i]%10!=0) out -= s[i];
        if(i==N-1&&out%10==0) out = 0;
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
	int a,b,c;
	cin >>a>>b>>c;
	int tc=a+b;
	tc=min(a+b+1,c);
	cout <<tc+b<<endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

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

int main() {
    int n, x, a;
    cin >> n >> x;

    int ans = -1;

    for (int i = 0; i < n; i++) {
        cin >> a;
        a = abs(a - x);
        if (ans >= 0) {
            ans = gcd(ans, a);
        } else {
            ans = a;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  long long n, min, max, sum, l, x;
  sum = 0;

  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> x;
    sum += x;

    if (i >= 1) {
      if (x < min) {
        l = x;
        x = min;
        min = l;
      }
      if (max < x) {
        l = x;
        x = max;
        max = l;
      }
    } 
    else {
      min = x;
      max = x;
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3128
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int n = sc.nextInt();
    int w1 = 0;
    int h1 = 0;
    int w2 = 0;
    int h2 = 0;
    
    //黒くなる部分求める
    for(int i = 0 ; i < n ; ++i){
      int x = sc.nextInt();
      int y = sc.nextInt();
      int a = sc.nextInt();      
      if(a==1){
        w1 = Math.max(w1,x);
      }
      if(a==2){
        w2 = Math.max(w2,(w-x));
      }
      if(a==3){
        h1 = Math.max(h1,y);
      }
      if(a==4){
        h2 = Math.max(h2,(h-y));
      }
    }
    int ans = (w-w1-w2)*(h-h1-h2);
    if(w-w1-w2<0 || h-h1-h2<0) ans = 0;
    System.out.println(ans);
    
  }
}

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

 int N;
 string s;
 string t;

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

   int output = 0;
   for (int i = N-1; i >= 0; i--) {
     int cnt = 0;
     for (int j = i; j < N; j++) {
       if (s[j] == t[j - i]) {
         cnt += 1;
       } else {
         cnt = 0;
         break;
       }
     }
     output = max(output, cnt);
   }
   cout << 2*N - output << endl;
   return 0;
 }

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

A -= 1

Cnum = B // C - A // C
Dnum = B // D - A // D

Cnum = B - A - Cnum
Dnum = B - A - Dnum

if(C < D):
    C, D = C, D

x = C*D

r = C % D

while(r != 0):
    C = D
    D = r
    r = C % D

LCM_CD = x // D

CDnum = B // LCM_CD - A // LCM_CD

CDnum = B - A - CDnum

ans = Cnum + Dnum - CDnum

print(ans)

Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		BigInteger bordersum = BigInteger.ZERO;
		int tmpborder = 0;
		for (int i = 0; i < n; i++) {
			int tmp = sc.nextInt();
			if (i == 0) {
				tmpborder = tmp;
				continue;
			}
			if (tmp < tmpborder) {
				bordersum = bordersum.add(BigInteger.valueOf(tmpborder).subtract(BigInteger.valueOf(tmp)));
			} else {
				tmpborder = tmp;
			}
		}
		System.out.println(bordersum);
	}
}


Measured memory_bytes: 59048
#include<stdio.h>
int main()
{
   int n,count4=0,i,count2=0;
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {  int a;
     scanf("%d",&a);
     if(a%4==0) count4++;
     else if(a%4!=0&&a%2==0) count2++;
   }
   n-=count2;
   if(count2==0){ 
   if(n%2==0)
   {
   	   if(count4>=n/2) printf("Yes\n");
   	   else printf("No\n");
   }
   if(n%2==1)
   {   n--;
        if(count4>=n/2) printf("Yes\n");
		else printf("No\n");	
   }
   }
    else if(count2!=0)
    {
    	if(n%2==0)
   {
   	   if(count4>=n/2) printf("Yes\n");
   	   else printf("No\n");
   }
   if(n%2==1)
   {   n++;
        if(count4>=n/2) printf("Yes\n");
		else printf("No\n");	
   }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 2e3 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	}while(isdigit(ch));
	return res * sign;
}
int n,cnt;
bool E[Maxn][Maxn],vis[Maxn];
int fir[Maxn],a[Maxn],ind[Maxn];
struct {
	int to,last;
}e[Maxn*Maxn];
void con(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].last=fir[u];
	fir[u]=cnt;
	ind[v]++;
}
int gcd(rg int x,rg int y)
{
	rg int z=x%y;
	while(z)
	{
		x=y;
		y=z;
		z=x%y;
	}
	return y;
}
void DFS(int x)
{
	vis[x]=true;
	for(int i=1;i<=n;i++)
	{
		if(!E[x][i]||vis[i])
			continue;
		con(x,i);
		DFS(i);
	}
}
priority_queue<int>q;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(gcd(a[i],a[j])!=1)
				E[i][j]=E[j][i]=true;
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			DFS(i);
			q.push(i);
		}	
	rg int x;
	while(!q.empty())
	{
		x=q.top();
		q.pop();
		for(int next=fir[x],nx;next;next=e[next].last)
		{
			nx=e[next].to;
			ind[nx]--;
			if(!ind[nx])
				q.push({nx});
		}
		printf("%d ",a[x]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> cnt(m);
  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    vector<int> a(k);
    for(int j=0;j<k;j++){
      cin >> a[j];
      cnt[a[j]-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<m;i++){
    if(cnt[i]==n){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, K = input().split()
N=int(N)
K=int(K)

array = []
for i in range(N):
    n = i+1
    nankai = 0
    while n < K:
        n = n * 2
        nankai += 1
    array.append(nankai)

kakus = 0
for k in array:
    kaku = 1 / N
    for q in range(k):
        kaku = kaku / 2
    kakus += kaku

print(kakus)

Measured memory_bytes: 3864
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

def f(x,y):
    ma = x*y - 1
    ok = 0
    ng = 10**9 + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if mid**2 <= ma:
            ok = mid
        else:
            ng = mid
    return ok

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    if a == 1 and b == 1:
        ans.append(0)
        continue
    p = f(a,b)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')

Measured memory_bytes: 65372
#include <iostream>

using namespace std;

int main()
{
	int n, k;
	int a[100000];

	cin >> n >> k;

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

	if(n % (k - 1) <= 1)
	{
		if(k == 2)
		{
			cout << n - 1 << endl;
		}
		else
		{
			cout << n / (k - 1) << endl;
		}
	}
	else
	{
		cout << n / (k - 1) + 1 << endl;
	}

	//cout << n / (k - 1)
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	


int main() {
	int a, b, c,x;
	cin >> a >> b >> c>> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				int total = 500 * i + 100 * j + 50 * k;
				if (total == x) ans += 1;
			}
		}
	}
	cout << ans;
	
	return 0;
}










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



int main() {
    int a, b;
    cin >> a >> b;
    
    if((a+b)%2 == 0)
        cout << (a+b) / 2 << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3552
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i] +B[i])
ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K -a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 134164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


main() {

  int n; /* プロセス数 */
  int q; /* クオンタム時間 */
  int sumTime = 0; /* 経過時間 */

  int head=0; /* キューの先頭と末尾+1 */
  int tail=1;

  char name[100000][11]; /* プロセス名 */
  int time[100000]; /* 各プロセスの所要時間 */


  scanf("%d%d", &n, &q);

  for( tail=0; tail<n; tail++) {
    scanf("%s%d", name[tail], &time[tail]);
  }

  while(head != tail) {
    
    if( time[head] <= q ) { /* プロセスが完了する */
      sumTime += time[head];
      printf("%s %d\n", name[head], sumTime);
    }

    else { /* プロセスが完了しない */
      sumTime += q;
      strcpy(name[tail], name[head]);
      time[tail] = time[head] - q;

      if( tail+1 >= 100000 ) {
	tail = 0;
      }
      else {
	tail++;
      }
    }
    
    if( head+1 >= 100000 ) {
      head = 0;
    }
    else {
      head++;
    }
  }

  return 0;

}

Measured memory_bytes: 2076
number_of_traials = int(input())

AC_counter = 0
WA_counter = 0
TLE_counter = 0
RE_counter = 0

for i in range(number_of_traials):
    result = input()
    if result == "AC":
        AC_counter += 1
    elif result == "WA":
        WA_counter += 1
    elif result == "TLE":
        TLE_counter += 1
    elif result == "RE":
        RE_counter += 1

print("AC x {}".format(AC_counter))
print("WA x {}".format(WA_counter))
print("TLE x {}".format(TLE_counter))
print("RE x {}".format(RE_counter))

Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt64();
            var X = line[0];

            switch (X)
            {
                case 7:
                case 5:
                case 3:
                    return "YES";
                default:
                    return "NO";
            }
        }


        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); }
        public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); }
        public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); }
        public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); }
        public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); }
    }
}


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

using namespace std;

string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main(){
	string str;
	cin >> str;
	int idx;
	for(int i=0; i<7; i++){
		if(str == day[i]) idx = i;
	}
	idx = 7 - idx;
	cout << idx << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pll pair<long long int, long long int>
#define great (long long int)(1e9+7)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fst first
#define scd second

void solve()
{
  ll n;
  cin>>n;
  if(n%1000==0) {cout<<0<<endl;return;}
  ll r=n/1000;
  ll p=(r+1)*1000;
  cout<<p-n<<endl;


}
int main()
{
    //fastio;
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

ll mod = 1e9 + 7;

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, r = 0;
  
  REP(i, n){
    if(s[i] == ')') l++;
    else l--;
    r = max(r, l);
  }
  vector<char> ans;
  REP(i, r) ans.push_back('(');
  REP(i, n) ans.push_back(s[i]);
  REP(i, r - l) ans.push_back(')');

  REP(i, ans.size()) cout << ans[i];
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;

double w,h,x,y;
int main(){
  scanf("%lf%lf%lf%lf",&w,&h,&x,&y);
  printf("%.10f ",w * h / 2.0);
  if(x * 2 == w && y * 2 == h) puts("1");
  else puts("0");
  return 0;
}


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

int main(){
    int n,m;

    cin >> n >> m;

    cout << (n*(n-1)/2)+(m*(m-1)/2) << endl;
}

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

int main(){
  int abc[3];
  cin >> abc[0] >> abc[1] >> abc[2];
  
  int count5 = 0;
  int count7 = 0;
  for(int num : abc){
    if(num == 5) count5++;
    else if(num == 7) count7++;
  }
  string result = (count5 == 2 && count7 == 1)? "YES" : "NO";

  cout << result;
  return 0;
}

Measured memory_bytes: 3544
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[M];
        int[] C = new int[M];

        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i=0; i<M; i++) {
            B[i] = sc.nextInt();
            C[i] = sc.nextInt();
        }

        System.out.println(solve(N, M, A, B, C));
    }

    private static long solve(int N, int M, int[] A, int[] B, int[] C) {
        long sum = 0;
        Arrays.sort(A);

        List<Pair> list = new ArrayList<>();
        for (int i=0; i<M; i++) {
            list.add(new Pair(C[i], i));
        }
        Collections.sort(list);

        int count = 0;
        int idxA = N-1;
        while (count < N) {
            if (list.size() == 0 || A[idxA] >= list.get(0).a) {
                sum += A[idxA];
                count++;
                idxA--;
//                System.err.println("use A " + A[idxA+1]);
            } else {

                Pair p = list.get(0);
                int v = p.a;
                int idx = p.b;
                int c = B[idx];

                if (count + c > N) {
                    c = N - count;
                }
                sum += (long)v * c;
                count += c;
                list.remove(0);

//                System.err.println("use C " + v + ", " + idx + ", " + c);
            }

//            System.err.println("sum = " + sum);
        }

        return sum;
    }

    static class Pair implements Comparable<Pair> {
        public int a;
        public int b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair p) {
            return p.a - a;
        }
    }
}


Measured memory_bytes: 95672
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int n;
vector<int> g[100000];
ll dp[2][100000];
bool used[100000];
void dfs(int x){
	used[x]=1;
	dp[0][x]=1, dp[1][x]=1;
	for(auto y:g[x]){
		if(used[y]){
			continue;
		}
		dfs(y);
		dp[0][x]*=(dp[0][y]+dp[1][y]);
		dp[0][x]%=MOD;
		dp[1][x]*=dp[0][y];
		dp[1][x]%=MOD;
	}
}
int main()
{
	cin>>n;
	for(int i=0; i<n-1; i++){
		int x, y; cin>>x>>y;
		x--; y--;
		g[x].push_back(y); g[y].push_back(x);
	}
	dfs(0);
	cout<<(dp[0][0]+dp[1][0])%MOD<<endl;
	return 0;
}

Measured memory_bytes: 11520
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var XY = ReadSplitLong();
            var X = XY[0];
            var Y = XY[1];

            var ans = 0L;
            for (long i = X; i <= Y; i*=2)
            {
                ans++;
            }
            Println(ans);
        }

        static List<int> ReadLines(int n)
        {
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                l.Add(ReadInt());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

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

/*
#include <bits/stdc++.h>
using namespace std;

const int Nmx = 5;

const int fac[6] = {1, 1, 2, 6, 24, 120};
int shuf[Nmx + 1][120][1 << Nmx];

void prepare() {
  auto arrange = [&] (int v, int l, const vector<int>& p) {
    int rt = 0;
    for (auto x : p) {
      if (v & 1) {
        rt |= 1 << x;
      }
      v >>= 1;
    }
    return rt;
  };
  for (int l = 1; l <= Nmx; l++) {
    vector<int> p (l);
    for (int i = 0; i < l; i++) {
      p[i] = i;
    }
    for (int id = 0; next_permutation(p.begin(), p.end()); id++) {
      for (int i = 0; i < (1 << l); i++) {
        shuf[l][id][i] = arrange(i, l, p);
      }
    }
  }
}


bool check(int n, const vector<int>& tb) {
  static int vis[1 << Nmx], dfc = 0;
  ++dfc;
  for (auto x : tb) {
    vis[x] = dfc;
  }
  for (int i = 0; i < fac[n] - 1; i++) {
    bool flag = true;
    for (int j = 0; j < (signed) tb.size() && flag; j++) {
      flag = vis[shuf[n][i][tb[j]]] == dfc;
    }
    if (flag) {
      return false;
    }
  }
  return true;
}

int ans = 0;
vector<int> stk;
void dfs(int l, int d, int k, int ls) {
  if (d == k) {
    ans += check(l, stk);
    if (ans > 1000 * fac[l]) {
      throw 1;
    }
    return;
  }
  for (int s = ls + 1; s < (1 << l); s++) {
    stk[d] = s;
    dfs(l, d + 1, k, s);
  }
}

int n, k;
int table[6][20];

int main() {
  prepare();
  for (int k = 1; k <= 5; k++) {
    for (int n = k; n <= (1 << (k - 1)); n++) {
      ::k = k;
      ::n = n;
      ::ans = 0;
      stk.resize(n);
      try {
        dfs(k, 0, n, -1);
      } catch(int) {
        ans = 1001 * fac[k];
      }
      cout << k << " " << n << '\n';
      ans /= fac[k];
      table[k][n] = ans;
    }
  }
  cout << "{{}";
  for (int i = 1; i <= 5; i++) {
    cout << ",\n {";
    cout << table[i][0];
    for (int j = 1; j <= 16; j++) {
      cout << ", " << table[i][j];
    }
    cout << "}";
  }
  cout << "};\n";
  return 0;
}
*/

const int table[6][20] = {{},
 {1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 36, 108, 220, 334, 384, 0, 0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001}};

#define ll long long

vector<int> G (105);
void prepare() {
	G[1] = 0;
	for (int n = 2; n <= 100; n++) {
		for (int k = 1; k < n; k++) {
			if ((1 << k) >= n && ((1 << k) - n) >= G[k]) {
				G[n] = k;
				break;
			}
		}
	}
}

int g(ll n) {
	if (n <= 100) {
		return G[n];
	}
	for (int k = 1; ; k++) {
		if ((1ll << k) >= n && ((1ll << k) - n) >= g(k)) {
			return k;
		}
	}
	assert(false);
	return -1;
}

int solve(ll n, ll k) {
	if (n < k) {
		swap(n, k);
	}
	if (k < 63 && (1ll << k) - n < n) {
		return solve((1ll << k) - n, k);
	}
	if (k > 5) {
		return 1001;
	}
	return k == 0 ? 1 : table[k][n];
}

int main() {
	ll n;
	prepare();
	scanf("%lld", &n);
	int ans = solve(n, g(n));
	ans += (n == 4);
	ans += (n == 7) * 2;
	printf("%d\n", (ans > 1000) ? -1 : ans);
	return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
ll mod(ll val, ll MOD) {
    long long res = val % MOD;
    if (res < 0) res += MOD;
    return res;
}

ll modinv(ll a, ll MOD) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     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;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }

ll f(ll a, ll b, ll x) {
    return floor(a * x / b) - a * floor(x / b);
}

int main() {
    ld a, b, n;
    cin >> a >> b >>n;
    cout << f(a, b, min(n, b-1)) << endl;
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;

using p = pair<ll, ll>;

bool f(const p & p1,const p & p2)
{
	return p1.second > p2.second;
}


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

	vector<pair<ll,ll>> P(N);

	for (ll i = 0; i < N; ++i)
	{
		cin >> P[i].second;
		P[i].first = i;
	}

	sort(P.begin(), P.end(), f);

	map<ll, ll> mp;

	mp[P[0].first] = P[0].second;


	ll ans = 0;
	for (ll i = 1; i < N; ++i)
	{
		ll k = P[i].first;
		mp[P[i].first] = P[i].second;
		ll a, b, c, d;
		auto itrL = mp.find(P[i].first);
		auto itrR = itrL;

		bool flagL=true, flagR = true;

		if(itrL!=mp.begin())
		{
			--itrL;
			b = itrL->first;
			if (itrL != mp.begin())
			{
				--itrL;
				a = itrL->first;
			}
			else
			{
				a = -1;
			}
		}
		else
		{
			a = b = -1;
			flagL = false;
		}

		++itrR;
		if (itrR != mp.end())
		{
			c = itrR->first;
			++itrR;
			if (itrR != mp.end())
			{
				d = itrR->first;
			}
			else
			{
				d = N;
			}
		}
		else
		{
			c = d = N;
			flagR = false;
		}

		if (flagL)
		{
			ans += (b-a) * (c-k)*P[i].second;
		}
		if (flagR)
		{
			ans += (d-c) * (k-b)*P[i].second;
		}

		//cout << ans << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
using namespace std;
int main(void){

    int n;
    cin >> n;
    int kazu[n];
    int hanten[n];
    for(int i=0;i<n;i++){
        cin >> kazu[i];
    }
    
   
   
    for(int i=0;i<n;i++){
         hanten[n-i-1] = kazu[i];
    }
 
  
    for(int i=0;i<n;i++){
        kazu[i]=hanten[i];
    }
    
    
    for(int i=0;i<=n-2;i++){
        cout << kazu[i]<<" ";
    }
    cout << kazu[n-1];
    cout << endl;
}




Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define N 200009
#define pb push_back
using namespace std;
typedef long long ll;
void slv()
{
    int n;
    double d,x,y;
    cin>>n>>d;
    int ans=0;
    while (n--)
    {
        cin>>x>>y;
        x*=x;
        y*=y;
        double tl=x+y;
        tl=sqrt(tl);
        if(tl <= d) ans++;
    }
    
    cout<<ans<<endl;
}
int main()
{
    int t;
    t=1;
    for(int cs=1;cs<=t;cs++)
    {
        //printf("Case #%d: ",cs);
        slv();
    }
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k-1] = s[k-1] - ('A' - 'a');
  cout << s << endl;
}


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

int main()
{

    int A, B, X;

    cin >> A >> B >> X;
    int cat = A;
    for (int i = 0; i <= B; i++)
    {
        if (cat == X)
        {
            cout << "YES";
            return 0;
        }
        ++cat;
    }
    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
A,B,K=map(int,input().split())
if (A+B)<=K:
  print('0 0')
else:
  if A <= K:
    if B <= (K-A):
      print('0 0')
    else:
      print('0 {}'.format(str(B-(K-A))))
  else:
    print('{} {}'.format(str(A-K),str(B)))


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

int main(){
  int n;cin>>n;
  vector<long long int> l(n+1);
  l.at(0)=2;
  l.at(1)=1;
  for(int i=2;i<=n;i++) l.at(i)=l.at(i-1)+l.at(i-2);
  cout<<l.at(n)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, h, h_max = 0, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> h;
        if(h_max <= h){
            h_max = h;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int A[4][2]={-1,0,0,1,1,0,0,-1},ans,N,M;char RB[25][25];void bfs(int x, int y) {RB[x][y]='#';ans++;for (int i=0;i<4;i++) {int nx=x+A[i][0],ny=y+A[i][1];if (nx>=0 && nx<N && ny>=0 && ny<M && RB[nx][ny]=='.') bfs(nx,ny);}}
int main() {int i,j;while (1) {scanf("%d %d",&M,&N);if (!N && !M) return 0;for (i=0;i<N;scanf("%s",&RB[i++]));ans=0;for (i=0;i<N;i++) for (j=0;j<M;j++) if (RB[i][j]=='@') bfs(i,j);printf("%d\n",ans);}}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <math.h>

char prime[50001];

void eratosthenes() {
    int i, l, j, d;
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (i = 3, l = (int)sqrt(50000) + 1; i < l; i++) {
        if (prime[i] == 1) {
            for (d = i * 2, j = i + d; j <= 50000; j += d) {
                prime[j] = 0;
            }
        }
    }
}


int main(void) {
    int n, i, pat;

    eratosthenes();

    while (scanf("%d", &n) == 1 && n) {
        if (n&1 || n == 4) {
            if (prime[n - 2]) {
                puts("1");
            }
            else {
                puts("0");
            }
            continue;
        }
        for (i = n - 1, pat = 0; i >= n / 2; i -= 2) {
            if (prime[i] && prime[n - i]) {
                pat++;
            }
        }
        printf("%d\n", pat);
    }
    return 0;
}

Measured memory_bytes: 668
N = int(input())
NN = N
b = ''
i = 0
if N == 0:
  b = '0'
else:
  while (NN!=0):
    bi = abs(NN)%2
    b=str(bi)+b
    NN = (NN-bi*(-1)**i)//2
    i+=1
print(b)

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

int main(){
  string S, T;
  cin >> S >> T;
  int L=S.size();
  int sspel[26]={0};
  int tspel[26]={0};
  string ans="Yes";
  for(int i=0; i<L; i++){
    sspel[S.at(i)-97]++;
    tspel[T.at(i)-97]++;
    if(sspel[S.at(i)-97]!=tspel[T.at(i)-97]){
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 776